source: other-projects/rsyntax-textarea/src/java/org/fife/ui/rsyntaxtextarea/folding/FoldParserManager.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 3.2 KB
Line 
1/*
2 * 10/08/2011
3 *
4 * FoldParserManager.java - Used by RSTA to determine what fold parser to use
5 * for each language it supports.
6 *
7 * This library is distributed under a modified BSD license. See the included
8 * RSyntaxTextArea.License.txt file for details.
9 */
10package org.fife.ui.rsyntaxtextarea.folding;
11
12import java.util.HashMap;
13import java.util.Map;
14
15import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
16
17
18/**
19 * Manages fold parsers. Instances of <code>RSyntaxTextArea</code> call into
20 * this class to retrieve fold parsers for whatever language they're editing.
21 * Folks implementing custom languages can add a {@link FoldParser}
22 * implementation for their language to this manager and it will be used by
23 * RSTA.
24 *
25 * @author Robert Futrell
26 * @version 1.0
27 */
28public class FoldParserManager implements SyntaxConstants {
29
30 /**
31 * Map from syntax styles to fold parsers.
32 */
33 private Map foldParserMap;
34
35 private static final FoldParserManager INSTANCE = new FoldParserManager();
36
37
38 /**
39 * Private constructor to prevent instantiation.
40 */
41 private FoldParserManager() {
42 foldParserMap = createFoldParserMap();
43 }
44
45
46 /**
47 * Adds a mapping from a syntax style to a fold parser. The parser
48 * specified will be shared among all RSTA instances editing that language,
49 * so it should be stateless (which should not be difficult for a fold
50 * parser). You can also override the fold parser for built-in languages,
51 * such as <code>SYNTAX_STYLE_JAVA</code>, with your own parser
52 * implementations.
53 *
54 * @param syntaxStyle The syntax style.
55 * @param parser The parser.
56 * @see SyntaxConstants
57 */
58 public void addFoldParserMapping(String syntaxStyle, FoldParser parser) {
59 foldParserMap.put(syntaxStyle, parser);
60 }
61
62
63 /**
64 * Creates the syntax style-to-fold parser mapping for built-in languages.
65 * @return
66 */
67 private Map createFoldParserMap() {
68
69 Map map = new HashMap();
70
71 map.put(SYNTAX_STYLE_C, new CurlyFoldParser());
72 map.put(SYNTAX_STYLE_CPLUSPLUS, new CurlyFoldParser());
73 map.put(SYNTAX_STYLE_CSHARP, new CurlyFoldParser());
74 map.put(SYNTAX_STYLE_CSS, new CurlyFoldParser());
75 map.put(SYNTAX_STYLE_GROOVY, new CurlyFoldParser());
76 map.put(SYNTAX_STYLE_JAVA, new CurlyFoldParser(true, true));
77 map.put(SYNTAX_STYLE_JAVASCRIPT, new CurlyFoldParser());
78 map.put(SYNTAX_STYLE_LATEX, new LatexFoldParser());
79 map.put(SYNTAX_STYLE_MXML, new XmlFoldParser());
80 map.put(SYNTAX_STYLE_PERL, new CurlyFoldParser());
81 map.put(SYNTAX_STYLE_XML, new XmlFoldParser());
82
83 return map;
84
85 }
86
87
88 /**
89 * Returns the singleton instance of this class.
90 *
91 * @return The singleton instance.
92 */
93 public static FoldParserManager get() {
94 return INSTANCE;
95 }
96
97
98 /**
99 * Returns a fold parser to use for an editor highlighting code of a
100 * specific language.
101 *
102 * @param syntaxStyle A value from {@link SyntaxConstants}, such as
103 * <code>SYNTAX_STYLE_JAVA</code>.
104 * @return A fold parser to use, or <code>null</code> if none is registered
105 * for the language.
106 */
107 public FoldParser getFoldParser(String syntaxStyle) {
108 return (FoldParser)foldParserMap.get(syntaxStyle);
109 }
110
111
112}
Note: See TracBrowser for help on using the repository browser.