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 java.awt.Font;
045: import javax.swing.JDialog;
046: import com.tomsawyer.service.TSServiceInputData;
047: import com.tomsawyer.editor.TSEGraph;
048: import com.tomsawyer.editor.TSEResourceBundleWrapper;
049: import java.awt.Component;
050: import javax.swing.BorderFactory;
051: import javax.swing.BoxLayout;
052: import javax.swing.JLabel;
053: import javax.swing.JPanel;
054: import javax.swing.border.TitledBorder;
055:
056: public class TSEDisconnectedTabExt extends TSEDisconnectedTab {
057: public static TSEResourceBundleWrapper tsBundle = TSEResourceBundleWrapper
058: .getSystemLabelBundle();
059:
060: /**
061: * This constructor creates a new Disconnected tab.
062: * @param graph the <code>TSEGraph</code> whose layout properties are being
063: * edited.
064: * @param inputData the service input data object where the layout
065: * properties are stored
066: * @param dialog the Layout Properties dialog that this tab belongs to.
067: */
068: public TSEDisconnectedTabExt(TSEGraph graph,
069: TSServiceInputData inputData, JDialog dialog) {
070: super (graph, inputData, dialog);
071: setA11yFeatures();
072: }
073:
074: /**
075: * This method creates the Components panel of this tab.
076: */
077: protected JPanel makeComponentsPanel() {
078: JPanel result = new JPanel();
079:
080: // Create the components
081:
082: this .detectConn = this .createCheckbox("Detect_Components",
083: DETECT_COMPONENTS);
084:
085: // create doubld fields
086: this .connConstantSpacingField = this .createDoubleField(4, 0,
087: 1000);
088: this .connProportionalSpacingField = this .createDoubleField(4,
089: 0, 1000);
090:
091: // create labels
092: JLabel connConstantSpacingLabel = this .createLabel(
093: "Constant_Spacing", null, connConstantSpacingField);
094:
095: JLabel connProportionalSpacingLabel = this .createLabel(
096: "Proportional_Spacing", null,
097: connProportionalSpacingField);
098:
099: // Layout the components
100: result.setLayout(new BoxLayout(result, BoxLayout.Y_AXIS));
101:
102: JPanel leftPanel = new JPanel();
103: JPanel rightPanel = new JPanel();
104:
105: // Layout the components
106: JPanel table = new JPanel();
107:
108: table.setLayout(new BoxLayout(table, BoxLayout.X_AXIS));
109: leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
110: rightPanel
111: .setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
112:
113: leftPanel.setAlignmentX(LEFT_ALIGNMENT);
114: rightPanel.setAlignmentX(LEFT_ALIGNMENT);
115: table.setAlignmentX(LEFT_ALIGNMENT);
116:
117: leftPanel.add(connConstantSpacingLabel);
118: leftPanel.add(this .createVerticalRigidArea(9));
119: leftPanel.add(connProportionalSpacingLabel);
120:
121: rightPanel.add(this .connConstantSpacingField);
122: rightPanel.add(this .createVerticalRigidArea(5));
123: rightPanel.add(this .connProportionalSpacingField);
124:
125: table.add(leftPanel);
126: table.add(this .createHorizontalRigidArea(40));
127: table.add(rightPanel);
128:
129: result.add(this .detectConn);
130: result.add(this .createVerticalRigidArea(5));
131: result.add(table);
132:
133: this .createCompoundBorder(result, "Components", 0, 6, 5, 5);
134:
135: return result;
136: }
137:
138: /**
139: * This method creates the Disconnected Nodes panel of this tab.
140: */
141: protected JPanel makeDisconnectedPanel() {
142: JPanel result = new JPanel();
143:
144: // Create the components.
145:
146: this .detectDisc = this .createCheckbox(
147: "Detect_Disconnected_Nodes", DETECT_DISCONNECTED_NODES);
148:
149: this .discConstantSpacingField = this .createDoubleField(4, 0,
150: 1000);
151: this .discProportionalSpacingField = this .createDoubleField(4,
152: 0, 1000);
153:
154: JLabel discConstantSpacingLabel = this .createLabel(
155: "Constant_Spacing", null, discConstantSpacingField);
156:
157: JLabel discProportionalSpacingLabel = this .createLabel(
158: "Proportional_Spacing", null,
159: discProportionalSpacingField);
160:
161: // Layout the components
162: result.setLayout(new BoxLayout(result, BoxLayout.Y_AXIS));
163:
164: JPanel leftPanel = new JPanel();
165: JPanel rightPanel = new JPanel();
166:
167: // Layout the components
168: JPanel table = new JPanel();
169:
170: table.setLayout(new BoxLayout(table, BoxLayout.X_AXIS));
171: leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
172: rightPanel
173: .setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
174:
175: leftPanel.setAlignmentX(LEFT_ALIGNMENT);
176: rightPanel.setAlignmentX(LEFT_ALIGNMENT);
177: table.setAlignmentX(LEFT_ALIGNMENT);
178:
179: leftPanel.add(discConstantSpacingLabel);
180: leftPanel.add(this .createVerticalRigidArea(9));
181: leftPanel.add(discProportionalSpacingLabel);
182:
183: rightPanel.add(this .discConstantSpacingField);
184: rightPanel.add(this .createVerticalRigidArea(5));
185: rightPanel.add(this .discProportionalSpacingField);
186:
187: table.add(leftPanel);
188: table.add(this .createHorizontalRigidArea(40));
189: table.add(rightPanel);
190:
191: result.add(this .detectDisc);
192: result.add(this .createVerticalRigidArea(5));
193: result.add(table);
194:
195: this .createCompoundBorder(result, "Disconnected_Nodes", 0, 6,
196: 5, 5);
197:
198: return result;
199: }
200:
201: /**
202: * This method creates a new JPanel and sets its layout manager to
203: * a BoxLayout with the input layout style.
204: */
205: protected JPanel createBoxLayoutPanel(int layout) {
206: JPanel panel = new JPanel();
207: panel.setLayout(new BoxLayout(panel, layout));
208: panel.setAlignmentX(LEFT_ALIGNMENT);
209: panel.setAlignmentY(TOP_ALIGNMENT);
210: return panel;
211: }
212:
213: /**
214: * This method creates a new <code>JLabel</code> with the given text
215: * @param labelKey the key for which the label text will be obtained from the resource bundle
216: * @param mnemonicKey the for which the mnemonic will be obtained from the resource bundle.
217: * set it to null if you don't want to set mnemonic for this label.
218: * @param labelForComp the component for which the label is set
219: */
220: protected JLabel createLabel(String labelKey, String mnemonicKey,
221: Component labelForComp) {
222: JLabel label = new JLabel(tsBundle.getStringSafely(labelKey)
223: + ":");
224: label.setForeground(labelColor);
225: label.setAlignmentX(LEFT_ALIGNMENT);
226: label.setAlignmentY(TOP_ALIGNMENT);
227: //A11y
228: label.setLabelFor(labelForComp);
229: if (mnemonicKey != null) {
230: label.setDisplayedMnemonic(AccessiblityUtils
231: .getMnemonic(mnemonicKey));
232: }
233: return (label);
234: }
235:
236: public void createCompoundBorder(JPanel panel, String labelKey,
237: int top, int left, int bottom, int right) {
238: String label = this .tsBundle.getStringSafely(labelKey);
239: TitledBorder titledBorder = BorderFactory
240: .createTitledBorder(label);
241: titledBorder.setTitleColor(labelColor);
242: panel.setBorder(BorderFactory.createCompoundBorder(
243: titledBorder, BorderFactory.createEmptyBorder(top,
244: left, bottom, right)));
245: }
246:
247: public void setA11yFeatures() {
248: Font defaultFont = this .getFont();
249:
250: // set nmemonics for checkboxes radio buttons (only the 1st one in a component group)
251: detectConn.setMnemonic(AccessiblityUtils
252: .getMnemonic("Detect_Components"));
253: detectDisc.setMnemonic(AccessiblityUtils
254: .getMnemonic("Detect_Disconnected_Nodes"));
255: aspectRatioAutomaticRadioButton.setMnemonic(AccessiblityUtils
256: .getMnemonic("Automatic"));
257:
258: // set font to use the default font
259: detectConn.setFont(defaultFont);
260: detectDisc.setFont(defaultFont);
261: aspectRatioAutomaticRadioButton.setFont(defaultFont);
262: aspectRatioCustomRadioButton.setFont(defaultFont);
263:
264: // set accessibility name and descritpion
265: AccessiblityUtils.setAccessibleProperties(detectConn, null,
266: "Detect_Components");
267: AccessiblityUtils.setAccessibleProperties(detectDisc, null,
268: "Detect_Disconnected_Nodes");
269: AccessiblityUtils.setAccessibleProperties(
270: aspectRatioAutomaticRadioButton, null, "Automatic");
271: AccessiblityUtils.setAccessibleProperties(
272: aspectRatioCustomRadioButton, null, "Custom");
273:
274: AccessiblityUtils.setAccessibleProperties(
275: connConstantSpacingField, null, "Constant_Spacing");
276: AccessiblityUtils.setAccessibleProperties(
277: connProportionalSpacingField, null,
278: "Proportional_Spacing");
279: AccessiblityUtils.setAccessibleProperties(
280: discConstantSpacingField, null, "Constant_Spacing");
281: AccessiblityUtils.setAccessibleProperties(
282: discProportionalSpacingField, null,
283: "Proportional_Spacing");
284: AccessiblityUtils.setAccessibleProperties(
285: aspectRatioCustomField, "Aspect_Ratio_Custom",
286: "Aspect_Ratio_Custom");
287:
288: // set accessible description of the tab itself to be the same as the accesible name
289: this.getAccessibleContext().setAccessibleDescription(
290: this.getAccessibleContext().getAccessibleName());
291: }
292: }
|