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.ButtonGroup;
050: import javax.swing.JDialog;
051: import com.tomsawyer.service.TSServiceInputData;
052: import com.tomsawyer.editor.TSEGraph;
053: import java.awt.Dimension;
054: import javax.swing.BorderFactory;
055: import javax.swing.Box;
056: import javax.swing.JLabel;
057: import javax.swing.JPanel;
058: import javax.swing.border.TitledBorder;
059:
060: public class TSESymmetricTabExt extends TSESymmetricTab {
061: public static TSEResourceBundleWrapper tsBundle = TSEResourceBundleWrapper
062: .getSystemLabelBundle();
063:
064: /**
065: * This constructor creates a new Symmetric tab.
066: * @param
067: * graph the <code>TSEGraph</code> whose layout
068: * properties are being edited.
069: * @param
070: * inputData the service input data object where the
071: * layout options are stored
072: * @param
073: * dialog the Layout Properties dialog that this
074: * tab belongs to.
075: */
076: public TSESymmetricTabExt(TSEGraph graph,
077: TSServiceInputData inputData, JDialog dialog) {
078: super (graph, inputData, dialog);
079: setA11yFeatures();
080: }
081:
082: /**
083: * This method creates the Spacing Options panel of this tab.
084: */
085: protected JPanel makeSpacingOptionsPanel() {
086: JPanel panel = this .createBoxLayoutPanel(BoxLayout.X_AXIS);
087:
088: // Create the components
089: this .nodeSpacingField = this .createDoubleField(4, 0, 1000);
090: JLabel nodeSpacingLabel = this .createLabel("Node_Spacing",
091: "Node_Spacing", nodeSpacingField);
092:
093: // Layout the components
094: JPanel labels = this .createBoxLayoutPanel(BoxLayout.Y_AXIS);
095: labels.add(nodeSpacingLabel);
096:
097: JPanel fields = this .createBoxLayoutPanel(BoxLayout.Y_AXIS);
098: this .nodeSpacingField.setAlignmentX(RIGHT_ALIGNMENT);
099: fields.add(this .nodeSpacingField);
100:
101: panel.add(labels);
102: panel.add(Box.createRigidArea(new Dimension(20, 0)));
103: panel.add(fields);
104:
105: // Create a border
106: this .createCompoundBorder(panel, "Spacing_Options", 0, 5, 5, 5);
107:
108: return (panel);
109: }
110:
111: /**
112: * This method creates the Layout Quality Options panel of this tab.
113: */
114: protected JPanel makeLayoutQualityPanel() {
115: JPanel wrapperPanel = this
116: .createBoxLayoutPanel(BoxLayout.X_AXIS);
117: JPanel panel = this .createBoxLayoutPanel(BoxLayout.Y_AXIS);
118:
119: // create the components
120: this .qualityDraftRadioButton = this .createRadioButton("Draft");
121: this .qualityDefaultRadioButton = this
122: .createRadioButton("Default");
123: this .qualityProofRadioButton = this .createRadioButton("Proof");
124:
125: ButtonGroup buttonGroup = new ButtonGroup();
126:
127: buttonGroup.add(this .qualityDraftRadioButton);
128: buttonGroup.add(this .qualityDefaultRadioButton);
129: buttonGroup.add(this .qualityProofRadioButton);
130:
131: // add the components to the panel
132:
133: panel.add(this .qualityDraftRadioButton);
134: panel.add(Box.createRigidArea(new Dimension(0, 5)));
135: panel.add(this .qualityDefaultRadioButton);
136: panel.add(Box.createRigidArea(new Dimension(0, 5)));
137: panel.add(this .qualityProofRadioButton);
138:
139: wrapperPanel.add(panel);
140: wrapperPanel.add(Box.createRigidArea(new Dimension(30, 0)));
141:
142: this .createCompoundBorder(wrapperPanel, "Layout_Quality", 0, 5,
143: 5, 5);
144:
145: return wrapperPanel;
146: }
147:
148: /**
149: * This method creates a new JPanel and sets its layout manager to
150: * a BoxLayout with the input layout style.
151: */
152: protected JPanel createBoxLayoutPanel(int layout) {
153: JPanel panel = new JPanel();
154: panel.setLayout(new BoxLayout(panel, layout));
155: panel.setAlignmentX(LEFT_ALIGNMENT);
156: panel.setAlignmentY(TOP_ALIGNMENT);
157: return panel;
158: }
159:
160: /**
161: * This method creates a new <code>JLabel</code> with the given text
162: * @param labelKey the key for which the label text will be obtained from the resource bundle
163: * @param mnemonicKey the for which the mnemonic will be obtained from the resource bundle
164: * set it to null if you don't want to set mnemonic for this label.
165: * @param labelForComp the component for which the label is set
166: */
167: protected JLabel createLabel(String labelKey, String mnemonicKey,
168: Component labelForComp) {
169: JLabel label = new JLabel(tsBundle.getStringSafely(labelKey)
170: + ":");
171: label.setForeground(labelColor);
172: label.setAlignmentX(LEFT_ALIGNMENT);
173: label.setAlignmentY(TOP_ALIGNMENT);
174: //A11y
175: label.setLabelFor(labelForComp);
176: if (mnemonicKey != null) {
177: label.setDisplayedMnemonic(AccessiblityUtils
178: .getMnemonic(mnemonicKey));
179: }
180: return (label);
181: }
182:
183: public void createCompoundBorder(JPanel panel, String labelKey,
184: int top, int left, int bottom, int right) {
185: String label = this .tsBundle.getStringSafely(labelKey);
186: TitledBorder titledBorder = BorderFactory
187: .createTitledBorder(label);
188: titledBorder.setTitleColor(labelColor);
189: panel.setBorder(BorderFactory.createCompoundBorder(
190: titledBorder, BorderFactory.createEmptyBorder(top,
191: left, bottom, right)));
192: }
193:
194: //override the super method to to do nothing inorder to fix the component display issue with different fontsizes
195: protected int normalizeComponentDimensions(List compList,
196: boolean xDim, boolean yDim) {
197: return 0;
198: }
199:
200: public void setA11yFeatures() {
201: Font defaultFont = this .getFont();
202: // set nmemonics checkboxes
203: qualityDraftRadioButton.setMnemonic(AccessiblityUtils
204: .getMnemonic("Draft"));
205:
206: // set font to use the default font
207: qualityDraftRadioButton.setFont(defaultFont);
208: qualityDefaultRadioButton.setFont(defaultFont);
209: qualityProofRadioButton.setFont(defaultFont);
210:
211: // set accessibility name and descritpion
212: AccessiblityUtils.setAccessibleProperties(nodeSpacingField,
213: null, "Node_Spacing");
214: AccessiblityUtils.setAccessibleProperties(
215: qualityDraftRadioButton, null, "Draft");
216: AccessiblityUtils.setAccessibleProperties(
217: qualityDefaultRadioButton, null, "Default");
218: AccessiblityUtils.setAccessibleProperties(
219: qualityProofRadioButton, null, "Proof");
220:
221: this.getAccessibleContext().setAccessibleDescription(
222: this.getAccessibleContext().getAccessibleName());
223: }
224: }
|