Ticket #2179: PotlatchDrawing AddDblClick FixRectangle.patch

File PotlatchDrawing AddDblClick FixRectangle.patch, 3.1 KB (added by xeen, 17 years ago)
  • src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

     
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
    1111import java.awt.event.MouseEvent;
     12import java.util.ArrayList;
    1213import java.util.Collection;
    1314import java.util.Collections;
    1415import java.util.LinkedList;
     16import java.util.List;
    1517
    1618import javax.swing.JOptionPane;
    1719
     
    5658    private Mode mode = null;
    5759    private long mouseDownTime = 0;
    5860    private boolean didMove = false;
     61    private boolean cancelDrawMode = false;
    5962    Node virtualNode = null;
    6063    WaySegment virtualWay = null;
    6164    SequenceCommand virtualCmds = null;
     
    141144     * mouse (which will become selected).
    142145     */
    143146    @Override public void mouseDragged(MouseEvent e) {
     147        cancelDrawMode = true;
    144148        if (mode == Mode.select) return;
    145149
    146150        // do not count anything as a move if it lasts less than 100 milliseconds.
     
    278282     * cursor to movement.
    279283     */
    280284    @Override public void mousePressed(MouseEvent e) {
     285        cancelDrawMode = false;
    281286        if (! (Boolean)this.getValue("active")) return;
    282287        if (e.getButton() != MouseEvent.BUTTON1)
    283288            return;
     
    328333    @Override public void mouseReleased(MouseEvent e) {
    329334        if (mode == Mode.select) {
    330335            selectionManager.unregister(Main.map.mapView);
    331             if(Main.ds.getSelected().size() == 0)
     336
     337            // Select Draw Tool if no selection has been made
     338            if(Main.ds.getSelected().size() == 0 && !cancelDrawMode) {
    332339                Main.map.selectDrawTool(true);
    333340                return;
     341            }
    334342        }
    335343        restoreCursor();
    336344
     
    341349                selectPrims(
    342350                    Main.map.mapView.getNearestCollection(e.getPoint()),
    343351                    shift, ctrl);
     352
     353                // If the user double-clicked a node, change to draw mode
     354                List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(Main.ds.getSelected());
     355                if(e.getClickCount() >=2 && sel.size() == 1 && sel.get(0) instanceof Node) {
     356                    // We need to do it like this as otherwise drawAction will see a double
     357                    // click and switch back to SelectMode
     358                    Main.worker.execute(new Runnable(){
     359                        public void run() {
     360                            Main.map.selectDrawTool(true);
     361                        }
     362                    });
     363                    return;
     364                }
    344365            } else {
    345366                Collection<OsmPrimitive> selection = Main.ds.getSelected();
    346367                if (ctrl) {
     
    401422            return tr("Move objects by dragging; Shift to add to selection (Ctrl to remove); Shift-Ctrl to rotate selected; or change selection");
    402423        }
    403424    }
    404    
     425
    405426    @Override public boolean layerIsSupported(Layer l) {
    406427        return l instanceof OsmDataLayer;
    407428    }