Changeset 10467 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-06-24T00:30:42+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13037 - Small fixes for unit tests (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java

    r10382 r10467  
    6666        Main.main.undoRedo.add(new AddCommand(nnew));
    6767        getLayerManager().getEditDataSet().setSelected(nnew);
    68         if (Main.map.mapView.getRealBounds().contains(nnew.getCoor())) {
    69             Main.map.mapView.repaint();
    70         } else {
    71             AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
     68        if (Main.map.mapView != null) {
     69            if (Main.map.mapView.getRealBounds().contains(nnew.getCoor())) {
     70                Main.map.mapView.repaint();
     71            } else {
     72                AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
     73            }
    7274        }
    7375    }
  • trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    r10383 r10467  
    284284
    285285        Main.main.undoRedo.add(new SequenceCommand(tr("Align Nodes in Circle"), cmds));
    286         Main.map.repaint();
    287286    }
    288287
  • trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java

    r10463 r10467  
    205205            // Do it!
    206206            Main.main.undoRedo.add(cmd);
    207             Main.map.repaint();
    208207
    209208        } catch (InvalidSelection except) {
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r10409 r10467  
    241241
    242242        Main.main.undoRedo.add(new SequenceCommand(tr("Create Circle"), cmds));
    243         Main.map.repaint();
    244243    }
    245244
  • trunk/src/org/openstreetmap/josm/actions/DistributeAction.java

    r10409 r10467  
    9898        // Do it!
    9999        Main.main.undoRedo.add(new SequenceCommand(tr("Distribute Nodes"), cmds));
    100         Main.map.repaint();
    101100    }
    102101
  • trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java

    r10292 r10467  
    137137            }
    138138            kev.consume();
    139             Main.map.repaint();
    140139        }
    141140    }
     
    164163            offsetDialog.updateOffset();
    165164        }
    166         Main.map.repaint();
    167165        prevEastNorth = eastNorth;
    168166    }
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r10409 r10467  
    160160        if (cmds.isEmpty()) return;
    161161        Main.main.undoRedo.add(new SequenceCommand(getValue(NAME).toString(), cmds));
    162         Main.map.repaint();
    163162    }
    164163
  • trunk/src/org/openstreetmap/josm/actions/MirrorAction.java

    r10409 r10467  
    8181
    8282        Main.main.undoRedo.add(new SequenceCommand(tr("Mirror"), cmds));
    83         Main.map.repaint();
    8483    }
    8584
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r10463 r10467  
    113113                if (!commands.isEmpty()) {
    114114                    Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize / Undo"), commands));
    115                     Main.map.repaint();
    116115                } else {
    117116                    throw new InvalidUserInputException("Commands are empty");
     
    153152            final SequenceCommand command = orthogonalize(sel);
    154153            Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), command));
    155             Main.map.repaint();
    156154        } catch (InvalidUserInputException ex) {
    157155            Main.debug(ex);
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r10463 r10467  
    103103        }
    104104        Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c));
     105        // FIXME: This should be handled by undoRedo.
    105106        if (propertiesUpdated) {
    106107            ds.fireSelectionChanged();
    107108        }
    108         Main.map.repaint();
    109109    }
    110110
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r10409 r10467  
    124124            ds.endUpdate();
    125125        }
    126         Main.map.repaint();
    127126    }
    128127
  • trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java

    r10409 r10467  
    9191        // I'm sure there's a better way to handle this
    9292        Main.main.undoRedo.add(new RemoveNodesCommand(selectedWay, selectedNodes));
    93         Main.map.repaint();
    9493    }
    9594
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java

    r10306 r10467  
    122122                    public void run() {
    123123                        targetLayer.onPostDownloadFromServer();
    124                         if (Main.map != null)
    125                             Main.map.mapView.repaint();
    126124                    }
    127125                }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r10448 r10467  
    134134     */
    135135    public static void doActionPerformed(ActionEvent e) {
    136         if (!Main.map.mapView.isActiveLayerDrawable())
    137             return;
     136        MainLayerManager lm = Main.getLayerManager();
     137        OsmDataLayer editLayer = lm.getEditLayer();
     138        if (editLayer == null) {
     139            return;
     140        }
     141
    138142        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    139143        boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK)) != 0;
    140144
    141         MainLayerManager lm = Main.getLayerManager();
    142145        Command c;
    143146        if (ctrl) {
    144             c = DeleteCommand.deleteWithReferences(lm.getEditLayer(), lm.getEditDataSet().getSelected());
     147            c = DeleteCommand.deleteWithReferences(editLayer, lm.getEditDataSet().getSelected());
    145148        } else {
    146             c = DeleteCommand.delete(lm.getEditLayer(), lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
     149            c = DeleteCommand.delete(editLayer, lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
    147150        }
    148151        // if c is null, an error occurred or the user aborted. Don't do anything in that case.
    149152        if (c != null) {
    150153            Main.main.undoRedo.add(c);
     154            //FIXME: This should not be required, DeleteCommand should update the selection, otherwise undo/redo won't work.
    151155            lm.getEditDataSet().setSelected();
    152             Main.map.repaint();
    153156        }
    154157    }
     
    213216    private void repaintIfRequired(Set<OsmPrimitive> newHighlights, WaySegment newHighlightedWaySegment) {
    214217        boolean needsRepaint = false;
    215         DataSet ds = getLayerManager().getEditDataSet();
     218        OsmDataLayer editLayer = getLayerManager().getEditLayer();
    216219
    217220        if (newHighlightedWaySegment == null && oldHighlightedWaySegment != null) {
    218             if (ds != null) {
    219                 ds.clearHighlightedWaySegments();
     221            if (editLayer != null) {
     222                editLayer.data.clearHighlightedWaySegments();
    220223                needsRepaint = true;
    221224            }
    222225            oldHighlightedWaySegment = null;
    223226        } else if (newHighlightedWaySegment != null && !newHighlightedWaySegment.equals(oldHighlightedWaySegment)) {
    224             if (ds != null) {
    225                 ds.setHighlightedWaySegments(Collections.singleton(newHighlightedWaySegment));
     227            if (editLayer != null) {
     228                editLayer.data.setHighlightedWaySegments(Collections.singleton(newHighlightedWaySegment));
    226229                needsRepaint = true;
    227230            }
     
    229232        }
    230233        needsRepaint |= highlightHelper.highlightOnly(newHighlights);
    231         if (needsRepaint) {
    232             Main.map.mapView.repaint();
     234        if (needsRepaint && editLayer != null) {
     235            editLayer.invalidate();
    233236        }
    234237    }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r10446 r10467  
    185185
    186186        // update selection to reflect which way being modified
    187         DataSet currentDataSet = getLayerManager().getEditDataSet();
    188         if (getCurrentBaseNode() != null && currentDataSet != null && !currentDataSet.selectionEmpty()) {
     187        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     188        if (getCurrentBaseNode() != null && editLayer != null && !editLayer.data.selectionEmpty()) {
     189            DataSet currentDataSet = editLayer.data;
    189190            Way continueFrom = getWayForNode(getCurrentBaseNode());
    190191            if (alt && continueFrom != null && (!getCurrentBaseNode().isSelected() || continueFrom.isSelected())) {
     
    197198        }
    198199
    199         if (needsRepaint) {
    200             Main.map.mapView.repaint();
     200        if (needsRepaint && editLayer != null) {
     201            editLayer.invalidate();
    201202        }
    202203        return needsRepaint;
     
    917918    @Override
    918919    public void mouseExited(MouseEvent e) {
    919         if (!Main.map.mapView.isActiveLayerDrawable())
     920        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
     921        if (editLayer == null)
    920922            return;
    921923        mousePos = e.getPoint();
     
    925927        // caused one already, don’t do it again.
    926928        if (!repaintIssued) {
    927             Main.map.mapView.repaint();
     929            editLayer.invalidate();
    928930        }
    929931    }
  • trunk/src/org/openstreetmap/josm/command/AddCommand.java

    r9371 r10467  
    5959    @Override
    6060    public boolean executeCommand() {
    61         getLayer().data.addPrimitive(osm);
     61        getAffectedDataSet().addPrimitive(osm);
    6262        osm.setModified(true);
    6363        checkNodeStyles(osm);
     
    6767    @Override
    6868    public void undoCommand() {
    69         getLayer().data.removePrimitive(osm);
     69        getAffectedDataSet().removePrimitive(osm);
    7070        checkNodeStyles(osm);
    7171    }
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r9371 r10467  
    7878
    7979            for (PrimitiveData pd : data) {
    80                 OsmPrimitive primitive = getLayer().data.getPrimitiveById(pd);
     80                OsmPrimitive primitive = getAffectedDataSet().getPrimitiveById(pd);
    8181                boolean created = primitive == null;
    8282                if (created) {
     
    8787                }
    8888                if (created) {
    89                     getLayer().data.addPrimitive(primitive);
     89                    getAffectedDataSet().addPrimitive(primitive);
    9090                }
    9191                newPrimitives.add(primitive);
     
    115115
    116116    @Override public void undoCommand() {
    117         DataSet ds = getLayer().data;
     117        DataSet ds = getAffectedDataSet();
    118118
    119119        if (createdPrimitives == null) {
     
    167167        Collection<OsmPrimitive> prims = new HashSet<>();
    168168        for (PrimitiveData d : data) {
    169             OsmPrimitive osm = getLayer().data.getPrimitiveById(d);
     169            OsmPrimitive osm = getAffectedDataSet().getPrimitiveById(d);
    170170            if (osm == null)
    171171                throw new RuntimeException();
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r10452 r10467  
    1717import org.openstreetmap.josm.data.coor.EastNorth;
    1818import org.openstreetmap.josm.data.coor.LatLon;
     19import org.openstreetmap.josm.data.osm.DataSet;
    1920import org.openstreetmap.josm.data.osm.Node;
    2021import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    210211    protected OsmDataLayer getLayer() {
    211212        return layer;
     213    }
     214
     215    /**
     216     * Gets the data set this command affects.
     217     * @return The data set. May be <code>null</code> if no layer was set and no edit layer was found.
     218     * @since 10467
     219     */
     220    public DataSet getAffectedDataSet() {
     221        return layer == null ? null : layer.data;
    212222    }
    213223
  • trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java

    r9371 r10467  
    5959        //
    6060        for (Node n:mergedNodeList) {
    61             if (!getLayer().data.getNodes().contains(n)) {
     61            if (!getAffectedDataSet().getNodes().contains(n)) {
    6262                Main.warn(tr("Main dataset does not include node {0}", n.toString()));
    6363            }
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r10452 r10467  
    7474     */
    7575    public synchronized void add(final Command c) {
    76         DataSet ds = Main.getLayerManager().getEditDataSet();
    77         Collection<? extends OsmPrimitive> oldSelection = ds.getSelected();
     76        DataSet ds = c.getAffectedDataSet();
     77        if (ds == null) {
     78            // old, legacy behaviour
     79            ds = Main.getLayerManager().getEditDataSet();
     80        }
     81        Collection<? extends OsmPrimitive> oldSelection = null;
     82        if (ds != null) {
     83            oldSelection = ds.getSelected();
     84        }
    7885        addNoRedraw(c);
    7986        afterAdd();
    8087
    8188        // the command may have changed the selection so tell the listeners about the current situation
    82         fireIfSelectionChanged(ds, oldSelection);
     89        if (ds != null) {
     90            fireIfSelectionChanged(ds, oldSelection);
     91        }
    8392    }
    8493
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java

    r10001 r10467  
    203203                    if (pnt.compareTo(earliest) < 0) {
    204204                        earliest = pnt;
    205                     } else {
     205                    } else if (pnt.compareTo(latest) > 0) {
    206206                        latest = pnt;
    207207                    }
  • trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java

    r10212 r10467  
    1919
    2020    /**
    21      * The seconds (not milliseconds!) since 1970-01-01.
     21     * The seconds (not milliseconds!) since 1970-01-01 00:00 UTC
    2222     */
    2323    public double time;
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r10444 r10467  
    101101    @Override
    102102    protected void initializeMainWindow() {
     103        mainPanel.reAddListeners();
    103104        if (mainFrame != null) {
    104105            mainFrame.initialize();
     
    410411        final MainFrame mainFrame = new MainFrame(contentPanePrivate, mainPanel, geometry);
    411412        Main.parent = mainFrame;
    412         mainPanel.reAddListeners();
    413413
    414414        if (args.containsKey(Option.LOAD_PREFERENCES)) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r10432 r10467  
    175175     * Creates a layer list and attach it to the given mapView.
    176176     * @param layerManager The layer manager this list is for
    177      */
    178     private LayerListDialog(MainLayerManager layerManager) {
     177     * @since 10467
     178     */
     179    public LayerListDialog(MainLayerManager layerManager) {
    179180        super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."),
    180181                Shortcut.registerShortcut("subwindow:layers", tr("Toggle: {0}", tr("Layers")), KeyEvent.VK_L,
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r10428 r10467  
    257257        Main.pref.addPreferenceChangeListener(this);
    258258
     259        registerInWindowMenu();
     260    }
     261
     262    /**
     263     * Registers this dialog in the window menu. Called in the constructor.
     264     * @since 10467
     265     */
     266    protected void registerInWindowMenu() {
    259267        windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu,
    260268                (JosmAction) getToggleAction(),
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r10420 r10467  
    117117    }
    118118
     119    /**
     120     * Sets the displacement offset of this layer. The layer is automatically invalidated.
     121     * @param dx The x offset
     122     * @param dy The y offset
     123     */
    119124    public void setOffset(double dx, double dy) {
    120125        this.dx = dx;
    121126        this.dy = dy;
     127        invalidate();
    122128    }
    123129
  • trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java

    r10458 r10467  
    77import java.util.concurrent.CopyOnWriteArrayList;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.gui.util.GuiHelper;
    1011import org.openstreetmap.josm.tools.Utils;
     
    175176        insertLayerAt(layer, position);
    176177        fireLayerAdded(layer);
    177         layer.hookUpMapView(); // needs to be after fireLayerAdded
     178        if (Main.map != null) {
     179            layer.hookUpMapView(); // needs to be after fireLayerAdded
     180        }
    178181    }
    179182
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r10436 r10467  
    878878        setRequiresSaveToFile(false);
    879879        setRequiresUploadToServer(isModified());
     880        invalidate();
    880881    }
    881882
     
    886887        setRequiresSaveToFile(true);
    887888        setRequiresUploadToServer(isModified());
     889        invalidate();
    888890    }
    889891
Note: See TracChangeset for help on using the changeset viewer.