11package com .ss .editor .ui .component .editor .impl ;
22
3- import static java .util .Collections .singleton ;
43import com .ss .editor .FileExtensions ;
54import com .ss .editor .Messages ;
65import com .ss .editor .annotation .FXThread ;
76import com .ss .editor .annotation .FromAnyThread ;
87import com .ss .editor .ui .component .editor .EditorDescription ;
9- import org . fxmisc . richtext . model . StyleSpans ;
10- import org . fxmisc . richtext . model . StyleSpansBuilder ;
8+ import com . ss . editor . ui . control . code . BaseCodeArea ;
9+ import com . ss . editor . ui . control . code . MaterialDefinitionCodeArea ;
1110import org .jetbrains .annotations .NotNull ;
1211
13- import java .util .Collection ;
14- import java .util .regex .Matcher ;
15- import java .util .regex .Pattern ;
16-
1712/**
1813 * The implementation of editor to edit material definition files.
1914 *
@@ -34,112 +29,10 @@ public class MaterialDefinitionFileEditor extends CodeAreaFileEditor {
3429 DESCRIPTION .addExtension (FileExtensions .JME_MATERIAL_DEFINITION );
3530 }
3631
37- @ NotNull
38- private static final String [] KEYWORDS = {
39- "MaterialDef" , "MaterialParameters" , "Technique" , "WorldParameters" , "Defines" , "ForcedRenderState"
40- };
41-
42- @ NotNull
43- private static final String [] VALUE_TYPES = {
44- "Texture2D" , "Float" , "Boolean" , "Int" , "Color" , "Vector3" , "TextureCubeMap" , "Matrix4" , "Vector4" , "Vector2" ,
45- "VertexShader" , "TessellationEvaluationShader " , "TessellationControlShader" , "FragmentShader" , "LightMode" ,
46- "WorldViewProjectionMatrix" , "Time" , "NormalMatrix" , "WorldViewMatrix" ,
47- "ViewMatrix" , "CameraPosition" , "WorldMatrix" , "FaceCull" , "DepthTest" , "DepthWrite" , "PolyOffset" ,
48- "ColorWrite" , "Blend" , "Resolution" , "FragmentShader" , "ViewProjectionMatrix" ,
49- "IntArray" , "FloatArray" , "Vector2Array" , "Vector3Array" , "Vector4Array" , "Matrix3" ,
50- "Matrix3Array" , "Matrix4Array" , "TextureBuffer" , "Texture3D" , "TextureArray" , "GeometryShader"
51- };
52-
53- @ NotNull
54- private static final String [] VALUE_VALUES = {
55- "true" , "false" , "Off" , "On" , "True" , "False" , "Disable" , "SinglePass" , "MultiPass" ,
56- "SinglePassAndImageBased" , "FixedPipeline" , "StaticPass" , "InPass" , "PostPass" , "World" , "View" ,
57- "Legacy" , "GLSL100" , "GLSL110" , "GLSL120" , "GLSL130" , "GLSL140" , "GLSL150" , "GLSL400" , "GLSL330" ,
58- "GLSL410" , "GLSL420" , "GLSL430" , "GLSL440" , "GLSL450" ,
59- };
60-
61- private static final String KEYWORD_PATTERN = "\\ b(" + String .join ("|" , KEYWORDS ) + ")\\ b" ;
62- private static final String VALUE_TYPE_PATTERN = "\\ b(" + String .join ("|" , VALUE_TYPES ) + ")\\ b" ;
63- private static final String VALUE_VALUE_PATTERN = "\\ b(" + String .join ("|" , VALUE_VALUES ) + ")\\ b" ;
64- private static final String PAREN_PATTERN = "\\ (|\\ )" ;
65- private static final String BRACE_PATTERN = "\\ {|\\ }" ;
66- private static final String BRACKET_PATTERN = "\\ [|\\ ]" ;
67- private static final String SEMICOLON_PATTERN = "\\ ;" ;
68- private static final String STRING_PATTERN = "\" ([^\" \\ \\ ]|\\ \\ .)*\" " ;
69- private static final String COMMENT_PATTERN = "//[^\n ]*" + "|" + "/\\ *(.|\\ R)*?\\ */" ;
70-
71- private static final Pattern PATTERN = Pattern .compile (
72- "(?<KEYWORD>" + KEYWORD_PATTERN + ")"
73- + "|(?<VALUETYPE>" + VALUE_TYPE_PATTERN + ")"
74- + "|(?<VALUEVALUE>" + VALUE_VALUE_PATTERN + ")"
75- + "|(?<PAREN>" + PAREN_PATTERN + ")"
76- + "|(?<BRACE>" + BRACE_PATTERN + ")"
77- + "|(?<BRACKET>" + BRACKET_PATTERN + ")"
78- + "|(?<SEMICOLON>" + SEMICOLON_PATTERN + ")"
79- + "|(?<STRING>" + STRING_PATTERN + ")"
80- + "|(?<COMMENT>" + COMMENT_PATTERN + ")"
81- );
82-
83- private static StyleSpans <Collection <String >> computeHighlighting (final String text ) {
84-
85- final Matcher matcher = PATTERN .matcher (text );
86- final StyleSpansBuilder <Collection <String >> spansBuilder = new StyleSpansBuilder <>();
87-
88- int lastKwEnd = 0 ;
89-
90- while (matcher .find ()) {
91-
92- String styleClass = matcher .group ("KEYWORD" ) != null ? "keyword" : null ;
93-
94- if (styleClass == null ) {
95- styleClass = matcher .group ("VALUETYPE" ) != null ? "value-type" : null ;
96- }
97-
98- if (styleClass == null ) {
99- styleClass = matcher .group ("VALUEVALUE" ) != null ? "value-value" : null ;
100- }
101-
102- if (styleClass == null ) {
103- styleClass = matcher .group ("PAREN" ) != null ? "paren" : null ;
104- }
105-
106- if (styleClass == null ) {
107- styleClass = matcher .group ("BRACE" ) != null ? "brace" : null ;
108- }
109-
110- if (styleClass == null ) {
111- styleClass = matcher .group ("BRACKET" ) != null ? "bracket" : null ;
112- }
113-
114- if (styleClass == null ) {
115- styleClass = matcher .group ("SEMICOLON" ) != null ? "semicolon" : null ;
116- }
117-
118- if (styleClass == null ) {
119- styleClass = matcher .group ("STRING" ) != null ? "string" : null ;
120- }
121-
122- if (styleClass == null ) {
123- styleClass = matcher .group ("COMMENT" ) != null ? "comment" : null ;
124- }
125-
126- assert styleClass != null ;
127-
128- spansBuilder .add (singleton ("plain-code" ), matcher .start () - lastKwEnd );
129- spansBuilder .add (singleton (styleClass ), matcher .end () - matcher .start ());
130-
131- lastKwEnd = matcher .end ();
132- }
133-
134- spansBuilder .add (singleton ("plain-code" ), text .length () - lastKwEnd );
135-
136- return spansBuilder .create ();
137- }
138-
13932 @ Override
14033 @ FXThread
141- protected @ NotNull StyleSpans <? extends Collection < String >> getStyleSpans ( @ NotNull final String text ) {
142- return computeHighlighting ( text );
34+ protected @ NotNull BaseCodeArea createCodeArea ( ) {
35+ return new MaterialDefinitionCodeArea ( );
14336 }
14437
14538 @ Override
0 commit comments