Added plaintext highlighting
This commit is contained in:
parent
6316c1d5f9
commit
0b46331314
3 changed files with 32 additions and 3 deletions
|
@ -2,6 +2,7 @@ package com.rohitawate.everest.controllers.codearea;
|
||||||
|
|
||||||
import com.rohitawate.everest.controllers.codearea.highlighters.Highlighter;
|
import com.rohitawate.everest.controllers.codearea.highlighters.Highlighter;
|
||||||
import com.rohitawate.everest.controllers.codearea.highlighters.JSONHighlighter;
|
import com.rohitawate.everest.controllers.codearea.highlighters.JSONHighlighter;
|
||||||
|
import com.rohitawate.everest.controllers.codearea.highlighters.PlaintextHighlighter;
|
||||||
import com.rohitawate.everest.controllers.codearea.highlighters.XMLHighlighter;
|
import com.rohitawate.everest.controllers.codearea.highlighters.XMLHighlighter;
|
||||||
import com.rohitawate.everest.util.settings.Settings;
|
import com.rohitawate.everest.util.settings.Settings;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
@ -15,8 +16,10 @@ public class EverestCodeArea extends CodeArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Highlighter highlighter;
|
private Highlighter highlighter;
|
||||||
private JSONHighlighter jsonHighlighter;
|
|
||||||
private XMLHighlighter xmlHighlighter;
|
private static JSONHighlighter jsonHighlighter;
|
||||||
|
private static XMLHighlighter xmlHighlighter;
|
||||||
|
private static PlaintextHighlighter plaintextHighlighter;
|
||||||
|
|
||||||
public EverestCodeArea() {
|
public EverestCodeArea() {
|
||||||
this.getStylesheets().add(getClass().getResource("/css/syntax/Moondust.css").toString());
|
this.getStylesheets().add(getClass().getResource("/css/syntax/Moondust.css").toString());
|
||||||
|
@ -26,6 +29,7 @@ public class EverestCodeArea extends CodeArea {
|
||||||
|
|
||||||
jsonHighlighter = new JSONHighlighter();
|
jsonHighlighter = new JSONHighlighter();
|
||||||
xmlHighlighter = new XMLHighlighter();
|
xmlHighlighter = new XMLHighlighter();
|
||||||
|
plaintextHighlighter = new PlaintextHighlighter();
|
||||||
|
|
||||||
setMode(HighlightMode.PLAIN);
|
setMode(HighlightMode.PLAIN);
|
||||||
|
|
||||||
|
@ -39,9 +43,12 @@ public class EverestCodeArea extends CodeArea {
|
||||||
case JSON:
|
case JSON:
|
||||||
highlighter = jsonHighlighter;
|
highlighter = jsonHighlighter;
|
||||||
break;
|
break;
|
||||||
default:
|
case XML:
|
||||||
|
case HTML:
|
||||||
highlighter = xmlHighlighter;
|
highlighter = xmlHighlighter;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
highlighter = plaintextHighlighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-computes the highlighting for the new mode
|
// Re-computes the highlighting for the new mode
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.rohitawate.everest.controllers.codearea.highlighters;
|
||||||
|
|
||||||
|
import org.fxmisc.richtext.model.StyleSpans;
|
||||||
|
import org.fxmisc.richtext.model.StyleSpansBuilder;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class PlaintextHighlighter implements Highlighter {
|
||||||
|
@Override
|
||||||
|
public StyleSpans<Collection<String>> computeHighlighting(String text) {
|
||||||
|
StyleSpansBuilder<Collection<String>> spansBuilder
|
||||||
|
= new StyleSpansBuilder<>();
|
||||||
|
|
||||||
|
spansBuilder.add(Collections.singleton("plain-text"), text.length());
|
||||||
|
return spansBuilder.create();
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,10 @@
|
||||||
-fx-stroke: white;
|
-fx-stroke: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.plain-text {
|
||||||
|
-fx-fill: azure !important;
|
||||||
|
}
|
||||||
|
|
||||||
/*Common to JSON and XML*/
|
/*Common to JSON and XML*/
|
||||||
|
|
||||||
.xml_bracket,
|
.xml_bracket,
|
||||||
|
|
Loading…
Reference in a new issue