8000 InterpreterPane/InterpreterWindow: Add constructor parameter to speci… · scijava/script-editor@8573d13 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8573d13

Browse files
InterpreterPane/InterpreterWindow: Add constructor parameter to specify language preference for REPL
1 parent c70e981 commit 8573d13

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/main/java/org/scijava/ui/swing/script/InterpreterPane.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,22 @@ public class InterpreterPane implements UIComponent<JComponent> {
7171
private LogService log;
7272

7373
/**
74-
* Constructs an interpreter UI pane for a SciJava scripting REPL.
74+
* Constructs an interpreter UI pane for a SciJava scripting REPL, with a given language preference.
7575
*
7676
* @param context The SciJava application context to use
77+
* @param languagePreference The given language to use, or null to fall back to the default.
7778
*/
78-
public InterpreterPane(final Context context) {
79+
public InterpreterPane(final Context context, final String languagePreference) {
7980
context.inject(this);
8081
output = new OutputPane(log);
8182
final JScrollPane outputScroll = new JScrollPane(output);
8283
outputScroll.setPreferredSize(new Dimension(440, 400));
8384

84-
repl = new ScriptREPL(context, output.getOutputStream());
85+
if(languagePreference == null) {
86+
repl = new ScriptREPL(context, output.getOutputStream());
87+
} else {
88+
repl = new ScriptREPL(context, languagePreference, output.getOutputStream());
89+
}
8590
repl.initialize();
8691

8792
final Writer writer = output.getOutputWriter();
@@ -137,6 +142,10 @@ public void quit() {
137142
mainPane.setDividerLocation(300);
138143
}
139144

145+
public InterpreterPane(final Context context) {
146+
this(context, null);
147+
}
148+
140149
// -- InterpreterPane methods --
141150

142151
/** Gets the associated script REPL. */

src/main/java/org/scijava/ui/swing/script/InterpreterWindow.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,39 @@ public class InterpreterWindow extends JFrame {
6060
private LogService log;
6161

6262
/** Constructs the scripting interpreter window. */
63-
public InterpreterWindow(final Context context) {
63+
public InterpreterWindow(final Context context, final String languagePreference) {
6464
super("Script Interpreter");
6565
context.inject(this);
6666

67-
pane = new InterpreterPane(context) {
68-
@Override
69-
public void dispose() {
70-
super.dispose();
71-
InterpreterWindow.super.dispose();
72-
}
73-
};
67+
if(languagePreference == null) {
68+
pane = new InterpreterPane(context) {
69+
@Override
70+
public void dispose() {
71+
super.dispose();
72+
InterpreterWindow.super.dispose();
73+
}
74+
};
75+
} else {
76+
pane = new InterpreterPane(context, languagePreference) {
77+
@Override
78+
public void dispose() {
79+
super.dispose();
80+
InterpreterWindow.super.dispose();
81+
}
82+
};
83+
}
7484
setContentPane(pane.getComponent());
7585

7686
pack();
7787

7888
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
7989
}
8090

91+
/** Construct the scripting interpreter with a given language preference. */
92+
public InterpreterWindow(final Context context) {
93+
this(context, null);
94+
}
95+
8196
/** Gets the window's associated {@link ScriptREPL}. */
8297
public ScriptREPL getREPL() {
8398
return pane.getREPL();

0 commit comments

Comments
 (0)
0