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-2006 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 org.apache.tools.ant.module.wizards.shortcut;
043:
044: import java.awt.Component;
045: import javax.swing.event.ChangeListener;
046: import org.openide.WizardDescriptor;
047: import org.openide.util.ChangeSupport;
048: import org.openide.util.HelpCtx;
049: import org.openide.util.NbBundle;
050:
051: final class IntroPanel extends javax.swing.JPanel {
052:
053: private IntroWizardPanel wiz;
054:
055: /** Create the wizard panel component and set up some basic properties. */
056: public IntroPanel(IntroWizardPanel wiz) {
057: this .wiz = wiz;
058: initComponents();
059: initAccessibility();
060: // Provide a name in the title bar.
061: setName(NbBundle.getMessage(IntroPanel.class,
062: "IP_LBL_cfg_basic_opts"));
063: }
064:
065: // --- VISUAL DESIGN OF PANEL ---
066:
067: @Override
068: public void requestFocus() {
069: super .requestFocus();
070: customizeCheck.requestFocus();
071: }
072:
073: private void initAccessibility() {
074: this .getAccessibleContext().setAccessibleDescription(
075: NbBundle.getMessage(IntroPanel.class,
076: "IP_TEXT_select_how_to_install_shortcut"));
077: menuCheck.getAccessibleContext().setAccessibleDescription(
078: NbBundle.getMessage(IntroPanel.class,
079: "ACS_IP_LBL_add_menu_item"));
080: toolbarCheck.getAccessibleContext().setAccessibleDescription(
081: NbBundle.getMessage(IntroPanel.class,
082: "ACS_IP_LBL_add_toolbar_button"));
083: keyboardCheck.getAccessibleContext().setAccessibleDescription(
084: NbBundle.getMessage(IntroPanel.class,
085: "ACS_IP_LBL_add_kbd_shortcut"));
086: customizeCheck.getAccessibleContext().setAccessibleDescription(
087: NbBundle.getMessage(IntroPanel.class,
088: "ACS_IP_LBL_cust_code_checkbox"));
089: }
090:
091: /** This method is called from within the constructor to
092: * initialize the form.
093: * WARNING: Do NOT modify this code. The content of this method is
094: * always regenerated by the Form Editor.
095: */
096: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
097: private void initComponents() {
098: java.awt.GridBagConstraints gridBagConstraints;
099:
100: customizeCheck = new javax.swing.JCheckBox();
101: menuCheck = new javax.swing.JCheckBox();
102: toolbarCheck = new javax.swing.JCheckBox();
103: keyboardCheck = new javax.swing.JCheckBox();
104: hintsArea = new javax.swing.JTextArea();
105:
106: setLayout(new java.awt.GridBagLayout());
107:
108: org.openide.awt.Mnemonics.setLocalizedText(customizeCheck,
109: NbBundle.getMessage(IntroPanel.class,
110: "IP_LBL_cust_code_checkbox")); // NOI18N
111: gridBagConstraints = new java.awt.GridBagConstraints();
112: gridBagConstraints.gridx = 0;
113: gridBagConstraints.gridy = 4;
114: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
115: gridBagConstraints.weighty = 1.0;
116: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
117: add(customizeCheck, gridBagConstraints);
118:
119: org.openide.awt.Mnemonics.setLocalizedText(menuCheck, NbBundle
120: .getMessage(IntroPanel.class, "IP_LBL_add_menu_item")); // NOI18N
121: menuCheck
122: .addActionListener(new java.awt.event.ActionListener() {
123: public void actionPerformed(
124: java.awt.event.ActionEvent evt) {
125: someCheckboxClicked(evt);
126: }
127: });
128: gridBagConstraints = new java.awt.GridBagConstraints();
129: gridBagConstraints.gridx = 0;
130: gridBagConstraints.gridy = 1;
131: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
132: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
133: add(menuCheck, gridBagConstraints);
134:
135: org.openide.awt.Mnemonics.setLocalizedText(toolbarCheck,
136: NbBundle.getMessage(IntroPanel.class,
137: "IP_LBL_add_toolbar_button")); // NOI18N
138: toolbarCheck
139: .addActionListener(new java.awt.event.ActionListener() {
140: public void actionPerformed(
141: java.awt.event.ActionEvent evt) {
142: someCheckboxClicked(evt);
143: }
144: });
145: gridBagConstraints = new java.awt.GridBagConstraints();
146: gridBagConstraints.gridx = 0;
147: gridBagConstraints.gridy = 2;
148: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
149: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
150: add(toolbarCheck, gridBagConstraints);
151:
152: org.openide.awt.Mnemonics.setLocalizedText(keyboardCheck,
153: NbBundle.getMessage(IntroPanel.class,
154: "IP_LBL_add_kbd_shortcut")); // NOI18N
155: keyboardCheck
156: .addActionListener(new java.awt.event.ActionListener() {
157: public void actionPerformed(
158: java.awt.event.ActionEvent evt) {
159: someCheckboxClicked(evt);
160: }
161: });
162: gridBagConstraints = new java.awt.GridBagConstraints();
163: gridBagConstraints.gridx = 0;
164: gridBagConstraints.gridy = 3;
165: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
166: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
167: add(keyboardCheck, gridBagConstraints);
168:
169: hintsArea.setEditable(false);
170: hintsArea.setFont(javax.swing.UIManager.getFont("Label.font"));
171: hintsArea.setText(NbBundle.getMessage(IntroPanel.class,
172: "IP_TEXT_select_how_to_install_shortcut")); // NOI18N
173: hintsArea.setBackground(new java.awt.Color(204, 204, 204));
174: hintsArea.setLineWrap(true);
175: hintsArea.setForeground(new java.awt.Color(102, 102, 153));
176: hintsArea.setWrapStyleWord(true);
177: hintsArea.setDisabledTextColor(javax.swing.UIManager
178: .getColor("Label.foreground"));
179: hintsArea.setOpaque(false);
180: hintsArea.setEnabled(false);
181: gridBagConstraints = new java.awt.GridBagConstraints();
182: gridBagConstraints.gridx = 0;
183: gridBagConstraints.gridy = 0;
184: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
185: gridBagConstraints.weightx = 1.0;
186: add(hintsArea, gridBagConstraints);
187: }// </editor-fold>//GEN-END:initComponents
188:
189: private void someCheckboxClicked(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_someCheckboxClicked
190: wiz.fireChangeEvent();
191: }//GEN-LAST:event_someCheckboxClicked
192:
193: // Variables declaration - do not modify//GEN-BEGIN:variables
194: private javax.swing.JCheckBox customizeCheck;
195: private javax.swing.JTextArea hintsArea;
196: private javax.swing.JCheckBox keyboardCheck;
197: private javax.swing.JCheckBox menuCheck;
198: private javax.swing.JCheckBox toolbarCheck;
199:
200: // End of variables declaration//GEN-END:variables
201:
202: public static class IntroWizardPanel implements
203: WizardDescriptor.Panel<ShortcutWizard> {
204:
205: private IntroPanel panel = null;
206: private ShortcutWizard wiz = null;
207:
208: public void initialize(ShortcutWizard wiz) {
209: this .wiz = wiz;
210: }
211:
212: public Component getComponent() {
213: return getPanel();
214: }
215:
216: private IntroPanel getPanel() {
217: if (panel == null) {
218: panel = new IntroPanel(this );
219: }
220: return panel;
221: }
222:
223: public HelpCtx getHelp() {
224: return HelpCtx.DEFAULT_HELP;
225: }
226:
227: public boolean isValid() {
228: return getPanel().menuCheck.isSelected()
229: || getPanel().toolbarCheck.isSelected()
230: || getPanel().keyboardCheck.isSelected();
231: }
232:
233: private final ChangeSupport cs = new ChangeSupport(this );
234:
235: public final void addChangeListener(ChangeListener l) {
236: cs.addChangeListener(l);
237: }
238:
239: public final void removeChangeListener(ChangeListener l) {
240: cs.removeChangeListener(l);
241: }
242:
243: protected final void fireChangeEvent() {
244: // #44409: need to update the PROP_SHOW_* flags before storeSettings is called,
245: // because then it will be too late (iterator will already have progressed):
246: // XXX workaround should no longer be necessary...
247: storeSettings(wiz);
248: cs.fireChange();
249: }
250:
251: public void readSettings(ShortcutWizard wiz) {
252: getPanel().customizeCheck
253: .setSelected(flag(ShortcutWizard.PROP_SHOW_CUST));
254: getPanel().menuCheck
255: .setSelected(flag(ShortcutWizard.PROP_SHOW_MENU));
256: getPanel().toolbarCheck
257: .setSelected(flag(ShortcutWizard.PROP_SHOW_TOOL));
258: getPanel().keyboardCheck
259: .setSelected(flag(ShortcutWizard.PROP_SHOW_KEYB));
260: }
261:
262: private boolean flag(String prop) {
263: Boolean val = (Boolean) wiz
264: .getProperty(ShortcutWizard.PROP_SHOW_KEYB);
265: return val != null ? val : false;
266: }
267:
268: public void storeSettings(ShortcutWizard wiz) {
269: wiz
270: .putProperty(
271: ShortcutWizard.PROP_SHOW_CUST,
272: getPanel().customizeCheck.isSelected() ? Boolean.TRUE
273: : Boolean.FALSE);
274: wiz.putProperty(ShortcutWizard.PROP_SHOW_MENU,
275: getPanel().menuCheck.isSelected() ? Boolean.TRUE
276: : Boolean.FALSE);
277: wiz.putProperty(ShortcutWizard.PROP_SHOW_TOOL,
278: getPanel().toolbarCheck.isSelected() ? Boolean.TRUE
279: : Boolean.FALSE);
280: wiz
281: .putProperty(
282: ShortcutWizard.PROP_SHOW_KEYB,
283: getPanel().keyboardCheck.isSelected() ? Boolean.TRUE
284: : Boolean.FALSE);
285: }
286: }
287:
288: }
|