summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a1d3c9a)
raw | patch | inline | side by side (parent: a1d3c9a)
author | ishmal <ishmal@users.sourceforge.net> | |
Tue, 1 Apr 2008 18:20:03 +0000 (18:20 +0000) | ||
committer | ishmal <ishmal@users.sourceforge.net> | |
Tue, 1 Apr 2008 18:20:03 +0000 (18:20 +0000) |
src/bind/java/org/inkscape/script/ScriptConsole.java | patch | blob | history |
diff --git a/src/bind/java/org/inkscape/script/ScriptConsole.java b/src/bind/java/org/inkscape/script/ScriptConsole.java
index 241a95fcbd245027b0e212227cc92e6821c7cfb5..890d78189184be78e9773d226c3f272556bdb3c1 100644 (file)
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JMenu;
+import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
-import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JComboBox;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import java.util.List;
import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
/**
- *
+ * This is the main Script Console window. It contains
+ * a terminal-like console, and a simple script editor.
*/
public class ScriptConsole extends JFrame
{
JTabbedPane tabPane;
JToolBar toolbar;
JMenuBar menubar;
-
+JComboBox engineBox;
//########################################################################
//# MESSSAGES
//########################################################################
ScriptEngine engine;
-HashMap<String, ScriptEngineAction> scriptEngineActions;
+ArrayList<ScriptEngine> engines;
+
public void setEngine(ScriptEngine engine)
{
this.engine = engine;
this.engine.getContext().setWriter(terminal.getOutWriter());
this.engine.getContext().setErrorWriter(terminal.getErrWriter());
+ //do something to make the combobox show the current engine
}
}
-public boolean setEngine(String name)
+public boolean setEngine(String langName)
{
- ScriptEngineAction action = scriptEngineActions.get(name);
- if (action == null)
- return false;
- action.setEnabled(true);
- setEngine(action.factory.getScriptEngine());
- return true;
+ for (ScriptEngine engine : engines)
+ {
+ if (langName.equalsIgnoreCase(engine.getFactory().getLanguageName()))
+ {
+ setEngine(engine);
+ return true;
+ }
+ }
+ return false;
}
}
+
class ScriptEngineAction extends AbstractAction
{
-ScriptEngineFactory factory;
public void actionPerformed(ActionEvent evt)
{
- setEngine(factory.getScriptEngine());
+ int index = engineBox.getSelectedIndex();
+ if (index<0)
+ return;
+ ScriptEngine engine = engines.get(index);
+ setEngine(engine);
}
-public ScriptEngineAction(ScriptEngineFactory factory)
+public ScriptEngineAction()
{
- super(factory.getEngineName(), null);
- putValue(SHORT_DESCRIPTION, factory.getLanguageName());
- this.factory = factory;
+ super("SelectEngine", null);
+ putValue(SHORT_DESCRIPTION, "Select a scripting engine");
}
}
private void initScripts()
{
- JMenu menu = new JMenu("Language");
- ButtonGroup group = new ButtonGroup();
- menubar.add(menu);
+ engines = new ArrayList<ScriptEngine>();
+ Action action = new ScriptEngineAction();
+ engineBox = new JComboBox();
+ engineBox.setAction(action);
+ engineBox.setEditable(false);
+ toolbar.add(engineBox);
ScriptEngineManager scriptEngineManager =
new ScriptEngineManager();
List<ScriptEngineFactory> factories =
- scriptEngineManager.getEngineFactories();
+ scriptEngineManager.getEngineFactories();
for (ScriptEngineFactory factory: factories)
{
trace("ScriptEngineFactory Info");
trace("\tEngine Alias: %s", name);
}
trace("\tLanguage: %s (%s)", langName, langVersion);
- ScriptEngineAction action = new ScriptEngineAction(factory);
- JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
- group.add(item);
- menu.add(item);
+ engines.add(factory.getScriptEngine());
+ //JLabel item = new JLabel(langName);
+ engineBox.addItem(langName);
}
- if (menu.getItemCount()>0)
+ if (engineBox.getItemCount()>0)
{
- JMenuItem item = menu.getItem(0);
- group.setSelected(item.getModel(), true);
- ScriptEngineAction action = (ScriptEngineAction)item.getAction();
- setEngine(action.factory.getScriptEngine());
+ engineBox.setSelectedIndex(0);
+ setEngine(engines.get(0));
}
}