Changeset 33733 in osm for applications/editors
- Timestamp:
- 2017-10-26T00:42:11+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/CommandLine
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/CommandLine
- Property svn:ignore
-
old new 2 2 checkstyle-josm-CommandLine.xml 3 3 findbugs-josm-CommandLine.xml 4 spotbugs-josm-CommandLine.xml
-
- Property svn:ignore
-
applications/editors/josm/plugins/CommandLine/build.xml
r33238 r33733 4 4 <property name="commit.message" value="JOSM/CommandLine: fix exception after JOSM update"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1 1713"/>6 <property name="plugin.main.version" value="13007"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/CommandLine/src/CommandLine/AbstractOsmAction.java
r33239 r33733 11 11 import java.awt.event.MouseEvent; 12 12 13 import org.openstreetmap.josm.Main;14 13 import org.openstreetmap.josm.actions.mapmode.MapMode; 15 14 import org.openstreetmap.josm.data.osm.DataSet; 16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.gui.MainApplication; 17 import org.openstreetmap.josm.gui.MapFrame; 17 18 import org.openstreetmap.josm.tools.ImageProvider; 19 import org.openstreetmap.josm.tools.Logging; 18 20 19 21 public abstract class AbstractOsmAction<T extends OsmPrimitive> extends MapMode implements AWTEventListener { … … 38 40 super.enterMode(); 39 41 currentCursor = cursorNormal; 40 Main .map.mapView.addMouseListener(this);41 Main .map.mapView.addMouseMotionListener(this);42 MainApplication.getMap().mapView.addMouseListener(this); 43 MainApplication.getMap().mapView.addMouseMotionListener(this); 42 44 try { 43 45 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 44 46 } catch (SecurityException ex) { 45 Main.warn(ex);47 Logging.warn(ex); 46 48 } 47 49 } … … 49 51 @Override public void exitMode() { 50 52 super.exitMode(); 51 Main .map.mapView.removeMouseListener(this);52 Main .map.mapView.removeMouseMotionListener(this);53 MainApplication.getMap().mapView.removeMouseListener(this); 54 MainApplication.getMap().mapView.removeMouseMotionListener(this); 53 55 try { 54 56 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 55 57 } catch (SecurityException ex) { 56 Main.warn(ex);58 Logging.warn(ex); 57 59 } 58 60 } … … 60 62 @Override 61 63 public void mouseMoved(MouseEvent e) { 62 if (!Main .map.mapView.isActiveLayerDrawable())64 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 63 65 return; 64 66 processMouseEvent(e); 65 67 updCursor(); 66 Main .map.mapView.repaint();68 MainApplication.getMap().mapView.repaint(); 67 69 super.mouseMoved(e); 68 70 } … … 70 72 @Override 71 73 public void mousePressed(MouseEvent e) { 72 if (!Main.map.mapView.isActiveLayerDrawable()) 74 MapFrame map = MainApplication.getMap(); 75 if (!map.mapView.isActiveLayerDrawable()) 73 76 return; 74 77 processMouseEvent(e); 75 78 if (nearestPrimitive != null) { 76 DataSet ds = Main.getLayerManager().getEditDataSet(); 79 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 77 80 if (isCtrlDown) { 78 81 ds.clearSelection(nearestPrimitive); 79 Main.map.mapView.repaint();82 map.mapView.repaint(); 80 83 } else { 81 84 int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances; … … 83 86 case 0: 84 87 ds.addSelected(nearestPrimitive); 85 Main.map.mapView.repaint();88 map.mapView.repaint(); 86 89 break; 87 90 case 1: 88 91 ds.addSelected(nearestPrimitive); 89 Main.map.mapView.repaint();92 map.mapView.repaint(); 90 93 parentPlugin.loadParameter(nearestPrimitive, true); 91 Main.map.selectSelectTool(false);94 map.selectSelectTool(false); 92 95 break; 93 96 default: 94 97 if (ds.getSelected().size() < maxInstances) { 95 98 ds.addSelected(nearestPrimitive); 96 Main.map.mapView.repaint();99 map.mapView.repaint(); 97 100 } else 98 101 parentPlugin.printHistory("Maximum instances is " + maxInstances); … … 117 120 private void updCursor() { 118 121 if (mousePos != null) { 119 if (!Main.isDisplayingMapView()) 122 if (!MainApplication.isDisplayingMapView()) 120 123 return; 121 124 nearestPrimitive = getNearest(mousePos); … … 143 146 EventQueue.invokeLater(() -> { 144 147 // Don't change cursor when mode has changed already 145 if (!AbstractOsmAction.this.getClass().isAssignableFrom(Main .map.mapMode.getClass()))148 if (!AbstractOsmAction.this.getClass().isAssignableFrom(MainApplication.getMap().mapMode.getClass())) 146 149 return; 147 Main .map.mapView.setCursor(c);150 MainApplication.getMap().mapView.setCursor(c); 148 151 }); 149 152 currentCursor = c; 150 153 } catch (Exception e) { 151 Main.warn(e);154 Logging.warn(e); 152 155 } 153 156 } 154 157 155 158 public void cancelDrawing() { 156 if (Main.map == null || Main.map.mapView == null) 159 MapFrame map = MainApplication.getMap(); 160 if (map == null || map.mapView == null) 157 161 return; 158 Main.map.statusLine.setHeading(-1);159 Main.map.statusLine.setAngle(-1);160 Main.map.mapView.repaint();162 map.statusLine.setHeading(-1); 163 map.statusLine.setAngle(-1); 164 map.mapView.repaint(); 161 165 updateStatusLine(); 162 166 parentPlugin.abortInput(); -
applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java
r33238 r33733 4 4 import java.awt.Point; 5 5 6 import org.openstreetmap.josm.Main;7 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 import org.openstreetmap.josm.gui.MainApplication; 8 8 9 9 public class AnyAction extends AbstractOsmAction<OsmPrimitive> { … … 15 15 @Override 16 16 protected OsmPrimitive getNearest(Point mousePos) { 17 return Main .map.mapView.getNearestNodeOrWay(mousePos, OsmPrimitive::isUsable, false);17 return MainApplication.getMap().mapView.getNearestNodeOrWay(mousePos, OsmPrimitive::isUsable, false); 18 18 } 19 19 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java
r33238 r33733 43 43 import org.openstreetmap.josm.data.osm.Relation; 44 44 import org.openstreetmap.josm.data.osm.Way; 45 import org.openstreetmap.josm.gui.MainApplication; 45 46 import org.openstreetmap.josm.gui.MainMenu; 46 47 import org.openstreetmap.josm.gui.MapFrame; … … 56 57 import org.openstreetmap.josm.plugins.PluginInformation; 57 58 import org.openstreetmap.josm.tools.HttpClient; 59 import org.openstreetmap.josm.tools.Logging; 58 60 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 59 61 import org.openstreetmap.josm.tools.Utils; … … 82 84 textField = new CommandTextField(); 83 85 84 if (Main.main.menu != null) { 85 commandMenu = Main.main.menu.addMenu("Commands", tr("Commands"), KeyEvent.VK_O, 86 Main.main.menu.getDefaultMenuPos(), ht("/Plugin/CommandLine")); 86 MainMenu mainMenu = MainApplication.getMenu(); 87 if (mainMenu != null) { 88 commandMenu = mainMenu.addMenu("Commands", tr("Commands"), KeyEvent.VK_O, 89 mainMenu.getDefaultMenuPos(), ht("/Plugin/CommandLine")); 87 90 MainMenu.add(commandMenu, new CommandLineAction(this)); 88 91 } … … 99 102 100 103 protected void startCommand(Command command) { 101 if (Main.map == null) 104 MapFrame map = MainApplication.getMap(); 105 if (map == null) 102 106 return; 103 DataSet ds = Main.getLayerManager().getEditDataSet(); 107 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 104 108 if (ds == null) 105 109 return; … … 107 111 currentCommand.resetLoading(); 108 112 parseSelection(ds.getSelected()); 109 if (!( Main.map.mapMode instanceof AnyAction110 || Main.map.mapMode instanceof DummyAction111 || Main.map.mapMode instanceof LengthAction112 || Main.map.mapMode instanceof NodeAction113 || Main.map.mapMode instanceof PointAction114 || Main.map.mapMode instanceof RelationAction115 || Main.map.mapMode instanceof WayAction)) {116 previousMode = Main.map.mapMode;113 if (!(map.mapMode instanceof AnyAction 114 || map.mapMode instanceof DummyAction 115 || map.mapMode instanceof LengthAction 116 || map.mapMode instanceof NodeAction 117 || map.mapMode instanceof PointAction 118 || map.mapMode instanceof RelationAction 119 || map.mapMode instanceof WayAction)) { 120 previousMode = map.mapMode; 117 121 } 118 122 if (currentCommand.currentParameterNum < currentCommand.parameters.size()) … … 138 142 139 143 protected void printHistory(final String text) { 140 SwingUtilities.invokeLater(new Runnable() { 141 @Override 142 public void run() { 143 historyField.setText(text); 144 } 145 }); 144 SwingUtilities.invokeLater(() -> historyField.setText(text)); 146 145 } 147 146 148 147 private void loadCommands() { 149 commands = (new Loader(getPluginDir ())).load();148 commands = (new Loader(getPluginDirs().getUserDataDirectory(false))).load(); 150 149 if (commands.isEmpty()) { 151 150 if (!GraphicsEnvironment.isHeadless() && JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Main.parent, … … 154 153 try { 155 154 downloadAndInstallDefaultCommands(); 156 commands = (new Loader(getPluginDir ())).load();155 commands = (new Loader(getPluginDirs().getUserDataDirectory(false))).load(); 157 156 JOptionPane.showMessageDialog(Main.parent, tr("Default commands have been successfully installed"), 158 157 tr("Success"), JOptionPane.INFORMATION_MESSAGE); 159 158 } catch (IOException e) { 160 Main.warn(e);159 Logging.warn(e); 161 160 JOptionPane.showMessageDialog(Main.parent, 162 161 tr("Failed to download and install default commands.\n\nError: {0}", e.getMessage()), … … 174 173 "https://github.com/Foxhind/JOSM-CommandLine-commands/archive/master.zip"); 175 174 try (ZipInputStream zis = new ZipInputStream(HttpClient.create(new URL(url)).connect().getContent(), StandardCharsets.UTF_8)) { 176 File dir = new File(getPluginDir());175 File dir = getPluginDirs().getUserDataDirectory(false); 177 176 if (!dir.exists()) { 178 177 dir.mkdirs(); … … 186 185 } 187 186 File file = new File(dir + File.separator + name); 188 Main.info("Installing command file: "+file);187 Logging.info("Installing command file: "+file); 189 188 if (!file.createNewFile()) { 190 189 throw new IOException("Could not create file: " + file.getAbsolutePath()); … … 216 215 217 216 protected void setMode(Mode targetMode) { 218 DataSet currentDataSet = Main.getLayerManager().getEditDataSet(); 217 DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet(); 219 218 if (currentDataSet != null) { 220 219 currentDataSet.clearSelection(); 221 Main .map.mapView.repaint();220 MainApplication.getMap().mapView.repaint(); 222 221 } 223 222 if (targetMode == Mode.IDLE) { … … 261 260 break; 262 261 case IMAGERYURL: 263 Layer layer = Main.getLayerManager().getActiveLayer(); 262 Layer layer = MainApplication.getLayerManager().getActiveLayer(); 264 263 if (layer != null) { 265 264 if (!(layer instanceof ImageryLayer)) { 266 List<ImageryLayer> imageryLayers = Main.getLayerManager().getLayersOfType(ImageryLayer.class); 265 List<ImageryLayer> imageryLayers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class); 267 266 if (imageryLayers.size() == 1) { 268 267 layer = imageryLayers.get(0); … … 281 280 break; 282 281 case IMAGERYOFFSET: 283 Layer olayer = Main.getLayerManager().getActiveLayer(); 282 Layer olayer = MainApplication.getLayerManager().getActiveLayer(); 284 283 if (olayer != null) { 285 284 if (!(olayer instanceof ImageryLayer)) { 286 List<ImageryLayer> imageryLayers = Main.getLayerManager().getLayersOfType(ImageryLayer.class); 285 List<ImageryLayer> imageryLayers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class); 287 286 if (imageryLayers.size() == 1) { 288 287 olayer = imageryLayers.get(0); … … 307 306 prefix = tr("Processing..."); 308 307 textField.setText(prefix); 309 Main .map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));308 MainApplication.getMap().mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 310 309 } 311 310 } … … 317 316 318 317 public void deactivate() { 319 Main .map.mapView.requestFocus();318 MainApplication.getMap().mapView.requestFocus(); 320 319 } 321 320 … … 327 326 public void endInput() { 328 327 setMode(Mode.IDLE); 329 Main .map.selectMapMode(previousMode);330 Main .map.mapView.repaint();328 MainApplication.getMap().selectMapMode(previousMode); 329 MainApplication.getMap().mapView.repaint(); 331 330 } 332 331 … … 347 346 } 348 347 } else { 349 Main.info("Invalid argument");348 Logging.info("Invalid argument"); 350 349 endInput(); 351 350 } … … 392 391 || currentMapFrame.mapMode instanceof RelationAction 393 392 || currentMapFrame.mapMode instanceof AnyAction) { 394 Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected(); 393 Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getSelected(); 395 394 if (!selected.isEmpty()) 396 395 loadParameter(selected, true); … … 488 487 ProcessBuilder builder; 489 488 builder = new ProcessBuilder(listToRun); 490 builder.directory( new File(getPluginDir()));489 builder.directory(getPluginDirs().getUserDataDirectory(false)); 491 490 492 491 final StringBuilder debugstr = new StringBuilder(); … … 497 496 } 498 497 debugstr.append("\n"); 499 Main.info(debugstr.toString());498 Logging.info(debugstr.toString()); 500 499 501 500 final ToolProcess tp = new ToolProcess(); … … 504 503 } catch (final IOException e) { 505 504 synchronized (debugstr) { 506 Main.error(505 Logging.error( 507 506 tr("Error executing the script: ") + 508 507 debugstr.toString() + e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())); … … 525 524 } 526 525 } catch (IOException e) { 527 Main.warn(e);526 Logging.warn(e); 528 527 } 529 528 }).start(); … … 537 536 printWriter = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); 538 537 } catch (Exception e1) { 539 Main.error(e1);538 Logging.error(e1); 540 539 } 541 540 final OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(printWriter, true, null); … … 581 580 GpxFilter gpxFilter = new GpxFilter(); 582 581 gpxFilter.initBboxFilter(bbox); 583 List<GpxLayer> gpxLayers = Main.getLayerManager().getLayersOfType(GpxLayer.class); 582 List<GpxLayer> gpxLayers = MainApplication.getLayerManager().getLayersOfType(GpxLayer.class); 584 583 for (GpxLayer gpxLayer : gpxLayers) { 585 584 gpxFilter.addGpxData(gpxLayer.data); … … 587 586 gpxWriter.write(gpxFilter.getGpxData()); 588 587 } catch (IOException e2) { 589 Main.warn(e2);588 Logging.warn(e2); 590 589 } 591 590 } … … 600 599 601 600 // Read stdout stream 602 final DataSet currentDataSet = Main.getLayerManager().getEditDataSet(); 601 final DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet(); 603 602 final CommandLine that = this; 604 Thread osmParseThread = new Thread(new Runnable() { 605 @Override 606 public void run() { 607 try { 608 final OsmToCmd osmToCmd = new OsmToCmd(that, currentDataSet); 609 String commandName = currentCommand.name; 610 final InputStream inputStream = tp.process.getInputStream(); 611 osmToCmd.parseStream(inputStream); 612 final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList(); 613 if (!cmdlist.isEmpty()) { 614 final SequenceCommand cmd = new SequenceCommand(commandName, cmdlist); 615 SwingUtilities.invokeLater(new Runnable() { 616 @Override 617 public void run() { 618 Main.main.undoRedo.add(cmd); 619 } 620 }); 621 } 622 } catch (Exception e) { 623 Main.warn(e); 624 } finally { 625 synchronized (syncObj) { 626 tp.running = false; 627 syncObj.notifyAll(); 628 } 629 } 630 } 631 603 Thread osmParseThread = new Thread(() -> { 604 try { 605 final OsmToCmd osmToCmd = new OsmToCmd(that, currentDataSet); 606 String commandName = currentCommand.name; 607 final InputStream inputStream = tp.process.getInputStream(); 608 osmToCmd.parseStream(inputStream); 609 final List<org.openstreetmap.josm.command.Command> cmdlist = osmToCmd.getCommandList(); 610 if (!cmdlist.isEmpty()) { 611 final SequenceCommand cmd = new SequenceCommand(commandName, cmdlist); 612 SwingUtilities.invokeLater(() -> Main.main.undoRedo.add(cmd)); 613 } 614 } catch (Exception e) { 615 Logging.warn(e); 616 } finally { 617 synchronized (syncObj) { 618 tp.running = false; 619 syncObj.notifyAll(); 620 } 621 } 632 622 }); 633 623 … … 637 627 synchronized (syncObj) { 638 628 try { 639 syncObj.wait(Main.pref.getInt eger("commandline.timeout", 20000));629 syncObj.wait(Main.pref.getInt("commandline.timeout", 20000)); 640 630 } catch (InterruptedException e) { 641 Main.warn(e);631 Logging.warn(e); 642 632 } 643 633 } … … 653 643 } 654 644 } catch (InterruptedException e) { 655 Main.warn(e);645 Logging.warn(e); 656 646 } 657 647 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java
r33238 r33733 6 6 import java.awt.event.KeyEvent; 7 7 8 import org.openstreetmap.josm.Main;9 8 import org.openstreetmap.josm.actions.mapmode.MapMode; 9 import org.openstreetmap.josm.gui.MainApplication; 10 import org.openstreetmap.josm.gui.MapFrame; 10 11 import org.openstreetmap.josm.tools.ImageProvider; 11 12 … … 30 31 31 32 public void cancelDrawing() { 32 if ( Main.map == null || Main.map.mapView == null)33 if (!MainApplication.isDisplayingMapView()) 33 34 return; 34 Main.map.statusLine.setHeading(-1); 35 Main.map.statusLine.setAngle(-1); 36 Main.map.mapView.repaint(); 35 MapFrame map = MainApplication.getMap(); 36 map.statusLine.setHeading(-1); 37 map.statusLine.setAngle(-1); 38 map.mapView.repaint(); 37 39 updateStatusLine(); 38 40 parentPlugin.abortInput(); -
applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java
r33238 r33733 18 18 import java.awt.geom.GeneralPath; 19 19 20 import org.openstreetmap.josm.Main;21 20 import org.openstreetmap.josm.actions.mapmode.MapMode; 22 21 import org.openstreetmap.josm.data.Bounds; … … 24 23 import org.openstreetmap.josm.data.osm.Node; 25 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 import org.openstreetmap.josm.data.preferences.ColorProperty; 25 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 26 import org.openstreetmap.josm.gui.MainApplication; 27 import org.openstreetmap.josm.gui.MapFrame; 27 28 import org.openstreetmap.josm.gui.MapView; 28 29 import org.openstreetmap.josm.gui.layer.Layer; … … 30 31 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 31 32 import org.openstreetmap.josm.tools.ImageProvider; 33 import org.openstreetmap.josm.tools.Logging; 32 34 33 35 public class LengthAction extends MapMode implements MapViewPaintable, AWTEventListener { … … 48 50 super(null, "addsegment.png", null, ImageProvider.getCursor("crosshair", null)); 49 51 this.parentPlugin = parentPlugin; 50 selectedColor = new ColorProperty(marktr("selected"), Color.red).get(); 52 selectedColor = new NamedColorProperty(marktr("selected"), Color.red).get(); 51 53 cursorCrosshair = ImageProvider.getCursor("crosshair", null); 52 54 cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode"); … … 58 60 public void enterMode() { 59 61 super.enterMode(); 60 Main.map.mapView.addMouseListener(this); 61 Main.map.mapView.addMouseMotionListener(this); 62 Main.map.mapView.addTemporaryLayer(this); 62 MapView mapView = MainApplication.getMap().mapView; 63 mapView.addMouseListener(this); 64 mapView.addMouseMotionListener(this); 65 mapView.addTemporaryLayer(this); 63 66 try { 64 67 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 65 68 } catch (SecurityException ex) { 66 Main.warn(ex);69 Logging.warn(ex); 67 70 } 68 71 } … … 71 74 public void exitMode() { 72 75 super.exitMode(); 73 Main.map.mapView.removeMouseListener(this); 74 Main.map.mapView.removeMouseMotionListener(this); 75 Main.map.mapView.removeTemporaryLayer(this); 76 MapView mapView = MainApplication.getMap().mapView; 77 mapView.removeMouseListener(this); 78 mapView.removeMouseMotionListener(this); 79 mapView.removeTemporaryLayer(this); 76 80 try { 77 81 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 78 82 } catch (SecurityException ex) { 79 Main.warn(ex);83 Logging.warn(ex); 80 84 } 81 85 if (drawing) 82 Main.map.mapView.repaint();86 mapView.repaint(); 83 87 } 84 88 85 89 public void cancelDrawing() { 86 if (Main.map == null || Main.map.mapView == null) 87 return; 88 Main.map.statusLine.setHeading(-1); 89 Main.map.statusLine.setAngle(-1); 90 MapFrame map = MainApplication.getMap(); 91 if (map == null || map.mapView == null) 92 return; 93 map.statusLine.setHeading(-1); 94 map.statusLine.setAngle(-1); 90 95 updateStatusLine(); 91 96 parentPlugin.abortInput(); … … 93 98 94 99 @Override 95 public void eventDispatched(AWTEvent arg0) {96 if (!( arg0instanceof KeyEvent))97 return; 98 KeyEvent ev = (KeyEvent) arg0;100 public void eventDispatched(AWTEvent event) { 101 if (!(event instanceof KeyEvent)) 102 return; 103 KeyEvent ev = (KeyEvent) event; 99 104 if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) { 100 105 if (drawing) … … 132 137 mousePos = e.getPoint(); 133 138 if (nearestNode != null) { 134 drawStartPos = Main .map.mapView.getPoint(nearestNode.getCoor());139 drawStartPos = MainApplication.getMap().mapView.getPoint(nearestNode.getCoor()); 135 140 } else { 136 141 drawStartPos = mousePos; 137 142 } 138 143 drawEndPos = drawStartPos; 139 startCoor = Main .map.mapView.getLatLon(drawStartPos.x, drawStartPos.y);144 startCoor = MainApplication.getMap().mapView.getLatLon(drawStartPos.x, drawStartPos.y); 140 145 endCoor = startCoor; 141 146 drawing = true; … … 153 158 public void mousePressed(MouseEvent e) { 154 159 if (e.getButton() == MouseEvent.BUTTON1) { 155 if (!Main .map.mapView.isActiveLayerDrawable())160 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 156 161 return; 157 162 requestFocusInMapView(); … … 165 170 if (e.getButton() != MouseEvent.BUTTON1) 166 171 return; 167 if (!Main .map.mapView.isActiveLayerDrawable())172 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 168 173 return; 169 174 boolean dragged = true; … … 179 184 processMouseEvent(e); 180 185 updCursor(); 186 MapFrame map = MainApplication.getMap(); 181 187 if (nearestNode != null) 182 drawEndPos = Main.map.mapView.getPoint(nearestNode.getCoor());188 drawEndPos = map.mapView.getPoint(nearestNode.getCoor()); 183 189 else 184 190 drawEndPos = mousePos; 185 endCoor = Main.map.mapView.getLatLon(drawEndPos.x, drawEndPos.y);191 endCoor = map.mapView.getLatLon(drawEndPos.x, drawEndPos.y); 186 192 if (drawing) { 187 Main.map.statusLine.setDist(startCoor.greatCircleDistance(endCoor));188 Main.map.mapView.repaint();193 map.statusLine.setDist(startCoor.greatCircleDistance(endCoor)); 194 map.mapView.repaint(); 189 195 } 190 196 } … … 192 198 @Override 193 199 public void mouseMoved(MouseEvent e) { 194 if (!Main .map.mapView.isActiveLayerDrawable())200 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 195 201 return; 196 202 processMouseEvent(e); 197 203 updCursor(); 198 204 if (drawing) 199 Main .map.mapView.repaint();205 MainApplication.getMap().mapView.repaint(); 200 206 } 201 207 … … 215 221 private void updCursor() { 216 222 if (mousePos != null) { 217 if (!Main.isDisplayingMapView()) 223 if (!MainApplication.isDisplayingMapView()) 218 224 return; 219 nearestNode = Main .map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);225 nearestNode = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable); 220 226 if (nearestNode != null) { 221 227 setCursor(cursorJoinNode); … … 231 237 try { 232 238 // We invoke this to prevent strange things from happening 233 EventQueue.invokeLater(new Runnable() { 234 @Override 235 public void run() { 236 // Don't change cursor when mode has changed already 237 if (!(Main.map.mapMode instanceof LengthAction)) 238 return; 239 Main.map.mapView.setCursor(c); 240 } 239 EventQueue.invokeLater(() -> { 240 // Don't change cursor when mode has changed already 241 if (!(MainApplication.getMap().mapMode instanceof LengthAction)) 242 return; 243 MainApplication.getMap().mapView.setCursor(c); 241 244 }); 242 245 currentCursor = c; 243 246 } catch (Exception e) { 244 Main.warn(e);247 Logging.warn(e); 245 248 } 246 249 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java
r32779 r33733 8 8 import javax.xml.parsers.SAXParserFactory; 9 9 10 import org.openstreetmap.josm. Main;10 import org.openstreetmap.josm.tools.Logging; 11 11 import org.xml.sax.Attributes; 12 12 import org.xml.sax.SAXException; … … 15 15 16 16 public class Loader extends DefaultHandler { 17 private final StringdirToScan;17 private final File dirToScan; 18 18 private String currentFile; // For debug XML-files 19 19 private String currentTag; … … 22 22 private final ArrayList<Command> loadingCommands; 23 23 24 public Loader( Stringdir) {24 public Loader(File dir) { 25 25 dirToScan = dir; 26 26 currentTag = ""; … … 34 34 35 35 // Files loading 36 String[] list = new File(dirToScan+ "/").list();36 String[] list = dirToScan.list(); 37 37 if (list != null) { 38 38 for (int i = 0; i < list.length; i++) { 39 39 if (list[i].endsWith(".xml")) { 40 currentFile = dirToScan + "/" + list[i]; 40 currentFile = dirToScan.getPath() + "/" + list[i]; 41 41 loadFile(sp, currentFile); 42 42 } … … 44 44 } 45 45 } catch (Exception e) { 46 Main.error(e);46 Logging.error(e); 47 47 } 48 48 return loadingCommands; … … 52 52 try { 53 53 String a = new File(fileName).toURI().toString().replace("file:/", "file:///"); 54 Main.info(a);54 Logging.info(a); 55 55 parser.parse(a, this); 56 56 } catch (Exception e) { 57 Main.error(e);57 Logging.error(e); 58 58 } 59 59 // TODO: Create links for each argument … … 153 153 @Override 154 154 public void warning(SAXParseException ex) { 155 Main.warn("Warning in command xml file " + currentFile + ": " + ex.getMessage());155 Logging.warn("Warning in command xml file " + currentFile + ": " + ex.getMessage()); 156 156 } 157 157 158 158 @Override 159 159 public void error(SAXParseException ex) { 160 Main.error("Error in command xml file " + currentFile + ": " + ex.getMessage());160 Logging.error("Error in command xml file " + currentFile + ": " + ex.getMessage()); 161 161 } 162 162 163 163 @Override 164 164 public void fatalError(SAXParseException ex) throws SAXException { 165 Main.error("Error in command xml file " + currentFile + ": " + ex.getMessage());165 Logging.error("Error in command xml file " + currentFile + ": " + ex.getMessage()); 166 166 throw ex; 167 167 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java
r33238 r33733 4 4 import java.awt.Point; 5 5 6 import org.openstreetmap.josm.Main;7 6 import org.openstreetmap.josm.data.osm.Node; 8 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.gui.MainApplication; 9 9 10 10 public class NodeAction extends AbstractOsmAction<Node> { … … 16 16 @Override 17 17 protected Node getNearest(Point mousePos) { 18 return Main .map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);18 return MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable); 19 19 } 20 20 } -
applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java
r32779 r33733 14 14 import javax.xml.parsers.SAXParserFactory; 15 15 16 import org.openstreetmap.josm.Main;17 16 import org.openstreetmap.josm.command.AddCommand; 18 17 import org.openstreetmap.josm.command.ChangeCommand; … … 34 33 import org.openstreetmap.josm.data.osm.Way; 35 34 import org.openstreetmap.josm.data.osm.WayData; 35 import org.openstreetmap.josm.gui.MainApplication; 36 36 import org.openstreetmap.josm.io.IllegalDataException; 37 37 import org.openstreetmap.josm.io.UTFInputStreamReader; 38 import org.openstreetmap.josm.tools.Logging; 38 39 import org.openstreetmap.josm.tools.XmlParsingException; 39 40 import org.openstreetmap.josm.tools.date.DateUtils; … … 218 219 currentPrimitive.put(key.intern(), value.intern()); 219 220 } else { 220 Main.warn(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));221 Logging.warn(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName)); 221 222 } 222 223 } catch (Exception e) { … … 227 228 @Override 228 229 public void endElement(String namespaceURI, String localName, String qName) { 230 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 229 231 if (qName.equals("node")) { 230 232 if (currentPrimitive.isDeleted()) { 231 233 cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()))); 232 234 } else if (currentPrimitive.isModified()) { 233 cmds.add(new ChangeCommand( Main.getLayerManager().getEditLayer(),235 cmds.add(new ChangeCommand(ds, 234 236 targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 235 237 } else if (currentPrimitive.isNew()) { 236 cmds.add(new AddCommand(currentPrimitive)); 238 cmds.add(new AddCommand(ds, currentPrimitive)); 237 239 } 238 240 } else if (qName.equals("way")) { … … 241 243 cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()))); 242 244 } else if (currentPrimitive.isModified()) { 243 cmds.add(new ChangeCommand( Main.getLayerManager().getEditLayer(),245 cmds.add(new ChangeCommand(ds, 244 246 targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 245 247 } else if (currentPrimitive.isNew()) { 246 cmds.add(new AddCommand(currentPrimitive)); 248 cmds.add(new AddCommand(ds, currentPrimitive)); 247 249 } 248 250 } else if (qName.equals("relation")) { … … 251 253 cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()))); 252 254 } else if (currentPrimitive.isModified()) { 253 cmds.add(new ChangeCommand( Main.getLayerManager().getEditLayer(),255 cmds.add(new ChangeCommand(ds, 254 256 targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive)); 255 257 } else if (currentPrimitive.isNew()) { 256 cmds.add(new AddCommand(currentPrimitive)); 258 cmds.add(new AddCommand(ds, currentPrimitive)); 257 259 } 258 260 } … … 370 372 } catch (NumberFormatException e) { 371 373 if (current.getUniqueId() <= 0) { 372 Main.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",374 Logging.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", 373 375 v, current.getUniqueId())); 374 376 current.setChangesetId(0); … … 379 381 if (current.getChangesetId() <= 0) { 380 382 if (current.getUniqueId() <= 0) { 381 Main.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.",383 Logging.warn(tr("Illegal value for attribute ''changeset'' on new object {1}. Got {0}. Resetting to 0.", 382 384 v, current.getUniqueId())); 383 385 current.setChangesetId(0); -
applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java
r33368 r33733 21 21 import org.openstreetmap.josm.data.osm.Node; 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.gui.MainApplication; 24 import org.openstreetmap.josm.gui.MapFrame; 23 25 import org.openstreetmap.josm.tools.ImageProvider; 26 import org.openstreetmap.josm.tools.Logging; 24 27 25 28 public class PointAction extends MapMode implements AWTEventListener { … … 46 49 super.enterMode(); 47 50 if (getLayerManager().getEditDataSet() == null) { 48 Main .map.selectSelectTool(false);51 MainApplication.getMap().selectSelectTool(false); 49 52 return; 50 53 } 51 54 currentCursor = cursorCrosshair; 52 Main .map.mapView.addMouseListener(this);53 Main .map.mapView.addMouseMotionListener(this);55 MainApplication.getMap().mapView.addMouseListener(this); 56 MainApplication.getMap().mapView.addMouseMotionListener(this); 54 57 try { 55 58 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 56 59 } catch (SecurityException ex) { 57 Main.warn(ex);60 Logging.warn(ex); 58 61 } 59 62 } … … 61 64 @Override public void exitMode() { 62 65 super.exitMode(); 63 Main .map.mapView.removeMouseListener(this);64 Main .map.mapView.removeMouseMotionListener(this);66 MainApplication.getMap().mapView.removeMouseListener(this); 67 MainApplication.getMap().mapView.removeMouseMotionListener(this); 65 68 try { 66 69 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 67 70 } catch (SecurityException ex) { 68 Main.warn(ex);71 Logging.warn(ex); 69 72 } 70 73 } … … 80 83 LatLon coor; 81 84 if (nearestNode == null) 82 coor = Main .map.mapView.getLatLon(e.getX(), e.getY());85 coor = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY()); 83 86 else 84 87 coor = nearestNode.getCoor(); … … 91 94 if (maxInstances == 1) { 92 95 parentPlugin.loadParameter(point, true); 93 Main .map.selectSelectTool(false);96 MainApplication.getMap().selectSelectTool(false); 94 97 } else { 95 98 if (pointList.size() < maxInstances || maxInstances == 0) { … … 97 100 updateTextEdit(); 98 101 } else 99 Main.info("Maximum instances!");102 Logging.info("Maximum instances!"); 100 103 } 101 104 } … … 105 108 @Override 106 109 public void mouseMoved(MouseEvent e) { 107 if (!Main .map.mapView.isActiveLayerDrawable())110 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 108 111 return; 109 112 processMouseEvent(e); 110 113 updCursor(); 111 Main .map.mapView.repaint();114 MainApplication.getMap().mapView.repaint(); 112 115 } 113 116 … … 126 129 private void updCursor() { 127 130 if (mousePos != null) { 128 if (!Main.isDisplayingMapView()) 131 if (!MainApplication.isDisplayingMapView()) 129 132 return; 130 nearestNode = Main .map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);133 nearestNode = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable); 131 134 if (nearestNode != null) { 132 135 setCursor(cursorJoinNode); … … 148 151 try { 149 152 // We invoke this to prevent strange things from happening 150 EventQueue.invokeLater(new Runnable() { 151 @Override 152 public void run() { 153 // Don't change cursor when mode has changed already 154 if (!(Main.map.mapMode instanceof PointAction)) 155 return; 156 Main.map.mapView.setCursor(c); 157 } 153 EventQueue.invokeLater(() -> { 154 // Don't change cursor when mode has changed already 155 if (!(MainApplication.getMap().mapMode instanceof PointAction)) 156 return; 157 MainApplication.getMap().mapView.setCursor(c); 158 158 }); 159 159 currentCursor = c; 160 160 } catch (Exception e) { 161 Main.warn(e);161 Logging.warn(e); 162 162 } 163 163 } 164 164 165 165 public void cancelDrawing() { 166 if ( Main.map == null || Main.map.mapView == null)166 if (!MainApplication.isDisplayingMapView()) 167 167 return; 168 Main.map.statusLine.setHeading(-1); 169 Main.map.statusLine.setAngle(-1); 170 Main.map.mapView.repaint(); 168 MapFrame map = MainApplication.getMap(); 169 map.statusLine.setHeading(-1); 170 map.statusLine.setAngle(-1); 171 map.mapView.repaint(); 171 172 updateStatusLine(); 172 173 parentPlugin.abortInput(); -
applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java
r33238 r33733 6 6 import java.awt.event.KeyEvent; 7 7 8 import org.openstreetmap.josm.Main;9 8 import org.openstreetmap.josm.actions.mapmode.MapMode; 9 import org.openstreetmap.josm.gui.MainApplication; 10 import org.openstreetmap.josm.gui.MapFrame; 10 11 import org.openstreetmap.josm.tools.ImageProvider; 11 12 … … 30 31 31 32 public void cancelDrawing() { 32 if ( Main.map == null || Main.map.mapView == null)33 if (!MainApplication.isDisplayingMapView()) 33 34 return; 34 Main.map.statusLine.setHeading(-1); 35 Main.map.statusLine.setAngle(-1); 36 Main.map.mapView.repaint(); 35 MapFrame map = MainApplication.getMap(); 36 map.statusLine.setHeading(-1); 37 map.statusLine.setAngle(-1); 38 map.mapView.repaint(); 37 39 updateStatusLine(); 38 40 parentPlugin.abortInput(); -
applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java
r33238 r33733 4 4 import java.awt.Point; 5 5 6 import org.openstreetmap.josm.Main;7 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 7 import org.openstreetmap.josm.data.osm.Way; 8 import org.openstreetmap.josm.gui.MainApplication; 9 9 10 10 public class WayAction extends AbstractOsmAction<Way> { … … 16 16 @Override 17 17 protected Way getNearest(Point mousePos) { 18 return Main .map.mapView.getNearestWay(mousePos, OsmPrimitive::isUsable);18 return MainApplication.getMap().mapView.getNearestWay(mousePos, OsmPrimitive::isUsable); 19 19 } 20 20 }
Note:
See TracChangeset
for help on using the changeset viewer.