Add script editor highlighting using RSyntaxTextArea

This commit is contained in:
Sampo Niskanen 2014-12-27 20:20:32 +02:00
parent a2c0af3b7f
commit eb5321e82c
4 changed files with 13 additions and 6 deletions

View File

@ -21,5 +21,6 @@
<classpathentry kind="lib" path="resources"/>
<classpathentry kind="lib" path="/OpenRocket Core/lib/annotation-detector-3.0.2.jar"/>
<classpathentry kind="lib" path="lib/miglayout-4.0-swing.jar" sourcepath="reference/miglayout-4.0-sources.jar"/>
<classpathentry kind="lib" path="lib/rsyntaxtextarea-2.5.6.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -105,6 +105,7 @@
<zipfileset src="${core.dir}/lib/slf4j-api-1.7.5.jar"/>
<zipfileset src="${lib.dir}/logback-classic-1.0.12.jar"/>
<zipfileset src="${lib.dir}/logback-core-1.0.12.jar"/>
<zipfileset src="${lib.dir}/rsyntaxtextarea-2.5.6.jar"/>
<!-- JOGL libraries need to be jar-in-jar -->

Binary file not shown.

View File

@ -1,20 +1,22 @@
package net.sf.openrocket.simulation.extension.impl;
import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.components.StyledLabel;
import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.plugin.Plugin;
import net.sf.openrocket.simulation.extension.AbstractSwingSimulationExtensionConfigurator;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
@Plugin
public class ScriptingConfigurator extends AbstractSwingSimulationExtensionConfigurator<ScriptingExtension> {
@ -27,11 +29,13 @@ public class ScriptingConfigurator extends AbstractSwingSimulationExtensionConfi
panel.add(new StyledLabel(trans.get("SimulationExtension.scripting.script.label"), Style.BOLD), "wrap");
final JTextArea text = new JTextArea(extension.getScript(), 20, 60);
final RSyntaxTextArea text = new RSyntaxTextArea(extension.getScript(), 15, 60);
text.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
text.setCodeFoldingEnabled(true);
text.setLineWrap(true);
text.setWrapStyleWord(true);
text.setEditable(true);
GUIUtil.setTabToFocusing(text);
text.setCurrentLineHighlightColor(new Color(255, 255, 230));
text.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent event) {
@ -46,7 +50,8 @@ public class ScriptingConfigurator extends AbstractSwingSimulationExtensionConfi
}
});
panel.add(new JScrollPane(text), "grow");
RTextScrollPane scroll = new RTextScrollPane(text);
panel.add(scroll, "grow");
return panel;
}