KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > options > colors > FontAndColorsPanel


1 /*
2  * FontAndColorsPanel1.java
3  *
4  * Created on January 18, 2006, 2:12 PM
5  */

6
7 package org.netbeans.modules.options.colors;
8
9 import java.awt.Component JavaDoc;
10 import java.awt.GridLayout JavaDoc;
11 import java.awt.event.ActionEvent JavaDoc;
12 import java.awt.event.ActionListener JavaDoc;
13 import java.awt.event.ItemEvent JavaDoc;
14 import java.awt.event.ItemListener JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import javax.swing.AbstractButton JavaDoc;
18 import javax.swing.JLabel JavaDoc;
19 import javax.swing.JPanel JavaDoc;
20 import org.openide.DialogDisplayer;
21 import org.openide.NotifyDescriptor;
22 import org.openide.NotifyDescriptor.InputLine;
23 import org.openide.NotifyDescriptor.Message;
24 import org.openide.awt.Mnemonics;
25 import org.openide.util.NbBundle;
26
27 /**
28  *
29  * @author Jan Jancura
30  */

31 public class FontAndColorsPanel extends JPanel JavaDoc implements ActionListener JavaDoc {
32     
33     
34     private SyntaxColoringPanel syntaxColoringPanel;
35     private HighlightingPanel highlightingPanel;
36     private AnnotationsPanel annotationsPanel;
37
38     private ColorModel colorModel;
39     private String JavaDoc currentProfile;
40     private boolean listen = false;
41     
42     
43     /** Creates new form FontAndColorsPanel1 */
44     public FontAndColorsPanel () {
45         initComponents ();
46         
47         // init components
48
cbProfile.getAccessibleContext ().setAccessibleName (loc ("AN_Profiles"));
49         cbProfile.getAccessibleContext ().setAccessibleDescription (loc ("AD_Profiles"));
50         bDelete.getAccessibleContext ().setAccessibleName (loc ("AN_Delete"));
51         bDelete.getAccessibleContext ().setAccessibleDescription (loc ("AD_Delete"));
52         bDuplicate.getAccessibleContext ().setAccessibleName (loc ("AN_Clone"));
53         bDuplicate.getAccessibleContext ().setAccessibleDescription (loc ("AD_Clone"));
54         tpCustomizers.getAccessibleContext ().setAccessibleName (loc ("AN_Categories"));
55         tpCustomizers.getAccessibleContext ().setAccessibleDescription (loc ("AD_Categories"));
56         syntaxColoringPanel = new SyntaxColoringPanel (this);
57         highlightingPanel = new HighlightingPanel ();
58         annotationsPanel = new AnnotationsPanel ();
59         cbProfile.addItemListener (new ItemListener JavaDoc () {
60             public void itemStateChanged (ItemEvent JavaDoc evt) {
61                 if (!listen) return;
62                 setCurrentProfile ((String JavaDoc) cbProfile.getSelectedItem ());
63             }
64         });
65         loc (bDuplicate, "CTL_Create_New");
66         bDuplicate.addActionListener (this);
67         loc (bDelete, "CTL_Delete");
68         bDelete.addActionListener (this);
69         
70     tpCustomizers.addTab (loc ("Syntax_coloring_tab"), syntaxColoringPanel);
71     tpCustomizers.addTab (loc ("Editor_tab"), highlightingPanel);
72     tpCustomizers.addTab (loc ("Annotations_tab"), annotationsPanel);
73         tpCustomizers.setMnemonicAt (0, loc ("Syntax_coloring_tab_mnemonic").charAt (0));
74         tpCustomizers.setMnemonicAt (1, loc ("Editor_tab_mnemonic").charAt (0));
75         tpCustomizers.setMnemonicAt (2, loc ("Annotations_tab_mnemonic").charAt (0));
76     }
77     
78     /** This method is called from within the constructor to
79      * initialize the form.
80      * WARNING: Do NOT modify this code. The content of this method is
81      * always regenerated by the Form Editor.
82      */

83     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
84
private void initComponents() {
85         lProfile = new javax.swing.JLabel JavaDoc();
86         cbProfile = new javax.swing.JComboBox JavaDoc();
87         tpCustomizers = new javax.swing.JTabbedPane JavaDoc();
88         bDuplicate = new javax.swing.JButton JavaDoc();
89         bDelete = new javax.swing.JButton JavaDoc();
90
91         lProfile.setText("Profile:");
92
93         bDuplicate.setText("Duplicate...");
94
95         bDelete.setText("Delete");
96         bDelete.addActionListener(new java.awt.event.ActionListener JavaDoc() {
97             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
98                 bDeleteActionPerformed(evt);
99             }
100         });
101
102         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
103         this.setLayout(layout);
104         layout.setHorizontalGroup(
105             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
106             .add(layout.createSequentialGroup()
107                 .add(lProfile)
108                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
109                 .add(cbProfile, 0, 195, Short.MAX_VALUE)
110                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
111                 .add(bDuplicate)
112                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
113                 .add(bDelete))
114             .add(tpCustomizers, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
115         );
116
117         layout.linkSize(new java.awt.Component JavaDoc[] {bDelete, bDuplicate}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
118
119         layout.setVerticalGroup(
120             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
121             .add(layout.createSequentialGroup()
122                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
123                     .add(lProfile)
124                     .add(bDelete)
125                     .add(bDuplicate)
126                     .add(cbProfile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
127                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
128                 .add(tpCustomizers, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE))
129         );
130     }// </editor-fold>//GEN-END:initComponents
131

132     private void bDeleteActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_bDeleteActionPerformed
133
// TODO add your handling code here:
134
}//GEN-LAST:event_bDeleteActionPerformed
135

136     
137     // Variables declaration - do not modify//GEN-BEGIN:variables
138
private javax.swing.JButton JavaDoc bDelete;
139     private javax.swing.JButton JavaDoc bDuplicate;
140     private javax.swing.JComboBox JavaDoc cbProfile;
141     private javax.swing.JLabel JavaDoc lProfile;
142     private javax.swing.JTabbedPane JavaDoc tpCustomizers;
143     // End of variables declaration//GEN-END:variables
144

145     
146     private void setCurrentProfile (String JavaDoc profile) {
147         if (colorModel.isCustomProfile (profile))
148             loc (bDelete, "CTL_Delete"); // NOI18N
149
else
150             loc (bDelete, "CTL_Restore"); // NOI18N
151
currentProfile = profile;
152         highlightingPanel.setCurrentProfile (currentProfile);
153         syntaxColoringPanel.setCurrentProfile (currentProfile);
154         annotationsPanel.setCurrentProfile (currentProfile);
155     }
156     
157     private void deleteCurrentProfile () {
158         String JavaDoc currentProfile = (String JavaDoc) cbProfile.getSelectedItem ();
159         highlightingPanel.deleteProfile (currentProfile);
160         syntaxColoringPanel.deleteProfile (currentProfile);
161         annotationsPanel.deleteProfile (currentProfile);
162         if (colorModel.isCustomProfile (currentProfile)) {
163             cbProfile.removeItem (currentProfile);
164             cbProfile.setSelectedIndex (0);
165         }
166     }
167     
168     
169     // other methods ...........................................................
170

171     void update () {
172         if (colorModel == null)
173             colorModel = new ColorModel ();
174         
175         highlightingPanel.update (colorModel);
176         syntaxColoringPanel.update (colorModel);
177         annotationsPanel.update (colorModel);
178         
179         currentProfile = colorModel.getCurrentProfile ();
180         if (colorModel.isCustomProfile (currentProfile))
181             loc (bDelete, "CTL_Delete"); // NOI18N
182
else
183             loc (bDelete, "CTL_Restore"); // NOI18N
184

185         // init schemes
186
listen = false;
187         Iterator JavaDoc it = colorModel.getProfiles ().iterator ();
188         cbProfile.removeAllItems ();
189         while (it.hasNext ())
190             cbProfile.addItem (it.next ());
191         listen = true;
192         cbProfile.setSelectedItem (currentProfile);
193     }
194     
195     
196     
197     void applyChanges () {
198         highlightingPanel.applyChanges ();
199         syntaxColoringPanel.applyChanges ();
200         annotationsPanel.applyChanges ();
201         if (colorModel == null) return;
202         colorModel.setCurrentProfile (currentProfile);
203     }
204     
205     void cancel () {
206         highlightingPanel.cancel ();
207         syntaxColoringPanel.cancel ();
208         annotationsPanel.cancel ();
209     }
210     
211     boolean dataValid () {
212         return true;
213     }
214     
215     boolean isChanged () {
216         if (currentProfile != null &&
217             colorModel != null &&
218             !currentProfile.equals (colorModel.getCurrentProfile ())
219         ) return true;
220         if (highlightingPanel.isChanged ()) return true;
221         if (syntaxColoringPanel.isChanged ()) return true;
222         if (annotationsPanel.isChanged ()) return true;
223         return false;
224     }
225    
226     public void actionPerformed (ActionEvent JavaDoc e) {
227         if (!listen) return;
228         if (e.getSource () == bDuplicate) {
229             InputLine il = new InputLine (
230                 loc ("CTL_Create_New_Profile_Message"), // NOI18N
231
loc ("CTL_Create_New_Profile_Title") // NOI18N
232
);
233             il.setInputText (currentProfile);
234             DialogDisplayer.getDefault ().notify (il);
235             if (il.getValue () == NotifyDescriptor.OK_OPTION) {
236                 String JavaDoc newScheme = il.getInputText ();
237                 Iterator JavaDoc it = colorModel.getProfiles ().iterator ();
238                 while (it.hasNext ())
239                     if (newScheme.equals (it.next ())) {
240                         Message md = new Message (
241                             loc ("CTL_Duplicate_Profile_Name"), // NOI18N
242
Message.ERROR_MESSAGE
243                         );
244                         DialogDisplayer.getDefault ().notify (md);
245                         return;
246                     }
247                 setCurrentProfile (newScheme);
248                 listen = false;
249                 cbProfile.addItem (il.getInputText ());
250                 cbProfile.setSelectedItem (il.getInputText ());
251                 listen = true;
252             }
253             return;
254         }
255         if (e.getSource () == bDelete) {
256             deleteCurrentProfile ();
257             return;
258         }
259     }
260     
261     Collection JavaDoc getDefaults () {
262         return syntaxColoringPanel.getAllLanguages ();
263     }
264     
265     Collection JavaDoc getHighlights () {
266         return highlightingPanel.getHighlightings ();
267     }
268     
269     Collection JavaDoc getSyntaxColorings () {
270         return syntaxColoringPanel.getSyntaxColorings ();
271     }
272     
273     private static String JavaDoc loc (String JavaDoc key) {
274         return NbBundle.getMessage (FontAndColorsPanel.class, key);
275     }
276     
277     private static void loc (Component JavaDoc c, String JavaDoc key) {
278         if (c instanceof AbstractButton JavaDoc)
279             Mnemonics.setLocalizedText (
280                 (AbstractButton JavaDoc) c,
281                 loc (key)
282             );
283         else
284             Mnemonics.setLocalizedText (
285                 (JLabel JavaDoc) c,
286                 loc (key)
287             );
288     }
289 }
290
Popular Tags