001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package com.tomsawyer.editor.service.layout.jlayout;
043:
044: import com.tomsawyer.editor.TSEResourceBundleWrapper;
045: import java.awt.Component;
046: import java.awt.Font;
047: import java.util.List;
048: import javax.swing.BoxLayout;
049: import javax.swing.JDialog;
050: import com.tomsawyer.service.TSServiceInputData;
051: import com.tomsawyer.editor.TSEGraph;
052: import javax.swing.BorderFactory;
053: import javax.swing.JLabel;
054: import javax.swing.JPanel;
055: import javax.swing.border.TitledBorder;
056:
057: public class TSERoutingTabExt extends TSERoutingTab {
058: public static TSEResourceBundleWrapper tsBundle = TSEResourceBundleWrapper
059: .getSystemLabelBundle();
060:
061: /**
062: * This constructor creates a new Symmetric tab.
063: * @param
064: * graph the <code>TSEGraph</code> whose layout
065: * properties are being edited.
066: * @param
067: * inputData the service input data object where the
068: * layout options are stored
069: * @param
070: * dialog the Layout Properties dialog that this
071: * tab belongs to.
072: */
073: public TSERoutingTabExt(TSEGraph graph,
074: TSServiceInputData inputData, JDialog dialog) {
075: super (graph, inputData, dialog);
076: setA11yFeatures();
077: }
078:
079: /**
080: * This method creates the Horizontal Spacing panel of this tab.
081: */
082: protected JPanel makeHorizontalSpacingPanel() {
083: JPanel panel = this .createBoxLayoutPanel(BoxLayout.X_AXIS);
084:
085: // create the subpanels
086: JPanel leftPanel = this .createBoxLayoutPanel(BoxLayout.Y_AXIS);
087: JPanel rightPanel = this .createBoxLayoutPanel(BoxLayout.Y_AXIS);
088:
089: // Create the components
090: horizontalSpacingBetweenNodesField = createDoubleField(4, 0,
091: 9999);
092: horizontalSpacingBetweenEdgesField = createDoubleField(4, 0,
093: 9999);
094:
095: JLabel spacingBetweenNodesLabel = this .createLabel(
096: "Spacing_Between_Nodes",
097: "Horizontal_Spacing_Between_Nodes",
098: horizontalSpacingBetweenNodesField);
099:
100: JLabel spacingBetweenEdgesLabel = this .createLabel(
101: "Spacing_Between_Edges", null,
102: horizontalSpacingBetweenEdgesField);
103:
104: // add the components to the subpanele
105: leftPanel.add(spacingBetweenNodesLabel);
106: leftPanel.add(this .createVerticalRigidArea(9));
107: leftPanel.add(spacingBetweenEdgesLabel);
108:
109: rightPanel.add(this .horizontalSpacingBetweenNodesField);
110: rightPanel.add(this .createVerticalRigidArea(5));
111: rightPanel.add(this .horizontalSpacingBetweenEdgesField);
112:
113: // add the subpanels to the panel
114:
115: panel.add(leftPanel);
116: panel.add(this .createHorizontalRigidArea(20));
117: panel.add(rightPanel);
118:
119: // Create a border
120:
121: this .createCompoundBorder(panel, "Horizontal_Spacing", 0, 6, 5,
122: 6);
123:
124: return panel;
125: }
126:
127: /**
128: * This method creates the Vertical Spacing panel of this tab.
129: */
130: protected JPanel makeVerticalSpacingPanel() {
131: JPanel panel = this .createBoxLayoutPanel(BoxLayout.X_AXIS);
132:
133: // create the subpanels
134: JPanel leftPanel = this .createBoxLayoutPanel(BoxLayout.Y_AXIS);
135: JPanel rightPanel = this .createBoxLayoutPanel(BoxLayout.Y_AXIS);
136:
137: // Create the components
138: verticalSpacingBetweenNodesField = createDoubleField(4, 0, 9999);
139: verticalSpacingBetweenEdgesField = createDoubleField(4, 0, 9999);
140:
141: JLabel spacingBetweenNodesLabel = this .createLabel(
142: "Spacing_Between_Nodes",
143: "Vertical_Spacing_Between_Nodes",
144: verticalSpacingBetweenNodesField);
145:
146: JLabel spacingBetweenEdgesLabel = this .createLabel(
147: "Spacing_Between_Edges", null,
148: verticalSpacingBetweenEdgesField);
149:
150: // add the components to the subpanel
151: leftPanel.add(spacingBetweenNodesLabel);
152: leftPanel.add(this .createVerticalRigidArea(9));
153: leftPanel.add(spacingBetweenEdgesLabel);
154:
155: rightPanel.add(this .verticalSpacingBetweenNodesField);
156: rightPanel.add(this .createVerticalRigidArea(5));
157: rightPanel.add(this .verticalSpacingBetweenEdgesField);
158:
159: // add the subpanels to the panel
160:
161: panel.add(leftPanel);
162: panel.add(this .createHorizontalRigidArea(20));
163: panel.add(rightPanel);
164:
165: // Create a border
166:
167: this
168: .createCompoundBorder(panel, "Vertical_Spacing", 0, 6,
169: 5, 6);
170:
171: return panel;
172: }
173:
174: /**
175: * This method creates a new JPanel and sets its layout manager to
176: * a BoxLayout with the input layout style.
177: */
178: protected JPanel createBoxLayoutPanel(int layout) {
179: JPanel panel = new JPanel();
180: panel.setLayout(new BoxLayout(panel, layout));
181: panel.setAlignmentX(LEFT_ALIGNMENT);
182: panel.setAlignmentY(TOP_ALIGNMENT);
183: return panel;
184: }
185:
186: /**
187: * This method creates a new <code>JLabel</code> with the given text
188: * @param labelKey the key for which the label text will be obtained from the resource bundle
189: * @param mnemonicKey the for which the mnemonic will be obtained from the resource bundle
190: * set it to null if you don't want to set mnemonic for this label.
191: * @param labelForComp the component for which the label is set
192: */
193: protected JLabel createLabel(String labelKey, String mnemonicKey,
194: Component labelForComp) {
195: JLabel label = new JLabel(tsBundle.getStringSafely(labelKey)
196: + ":");
197: label.setForeground(labelColor);
198: label.setAlignmentX(LEFT_ALIGNMENT);
199: label.setAlignmentY(TOP_ALIGNMENT);
200: //A11y
201: label.setLabelFor(labelForComp);
202: if (mnemonicKey != null) {
203: label.setDisplayedMnemonic(AccessiblityUtils
204: .getMnemonic(mnemonicKey));
205: }
206: return (label);
207: }
208:
209: public void createCompoundBorder(JPanel panel, String labelKey,
210: int top, int left, int bottom, int right) {
211: String label = this .tsBundle.getStringSafely(labelKey);
212: TitledBorder titledBorder = BorderFactory
213: .createTitledBorder(label);
214: titledBorder.setTitleColor(labelColor);
215: panel.setBorder(BorderFactory.createCompoundBorder(
216: titledBorder, BorderFactory.createEmptyBorder(top,
217: left, bottom, right)));
218: }
219:
220: //override the super method to to do nothing inorder to fix the component display issue with different fontsizes
221: protected int normalizeComponentDimensions(List compList,
222: boolean xDim, boolean yDim) {
223: return 0;
224: }
225:
226: public void setA11yFeatures() {
227: Font defaultFont = this .getFont();
228:
229: // set nmemonics for checkboxes (only the 1st one in a component group)
230: fixNodeSizesCheckBox.setMnemonic(AccessiblityUtils
231: .getMnemonic("Fix_Node_Sizes"));
232:
233: // set font to use the default font
234: fixNodeSizesCheckBox.setFont(defaultFont);
235: fixNodePositionsCheckBox.setFont(defaultFont);
236:
237: // set accessibility name and descritpion
238: AccessiblityUtils.setAccessibleProperties(
239: horizontalSpacingBetweenNodesField, null,
240: "Horizontal_Spacing_Between_Nodes");
241: AccessiblityUtils.setAccessibleProperties(
242: verticalSpacingBetweenNodesField, null,
243: "Vertical_Spacing_Between_Nodes");
244: AccessiblityUtils.setAccessibleProperties(
245: horizontalSpacingBetweenEdgesField, null,
246: "Horizontal_Spacing_Between_Edges");
247: AccessiblityUtils.setAccessibleProperties(
248: verticalSpacingBetweenEdgesField, null,
249: "Vertical_Spacing_Between_Edges");
250: AccessiblityUtils.setAccessibleProperties(fixNodeSizesCheckBox,
251: null, "Fix_Node_Sizes");
252: AccessiblityUtils.setAccessibleProperties(
253: fixNodePositionsCheckBox, null, "Fix_Node_Positions");
254:
255: this.getAccessibleContext().setAccessibleDescription(
256: this.getAccessibleContext().getAccessibleName());
257: }
258: }
|