Skip to content

Commit c17930a

Browse files
committed
Added Ruby syntax highlighting based on RSyntaxTextArea
1 parent ce16265 commit c17930a

4 files changed

Lines changed: 53 additions & 23 deletions

File tree

RubyScript/.classpath

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4-
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5-
<classpathentry kind="src" path="src"/>
6-
<classpathentry exported="true" kind="lib" path="lib/jruby-complete-1.7.9.jar"/>
7-
<classpathentry kind="output" path="bin"/>
8-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry exported="true" kind="lib" path="lib/jruby-complete-1.7.9.jar"/>
7+
<classpathentry kind="lib" path="lib/rsyntaxtextarea.jar"/>
8+
<classpathentry kind="output" path="bin"/>
9+
</classpath>

RubyScript/build.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ bin.includes = plugin.xml,\
55
lib/jruby-complete-1.7.9.jar,\
66
rb/knime.rb,\
77
icons/,\
8-
rb/README.rdoc
8+
rb/README.rdoc,\
9+
lib/rsyntaxtextarea.jar
910
src.includes = lib/jruby-complete-1.7.9.jar,\
1011
rb/knime.rb,\
1112
icons/,\
12-
rb/README.rdoc
13+
rb/README.rdoc,\
14+
lib/rsyntaxtextarea.jar

RubyScript/lib/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Prerequisits
2+
============
3+
4+
1. Download jruby-complete-x.x.x.jar from http://www.jruby.org/download and
5+
place it in this directory.
6+
7+
2. Download RSyntaxTextArea from https://github.com/bobbylight/RSyntaxTextArea,
8+
build it and place rsyntaxtextarea.jar in this directory.

RubyScript/src/org/knime/ext/jruby/RubyScriptNodeDialog.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
package org.knime.ext.jruby;
1010

1111
import java.awt.BorderLayout;
12+
import java.awt.Color;
1213
import java.awt.Component;
13-
import java.awt.Font;
1414
import java.awt.event.*;
1515
import java.io.BufferedReader;
1616
import java.io.File;
@@ -25,18 +25,28 @@
2525
import javax.swing.JFileChooser;
2626
import javax.swing.JLabel;
2727
import javax.swing.JPanel;
28-
import javax.swing.JScrollPane;
2928
import javax.swing.JTable;
30-
import javax.swing.JTextArea;
3129
import javax.swing.table.TableColumn;
3230
import javax.swing.table.TableCellEditor;
31+
import javax.swing.text.BadLocationException;
32+
3333
import org.knime.core.data.DataTableSpec;
3434
import org.knime.core.node.*;
3535

36+
//import javax.swing.JScrollPane;
37+
//import javax.swing.JTextArea;
38+
//import java.awt.Font;
39+
40+
import org.fife.ui.rtextarea.*;
41+
import org.fife.ui.rsyntaxtextarea.*;
42+
43+
3644
public class RubyScriptNodeDialog extends NodeDialogPane {
3745
private static NodeLogger logger = NodeLogger
3846
.getLogger(RubyScriptNodeDialog.class);
39-
private JTextArea scriptTextArea = new JTextArea();
47+
//private JTextArea scriptTextArea = new JTextArea();
48+
private RSyntaxTextArea m_scriptTextArea = new RSyntaxTextArea();
49+
4050
private JTable table;
4151
private int counter = 1;
4252
private JCheckBox m_appendColsCB;
@@ -48,9 +58,15 @@ public class RubyScriptNodeDialog extends NodeDialogPane {
4858
protected RubyScriptNodeDialog() {
4959
super();
5060

51-
scriptTextArea.setAutoscrolls(true);
52-
Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
53-
scriptTextArea.setFont(font);
61+
//scriptTextArea.setAutoscrolls(true);
62+
//Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
63+
//scriptTextArea.setFont(font);
64+
65+
m_scriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_RUBY);
66+
m_scriptTextArea.setCodeFoldingEnabled(true);
67+
m_scriptTextArea.setAntiAliasingEnabled(true);
68+
RTextScrollPane spScript = new RTextScrollPane(m_scriptTextArea);
69+
spScript.setFoldIndicatorEnabled(true);
5470

5571
// construct the output column selection panel
5672
JPanel outputPanel = new JPanel();
@@ -163,7 +179,7 @@ public void actionPerformed(final ActionEvent e) {
163179
exc.printStackTrace();
164180
}
165181

166-
scriptTextArea.setText(buffer.toString());
182+
m_scriptTextArea.setText(buffer.toString());
167183
}
168184
});
169185
scriptButton.setText("Load Script from File");
@@ -172,8 +188,11 @@ public void actionPerformed(final ActionEvent e) {
172188

173189
JPanel scriptMainPanel = new JPanel(new BorderLayout());
174190
scriptMainPanel.add(new JLabel("Script: "), BorderLayout.NORTH);
175-
scriptMainPanel.add(new JScrollPane(scriptTextArea),
176-
BorderLayout.CENTER);
191+
192+
//scriptMainPanel.add(new JScrollPane(scriptTextArea),
193+
// BorderLayout.CENTER);
194+
195+
scriptMainPanel.add(spScript, BorderLayout.CENTER);
177196

178197
scriptPanel.add(scriptButtonPanel, BorderLayout.PAGE_START);
179198
scriptPanel.add(scriptMainPanel, BorderLayout.CENTER);
@@ -191,7 +210,7 @@ protected final void loadSettingsFrom(final NodeSettingsRO settings,
191210
if (script == null) {
192211
script = "";
193212
}
194-
scriptTextArea.setText(script);
213+
m_scriptTextArea.setText(script);
195214

196215
boolean appendCols = settings.getBoolean(
197216
RubyScriptNodeModel.APPEND_COLS, true);
@@ -231,12 +250,12 @@ protected final void saveSettingsTo(final NodeSettingsWO settings)
231250
}
232251

233252
// save the settings
234-
String scriptSetting = scriptTextArea.getText();
253+
String scriptSetting = m_scriptTextArea.getText();
235254
if (scriptSetting == null || "".equals(scriptSetting)) {
236255
throw new InvalidSettingsException(
237256
"Please specify a script to be run.");
238257
}
239-
settings.addString(RubyScriptNodeModel.SCRIPT, scriptTextArea.getText());
258+
settings.addString(RubyScriptNodeModel.SCRIPT, m_scriptTextArea.getText());
240259

241260
settings.addBoolean(RubyScriptNodeModel.APPEND_COLS,
242261
m_appendColsCB.isSelected());

0 commit comments

Comments
 (0)