Changeset 33733 in osm for applications/editors


Ignore:
Timestamp:
2017-10-26T00:42:11+02:00 (7 years ago)
Author:
donvip
Message:

update to JOSM 13007

Location:
applications/editors/josm/plugins/CommandLine
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/CommandLine

    • Property svn:ignore
      •  

        old new  
        22checkstyle-josm-CommandLine.xml
        33findbugs-josm-CommandLine.xml
         4spotbugs-josm-CommandLine.xml
  • applications/editors/josm/plugins/CommandLine/build.xml

    r33238 r33733  
    44    <property name="commit.message" value="JOSM/CommandLine: fix exception after JOSM update"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="11713"/>
     6    <property name="plugin.main.version" value="13007"/>
    77
    88    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/AbstractOsmAction.java

    r33239 r33733  
    1111import java.awt.event.MouseEvent;
    1212
    13 import org.openstreetmap.josm.Main;
    1413import org.openstreetmap.josm.actions.mapmode.MapMode;
    1514import org.openstreetmap.josm.data.osm.DataSet;
    1615import org.openstreetmap.josm.data.osm.OsmPrimitive;
     16import org.openstreetmap.josm.gui.MainApplication;
     17import org.openstreetmap.josm.gui.MapFrame;
    1718import org.openstreetmap.josm.tools.ImageProvider;
     19import org.openstreetmap.josm.tools.Logging;
    1820
    1921public abstract class AbstractOsmAction<T extends OsmPrimitive> extends MapMode implements AWTEventListener {
     
    3840        super.enterMode();
    3941        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);
    4244        try {
    4345            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
    4446        } catch (SecurityException ex) {
    45             Main.warn(ex);
     47            Logging.warn(ex);
    4648        }
    4749    }
     
    4951    @Override public void exitMode() {
    5052        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);
    5355        try {
    5456            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    5557        } catch (SecurityException ex) {
    56             Main.warn(ex);
     58            Logging.warn(ex);
    5759        }
    5860    }
     
    6062    @Override
    6163    public void mouseMoved(MouseEvent e) {
    62         if (!Main.map.mapView.isActiveLayerDrawable())
     64        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
    6365            return;
    6466        processMouseEvent(e);
    6567        updCursor();
    66         Main.map.mapView.repaint();
     68        MainApplication.getMap().mapView.repaint();
    6769        super.mouseMoved(e);
    6870    }
     
    7072    @Override
    7173    public void mousePressed(MouseEvent e) {
    72         if (!Main.map.mapView.isActiveLayerDrawable())
     74        MapFrame map = MainApplication.getMap();
     75        if (!map.mapView.isActiveLayerDrawable())
    7376            return;
    7477        processMouseEvent(e);
    7578        if (nearestPrimitive != null) {
    76             DataSet ds = Main.getLayerManager().getEditDataSet();
     79            DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    7780            if (isCtrlDown) {
    7881                ds.clearSelection(nearestPrimitive);
    79                 Main.map.mapView.repaint();
     82                map.mapView.repaint();
    8083            } else {
    8184                int maxInstances = parentPlugin.currentCommand.parameters.get(parentPlugin.currentCommand.currentParameterNum).maxInstances;
     
    8386                case 0:
    8487                    ds.addSelected(nearestPrimitive);
    85                     Main.map.mapView.repaint();
     88                    map.mapView.repaint();
    8689                    break;
    8790                case 1:
    8891                    ds.addSelected(nearestPrimitive);
    89                     Main.map.mapView.repaint();
     92                    map.mapView.repaint();
    9093                    parentPlugin.loadParameter(nearestPrimitive, true);
    91                     Main.map.selectSelectTool(false);
     94                    map.selectSelectTool(false);
    9295                    break;
    9396                default:
    9497                    if (ds.getSelected().size() < maxInstances) {
    9598                        ds.addSelected(nearestPrimitive);
    96                         Main.map.mapView.repaint();
     99                        map.mapView.repaint();
    97100                    } else
    98101                        parentPlugin.printHistory("Maximum instances is " + maxInstances);
     
    117120    private void updCursor() {
    118121        if (mousePos != null) {
    119             if (!Main.isDisplayingMapView())
     122            if (!MainApplication.isDisplayingMapView())
    120123                return;
    121124            nearestPrimitive = getNearest(mousePos);
     
    143146            EventQueue.invokeLater(() -> {
    144147                // 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()))
    146149                    return;
    147                 Main.map.mapView.setCursor(c);
     150                MainApplication.getMap().mapView.setCursor(c);
    148151            });
    149152            currentCursor = c;
    150153        } catch (Exception e) {
    151             Main.warn(e);
     154            Logging.warn(e);
    152155        }
    153156    }
    154157
    155158    public void cancelDrawing() {
    156         if (Main.map == null || Main.map.mapView == null)
     159        MapFrame map = MainApplication.getMap();
     160        if (map == null || map.mapView == null)
    157161            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();
    161165        updateStatusLine();
    162166        parentPlugin.abortInput();
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/AnyAction.java

    r33238 r33733  
    44import java.awt.Point;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.data.osm.OsmPrimitive;
     7import org.openstreetmap.josm.gui.MainApplication;
    88
    99public class AnyAction extends AbstractOsmAction<OsmPrimitive> {
     
    1515    @Override
    1616    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);
    1818    }
    1919}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/CommandLine.java

    r33238 r33733  
    4343import org.openstreetmap.josm.data.osm.Relation;
    4444import org.openstreetmap.josm.data.osm.Way;
     45import org.openstreetmap.josm.gui.MainApplication;
    4546import org.openstreetmap.josm.gui.MainMenu;
    4647import org.openstreetmap.josm.gui.MapFrame;
     
    5657import org.openstreetmap.josm.plugins.PluginInformation;
    5758import org.openstreetmap.josm.tools.HttpClient;
     59import org.openstreetmap.josm.tools.Logging;
    5860import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    5961import org.openstreetmap.josm.tools.Utils;
     
    8284        textField = new CommandTextField();
    8385
    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"));
    8790            MainMenu.add(commandMenu, new CommandLineAction(this));
    8891        }
     
    99102
    100103    protected void startCommand(Command command) {
    101         if (Main.map == null)
     104        MapFrame map = MainApplication.getMap();
     105        if (map == null)
    102106            return;
    103         DataSet ds = Main.getLayerManager().getEditDataSet();
     107        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    104108        if (ds == null)
    105109            return;
     
    107111        currentCommand.resetLoading();
    108112        parseSelection(ds.getSelected());
    109         if (!(Main.map.mapMode instanceof AnyAction
    110            || Main.map.mapMode instanceof DummyAction
    111            || Main.map.mapMode instanceof LengthAction
    112            || Main.map.mapMode instanceof NodeAction
    113            || Main.map.mapMode instanceof PointAction
    114            || Main.map.mapMode instanceof RelationAction
    115            || 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;
    117121        }
    118122        if (currentCommand.currentParameterNum < currentCommand.parameters.size())
     
    138142
    139143    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));
    146145    }
    147146
    148147    private void loadCommands() {
    149         commands = (new Loader(getPluginDir())).load();
     148        commands = (new Loader(getPluginDirs().getUserDataDirectory(false))).load();
    150149        if (commands.isEmpty()) {
    151150            if (!GraphicsEnvironment.isHeadless() && JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Main.parent,
     
    154153                try {
    155154                    downloadAndInstallDefaultCommands();
    156                     commands = (new Loader(getPluginDir())).load();
     155                    commands = (new Loader(getPluginDirs().getUserDataDirectory(false))).load();
    157156                    JOptionPane.showMessageDialog(Main.parent, tr("Default commands have been successfully installed"),
    158157                            tr("Success"), JOptionPane.INFORMATION_MESSAGE);
    159158                } catch (IOException e) {
    160                     Main.warn(e);
     159                    Logging.warn(e);
    161160                    JOptionPane.showMessageDialog(Main.parent,
    162161                            tr("Failed to download and install default commands.\n\nError: {0}", e.getMessage()),
     
    174173                "https://github.com/Foxhind/JOSM-CommandLine-commands/archive/master.zip");
    175174        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);
    177176            if (!dir.exists()) {
    178177                dir.mkdirs();
     
    186185                    }
    187186                    File file = new File(dir + File.separator + name);
    188                     Main.info("Installing command file: "+file);
     187                    Logging.info("Installing command file: "+file);
    189188                    if (!file.createNewFile()) {
    190189                        throw new IOException("Could not create file: " + file.getAbsolutePath());
     
    216215
    217216    protected void setMode(Mode targetMode) {
    218         DataSet currentDataSet = Main.getLayerManager().getEditDataSet();
     217        DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet();
    219218        if (currentDataSet != null) {
    220219            currentDataSet.clearSelection();
    221             Main.map.mapView.repaint();
     220            MainApplication.getMap().mapView.repaint();
    222221        }
    223222        if (targetMode == Mode.IDLE) {
     
    261260                break;
    262261            case IMAGERYURL:
    263                 Layer layer = Main.getLayerManager().getActiveLayer();
     262                Layer layer = MainApplication.getLayerManager().getActiveLayer();
    264263                if (layer != null) {
    265264                    if (!(layer instanceof ImageryLayer)) {
    266                         List<ImageryLayer> imageryLayers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
     265                        List<ImageryLayer> imageryLayers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class);
    267266                        if (imageryLayers.size() == 1) {
    268267                            layer = imageryLayers.get(0);
     
    281280                break;
    282281            case IMAGERYOFFSET:
    283                 Layer olayer = Main.getLayerManager().getActiveLayer();
     282                Layer olayer = MainApplication.getLayerManager().getActiveLayer();
    284283                if (olayer != null) {
    285284                    if (!(olayer instanceof ImageryLayer)) {
    286                         List<ImageryLayer> imageryLayers = Main.getLayerManager().getLayersOfType(ImageryLayer.class);
     285                        List<ImageryLayer> imageryLayers = MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class);
    287286                        if (imageryLayers.size() == 1) {
    288287                            olayer = imageryLayers.get(0);
     
    307306            prefix = tr("Processing...");
    308307            textField.setText(prefix);
    309             Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     308            MainApplication.getMap().mapView.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    310309        }
    311310    }
     
    317316
    318317    public void deactivate() {
    319         Main.map.mapView.requestFocus();
     318        MainApplication.getMap().mapView.requestFocus();
    320319    }
    321320
     
    327326    public void endInput() {
    328327        setMode(Mode.IDLE);
    329         Main.map.selectMapMode(previousMode);
    330         Main.map.mapView.repaint();
     328        MainApplication.getMap().selectMapMode(previousMode);
     329        MainApplication.getMap().mapView.repaint();
    331330    }
    332331
     
    347346            }
    348347        } else {
    349             Main.info("Invalid argument");
     348            Logging.info("Invalid argument");
    350349            endInput();
    351350        }
     
    392391                         || currentMapFrame.mapMode instanceof RelationAction
    393392                         || currentMapFrame.mapMode instanceof AnyAction) {
    394                             Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected();
     393                            Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getSelected();
    395394                            if (!selected.isEmpty())
    396395                                loadParameter(selected, true);
     
    488487        ProcessBuilder builder;
    489488        builder = new ProcessBuilder(listToRun);
    490         builder.directory(new File(getPluginDir()));
     489        builder.directory(getPluginDirs().getUserDataDirectory(false));
    491490
    492491        final StringBuilder debugstr = new StringBuilder();
     
    497496        }
    498497        debugstr.append("\n");
    499         Main.info(debugstr.toString());
     498        Logging.info(debugstr.toString());
    500499
    501500        final ToolProcess tp = new ToolProcess();
     
    504503        } catch (final IOException e) {
    505504            synchronized (debugstr) {
    506                 Main.error(
     505                Logging.error(
    507506                        tr("Error executing the script: ") +
    508507                        debugstr.toString() + e.getMessage() + "\n" + Arrays.toString(e.getStackTrace()));
     
    525524                }
    526525            } catch (IOException e) {
    527                 Main.warn(e);
     526                Logging.warn(e);
    528527            }
    529528        }).start();
     
    537536                printWriter = new PrintWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));
    538537            } catch (Exception e1) {
    539                 Main.error(e1);
     538                Logging.error(e1);
    540539            }
    541540            final OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(printWriter, true, null);
     
    581580                    GpxFilter gpxFilter = new GpxFilter();
    582581                    gpxFilter.initBboxFilter(bbox);
    583                     List<GpxLayer> gpxLayers = Main.getLayerManager().getLayersOfType(GpxLayer.class);
     582                    List<GpxLayer> gpxLayers = MainApplication.getLayerManager().getLayersOfType(GpxLayer.class);
    584583                    for (GpxLayer gpxLayer : gpxLayers) {
    585584                        gpxFilter.addGpxData(gpxLayer.data);
     
    587586                    gpxWriter.write(gpxFilter.getGpxData());
    588587                } catch (IOException e2) {
    589                     Main.warn(e2);
     588                    Logging.warn(e2);
    590589                }
    591590            }
     
    600599
    601600        // Read stdout stream
    602         final DataSet currentDataSet = Main.getLayerManager().getEditDataSet();
     601        final DataSet currentDataSet = MainApplication.getLayerManager().getEditDataSet();
    603602        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            }
    632622        });
    633623
     
    637627        synchronized (syncObj) {
    638628            try {
    639                 syncObj.wait(Main.pref.getInteger("commandline.timeout", 20000));
     629                syncObj.wait(Main.pref.getInt("commandline.timeout", 20000));
    640630            } catch (InterruptedException e) {
    641                 Main.warn(e);
     631                Logging.warn(e);
    642632            }
    643633        }
     
    653643                        }
    654644                    } catch (InterruptedException e) {
    655                         Main.warn(e);
     645                        Logging.warn(e);
    656646                    }
    657647                }
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/DummyAction.java

    r33238 r33733  
    66import java.awt.event.KeyEvent;
    77
    8 import org.openstreetmap.josm.Main;
    98import org.openstreetmap.josm.actions.mapmode.MapMode;
     9import org.openstreetmap.josm.gui.MainApplication;
     10import org.openstreetmap.josm.gui.MapFrame;
    1011import org.openstreetmap.josm.tools.ImageProvider;
    1112
     
    3031
    3132    public void cancelDrawing() {
    32         if (Main.map == null || Main.map.mapView == null)
     33        if (!MainApplication.isDisplayingMapView())
    3334            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();
    3739        updateStatusLine();
    3840        parentPlugin.abortInput();
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/LengthAction.java

    r33238 r33733  
    1818import java.awt.geom.GeneralPath;
    1919
    20 import org.openstreetmap.josm.Main;
    2120import org.openstreetmap.josm.actions.mapmode.MapMode;
    2221import org.openstreetmap.josm.data.Bounds;
     
    2423import org.openstreetmap.josm.data.osm.Node;
    2524import org.openstreetmap.josm.data.osm.OsmPrimitive;
    26 import org.openstreetmap.josm.data.preferences.ColorProperty;
     25import org.openstreetmap.josm.data.preferences.NamedColorProperty;
     26import org.openstreetmap.josm.gui.MainApplication;
     27import org.openstreetmap.josm.gui.MapFrame;
    2728import org.openstreetmap.josm.gui.MapView;
    2829import org.openstreetmap.josm.gui.layer.Layer;
     
    3031import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3132import org.openstreetmap.josm.tools.ImageProvider;
     33import org.openstreetmap.josm.tools.Logging;
    3234
    3335public class LengthAction extends MapMode implements MapViewPaintable, AWTEventListener {
     
    4850        super(null, "addsegment.png", null, ImageProvider.getCursor("crosshair", null));
    4951        this.parentPlugin = parentPlugin;
    50         selectedColor = new ColorProperty(marktr("selected"), Color.red).get();
     52        selectedColor = new NamedColorProperty(marktr("selected"), Color.red).get();
    5153        cursorCrosshair = ImageProvider.getCursor("crosshair", null);
    5254        cursorJoinNode = ImageProvider.getCursor("crosshair", "joinnode");
     
    5860    public void enterMode() {
    5961        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);
    6366        try {
    6467            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
    6568        } catch (SecurityException ex) {
    66             Main.warn(ex);
     69            Logging.warn(ex);
    6770        }
    6871    }
     
    7174    public void exitMode() {
    7275        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);
    7680        try {
    7781            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    7882        } catch (SecurityException ex) {
    79             Main.warn(ex);
     83            Logging.warn(ex);
    8084        }
    8185        if (drawing)
    82             Main.map.mapView.repaint();
     86            mapView.repaint();
    8387    }
    8488
    8589    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);
    9095        updateStatusLine();
    9196        parentPlugin.abortInput();
     
    9398
    9499    @Override
    95     public void eventDispatched(AWTEvent arg0) {
    96         if (!(arg0 instanceof 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;
    99104        if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) {
    100105            if (drawing)
     
    132137        mousePos = e.getPoint();
    133138        if (nearestNode != null) {
    134             drawStartPos = Main.map.mapView.getPoint(nearestNode.getCoor());
     139            drawStartPos = MainApplication.getMap().mapView.getPoint(nearestNode.getCoor());
    135140        } else {
    136141            drawStartPos = mousePos;
    137142        }
    138143        drawEndPos = drawStartPos;
    139         startCoor = Main.map.mapView.getLatLon(drawStartPos.x, drawStartPos.y);
     144        startCoor = MainApplication.getMap().mapView.getLatLon(drawStartPos.x, drawStartPos.y);
    140145        endCoor = startCoor;
    141146        drawing = true;
     
    153158    public void mousePressed(MouseEvent e) {
    154159        if (e.getButton() == MouseEvent.BUTTON1) {
    155             if (!Main.map.mapView.isActiveLayerDrawable())
     160            if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
    156161                return;
    157162            requestFocusInMapView();
     
    165170        if (e.getButton() != MouseEvent.BUTTON1)
    166171            return;
    167         if (!Main.map.mapView.isActiveLayerDrawable())
     172        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
    168173            return;
    169174        boolean dragged = true;
     
    179184        processMouseEvent(e);
    180185        updCursor();
     186        MapFrame map = MainApplication.getMap();
    181187        if (nearestNode != null)
    182             drawEndPos = Main.map.mapView.getPoint(nearestNode.getCoor());
     188            drawEndPos = map.mapView.getPoint(nearestNode.getCoor());
    183189        else
    184190            drawEndPos = mousePos;
    185         endCoor = Main.map.mapView.getLatLon(drawEndPos.x, drawEndPos.y);
     191        endCoor = map.mapView.getLatLon(drawEndPos.x, drawEndPos.y);
    186192        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();
    189195        }
    190196    }
     
    192198    @Override
    193199    public void mouseMoved(MouseEvent e) {
    194         if (!Main.map.mapView.isActiveLayerDrawable())
     200        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
    195201            return;
    196202        processMouseEvent(e);
    197203        updCursor();
    198204        if (drawing)
    199             Main.map.mapView.repaint();
     205            MainApplication.getMap().mapView.repaint();
    200206    }
    201207
     
    215221    private void updCursor() {
    216222        if (mousePos != null) {
    217             if (!Main.isDisplayingMapView())
     223            if (!MainApplication.isDisplayingMapView())
    218224                return;
    219             nearestNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
     225            nearestNode = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
    220226            if (nearestNode != null) {
    221227                setCursor(cursorJoinNode);
     
    231237        try {
    232238            // 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);
    241244            });
    242245            currentCursor = c;
    243246        } catch (Exception e) {
    244             Main.warn(e);
     247            Logging.warn(e);
    245248        }
    246249    }
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/Loader.java

    r32779 r33733  
    88import javax.xml.parsers.SAXParserFactory;
    99
    10 import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.tools.Logging;
    1111import org.xml.sax.Attributes;
    1212import org.xml.sax.SAXException;
     
    1515
    1616public class Loader extends DefaultHandler {
    17     private final String dirToScan;
     17    private final File dirToScan;
    1818    private String currentFile; // For debug XML-files
    1919    private String currentTag;
     
    2222    private final ArrayList<Command> loadingCommands;
    2323
    24     public Loader(String dir) {
     24    public Loader(File dir) {
    2525        dirToScan = dir;
    2626        currentTag = "";
     
    3434
    3535            // Files loading
    36             String[] list = new File(dirToScan + "/").list();
     36            String[] list = dirToScan.list();
    3737            if (list != null) {
    3838                for (int i = 0; i < list.length; i++) {
    3939                    if (list[i].endsWith(".xml")) {
    40                         currentFile = dirToScan + "/" + list[i];
     40                        currentFile = dirToScan.getPath() + "/" + list[i];
    4141                        loadFile(sp, currentFile);
    4242                    }
     
    4444            }
    4545        } catch (Exception e) {
    46             Main.error(e);
     46            Logging.error(e);
    4747        }
    4848        return loadingCommands;
     
    5252        try {
    5353            String a = new File(fileName).toURI().toString().replace("file:/", "file:///");
    54             Main.info(a);
     54            Logging.info(a);
    5555            parser.parse(a, this);
    5656        } catch (Exception e) {
    57             Main.error(e);
     57            Logging.error(e);
    5858        }
    5959        // TODO: Create links for each argument
     
    153153    @Override
    154154    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());
    156156    }
    157157
    158158    @Override
    159159    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());
    161161    }
    162162
    163163    @Override
    164164    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());
    166166        throw ex;
    167167    }
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/NodeAction.java

    r33238 r33733  
    44import java.awt.Point;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.data.osm.Node;
    87import org.openstreetmap.josm.data.osm.OsmPrimitive;
     8import org.openstreetmap.josm.gui.MainApplication;
    99
    1010public class NodeAction extends AbstractOsmAction<Node> {
     
    1616    @Override
    1717    protected Node getNearest(Point mousePos) {
    18         return Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
     18        return MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
    1919    }
    2020}
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/OsmToCmd.java

    r32779 r33733  
    1414import javax.xml.parsers.SAXParserFactory;
    1515
    16 import org.openstreetmap.josm.Main;
    1716import org.openstreetmap.josm.command.AddCommand;
    1817import org.openstreetmap.josm.command.ChangeCommand;
     
    3433import org.openstreetmap.josm.data.osm.Way;
    3534import org.openstreetmap.josm.data.osm.WayData;
     35import org.openstreetmap.josm.gui.MainApplication;
    3636import org.openstreetmap.josm.io.IllegalDataException;
    3737import org.openstreetmap.josm.io.UTFInputStreamReader;
     38import org.openstreetmap.josm.tools.Logging;
    3839import org.openstreetmap.josm.tools.XmlParsingException;
    3940import org.openstreetmap.josm.tools.date.DateUtils;
     
    218219                    currentPrimitive.put(key.intern(), value.intern());
    219220                } 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));
    221222                }
    222223            } catch (Exception e) {
     
    227228        @Override
    228229        public void endElement(String namespaceURI, String localName, String qName) {
     230            DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    229231            if (qName.equals("node")) {
    230232                if (currentPrimitive.isDeleted()) {
    231233                    cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId())));
    232234                } else if (currentPrimitive.isModified()) {
    233                     cmds.add(new ChangeCommand(Main.getLayerManager().getEditLayer(),
     235                    cmds.add(new ChangeCommand(ds,
    234236                            targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
    235237                } else if (currentPrimitive.isNew()) {
    236                     cmds.add(new AddCommand(currentPrimitive));
     238                    cmds.add(new AddCommand(ds, currentPrimitive));
    237239                }
    238240            } else if (qName.equals("way")) {
     
    241243                    cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId())));
    242244                } else if (currentPrimitive.isModified()) {
    243                     cmds.add(new ChangeCommand(Main.getLayerManager().getEditLayer(),
     245                    cmds.add(new ChangeCommand(ds,
    244246                            targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
    245247                } else if (currentPrimitive.isNew()) {
    246                     cmds.add(new AddCommand(currentPrimitive));
     248                    cmds.add(new AddCommand(ds, currentPrimitive));
    247249                }
    248250            } else if (qName.equals("relation")) {
     
    251253                    cmds.add(new DeleteCommand(targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId())));
    252254                } else if (currentPrimitive.isModified()) {
    253                     cmds.add(new ChangeCommand(Main.getLayerManager().getEditLayer(),
     255                    cmds.add(new ChangeCommand(ds,
    254256                            targetDataSet.getPrimitiveById(currentPrimitive.getPrimitiveId()), currentPrimitive));
    255257                } else if (currentPrimitive.isNew()) {
    256                     cmds.add(new AddCommand(currentPrimitive));
     258                    cmds.add(new AddCommand(ds, currentPrimitive));
    257259                }
    258260            }
     
    370372                } catch (NumberFormatException e) {
    371373                    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.",
    373375                                v, current.getUniqueId()));
    374376                        current.setChangesetId(0);
     
    379381                if (current.getChangesetId() <= 0) {
    380382                    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.",
    382384                                v, current.getUniqueId()));
    383385                        current.setChangesetId(0);
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/PointAction.java

    r33368 r33733  
    2121import org.openstreetmap.josm.data.osm.Node;
    2222import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.gui.MainApplication;
     24import org.openstreetmap.josm.gui.MapFrame;
    2325import org.openstreetmap.josm.tools.ImageProvider;
     26import org.openstreetmap.josm.tools.Logging;
    2427
    2528public class PointAction extends MapMode implements AWTEventListener {
     
    4649        super.enterMode();
    4750        if (getLayerManager().getEditDataSet() == null) {
    48             Main.map.selectSelectTool(false);
     51            MainApplication.getMap().selectSelectTool(false);
    4952            return;
    5053        }
    5154        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);
    5457        try {
    5558            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
    5659        } catch (SecurityException ex) {
    57             Main.warn(ex);
     60            Logging.warn(ex);
    5861        }
    5962    }
     
    6164    @Override public void exitMode() {
    6265        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);
    6568        try {
    6669            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    6770        } catch (SecurityException ex) {
    68             Main.warn(ex);
     71            Logging.warn(ex);
    6972        }
    7073    }
     
    8083                LatLon coor;
    8184                if (nearestNode == null)
    82                     coor = Main.map.mapView.getLatLon(e.getX(), e.getY());
     85                    coor = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY());
    8386                else
    8487                    coor = nearestNode.getCoor();
     
    9194                if (maxInstances == 1) {
    9295                    parentPlugin.loadParameter(point, true);
    93                     Main.map.selectSelectTool(false);
     96                    MainApplication.getMap().selectSelectTool(false);
    9497                } else {
    9598                    if (pointList.size() < maxInstances || maxInstances == 0) {
     
    97100                        updateTextEdit();
    98101                    } else
    99                         Main.info("Maximum instances!");
     102                        Logging.info("Maximum instances!");
    100103                }
    101104            }
     
    105108    @Override
    106109    public void mouseMoved(MouseEvent e) {
    107         if (!Main.map.mapView.isActiveLayerDrawable())
     110        if (!MainApplication.getMap().mapView.isActiveLayerDrawable())
    108111            return;
    109112        processMouseEvent(e);
    110113        updCursor();
    111         Main.map.mapView.repaint();
     114        MainApplication.getMap().mapView.repaint();
    112115    }
    113116
     
    126129    private void updCursor() {
    127130        if (mousePos != null) {
    128             if (!Main.isDisplayingMapView())
     131            if (!MainApplication.isDisplayingMapView())
    129132                return;
    130             nearestNode = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
     133            nearestNode = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);
    131134            if (nearestNode != null) {
    132135                setCursor(cursorJoinNode);
     
    148151        try {
    149152            // 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);
    158158            });
    159159            currentCursor = c;
    160160        } catch (Exception e) {
    161             Main.warn(e);
     161            Logging.warn(e);
    162162        }
    163163    }
    164164
    165165    public void cancelDrawing() {
    166         if (Main.map == null || Main.map.mapView == null)
     166        if (!MainApplication.isDisplayingMapView())
    167167            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();
    171172        updateStatusLine();
    172173        parentPlugin.abortInput();
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/RelationAction.java

    r33238 r33733  
    66import java.awt.event.KeyEvent;
    77
    8 import org.openstreetmap.josm.Main;
    98import org.openstreetmap.josm.actions.mapmode.MapMode;
     9import org.openstreetmap.josm.gui.MainApplication;
     10import org.openstreetmap.josm.gui.MapFrame;
    1011import org.openstreetmap.josm.tools.ImageProvider;
    1112
     
    3031
    3132    public void cancelDrawing() {
    32         if (Main.map == null || Main.map.mapView == null)
     33        if (!MainApplication.isDisplayingMapView())
    3334            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();
    3739        updateStatusLine();
    3840        parentPlugin.abortInput();
  • applications/editors/josm/plugins/CommandLine/src/CommandLine/WayAction.java

    r33238 r33733  
    44import java.awt.Point;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.data.osm.OsmPrimitive;
    87import org.openstreetmap.josm.data.osm.Way;
     8import org.openstreetmap.josm.gui.MainApplication;
    99
    1010public class WayAction extends AbstractOsmAction<Way> {
     
    1616    @Override
    1717    protected Way getNearest(Point mousePos) {
    18         return Main.map.mapView.getNearestWay(mousePos, OsmPrimitive::isUsable);
     18        return MainApplication.getMap().mapView.getNearestWay(mousePos, OsmPrimitive::isUsable);
    1919    }
    2020}
Note: See TracChangeset for help on using the changeset viewer.