preferences for syntax highlighting theme

This commit is contained in:
ricardo.jl.rufino 2015-04-22 16:57:34 -03:00 committed by Federico Fissore
parent 45094a9d52
commit 1e61cd6b4c
6 changed files with 190 additions and 14 deletions

View File

@ -253,11 +253,11 @@ public class Editor extends JFrame implements RunnerListener {
lineStatus = new EditorLineStatus(textarea);
consolePanel.add(lineStatus, BorderLayout.SOUTH);
//scrollPane = new RTextScrollPane(textarea);
// RTextScrollPane
scrollPane = new RTextScrollPane(textarea, true);
scrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
scrollPane.setIconRowHeaderEnabled(true);
scrollPane.setLineNumbersEnabled(Preferences.getBoolean("editor.linenumbers"));
scrollPane.setIconRowHeaderEnabled(false);
Gutter gutter = scrollPane.getGutter();
gutter.setBookmarkingEnabled(false);
@ -450,7 +450,7 @@ public class Editor extends JFrame implements RunnerListener {
saveMenuItem.setEnabled(!external);
saveAsMenuItem.setEnabled(!external);
textarea.setMarginLineEnabled(PreferencesData.getBoolean("editor.linenumbers"));
scrollPane.setLineNumbersEnabled(PreferencesData.getBoolean("editor.linenumbers"));
if (external) {
// disable line highlight and turn off the caret when disabling
@ -479,6 +479,8 @@ public class Editor extends JFrame implements RunnerListener {
//sketchbook.rebuildMenus();
// For 0126, moved into Base, which will notify all editors.
//base.rebuildMenusAsync();
textarea.setTheme(Preferences.get("editor.syntax_theme"));
}
@ -956,6 +958,7 @@ public class Editor extends JFrame implements RunnerListener {
SketchTextArea textArea = new SketchTextArea();
textArea.requestFocusInWindow();
textArea.setMarkOccurrences(true);
textArea.setMarginLineEnabled(false);
textArea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.codefolding"));
textArea.setAntiAliasingEnabled(PreferencesData.getBoolean("editor.antialias"));
// textArea.setClearWhitespaceLinesEnabled(false);

View File

@ -230,6 +230,7 @@ public class Preferences {
JCheckBox autoAssociateBox;
JComboBox comboLanguage;
JComboBox comboWarnings;
JComboBox comboSyntaxThemes;
JCheckBox saveVerifyUploadBox;
JTextField proxyHTTPServer;
JTextField proxyHTTPPort;
@ -357,7 +358,27 @@ public class Preferences {
fontSizeField.setText(String.valueOf(editorFont.getSize()));
top += d.height + GUI_BETWEEN;
// Syntax Coloring [ ]
box = Box.createHorizontalBox();
label = new JLabel(_("Syntax Coloring: "));
box.add(label);
String[] syntaxThemes = new String[]{"default","dark"};
comboSyntaxThemes = new JComboBox(syntaxThemes);
String currentTheme = PreferencesData.get("editor.syntax_theme", "default");
for (String item : syntaxThemes) {
if (currentTheme.equals(item)) {
comboSyntaxThemes.setSelectedItem(item);
}
}
box.add(comboSyntaxThemes);
pane.add(box);
d = box.getPreferredSize();
box.setForeground(Color.gray);
box.setBounds(left, top, d.width, d.height);
right = Math.max(right, left + d.width);
top += d.height + GUI_BETWEEN;
// Show verbose output during: [ ] compilation [ ] upload
box = Box.createHorizontalBox();
@ -746,6 +767,7 @@ public class Preferences {
PreferencesData.set("sketchbook.path", newPath);
}
PreferencesData.set("editor.syntax_theme", comboSyntaxThemes.getSelectedItem().toString());
PreferencesData.setBoolean("editor.external", externalEditorBox.isSelected());
PreferencesData.setBoolean("update.check", checkUpdatesBox.isSelected());
PreferencesData.setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());

View File

@ -21,14 +21,12 @@ import javax.swing.text.Segment;
import javax.swing.undo.UndoManager;
import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip;
import org.fife.ui.rtextarea.RUndoManager;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.EditorLineStatus;
import processing.app.EditorListener;
import processing.app.*;
/**
* Arduino Sketch code editor based on RSyntaxTextArea (http://fifesoft.com/rsyntaxtextarea)
@ -57,9 +55,18 @@ public class SketchTextArea extends RSyntaxTextArea {
protected void installFeatures(){
setTheme(PreferencesData.get("editor.syntax_theme", "default"));
setLinkGenerator(new DocLinkGenerator());
fixControlTab();
installTokenMaker();
}
public void setTheme(String name){
FileInputStream defaultXmlInputStream = null;
try {
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/default.xml"));
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/"+name+".xml"));
Theme theme = Theme.load(defaultXmlInputStream);
theme.apply(this);
} catch (IOException e) {
@ -73,11 +80,6 @@ public class SketchTextArea extends RSyntaxTextArea {
}
}
}
setLinkGenerator(new DocLinkGenerator());
fixControlTab();
installTokenMaker();
}
// Removing the default focus traversal keys

View File

@ -86,6 +86,8 @@ editor.window.height.min = 290
# tested to be 515 on Windows XP, this leaves some room
#editor.window.height.min.windows = 530
# Syntax coloring ( on lib/theme/syntax )
editor.syntax_theme = default
# font size for editor
editor.font=Monospaced,plain,12

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE RSyntaxTheme SYSTEM "theme.dtd">
<!--
Dark theme based off of Notepad++'s Obsidian theme.
See theme.dtd and org.fife.ui.rsyntaxtextarea.Theme for more information.
-->
<RSyntaxTheme version="1.0">
<!-- Omitting baseFont will use a system-appropriate monospaced. -->
<!--<baseFont family="..." size="13"/>-->
<!-- General editor colors. -->
<background color="293134"/>
<caret color="c1cbc2"/>
<selection useFG="false" bg="404E51" roundedEdges="false"/>
<currentLineHighlight color="2F393C" fade="false"/>
<marginLine fg="394448"/>
<markAllHighlight color="6b8189"/> <!-- TODO: Fix me -->
<markOccurrencesHighlight color="5b7179" border="false"/>
<matchedBracket fg="6A8088" bg="6b8189" highlightBoth="false" animate="true"/>
<hyperlinks fg="a082bd"/>
<secondaryLanguages>
<language index="1" bg="333344"/>
<language index="2" bg="223322"/>
<language index="3" bg="332222"/>
</secondaryLanguages>
<!-- Gutter styling. -->
<gutterBorder color="81969A"/>
<lineNumbers fg="81969A"/>
<foldIndicator fg="6A8088" iconBg="2f383c"/>
<iconRowHeader activeLineRange="3399ff"/>
<!-- Syntax tokens. -->
<tokenStyles>
<style token="IDENTIFIER" fg="E0E2E4"/>
<style token="RESERVED_WORD" fg="93C763" bold="true"/>
<style token="RESERVED_WORD_2" fg="93C763" bold="true"/>
<style token="ANNOTATION" fg="E8E2B7"/>
<style token="COMMENT_DOCUMENTATION" fg="6C788C"/>
<style token="COMMENT_EOL" fg="66747B"/>
<style token="COMMENT_MULTILINE" fg="66747B"/>
<style token="COMMENT_KEYWORD" fg="ae9fbf"/>
<style token="COMMENT_MARKUP" fg="ae9fbf"/>
<style token="FUNCTION" fg="E0E2E4"/>
<style token="DATA_TYPE" fg="678CB1" bold="true"/>
<style token="LITERAL_BOOLEAN" fg="93C763" bold="true"/>
<style token="LITERAL_NUMBER_DECIMAL_INT" fg="FFCD22"/>
<style token="LITERAL_NUMBER_FLOAT" fg="FFCD22"/>
<style token="LITERAL_NUMBER_HEXADECIMAL" fg="FFCD22"/>
<style token="LITERAL_STRING_DOUBLE_QUOTE" fg="EC7600"/>
<style token="LITERAL_CHAR" fg="EC7600"/>
<style token="LITERAL_BACKQUOTE" fg="EC7600"/>
<style token="MARKUP_TAG_DELIMITER" fg="678CB1"/>
<style token="MARKUP_TAG_NAME" fg="ABBFD3" bold="true"/>
<style token="MARKUP_TAG_ATTRIBUTE" fg="B3B689"/>
<style token="MARKUP_TAG_ATTRIBUTE_VALUE" fg="e1e2cf"/>
<style token="MARKUP_COMMENT" fg="66747B"/>
<style token="MARKUP_DTD" fg="A082BD"/>
<style token="MARKUP_PROCESSING_INSTRUCTION" fg="A082BD"/>
<style token="MARKUP_CDATA" fg="d5e6f0"/>
<style token="MARKUP_CDATA_DELIMITER" fg="ae9fbf"/>
<style token="MARKUP_ENTITY_REFERENCE" fg="678CB1"/>
<style token="OPERATOR" fg="E8E2B7"/>
<style token="PREPROCESSOR" fg="A082BD"/>
<style token="REGEX" fg="d39745"/>
<style token="SEPARATOR" fg="E8E2B7"/>
<style token="VARIABLE" fg="ae9fbf" bold="true"/>
<style token="WHITESPACE" fg="E0E2E4"/>
<style token="ERROR_IDENTIFIER" fg="E0E2E4" bg="04790e"/>
<style token="ERROR_NUMBER_FORMAT" fg="E0E2E4" bg="04790e"/>
<style token="ERROR_STRING_DOUBLE" fg="E0E2E4" bg="04790e"/>
<style token="ERROR_CHAR" fg="E0E2E4" bg="04790e"/>
</tokenStyles>
</RSyntaxTheme>

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE RSyntaxTheme SYSTEM "theme.dtd">
<!--
RSyntaxTextArea's default theme.
See theme.dtd and org.fife.ui.rsyntaxtextarea.Theme for more information.
-->
<RSyntaxTheme version="1.0">
<!-- Omitting baseFont will use a system-appropriate monospaced. -->
<!--<baseFont family="..." size="13"/>-->
<!-- General editor colors. -->
<background color="ffffff"/>
<caret color="424242"/>
<selection fg="ffffff" bg="4a90d9" />
<currentLineHighlight color="ffffaa" fade="false"/>
<marginLine fg="b0b4b9"/>
<markAllHighlight color="ffc800"/>
<markOccurrencesHighlight color="d4d4d4" border="false"/>
<matchedBracket fg="000080" bg="eaeaff" highlightBoth="false" animate="true"/>
<hyperlinks fg="0000ff"/>
<secondaryLanguages>
<language index="1" bg="fff0cc"/>
<language index="2" bg="dafeda"/>
<language index="3" bg="ffe0f0"/>
</secondaryLanguages>
<!-- Gutter styling. -->
<gutterBorder color="dddddd"/>
<lineNumbers fg="787878"/>
<foldIndicator fg="808080" iconBg="ffffff"/>
<iconRowHeader activeLineRange="3399ff"/>
<!-- Syntax tokens. -->
<tokenStyles>
<style token="IDENTIFIER" fg="000000"/>
<style token="DATA_TYPE" fg="008080" bold="true"/>
<style token="FUNCTION" fg="cc6600"/>
<style token="VARIABLE" fg="cc6600" bold="true"/>
<style token="RESERVED_WORD" fg="024f8b" bold="true"/>
<style token="RESERVED_WORD_2" fg="008080" bold="false"/>
<style token="PREPROCESSOR" fg="024f8b" bold="false"/>
<style token="ANNOTATION" fg="808080"/>
<style token="COMMENT_DOCUMENTATION" fg="7e7e7e"/>
<style token="COMMENT_EOL" fg="7e7e7e"/>
<style token="COMMENT_MULTILINE" fg="7e7e7e"/>
<style token="COMMENT_KEYWORD" fg="7F9FBF" bold="true"/>
<style token="COMMENT_MARKUP" fg="7f7f9f"/>
<style token="LITERAL_BOOLEAN" fg="ff0000" bold="false"/>
<style token="LITERAL_NUMBER_DECIMAL_INT" fg="ff0000"/>
<style token="LITERAL_NUMBER_FLOAT" fg="ff0000"/>
<style token="LITERAL_NUMBER_HEXADECIMAL" fg="ff0000"/>
<style token="LITERAL_STRING_DOUBLE_QUOTE" fg="006699"/>
<style token="LITERAL_CHAR" fg="DC009C"/>
<style token="LITERAL_BACKQUOTE" fg="DC009C"/>
<style token="OPERATOR" fg="804040"/>
<style token="REGEX" fg="008040"/>
<style token="SEPARATOR" fg="000000" />
<style token="WHITESPACE" fg="000000"/>
<style token="ERROR_IDENTIFIER" fg="000000" />
<style token="ERROR_NUMBER_FORMAT" fg="000000" />
<style token="ERROR_STRING_DOUBLE" fg="000000" />
<style token="ERROR_CHAR" fg="000000" />
</tokenStyles>
</RSyntaxTheme>