Changeset 25110 in osm for applications/editors/josm/plugins
- Timestamp:
- 2011-01-22T16:39:26+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/scripting
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/scripting/scripts/AddHouseNumbers.groovy
r25107 r25110 1 /* 2 * This scripts sets a sequence of consecutive house numbers on the currently selected nodes. 3 * 4 */ 5 import java.awt.event.WindowAdapter; 1 6 2 /*3 * This scripts sets a sequence of house numbers on the currently selected nodes.4 *5 * The user can enter a start number and and an increment.6 */7 7 8 8 import java.awt.BorderLayout; … … 10 10 11 11 import java.awt.event.KeyEvent; 12 import java.awt.event.WindowAdapter; 13 import java.awt.event.WindowListener; 12 14 13 15 import javax.swing.KeyStroke; 14 16 15 17 import groovy.swing.SwingBuilder; 18 import groovy.util.ProxyGenerator; 19 16 20 import javax.swing.JOptionPane; 17 21 import org.openstreetmap.josm.Main; … … 35 39 import java.awt.GridBagLayout; 36 40 import javax.swing.JLabel; 41 import java.awt.event.FocusListener; 37 42 38 43 import javax.swing.Action; … … 43 48 import java.awt.event.ActionListener; 44 49 import java.awt.Dimension; 50 import java.awt.Dialog.ModalityType; 51 import java.awt.event.WindowEvent; 45 52 46 53 class AddHouseNumberDialog extends JDialog { … … 56 63 private JTextField tfStart; 57 64 private JTextField tfIncrement; 65 private def actApply; 58 66 59 67 public AddHouseNumberDialog(){ 60 super(Main.parent, true /* modal */)68 super(Main.parent,true) 61 69 build(); 62 70 } … … 95 103 SwingBuilder swing = new SwingBuilder() 96 104 return swing.panel(layout: new FlowLayout(FlowLayout.CENTER)) { 97 defactApply = action(name: "Apply", smallIcon: ImageProvider.get("ok"), closure: {apply(); setVisible(false)})105 actApply = action(name: "Apply", smallIcon: ImageProvider.get("ok"), closure: {apply(); setVisible(false)}) 98 106 def btnApply = button(action: actApply) 99 107 btnApply.setFocusable(true) … … 114 122 return 115 123 } 116 def cmds = getCurrentlySelectedNodes().collect { Node n -> 124 def nodes = Main?.map?.mapView?.editLayer?.data?.getSelectedNodes()?.asList() 125 if (nodes == null || nodes.isEmpty()) return 126 def cmds = nodes.collect { Node n -> 117 127 Node nn = new Node(n) 118 128 nn.put("addr:housenumber", start.toString()) … … 120 130 return new ChangeCommand(n, nn) 121 131 } 122 if (cmds.isEmpty()) return123 132 Main.main.undoRedo.add(new SequenceCommand("Setting house numbers", cmds)) 124 133 } … … 131 140 cp.add(buildInputPanel(), BorderLayout.CENTER) 132 141 cp.add(buildControlButtonPanel(), BorderLayout.SOUTH) 133 } 134 135 def getCurrentDataSet() { 136 def layer = Main?.map?.mapView?.activeLayer 137 if (layer == null) return null 138 if (! (layer instanceof OsmDataLayer)) return null 139 return layer.data 140 } 141 142 def getCurrentlySelectedNodes() { 143 def DataSet ds = getCurrentDataSet() 144 if (ds == null) return [] 145 return ds.getSelectedNodes().asList() 146 } 142 143 addWindowListener([windowActivated: {tfStart.requestFocusInWindow()}] as WindowAdapter) 144 getRootPane().registerKeyboardAction(actApply, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,KeyEvent.CTRL_MASK, false), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) 145 } 147 146 148 147 @Override -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/RunScriptAction.java
r25019 r25110 4 4 import java.awt.event.KeyEvent; 5 5 6 import javax.swing.KeyStroke; 7 6 8 import org.openstreetmap.josm.Main; 7 9 import org.openstreetmap.josm.actions.JosmAction; 10 import org.openstreetmap.josm.gui.help.HelpUtil; 8 11 import org.openstreetmap.josm.tools.ImageProvider; 9 12 import org.openstreetmap.josm.tools.Shortcut; … … 20 23 ); 21 24 putValue(MNEMONIC_KEY, KeyEvent.VK_R); 25 putValue("help", HelpUtil.ht("/Plugin/Scripting")); 22 26 } 23 27 -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/RunScriptDialog.java
r25107 r25110 11 11 import java.awt.Insets; 12 12 import java.awt.event.ActionEvent; 13 import java.awt.event.WindowAdapter; 14 import java.awt.event.WindowEvent; 13 15 import java.io.File; 14 16 import java.io.FileReader; … … 24 26 import javax.script.ScriptException; 25 27 import javax.swing.AbstractAction; 28 import javax.swing.Action; 26 29 import javax.swing.JButton; 30 import javax.swing.JComponent; 27 31 import javax.swing.JDialog; 28 32 import javax.swing.JFileChooser; … … 31 35 import javax.swing.JPanel; 32 36 import javax.swing.JTextField; 37 import javax.swing.KeyStroke; 33 38 import javax.swing.SwingUtilities; 34 39 35 40 import org.openstreetmap.josm.Main; 41 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 36 42 import org.openstreetmap.josm.gui.SideButton; 37 43 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; … … 41 47 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 42 48 import org.openstreetmap.josm.plugins.scripting.preferences.PreferenceKeys; 49 import org.openstreetmap.josm.plugins.scripting.util.IOUtil; 43 50 import org.openstreetmap.josm.tools.ImageProvider; 44 51 import org.openstreetmap.josm.tools.WindowGeometry; … … 53 60 /** the input field for the script file name */ 54 61 private HistoryComboBox cbScriptFile; 62 private Action actRun; 55 63 56 64 /** … … 60 68 */ 61 69 public RunScriptDialog(Component parent) { 62 super(JOptionPane.getFrameForComponent(parent), true);70 super(JOptionPane.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL); 63 71 build(); 72 HelpUtil.setHelpContext(this.getRootPane(), HelpUtil.ht("/Plugin/Scripting")); 64 73 } 65 74 … … 78 87 protected JPanel buildControlButtonPanel() { 79 88 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 80 pnl.add(new SideButton(new RunAction())); 89 JButton btn; 90 91 pnl.add(btn = new SideButton(actRun = new RunAction())); 92 btn.setFocusable(true); 93 btn.registerKeyboardAction(actRun, KeyStroke.getKeyStroke("ENTER"), JComponent.WHEN_FOCUSED); 81 94 pnl.add(new SideButton(new CancelAction())); 82 pnl.add(new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Plugin/ Macro#Run"))));95 pnl.add(new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Plugin/Scripting#Run")))); 83 96 return pnl; 84 97 } … … 108 121 gc.fill = GridBagConstraints.BOTH; 109 122 gc.insets = new Insets(3,0 /* no spacing to the left */,3,3); 110 pnl.add(new JButton(new SelectMacroFileAction()), gc); 123 JButton btn; 124 pnl.add(btn = new JButton(new SelectMacroFileAction()), gc); 125 btn.setFocusable(false); 111 126 112 127 // just a filler … … 135 150 getContentPane().add(buildContentPanel(), BorderLayout.CENTER); 136 151 152 getRootPane().registerKeyboardAction(actRun, KeyStroke.getKeyStroke("ctrl ENTER"), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 137 153 setTitle(tr("Run a script")); 138 154 setSize(600, 150); 155 156 addWindowListener(new WindowAdapter() { 157 @Override 158 public void windowActivated(WindowEvent e) { 159 cbScriptFile.requestFocusInWindow(); 160 } 161 }); 139 162 } 140 163 … … 194 217 tr("File not found"), 195 218 JOptionPane.ERROR_MESSAGE, 196 null // no help topic219 HelpUtil.ht("/Plugin/Scripting") 197 220 ); 198 221 } … … 204 227 tr("Empty file name"), 205 228 JOptionPane.ERROR_MESSAGE, 206 null // no help topic229 HelpUtil.ht("/Plugin/Scripting") 207 230 ); 208 231 } … … 214 237 tr("File not readable"), 215 238 JOptionPane.ERROR_MESSAGE, 216 null // no help topic239 HelpUtil.ht("/Plugin/Scripting") 217 240 ); 218 241 } … … 224 247 tr("IO error"), 225 248 JOptionPane.ERROR_MESSAGE, 226 null // no help topic249 HelpUtil.ht("/Plugin/Scripting") 227 250 ); 228 251 System.out.println(tr("Failed to read a macro from the file ''{0}''.", f.toString())); … … 236 259 tr("Script Error"), 237 260 JOptionPane.ERROR_MESSAGE, 238 null // no help topic261 HelpUtil.ht("/Plugin/Scripting") 239 262 ); 240 263 System.out.println(tr("Macro execution has failed.")); … … 252 275 + "</html>" 253 276 , 254 tr("No script ingengine"),255 JOptionPane.ERROR_MESSAGE, 256 null // no help topic277 tr("No script engine"), 278 JOptionPane.ERROR_MESSAGE, 279 HelpUtil.ht("/Plugin/Scripting") 257 280 ); 258 281 } … … 292 315 final ScriptEngine engine = getScriptEngine(f); 293 316 if (engine == null) return; 294 317 setVisible(false); 318 295 319 SwingUtilities.invokeLater( 296 320 new Runnable() { … … 300 324 if (engine instanceof Compilable) { 301 325 CompiledScript script = CompiledScriptCache.getInstance().compile((Compilable)engine,f); 302 logger.info("running compiled script for " + f);303 326 script.eval(); 304 327 } else { … … 311 334 warnFailedToOpenMacroFile(f, e); 312 335 } finally { 313 if (reader != null){ 314 try {reader.close();} catch(IOException e) {} 315 } 336 IOUtil.close(reader); 316 337 } 317 338 } 318 339 } 319 ); 320 321 setVisible(false); 340 ); 322 341 } 323 342 } -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/ScriptEngineSelectionDialog.java
r25107 r25110 82 82 */ 83 83 public ScriptEngineSelectionDialog(Component parent) { 84 super(JOptionPane.getFrameForComponent(parent), true /* modal */);84 super(JOptionPane.getFrameForComponent(parent), ModalityType.APPLICATION_MODAL); 85 85 build(); 86 HelpUtil.setHelpContext(getRootPane(), HelpUtil.ht("/Plugin/Scripting")); 86 87 } 87 88 … … 107 108 pnl.add(btn = new SideButton(actCancel = new CancelAction())); 108 109 btn.setFocusable(true); 109 pnl.add(btn = new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Plugin s/Scripting#SelectScriptingEngine"))));110 pnl.add(btn = new SideButton(new ContextSensitiveHelpAction(HelpUtil.ht("/Plugin/Scripting")))); 110 111 btn.setFocusable(true); 111 112 … … 113 114 getRootPane().registerKeyboardAction( 114 115 actOK, 115 KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK),116 KeyStroke.getKeyStroke("ctrl ENTER"), 116 117 JComponent.WHEN_IN_FOCUSED_WINDOW 117 118 ); … … 120 121 getRootPane().registerKeyboardAction( 121 122 actCancel, 122 KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0),123 KeyStroke.getKeyStroke("ESC"), 123 124 JComponent.WHEN_IN_FOCUSED_WINDOW 124 125 ); -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/preferences/ConfigureAction.java
r25071 r25110 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.actions.JosmAction; 14 import org.openstreetmap.josm.gui.help.HelpUtil; 14 15 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 15 16 import org.openstreetmap.josm.plugins.scripting.RunScriptDialog; … … 24 25 false // don't register 25 26 ); 27 putValue("help", HelpUtil.ht("/Plugin/Scripting")); 26 28 } 27 29 … … 62 64 */ 63 65 for(int i=0; i< tp.getTabCount(); i++) { 64 if (getChildByName(tp.getComponentAt(i), "scripting.preferences.editor") != null) {66 if (getChildByName(tp.getComponentAt(i), PreferenceEditor.NAME) != null) { 65 67 tp.setSelectedIndex(i); 66 68 break; -
applications/editors/josm/plugins/scripting/src/org/openstreetmap/josm/plugins/scripting/preferences/PreferenceEditor.java
r25071 r25110 13 13 14 14 public class PreferenceEditor extends JPanel implements PreferenceSetting { 15 static public final String NAME = "scripting.preferences.editor"; 15 16 16 17 private JTabbedPane tpPreferenceTabs; … … 34 35 JPanel tab = gui.createPreferenceTab("script-engine", tr("Scripting"), description); 35 36 tab.add(this, GBC.eol().fill(GBC.BOTH)); 36 this.setName( "scripting.preferences.editor");37 this.setName(NAME); 37 38 } 38 39
Note:
See TracChangeset
for help on using the changeset viewer.