KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > gsf > LanguageRegistry


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 package org.netbeans.modules.gsf;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Font JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.OutputStream JavaDoc;
26 import java.util.*;
27 import java.util.ArrayList JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32
33 import javax.swing.SwingUtilities JavaDoc;
34 import javax.swing.text.AttributeSet JavaDoc;
35 import javax.swing.text.SimpleAttributeSet JavaDoc;
36 import javax.swing.text.StyleConstants JavaDoc;
37
38 import org.netbeans.api.editor.settings.EditorStyleConstants;
39 import org.netbeans.api.gsf.annotations.NonNull;
40 import org.netbeans.api.lexer.TokenId;
41
42 //import org.netbeans.modules.editor.settings.storage.api.EditorSettings;
43
//import org.netbeans.modules.editor.settings.storage.api.FontColorSettingsFactory;
44
import org.netbeans.modules.gsf.Language;
45 import org.openide.ErrorManager;
46 import org.openide.filesystems.FileObject;
47 import org.openide.filesystems.FileObject;
48 import org.openide.filesystems.FileSystem;
49 import org.openide.filesystems.FileSystem;
50 import org.openide.filesystems.FileSystem.AtomicAction;
51 import org.openide.filesystems.FileUtil;
52 import org.openide.filesystems.FileUtil;
53 import org.openide.filesystems.Repository;
54 import org.openide.filesystems.Repository;
55
56
57 /**
58  * Registry which locates and provides information about languages supported
59  * by various plugins.
60  *
61  *
62  * @author Tor Norbye
63  */

64 public class LanguageRegistry implements Iterable JavaDoc<Language> {
65     private static LanguageRegistry instance;
66     private static final String JavaDoc DISPLAY_NAME = "displayName";
67     private static final String JavaDoc ICON_BASE = "iconBase";
68     private static final String JavaDoc EXTENSIONS = "extensions";
69     private static final String JavaDoc LANGUAGE = "language.instance";
70     private static final String JavaDoc PARSER = "parser.instance";
71     private static final String JavaDoc COMPLETION = "completion.instance";
72     private static final String JavaDoc RENAMER = "renamer.instance";
73     private static final String JavaDoc FORMATTER = "formatter.instance";
74     private static final String JavaDoc BRACKET_COMPLETION = "bracket.instance";
75     private static final String JavaDoc DECLARATION_FINDER = "declarationfinder.instance";
76     private static final String JavaDoc INDEXER = "indexer.instance";
77     private static final String JavaDoc PALETTE = "palette.instance";
78     private static final String JavaDoc STRUCTURE = "structure.instance";
79
80     /** Location in the system file system where languages are registered */
81     private static final String JavaDoc FOLDER = "GsfPlugins";
82     private List JavaDoc<Language> languages;
83     private boolean languagesInitialized;
84
85     /**
86      * Creates a new instance of LanguageRegistry
87      */

88     public LanguageRegistry() {
89         initialize();
90     }
91
92     public static synchronized LanguageRegistry getInstance() {
93         if (instance == null) {
94             instance = new LanguageRegistry();
95         }
96
97         return instance;
98     }
99
100     /**
101      * Return a language implementation that corresponds to the given file extension,
102      * or null if no such language is supported
103      */

104     public Language getLanguageByExtension(@NonNull
105     String JavaDoc extension) {
106         extension = extension.toLowerCase();
107
108         // TODO - create a map if this is slow
109
for (Language language : this) {
110             String JavaDoc[] extensions = language.getExtensions();
111
112             for (int i = 0; i < extensions.length; i++) {
113                 if (extension.equals(extensions[i])) {
114                     return language;
115                 }
116             }
117         }
118
119         return null;
120     }
121
122     /**
123      * Return a language implementation that corresponds to the given mimeType,
124      * or null if no such language is supported
125      */

126     public Language getLanguageByMimeType(@NonNull
127     String JavaDoc mimeType) {
128         assert mimeType.equals(mimeType.toLowerCase());
129
130         for (Language language : this) {
131             if (language.getMimeType().equals(mimeType)) {
132                 return language;
133             }
134         }
135
136         return null;
137     }
138
139     /**
140      * Return true iff the given mimeType is supported by a registered language plugin
141      * @return True iff the given mimeType is supported
142      */

143     public boolean isSupported(@NonNull
144     String JavaDoc mimeType) {
145         for (Language language : this) {
146             if (mimeType.equals(language.getMimeType())) {
147                 return true;
148             }
149         }
150
151         return false;
152     }
153
154     public Iterator JavaDoc<Language> iterator() {
155         if (languages == null) {
156             return new Iterator JavaDoc<Language>() {
157                     public boolean hasNext() {
158                         return false;
159                     }
160
161                     public Language next() {
162                         return null;
163                     }
164
165                     public void remove() {
166                     }
167                 };
168         } else {
169             return languages.iterator();
170         }
171     }
172
173     private synchronized void initialize() {
174         if (languages == null) {
175             readSfs();
176
177             initializeLanguages();
178         }
179     }
180
181     synchronized void initializeLanguages() {
182         if (languagesInitialized) {
183             return;
184         }
185
186         languagesInitialized = true;
187
188         if (languages == null) {
189             // No registered languages
190
return;
191         }
192
193         Iterator JavaDoc it = languages.iterator();
194
195         while (it.hasNext()) {
196             final Language language = (Language)it.next();
197
198             initializeLanguage(language);
199
200             // I had hoped to lazily initialize editors
201
// but the Options panel is eagerly (at startup) caching the
202
// set of mime folders that provide NetBeans/Defaults/coloring.xml
203
// in the system file system, and only those are listed in the
204
// Languages list for syntax editing.
205
// One thing I can do here, is ONLY populate the coloring in advance
206
// and leave the other portions for later - but coloring is probably
207
// the most expensive file to compute anyway. Luckily, this should
208
// only have to be done once - it will not be updated on subsequent
209
// IDE starts until the user dir is removed.
210

211             // Actually, this causes some real serious problems. DataLoader registration
212
// doesn't happen in just one go - and here, the call to initializeLanguageForEditor will
213
// be called before all loaders have been registered (I was seeing it with RhtmlDataLoader)
214
// but the list will be fixed (because DataLoaderPool calls down to the LoaderPoolNode
215
// and copies it list before it's done, and doesn't know to refresh itself).
216
//
217
// Perhaps I can work around this by adding some specific MIME folder registrations
218
// early, but not do full initialization? I specifically need to avoid any calls into
219
// the DataObject area - which initializeLanguageForEditor will do when instantiating the
220
// registered scanners etc.
221
// SwingUtilities.invokeLater(new Runnable() {
222
// // Gotta invoke later because if it's done as part of DataLoader initialization,
223
// // loader registration fails and our files are not recognized
224
// public void run() {
225
// initializeLanguageForEditor(language);
226
// }
227
// });
228
}
229     }
230
231     private void readSfs() {
232         FileSystem sfs = Repository.getDefault().getDefaultFileSystem();
233         FileObject f = sfs.findResource(FOLDER);
234
235         if (f == null) {
236             return;
237         }
238
239         // Read languages
240
FileObject[] children = f.getChildren();
241         languages = new ArrayList JavaDoc<Language>();
242
243         for (int i = 0; i < children.length; i++) {
244             FileObject mimePrefixFile = children[i];
245
246             // Read languages
247
FileObject[] innerChildren = mimePrefixFile.getChildren();
248
249             for (int j = 0; j < innerChildren.length; j++) {
250                 FileObject mimeFile = innerChildren[j];
251
252                 String JavaDoc mime = mimePrefixFile.getName() + "/" + mimeFile.getName();
253                 DefaultLanguage language = new DefaultLanguage(mime);
254                 languages.add(language);
255
256                 String JavaDoc displayName = (String JavaDoc)mimeFile.getAttribute(DISPLAY_NAME);
257
258                 /*
259                 public String getLanguageName (String mimeType) {
260                 if (!mimeTypeToName.containsKey (mimeType)) {
261                 FileSystem fs = Repository.getDefault ().getDefaultFileSystem ();
262                 FileObject fo = fs.findResource ("Editors/" + mimeType);
263                 if (fo == null) return "???";
264                 String bundleName = (String) fo.getAttribute ("SystemFileSystem.localizingBundle");
265                 String name = mimeType;
266                 if (bundleName != null)
267                 try {
268                     name = NbBundle.getBundle (bundleName).getString (mimeType);
269                 } catch (MissingResourceException ex) {}
270                 mimeTypeToName.put (mimeType, name);
271                 }
272                 return (String) mimeTypeToName.get (mimeType);
273                 }
274                   */

275                 if ((displayName != null) && (displayName.length() > 0)) {
276                     language.setDisplayName(displayName);
277                 }
278
279                 // Try to obtain icon from (new) IDE location for icons per mime type:
280
FileObject loaderMimeFile = sfs.findResource("Loaders/" + mime);
281
282                 if (loaderMimeFile != null) {
283                     String JavaDoc iconBase = (String JavaDoc)loaderMimeFile.getAttribute(ICON_BASE);
284
285                     if ((iconBase != null) && (iconBase.length() > 0)) {
286                         language.setIconBase(iconBase);
287                     }
288                 }
289
290                 //Local icon registration in the Languages/ folder
291
//String iconBase = (String)mimeFile.getAttribute(ICON_BASE);
292
//
293
//if ((iconBase != null) && (iconBase.length() > 0)) {
294
// language.setIconBase(iconBase);
295
//}
296

297                 // Look for extensions, scanners, parsers, etc.
298
FileObject extensionsDir = mimeFile.getFileObject(EXTENSIONS, null);
299
300                 if ((extensionsDir != null) && extensionsDir.isFolder()) {
301                     FileObject[] extensionFiles = extensionsDir.getChildren();
302
303                     for (int k = 0; k < extensionFiles.length; k++) {
304                         String JavaDoc extension = extensionFiles[k].getName();
305                         language.addExtension(extension);
306                     }
307                 }
308
309                 FileObject languageFile = mimeFile.getFileObject(LANGUAGE, null);
310
311                 if (languageFile != null) {
312                     language.setGsfLanguageFile(languageFile);
313                 }
314
315                 FileObject parserFile = mimeFile.getFileObject(PARSER, null);
316
317                 if (parserFile != null) {
318                     language.setParserFile(parserFile);
319                 }
320
321                 FileObject completionFile = mimeFile.getFileObject(COMPLETION, null);
322
323                 if (completionFile != null) {
324                     language.setCompletionProviderFile(completionFile);
325                 }
326
327                 FileObject renamerFile = mimeFile.getFileObject(RENAMER, null);
328
329                 if (renamerFile != null) {
330                     language.setInstantRenamerFile(renamerFile);
331                 }
332
333                 FileObject formatterFile = mimeFile.getFileObject(FORMATTER, null);
334
335                 if (formatterFile != null) {
336                     language.setFormatterFile(formatterFile);
337                 }
338
339                 FileObject finderFile = mimeFile.getFileObject(DECLARATION_FINDER, null);
340
341                 if (finderFile != null) {
342                     language.setDeclarationFinderFile(finderFile);
343                 }
344
345                 FileObject bracketFile = mimeFile.getFileObject(BRACKET_COMPLETION, null);
346
347                 if (bracketFile != null) {
348                     language.setBracketCompletionFile(bracketFile);
349                 }
350
351                 FileObject indexerFile = mimeFile.getFileObject(INDEXER, null);
352
353                 if (indexerFile != null) {
354                     language.setIndexerFile(indexerFile);
355                 }
356
357                 FileObject structureFile = mimeFile.getFileObject(STRUCTURE, null);
358
359                 if (structureFile != null) {
360                     language.setStructureFile(structureFile);
361                 }
362
363                 FileObject paletteFile = mimeFile.getFileObject(PALETTE, null);
364
365                 if (paletteFile != null) {
366                     language.setPaletteFile(paletteFile);
367                 }
368             }
369         }
370     }
371
372     /**
373      * Based on code from Schliemann
374      *
375      * @author Jan Jancura
376      */

377     private void initializeLanguage(Language language) {
378         FileSystem fs = Repository.getDefault().getDefaultFileSystem();
379
380         String JavaDoc oldNavFileName =
381             "Navigator/Panels/" + language.getMimeType() +
382             "/org-netbeans-modules-retouche-navigation-GsfStructurePanel.instance";
383
384         // Delete the old navigator description - I have moved the class name
385
FileObject fo = fs.findResource(oldNavFileName);
386
387         if (fo != null) {
388             try {
389                 fo.delete();
390             } catch (IOException JavaDoc ex) {
391                 ErrorManager.getDefault().notify(ex);
392             }
393         }
394
395         String JavaDoc navFileName =
396             "Navigator/Panels/" + language.getMimeType() +
397             "/org-netbeans-modules-retouche-navigation-ClassMemberPanel.instance";
398
399         fo = fs.findResource(navFileName);
400
401         if (fo == null) {
402             try {
403                 FileUtil.createData(fs.getRoot(), navFileName);
404             } catch (IOException JavaDoc ex) {
405                 ErrorManager.getDefault().notify(ex);
406             }
407         }
408     }
409
410     /**
411      * Delayed initialization of editor settings for a language, until the editor
412      * requests the info via mime lookup.
413      *
414      * @todo Ensure that the Options dialog also uses Mime lookup such that this
415      * is initialized in time.
416      *
417      * Based on code from Schliemann
418      *
419      * @author Jan Jancura
420      */

421     void initializeLanguageForEditor(Language l) {
422         FileSystem fs = Repository.getDefault().getDefaultFileSystem();
423         final FileObject root = fs.findResource("Editors/" + l.getMimeType());
424
425         // init old options
426
if (root.getFileObject("Settings.settings") == null) {
427             try {
428                 fs.runAtomicAction(new AtomicAction() {
429                         public void run() {
430                             try {
431                                 InputStream JavaDoc is =
432                                     getClass().getClassLoader()
433                                         .getResourceAsStream("org/netbeans/modules/gsf/GsfOptions.settings");
434
435                                 try {
436                                     FileObject fo = root.createData("Settings.settings");
437                                     OutputStream JavaDoc os = fo.getOutputStream();
438
439                                     try {
440                                         FileUtil.copy(is, os);
441
442                                         // System.out.println("@@@ Successfully created " + fo.getPath());
443
} finally {
444                                         os.close();
445                                     }
446                                 } finally {
447                                     is.close();
448                                 }
449                             } catch (IOException JavaDoc ex) {
450                                 ErrorManager.getDefault().notify(ex);
451                             }
452                         }
453                     });
454             } catch (IOException JavaDoc ex) {
455                 ErrorManager.getDefault().notify(ex);
456             }
457         }
458
459         // init code folding bar
460
if ((root.getFileObject(
461                     "SideBar/org-netbeans-modules-editor-retouche-GsfCodeFoldingSideBarFactory.instance") == null) &&
462                 (l.getParser() != null)) { // XXX Don't construct a new parser just to see this!
463

464             try {
465                 //FileUtil.createData (root, "FoldManager/org-netbeans-editor-CustomFoldManager$Factory.instance");
466
FileUtil.createData(root,
467                     "FoldManager/org-netbeans-modules-retouche-editor-fold-GsfFoldManagerFactory.instance");
468                 FileUtil.createData(root,
469                     "SideBar/org-netbeans-modules-editor-retouche-GsfCodeFoldingSideBarFactory.instance");
470
471                 FileObject fo = root.getFileObject("SideBar");
472                 fo.setAttribute("org-netbeans-editor-GlyphGutter.instance/org-netbeans-modules-editor-retouche-GsfCodeFoldingSideBarFactory.instance",
473                     Boolean.TRUE);
474             } catch (IOException JavaDoc ex) {
475                 ErrorManager.getDefault().notify(ex);
476             }
477         }
478
479         // init hyperlink provider
480
if (root.getFileObject("HyperlinkProviders/GsfHyperlinkProvider.instance") == null) {
481             try {
482                 FileObject fo =
483                     FileUtil.createData(root, "HyperlinkProviders/GsfHyperlinkProvider.instance");
484                 fo.setAttribute("instanceClass",
485                     "org.netbeans.modules.retouche.editor.hyperlink.GsfHyperlinkProvider");
486                 fo.setAttribute("instanceOf",
487                     "org.netbeans.lib.editor.hyperlink.spi.HyperlinkProvider");
488             } catch (IOException JavaDoc ex) {
489                 ErrorManager.getDefault().notify(ex);
490             }
491         }
492
493         // Context menu
494
FileObject popup = root.getFileObject("Popup");
495
496         if (popup == null) {
497             try {
498                 popup = root.createFolder("Popup");
499                 popup.createData("in-place-refactoring");
500                 popup.createData("generate-goto-popup");
501
502                 FileObject sep = popup.createData("SeparatorBeforeCut.instance");
503                 sep.setAttribute("instanceClass", "javax.swing.JSeparator");
504                 popup.setAttribute("SeparatorBeforeCut.instance/org-netbeans-modules-editor-NbSelectInPopupAction.instance",
505                     Boolean.TRUE);
506                 popup.setAttribute("SeparatorBeforeCut.instance/org-openide-actions-CutAction.instance",
507                     Boolean.TRUE);
508                 popup.setAttribute("in-place-refactoring/generate-goto-popup", Boolean.TRUE);
509                 popup.setAttribute("generate-goto-popup/SeparatorBeforeCut.instance", Boolean.TRUE);
510
511             
512                 popup.setAttribute("org-openide-actions-PasteAction.instance/SeparatorBeforeFormat.instance",
513                     Boolean.TRUE);
514                 FileObject sep2 = popup.createData("SeparatorBeforeFormat.instance");
515                 sep2.setAttribute("instanceClass", "javax.swing.JSeparator");
516                 popup.setAttribute("SeparatorBeforeFormat.instance/format",
517                     Boolean.TRUE);
518                 popup.createData("format");
519                 popup.createData("pretty-print");
520                 popup.setAttribute("format/pretty-print", Boolean.TRUE);
521             } catch (IOException JavaDoc ex) {
522                 ErrorManager.getDefault().notify(ex);
523             }
524         } else {
525             // Temporary userdir upgrade
526
if (root.getFileObject("Popup/format") == null) {
527                 try {
528                     popup.createData("format");
529                 } catch (IOException JavaDoc ex) {
530                     ErrorManager.getDefault().notify(ex);
531                 }
532             }
533             if (root.getFileObject("Popup/pretty-print") == null) {
534                 try {
535                     popup.createData("pretty-print");
536                 } catch (IOException JavaDoc ex) {
537                     ErrorManager.getDefault().notify(ex);
538                 }
539             }
540         }
541
542         // Service to show if file is compileable or not
543
if (root.getFileObject(
544                     "UpToDateStatusProvider/org-netbeans-modules-retouche-hints-GsfUpToDateStateProviderFactory.instance") == null) {
545             try {
546                 FileUtil.createData(root,
547                     "UpToDateStatusProvider/org-netbeans-modules-retouche-hints-GsfUpToDateStateProviderFactory.instance");
548             } catch (IOException JavaDoc ex) {
549                 ErrorManager.getDefault().notify(ex);
550             }
551         }
552
553         // I'm not sure what this is used for - perhaps to turn orange when there are unused imports etc.
554
if (root.getFileObject(
555                     "UpToDateStatusProvider/org-netbeans-modules-retouche-editor-semantic-OccurrencesMarkProviderCreator.instance") == null) {
556             try {
557                 FileUtil.createData(root,
558                     "UpToDateStatusProvider/org-netbeans-modules-retouche-editor-semantic-OccurrencesMarkProviderCreator.instance");
559             } catch (IOException JavaDoc ex) {
560                 ErrorManager.getDefault().notify(ex);
561             }
562         }
563
564         // Editor hints -- this may not be necessary - might already be done from the java source tasks factory...
565
String JavaDoc hintsFilename =
566             "Editors/" + l.getMimeType() +
567             "/org-netbeans-modules-retouche-hints-GsfHintsProvider.instance";
568
569         if (fs.findResource(hintsFilename) == null) {
570             try {
571                 FileObject fo = FileUtil.createData(fs.getRoot(), hintsFilename);
572                 fo.setAttribute("instanceOf", "org.netbeans.modules.editor.hints.spi.HintsProvider");
573             } catch (IOException JavaDoc ex) {
574                 ErrorManager.getDefault().notify(ex);
575             }
576         }
577
578         // Code completion
579
FileObject completion = root.getFileObject("CompletionProviders");
580
581         if (completion == null) {
582             try {
583                 completion = root.createFolder("CompletionProviders");
584                 completion.createData(
585                     "org-netbeans-lib-editor-codetemplates-CodeTemplateCompletionProvider.instance");
586                 completion.createData(
587                     "org-netbeans-modules-retouche-editor-completion-GsfCompletionProvider.instance");
588             } catch (IOException JavaDoc ex) {
589                 ErrorManager.getDefault().notify(ex);
590             }
591         }
592
593         // Editor toolbar: commenting and uncommenting actions
594
if (root.getFileObject("Toolbars/Default/comment") == null) {
595             if (!((l.getGsfLanguage() == null) ||
596                     (l.getGsfLanguage().getLineCommentPrefix() == null))) {
597                 try {
598                     FileObject sep =
599                         FileUtil.createData(root,
600                             "Toolbars/Default/Separator-before-comment.instance");
601                     sep.setAttribute("instanceClass", "javax.swing.JSeparator");
602
603                     FileObject folder = root.getFileObject("Toolbars/Default");
604                     folder.setAttribute("stop-macro-recording/Separator-before-comment.instance",
605                         Boolean.TRUE);
606                     FileUtil.createData(root, "Toolbars/Default/comment");
607                     folder.setAttribute("Separator-before-comment.instance/comment", Boolean.TRUE);
608                     FileUtil.createData(root, "Toolbars/Default/uncomment");
609                     folder.setAttribute("comment/uncomment", Boolean.TRUE);
610                 } catch (IOException JavaDoc ex) {
611                     ErrorManager.getDefault().notify(ex);
612                 }
613             }
614         }
615
616         // init code templates
617
if (root.getFileObject("CodeTemplateProcessorFactories") == null) {
618             try {
619                 FileObject fo =
620                     FileUtil.createData(root,
621                         "CodeTemplateProcessorFactories/org-netbeans-modules-retouche-editor-codetemplates-GsfCodeTemplateProcessor$Factory.instance");
622             } catch (IOException JavaDoc ex) {
623                 ErrorManager.getDefault().notify(ex);
624             }
625         }
626
627         // Temporarily disabled; each language does it instead
628
//initializeColoring(l);
629
}
630
631     // void initializeColoring(Language l) {
632
// FileSystem fs = Repository.getDefault().getDefaultFileSystem();
633
// final FileObject root = fs.findResource("Editors/" + l.getMimeType());
634
//
635
// // Initialize Coloring
636
// if (l.getGsfLanguage() != null) {
637
// List<?extends TokenId> types = l.getGsfLanguage().getRelevantTokenTypes();
638
//
639
// if ((types != null) && (types.size() > 0)) {
640
// //String prefix = "gls-";
641
// String prefix = "";
642
//
643
// // Default categories
644
// Collection defaults =
645
// EditorSettings.getDefault().getDefaultFontColorDefaults("NetBeans");
646
// Map defaultsMap = new HashMap();
647
// Iterator it = defaults.iterator(); // check if IDE Defaults module is installed
648
//
649
// while (it.hasNext()) {
650
// AttributeSet as = (AttributeSet)it.next();
651
// defaultsMap.put(as.getAttribute(StyleConstants.NameAttribute), as);
652
// }
653
//
654
// // current colors
655
// FontColorSettingsFactory fcsf =
656
// EditorSettings.getDefault()
657
// .getFontColorSettings(new String[] { l.getMimeType() });
658
// Collection colors = fcsf.getAllFontColors("NetBeans"); // NOI18N
659
// Map colorsMap = new HashMap();
660
// it = colors.iterator();
661
//
662
// while (it.hasNext()) {
663
// AttributeSet as = (AttributeSet)it.next();
664
// colorsMap.put(as.getAttribute(StyleConstants.NameAttribute), as);
665
// }
666
//
667
// for (TokenId id : types) {
668
// TokenType type = l.getGsfLanguage().getTokenType(id);
669
//
670
// if (type == null) {
671
// type = DefaultTokenType.getTokenType(id);
672
// }
673
//
674
// if (type == null) {
675
// continue;
676
// }
677
//
678
// //String colorName = type.getName();
679
// String colorName = id.name();
680
// String category = type.getCategory();
681
// SimpleAttributeSet as = new SimpleAttributeSet();
682
// as.addAttribute(StyleConstants.NameAttribute, colorName);
683
//
684
// if (colorName != null) {
685
// addColor(colorName, category, as, l, colorsMap, defaultsMap, prefix,
686
// type.getDisplayName(), type.getColor(), type.getBackgroundColor(),
687
// type.getFontType());
688
// } else {
689
// System.err.println("skipping null colorName for " + type);
690
// }
691
// }
692
//
693
// fcsf.setAllFontColorsDefaults("NetBeans", colorsMap.values());
694
// fcsf.setAllFontColors("NetBeans", colorsMap.values());
695
// }
696
// }
697
// }
698
//
699
// /**
700
// * Based on code from Schliemann
701
// *
702
// * @author Jan Jancura
703
// * @author Tor Norbye
704
// */
705
// private void addColor(String colorName, String category, SimpleAttributeSet sas, Language l,
706
// Map colorsMap, Map defaultsMap, String prefix, String displayName, Color fg, Color bg,
707
// int fontMode) {
708
// String color = colorName;
709
//
710
// String pcolor = prefix + color;
711
//
712
// if (sas == null) {
713
// sas = new SimpleAttributeSet();
714
// }
715
//
716
// sas.addAttribute(StyleConstants.NameAttribute, pcolor);
717
// sas.addAttribute(EditorStyleConstants.DisplayName, displayName);
718
//
719
// if (defaultsMap.containsKey(category)) {
720
// sas.addAttribute(EditorStyleConstants.Default, category);
721
// } else {
722
// if (fg != null) {
723
// sas.addAttribute(StyleConstants.Foreground, fg);
724
// }
725
//
726
// if (bg != null) {
727
// sas.addAttribute(StyleConstants.Background, bg);
728
// }
729
//
730
// if ((fontMode & Font.BOLD) != 0) {
731
// sas.addAttribute(StyleConstants.Bold, Boolean.TRUE);
732
// }
733
//
734
// if ((fontMode & Font.ITALIC) != 0) {
735
// sas.addAttribute(StyleConstants.Italic, Boolean.TRUE);
736
// }
737
// }
738
//
739
// colorsMap.put(pcolor, sas);
740
// }
741
}
742
Popular Tags