KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > wizards > shortcut > IntroPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.tools.ant.module.wizards.shortcut;
21
22 import java.awt.Component JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Set JavaDoc;
25 import javax.swing.event.ChangeEvent JavaDoc;
26 import javax.swing.event.ChangeListener JavaDoc;
27 import org.openide.WizardDescriptor;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30
31 final class IntroPanel extends javax.swing.JPanel JavaDoc {
32
33     private IntroWizardPanel wiz;
34
35     /** Create the wizard panel component and set up some basic properties. */
36     public IntroPanel (IntroWizardPanel wiz) {
37         this.wiz = wiz;
38         initComponents ();
39         initAccessibility();
40         // Provide a name in the title bar.
41
setName (NbBundle.getMessage (IntroPanel.class, "IP_LBL_cfg_basic_opts"));
42     }
43
44     // --- VISUAL DESIGN OF PANEL ---
45

46     @Override JavaDoc
47     public void requestFocus () {
48         super.requestFocus ();
49         customizeCheck.requestFocus ();
50     }
51
52     
53     private void initAccessibility () {
54         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(IntroPanel.class, "IP_TEXT_select_how_to_install_shortcut"));
55         menuCheck.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(IntroPanel.class, "ACS_IP_LBL_add_menu_item"));
56         toolbarCheck.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(IntroPanel.class, "ACS_IP_LBL_add_toolbar_button"));
57         keyboardCheck.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(IntroPanel.class, "ACS_IP_LBL_add_kbd_shortcut"));
58         customizeCheck.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(IntroPanel.class, "ACS_IP_LBL_cust_code_checkbox"));
59     }
60     
61     /** This method is called from within the constructor to
62      * initialize the form.
63      * WARNING: Do NOT modify this code. The content of this method is
64      * always regenerated by the Form Editor.
65      */

66     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
67
private void initComponents() {
68         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
69
70         customizeCheck = new javax.swing.JCheckBox JavaDoc();
71         menuCheck = new javax.swing.JCheckBox JavaDoc();
72         toolbarCheck = new javax.swing.JCheckBox JavaDoc();
73         keyboardCheck = new javax.swing.JCheckBox JavaDoc();
74         hintsArea = new javax.swing.JTextArea JavaDoc();
75
76         setLayout(new java.awt.GridBagLayout JavaDoc());
77
78         org.openide.awt.Mnemonics.setLocalizedText(customizeCheck, NbBundle.getMessage(IntroPanel.class, "IP_LBL_cust_code_checkbox")); // NOI18N
79
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
80         gridBagConstraints.gridx = 0;
81         gridBagConstraints.gridy = 4;
82         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
83         gridBagConstraints.weighty = 1.0;
84         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
85         add(customizeCheck, gridBagConstraints);
86
87         org.openide.awt.Mnemonics.setLocalizedText(menuCheck, NbBundle.getMessage(IntroPanel.class, "IP_LBL_add_menu_item")); // NOI18N
88
menuCheck.addActionListener(new java.awt.event.ActionListener JavaDoc() {
89             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
90                 someCheckboxClicked(evt);
91             }
92         });
93         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
94         gridBagConstraints.gridx = 0;
95         gridBagConstraints.gridy = 1;
96         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
98         add(menuCheck, gridBagConstraints);
99
100         org.openide.awt.Mnemonics.setLocalizedText(toolbarCheck, NbBundle.getMessage(IntroPanel.class, "IP_LBL_add_toolbar_button")); // NOI18N
101
toolbarCheck.addActionListener(new java.awt.event.ActionListener JavaDoc() {
102             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
103                 someCheckboxClicked(evt);
104             }
105         });
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridx = 0;
108         gridBagConstraints.gridy = 2;
109         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
110         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
111         add(toolbarCheck, gridBagConstraints);
112
113         org.openide.awt.Mnemonics.setLocalizedText(keyboardCheck, NbBundle.getMessage(IntroPanel.class, "IP_LBL_add_kbd_shortcut")); // NOI18N
114
keyboardCheck.addActionListener(new java.awt.event.ActionListener JavaDoc() {
115             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
116                 someCheckboxClicked(evt);
117             }
118         });
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridx = 0;
121         gridBagConstraints.gridy = 3;
122         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
123         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
124         add(keyboardCheck, gridBagConstraints);
125
126         hintsArea.setEditable(false);
127         hintsArea.setFont(javax.swing.UIManager.getFont ("Label.font"));
128         hintsArea.setText(NbBundle.getMessage(IntroPanel.class, "IP_TEXT_select_how_to_install_shortcut")); // NOI18N
129
hintsArea.setBackground(new java.awt.Color JavaDoc(204, 204, 204));
130         hintsArea.setLineWrap(true);
131         hintsArea.setForeground(new java.awt.Color JavaDoc(102, 102, 153));
132         hintsArea.setWrapStyleWord(true);
133         hintsArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground"));
134         hintsArea.setOpaque(false);
135         hintsArea.setEnabled(false);
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridx = 0;
138         gridBagConstraints.gridy = 0;
139         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140         gridBagConstraints.weightx = 1.0;
141         add(hintsArea, gridBagConstraints);
142     }// </editor-fold>//GEN-END:initComponents
143

144     private void someCheckboxClicked (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_someCheckboxClicked
145
wiz.fireChangeEvent ();
146     }//GEN-LAST:event_someCheckboxClicked
147

148     // Variables declaration - do not modify//GEN-BEGIN:variables
149
private javax.swing.JCheckBox JavaDoc customizeCheck;
150     private javax.swing.JTextArea JavaDoc hintsArea;
151     private javax.swing.JCheckBox JavaDoc keyboardCheck;
152     private javax.swing.JCheckBox JavaDoc menuCheck;
153     private javax.swing.JCheckBox JavaDoc toolbarCheck;
154     // End of variables declaration//GEN-END:variables
155

156     public static class IntroWizardPanel implements WizardDescriptor.Panel {
157     
158         private IntroPanel panel = null;
159         private ShortcutWizard wiz = null;
160         
161         public void initialize(ShortcutWizard wiz) {
162             this.wiz = wiz;
163         }
164         
165         public Component JavaDoc getComponent () {
166             return getPanel();
167         }
168         
169         private IntroPanel getPanel() {
170             if (panel == null) {
171                 panel = new IntroPanel(this);
172             }
173             return panel;
174         }
175
176         public HelpCtx getHelp () {
177             return HelpCtx.DEFAULT_HELP;
178         }
179
180         public boolean isValid () {
181             return getPanel().menuCheck.isSelected () ||
182                    getPanel().toolbarCheck.isSelected () ||
183                    getPanel().keyboardCheck.isSelected ();
184         }
185
186         private final Set JavaDoc<ChangeListener JavaDoc> listeners = new HashSet JavaDoc<ChangeListener JavaDoc>(1);
187         public final void addChangeListener (ChangeListener JavaDoc l) {
188             synchronized (listeners) {
189                 listeners.add (l);
190             }
191         }
192         public final void removeChangeListener (ChangeListener JavaDoc l) {
193             synchronized (listeners) {
194                 listeners.remove (l);
195             }
196         }
197         protected final void fireChangeEvent () {
198             // #44409: need to update the PROP_SHOW_* flags before storeSettings is called,
199
// because then it will be too late (iterator will already have progressed):
200
// XXX workaround should no longer be necessary...
201
storeSettings(wiz);
202             ChangeListener JavaDoc[] ls;
203             synchronized (listeners) {
204                 ls = listeners.toArray(new ChangeListener JavaDoc[listeners.size()]);
205             }
206             ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc (this);
207             for (ChangeListener JavaDoc l : ls) {
208                 l.stateChanged (ev);
209             }
210         }
211
212         public void readSettings (Object JavaDoc settings) {
213             // XXX should read checkboxes from settings... skip for now.
214
}
215         public void storeSettings (Object JavaDoc settings) {
216             WizardDescriptor wiz = (WizardDescriptor) settings;
217             wiz.putProperty(ShortcutWizard.PROP_SHOW_CUST, getPanel().customizeCheck.isSelected() ? Boolean.TRUE : Boolean.FALSE);
218             wiz.putProperty(ShortcutWizard.PROP_SHOW_MENU, getPanel().menuCheck.isSelected() ? Boolean.TRUE : Boolean.FALSE);
219             wiz.putProperty(ShortcutWizard.PROP_SHOW_TOOL, getPanel().toolbarCheck.isSelected() ? Boolean.TRUE : Boolean.FALSE);
220             wiz.putProperty(ShortcutWizard.PROP_SHOW_KEYB, getPanel().keyboardCheck.isSelected() ? Boolean.TRUE : Boolean.FALSE);
221         }
222     }
223
224 }
225
Popular Tags