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


Ignore:
Timestamp:
2013-12-27T15:03:59+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #9482, see #9423, see #6853 - fix regression from r6542: irregular behaviour drawing ways

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

Legend:

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

    r6535 r6546  
    5151import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    5252import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
     53import org.openstreetmap.josm.actions.mapmode.DrawAction;
    5354import org.openstreetmap.josm.actions.mapmode.MapMode;
    5455import org.openstreetmap.josm.actions.search.SearchAction;
     
    6061import org.openstreetmap.josm.data.coor.LatLon;
    6162import org.openstreetmap.josm.data.osm.DataSet;
     63import org.openstreetmap.josm.data.osm.OsmPrimitive;
    6264import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;
    6365import org.openstreetmap.josm.data.projection.Projection;
     
    591593        return getEditLayer().data;
    592594    }
     595   
     596    /**
     597     * Replies the current selected primitives, from a end-user point of view.
     598     * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
     599     * Indeed, if the user is currently in drawing mode, only the way currently being drawn is returned,
     600     * see {@link DrawAction#getInProgressSelection()}.
     601     *
     602     * @return The current selected primitives, from a end-user point of view. Can be {@code null}.
     603     * @since 6546
     604     */
     605    public Collection<OsmPrimitive> getInProgressSelection() {
     606        if (map != null && map.mapMode instanceof DrawAction) {
     607            return ((DrawAction) map.mapMode).getInProgressSelection();
     608        } else {
     609            DataSet ds = getCurrentDataSet();
     610            if (ds == null) return null;
     611            return ds.getSelected();
     612        }
     613    }
    593614
    594615    /**
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r6542 r6546  
    186186                needsRepaint = true;
    187187            } else if (!alt && continueFrom != null && !continueFrom.isSelected()) {
    188                 addRemoveSelection(currentDataSet, continueFrom, currentBaseNode);
     188                currentDataSet.addSelected(continueFrom);
    189189                needsRepaint = true;
    190190            }
     
    12561256     *
    12571257     * While drawing a way, technically the last node is selected.
    1258      * This is inconvenient when the user tries to add tags to the
    1259      * way using a keyboard shortcut. In that case, this method returns
    1260      * the current way as selection, to work around this issue.
     1258     * This is inconvenient when the user tries to add/edit tags to the way.
     1259     * For this case, this method returns the current way as selection,
     1260     * to work around this issue.
    12611261     * Otherwise the normal selection of the current data layer is returned.
    12621262     */
     
    12661266        if (currentBaseNode != null && !ds.getSelected().isEmpty()) {
    12671267            Way continueFrom = getWayForNode(currentBaseNode);
    1268             if (alt && continueFrom != null)
     1268            if (continueFrom != null)
    12691269                return Collections.<OsmPrimitive>singleton(continueFrom);
    12701270        }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r6507 r6546  
    942942
    943943        /**
    944          * Determine prmitive to be selected and build cycleList
     944         * Determine primitive to be selected and build cycleList
    945945         * @param nearest primitive found by simple method
    946946         * @param p point where user clicked
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r6365 r6546  
    212212        @Override public Collection<OsmPrimitive> getSelection() {
    213213            if (Main.main == null) return null;
    214             if (Main.main.getCurrentDataSet() == null) return null;
    215             return Main.main.getCurrentDataSet().getSelected();
     214            return Main.main.getInProgressSelection();
    216215        }
    217216    };
     
    499498     */
    500499    private void updateSelection() {
    501         if (Main.main.getCurrentDataSet() == null) {
    502             selectionChanged(Collections.<OsmPrimitive>emptyList());
    503         } else {
    504             selectionChanged(Main.main.getCurrentDataSet().getSelected());
    505         }
     500        // Parameter is ignored in this class
     501        selectionChanged(null);
    506502    }
    507503
     
    535531        super.setVisible(b);
    536532        if (b && Main.main.getCurrentDataSet() != null) {
    537             selectionChanged(Main.main.getCurrentDataSet().getSelected());
     533            updateSelection();
    538534        }
    539535    }
     
    560556        if (tagTable.getCellEditor() != null) {
    561557            tagTable.getCellEditor().cancelCellEditing();
     558        }
     559       
     560        // Discard parameter as we do not want to operate always on real selection here, especially in draw mode
     561        newSelection = Main.main.getInProgressSelection();
     562        if (newSelection == null) {
     563            newSelection = Collections.<OsmPrimitive>emptyList();
    562564        }
    563565
     
    875877            }
    876878
    877             Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     879            Collection<OsmPrimitive> sel = Main.main.getInProgressSelection();
    878880            Main.main.undoRedo.add(new ChangePropertyCommand(sel, tags));
    879881
     
    905907
    906908            Relation rel = new Relation(cur);
    907             Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
    908             for (OsmPrimitive primitive: sel) {
     909            for (OsmPrimitive primitive: Main.main.getInProgressSelection()) {
    909910                rel.removeMembersFor(primitive);
    910911            }
     
    11081109                return;
    11091110            String key = tagData.getValueAt(tagTable.getSelectedRow(), 0).toString();
    1110             Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     1111            Collection<OsmPrimitive> sel = Main.main.getInProgressSelection();
    11111112            String clipboard = Utils.getClipboardContent();
    11121113            if (sel.isEmpty() || clipboard == null)
     
    11241125            int[] rows = tagTable.getSelectedRows();
    11251126            Set<String> values = new TreeSet<String>();
    1126             Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     1127            Collection<OsmPrimitive> sel = Main.main.getInProgressSelection();
    11271128            if (rows.length == 0 || sel.isEmpty()) return;
    11281129
     
    12081209                return;
    12091210            String key = tagData.getValueAt(tagTable.getSelectedRow(), 0).toString();
    1210             Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     1211            Collection<OsmPrimitive> sel = Main.main.getInProgressSelection();
    12111212            if (sel.isEmpty())
    12121213                return;
     
    12431244        if ("display.discardable-keys".equals(e.getKey()) && Main.main.getCurrentDataSet() != null) {
    12441245            // Re-load data when display preference change
    1245             selectionChanged(Main.main.getCurrentDataSet().getSelected());
     1246            updateSelection();
    12461247        }
    12471248    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r6403 r6546  
    5757import org.openstreetmap.josm.Main;
    5858import org.openstreetmap.josm.actions.JosmAction;
    59 import org.openstreetmap.josm.actions.mapmode.DrawAction;
    6059import org.openstreetmap.josm.command.ChangePropertyCommand;
    6160import org.openstreetmap.josm.command.Command;
    6261import org.openstreetmap.josm.command.SequenceCommand;
    63 import org.openstreetmap.josm.data.osm.DataSet;
    6462import org.openstreetmap.josm.data.osm.OsmPrimitive;
    6563import org.openstreetmap.josm.data.osm.Tag;
     
    105103    public static final int MAX_LRU_TAGS_NUMBER = 30;
    106104
    107     // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) 
     105    // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html)
    108106    private final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(MAX_LRU_TAGS_NUMBER+1, 1.1f, true) {
    109107        @Override
     
    124122    public void addTag() {
    125123        changedKey = null;
    126         if (Main.map.mapMode instanceof DrawAction) {
    127             sel = ((DrawAction) Main.map.mapMode).getInProgressSelection();
    128         } else {
    129             DataSet ds = Main.main.getCurrentDataSet();
    130             if (ds == null) return;
    131             sel = ds.getSelected();
    132         }
    133         if (sel.isEmpty()) return;
    134 
    135         final AddTagsDialog addDialog = new AddTagsDialog();       
     124        sel = Main.main.getInProgressSelection();
     125        if (sel == null || sel.isEmpty()) return;
     126
     127        final AddTagsDialog addDialog = new AddTagsDialog();
    136128       
    137129        addDialog.showDialog();
    138130       
    139131        addDialog.destroyActions();
    140         if (addDialog.getValue() == 1)           
     132        if (addDialog.getValue() == 1)
    141133            addDialog.performTagAdding();
    142         else 
     134        else
    143135            addDialog.undoAllTagsAdding();
    144136    }
     
    152144    public void editTag(final int row, boolean focusOnKey) {
    153145        changedKey = null;
    154         sel = Main.main.getCurrentDataSet().getSelected();
    155         if (sel.isEmpty()) return;
     146        sel = Main.main.getInProgressSelection();
     147        if (sel == null || sel.isEmpty()) return;
    156148
    157149        String key = tagData.getValueAt(row, 0).toString();
     
    159151       
    160152        @SuppressWarnings("unchecked")
    161         final EditTagDialog editDialog = new EditTagDialog(key, row, 
     153        final EditTagDialog editDialog = new EditTagDialog(key, row,
    162154                (Map<String, Integer>) tagData.getValueAt(row, 1), focusOnKey);
    163155        editDialog.showDialog();
     
    290282            keys.setSelectedItem(key);
    291283
    292             p.add(Box.createVerticalStrut(5),GBC.eol()); 
     284            p.add(Box.createVerticalStrut(5),GBC.eol());
    293285            p.add(new JLabel(tr("Key")), GBC.std());
    294286            p.add(Box.createHorizontalStrut(10), GBC.std());
     
    307299            values.setSelectedItem(selection);
    308300            values.getEditor().setItem(selection);
    309             p.add(Box.createVerticalStrut(5),GBC.eol()); 
     301            p.add(Box.createVerticalStrut(5),GBC.eol());
    310302            p.add(new JLabel(tr("Value")), GBC.std());
    311303            p.add(Box.createHorizontalStrut(10), GBC.std());
     
    629621       
    630622        private void suggestRecentlyAddedTags(JPanel mainPanel, int tagsToShow, final FocusAdapter focus) {
    631             if (!(tagsToShow > 0 && !recentTags.isEmpty())) 
     623            if (!(tagsToShow > 0 && !recentTags.isEmpty()))
    632624                return;
    633625
     
    649641                    public void actionPerformed(ActionEvent e) {
    650642                        keys.setSelectedItem(t.getKey());
    651                         // Update list of values (fix #7951) 
     643                        // Update list of values (fix #7951)
    652644                        // fix #8298 - update list of values before setting value (?)
    653645                        focus.focusGained(null);
     
    691683                final String color = action.isEnabled() ? "" : "; color:gray";
    692684                final JLabel tagLabel = new JLabel("<html>"
    693                     + "<style>td{border:1px solid gray; font-weight:normal"+color+"}</style>" 
     685                    + "<style>td{border:1px solid gray; font-weight:normal"+color+"}</style>"
    694686                    + "<table><tr><td>" + XmlWriter.encode(t.toString(), true) + "</td></tr></table></html>");
    695687                if (action.isEnabled()) {
Note: See TracChangeset for help on using the changeset viewer.