Changeset 33698 in osm for applications/editors/josm/plugins/ext_tools
- Timestamp:
- 2017-10-03T22:55:07+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/ext_tools
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ext_tools/build.xml
r32680 r33698 5 5 <property name="commit.message" value="ExtTools: help shortcut paser, rebuild"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="1 0580"/>7 <property name="plugin.main.version" value="12726"/> 8 8 9 9 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/ext_tools/src/ext_tools/DataSetToCmd.java
r30737 r33698 14 14 import org.openstreetmap.josm.command.Command; 15 15 import org.openstreetmap.josm.data.osm.*; 16 import org.openstreetmap.josm.gui.MainApplication; 16 17 17 18 final class DataSetToCmd { … … 65 66 target.mergeFrom(source); 66 67 mergedMap.put(source.getPrimitiveId(), target); 67 cmds.add(new AddCommand(target)); 68 cmds.add(new AddCommand(MainApplication.getLayerManager().getEditDataSet(), target)); 68 69 } 69 70 … … 123 124 newNodes.add(targetNode); 124 125 } 125 cmds.add(new ChangeNodesCommand(target, newNodes)); 126 cmds.add(new ChangeNodesCommand(MainApplication.getLayerManager().getEditDataSet(), target, newNodes)); 126 127 } 127 128 … … 163 164 Relation newRelation = new Relation(target); 164 165 newRelation.setMembers(newMembers); 165 cmds.add(new ChangeCommand(target, newRelation)); 166 cmds.add(new ChangeCommand(MainApplication.getLayerManager().getEditDataSet(), target, newRelation)); 166 167 } 167 168 -
applications/editors/josm/plugins/ext_tools/src/ext_tools/ExtTool.java
r32688 r33698 27 27 import org.openstreetmap.josm.data.coor.LatLon; 28 28 import org.openstreetmap.josm.data.osm.DataSet; 29 import org.openstreetmap.josm.gui.MainApplication; 29 30 import org.openstreetmap.josm.gui.MainMenu; 30 31 import org.openstreetmap.josm.gui.MapView; … … 35 36 import org.openstreetmap.josm.io.OsmReader; 36 37 import org.openstreetmap.josm.tools.GBC; 38 import org.openstreetmap.josm.tools.Logging; 37 39 38 40 public class ExtTool { … … 57 59 if (action == null) 58 60 action = new ExtToolAction(this); 59 menuItem = MainMenu.add(Main .main.menu.toolsMenu, action);61 menuItem = MainMenu.add(MainApplication.getMenu().toolsMenu, action); 60 62 } else { 61 Main .main.menu.toolsMenu.remove(menuItem);63 MainApplication.getMenu().toolsMenu.remove(menuItem); 62 64 } 63 65 } … … 107 109 } 108 110 109 private class ToolProcess { 111 private static class ToolProcess { 110 112 public Process process; 111 113 public volatile boolean running; … … 113 115 114 116 static double getPPD() { 115 ProjectionBounds bounds = Main .map.mapView.getProjectionBounds();116 return Main .map.mapView.getWidth() /117 ProjectionBounds bounds = MainApplication.getMap().mapView.getProjectionBounds(); 118 return MainApplication.getMap().mapView.getWidth() / 117 119 (bounds.maxEast - bounds.minEast); 118 120 } … … 129 131 130 132 private double getTMSZoom() { 131 if ( Main.map == null || Main.map.mapView == null) return 1;132 MapView mv = Main .map.mapView;133 if (!MainApplication.isDisplayingMapView()) return 1; 134 MapView mv = MainApplication.getMap().mapView; 133 135 LatLon topLeft = mv.getLatLon(0, 0); 134 136 LatLon botRight = mv.getLatLon(mv.getWidth(), mv.getHeight()); … … 145 147 146 148 protected void showErrorMessage(final String message, final String details) { 147 SwingUtilities.invokeLater(new Runnable() { 148 public void run() { 149 final JPanel p = new JPanel(new GridBagLayout()); 150 p.add(new JMultilineLabel(message),GBC.eol()); 151 if (details != null) { 152 JTextArea info = new JTextArea(details, 20, 60); 153 info.setCaretPosition(0); 154 info.setEditable(false); 155 p.add(new JScrollPane(info), GBC.eop()); 156 } 157 JOptionPane.showMessageDialog(Main.parent, p, tr("External tool error"), JOptionPane.ERROR_MESSAGE); 158 } 149 SwingUtilities.invokeLater(() -> { 150 final JPanel p = new JPanel(new GridBagLayout()); 151 p.add(new JMultilineLabel(message),GBC.eol()); 152 if (details != null) { 153 JTextArea info = new JTextArea(details, 20, 60); 154 info.setCaretPosition(0); 155 info.setEditable(false); 156 p.add(new JScrollPane(info), GBC.eop()); 157 } 158 JOptionPane.showMessageDialog(Main.parent, p, tr("External tool error"), JOptionPane.ERROR_MESSAGE); 159 159 }); 160 160 } 161 161 162 162 public void runTool(LatLon pos) { 163 Main .map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));163 MainApplication.getMap().mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 164 164 // parse cmdline and build cmdParams array 165 165 HashMap<String, String> replace = new HashMap<>(); … … 201 201 tp.process = builder.start(); 202 202 } catch (final IOException e) { 203 e.printStackTrace();203 Logging.error(e); 204 204 synchronized (debugstr) { 205 205 showErrorMessage( … … 212 212 213 213 // redirect child process's stderr to JOSM stderr 214 new Thread(new Runnable() { 215 public void run() { 216 try { 217 byte[] buffer = new byte[1024]; 218 InputStream errStream = tp.process.getErrorStream(); 219 int len; 220 while ((len = errStream.read(buffer)) > 0) { 221 synchronized (debugstr) { 222 debugstr.append(new String(buffer, 0, len)); 223 } 224 System.err.write(buffer, 0, len); 225 } 226 } catch (IOException e) { 227 } 214 new Thread(() -> { 215 try { 216 byte[] buffer = new byte[1024]; 217 InputStream errStream = tp.process.getErrorStream(); 218 int len; 219 while ((len = errStream.read(buffer)) > 0) { 220 synchronized (debugstr) { 221 debugstr.append(new String(buffer, 0, len)); 222 } 223 System.err.write(buffer, 0, len); 224 } 225 } catch (IOException e) { 226 Logging.error(e); 228 227 } 229 228 }).start(); 230 229 231 230 // read stdout stream 232 Thread osmParseThread = new Thread(new Runnable() { 233 public void run() { 234 try { 235 final InputStream inputStream = tp.process.getInputStream(); 236 final DataSet ds = OsmReader.parseDataSet(inputStream, 237 NullProgressMonitor.INSTANCE); 238 final List<Command> cmdlist = new DataSetToCmd(ds).getCommandList(); 239 if (!cmdlist.isEmpty()) { 240 SequenceCommand cmd = 241 new SequenceCommand(getName(), cmdlist); 242 Main.main.undoRedo.add(cmd); 243 } 244 } catch (IllegalDataException e) { 245 e.printStackTrace(); 246 if (tp.running) { 247 tp.process.destroy(); 248 synchronized (debugstr) { 249 showErrorMessage( 250 tr("Child script have returned invalid data.\n\nstderr contents:"), 251 debugstr.toString()); 252 } 253 } 254 } finally { 255 synchronized (syncObj) { 256 tp.running = false; 257 syncObj.notifyAll(); 258 } 259 } 260 } 261 231 Thread osmParseThread = new Thread(() -> { 232 try { 233 final InputStream inputStream = tp.process.getInputStream(); 234 final DataSet ds = OsmReader.parseDataSet(inputStream, 235 NullProgressMonitor.INSTANCE); 236 final List<Command> cmdlist = new DataSetToCmd(ds).getCommandList(); 237 if (!cmdlist.isEmpty()) { 238 Main.main.undoRedo.add(new SequenceCommand(getName(), cmdlist)); 239 } 240 } catch (IllegalDataException e) { 241 Logging.error(e); 242 if (tp.running) { 243 tp.process.destroy(); 244 synchronized (debugstr) { 245 showErrorMessage( 246 tr("Child script have returned invalid data.\n\nstderr contents:"), 247 debugstr.toString()); 248 } 249 } 250 } finally { 251 synchronized (syncObj) { 252 tp.running = false; 253 syncObj.notifyAll(); 254 } 255 } 262 256 }); 263 257 osmParseThread.start(); … … 267 261 syncObj.wait(10000); 268 262 } catch (InterruptedException e) { 263 Logging.trace(e); 269 264 } 270 265 } -
applications/editors/josm/plugins/ext_tools/src/ext_tools/ExtToolAction.java
r27847 r33698 7 7 import java.awt.event.MouseEvent; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.actions.mapmode.MapMode; 10 import org.openstreetmap.josm.gui.MainApplication; 11 11 import org.openstreetmap.josm.gui.layer.Layer; 12 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 24 24 Shortcut.registerShortcut(tr("exttool:{0}", tool.name), tr("External Tool: {0}", tool.name), 25 25 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), 26 null,ImageProvider.getCursor("crosshair", null));26 ImageProvider.getCursor("crosshair", null)); 27 27 this.tool = tool; 28 28 setEnabled(true); … … 31 31 @Override 32 32 public void actionPerformed(ActionEvent e) { 33 if ( Main.map == null || Main.map.mapView == null)33 if (!MainApplication.isDisplayingMapView()) 34 34 return; 35 oldMapMode = Main .map.mapMode;35 oldMapMode = MainApplication.getMap().mapMode; 36 36 super.actionPerformed(e); 37 37 } … … 40 40 public void enterMode() { 41 41 super.enterMode(); 42 Main .map.mapView.addMouseListener(this);42 MainApplication.getMap().mapView.addMouseListener(this); 43 43 } 44 44 … … 46 46 public void exitMode() { 47 47 super.exitMode(); 48 Main .map.mapView.removeMouseListener(this);48 MainApplication.getMap().mapView.removeMouseListener(this); 49 49 } 50 50 51 51 @Override 52 52 public void mouseClicked(MouseEvent e) { 53 if ( Main.map == null || Main.map.mapView == null) {53 if (!MainApplication.isDisplayingMapView()) { 54 54 return; 55 55 } 56 56 57 tool.runTool(Main .map.mapView.getLatLon(e.getX(), e.getY()));58 Main .map.selectMapMode(oldMapMode);57 tool.runTool(MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY())); 58 MainApplication.getMap().selectMapMode(oldMapMode); 59 59 } 60 60 -
applications/editors/josm/plugins/ext_tools/src/ext_tools/ToolsInformation.java
r30738 r33698 9 9 import java.util.List; 10 10 11 import org.openstreetmap.josm. Main;11 import org.openstreetmap.josm.tools.Logging; 12 12 13 13 public class ToolsInformation { … … 34 34 } 35 35 } catch (Exception e) { 36 Main.warn("Ext_Tools warning: can not load file "+filename);36 Logging.warn("Ext_Tools warning: can not load file "+filename); 37 37 } 38 38 } … … 43 43 w.write(tool.serialize()); 44 44 } catch (Exception e) { 45 Main.warn("Ext_Tools warning: can not save file "+filename);45 Logging.warn("Ext_Tools warning: can not save file "+filename); 46 46 } 47 47 } -
applications/editors/josm/plugins/ext_tools/src/ext_tools/preferences/MyToolsPanel.java
r21930 r33698 42 42 final JCheckBox cbTool = new JCheckBox(tool.getName()); 43 43 cbTool.setSelected(tool.isEnabled()); 44 cbTool.addActionListener(new ActionListener() { 45 public void actionPerformed(ActionEvent e) { 46 tool.setEnabled(cbTool.isSelected()); 47 } 48 }); 44 cbTool.addActionListener(e -> tool.setEnabled(cbTool.isSelected())); 49 45 add(cbTool, gbc); 50 46 -
applications/editors/josm/plugins/ext_tools/src/ext_tools/preferences/ToolsRepositoryPanel.java
r21930 r33698 41 41 final JCheckBox cbTool = new JCheckBox(tool.getName()); 42 42 cbTool.setSelected(tool.isEnabled()); 43 cbTool.addActionListener(new ActionListener() { 44 public void actionPerformed(ActionEvent e) { 45 tool.setEnabled(cbTool.isSelected()); 46 } 47 }); 43 cbTool.addActionListener(e -> tool.setEnabled(cbTool.isSelected())); 48 44 add(cbTool, gbc); 49 45
Note:
See TracChangeset
for help on using the changeset viewer.