~ubuntu-branches/ubuntu/trusty/netbeans/trusty

« back to all changes in this revision

Viewing changes to editor/options/src/org/netbeans/modules/options/colors/SyntaxColoringPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
package org.netbeans.modules.options.colors;
 
43
 
 
44
import org.netbeans.modules.options.colors.spi.FontsColorsController;
 
45
import java.awt.Color;
 
46
import java.awt.Component;
 
47
import java.awt.Font;
 
48
import java.awt.Insets;
 
49
import java.awt.event.ActionEvent;
 
50
import java.awt.event.ActionListener;
 
51
import java.beans.PropertyChangeEvent;
 
52
import java.beans.PropertyChangeListener;
 
53
import java.beans.PropertyEditor;
 
54
import java.beans.PropertyEditorManager;
 
55
import java.util.ArrayList;
 
56
import java.util.Collection;
 
57
import java.util.Collections;
 
58
import java.util.Comparator;
 
59
import java.util.HashMap;
 
60
import java.util.HashSet;
 
61
import java.util.Iterator;
 
62
import java.util.List;
 
63
import java.util.Map;
 
64
import java.util.Set;
 
65
import java.util.Vector;
 
66
import javax.swing.AbstractButton;
 
67
import javax.swing.JComboBox;
 
68
import javax.swing.JComponent;
 
69
import javax.swing.JLabel;
 
70
import javax.swing.JPanel;
 
71
import javax.swing.ListSelectionModel;
 
72
import javax.swing.UIManager;
 
73
import javax.swing.event.ListSelectionEvent;
 
74
import javax.swing.event.ListSelectionListener;
 
75
import javax.swing.text.AttributeSet;
 
76
import javax.swing.text.SimpleAttributeSet;
 
77
import javax.swing.text.StyleConstants;
 
78
import org.netbeans.api.editor.settings.EditorStyleConstants;
 
79
import org.netbeans.modules.options.colors.ColorModel.Preview;
 
80
import org.openide.DialogDescriptor;
 
81
import org.openide.DialogDisplayer;
 
82
import org.openide.awt.Mnemonics;
 
83
import org.openide.util.NbBundle;
 
84
import org.openide.util.RequestProcessor;
 
85
import org.openide.util.RequestProcessor.Task;
 
86
 
 
87
/**
 
88
 *
 
89
 * @author  Jan Jancura
 
90
 */
 
91
public class SyntaxColoringPanel extends JPanel implements ActionListener, 
 
92
    PropertyChangeListener, FontsColorsController {
 
93
    
 
94
    
 
95
    private Preview             preview;
 
96
    private Task                selectTask;
 
97
    private ColorModel          colorModel = null;
 
98
    private String              currentLanguage;
 
99
    private String              currentProfile;
 
100
    /** cache Map (String (profile name) > Map (String (language name) > Vector (AttributeSet))). */
 
101
    private Map<String, Map<String, Vector<AttributeSet>>> profiles = new HashMap<String, Map<String, Vector<AttributeSet>>>();
 
102
    /** Map (String (profile name) > Set (String (language name))) of names of changed languages. */
 
103
    private Map<String, Set<String>> toBeSaved = new HashMap<String, Set<String>>();
 
104
    private boolean             listen = false;
 
105
    
 
106
    /** Creates new form SyntaxColoringPanel1 */
 
107
    public SyntaxColoringPanel () {
 
108
        initComponents ();
 
109
 
 
110
        setName(loc("Syntax_coloring_tab")); //NOI18N
 
111
        // 1) init components
 
112
        cbLanguage.getAccessibleContext ().setAccessibleName (loc ("AN_Languages"));
 
113
        cbLanguage.getAccessibleContext ().setAccessibleDescription (loc ("AD_Languages"));
 
114
        lCategories.getAccessibleContext ().setAccessibleName (loc ("AN_Categories"));
 
115
        lCategories.getAccessibleContext ().setAccessibleDescription (loc ("AD_Categories"));
 
116
        bFont.getAccessibleContext ().setAccessibleName (loc ("AN_Font"));
 
117
        bFont.getAccessibleContext ().setAccessibleDescription (loc ("AD_Font"));
 
118
        cbForeground.getAccessibleContext ().setAccessibleName (loc ("AN_Foreground_Chooser"));
 
119
        cbForeground.getAccessibleContext ().setAccessibleDescription (loc ("AD_Foreground_Chooser"));
 
120
//        bForeground.getAccessibleContext ().setAccessibleName (loc ("AN_Foreground"));
 
121
//        bForeground.getAccessibleContext ().setAccessibleDescription (loc ("AD_Foreground"));
 
122
        cbBackground.getAccessibleContext ().setAccessibleName (loc ("AN_Background_Chooser"));
 
123
        cbBackground.getAccessibleContext ().setAccessibleDescription (loc ("AD_Background_Chooser"));
 
124
//        bBackground.getAccessibleContext ().setAccessibleName (loc ("AN_Background"));
 
125
//        bBackground.getAccessibleContext ().setAccessibleDescription (loc ("AD_Background"));
 
126
        cbEffects.getAccessibleContext ().setAccessibleName (loc ("AN_Efects_Color_Chooser"));
 
127
        cbEffects.getAccessibleContext ().setAccessibleDescription (loc ("AD_Efects_Color_Chooser"));
 
128
        cbEffectColor.getAccessibleContext ().setAccessibleName (loc ("AN_Efects_Color"));
 
129
        cbEffectColor.getAccessibleContext ().setAccessibleDescription (loc ("AD_Efects_Color"));
 
130
        ColorComboBox.init (cbBackground);
 
131
        ColorComboBox.init (cbForeground);
 
132
        ColorComboBox.init (cbEffectColor);
 
133
        cbLanguage.addActionListener (this);
 
134
        lCategories.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
 
135
        lCategories.setVisibleRowCount (3);
 
136
        lCategories.setCellRenderer (new CategoryRenderer ());
 
137
        lCategories.addListSelectionListener (new ListSelectionListener () {
 
138
            public void valueChanged (ListSelectionEvent e) {
 
139
                if (!listen) return;
 
140
                selectTask.schedule (200);
 
141
            }
 
142
        });
 
143
        tfFont.setEditable (false);
 
144
        bFont.addActionListener (this);
 
145
        bFont.setMargin (new Insets (0, 0, 0, 0));
 
146
//        bForeground.addActionListener (this);
 
147
//        bForeground.setMargin (new Insets (0, 0, 0, 0));
 
148
//        bBackground.addActionListener (this);
 
149
//        bBackground.setMargin (new Insets (0, 0, 0, 0));
 
150
        cbForeground.addActionListener (this);
 
151
        ((JComponent)cbForeground.getEditor()).addPropertyChangeListener (this);
 
152
 
 
153
        cbBackground.addActionListener (this);
 
154
        ((JComponent)cbBackground.getEditor()).addPropertyChangeListener (this);
 
155
        
 
156
        cbEffects.addItem (loc ("CTL_Effects_None"));
 
157
        cbEffects.addItem (loc ("CTL_Effects_Underlined"));
 
158
        cbEffects.addItem (loc ("CTL_Effects_Wave_Underlined"));
 
159
        cbEffects.addItem (loc ("CTL_Effects_Strike_Through"));
 
160
        cbEffects.getAccessibleContext ().setAccessibleName (loc ("AN_Effects"));
 
161
        cbEffects.getAccessibleContext ().setAccessibleDescription (loc ("AD_Effects"));
 
162
        cbEffects.addActionListener (this);
 
163
        cbEffectColor.addActionListener (this);
 
164
        
 
165
        loc(bFont, "CTL_Font_button");
 
166
        loc(lBackground, "CTL_Background_label");
 
167
        loc(lCategory, "CTL_Category");
 
168
        loc(lEffectColor, "CTL_Effects_color");
 
169
        loc(lEffects, "CTL_Effects_label");
 
170
        loc(lFont, "CTL_Font");
 
171
        loc(lForeground, "CTL_Foreground_label");
 
172
        loc(lLanguage, "CTL_Languages");
 
173
        loc(lPreview, "CTL_Preview");
 
174
 
 
175
        selectTask = new RequestProcessor ("SyntaxColoringPanel1").create (
 
176
            new Runnable () {
 
177
                public void run () {
 
178
                    refreshUI ();
 
179
                    if (!blink) return;
 
180
                    startBlinking ();
 
181
                }
 
182
            }
 
183
        );
 
184
    }
 
185
    
 
186
    /** This method is called from within the constructor to
 
187
     * initialize the form.
 
188
     * WARNING: Do NOT modify this code. The content of this method is
 
189
     * always regenerated by the Form Editor.
 
190
     */
 
191
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
 
192
    private void initComponents() {
 
193
 
 
194
        lLanguage = new javax.swing.JLabel();
 
195
        cbLanguage = new javax.swing.JComboBox();
 
196
        lCategory = new javax.swing.JLabel();
 
197
        spCategories = new javax.swing.JScrollPane();
 
198
        lCategories = new javax.swing.JList();
 
199
        lPreview = new javax.swing.JLabel();
 
200
        spPreview = new javax.swing.JScrollPane();
 
201
        pPreview = new javax.swing.JPanel();
 
202
        lFont = new javax.swing.JLabel();
 
203
        lForeground = new javax.swing.JLabel();
 
204
        lBackground = new javax.swing.JLabel();
 
205
        lEffects = new javax.swing.JLabel();
 
206
        lEffectColor = new javax.swing.JLabel();
 
207
        cbForeground = new javax.swing.JComboBox();
 
208
        cbBackground = new javax.swing.JComboBox();
 
209
        cbEffects = new javax.swing.JComboBox();
 
210
        cbEffectColor = new javax.swing.JComboBox();
 
211
        tfFont = new javax.swing.JTextField();
 
212
        bFont = new javax.swing.JButton();
 
213
 
 
214
        lLanguage.setLabelFor(cbLanguage);
 
215
        lLanguage.setText("Language:");
 
216
 
 
217
        lCategory.setLabelFor(lCategories);
 
218
        lCategory.setText("Category:");
 
219
 
 
220
        spCategories.setViewportView(lCategories);
 
221
 
 
222
        lPreview.setText("Preview:");
 
223
 
 
224
        spPreview.setBorder(javax.swing.BorderFactory.createEtchedBorder());
 
225
        spPreview.setAutoscrolls(true);
 
226
 
 
227
        pPreview.setAutoscrolls(true);
 
228
        pPreview.setLayout(new java.awt.BorderLayout());
 
229
        spPreview.setViewportView(pPreview);
 
230
 
 
231
        lFont.setLabelFor(bFont);
 
232
        lFont.setText("Font:");
 
233
 
 
234
        lForeground.setLabelFor(cbForeground);
 
235
        lForeground.setText("Foreground:");
 
236
 
 
237
        lBackground.setLabelFor(cbBackground);
 
238
        lBackground.setText("Background:");
 
239
 
 
240
        lEffects.setLabelFor(cbEffects);
 
241
        lEffects.setText("Effects:");
 
242
 
 
243
        lEffectColor.setLabelFor(cbEffectColor);
 
244
        lEffectColor.setText("Effect Color:");
 
245
 
 
246
        bFont.setText("...");
 
247
        bFont.setMargin(new java.awt.Insets(2, 2, 2, 2));
 
248
 
 
249
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
 
250
        this.setLayout(layout);
 
251
        layout.setHorizontalGroup(
 
252
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 
253
            .add(layout.createSequentialGroup()
 
254
                .addContainerGap()
 
255
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 
256
                    .add(spPreview, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
 
257
                    .add(layout.createSequentialGroup()
 
258
                        .add(lLanguage)
 
259
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
260
                        .add(cbLanguage, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
 
261
                    .add(lCategory)
 
262
                    .add(layout.createSequentialGroup()
 
263
                        .add(spCategories, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE)
 
264
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
265
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 
266
                            .add(lEffectColor)
 
267
                            .add(lForeground)
 
268
                            .add(lFont)
 
269
                            .add(lEffects)
 
270
                            .add(lBackground))
 
271
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
272
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 
273
                            .add(layout.createSequentialGroup()
 
274
                                .add(tfFont, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 13, Short.MAX_VALUE)
 
275
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
276
                                .add(bFont))
 
277
                            .add(cbForeground, 0, 38, Short.MAX_VALUE)
 
278
                            .add(cbBackground, 0, 38, Short.MAX_VALUE)
 
279
                            .add(cbEffects, 0, 38, Short.MAX_VALUE)
 
280
                            .add(cbEffectColor, 0, 38, Short.MAX_VALUE))
 
281
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
 
282
                    .add(lPreview))
 
283
                .addContainerGap())
 
284
        );
 
285
        layout.setVerticalGroup(
 
286
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 
287
            .add(layout.createSequentialGroup()
 
288
                .addContainerGap()
 
289
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
 
290
                    .add(lLanguage)
 
291
                    .add(cbLanguage, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
 
292
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
293
                .add(lCategory)
 
294
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
295
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 
296
                    .add(layout.createSequentialGroup()
 
297
                        .add(spCategories, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
 
298
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
299
                        .add(lPreview))
 
300
                    .add(layout.createSequentialGroup()
 
301
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
 
302
                            .add(lFont)
 
303
                            .add(tfFont, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
 
304
                            .add(bFont))
 
305
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
306
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
 
307
                            .add(lForeground)
 
308
                            .add(cbForeground, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
 
309
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
310
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
 
311
                            .add(lBackground)
 
312
                            .add(cbBackground, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
 
313
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
314
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
 
315
                            .add(lEffects)
 
316
                            .add(cbEffects, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
 
317
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
318
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
 
319
                            .add(lEffectColor)
 
320
                            .add(cbEffectColor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
 
321
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
 
322
                .add(spPreview, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
 
323
                .addContainerGap())
 
324
        );
 
325
    }// </editor-fold>//GEN-END:initComponents
 
326
    
 
327
    
 
328
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
329
    private javax.swing.JButton bFont;
 
330
    private javax.swing.JComboBox cbBackground;
 
331
    private javax.swing.JComboBox cbEffectColor;
 
332
    private javax.swing.JComboBox cbEffects;
 
333
    private javax.swing.JComboBox cbForeground;
 
334
    private javax.swing.JComboBox cbLanguage;
 
335
    private javax.swing.JLabel lBackground;
 
336
    private javax.swing.JList lCategories;
 
337
    private javax.swing.JLabel lCategory;
 
338
    private javax.swing.JLabel lEffectColor;
 
339
    private javax.swing.JLabel lEffects;
 
340
    private javax.swing.JLabel lFont;
 
341
    private javax.swing.JLabel lForeground;
 
342
    private javax.swing.JLabel lLanguage;
 
343
    private javax.swing.JLabel lPreview;
 
344
    private javax.swing.JPanel pPreview;
 
345
    private javax.swing.JScrollPane spCategories;
 
346
    private javax.swing.JScrollPane spPreview;
 
347
    private javax.swing.JTextField tfFont;
 
348
    // End of variables declaration//GEN-END:variables
 
349
    
 
350
 
 
351
    public void actionPerformed (ActionEvent evt) {
 
352
        if (!listen) return;
 
353
        if (evt.getSource () == cbEffects) {
 
354
            cbEffectColor.setEnabled (cbEffects.getSelectedIndex () > 0);
 
355
            if (cbEffects.getSelectedIndex () == 0)
 
356
                ColorComboBox.setColor (cbEffectColor, null);
 
357
            updateData ();
 
358
        } else
 
359
        if (evt.getSource () == cbLanguage) {
 
360
            setCurrentLanguage ((String) cbLanguage.getSelectedItem ());
 
361
        } else
 
362
        if (evt.getSource () == bFont) {
 
363
            PropertyEditor pe = PropertyEditorManager.findEditor (Font.class);
 
364
            AttributeSet category = getCurrentCategory ();
 
365
            Font f = getFont (category);
 
366
            pe.setValue (f);
 
367
            DialogDescriptor dd = new DialogDescriptor (
 
368
                pe.getCustomEditor (),
 
369
                loc ("CTL_Font_Chooser")                          // NOI18N
 
370
            );
 
371
            DialogDisplayer.getDefault ().createDialog (dd).setVisible (true);
 
372
            if (dd.getValue () == DialogDescriptor.OK_OPTION) {
 
373
                f = (Font) pe.getValue ();
 
374
                category = modifyFont (category, f);
 
375
                replaceCurrrentCategory (category);
 
376
                setToBeSaved (currentProfile, currentLanguage);
 
377
                refreshUI (); // refresh font viewer
 
378
            }
 
379
        } else
 
380
        if (evt.getSource () instanceof JComboBox) {
 
381
            updateData ();
 
382
        }
 
383
    }
 
384
    
 
385
    public void propertyChange(PropertyChangeEvent evt) {
 
386
        if (!listen || evt.getPropertyName() == null ) {
 
387
            return;
 
388
        }
 
389
        
 
390
        if (Preview.PROP_CURRENT_ELEMENT.equals(evt.getPropertyName())) {
 
391
            String currentCategory = (String) evt.getNewValue();
 
392
            Vector<AttributeSet> categories = getCategories(currentProfile, currentLanguage);
 
393
            if (currentLanguage.equals(ColorModel.ALL_LANGUAGES)) {
 
394
                String converted = (String) convertALC.get(currentCategory);
 
395
                if (converted != null) {
 
396
                    currentCategory = converted;
 
397
                }
 
398
            }
 
399
 
 
400
            for (int i = 0; i < categories.size(); i++) {
 
401
                AttributeSet as = categories.get(i);
 
402
                if (currentCategory.equals(as.getAttribute(StyleConstants.NameAttribute))) {
 
403
                    blink = false;
 
404
                    lCategories.setSelectedIndex(i);
 
405
                    lCategories.ensureIndexIsVisible(i);
 
406
                    blink = true;
 
407
                    break;
 
408
                }
 
409
            }
 
410
        } else if (ColorComboBox.PROP_COLOR.equals(evt.getPropertyName())) {
 
411
            updateData();
 
412
        }
 
413
    }
 
414
    
 
415
    public void update (ColorModel colorModel) {
 
416
        this.colorModel = colorModel;
 
417
        currentProfile = colorModel.getCurrentProfile ();
 
418
        currentLanguage = (String) colorModel.getLanguages ().
 
419
            iterator ().next ();
 
420
        if (preview != null) 
 
421
            preview.removePropertyChangeListener 
 
422
                (Preview.PROP_CURRENT_ELEMENT, this);
 
423
        Component component = colorModel.getSyntaxColoringPreviewComponent 
 
424
            (currentLanguage);
 
425
        preview = (Preview) component;
 
426
        pPreview.removeAll ();
 
427
        pPreview.add ("Center", component);
 
428
        preview.addPropertyChangeListener 
 
429
            (Preview.PROP_CURRENT_ELEMENT, this);
 
430
        listen = false;
 
431
        List<String> languages = new ArrayList<String>(colorModel.getLanguages ());
 
432
        Collections.sort (languages, new LanguagesComparator ());
 
433
        Iterator it = languages.iterator ();
 
434
        cbLanguage.removeAllItems ();
 
435
        while (it.hasNext ())
 
436
            cbLanguage.addItem (it.next ());
 
437
        listen = true;
 
438
        cbLanguage.setSelectedIndex (0);
 
439
    }
 
440
    
 
441
    public void cancel () {
 
442
        toBeSaved = new HashMap<String, Set<String>>();
 
443
        profiles = new HashMap<String, Map<String, Vector<AttributeSet>>>();
 
444
    }
 
445
    
 
446
    public void applyChanges() {
 
447
        if (colorModel == null) return;
 
448
        for(String profile : toBeSaved.keySet()) {
 
449
            Set<String> toBeSavedLanguages = toBeSaved.get(profile);
 
450
            Map<String, Vector<AttributeSet>> schemeMap = profiles.get(profile);
 
451
            for(String languageName : toBeSavedLanguages) {
 
452
                colorModel.setCategories(
 
453
                    profile,
 
454
                    languageName,
 
455
                    schemeMap.get(languageName)
 
456
                );
 
457
            }
 
458
        }
 
459
        toBeSaved = new HashMap<String, Set<String>>();
 
460
        profiles = new HashMap<String, Map<String, Vector<AttributeSet>>>();
 
461
    }
 
462
    
 
463
    public boolean isChanged () {
 
464
        return !toBeSaved.isEmpty ();
 
465
    }
 
466
    
 
467
    public void setCurrentProfile (String currentProfile) {
 
468
        String oldProfile = this.currentProfile;
 
469
        this.currentProfile = currentProfile;
 
470
        if (!colorModel.getProfiles ().contains (currentProfile))
 
471
            cloneScheme (oldProfile, currentProfile);
 
472
        Vector categories = getCategories (currentProfile, currentLanguage);
 
473
        lCategories.setListData (categories);
 
474
        blink = false;
 
475
        lCategories.setSelectedIndex (0);
 
476
        blink = true;
 
477
        refreshUI ();
 
478
    }
 
479
 
 
480
    public void deleteProfile(String profile) {
 
481
        Map<String, Vector<AttributeSet>> m = new HashMap<String, Vector<AttributeSet>>();
 
482
        boolean custom = colorModel.isCustomProfile(profile);
 
483
        for(String language : colorModel.getLanguages()) {
 
484
            if (custom) {
 
485
                m.put(language, null);
 
486
            } else {
 
487
                m.put(language, getDefaults(profile, language));
 
488
            }
 
489
        }
 
490
        profiles.put(profile, m);
 
491
        toBeSaved.put(profile, new HashSet<String>(colorModel.getLanguages()));
 
492
        if (!custom) {
 
493
            refreshUI();
 
494
        }
 
495
    }
 
496
    
 
497
    public JComponent getComponent() {
 
498
        return this;
 
499
    }
 
500
        
 
501
    // other methods ...........................................................
 
502
    
 
503
    private void cloneScheme(String oldScheme, String newScheme) {
 
504
        Map<String, Vector<AttributeSet>> m = new HashMap<String, Vector<AttributeSet>>();
 
505
        for(String language : colorModel.getLanguages()) {
 
506
            Vector<AttributeSet> v = getCategories(oldScheme, language);
 
507
            m.put(language, new Vector<AttributeSet>(v));
 
508
            setToBeSaved(newScheme, language);
 
509
        }
 
510
        profiles.put(newScheme, m);
 
511
    }
 
512
    
 
513
    Collection<AttributeSet> getAllLanguages() {
 
514
        return getCategories(currentProfile, ColorModel.ALL_LANGUAGES);
 
515
    }
 
516
    
 
517
    Collection<AttributeSet> getSyntaxColorings() {
 
518
        return getCategories(currentProfile, currentLanguage);
 
519
    }
 
520
    
 
521
    private void setCurrentLanguage (String language) {
 
522
        currentLanguage = language;
 
523
        
 
524
        // setup categories list
 
525
        blink = false;
 
526
        lCategories.setListData (getCategories (currentProfile, currentLanguage));
 
527
        lCategories.setSelectedIndex (0);
 
528
        blink = true;
 
529
        refreshUI ();
 
530
    }
 
531
    
 
532
    private static String loc (String key) {
 
533
        return NbBundle.getMessage (SyntaxColoringPanel.class, key);
 
534
    }
 
535
    
 
536
    private static void loc (Component c, String key) {
 
537
        if (c instanceof AbstractButton)
 
538
            Mnemonics.setLocalizedText (
 
539
                (AbstractButton) c, 
 
540
                loc (key)
 
541
            );
 
542
        else
 
543
            Mnemonics.setLocalizedText (
 
544
                (JLabel) c, 
 
545
                loc (key)
 
546
            );
 
547
    }
 
548
 
 
549
    /**
 
550
     * Called on user change.
 
551
     * Updates data structures and preview panel.
 
552
     */
 
553
    private void updateData () {
 
554
        int i = lCategories.getSelectedIndex ();
 
555
        if (i < 0) return;
 
556
        
 
557
        AttributeSet category = getCurrentCategory ();
 
558
        Color underline = null, 
 
559
              wave = null, 
 
560
              strikethrough = null;
 
561
        if (cbEffects.getSelectedIndex () == 1)
 
562
            underline = ColorComboBox.getColor(cbEffectColor);
 
563
        if (cbEffects.getSelectedIndex () == 2)
 
564
            wave = ColorComboBox.getColor(cbEffectColor);
 
565
        if (cbEffects.getSelectedIndex () == 3)
 
566
            strikethrough = ColorComboBox.getColor(cbEffectColor);
 
567
        
 
568
        SimpleAttributeSet c = new SimpleAttributeSet (category);
 
569
        
 
570
        Color color = ColorComboBox.getColor(cbBackground);
 
571
        if (color != null) {
 
572
            c.addAttribute(StyleConstants.Background, color);
 
573
        } else {
 
574
            c.removeAttribute(StyleConstants.Background);
 
575
        }
 
576
        
 
577
        color = ColorComboBox.getColor(cbForeground);
 
578
        if (color != null) {
 
579
            c.addAttribute(StyleConstants.Foreground, color);
 
580
        } else {
 
581
            c.removeAttribute(StyleConstants.Foreground);
 
582
        }
 
583
        
 
584
        if (underline != null) {
 
585
            c.addAttribute(StyleConstants.Underline, underline);
 
586
        } else {
 
587
            c.removeAttribute(StyleConstants.Underline);
 
588
        }
 
589
        
 
590
        if (strikethrough != null) {
 
591
            c.addAttribute(StyleConstants.StrikeThrough, strikethrough);
 
592
        } else {
 
593
            c.removeAttribute(StyleConstants.StrikeThrough);
 
594
        }
 
595
        
 
596
        if (wave != null) {
 
597
            c.addAttribute(EditorStyleConstants.WaveUnderlineColor, wave);
 
598
        } else {
 
599
            c.removeAttribute(EditorStyleConstants.WaveUnderlineColor);
 
600
        }
 
601
        
 
602
        replaceCurrrentCategory(c);
 
603
        setToBeSaved(currentProfile, currentLanguage);
 
604
        updatePreview();
 
605
    }
 
606
 
 
607
    private boolean                 blink = true;
 
608
    private int                     blinkSequence = 0;
 
609
    private RequestProcessor.Task   task = new RequestProcessor 
 
610
        ("SyntaxColoringPanel").create (new Runnable () {
 
611
        public void run () {
 
612
            updatePreview ();
 
613
            if (blinkSequence == 0) return;
 
614
            blinkSequence --;
 
615
            task.schedule (250);
 
616
        }
 
617
    });
 
618
    
 
619
    private void startBlinking () {
 
620
        blinkSequence = 5;
 
621
        task.schedule (0);
 
622
    }
 
623
    
 
624
    private void updatePreview () {
 
625
        Collection<AttributeSet> syntaxColorings = getSyntaxColorings();
 
626
        Collection<AttributeSet> allLanguages = getAllLanguages();
 
627
        if ((blinkSequence % 2) == 1) {
 
628
            if (ColorModel.ALL_LANGUAGES.equals(currentLanguage)) {
 
629
                allLanguages = invertCategory(allLanguages, getCurrentCategory());
 
630
            } else {
 
631
                syntaxColorings = invertCategory(syntaxColorings, getCurrentCategory());
 
632
            }
 
633
        }
 
634
        preview.setParameters (
 
635
            currentLanguage,
 
636
            allLanguages,
 
637
            Collections.<AttributeSet>emptySet(),
 
638
            syntaxColorings
 
639
        );
 
640
    }
 
641
    
 
642
    private Collection<AttributeSet> invertCategory (Collection<AttributeSet> c, AttributeSet category) {
 
643
        if (category == null) return c;
 
644
        ArrayList<AttributeSet> result = new ArrayList<AttributeSet> (c);
 
645
        int i = result.indexOf (category);
 
646
        SimpleAttributeSet as = new SimpleAttributeSet (category);
 
647
        Color highlight = (Color) getValue (currentLanguage, category, StyleConstants.Background);
 
648
        if (highlight == null) return result;
 
649
        Color newColor = new Color (
 
650
            255 - highlight.getRed (),
 
651
            255 - highlight.getGreen (),
 
652
            255 - highlight.getBlue ()
 
653
        );
 
654
        as.addAttribute (
 
655
            StyleConstants.Underline,
 
656
            newColor
 
657
        );
 
658
        result.set (i, as);
 
659
        return result;
 
660
    }
 
661
    
 
662
    /**
 
663
     * Called when current category, profile or language has been changed.
 
664
     * Updates all ui components.
 
665
     */
 
666
    private void refreshUI () {
 
667
        listen = false;
 
668
        AttributeSet category = getCurrentCategory ();
 
669
        if (category == null) {
 
670
            // no category selected > disable all elements
 
671
            tfFont.setText ("");
 
672
            bFont.setEnabled (false);
 
673
            cbEffects.setEnabled (false);
 
674
            cbForeground.setEnabled (false);
 
675
            cbForeground.setSelectedItem (new ColorValue (null, null));
 
676
            cbBackground.setEnabled (false);
 
677
            cbBackground.setSelectedItem (new ColorValue (null, null));
 
678
            cbEffectColor.setEnabled (false);
 
679
            cbEffectColor.setSelectedItem (new ColorValue (null, null));
 
680
            updatePreview ();
 
681
            return;
 
682
        }
 
683
        bFont.setEnabled (true);
 
684
        cbEffects.setEnabled (true);
 
685
        cbForeground.setEnabled (true);
 
686
        cbBackground.setEnabled (true);
 
687
        
 
688
        // set defaults
 
689
        Color inheritedForeground = (Color) getDefault 
 
690
            (currentLanguage, category, StyleConstants.Foreground);
 
691
        if (inheritedForeground == null) inheritedForeground = Color.black;
 
692
        ColorComboBox.setInheritedColor (cbForeground, inheritedForeground);
 
693
        Color inheritedBackground = (Color) getDefault 
 
694
            (currentLanguage, category, StyleConstants.Background);
 
695
        if (inheritedBackground == null) inheritedBackground = Color.white;
 
696
        ColorComboBox.setInheritedColor (cbBackground, inheritedBackground);
 
697
        
 
698
        String font = fontToString (category);
 
699
        tfFont.setText (font);
 
700
        ColorComboBox.setColor (
 
701
            cbForeground,
 
702
            (Color) category.getAttribute (StyleConstants.Foreground)
 
703
        );
 
704
        ColorComboBox.setColor (
 
705
            cbBackground,
 
706
            (Color) category.getAttribute (StyleConstants.Background)
 
707
        );
 
708
        
 
709
        if (category.getAttribute (StyleConstants.Underline) != null) {
 
710
            cbEffects.setSelectedIndex (1);
 
711
            cbEffectColor.setEnabled (true);
 
712
            ColorComboBox.setColor (
 
713
                cbEffectColor,
 
714
                (Color) category.getAttribute (StyleConstants.Underline)
 
715
            );
 
716
        } else
 
717
        if (category.getAttribute (EditorStyleConstants.WaveUnderlineColor) != null) {
 
718
            cbEffects.setSelectedIndex (2);
 
719
            cbEffectColor.setEnabled (true);
 
720
            ColorComboBox.setColor (
 
721
                cbEffectColor,
 
722
                (Color) category.getAttribute (EditorStyleConstants.WaveUnderlineColor)
 
723
            );
 
724
        } else
 
725
        if (category.getAttribute (StyleConstants.StrikeThrough) != null) {
 
726
            cbEffects.setSelectedIndex (3);
 
727
            cbEffectColor.setEnabled (true);
 
728
            ColorComboBox.setColor (
 
729
                cbEffectColor,
 
730
                (Color) category.getAttribute (StyleConstants.StrikeThrough)
 
731
            );
 
732
        } else {
 
733
            cbEffects.setSelectedIndex (0);
 
734
            cbEffectColor.setEnabled (false);
 
735
            cbEffectColor.setSelectedItem (new ColorValue (null, null));
 
736
        }
 
737
        updatePreview ();
 
738
        listen = true;
 
739
    }
 
740
    
 
741
    private void setToBeSaved(String currentProfile, String currentLanguage) {
 
742
        Set<String> s = toBeSaved.get(currentProfile);
 
743
        if (s == null) {
 
744
            s = new HashSet<String>();
 
745
            toBeSaved.put(currentProfile, s);
 
746
        }
 
747
        s.add(currentLanguage);
 
748
    }
 
749
    
 
750
    private Vector<AttributeSet> getCategories(String profile, String language) {
 
751
        if (colorModel == null) return null;
 
752
        Map<String, Vector<AttributeSet>> m = profiles.get(profile);
 
753
        if (m == null) {
 
754
            m = new HashMap<String, Vector<AttributeSet>>();
 
755
            profiles.put(profile, m);
 
756
        }
 
757
        Vector<AttributeSet> v = m.get(language);
 
758
        if (v == null) {
 
759
            Collection<AttributeSet> c = colorModel.getCategories(profile, language);
 
760
            if (c == null) {
 
761
                c = Collections.<AttributeSet>emptySet(); // XXX OK?
 
762
            }
 
763
            List<AttributeSet> l = new ArrayList<AttributeSet>(c);
 
764
            Collections.sort(l, new CategoryComparator());
 
765
            v = new Vector<AttributeSet>(l);
 
766
            m.put(language, v);
 
767
        }
 
768
        return v;
 
769
    }
 
770
 
 
771
    private Map<String, Map<String, Vector<AttributeSet>>> defaults = new HashMap<String, Map<String, Vector<AttributeSet>>>();
 
772
    /**
 
773
     * Returns original colors for given profile.
 
774
     */
 
775
    private Vector<AttributeSet> getDefaults(String profile, String language) {
 
776
        Map<String, Vector<AttributeSet>> m = defaults.get(profile);
 
777
        if (m == null) {
 
778
            m = new HashMap<String, Vector<AttributeSet>>();
 
779
            defaults.put(profile, m);
 
780
        }
 
781
        Vector<AttributeSet> v = m.get(language);
 
782
        if (v == null) {
 
783
            Collection<AttributeSet> c = colorModel.getDefaults(profile, language);
 
784
            List<AttributeSet> l = new ArrayList<AttributeSet>(c);
 
785
            Collections.sort(l, new CategoryComparator());
 
786
            v = new Vector<AttributeSet>(l);
 
787
            m.put(language, v);
 
788
        }
 
789
        return new Vector<AttributeSet>(v);
 
790
    }
 
791
    
 
792
    private AttributeSet getCurrentCategory () {
 
793
        int i = lCategories.getSelectedIndex ();
 
794
        if (i < 0) return null;
 
795
        return (AttributeSet) getCategories (currentProfile, currentLanguage).get (i);
 
796
    }
 
797
    
 
798
    private void replaceCurrrentCategory (AttributeSet newValues) {
 
799
        int i = lCategories.getSelectedIndex ();
 
800
        getCategories (currentProfile, currentLanguage).set (i, newValues);
 
801
    }
 
802
    
 
803
    private AttributeSet getCategory (
 
804
        String profile, 
 
805
        String language, 
 
806
        String name
 
807
    ) {
 
808
        Vector v = getCategories (profile, language);
 
809
        Iterator it = v.iterator ();
 
810
        while (it.hasNext ()) {
 
811
            AttributeSet c = (AttributeSet) it.next ();
 
812
            if (c.getAttribute (StyleConstants.NameAttribute).equals (name)) 
 
813
                return c;
 
814
        }
 
815
        return null;
 
816
    }
 
817
    
 
818
    private Object getValue (String language, AttributeSet category, Object key) {
 
819
        if (category.isDefined (key))
 
820
            return category.getAttribute (key);
 
821
        return getDefault (language, category, key);
 
822
    }
 
823
    
 
824
    private Object getDefault (String language, AttributeSet category, Object key) {
 
825
        String name = (String) category.getAttribute (EditorStyleConstants.Default);
 
826
        if (name == null) name = "default";
 
827
 
 
828
        // 1) search current language
 
829
        if (!name.equals (category.getAttribute (StyleConstants.NameAttribute))
 
830
        ) {
 
831
            AttributeSet defaultAS = getCategory 
 
832
                (currentProfile, language, name);
 
833
            if (defaultAS != null)
 
834
                return getValue (language, defaultAS, key);
 
835
        }
 
836
        
 
837
        // 2) search default language
 
838
        if (!language.equals (ColorModel.ALL_LANGUAGES)) {
 
839
            AttributeSet defaultAS = getCategory 
 
840
                (currentProfile, ColorModel.ALL_LANGUAGES, name);
 
841
            if (defaultAS != null)
 
842
                return getValue (ColorModel.ALL_LANGUAGES, defaultAS, key);
 
843
        }
 
844
        
 
845
        if (key == StyleConstants.FontFamily) return "Monospaced";    // NOI18N
 
846
        if (key == StyleConstants.FontSize) return getDefaultFontSize ();
 
847
        return null;
 
848
    }
 
849
    
 
850
    private Font getFont (AttributeSet category) {
 
851
        String name = (String) getValue (currentLanguage, category, StyleConstants.FontFamily);
 
852
        if (name == null) name = "Monospaced";                        // NOI18N
 
853
        Integer size = (Integer) getValue (currentLanguage, category, StyleConstants.FontSize);
 
854
        if (size == null)
 
855
            size = getDefaultFontSize ();
 
856
        Boolean bold = (Boolean) getValue (currentLanguage, category, StyleConstants.Bold);
 
857
        if (bold == null) bold = Boolean.FALSE;
 
858
        Boolean italic = (Boolean) getValue (currentLanguage, category, StyleConstants.Italic);
 
859
        if (italic == null) italic = Boolean.FALSE;
 
860
        int style = bold.booleanValue () ? Font.BOLD : Font.PLAIN;
 
861
        if (italic.booleanValue ()) style += Font.ITALIC;
 
862
        return new Font (name, style, size.intValue ());
 
863
    }
 
864
    
 
865
    private AttributeSet modifyFont (AttributeSet category, Font f) {
 
866
        String fontName = f.getName ();
 
867
        Integer fontSize = new Integer (f.getSize ());
 
868
        Boolean bold = Boolean.valueOf (f.isBold ());
 
869
        Boolean italic = Boolean.valueOf (f.isItalic ());
 
870
        boolean isDefault = "default".equals (
 
871
            category.getAttribute (StyleConstants.NameAttribute)
 
872
        );
 
873
        if (fontName.equals (
 
874
            getDefault (currentLanguage, category, StyleConstants.FontFamily)
 
875
        ) && !isDefault)
 
876
            fontName = null;
 
877
        if (fontSize.equals (
 
878
            getDefault (currentLanguage, category, StyleConstants.FontSize)
 
879
        ) && !isDefault)
 
880
            fontSize = null;
 
881
        if (bold.equals (getDefault (currentLanguage, category, StyleConstants.Bold))
 
882
        )
 
883
            bold = null;
 
884
        else
 
885
        if (bold.equals (Boolean.FALSE) &&
 
886
            getDefault (currentLanguage, category, StyleConstants.Bold) == null
 
887
        )
 
888
            bold = null;
 
889
        if (italic.equals (getDefault (currentLanguage, category, StyleConstants.Italic))
 
890
        )
 
891
            italic = null;
 
892
        else
 
893
        if (italic.equals (Boolean.FALSE) &&
 
894
            getDefault (currentLanguage, category, StyleConstants.Italic) == null
 
895
        )
 
896
            italic = null;
 
897
        SimpleAttributeSet c = new SimpleAttributeSet (category);
 
898
        if (fontName != null)
 
899
            c.addAttribute (
 
900
                StyleConstants.FontFamily,
 
901
                fontName
 
902
            );
 
903
        else
 
904
            c.removeAttribute (StyleConstants.FontFamily);
 
905
        if (fontSize != null)
 
906
            c.addAttribute (
 
907
                StyleConstants.FontSize,
 
908
                fontSize
 
909
            );
 
910
        else
 
911
            c.removeAttribute (StyleConstants.FontSize);
 
912
        if (bold != null)
 
913
            c.addAttribute (
 
914
                StyleConstants.Bold,
 
915
                bold
 
916
            );
 
917
        else
 
918
            c.removeAttribute (StyleConstants.Bold);
 
919
        if (italic != null)
 
920
            c.addAttribute (
 
921
                StyleConstants.Italic,
 
922
                italic
 
923
            );
 
924
        else
 
925
            c.removeAttribute (StyleConstants.Italic);
 
926
        
 
927
        return c;
 
928
    }
 
929
    
 
930
    private String fontToString (AttributeSet category) {
 
931
        if ("default".equals (
 
932
            category.getAttribute (StyleConstants.NameAttribute)
 
933
        )) {
 
934
            StringBuffer sb = new StringBuffer ();
 
935
            sb.append (getValue (currentLanguage, category, StyleConstants.FontFamily));
 
936
            sb.append (' ');
 
937
            sb.append (getValue (currentLanguage, category, StyleConstants.FontSize));
 
938
            Boolean bold = (Boolean) getValue (currentLanguage, category, StyleConstants.Bold);
 
939
            if (bold != null && bold.booleanValue ())
 
940
                sb.append (' ').append (loc ("CTL_Bold"));                // NOI18N
 
941
            Boolean italic = (Boolean) getValue (currentLanguage, category, StyleConstants.Italic);
 
942
            if (italic != null && italic.booleanValue ())
 
943
                sb.append (' ').append (loc ("CTL_Italic"));              // NOI18N
 
944
            return sb.toString ();
 
945
        }
 
946
        boolean def = false;
 
947
        StringBuffer sb = new StringBuffer ();
 
948
        if (category.getAttribute (StyleConstants.FontFamily) != null)
 
949
            sb.append ('+').append (category.getAttribute (StyleConstants.FontFamily));
 
950
        else
 
951
            def = true;
 
952
        if (category.getAttribute (StyleConstants.FontSize) != null)
 
953
            sb.append ('+').append (category.getAttribute (StyleConstants.FontSize));
 
954
        else
 
955
            def = true;
 
956
        if (Boolean.TRUE.equals (category.getAttribute (StyleConstants.Bold)))
 
957
            sb.append ('+').append (loc ("CTL_Bold"));                // NOI18N
 
958
        if (Boolean.FALSE.equals (category.getAttribute (StyleConstants.Bold)))
 
959
            sb.append ('-').append (loc ("CTL_Bold"));                // NOI18N
 
960
        if (Boolean.TRUE.equals (category.getAttribute (StyleConstants.Italic)))
 
961
            sb.append ('+').append (loc ("CTL_Italic"));              // NOI18N
 
962
        if (Boolean.FALSE.equals (category.getAttribute (StyleConstants.Italic)))
 
963
            sb.append ('-').append (loc ("CTL_Italic"));              // NOI18N
 
964
        
 
965
        if (def) {
 
966
            sb.insert (0, loc ("CTL_Inherited"));                     // NOI18N
 
967
            return sb.toString ();
 
968
        } else {
 
969
            String result = sb.toString ();
 
970
            return result.replace ('+', ' ');
 
971
        }
 
972
    }
 
973
    
 
974
    private static Map<String, String> convertALC = new HashMap<String, String>();
 
975
    
 
976
    static {
 
977
        convertALC.put("character", "char"); //NOI18N
 
978
        convertALC.put("errors", "error"); //NOI18N
 
979
        convertALC.put("literal", "keyword"); //NOI18N
 
980
        convertALC.put("keyword-directive", "keyword"); //NOI18N
 
981
    }
 
982
    
 
983
    private static Integer defaultFontSize;
 
984
    private static Integer getDefaultFontSize () {
 
985
        if (defaultFontSize == null) {
 
986
            defaultFontSize = (Integer) UIManager.get("customFontSize"); // NOI18N
 
987
            if (defaultFontSize == null) {
 
988
                int s = UIManager.getFont ("TextField.font").getSize (); // NOI18N
 
989
                if (s < 12) s = 12;
 
990
                defaultFontSize = new Integer (s);
 
991
            }
 
992
        }
 
993
        return defaultFontSize;
 
994
    }
 
995
    
 
996
    private static final class LanguagesComparator implements Comparator<String> {
 
997
        public int compare(String o1, String o2) {
 
998
            if (o1.equals(ColorModel.ALL_LANGUAGES))
 
999
                return o2.equals(ColorModel.ALL_LANGUAGES) ? 0 : -1;
 
1000
            return o1.compareTo(o2);
 
1001
        }
 
1002
    }
 
1003
}