Changeset 30710 in osm


Ignore:
Timestamp:
2014-10-11T19:13:13+02:00 (10 years ago)
Author:
akks
Message:

JOSM/FastDraw: use Main.map.keyDetector instead of AWTEventListener

Location:
applications/editors/josm/plugins/FastDraw
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/FastDraw/build.xml

    r30709 r30710  
    22<project name="FastDraw" default="dist" basedir=".">
    33    <!-- enter the SVN commit message -->
    4     <property name="commit.message" value="JOSM/FastDraw: do not catch keys from other windows, fix default tags combobox"/>
     4    <property name="commit.message" value="JOSM/FastDraw: use Main.map.keyDetector instead of AWTEventListener"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="7001"/>
     6    <property name="plugin.main.version" value="7609"/>
    77   
    88    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/DrawnPolyLine.java

    r29532 r30710  
    9696        fixed.add(coor);
    9797    }
     98
     99    public Set<LatLon> getFixedPoints() {
     100        return fixed;
     101    }
     102   
    98103    void addLast(LatLon coor) {
    99104        if (closedFlag && lastIdx>points.size()-1) return;
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawConfigDialog.java

    r30709 r30710  
    88import java.text.ParseException;
    99import java.util.ArrayList;
    10 import java.util.Collection;
    11 import java.util.Collections;
    1210
    1311import javax.swing.AbstractAction;
     
    3028public class FastDrawConfigDialog extends ExtendedDialog {
    3129
     30    private final JLabel label1=new JLabel(tr("Epsilon multiplier"));
     31    private final JLabel label2=new JLabel(tr("Starting Epsilon"));
     32    private final JLabel label3=new JLabel(tr("Max points count per 1 km"));
     33    private final JLabel label4=new JLabel(/* I18n: Combobox to select what a press to return key does */ tr("Enter key mode"));
     34    private final JLabel label5=new JLabel(tr("Auto add tags"));
     35    private final JFormattedTextField text1=new JFormattedTextField(NumberFormat.getInstance());
     36    private final JFormattedTextField text2=new  JFormattedTextField(NumberFormat.getInstance());
     37    private final JFormattedTextField text3=new  JFormattedTextField(NumberFormat.getInstance());
     38    private final JComboBox<String> combo1=new JComboBox<>(new String[]{tr("Autosimplify"),
     39        tr("Simplify with initial epsilon"),tr("Save as is")});
     40    private final JCheckBox snapCb=new JCheckBox(tr("Snap to nodes"));
     41    private final JCheckBox fixedClickCb = new JCheckBox(tr("Add fixed points on click"));
     42    private final JCheckBox fixedSpaceCb = new JCheckBox(tr("Add fixed points on spacebar"));
     43    private final JCheckBox drawClosedCb = new JCheckBox(tr("Draw closed polygons only"));
     44    private final HistoryComboBox addTags = new HistoryComboBox();
     45    private final FDSettings settings;
     46
    3247    public FastDrawConfigDialog(FDSettings settings) {
    3348        super(Main.parent,tr("FastDraw configuration"),new String[] {tr("Ok"), tr("Cancel")});
     49        this.settings = settings;
     50       
    3451        JPanel all = new JPanel();
    3552        GridBagLayout layout = new GridBagLayout();
    3653        all.setLayout(layout);
    37        
    38         JLabel label1=new JLabel(tr("Epsilon multiplier"));
    39         JLabel label2=new JLabel(tr("Starting Epsilon"));
    40         JLabel label3=new JLabel(tr("Max points count per 1 km"));
    41         JLabel label4=new JLabel(/* I18n: Combobox to select what a press to return key does */ tr("Enter key mode"));
    42         JLabel label5=new JLabel(tr("Auto add tags"));
    43         JFormattedTextField text1=new JFormattedTextField(NumberFormat.getInstance());
    44         JFormattedTextField text2=new  JFormattedTextField(NumberFormat.getInstance());
    45         JFormattedTextField text3=new  JFormattedTextField(NumberFormat.getInstance());
    46 //        JComboBox combo1=new JComboBox(new String[]{tr("Autosimplify and wait"),
    47 //            tr("Autosimplify and save"),tr("Simplify and wait"),tr("Simplify and save"),
    48 //            tr("Save as is")});
    49         JComboBox<String> combo1=new JComboBox<>(new String[]{tr("Autosimplify"),
    50             tr("Simplify with initial epsilon"),tr("Save as is")});
    51         JCheckBox snapCb=new JCheckBox(tr("Snap to nodes"));
    52         JCheckBox fixedClickCb = new JCheckBox(tr("Add fixed points on click"));
    53         JCheckBox fixedSpaceCb = new JCheckBox(tr("Add fixed points on spacebar"));
    54         JCheckBox drawClosedCb = new JCheckBox(tr("Draw closed polygons only"));
    55         final HistoryComboBox addTags = new HistoryComboBox();
    5654        JButton pasteButton = new JButton(new AbstractAction(tr("Paste"), ImageProvider.get("apply")) {
    5755            @Override
     
    6462        });
    6563        pasteButton.setToolTipText(tr("Try copying tags from properties table"));
     64       
    6665        ArrayList<String> history = new ArrayList<>(Main.pref.getCollection("fastdraw.tags-history"));
    6766        while (history.remove("")) { };
     
    9897        combo1.setSelectedIndex(settings.simplifyMode);
    9998       
    100         ExtendedDialog dialog = new ExtendedDialog(Main.parent,
    101                 tr("FastDraw settings"),
    102                 new String[] {tr("Ok"), tr("Cancel")}
    103         );
    10499        setContent(all, false);
    105100        setButtonIcons(new String[] {"ok.png", "cancel.png"});
     
    110105        setDefaultButton(1);
    111106        //configureContextsensitiveHelp("/Action/DownloadObject", true /* show help button */);
    112         showDialog();
    113         if (dialog.getValue() == 0) {
     107    }
     108
     109    @Override
     110    public ExtendedDialog showDialog() {
     111        ExtendedDialog result = super.showDialog();
     112        if (getValue() == 0) {
    114113            try {
    115             settings.epsilonMult=NumberFormat.getInstance().parse(text1.getText()).doubleValue();
    116             settings.startingEps=NumberFormat.getInstance().parse(text2.getText()).doubleValue();
    117             settings.maxPointsPerKm=NumberFormat.getInstance().parse(text3.getText()).doubleValue();
    118             settings.snapNodes=snapCb.isSelected();
    119             settings.fixedClick=fixedClickCb.isSelected();
    120             settings.fixedSpacebar=fixedSpaceCb.isSelected();
    121             settings.drawClosed=drawClosedCb.isSelected();
    122             settings.simplifyMode=combo1.getSelectedIndex();
    123             settings.autoTags=addTags.getText();
    124             if (!settings.autoTags.isEmpty()) {
    125                 addTags.addCurrentItemToHistory();
    126             }
    127             Main.pref.putCollection("fastdraw.tags-history", addTags.getHistory());
    128             settings.savePrefs();
     114                settings.epsilonMult=NumberFormat.getInstance().parse(text1.getText()).doubleValue();
     115                settings.startingEps=NumberFormat.getInstance().parse(text2.getText()).doubleValue();
     116                settings.maxPointsPerKm=NumberFormat.getInstance().parse(text3.getText()).doubleValue();
     117                settings.snapNodes=snapCb.isSelected();
     118                settings.fixedClick=fixedClickCb.isSelected();
     119                settings.fixedSpacebar=fixedSpaceCb.isSelected();
     120                settings.drawClosed=drawClosedCb.isSelected();
     121                settings.simplifyMode=combo1.getSelectedIndex();
     122                settings.autoTags=addTags.getText();
     123                if (!settings.autoTags.isEmpty()) {
     124                    addTags.addCurrentItemToHistory();
     125                }
     126                Main.pref.putCollection("fastdraw.tags-history", addTags.getHistory());
     127                settings.savePrefs();
    129128            } catch (ParseException e) {
    130129              JOptionPane.showMessageDialog(Main.parent,
     
    132131            }
    133132        }
    134            
     133        return result;
     134       
    135135    }
    136136   
  • applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java

    r30709 r30710  
    77package org.openstreetmap.josm.plugins.fastdraw;
    88
    9 import java.awt.AWTEvent;
    109import java.awt.Color;
    11 import java.awt.Component;
    1210import java.awt.Cursor;
    1311import java.awt.Graphics2D;
    14 import java.awt.KeyboardFocusManager;
    1512import java.awt.Point;
    16 import java.awt.Toolkit;
    17 import java.awt.event.*;
    18 import java.util.*;
    19 import javax.swing.JFrame;
     13import java.awt.event.KeyEvent;
     14import java.awt.event.MouseEvent;
     15import java.util.ArrayList;
     16import java.util.Collection;
     17import java.util.HashSet;
     18import java.util.Iterator;
     19import java.util.LinkedList;
     20import java.util.List;
     21import java.util.Map;
     22import java.util.Set;
    2023import javax.swing.JOptionPane;
    21 import javax.swing.SwingUtilities;
    22 import javax.swing.Timer;
    2324
    2425import org.openstreetmap.josm.Main;
     
    3132import org.openstreetmap.josm.data.Bounds;
    3233import org.openstreetmap.josm.data.coor.LatLon;
    33 import org.openstreetmap.josm.data.osm.Tag;
    3434import org.openstreetmap.josm.data.osm.Node;
    3535import org.openstreetmap.josm.data.osm.OsmPrimitive;
     36import org.openstreetmap.josm.data.osm.Tag;
    3637import org.openstreetmap.josm.data.osm.Way;
    3738import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
     
    4142import org.openstreetmap.josm.gui.layer.MapViewPaintable;
    4243import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     44import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
     45import org.openstreetmap.josm.gui.util.ModifierListener;
     46import static org.openstreetmap.josm.tools.I18n.tr;
    4347import org.openstreetmap.josm.tools.ImageProvider;
    4448import org.openstreetmap.josm.tools.Shortcut;
    4549import org.openstreetmap.josm.tools.TextTagParser;
    4650
    47 import static org.openstreetmap.josm.tools.I18n.tr;
    48 
    4951class FastDrawingMode extends MapMode implements MapViewPaintable,
    50         AWTEventListener {
     52        KeyPressReleaseListener, ModifierListener {
    5153    private static final String SIMPLIFYMODE_MESSAGE=
    5254            tr("Q=Options, Enter=save, Ctrl-Enter=save with tags, Up/Down=tune");
     
    5658    private FDSettings settings;
    5759
    58     private DrawnPolyLine line;
     60    private final DrawnPolyLine line;
    5961    private MapView mv;
    6062    private String statusText;
    6163    private boolean drawing;
    62     private boolean ctrl;
    63     private boolean shift;
    6464    private double eps;
    6565    private final Cursor cursorDraw;
     
    7070    private final Cursor cursorDrawing;
    7171    private boolean nearSomeNode;
    72     private LatLon highlighted;
    73     private int nearestIdx;
     72    private LatLon highlightedFragmentStart;
     73    private int nearestPointIndex;
    7474    private int dragNode=-1;
    7575    private SequenceCommand delCmd;
    7676    private List<Node> oldNodes;
    7777   
    78     private final TreeSet<Integer> set = new TreeSet<Integer>();
    79     private Timer timer;
    80  
    81     private KeyEvent releaseEvent;
    8278    private boolean lineWasSaved;
    8379    private boolean deltaChanged;
    84     /**
    85      * used for skipping keyboard AWTTevents while dialogs are active
    86      */
    87     private boolean listenKeys = false;
    8880   
    8981    FastDrawingMode(MapFrame mapFrame) {
     
    121113        Main.map.mapView.addMouseMotionListener(this);
    122114        Main.map.mapView.addTemporaryLayer(this);
    123 
    124         //tryToLoadWay();
    125        
    126         timer = new Timer(0, new ActionListener() {
    127             @Override
    128             public void actionPerformed(ActionEvent ae) {
    129                  timer.stop();
    130                  if (set.remove(releaseEvent.getKeyCode())) {
    131                   doKeyReleaseEvent(releaseEvent);
    132                  }
    133             }
    134         });
    135        
    136         listenKeys = true;
    137         try {
    138             Toolkit.getDefaultToolkit().addAWTEventListener(this,
    139                     AWTEvent.KEY_EVENT_MASK);
    140         } catch (SecurityException ex) {
    141         }
     115       
     116        Main.map.keyDetector.addKeyListener(this);
     117        Main.map.keyDetector.addModifierListener(this);
    142118    }
    143119
     
    151127
    152128        Main.map.mapView.removeTemporaryLayer(this);
    153 
    154         try {
    155             Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    156         } catch (SecurityException ex) {
    157         }
     129       
     130        Main.map.keyDetector.removeKeyListener(this);
     131        Main.map.keyDetector.removeModifierListener(this);
     132
    158133        settings.savePrefs();
    159134        Main.map.mapView.setCursor(cursorDraw);
     
    171146    }
    172147
     148    private final ArrayList<Point> fixedPoints =new ArrayList<>(3000); // tamporyrary storate for paint
     149   
    173150    //////////    Event listener methods
    174 
    175151    @Override
    176152    public void paint(Graphics2D g, MapView mv, Bounds bbox) {
     
    198174        dp=line.wasSimplified() ? settings.bigDotSize : settings.dotSize;  rp=dp/2;
    199175        if (pts.size() > 1) {
    200         Iterator<LatLon> it1,it2;
    201         it1=pts.listIterator(0);
    202         it2=pts.listIterator(1);
    203         for (int i = 0; i < pts.size() - 1; i++) {
     176            Iterator<LatLon> it1,it2;
     177            it1=pts.listIterator(0);
     178            it2=pts.listIterator(1);
     179            fixedPoints.clear();
     180            for (int i = 0; i < pts.size() - 1; i++) {
    204181                pp1 = it1.next();
    205182                p1 = line.getPoint(pp1);
    206183                pp2 = it2.next();
    207184                p2 = line.getPoint(pp2);
    208                 if (shift && highlighted==pp1 && nearestIdx<0) {lineColor=settings.COLOR_SELECTEDFRAGMENT;}
     185                if (shift && highlightedFragmentStart==pp1 && nearestPointIndex<0) {lineColor=settings.COLOR_SELECTEDFRAGMENT;}
    209186                if (!shift && line.isLastPoint(i)) { lineColor=settings.COLOR_EDITEDFRAGMENT; }
    210187                g.setColor(lineColor);
    211188                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    212                 if (line.isFixed(pp2)) {
     189                if (line.isFixed(pp2)) { 
    213190                    lineColor=initLineColor;
    214                     g.setColor(settings.COLOR_FIXED);
    215                     g.fillOval(p2.x - bigDotSize/2, p2.y - bigDotSize/2, bigDotSize, bigDotSize);
     191                    fixedPoints.add(p2);
    216192                } else {
    217193                    g.fillRect(p2.x - rp, p2.y - rp, dp, dp);
    218194                }
    219195                if (!drawing) {
    220                     if (!line.wasSimplified() && nearestIdx==i+1 ) {
     196                    if (!line.wasSimplified() && nearestPointIndex==i+1 ) {
    221197                    if (shift) {
    222198                        // highlight node to delete
     
    236212                }
    237213            }
     214            g.setColor(settings.COLOR_FIXED);
     215            for (Point p: fixedPoints) {
     216                g.fillOval(p.x - bigDotSize/2, p.y - bigDotSize/2, bigDotSize, bigDotSize);
     217            }
    238218        }
    239219        if (settings.drawLastSegment && !drawing && dragNode<0  && !shift &&
    240                 nearestIdx<=0 && !line.wasSimplified()) {
     220                nearestPointIndex<=0 && !line.wasSimplified()) {
    241221            // draw line to current point
    242222            g.setColor(lineColor);
     
    253233    }
    254234
    255     @Override
    256     public void eventDispatched(AWTEvent event) {
    257         if (!listenKeys || Main.map == null || Main.map.mapView == null
    258                 || !Main.map.mapView.isActiveLayerDrawable()) {
    259             return;
    260         }
    261         updateKeyModifiers((InputEvent) event);
    262         if (event instanceof KeyEvent) {
    263         KeyEvent e=(KeyEvent) event;
    264        
    265         if (event.getID() == KeyEvent.KEY_PRESSED) {
    266              if (timer.isRunning()) {
    267                   timer.stop();
    268                 } else {
    269                   set.add((e.getKeyCode()));
    270                 }
    271             // check if key press is done in main window, not in dialogs
    272             Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    273             if (SwingUtilities.getWindowAncestor(focused) instanceof JFrame) {
    274                 doKeyEvent((KeyEvent) event);
    275             }
    276         }
    277         if (event.getID() == KeyEvent.KEY_RELEASED) {
    278             if (timer.isRunning()) {
    279               timer.stop();
    280                if (set.remove(e.getKeyCode())) {
    281                   doKeyReleaseEvent(e);
    282                }
    283             } else {
    284               releaseEvent = e;
    285               timer.restart();
    286             }
    287         }
    288         }
    289     }
    290235
    291236    @Override
     
    293238        if (!isEnabled()) return;
    294239        if (e.getButton() != MouseEvent.BUTTON1) return;
     240        updateKeyModifiers(e);
    295241       
    296242        requestFocusInMapView();
     
    309255        if (ctrl && shift) {newDrawing();repaint();return;}
    310256        if (!ctrl && shift) {
    311             if (idx>=0) {line.deleteNode(idx); nearestIdx=-1;}
     257            if (idx>=0) {line.deleteNode(idx); nearestPointIndex=-1;}
    312258            else line.tryToDeleteSegment(e.getPoint());
    313259            return;
     
    364310        dragNode = -1;
    365311        drawing = false;
    366         highlighted=null;
     312        highlightedFragmentStart=null;
    367313        if (!line.isClosed()) setStatusLine(DRAWINGMODE_MESSAGE);
    368314        updateCursor();
     
    378324    public void mouseMoved(MouseEvent e) {
    379325        if (!isEnabled()) return;
     326        updateKeyModifiers(e);
    380327        deltaChanged=false;
    381328        Node nd1 = getNearestNode(e.getPoint(), settings.maxDist);
    382329        boolean nearSomeNode2=nd1!=null;
    383330        boolean needRepaint=false;
    384         if (nearSomeNode!=nearSomeNode2) {nearSomeNode=nearSomeNode2;updateCursor();needRepaint=true;}
     331        if (nearSomeNode!=nearSomeNode2) {
     332            nearSomeNode=nearSomeNode2;
     333            updateCursor();
     334            needRepaint=true;
     335        }
    385336
    386337        int nearestIdx2=line.findClosestPoint(e.getPoint(),settings.maxDist);
    387         if (nearestIdx != nearestIdx2) {nearestIdx=nearestIdx2; updateCursor();needRepaint=true;}
    388         if (settings.drawLastSegment) needRepaint=true;
     338        if (nearestPointIndex != nearestIdx2) {
     339            nearestPointIndex=nearestIdx2;
     340            updateCursor();
     341            needRepaint=true;
     342        }
     343        if (settings.drawLastSegment) {
     344            needRepaint=true;
     345        }
    389346       
    390347        if (!drawing) {
     
    395352            }
    396353
    397             if (shift) {
     354            if (shift && nearestPointIndex == -1) {
    398355                // find line fragment to highlight
    399356                LatLon h2=line.findBigSegment(e.getPoint());
    400                 if (highlighted!=h2) { highlighted=h2; repaint(); }
    401             } else if (needRepaint) {
     357                if (highlightedFragmentStart!=h2) {
     358                    highlightedFragmentStart=h2;
     359                    needRepaint=true;
     360                }
     361            }
     362           
     363            if (needRepaint) {
    402364                repaint();
    403365            }
     
    407369
    408370        // do not draw points close to existing points - we do not want self-intersections
    409         if (nearestIdx>=0) { return; }
     371        if (nearestPointIndex>=0) { return; }
    410372
    411373        Point lastP = line.getLastPoint(); // last point of line fragment being edited
     
    428390    }
    429391
    430     private void doKeyEvent(KeyEvent e) {
     392    @Override
     393    public void doKeyPressed(KeyEvent e) {
    431394        if (getShortcut().isEvent(e)) { // repeated press
    432395            tryToLoadWay();
     
    486449            if (lastPoint==null || lastPoint.equals(line.getLastPoint())) {
    487450                 if (line.getPoints().size()>5) {
    488                     // no key events while the dialog is active!
    489                     listenKeys = false;
    490451                    boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    491452                       "delete_drawn_line", Main.parent,
     
    493454                            line.getPoints().size()), tr("Delete confirmation"),
    494455                       JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_OPTION );
    495                     listenKeys = true;
    496456                    if(!answer) break;
    497457                }
     
    503463       
    504464        case KeyEvent.VK_I:
    505            listenKeys = false;
    506465           JOptionPane.showMessageDialog(Main.parent,
    507                         tr("{0} m - length of the line\n{1} nodes\n{2} points per km (maximum)\n{3} points per km (average)",
    508                         line.getLength(),line.getPoints().size(),line.getNodesPerKm(settings.pkmBlockSize),
    509                         line.getNodesPerKm(1000000)),
    510                         tr("Line information"),JOptionPane.INFORMATION_MESSAGE);
    511            listenKeys = true;
     466                tr("{0} m - length of the line\n{1} nodes\n{2} points per km (maximum)\n{3} points per km (average)",
     467                line.getLength(),line.getPoints().size(),line.getNodesPerKm(settings.pkmBlockSize),
     468                line.getNodesPerKm(1000000)),
     469                tr("Line information"),JOptionPane.INFORMATION_MESSAGE);
    512470        break;           
    513471        case KeyEvent.VK_Q:
    514472            // less details
    515473            e.consume();
    516             try {
    517                 listenKeys = false;
    518                 new FastDrawConfigDialog(settings);
    519                 if (line.wasSimplified()) {
     474            new FastDrawConfigDialog(settings).showDialog();
     475            if (line.wasSimplified()) {
    520476                eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, settings.pkmBlockSize,settings.maxPointsPerKm);
    521477                showSimplifyHint();
    522                 }
    523                 //System.out.println("final eps="+eps);
    524                 listenKeys = true;
    525             } catch (SecurityException ex) {  }
     478            }
    526479            repaint();
    527480        break;
     
    536489    }
    537490   
    538     private void doKeyReleaseEvent(KeyEvent keyEvent) {
    539             //System.out.println("released "+keyEvent);
    540             if (keyEvent.getKeyCode()==KeyEvent.VK_SPACE) stopDrawing();
    541             updateCursor();
    542     }
    543     /**
    544      * Updates shift and ctrl key states
    545      */
    546     protected void updateKeyModifiers(InputEvent e) {
    547         ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    548         shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     491    @Override
     492    public void doKeyReleased(KeyEvent keyEvent) {
     493        //System.out.println("released "+keyEvent);
     494        if (keyEvent.getKeyCode()==KeyEvent.VK_SPACE) stopDrawing();
    549495        updateCursor();
    550496    }
    551497
     498    @Override
     499    public void modifiersChanged(int modifiers) {
     500        updateKeyModifiers(modifiers);
     501        updateCursor();
     502    }
     503   
    552504    @Override
    553505    protected void updateStatusLine() {
     
    572524        if (line.isClosed() && n==3) pts.remove(2); // two-point way can not be closed
    573525
    574         Collection<Command> cmds = new LinkedList<Command>();
     526        Collection<Command> cmds = new LinkedList<>();
    575527        int i = 0;
    576528        Way w = new Way();
     
    579531
    580532        for (LatLon p : pts) {
    581             Node nd=null;
    582  
    583             nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isSelectablePredicate);
     533            Node nd = Main.map.mapView.getNearestNode(line.getPoint(p), OsmPrimitive.isSelectablePredicate);
    584534            // there may be a node with the same coords!
    585535           
    586536            if (nd!=null && p.greatCircleDistance(nd.getCoor())>0.01) nd=null;
    587537            if (nd==null) {
    588                 if (i>0 && p.equals(first)) nd=firstNode; else {
     538                if (i>0 && p.equals(first)) {
     539                    nd=firstNode;
     540                } else {
    589541                    nd = new Node(p);
    590542                    cmds.add(new AddCommand(nd));
     
    596548                return;
    597549            }
    598             if (i==0) firstNode=nd;
     550            if (i==0) {
     551                firstNode=nd;
     552            }
    599553            w.addNode(nd);
    600554            i++;
     
    602556        if (ctrl) {
    603557            // paste tags - from ctrl-shift-v
    604             Set <OsmPrimitive> ts = new HashSet<OsmPrimitive>();
     558            Set <OsmPrimitive> ts = new HashSet<>();
    605559            ts.add(w);
    606560            TagPaster tp = new TagPaster(Main.pasteBuffer.getDirectlyAdded(), ts);
     
    684638
    685639    private void loadFromWay(Way w) {
    686         Collection<Command> cmds = new LinkedList<Command>();
     640        Collection<Command> cmds = new LinkedList<>();
    687641       
    688642        Object[] nodes = w.getNodes().toArray();
     
    695649        if (w.isClosed()) line.closeLine();
    696650        oldNodes = w.getNodes();
    697         List <OsmPrimitive> wl = new ArrayList<OsmPrimitive>(); wl.add(w);
     651        List <OsmPrimitive> wl = new ArrayList<>(); wl.add(w);
    698652       
    699653        Command c = DeleteCommand.delete(getEditLayer(), wl, false);
     
    716670    private void updateCursor() {
    717671        if (shift) Main.map.mapView.setCursor(cursorShift); else
    718         if (line.isClosed() || (nearestIdx==0)) Main.map.mapView.setCursor(cursorReady); else
     672        if (line.isClosed() || (nearestPointIndex==0)) Main.map.mapView.setCursor(cursorReady); else
    719673        if (ctrl) Main.map.mapView.setCursor(cursorCtrl); else
    720674        if (nearSomeNode && settings.snapNodes) Main.map.mapView.setCursor(cursorCtrl); else
Note: See TracChangeset for help on using the changeset viewer.