1 6 7 package org.netbeans.modules.options.colors; 8 9 import java.awt.Component ; 10 import java.awt.GridLayout ; 11 import java.awt.event.ActionEvent ; 12 import java.awt.event.ActionListener ; 13 import java.awt.event.ItemEvent ; 14 import java.awt.event.ItemListener ; 15 import java.util.Collection ; 16 import java.util.Iterator ; 17 import javax.swing.AbstractButton ; 18 import javax.swing.JLabel ; 19 import javax.swing.JPanel ; 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 31 public class FontAndColorsPanel extends JPanel implements ActionListener { 32 33 34 private SyntaxColoringPanel syntaxColoringPanel; 35 private HighlightingPanel highlightingPanel; 36 private AnnotationsPanel annotationsPanel; 37 38 private ColorModel colorModel; 39 private String currentProfile; 40 private boolean listen = false; 41 42 43 44 public FontAndColorsPanel () { 45 initComponents (); 46 47 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 () { 60 public void itemStateChanged (ItemEvent evt) { 61 if (!listen) return; 62 setCurrentProfile ((String ) 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 83 private void initComponents() { 85 lProfile = new javax.swing.JLabel (); 86 cbProfile = new javax.swing.JComboBox (); 87 tpCustomizers = new javax.swing.JTabbedPane (); 88 bDuplicate = new javax.swing.JButton (); 89 bDelete = new javax.swing.JButton (); 90 91 lProfile.setText("Profile:"); 92 93 bDuplicate.setText("Duplicate..."); 94 95 bDelete.setText("Delete"); 96 bDelete.addActionListener(new java.awt.event.ActionListener () { 97 public void actionPerformed(java.awt.event.ActionEvent 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 [] {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 } 132 private void bDeleteActionPerformed (java.awt.event.ActionEvent evt) { } 136 137 private javax.swing.JButton bDelete; 139 private javax.swing.JButton bDuplicate; 140 private javax.swing.JComboBox cbProfile; 141 private javax.swing.JLabel lProfile; 142 private javax.swing.JTabbedPane tpCustomizers; 143 145 146 private void setCurrentProfile (String profile) { 147 if (colorModel.isCustomProfile (profile)) 148 loc (bDelete, "CTL_Delete"); else 150 loc (bDelete, "CTL_Restore"); currentProfile = profile; 152 highlightingPanel.setCurrentProfile (currentProfile); 153 syntaxColoringPanel.setCurrentProfile (currentProfile); 154 annotationsPanel.setCurrentProfile (currentProfile); 155 } 156 157 private void deleteCurrentProfile () { 158 String currentProfile = (String ) 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 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"); else 183 loc (bDelete, "CTL_Restore"); 185 listen = false; 187 Iterator 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 e) { 227 if (!listen) return; 228 if (e.getSource () == bDuplicate) { 229 InputLine il = new InputLine ( 230 loc ("CTL_Create_New_Profile_Message"), loc ("CTL_Create_New_Profile_Title") ); 233 il.setInputText (currentProfile); 234 DialogDisplayer.getDefault ().notify (il); 235 if (il.getValue () == NotifyDescriptor.OK_OPTION) { 236 String newScheme = il.getInputText (); 237 Iterator 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"), 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 getDefaults () { 262 return syntaxColoringPanel.getAllLanguages (); 263 } 264 265 Collection getHighlights () { 266 return highlightingPanel.getHighlightings (); 267 } 268 269 Collection getSyntaxColorings () { 270 return syntaxColoringPanel.getSyntaxColorings (); 271 } 272 273 private static String loc (String key) { 274 return NbBundle.getMessage (FontAndColorsPanel.class, key); 275 } 276 277 private static void loc (Component c, String key) { 278 if (c instanceof AbstractButton ) 279 Mnemonics.setLocalizedText ( 280 (AbstractButton ) c, 281 loc (key) 282 ); 283 else 284 Mnemonics.setLocalizedText ( 285 (JLabel ) c, 286 loc (key) 287 ); 288 } 289 } 290 | Popular Tags |