Changeset 25107 in osm for applications/editors/josm/plugins/scripting/src
- Timestamp:
- 2011-01-22T12:18:25+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/RunScriptDialog.java
r25071 r25107 14 14 import java.io.FileReader; 15 15 import java.io.IOException; 16 import java.net.MalformedURLException;17 import java.net.URL;18 import java.net.URLClassLoader;19 16 import java.util.Collections; 20 17 import java.util.LinkedList; 21 18 import java.util.List; 22 19 import java.util.logging.Logger; 23 import java.util.regex.Matcher; 24 import java.util.regex.Pattern; 25 26 import javax.activation.MimetypesFileTypeMap; 20 21 import javax.script.Compilable; 22 import javax.script.CompiledScript; 27 23 import javax.script.ScriptEngine; 28 import javax.script.ScriptEngineFactory;29 import javax.script.ScriptEngineManager;30 24 import javax.script.ScriptException; 31 25 import javax.swing.AbstractAction; … … 46 40 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 47 41 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 42 import org.openstreetmap.josm.plugins.scripting.preferences.PreferenceKeys; 48 43 import org.openstreetmap.josm.tools.ImageProvider; 49 44 import org.openstreetmap.josm.tools.WindowGeometry; … … 53 48 * running a script.</p> 54 49 */ 55 public class RunScriptDialog extends JDialog { 50 public class RunScriptDialog extends JDialog implements PreferenceKeys{ 56 51 static private final Logger logger = Logger.getLogger(RunScriptDialog.class.getName()); 57 58 /**59 * <p>The preferences key for the script file history.</p>60 */61 static private final String PREF_KEY_FILE_HISTORY = "scripting.RunScriptDialog.file-history";62 63 /**64 * <p>The preferences key for the last script file name entered in the script file65 * selection field.</p>66 */67 static private final String PREF_KEY_LAST_FILE = "scripting.RunScriptDialog.last-file";68 52 69 53 /** the input field for the script file name */ … … 227 211 HelpAwareOptionPane.showOptionDialog( 228 212 RunScriptDialog.this, 229 tr("The script file ''{0}'' isn't readable.", f.toString()), 213 tr("The script file ''{0}'' isn''t readable.", f.toString()), 230 214 tr("File not readable"), 231 215 JOptionPane.ERROR_MESSAGE, … … 263 247 "<html>" 264 248 + tr( 265 "<p>The script can''t be executed, beca sue there are currently no scripting engines installed.</p>"249 "<p>The script can''t be executed, because there are currently no scripting engines installed.</p>" 266 250 + "<p>Refer to the online help for information about how to install a scripting engine with JOSM.</p>" 267 251 ) … … 308 292 final ScriptEngine engine = getScriptEngine(f); 309 293 if (engine == null) return; 294 310 295 SwingUtilities.invokeLater( 311 296 new Runnable() { … … 313 298 FileReader reader = null; 314 299 try { 315 reader = new FileReader(f); 316 engine.eval(reader); 300 if (engine instanceof Compilable) { 301 CompiledScript script = CompiledScriptCache.getInstance().compile((Compilable)engine,f); 302 logger.info("running compiled script for " + f); 303 script.eval(); 304 } else { 305 reader = new FileReader(f); 306 engine.eval(reader); 307 } 317 308 } catch(ScriptException e){ 318 309 warnExecutingScriptFailed(e); … … 327 318 } 328 319 ); 320 329 321 setVisible(false); 330 322 } -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/ScriptEngineProvider.java
r25071 r25107 7 7 import java.io.IOException; 8 8 import java.io.InputStream; 9 import java.lang.reflect.Field; 9 10 import java.net.MalformedURLException; 10 11 import java.net.URL; … … 44 45 private final List<File> scriptEngineJars = new ArrayList<File>(); 45 46 private MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); 47 private ClassLoader scriptClassLoader = getClass().getClassLoader(); 46 48 47 49 protected void loadMimeTypesMap() { … … 81 83 scriptEngineJars.add(new File(jar)); 82 84 } 85 scriptClassLoader = buildClassLoader(); 83 86 } 84 87 … … 151 154 */ 152 155 public ScriptEngine getEngineByName(String name) { 153 ScriptEngineManager mgr = new ScriptEngineManager( buildClassLoader());156 ScriptEngineManager mgr = new ScriptEngineManager(scriptClassLoader); 154 157 return mgr.getEngineByName(name); 155 158 } … … 201 204 } 202 205 } 206 buildClassLoader(); 203 207 loadScriptEngineFactories(); 204 208 fireContentsChanged(this, 0, scriptEngineJars.size()); -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/ScriptEngineSelectionDialog.java
r25071 r25107 13 13 import java.awt.event.MouseAdapter; 14 14 import java.awt.event.MouseEvent; 15 import java.util.List;16 15 17 16 import javax.script.ScriptEngine; 18 import javax.script.ScriptEngineFactory;19 17 import javax.swing.AbstractAction; 20 18 import javax.swing.BorderFactory; … … 22 20 import javax.swing.JComponent; 23 21 import javax.swing.JDialog; 24 import javax.swing.JLabel;25 22 import javax.swing.JList; 26 23 import javax.swing.JOptionPane; 27 24 import javax.swing.JPanel; 28 25 import javax.swing.KeyStroke; 29 import javax.swing.ListCellRenderer;30 26 import javax.swing.ListSelectionModel; 31 import javax.swing.UIManager;32 27 import javax.swing.event.ListSelectionEvent; 33 28 import javax.swing.event.ListSelectionListener; … … 38 33 import org.openstreetmap.josm.gui.help.HelpUtil; 39 34 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 35 import org.openstreetmap.josm.plugins.scripting.ui.ScriptEngineCellRenderer; 40 36 import org.openstreetmap.josm.tools.ImageProvider; 41 37 import org.openstreetmap.josm.tools.WindowGeometry; 42 import org.openstreetmap.josm.plugins.scripting.ui.ScriptEngineCellRenderer;43 38 44 39 /** -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/preferences/PreferenceKeys.java
r25071 r25107 9 9 */ 10 10 String PREF_KEY_SCRIPTING_ENGINE_JARS = "scripting.engine-jars"; 11 11 12 /** 13 * <p>The preferences key for the script file history.</p> 14 */ 15 String PREF_KEY_FILE_HISTORY = "scripting.RunScriptDialog.file-history"; 16 17 /** 18 * <p>The preferences key for the last script file name entered in the script file 19 * selection field.</p> 20 */ 21 String PREF_KEY_LAST_FILE = "scripting.RunScriptDialog.last-file"; 12 22 }
Note:
See TracChangeset
for help on using the changeset viewer.