Changeset 32410 in osm


Ignore:
Timestamp:
2016-06-26T17:19:30+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/utilsplugin2
Files:
2 added
54 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/.project

    r32286 r32410  
    1616                        </arguments>
    1717                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
    1823        </buildSpec>
    1924        <natures>
    2025                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2127        </natures>
    2228</projectDescription>
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java

    r32097 r32410  
    1 // License: GPL v2 or later. See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2;
    33
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AddIntersectionsAction.java

    r32333 r32410  
    2828
    2929public class AddIntersectionsAction extends JosmAction {
    30    
     30
    3131    /**
    3232     * Constructs a new {@code AddIntersectionsAction}.
     
    3434    public AddIntersectionsAction() {
    3535        super(tr("Add nodes at intersections"), "addintersect", tr("Add missing nodes at intersections of selected ways."),
    36                 Shortcut.registerShortcut("tools:addintersect", tr("Tool: {0}", tr("Add nodes at intersections")), KeyEvent.VK_I, Shortcut.SHIFT), true);
     36                Shortcut.registerShortcut("tools:addintersect", tr("Tool: {0}", tr("Add nodes at intersections")),
     37                        KeyEvent.VK_I, Shortcut.SHIFT),
     38                true);
    3739        putValue("help", ht("/Action/AddIntersections"));
    3840    }
     
    4547        if (ways.isEmpty()) {
    4648            new Notification(
    47                tr("Please select one or more ways with intersections of segments."))
    48                .setIcon(JOptionPane.INFORMATION_MESSAGE)
    49                .show();
     49                    tr("Please select one or more ways with intersections of segments."))
     50            .setIcon(JOptionPane.INFORMATION_MESSAGE)
     51            .show();
    5052            return;
    5153        }
     
    5456        Geometry.addIntersections(ways, false, cmds);
    5557        if (!cmds.isEmpty()) {
    56             Main.main.undoRedo.add(new SequenceCommand(tr("Add nodes at intersections"),cmds));
     58            Main.main.undoRedo.add(new SequenceCommand(tr("Add nodes at intersections"), cmds));
    5759            Set<Node> nodes = new HashSet<>(10);
    5860            // find and select newly added nodes
    59             for (Command cmd: cmds) if (cmd instanceof AddCommand){
     61            for (Command cmd: cmds) if (cmd instanceof AddCommand) {
    6062                Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives();
    61                 for ( OsmPrimitive p : pp) { // find all affected nodes
     63                for (OsmPrimitive p : pp) { // find all affected nodes
    6264                    if (p instanceof Node && p.isNew())
    63                         nodes.add((Node)p);
     65                        nodes.add((Node) p);
    6466                }
    6567                if (!nodes.isEmpty()) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AlignWayNodesAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    23
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.event.ActionEvent;
    37import java.awt.event.KeyEvent;
     8import java.util.ArrayList;
     9import java.util.Collection;
     10import java.util.HashSet;
     11import java.util.List;
     12import java.util.Set;
     13
     14import javax.swing.JOptionPane;
     15
     16import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.actions.JosmAction;
     18import org.openstreetmap.josm.command.Command;
     19import org.openstreetmap.josm.command.MoveCommand;
     20import org.openstreetmap.josm.command.SequenceCommand;
     21import org.openstreetmap.josm.data.osm.Node;
     22import org.openstreetmap.josm.data.osm.OsmPrimitive;
     23import org.openstreetmap.josm.data.osm.Way;
     24import org.openstreetmap.josm.gui.Notification;
    425import org.openstreetmap.josm.tools.Shortcut;
    5 import org.openstreetmap.josm.data.osm.*;
    6 import org.openstreetmap.josm.Main;
    7 import org.openstreetmap.josm.command.*;
    8 import java.util.*;
    9 import java.awt.event.ActionEvent;
    10 import javax.swing.JOptionPane;
    11 import org.openstreetmap.josm.actions.JosmAction;
    12 import org.openstreetmap.josm.gui.Notification;
    13 import static org.openstreetmap.josm.tools.I18n.tr;
    1426
    1527/**
     
    2739    public AlignWayNodesAction() {
    2840        super(TITLE, "dumbutils/alignwaynodes", tr("Align nodes in a way"),
    29                 Shortcut.registerShortcut("tools:alignwaynodes", tr("Tool: {0}", tr("Align Way Nodes")), KeyEvent.VK_L, Shortcut.SHIFT)
    30                 , true);
    31     }
    32 
    33     public void actionPerformed( ActionEvent e ) {
     41                Shortcut.registerShortcut("tools:alignwaynodes", tr("Tool: {0}", tr("Align Way Nodes")), KeyEvent.VK_L, Shortcut.SHIFT),
     42                true);
     43    }
     44
     45    @Override
     46    public void actionPerformed(ActionEvent e) {
    3447        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
    3548        Set<Node> selectedNodes = filterNodes(selection);
    3649        int selectedNodesCount = selectedNodes.size();
    3750        Set<Way> ways = findCommonWays(selectedNodes);
    38         if( ways == null || ways.size() != 1 || selectedNodesCount == 0 )
     51        if (ways == null || ways.size() != 1 || selectedNodesCount == 0)
    3952            return;
    4053        Way way = ways.iterator().next();
    41         if( way.getNodesCount() < (way.isClosed() ? 4 : 3) ) {
     54        if (way.getNodesCount() < (way.isClosed() ? 4 : 3)) {
    4255            new Notification(tr("The way with selected nodes can not be straightened."))
    43                     .setIcon(JOptionPane.ERROR_MESSAGE).show();
     56            .setIcon(JOptionPane.ERROR_MESSAGE).show();
    4457            return;
    4558        }
     
    5164        int i = firstNodePos;
    5265        boolean iterated = false;
    53         while( !iterated || i != lastNodePos ) {
     66        while (!iterated || i != lastNodePos) {
    5467            Node node = way.getNode(i);
    55             if( selectedNodes.contains(node) ) {
     68            if (selectedNodes.contains(node)) {
    5669                nodes.add(node);
    5770                selectedNodes.remove(node);
    58                 if( selectedNodesCount == 1 ) {
    59                     nodes.add(0, way.getNode( i > 0 ? i - 1 : way.isClosed() ? way.getNodesCount() - 2 : i + 2 ));
    60                     nodes.add(way.getNode( i + 1 < way.getNodesCount() ? i + 1 : way.isClosed() ? 1 : i - 2 ));
     71                if (selectedNodesCount == 1) {
     72                    nodes.add(0, way.getNode(i > 0 ? i - 1 : way.isClosed() ? way.getNodesCount() - 2 : i + 2));
     73                    nodes.add(way.getNode(i + 1 < way.getNodesCount() ? i + 1 : way.isClosed() ? 1 : i - 2));
    6174                }
    62                 if( selectedNodes.isEmpty() )
     75                if (selectedNodes.isEmpty())
    6376                    break;
    64             } else if( selectedNodesCount == 2 && selectedNodes.size() == 1 )
     77            } else if (selectedNodesCount == 2 && selectedNodes.size() == 1)
    6578                nodes.add(node);
    6679            i++;
    67             if( i >= way.getNodesCount() && way.isClosed() )
     80            if (i >= way.getNodesCount() && way.isClosed())
    6881                i = 0;
    6982            iterated = true;
    7083        }
    7184
    72         if( nodes.size() < 3 ) {
     85        if (nodes.size() < 3) {
    7386            new Notification(tr("Internal error: number of nodes is {0}.", nodes.size()))
    74                 .setIcon(JOptionPane.ERROR_MESSAGE).show();
     87            .setIcon(JOptionPane.ERROR_MESSAGE).show();
    7588            return;
    7689        }
     
    8396        double bx = nodes.get(nodes.size() - 1).getEastNorth().east();
    8497        double by = nodes.get(nodes.size() - 1).getEastNorth().north();
    85        
    86         for( i = 1; i + 1 < nodes.size(); i++ ) {
     98
     99        for (i = 1; i + 1 < nodes.size(); i++) {
    87100            Node n = nodes.get(i);
    88            
     101
    89102            // Algorithm is copied from org.openstreetmap.josm.actions.AlignInLineAction
    90103            double nx = n.getEastNorth().east();
    91104            double ny = n.getEastNorth().north();
    92105
    93             if( ax == bx ) {
     106            if (ax == bx) {
    94107                // Special case if AB is vertical...
    95108                nx = ax;
    96             } else if( ay == by ) {
     109            } else if (ay == by) {
    97110                // ...or horizontal
    98111                ny = ay;
     
    109122
    110123            // Add the command to move the node to its new position.
    111             if( Math.abs(nx - n.getEastNorth().east()) > MOVE_THRESHOLD && Math.abs(ny - n.getEastNorth().north()) > MOVE_THRESHOLD )
     124            if (Math.abs(nx - n.getEastNorth().east()) > MOVE_THRESHOLD && Math.abs(ny - n.getEastNorth().north()) > MOVE_THRESHOLD)
    112125                commands.add(new MoveCommand(n, nx - n.getEastNorth().east(), ny - n.getEastNorth().north()));
    113126        }
    114127
    115         if( !commands.isEmpty() )
     128        if (!commands.isEmpty())
    116129            Main.main.undoRedo.add(new SequenceCommand(TITLE, commands));
    117130    }
     
    123136
    124137    @Override
    125     protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
     138    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    126139        Set<Node> nodes = filterNodes(selection);
    127140        Set<Way> ways = findCommonWays(nodes);
     
    129142    }
    130143
    131     private Set<Way> findCommonWays( Set<Node> nodes ) {
     144    private Set<Way> findCommonWays(Set<Node> nodes) {
    132145        Set<Way> ways = null;
    133         for( Node n : nodes ) {
     146        for (Node n : nodes) {
    134147            List<Way> referrers = OsmPrimitive.getFilteredList(n.getReferrers(), Way.class);
    135             if( ways == null )
     148            if (ways == null)
    136149                ways = new HashSet<>(referrers);
    137150            else {
     
    142155    }
    143156
    144     private Set<Node> filterNodes( Collection<? extends OsmPrimitive> selection ) {
     157    private Set<Node> filterNodes(Collection<? extends OsmPrimitive> selection) {
    145158        Set<Node> result = new HashSet<>();
    146         if( selection != null ) {
    147             for( OsmPrimitive p : selection )
    148                 if( p instanceof Node )
    149                     result.add((Node)p);
     159        if (selection != null) {
     160            for (OsmPrimitive p : selection) {
     161                if (p instanceof Node)
     162                    result.add((Node) p);
     163            }
    150164        }
    151165        return result;
     
    157171     * TODO: not the maximum node count, but maximum distance!
    158172     */
    159     private int findFirstNode( Way way, Set<Node> nodes ) {
     173    private int findFirstNode(Way way, Set<Node> nodes) {
    160174        int pos = 0;
    161         while( pos < way.getNodesCount() && !nodes.contains(way.getNode(pos)) )
     175        while (pos < way.getNodesCount() && !nodes.contains(way.getNode(pos))) {
    162176            pos++;
    163         if( pos >= way.getNodesCount() )
     177        }
     178        if (pos >= way.getNodesCount())
    164179            return 0;
    165         if( !way.isClosed() || nodes.size() <= 1 )
     180        if (!way.isClosed() || nodes.size() <= 1)
    166181            return pos;
    167182
     
    170185        int maxLength = 0;
    171186        int lastPos = 0;
    172         while( !fullCircle ) {
     187        while (!fullCircle) {
    173188            int length = 0;
    174189            boolean skippedFirst = false;
    175             while( !(skippedFirst && nodes.contains(way.getNode(pos))) ) {
     190            while (!(skippedFirst && nodes.contains(way.getNode(pos)))) {
    176191                skippedFirst = true;
    177192                length++;
    178193                pos++;
    179                 if( pos >= way.getNodesCount() ) {
     194                if (pos >= way.getNodesCount()) {
    180195                    pos = 0;
    181196                    fullCircle = true;
    182197                }
    183198            }
    184             if( length > maxLength ) {
     199            if (length > maxLength) {
    185200                maxLength = length;
    186201                lastPos = pos;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/ExtractPointAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    33
    4 import java.awt.Point;
    54import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    65import static org.openstreetmap.josm.tools.I18n.tr;
    76
     7import java.awt.Point;
    88import java.awt.event.ActionEvent;
    99import java.awt.event.KeyEvent;
     
    1111import java.util.LinkedList;
    1212import java.util.List;
     13
    1314import javax.swing.JOptionPane;
     15
    1416import org.openstreetmap.josm.Main;
    1517import org.openstreetmap.josm.actions.JosmAction;
     
    1921import org.openstreetmap.josm.command.MoveCommand;
    2022import org.openstreetmap.josm.command.SequenceCommand;
    21 import org.openstreetmap.josm.data.osm.*;
     23import org.openstreetmap.josm.data.osm.Node;
     24import org.openstreetmap.josm.data.osm.OsmPrimitive;
     25import org.openstreetmap.josm.data.osm.Way;
    2226import org.openstreetmap.josm.gui.Notification;
    23 
    2427import org.openstreetmap.josm.tools.Shortcut;
    2528
     
    3538        super(tr("Extract node"), "extnode",
    3639                tr("Extracts node from a way"),
    37                 Shortcut.registerShortcut("tools:extnode", tr("Tool: {0}","Extract node"),
    38                 KeyEvent.VK_J, Shortcut.ALT_SHIFT), true);
     40                Shortcut.registerShortcut("tools:extnode", tr("Tool: {0}", "Extract node"),
     41                        KeyEvent.VK_J, Shortcut.ALT_SHIFT), true);
    3942        putValue("help", ht("/Action/ExtractNode"));
    4043    }
     
    4447        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
    4548        List<Node> selectedNodes = OsmPrimitive.getFilteredList(selection, Node.class);
    46         if (selectedNodes.size()!=1) {
     49        if (selectedNodes.size() != 1) {
    4750            new Notification(tr("This tool extracts node from its ways and requires single node to be selected."))
    48                 .setIcon(JOptionPane.WARNING_MESSAGE).show();
     51            .setIcon(JOptionPane.WARNING_MESSAGE).show();
    4952            return;
    5053        }
     
    5558        Point p = Main.map.mapView.getMousePosition();
    5659        if (p != null)
    57             cmds.add(new MoveCommand(nd,Main.map.mapView.getLatLon(p.x, p.y)));
     60            cmds.add(new MoveCommand(nd, Main.map.mapView.getLatLon(p.x, p.y)));
    5861        List<OsmPrimitive> refs = nd.getReferrers();
    5962        cmds.add(new AddCommand(ndCopy));
    60        
     63
    6164        for (OsmPrimitive pr: refs) {
    6265            if (pr instanceof Way) {
    63                 Way w=(Way)pr;
     66                Way w = (Way) pr;
    6467                List<Node> nodes = w.getNodes();
    65                 int idx=nodes.indexOf(nd);
     68                int idx = nodes.indexOf(nd);
    6669                nodes.set(idx, ndCopy); // replace node with its copy
    6770                cmds.add(new ChangeNodesCommand(w, nodes));
    6871            }
    6972        }
    70         if (cmds.size()>1) Main.main.undoRedo.add(new SequenceCommand(tr("Extract node from line"),cmds));
     73        if (cmds.size() > 1) Main.main.undoRedo.add(new SequenceCommand(tr("Extract node from line"), cmds));
    7174    }
    7275
     
    8285            return;
    8386        }
    84         setEnabled(selection.size()==1);
     87        setEnabled(selection.size() == 1);
    8588    }
    8689}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteRelationsAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    23
     
    3233    public PasteRelationsAction() {
    3334        super(TITLE, "dumbutils/pasterelations", tr("Paste relation membership from objects in the buffer onto selected object(s)"),
    34                 Shortcut.registerShortcut("tools:pasterelations", tr("Tool: {0}",  tr("Paste Relations")), KeyEvent.VK_V, Shortcut.ALT_CTRL), true);
     35                Shortcut.registerShortcut("tools:pasterelations", tr("Tool: {0}", tr("Paste Relations")), KeyEvent.VK_V, Shortcut.ALT_CTRL),
     36                true);
    3537    }
    3638
    3739    @Override
    38     public void actionPerformed( ActionEvent e ) {
     40    public void actionPerformed(ActionEvent e) {
    3941        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
    40         if( selection.isEmpty() )
     42        if (selection.isEmpty())
    4143            return;
    4244
    4345        Map<Relation, String> relations = new HashMap<>();
    44         for( PrimitiveData pdata : Main.pasteBuffer.getDirectlyAdded() ) {
     46        for (PrimitiveData pdata : Main.pasteBuffer.getDirectlyAdded()) {
    4547            OsmPrimitive p = getLayerManager().getEditDataSet().getPrimitiveById(pdata.getUniqueId(), pdata.getType());
    4648            if (p != null) {
    47                     for( Relation r : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) {
    48                         String role = relations.get(r);
    49                         for( RelationMember m : r.getMembers() ) {
    50                             if( m.getMember().equals(p) ) {
    51                                 String newRole = m.getRole();
    52                                 if( newRole != null && role == null )
    53                                     role = newRole;
    54                                 else if( newRole != null ? !newRole.equals(role) : role != null ) {
    55                                     role = "";
    56                                     break;
    57                                 }
    58                             }
    59                         }
    60                         relations.put(r, role);
    61                     }
     49                for (Relation r : OsmPrimitive.getFilteredList(p.getReferrers(), Relation.class)) {
     50                    String role = relations.get(r);
     51                    for (RelationMember m : r.getMembers()) {
     52                        if (m.getMember().equals(p)) {
     53                            String newRole = m.getRole();
     54                            if (newRole != null && role == null)
     55                                role = newRole;
     56                            else if (newRole != null ? !newRole.equals(role) : role != null) {
     57                                role = "";
     58                                break;
     59                            }
     60                        }
     61                    }
     62                    relations.put(r, role);
     63                }
    6264            }
    6365        }
    6466
    6567        List<Command> commands = new ArrayList<>();
    66         for( Relation rel : relations.keySet() ) {
     68        for (Relation rel : relations.keySet()) {
    6769            Relation r = new Relation(rel);
    6870            boolean changed = false;
    69             for( OsmPrimitive p : selection ) {
    70                 if( !r.getMemberPrimitives().contains(p) && !r.equals(p) ) {
     71            for (OsmPrimitive p : selection) {
     72                if (!r.getMemberPrimitives().contains(p) && !r.equals(p)) {
    7173                    String role = relations.get(rel);
    7274                    if ("associatedStreet".equals(r.get("type"))) {
    7375                        if (p.get("highway") != null) {
    74                             role="street";
     76                            role = "street";
    7577                        } else if (p.get("addr:housenumber") != null) {
    76                             role="house";
     78                            role = "house";
    7779                        }
    7880                    }
     
    8183                }
    8284            }
    83             if( changed )
     85            if (changed)
    8486                commands.add(new ChangeCommand(rel, r));
    8587        }
    8688
    87         if( !commands.isEmpty() )
     89        if (!commands.isEmpty())
    8890            Main.main.undoRedo.add(new SequenceCommand(TITLE, commands));
    8991    }
     
    9597
    9698    @Override
    97     protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
    98         setEnabled(selection != null && !selection.isEmpty() && !Main.pasteBuffer.isEmpty() );
     99    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
     100        setEnabled(selection != null && !selection.isEmpty() && !Main.pasteBuffer.isEmpty());
    99101    }
    100102}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    33
     
    2626import org.openstreetmap.josm.data.osm.Way;
    2727import org.openstreetmap.josm.gui.Notification;
    28 
    2928import org.openstreetmap.josm.tools.Shortcut;
    3029
     
    4443    public SplitObjectAction() {
    4544        super(tr("Split Object"), "splitobject", tr("Split an object at the selected nodes."),
    46                 Shortcut.registerShortcut("tools:splitobject", tr("Tool: {0}", tr("Split Object")),
    47                 KeyEvent.VK_X,  Shortcut.ALT)
    48                 , true);
     45                Shortcut.registerShortcut("tools:splitobject", tr("Tool: {0}", tr("Split Object")), KeyEvent.VK_X, Shortcut.ALT),
     46                true);
    4947        putValue("help", ht("/Action/SplitObject"));
    5048    }
     
    7573            for (Way selWay : selectedWays) {       // we assume not more 2 ways in the list
    7674                if (selWay != null &&               // If one of selected ways is not closed we have it to get split points
    77                     selWay.isUsable() &&
    78                     !selWay.isClosed() &&
    79                     selWay.getKeys().isEmpty()) {
    80                         selectedNodes.add(selWay.firstNode());
    81                         selectedNodes.add(selWay.lastNode());
    82                         splitWay = selWay;
     75                        selWay.isUsable() &&
     76                        !selWay.isClosed() &&
     77                        selWay.getKeys().isEmpty()) {
     78                    selectedNodes.add(selWay.firstNode());
     79                    selectedNodes.add(selWay.lastNode());
     80                    splitWay = selWay;
    8381                } else {
    8482                    selectedWay = selWay;           // use another way as selected way
     
    114112            if (wayOccurenceCounter.isEmpty()) {
    115113                showWarningNotification(
    116                    trn("The selected node is not in the middle of any way.",
    117                        "The selected nodes are not in the middle of any way.",
    118                         selectedNodes.size()));
     114                        trn("The selected node is not in the middle of any way.",
     115                                "The selected nodes are not in the middle of any way.",
     116                                selectedNodes.size()));
    119117                return;
    120118            }
     
    124122                    if (selectedWay != null) {
    125123                        showWarningNotification(
    126                             trn("There is more than one way using the node you selected. Please select the way also.",
    127                                     "There is more than one way using the nodes you selected. Please select the way also.",
    128                                     selectedNodes.size())
    129                             );
     124                                trn("There is more than one way using the node you selected. Please select the way also.",
     125                                        "There is more than one way using the nodes you selected. Please select the way also.",
     126                                        selectedNodes.size())
     127                                );
    130128                        return;
    131129                    }
     
    150148            if (!nds.isEmpty()) {
    151149                showWarningNotification(
    152                     trn("The selected way does not contain the selected node.",
    153                             "The selected way does not contain all the selected nodes.",
    154                             selectedNodes.size()));
     150                        trn("The selected way does not contain the selected node.",
     151                                "The selected way does not contain all the selected nodes.",
     152                                selectedNodes.size()));
    155153                return;
    156154            }
    157155        } else if (selectedWay != null && selectedNodes.isEmpty()) {
    158156            showWarningNotification(
    159                 tr("The selected way is not a split way, please select split points or split way too."));
     157                    tr("The selected way is not a split way, please select split points or split way too."));
    160158            return;
    161159        }
     
    183181                (nodeIndex2 == 0 && nodeIndex1 == selectedWay.getNodesCount() - 2)) {
    184182            showWarningNotification(
    185                 tr("The selected nodes can not be consecutive nodes in the object."));
     183                    tr("The selected nodes can not be consecutive nodes in the object."));
    186184            return;
    187185        }
     
    253251        setEnabled(checkSelection(selection));
    254252    }
    255    
     253
    256254    void showWarningNotification(String msg) {
    257255        new Notification(msg)
    258             .setIcon(JOptionPane.WARNING_MESSAGE).show();
     256        .setIcon(JOptionPane.WARNING_MESSAGE).show();
    259257    }
    260258}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitOnIntersectionsAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    23
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.event.ActionEvent;
     7import java.awt.event.KeyEvent;
     8import java.util.ArrayList;
     9import java.util.Collection;
     10import java.util.HashMap;
     11import java.util.Iterator;
     12import java.util.List;
     13import java.util.Map;
     14
    315import javax.swing.JOptionPane;
     16
     17import org.openstreetmap.josm.Main;
     18import org.openstreetmap.josm.actions.JosmAction;
    419import org.openstreetmap.josm.actions.SplitWayAction;
     20import org.openstreetmap.josm.command.Command;
     21import org.openstreetmap.josm.command.SequenceCommand;
    522import org.openstreetmap.josm.data.osm.Node;
     23import org.openstreetmap.josm.data.osm.OsmPrimitive;
    624import org.openstreetmap.josm.data.osm.Way;
    7 import org.openstreetmap.josm.Main;
    8 import org.openstreetmap.josm.command.*;
    9 import java.util.*;
    10 import java.awt.event.KeyEvent;
     25import org.openstreetmap.josm.gui.Notification;
    1126import org.openstreetmap.josm.tools.Shortcut;
    12 import java.awt.event.ActionEvent;
    13 import org.openstreetmap.josm.actions.JosmAction;
    14 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    15 import org.openstreetmap.josm.gui.Notification;
    16 import static org.openstreetmap.josm.tools.I18n.tr;
    1727
    1828/**
     
    2838        super(TITLE, "dumbutils/splitonintersections", tr("Split adjacent ways on T-intersections"),
    2939                Shortcut.registerShortcut("tools:splitonintersections", tr("Tool: {0}", tr("Split adjacent ways")),
    30                 KeyEvent.VK_P, Shortcut.ALT_CTRL_SHIFT), true);
     40                        KeyEvent.VK_P, Shortcut.ALT_CTRL_SHIFT), true);
    3141    }
    3242
    3343    @Override
    34     public void actionPerformed( ActionEvent e ) {
     44    public void actionPerformed(ActionEvent e) {
    3545        List<Command> list = new ArrayList<>();
    3646        List<Way> selectedWays = OsmPrimitive.getFilteredList(getLayerManager().getEditDataSet().getSelected(), Way.class);
    3747        Map<Way, List<Node>> splitWays = new HashMap<>();
    3848
    39         for( Way way : selectedWays ) {
    40             if( way.getNodesCount() > 1 && !way.hasIncompleteNodes() && !way.isClosed() )
    41             for( Node node : new Node[] {way.getNode(0), way.getNode(way.getNodesCount() - 1)} ) {
    42                 List<Way> refs = OsmPrimitive.getFilteredList(node.getReferrers(), Way.class);
    43                 refs.remove(way);
    44                 if( selectedWays.size() > 1 ) {
    45                     // When several ways are selected, split only those among selected
     49        for (Way way : selectedWays) {
     50            if (way.getNodesCount() > 1 && !way.hasIncompleteNodes() && !way.isClosed())
     51                for (Node node : new Node[] {way.getNode(0), way.getNode(way.getNodesCount() - 1)}) {
     52                    List<Way> refs = OsmPrimitive.getFilteredList(node.getReferrers(), Way.class);
     53                    refs.remove(way);
     54                    if (selectedWays.size() > 1) {
     55                        // When several ways are selected, split only those among selected
     56                        Iterator<Way> it = refs.iterator();
     57                        while (it.hasNext()) {
     58                            if (!selectedWays.contains(it.next()))
     59                                it.remove();
     60                        }
     61                    }
     62
    4663                    Iterator<Way> it = refs.iterator();
    4764                    while (it.hasNext()) {
    48                         if(!selectedWays.contains(it.next()))
     65                        Way w = it.next();
     66                        if (w.isDeleted() || w.isIncomplete() || !w.isInnerNode(node))
    4967                            it.remove();
    5068                    }
     69                    if (refs.size() == 1) {
     70                        if (splitWays.containsKey(refs.get(0)))
     71                            splitWays.get(refs.get(0)).add(node);
     72                        else {
     73                            List<Node> nodes = new ArrayList<>(1);
     74                            nodes.add(node);
     75                            splitWays.put(refs.get(0), nodes);
     76                        }
     77                    } else if (refs.size() > 1) {
     78                        new Notification(
     79                                tr("There are several ways containing one of the splitting nodes. Select ways participating in this operation.")
     80                                ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     81                        return;
     82                    }
    5183                }
    52 
    53                 Iterator<Way> it = refs.iterator();
    54                 while (it.hasNext()) {
    55                     Way w = it.next();
    56                     if( w.isDeleted() || w.isIncomplete() || !w.isInnerNode(node) )
    57                         it.remove();
    58                 }
    59                 if( refs.size() == 1 ) {
    60                     if( splitWays.containsKey(refs.get(0)) )
    61                         splitWays.get(refs.get(0)).add(node);
    62                     else {
    63                         List<Node> nodes = new ArrayList<>(1);
    64                         nodes.add(node);
    65                         splitWays.put(refs.get(0), nodes);
    66                     }
    67                 } else if( refs.size() > 1 ) {
    68                     new Notification(
    69                         tr("There are several ways containing one of the splitting nodes. Select ways participating in this operation.")
    70                         ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 
    71                     return;
    72                 }
    73             }
    7484        }
    7585
    76         for( Way splitWay : splitWays.keySet() ) {
     86        for (Way splitWay : splitWays.keySet()) {
    7787            List<List<Node>> wayChunks = SplitWayAction.buildSplitChunks(splitWay, splitWays.get(splitWay));
    78             if( wayChunks != null ) {
     88            if (wayChunks != null) {
    7989                List<OsmPrimitive> sel = new ArrayList<>(selectedWays.size());
    8090                sel.addAll(selectedWays);
     
    8494        }
    8595
    86         if( !list.isEmpty() ) {
     96        if (!list.isEmpty()) {
    8797            Main.main.undoRedo.add(list.size() == 1 ? list.get(0) : new SequenceCommand(TITLE, list));
    8898            getLayerManager().getEditDataSet().clearSelection();
     
    96106
    97107    @Override
    98     protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
     108    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    99109        boolean ok = false;
    100         if( selection != null )
    101         for( OsmPrimitive p : selection ) {
    102             if( p instanceof Way )
    103                 ok = true;
    104             else {
    105                 ok = false;
    106                 break;
     110        if (selection != null)
     111            for (OsmPrimitive p : selection) {
     112                if (p instanceof Way)
     113                    ok = true;
     114                else {
     115                    ok = false;
     116                    break;
     117                }
    107118            }
    108         }
    109119        setEnabled(ok);
    110120    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SymmetryAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    66
    77import java.awt.event.ActionEvent;
     
    2323import org.openstreetmap.josm.data.osm.Way;
    2424import org.openstreetmap.josm.gui.Notification;
    25 
    2625import org.openstreetmap.josm.tools.Shortcut;
    2726
     
    3231 *
    3332 * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :)
    34  */ 
     33 */
    3534public final class SymmetryAction extends JosmAction {
    3635
     
    4948        Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected();
    5049        HashSet<Node> nodes = new HashSet<>();
    51         EastNorth p1=null,p2=null;
    52        
     50        EastNorth p1 = null, p2 = null;
     51
    5352        for (OsmPrimitive osm : sel) {
    5453            if (osm instanceof Node) {
    55                 if (p1==null) p1=((Node)osm).getEastNorth(); else
    56                 if (p2==null) p2=((Node)osm).getEastNorth(); else
    57                 nodes.add((Node)osm);
     54                if (p1 == null) p1 = ((Node) osm).getEastNorth(); else
     55                    if (p2 == null) p2 = ((Node) osm).getEastNorth(); else
     56                        nodes.add((Node) osm);
    5857            }
    5958        }
    6059        for (OsmPrimitive osm : sel) {
    6160            if (osm instanceof Way) {
    62                 nodes.addAll(((Way)osm).getNodes());
     61                nodes.addAll(((Way) osm).getNodes());
    6362            }
    6463        }
    65        
    66         if (p1==null || p2==null || nodes.size() < 1) {
     64
     65        if (p1 == null || p2 == null || nodes.size() < 1) {
    6766            new Notification(
    6867                    tr("Please select at least two nodes for symmetry axis and something else to mirror.")
    69                 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 
     68                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    7069            return;
    7170        }
    7271
    73         double ne,nn,l,e0,n0;
    74         e0=p1.east();        n0=p1.north();
    75         ne =  -(p2.north()-p1.north());      nn =  (p2.east()-p1.east());
    76         l = Math.hypot(ne,nn);
     72        double ne, nn, l, e0, n0;
     73        e0 = p1.east();
     74        n0 = p1.north();
     75        ne = -(p2.north() - p1.north());
     76        nn = (p2.east() - p1.east());
     77        l = Math.hypot(ne, nn);
    7778        ne /= l; nn /= l; // normal unit vector
    78        
     79
    7980        Collection<Command> cmds = new LinkedList<>();
    8081
     
    8384            double pr = (c.east()-e0)*ne + (c.north()-n0)*nn;
    8485            //pr=10;
    85             cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr ));
     86            cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr));
    8687        }
    8788
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    23
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.event.ActionEvent;
     7import java.awt.event.KeyEvent;
     8import java.util.ArrayList;
     9import java.util.Collection;
     10import java.util.HashMap;
     11import java.util.HashSet;
     12import java.util.List;
     13import java.util.Map;
     14import java.util.Set;
     15
    316import org.openstreetmap.josm.Main;
    4 import org.openstreetmap.josm.command.*;
    5 import java.util.*;
    6 import java.awt.event.KeyEvent;
     17import org.openstreetmap.josm.actions.JosmAction;
     18import org.openstreetmap.josm.command.ChangePropertyCommand;
     19import org.openstreetmap.josm.command.Command;
     20import org.openstreetmap.josm.command.SequenceCommand;
     21import org.openstreetmap.josm.data.osm.OsmPrimitive;
    722import org.openstreetmap.josm.tools.Predicate;
    823import org.openstreetmap.josm.tools.Shortcut;
    9 import java.awt.event.ActionEvent;
    10 import org.openstreetmap.josm.actions.JosmAction;
    11 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1224import org.openstreetmap.josm.tools.Utils;
    13 import static org.openstreetmap.josm.tools.I18n.tr;
    1425
    1526/**
     
    3546    public TagBufferAction() {
    3647        super(TITLE, "dumbutils/tagbuffer", tr("Pastes tags of previously selected object(s)"),
    37                 Shortcut.registerShortcut("tools:tagbuffer", tr("Tool: {0}", tr("Copy tags from previous selection")), KeyEvent.VK_R, Shortcut.SHIFT)
    38         , true, false);
     48                Shortcut.registerShortcut("tools:tagbuffer", tr("Tool: {0}", tr("Copy tags from previous selection")),
     49                        KeyEvent.VK_R, Shortcut.SHIFT),
     50                true, false);
    3951        // The fields are not initialized while the super constructor is running, so we have to call this afterwards:
    4052        installAdapters();
     
    4254
    4355    @Override
    44     public void actionPerformed( ActionEvent e ) {
     56    public void actionPerformed(ActionEvent e) {
    4557        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
    46         if( selection.isEmpty() )
     58        if (selection.isEmpty())
    4759            return;
    4860
    4961        List<Command> commands = new ArrayList<>();
    50         for( String key : tags.keySet() ) {
     62        for (String key : tags.keySet()) {
    5163            String value = tags.get(key);
    5264            boolean foundNew = false;
    53             for( OsmPrimitive p : selection ) {
    54                 if( !p.hasKey(key) || !p.get(key).equals(value) ) {
     65            for (OsmPrimitive p : selection) {
     66                if (!p.hasKey(key) || !p.get(key).equals(value)) {
    5567                    foundNew = true;
    5668                    break;
    5769                }
    5870            }
    59             if( foundNew )
     71            if (foundNew)
    6072                commands.add(new ChangePropertyCommand(selection, key, value));
    6173        }
    62        
    63         if( !commands.isEmpty() )
     74
     75        if (!commands.isEmpty())
    6476            Main.main.undoRedo.add(new SequenceCommand(TITLE, commands));
    6577    }
     
    6779    @Override
    6880    protected void updateEnabledState() {
    69         if( getLayerManager().getEditDataSet() == null ) {
     81        if (getLayerManager().getEditDataSet() == null) {
    7082            setEnabled(false);
    71             if( selectionBuf != null )
     83            if (selectionBuf != null)
    7284                selectionBuf.clear();
    73         }  else
     85        } else
    7486            updateEnabledState(getLayerManager().getEditDataSet().getSelected());
    7587    }
    7688
    7789    @Override
    78     protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
     90    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    7991        // selection changed => check if selection is completely different from before
    8092        boolean foundOld = false;
    81         if( selection != null ) {
    82             for( OsmPrimitive p : selectionBuf ) {
    83                 if( selection.contains(p) ) {
     93        if (selection != null) {
     94            for (OsmPrimitive p : selectionBuf) {
     95                if (selection.contains(p)) {
    8496                    foundOld = true;
    8597                    break;
     
    92104            selectionBuf.clear();
    93105        }
    94         if( !foundOld ) {
     106        if (!foundOld) {
    95107            // selection has completely changed, remember tags
    96108            tags.clear();
    97109            tags.putAll(currentTags);
    98110        }
    99         if( getLayerManager().getEditDataSet() != null)
     111        if (getLayerManager().getEditDataSet() != null)
    100112            rememberSelectionTags();
    101113
     
    105117    private void rememberSelectionTags() {
    106118        // Fix #8350 - only care about tagged objects
    107         final Collection<OsmPrimitive> selectedTaggedObjects = Utils.filter(getLayerManager().getEditDataSet().getSelected(), IS_TAGGED_PREDICATE);
    108         if( !selectedTaggedObjects.isEmpty() ) {
     119        final Collection<OsmPrimitive> selectedTaggedObjects = Utils.filter(
     120                getLayerManager().getEditDataSet().getSelected(), IS_TAGGED_PREDICATE);
     121        if (!selectedTaggedObjects.isEmpty()) {
    109122            currentTags.clear();
    110123            Set<String> bad = new HashSet<>();
    111             for( OsmPrimitive p : selectedTaggedObjects ) {
    112                 if( currentTags.isEmpty() ) {
    113                     for( String key : p.keySet() )
     124            for (OsmPrimitive p : selectedTaggedObjects) {
     125                if (currentTags.isEmpty()) {
     126                    for (String key : p.keySet()) {
    114127                        currentTags.put(key, p.get(key));
     128                    }
    115129                } else {
    116                     for( String key : p.keySet() )
    117                         if( !currentTags.containsKey(key) || !currentTags.get(key).equals(p.get(key)) )
     130                    for (String key : p.keySet()) {
     131                        if (!currentTags.containsKey(key) || !currentTags.get(key).equals(p.get(key)))
    118132                            bad.add(key);
    119                     for( String key : currentTags.keySet() )
    120                         if( !p.hasKey(key) )
     133                    }
     134                    for (String key : currentTags.keySet()) {
     135                        if (!p.hasKey(key))
    121136                            bad.add(key);
     137                    }
    122138                }
    123139            }
    124             for( String key : bad )
     140            for (String key : bad) {
    125141                currentTags.remove(key);
     142            }
    126143        }
    127144    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagSourceAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    23
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.event.ActionEvent;
     7import java.awt.event.KeyEvent;
     8import java.util.Collection;
     9import java.util.HashSet;
     10import java.util.Set;
     11
    312import org.openstreetmap.josm.Main;
    4 import org.openstreetmap.josm.command.*;
    5 import java.util.*;
    6 import java.awt.event.KeyEvent;
     13import org.openstreetmap.josm.actions.JosmAction;
     14import org.openstreetmap.josm.command.ChangePropertyCommand;
     15import org.openstreetmap.josm.data.osm.OsmPrimitive;
    716import org.openstreetmap.josm.tools.Shortcut;
    8 import java.awt.event.ActionEvent;
    9 import org.openstreetmap.josm.actions.JosmAction;
    10 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    11 import static org.openstreetmap.josm.tools.I18n.tr;
    1217
    1318/**
     
    2429    public TagSourceAction() {
    2530        super(TITLE, "dumbutils/sourcetag", tr("Add remembered source tag"),
    26                 Shortcut.registerShortcut("tools:sourcetag", tr("Tool: {0}", tr("Add Source Tag")), KeyEvent.VK_S, Shortcut.ALT_CTRL)
    27                 , true, false);
     31                Shortcut.registerShortcut("tools:sourcetag", tr("Tool: {0}", tr("Add Source Tag")), KeyEvent.VK_S, Shortcut.ALT_CTRL),
     32                true, false);
    2833        source = Main.pref.get("sourcetag.value");
    2934        // The fields are not initialized while the super constructor is running, so we have to call this afterwards:
     
    3237
    3338    @Override
    34     public void actionPerformed( ActionEvent e ) {
     39    public void actionPerformed(ActionEvent e) {
    3540        Collection<OsmPrimitive> selection = getLayerManager().getEditDataSet().getSelected();
    36         if( selection.isEmpty() || source == null || source.length() == 0 )
     41        if (selection.isEmpty() || source == null || source.length() == 0)
    3742            return;
    3843
     
    4247    @Override
    4348    protected void updateEnabledState() {
    44         if( getLayerManager().getEditDataSet() == null ) {
     49        if (getLayerManager().getEditDataSet() == null) {
    4550            setEnabled(false);
    46             if( selectionBuf != null )
     51            if (selectionBuf != null)
    4752                selectionBuf.clear();
    48         }  else
     53        } else
    4954            updateEnabledState(getLayerManager().getEditDataSet().getSelected());
    5055    }
    5156
    5257    @Override
    53     protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
    54         if( selection == null || selection.isEmpty() ) {
     58    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
     59        if (selection == null || selection.isEmpty()) {
    5560            selectionBuf.clear();
    5661            clickedTwice = false;
     
    5964        }
    6065
    61         if( selectionBuf.size() == selection.size() && selectionBuf.containsAll(selection) ) {
    62             if( !clickedTwice )
     66        if (selectionBuf.size() == selection.size() && selectionBuf.containsAll(selection)) {
     67            if (!clickedTwice)
    6368                clickedTwice = true;
    6469            else {
    6570                // tags may have been changed, get the source
    6671                String newSource = null;
    67                 for( OsmPrimitive p : selection ) {
     72                for (OsmPrimitive p : selection) {
    6873                    String value = p.get("source");
    69                     if( value != null && newSource == null )
     74                    if (value != null && newSource == null)
    7075                        newSource = value;
    71                     else if( value != null ? !value.equals(newSource) : newSource != null ) {
     76                    else if (value != null ? !value.equals(newSource) : newSource != null) {
    7277                        newSource = "";
    7378                        break;
    7479                    }
    7580                }
    76                 if( newSource != null && newSource.length() > 0 && !newSource.equals(source) ) {
     81                if (newSource != null && newSource.length() > 0 && !newSource.equals(source)) {
    7782                    source = newSource;
    7883                    Main.pref.put("sourcetag.value", source);
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java

    r32333 r32410  
    1 // License: GPL v2 or later. Copyright 2010 by Kalle Lampila and others
    2 // See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    32package org.openstreetmap.josm.plugins.utilsplugin2.actions;
    43
     
    3938    public UnGlueRelationAction() {
    4039        super(tr("UnGlue Relation"), "ungluerelations", tr("Duplicate nodes, ways and relations that are used by multiple relations."),
    41               Shortcut.registerShortcut("tools:ungluerelation", tr("Tool: {0}", tr("UnGlue Relations")), KeyEvent.VK_G, Shortcut.ALT_SHIFT ), true);
     40                Shortcut.registerShortcut("tools:ungluerelation", tr("Tool: {0}", tr("UnGlue Relations")), KeyEvent.VK_G, Shortcut.ALT_SHIFT),
     41                true);
    4242        putValue("help", ht("/Action/UnGlueRelation"));
    4343    }
     
    6262                    OsmPrimitive newp;
    6363                    switch(p.getType()) {
    64                     case NODE: newp = new Node((Node)p, true); break;
    65                     case WAY: newp = new Way((Way)p, true); break;
    66                     case RELATION: newp = new Relation((Relation)p, true); break;
     64                    case NODE: newp = new Node((Node) p, true); break;
     65                    case WAY: newp = new Way((Way) p, true); break;
     66                    case RELATION: newp = new Relation((Relation) p, true); break;
    6767                    default: throw new AssertionError();
    68                     }                   
     68                    }
    6969                    newPrimitives.add(newp);
    7070                    cmds.add(new AddCommand(newp));
     
    7676        }
    7777
    78         if (newPrimitives.isEmpty() ) {
     78        if (newPrimitives.isEmpty()) {
    7979            // error message nothing to do
    80         }
    81         else {
     80        } else {
    8281            Main.main.undoRedo.add(new SequenceCommand(tr("Unglued Relations"), cmds));
    8382            //Set selection all primiteves (new and old)
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/command/ChangeRelationMemberCommand.java

    r30737 r32410  
    1 // License: GPL v2 or later. See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.command;
    33
     
    4444        relation.setMembers(newrms);
    4545    }
    46    
     46
    4747    @Override
    4848    public boolean executeCommand() {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CircleArcMaker.java

    r30737 r32410  
    1 // License: GPL. Copyright 2011 by Ole Jørgen Brønner
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.curves;
    33
     
    2121import org.openstreetmap.josm.data.osm.Way;
    2222
    23 public class CircleArcMaker {
     23public final class CircleArcMaker {
     24
     25    private CircleArcMaker() {
     26        // Hide default constructor for utilities classes
     27    }
     28
    2429    public static Collection<Command> doCircleArc(List<Node> selectedNodes, List<Way> selectedWays, int angleSeparation) {
    2530        Collection<Command> cmds = new LinkedList<>();
     
    95100            }
    96101            // Fix #7341. Find the first way having all nodes in common to sort them in its nodes order
    97             List<Node> consideredNodes = Arrays.asList(new Node[]{n1,n2,n3});
     102            List<Node> consideredNodes = Arrays.asList(new Node[]{n1, n2, n3});
    98103            for (Way w : selectedWays) {
    99104                final List<Node> nodes = w.getNodes();
     
    111116                }
    112117            }
    113            
     118
    114119            for (Node n : consideredNodes) {
    115120                targetWays.addAll(OsmPrimitive.getFilteredList(n.getReferrers(), Way.class));
     
    133138        List<Node> arcNodes = new ArrayList<>(points.size());
    134139        arcNodes.add(n1);
    135         {
    136             int i = 1;
    137             for (EastNorth p : slice(points, 1, -2)) {
    138                 //            if (p == p2) {
    139                 if (i == p2Index.value) {
    140                     Node n2new = new Node(n2);
    141                     n2new.setEastNorth(p);
    142                     arcNodes.add(n2); // add the original n2, or else we can't find it in the target ways
    143                     cmds.add(new ChangeCommand(n2, n2new));
    144                 } else {
    145                     Node n = new Node(p);
    146                     arcNodes.add(n);
    147                     cmds.add(new AddCommand(n));
    148                 }
    149                 i++;
    150             }
     140        int i = 1;
     141        for (EastNorth p : slice(points, 1, -2)) {
     142            if (i == p2Index.value) {
     143                Node n2new = new Node(n2);
     144                n2new.setEastNorth(p);
     145                arcNodes.add(n2); // add the original n2, or else we can't find it in the target ways
     146                cmds.add(new ChangeCommand(n2, n2new));
     147            } else {
     148                Node n = new Node(p);
     149                arcNodes.add(n);
     150                cmds.add(new AddCommand(n));
     151            }
     152            i++;
    151153        }
    152154        arcNodes.add(n3);
    153155
    154         Node[] anchorNodes = { n1, n2, n3 };
     156        Node[] anchorNodes = {n1, n2, n3};
    155157        //// "Fuse" the arc with all target ways
    156158        fuseArc(anchorNodes, arcNodes, targetWays, cmds);
     
    359361        return a;
    360362    }
     363
    361364    public static class ReturnValue<T> {
    362365        public T value;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CurveAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Ole Jørgen Brønner
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.curves;
    33
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/ChooseURLAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.customurl;
    23
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    36import java.awt.GridBagLayout;
     7import java.awt.event.ActionEvent;
    48import java.util.List;
    5 import javax.swing.JPanel;
    6 import javax.swing.event.ListSelectionEvent;
    7 import org.openstreetmap.josm.gui.ExtendedDialog;
    8 import org.openstreetmap.josm.tools.GBC;
    9 import org.openstreetmap.josm.Main;
    10 import java.awt.event.ActionEvent;
     9
    1110import javax.swing.JCheckBox;
    1211import javax.swing.JLabel;
    1312import javax.swing.JList;
     13import javax.swing.JPanel;
    1414import javax.swing.JTextField;
    1515import javax.swing.ListSelectionModel;
     16import javax.swing.event.ListSelectionEvent;
    1617import javax.swing.event.ListSelectionListener;
     18
     19import org.openstreetmap.josm.Main;
    1720import org.openstreetmap.josm.actions.JosmAction;
    18 import static org.openstreetmap.josm.tools.I18n.tr;
     21import org.openstreetmap.josm.gui.ExtendedDialog;
     22import org.openstreetmap.josm.tools.GBC;
    1923
    2024public class ChooseURLAction extends JosmAction {
    2125
    2226    public ChooseURLAction() {
    23         super(tr("Select custom URL"), "selecturl", tr("Select custom URL"),null,true,true);
     27        super(tr("Select custom URL"), "selecturl", tr("Select custom URL"), null, true, true);
    2428    }
    2529
     
    3337        setEnabled(getLayerManager().getEditDataSet() != null);
    3438    }
    35        
     39
    3640    public static void showConfigDialog(final boolean fast) {
    3741        JPanel all = new JPanel(new GridBagLayout());
    38        
     42
    3943        List<String> items = URLList.getURLList();
    4044        String addr = URLList.getSelectedURL();
    41         int n=items.size()/2 , idxToSelect=-1;
    42         final String names[] =new String[n];
    43         final String vals[] =new String[n];
    44         for (int i=0;i<n;i++) {
    45             names[i]=items.get(i*2);
    46             vals[i]=items.get(i*2+1);
    47             if (vals[i].equals(addr)) idxToSelect=i;
     45        int n = items.size()/2, idxToSelect = -1;
     46        final String[] names = new String[n];
     47        final String[] vals = new String[n];
     48        for (int i = 0; i < n; i++) {
     49            names[i] = items.get(i*2);
     50            vals[i] = items.get(i*2+1);
     51            if (vals[i].equals(addr)) idxToSelect = i;
    4852        }
    49         final JLabel label1=new JLabel(tr("Please select one of custom URLs (configured in Preferences)"));
    50         final JList<String> list1=new JList<>(names);
    51         final JTextField editField=new JTextField();
    52         final JCheckBox check1=new JCheckBox(tr("Ask every time"));
    53        
     53        final JLabel label1 = new JLabel(tr("Please select one of custom URLs (configured in Preferences)"));
     54        final JList<String> list1 = new JList<>(names);
     55        final JTextField editField = new JTextField();
     56        final JCheckBox check1 = new JCheckBox(tr("Ask every time"));
     57
    5458        final ExtendedDialog dialog = new ExtendedDialog(Main.parent,
    5559                tr("Configure custom URL"),
    56                 new String[] {tr("OK"),tr("Cancel"),}
    57         );
     60                new String[] {tr("OK"), tr("Cancel")}
     61                );
    5862        list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    5963        list1.addListSelectionListener(new ListSelectionListener() {
    6064            @Override
    6165            public void valueChanged(ListSelectionEvent e) {
    62                 int idx=list1.getSelectedIndex();
    63                 if (idx>=0) editField.setText(vals[idx]);
     66                int idx = list1.getSelectedIndex();
     67                if (idx >= 0) editField.setText(vals[idx]);
    6468            }
    6569        });
    6670        list1.setSelectedIndex(idxToSelect);
    67         check1.setSelected(Main.pref.getBoolean("utilsplugin2.askurl",false));
    68        
     71        check1.setSelected(Main.pref.getBoolean("utilsplugin2.askurl", false));
     72
    6973        editField.setEditable(false);
    70        
    71         all.add(label1,GBC.eop().fill(GBC.HORIZONTAL).insets(15,5,15,0));
    72         all.add(list1,GBC.eop().fill(GBC.HORIZONTAL).insets(5,5,0,0));
    73         all.add(editField,GBC.eop().fill(GBC.HORIZONTAL).insets(5,5,0,0));
    74         all.add(check1,GBC.eop().fill(GBC.HORIZONTAL).insets(5,5,0,0));
    75        
    76        
     74
     75        all.add(label1, GBC.eop().fill(GBC.HORIZONTAL).insets(15, 5, 15, 0));
     76        all.add(list1, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5, 0, 0));
     77        all.add(editField, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5, 0, 0));
     78        all.add(check1, GBC.eop().fill(GBC.HORIZONTAL).insets(5, 5, 0, 0));
     79
     80
    7781        dialog.setContent(all, false);
    78         dialog.setButtonIcons(new String[] {"ok.png","cancel.png",});
     82        dialog.setButtonIcons(new String[] {"ok.png", "cancel.png"});
    7983        dialog.setDefaultButton(1);
    8084        dialog.showDialog();
    81        
     85
    8286        int idx = list1.getSelectedIndex();
    83         if (dialog.getValue() ==1 && idx>=0) {
    84            URLList.select(vals[idx]);
    85            Main.pref.put("utilsplugin2.askurl", check1.isSelected());
     87        if (dialog.getValue() == 1 && idx >= 0) {
     88            URLList.select(vals[idx]);
     89            Main.pref.put("utilsplugin2.askurl", check1.isSelected());
    8690        }
    8791    }
    88 
    89    
    90    
    9192}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/OpenPageAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.customurl;
    33
    4 import java.io.UnsupportedEncodingException;
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    55import static org.openstreetmap.josm.tools.I18n.tr;
    6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    76
    87import java.awt.event.ActionEvent;
    98import java.awt.event.KeyEvent;
     9import java.io.UnsupportedEncodingException;
    1010import java.net.URLEncoder;
    1111import java.util.Collection;
    12 
    1312import java.util.regex.Matcher;
    14 
    1513import java.util.regex.Pattern;
    1614
     
    3028 *
    3129 * @author Alexei Kasatkin, based on much copy&Paste from other MirrorAction :)
    32  */ 
     30 */
    3331public final class OpenPageAction extends JosmAction {
    34    
     32
    3533    public OpenPageAction() {
    3634        super(tr("Open custom URL"), "openurl",
    3735                tr("Opens specified URL browser"),
    3836                Shortcut.registerShortcut("tools:openurl", tr("Tool: {0}", tr("Open custom URL")),
    39                 KeyEvent.VK_H, Shortcut.SHIFT), true);
     37                        KeyEvent.VK_H, Shortcut.SHIFT), true);
    4038        putValue("help", ht("/Action/OpenPage"));
    4139    }
     
    4442    public void actionPerformed(ActionEvent e) {
    4543        Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected();
    46         OsmPrimitive p=null;
    47         if (sel.size()>=1) {
    48             p=sel.iterator().next();
     44        OsmPrimitive p = null;
     45        if (sel.size() >= 1) {
     46            p = sel.iterator().next();
    4947        }
    50        
    51         if (Main.pref.getBoolean("utilsplugin2.askurl",false)==true)
     48
     49        if (Main.pref.getBoolean("utilsplugin2.askurl", false) == true)
    5250            ChooseURLAction.showConfigDialog(true);
    53        
    54         //lat = p.getBBox().getTopLeft().lat();
    55         //lon = p.getBBox().getTopLeft().lon();
     51
    5652        LatLon center = Main.map.mapView.getLatLon(Main.map.mapView.getWidth()/2, Main.map.mapView.getHeight()/2);
    57                
    58         String addr =  URLList.getSelectedURL();
     53
     54        String addr = URLList.getSelectedURL();
    5955        Pattern pat = Pattern.compile("\\{([^\\}]*)\\}");
    6056        Matcher m = pat.matcher(addr);
    61         String val,key;
    62         String keys[]=new String[100],vals[]=new String[100];
    63         int i=0;
     57        String val, key;
     58        String[] keys = new String[100], vals = new String[100];
     59        int i = 0;
    6460        try {
    65         while (m.find()) {
    66             key=m.group(1); val=null;               
    67             if (key.equals("#id")) {
    68                 if (p!=null) val=Long.toString(p.getId());
    69             } else if (key.equals("#type")) {
    70                 if (p!=null) val = OsmPrimitiveType.from(p).getAPIName();
    71             } else if (key.equals("#lat")) {
    72                 val = Double.toString(center.lat());
    73             } else if (key.equals("#lon")) {
    74                 val = Double.toString(center.lon());
    75             } else if (key.equals("#zoom")) {
    76                 val = Integer.toString(OsmUrlToBounds.getZoom(Main.map.mapView.getRealBounds()));
     61            while (m.find()) {
     62                key = m.group(1); val = null;
     63                if (key.equals("#id")) {
     64                    if (p != null) val = Long.toString(p.getId());
     65                } else if (key.equals("#type")) {
     66                    if (p != null) val = OsmPrimitiveType.from(p).getAPIName();
     67                } else if (key.equals("#lat")) {
     68                    val = Double.toString(center.lat());
     69                } else if (key.equals("#lon")) {
     70                    val = Double.toString(center.lon());
     71                } else if (key.equals("#zoom")) {
     72                    val = Integer.toString(OsmUrlToBounds.getZoom(Main.map.mapView.getRealBounds()));
     73                } else {
     74                    if (p != null) {
     75                        val = p.get(key);
     76                        if (val != null) val = URLEncoder.encode(p.get(key), "UTF-8"); else return;
     77                    }
     78                }
     79                keys[i] = m.group();
     80                if (val != null) vals[i] = val;
     81                else vals[i] = "";
     82                i++;
    7783            }
    78             else {
    79                 if (p!=null) {
    80                     val =p.get(key);
    81                     if (val!=null) val =URLEncoder.encode(p.get(key), "UTF-8"); else return;
    82                 }
    83             }
    84             keys[i]=m.group();
    85             if  (val!=null) vals[i]=val;
    86             else vals[i]="";
    87             i++;
    88         }
    8984        } catch (UnsupportedEncodingException ex) {
    9085            Main.error(ex, "Encoding error");
    9186            return;
    9287        }
    93         for (int j=0;j<i;j++){
    94             addr = addr.replace(keys[j],vals[j]);
     88        for (int j = 0; j < i; j++) {
     89            addr = addr.replace(keys[j], vals[j]);
    9590        }
    9691        try {
     
    9994            Main.error(ex, "Can not open URL " + addr);
    10095        }
    101         //Collection<Command> cmds = new LinkedList<Command>();
    102 
    103         //cmds.add(new MoveCommand(n, -2*ne*pr, -2*nn*pr ));
    104         //Main.main.undoRedo.add(new SequenceCommand(tr("Symmetry"), cmds));
    10596    }
    10697
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/URLList.java

    r31153 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.customurl;
    23
     
    1415import org.openstreetmap.josm.plugins.utilsplugin2.UtilsPlugin2;
    1516
    16 public class URLList {
     17public final class URLList {
    1718    public static final String defaultURL = "http://osm.mapki.com/history/{#type}.php?id={#id}";
     19
     20    private URLList() {
     21        // Hide default constructor for utilities classes
     22    }
    1823
    1924    public static String getSelectedURL() {
     
    2126        return Main.pref.get("utilsplugin2.customurl", defaultURL);
    2227    }
     28
    2329    public static void select(String url) {
    24         Main.pref.put("utilsplugin2.customurl",url);
     30        Main.pref.put("utilsplugin2.customurl", url);
    2531    }
     32
    2633    public static List<String> resetURLList() {
    27         List<String> items=new ArrayList<>();
     34        List<String> items = new ArrayList<>();
    2835        items.add("Wikipedia");
    2936        items.add("https://en.wikipedia.org/w/index.php?search={name}&fulltext=Search");
     
    3845        items.add("Browse element [demo, =Ctrl-Shift-I]");
    3946        items.add("https://www.openstreetmap.org/{#type}/{#id}");
    40         Main.pref.putCollection("utilsplugin2.urlHistory",items);
    41         Main.pref.put("utilsplugin2.customurl",items.get(9));
     47        Main.pref.putCollection("utilsplugin2.urlHistory", items);
     48        Main.pref.put("utilsplugin2.customurl", items.get(9));
    4249        return items;
    4350    }
     
    4552    public static List<String> getURLList() {
    4653        List<String> items = (List<String>) Main.pref.getCollection("utilsplugin2.urlHistory");
    47         if (items==null || items.isEmpty()) {
     54        if (items == null || items.isEmpty()) {
    4855            resetURLList();
    49             items=(List<String>) Main.pref.getCollection("utilsplugin2.urlHistory");
     56            items = (List<String>) Main.pref.getCollection("utilsplugin2.urlHistory");
    5057        }
    5158        return items;
     
    5360
    5461    public static void updateURLList(List<String> lst) {
    55         Main.pref.putCollection("utilsplugin2.urlHistory",lst);
     62        Main.pref.putCollection("utilsplugin2.urlHistory", lst);
    5663        try {
    5764            Main.pref.save();
     
    6269
    6370    public static List<String> loadURLList() {
    64         ArrayList<String> items=new ArrayList<>();
    65         BufferedReader fr=null;
     71        ArrayList<String> items = new ArrayList<>();
     72        BufferedReader fr = null;
    6673        try {
    67                 File f = new File(UtilsPlugin2.getInstance().getPluginDir(), "customurl.txt");
    68                 fr = new BufferedReader(new FileReader(f));
    69                 String s;
    70                 while ((s = fr.readLine()) !=null ) items.add(s);
     74            File f = new File(UtilsPlugin2.getInstance().getPluginDir(), "customurl.txt");
     75            fr = new BufferedReader(new FileReader(f));
     76            String s;
     77            while ((s = fr.readLine()) != null) items.add(s);
    7178        } catch (IOException e) {
    7279            e.printStackTrace();
    7380        } finally {
    74             try { if (fr!=null) fr.close(); } catch (Exception e) {}
     81            try {
     82                if (fr != null)
     83                    fr.close();
     84            } catch (Exception e) {
     85                Main.warn(e);
     86            }
    7587        }
    7688        return items;
     
    7991    public static void saveURLList(List<String> items) {
    8092        File f = new File(UtilsPlugin2.getInstance().getPluginDir(), "customurl.txt");
    81         PrintWriter fw=null;
     93        PrintWriter fw = null;
    8294        try {
    8395            f.getParentFile().mkdirs();
    84                 fw=new PrintWriter(f);
    85                 for (String s : items) {
    86                     fw.println(s);
    87                 }
     96            fw = new PrintWriter(f);
     97            for (String s : items) {
     98                fw.println(s);
     99            }
    88100        } catch (IOException e) {
    89101            e.printStackTrace();
    90102        } finally {
    91             try { if (fw!=null) fw.close(); } catch (Exception e) {}
     103            try {
     104                if (fw != null)
     105                    fw.close();
     106            } catch (Exception e) {
     107                Main.warn(e);
     108            }
    92109        }
    93110    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/UtilsPluginPreferences.java

    r30737 r32410  
    22package org.openstreetmap.josm.plugins.utilsplugin2.customurl;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.GridBagLayout;
    47import java.awt.event.ActionEvent;
     8import java.awt.event.ActionListener;
     9import java.util.ArrayList;
     10import java.util.List;
     11
    512import javax.swing.JButton;
    6 import java.util.List;
     13import javax.swing.JLabel;
     14import javax.swing.JPanel;
     15import javax.swing.JTable;
     16import javax.swing.ListSelectionModel;
     17import javax.swing.event.TableModelEvent;
     18import javax.swing.event.TableModelListener;
     19import javax.swing.table.DefaultTableModel;
    720import javax.swing.table.TableModel;
    8 import javax.swing.JTable;
    9 import javax.swing.JLabel;
    10 import java.awt.GridBagLayout;
    11 import java.util.ArrayList;
    12 import javax.swing.event.TableModelEvent;
     21
     22import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
     23import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
    1324import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
    1425import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    15 import java.awt.event.ActionListener;
    16 import javax.swing.JPanel;
    17 import javax.swing.ListSelectionModel;
    18 import javax.swing.event.TableModelListener;
    19 import javax.swing.table.DefaultTableModel;
    20 import org.openstreetmap.josm.gui.preferences.DefaultTabPreferenceSetting;
    21 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
    2226import org.openstreetmap.josm.tools.GBC;
    2327
    24 import static org.openstreetmap.josm.tools.I18n.*;
    25 
    2628public class UtilsPluginPreferences extends DefaultTabPreferenceSetting {
    27     HistoryComboBox combo1=new HistoryComboBox();
     29    HistoryComboBox combo1 = new HistoryComboBox();
    2830    JTable table;
    2931    JButton resetButton;
     
    4042
    4143        URLList.getSelectedURL();
    42         table=new JTable(new DefaultTableModel(null,new String[]{"Title","URL"}));
     44        table = new JTable(new DefaultTableModel(null, new String[]{"Title", "URL"}));
    4345
    4446        List<String> items = URLList.getURLList();
     
    7779                + " Your can manually load settings from file <b>customurl.txt</b> in JOSM folder"));
    7880
    79         all.add(new JLabel(tr("Custom URL configuration")),GBC.std().insets(5,10,0,0));
    80         all.add(resetButton,GBC.std().insets(25,10,0,0));
    81         all.add(loadButton,GBC.std().insets(25,10,0,0));
    82         all.add(saveButton,GBC.eol().insets(25,10,0,0));
    83         all.add(help,GBC.eop().insets(5,10,0,0));
     81        all.add(new JLabel(tr("Custom URL configuration")), GBC.std().insets(5, 10, 0, 0));
     82        all.add(resetButton, GBC.std().insets(25, 10, 0, 0));
     83        all.add(loadButton, GBC.std().insets(25, 10, 0, 0));
     84        all.add(saveButton, GBC.eol().insets(25, 10, 0, 0));
     85        all.add(help, GBC.eop().insets(5, 10, 0, 0));
    8486
    8587        table.getColumnModel().getColumn(0).setPreferredWidth(150);
     
    9294                int row = e.getFirstRow();
    9395                int column = e.getColumn();
    94                 DefaultTableModel model = (DefaultTableModel)(e.getSource());
    95                 if (row<0  || column<0) return;
    96                 String data = (String)model.getValueAt(row, column);
    97                 if (data!=null && data.length()>0 && row==model.getRowCount()-1)
    98                     model.addRow(new String[]{"",""});
     96                DefaultTableModel model = (DefaultTableModel) e.getSource();
     97                if (row < 0 || column < 0) return;
     98                String data = (String) model.getValueAt(row, column);
     99                if (data != null && data.length() > 0 && row == model.getRowCount()-1)
     100                    model.addRow(new String[]{"", ""});
    99101            }
    100102        });
    101         all.add(table,GBC.eop().fill());
     103        all.add(table, GBC.eop().fill());
    102104        createPreferenceTabWithScrollPane(gui, all);
    103105    }
    104106
    105107    private void fillRows(List<String> items) {
    106         if (items==null) return;
    107         int p=0;
     108        if (items == null) return;
     109        int p = 0;
    108110        String name, url;
    109111        DefaultTableModel model = (DefaultTableModel) table.getModel();
    110112        model.setRowCount(0);
    111         int n=items.size();
     113        int n = items.size();
    112114        while (true) {
    113             if (p>=n) break;
     115            if (p >= n) break;
    114116            name = items.get(p);
    115117            p++;
    116             if (p>=n) break;
     118            if (p >= n) break;
    117119            url = items.get(p);
    118120            p++;
    119             model.addRow(new String[]{name,url});
     121            model.addRow(new String[]{name, url});
    120122        }
    121         model.addRow(new String[]{"",""});
     123        model.addRow(new String[]{"", ""});
    122124    }
    123125
     
    134136        TableModel model = (table.getModel());
    135137        String v;
    136         ArrayList<String> lst=new ArrayList<>();
    137         int n=model.getRowCount();
    138         for (int i=0;i<n;i++) {
    139             v=(String) model.getValueAt(i, 0);
    140             if (v.length()==0) continue;
     138        ArrayList<String> lst = new ArrayList<>();
     139        int n = model.getRowCount();
     140        for (int i = 0; i < n; i++) {
     141            v = (String) model.getValueAt(i, 0);
     142            if (v.length() == 0) continue;
    141143            lst.add(v);
    142             v=(String) model.getValueAt(i, 1);
     144            v = (String) model.getValueAt(i, 1);
    143145            lst.add(v);
    144146        }
    145         int row=table.getSelectedRow();
    146         if (row!=-1) {
    147             v=(String) model.getValueAt(row, 1);
     147        int row = table.getSelectedRow();
     148        if (row != -1) {
     149            v = (String) model.getValueAt(row, 1);
    148150            URLList.select(v);
    149151        }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/latlon/LatLonAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.latlon;
    33
     
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
    9 
    109import java.util.Collection;
    1110import java.util.LinkedList;
    1211
    1312import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.actions.JosmAction;
    1414import org.openstreetmap.josm.command.AddCommand;
     15import org.openstreetmap.josm.command.Command;
    1516import org.openstreetmap.josm.command.SequenceCommand;
    16 import org.openstreetmap.josm.command.Command;
    1717import org.openstreetmap.josm.data.coor.LatLon;
    1818import org.openstreetmap.josm.data.osm.Node;
    1919import org.openstreetmap.josm.data.osm.Way;
    2020import org.openstreetmap.josm.tools.Shortcut;
    21 import org.openstreetmap.josm.actions.JosmAction;
    2221
    2322/**
     
    4746
    4847        dialog.showDialog();
    49        
     48
    5049        if (dialog.getValue() != 1)
    5150            return;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/latlon/LatLonDialog.java

    r31651 r32410  
    1818
    1919import javax.swing.BorderFactory;
     20import javax.swing.ButtonGroup;
    2021import javax.swing.JLabel;
    2122import javax.swing.JPanel;
     23import javax.swing.JRadioButton;
     24import javax.swing.JScrollPane;
    2225import javax.swing.JSeparator;
    2326import javax.swing.JTabbedPane;
    24 
    2527import javax.swing.JTextArea;
    26 import javax.swing.JScrollPane;
    27 import javax.swing.ButtonGroup;
    28 import javax.swing.JRadioButton;
    29 
    3028import javax.swing.UIManager;
    3129import javax.swing.event.ChangeEvent;
     
    4341
    4442public class LatLonDialog extends ExtendedDialog {
    45     private static final Color BG_COLOR_ERROR = new Color(255,224,224);
     43    private static final Color BG_COLOR_ERROR = new Color(255, 224, 224);
    4644
    4745    public JTabbedPane tabs;
     
    7876    protected JPanel buildLatLon() {
    7977        JPanel pnl = new JPanel(new GridBagLayout());
    80         pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    81 
    82         pnl.add(new JLabel(tr("Coordinates:")), GBC.std().insets(0,10,5,0));
    83 
    84         taLatLon = new JTextArea(5,24);
     78        pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     79
     80        pnl.add(new JLabel(tr("Coordinates:")), GBC.std().insets(0, 10, 5, 0));
     81
     82        taLatLon = new JTextArea(5, 24);
    8583        taLatLon.getDocument().addDocumentListener(new CoordinateListener());
    86         spScroll = new JScrollPane(taLatLon);
    87         pnl.add(spScroll, GBC.eol().insets(0,10,0,0).fill().weight(2.0, 2.0));
    88 
    89         //Radio button setup
    90         bgType = new ButtonGroup();
    91 
    92         rbNodes = new JRadioButton("Nodes", true);
    93         rbNodes.setActionCommand("nodes");
    94         bgType.add(rbNodes);
    95         pnl.add(rbNodes);
    96 
    97         rbWay = new JRadioButton("Way");
    98         rbWay.setActionCommand("way");
    99         bgType.add(rbWay);
    100         pnl.add(rbWay);
    101 
    102         rbClosedWay = new JRadioButton("Closed Way (Area)");
    103         rbClosedWay.setActionCommand("area");
    104         bgType.add(rbClosedWay);
    105         pnl.add(rbClosedWay, GBC.eol());
    106 
    107         //pnl.add(bgType, GBC.eol().insets(0,10,0,0).fill(GBC.HORIZONTAL).weight(2.0, 0.0));
    108         //pnl.add(new JRadioButton("test"));
    109         //pnl.add(bgType);
    110 
    111         pnl.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0,5,0,5));
     84        spScroll = new JScrollPane(taLatLon);
     85        pnl.add(spScroll, GBC.eol().insets(0, 10, 0, 0).fill().weight(2.0, 2.0));
     86
     87        //Radio button setup
     88        bgType = new ButtonGroup();
     89
     90        rbNodes = new JRadioButton("Nodes", true);
     91        rbNodes.setActionCommand("nodes");
     92        bgType.add(rbNodes);
     93        pnl.add(rbNodes);
     94
     95        rbWay = new JRadioButton("Way");
     96        rbWay.setActionCommand("way");
     97        bgType.add(rbWay);
     98        pnl.add(rbWay);
     99
     100        rbClosedWay = new JRadioButton("Closed Way (Area)");
     101        rbClosedWay.setActionCommand("area");
     102        bgType.add(rbClosedWay);
     103        pnl.add(rbClosedWay, GBC.eol());
     104
     105        pnl.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 5));
    112106
    113107        pnl.add(new HtmlPanel(
    114                 tr("Enter the coordinates for the new nodes, one for each line.<br/>If you enter two lines with the same coordinates there will be generated duplicate nodes.<br/>You can separate longitude and latitude with space, comma or semicolon.<br/>" +
    115                     "Use positive numbers or N, E characters to indicate North or East cardinal direction.<br/>" +
    116                     "For South and West cardinal directions you can use either negative numbers or S, W characters.<br/>" +
    117                     "Coordinate value can be in one of three formats:<ul>" +
    118                     "<li><i>degrees</i><tt>&deg;</tt></li>" +
    119                     "<li><i>degrees</i><tt>&deg;</tt> <i>minutes</i><tt>&#39;</tt></li>" +
    120                     "<li><i>degrees</i><tt>&deg;</tt> <i>minutes</i><tt>&#39;</tt> <i>seconds</i><tt>&quot</tt></li>" +
    121                     "</ul>" +
    122                     "Symbols <tt>&deg;</tt>, <tt>&#39;</tt>, <tt>&prime;</tt>, <tt>&quot;</tt>, <tt>&Prime;</tt> are optional.<br/><br/>" +
    123                     "Some examples:<ul>" +
    124                     "<li>49.29918&deg; 19.24788&deg;</li>" +
    125                     "<li>N 49.29918 E 19.24788</li>" +
    126                     "<li>W 49&deg;29.918&#39; S 19&deg;24.788&#39;</li>" +
    127                     "<li>N 49&deg;29&#39;04&quot; E 19&deg;24&#39;43&quot;</li>" +
    128                     "<li>49.29918 N, 19.24788 E</li>" +
    129                     "<li>49&deg;29&#39;21&quot; N 19&deg;24&#39;38&quot; E</li>" +
    130                     "<li>49 29 51, 19 24 18</li>" +
    131                     "<li>49 29, 19 24</li>" +
    132                     "<li>E 49 29, N 19 24</li>" +
    133                     "<li>49&deg; 29; 19&deg; 24</li>" +
    134                     "<li>N 49&deg; 29, W 19&deg; 24</li>" +
    135                     "<li>49&deg; 29.5 S, 19&deg; 24.6 E</li>" +
    136                     "<li>N 49 29.918 E 19 15.88</li>" +
    137                     "<li>49 29.4 19 24.5</li>" +
    138                     "<li>-49 29.4 N -19 24.5 W</li></ul>" +
    139                     "<li>48 deg 42&#39; 52.13\" N, 21 deg 11&#39; 47.60\" E</li></ul>"
    140                 )),
     108                tr("Enter the coordinates for the new nodes, one for each line.<br/>"+
     109                        "If you enter two lines with the same coordinates there will be generated duplicate nodes.<br/>"+
     110                        "You can separate longitude and latitude with space, comma or semicolon.<br/>" +
     111                        "Use positive numbers or N, E characters to indicate North or East cardinal direction.<br/>" +
     112                        "For South and West cardinal directions you can use either negative numbers or S, W characters.<br/>" +
     113                        "Coordinate value can be in one of three formats:<ul>" +
     114                        "<li><i>degrees</i><tt>&deg;</tt></li>" +
     115                        "<li><i>degrees</i><tt>&deg;</tt> <i>minutes</i><tt>&#39;</tt></li>" +
     116                        "<li><i>degrees</i><tt>&deg;</tt> <i>minutes</i><tt>&#39;</tt> <i>seconds</i><tt>&quot</tt></li>" +
     117                        "</ul>" +
     118                        "Symbols <tt>&deg;</tt>, <tt>&#39;</tt>, <tt>&prime;</tt>, <tt>&quot;</tt>, <tt>&Prime;</tt> are optional.<br/><br/>" +
     119                        "Some examples:<ul>" +
     120                        "<li>49.29918&deg; 19.24788&deg;</li>" +
     121                        "<li>N 49.29918 E 19.24788</li>" +
     122                        "<li>W 49&deg;29.918&#39; S 19&deg;24.788&#39;</li>" +
     123                        "<li>N 49&deg;29&#39;04&quot; E 19&deg;24&#39;43&quot;</li>" +
     124                        "<li>49.29918 N, 19.24788 E</li>" +
     125                        "<li>49&deg;29&#39;21&quot; N 19&deg;24&#39;38&quot; E</li>" +
     126                        "<li>49 29 51, 19 24 18</li>" +
     127                        "<li>49 29, 19 24</li>" +
     128                        "<li>E 49 29, N 19 24</li>" +
     129                        "<li>49&deg; 29; 19&deg; 24</li>" +
     130                        "<li>N 49&deg; 29, W 19&deg; 24</li>" +
     131                        "<li>49&deg; 29.5 S, 19&deg; 24.6 E</li>" +
     132                        "<li>N 49 29.918 E 19 15.88</li>" +
     133                        "<li>49 29.4 19 24.5</li>" +
     134                        "<li>-49 29.4 N -19 24.5 W</li></ul>" +
     135                        "<li>48 deg 42&#39; 52.13\" N, 21 deg 11&#39; 47.60\" E</li></ul>"
     136                        )),
    141137                GBC.eol().fill().weight(1.0, 1.0));
    142138
     
    160156            public void stateChanged(ChangeEvent e) {
    161157                switch (tabs.getModel().getSelectedIndex()) {
    162                     case 0: parseLatLonUserInput(); break;
    163                     default: throw new AssertionError();
     158                case 0: parseLatLonUserInput(); break;
     159                default: throw new AssertionError();
    164160                }
    165161            }
     
    169165
    170166    public LatLonDialog(Component parent, String title, String help) {
    171         super(Main.parent, tr("Add Node..."), new String[] { tr("Ok"), tr("Cancel") });
    172         setButtonIcons(new String[] { "ok", "cancel" });
     167        super(Main.parent, tr("Add Node..."), new String[] {tr("Ok"), tr("Cancel")});
     168        setButtonIcons(new String[] {"ok", "cancel"});
    173169        configureContextsensitiveHelp("/Action/AddNode", true);
    174170
     
    182178        }
    183179        this.latLonCoordinates = ll;
    184     String text = "";
    185     for (LatLon latlon : ll) {
    186             text = text + latlon.latToString(CoordinateFormat.getDefaultFormat()) + " " + latlon.lonToString(CoordinateFormat.getDefaultFormat()) + "\n";
     180        String text = "";
     181        for (LatLon latlon : ll) {
     182            text = text + latlon.latToString(CoordinateFormat.getDefaultFormat())
     183            + " " + latlon.lonToString(CoordinateFormat.getDefaultFormat()) + "\n";
    187184        }
    188185        taLatLon.setText(text);
     
    224221        //
    225222        NumberFormat f = NumberFormat.getNumberInstance();
    226         Number n=null;
     223        Number n = null;
    227224        ParsePosition pp = new ParsePosition(0);
    228         n = f.parse(input,pp);
    229         if (pp.getErrorIndex() >= 0 || pp.getIndex()<input.length()) {
     225        n = f.parse(input, pp);
     226        if (pp.getErrorIndex() >= 0 || pp.getIndex() < input.length()) {
    230227            // fall back - try to parse with the english locale
    231228            //
     
    233230            f = NumberFormat.getNumberInstance(Locale.ENGLISH);
    234231            n = f.parse(input, pp);
    235             if (pp.getErrorIndex() >= 0 || pp.getIndex()<input.length())
     232            if (pp.getErrorIndex() >= 0 || pp.getIndex() < input.length())
    236233                return null;
    237234        }
    238         return n== null ? null : n.doubleValue();
     235        return n == null ? null : n.doubleValue();
    239236    }
    240237
     
    243240        try {
    244241            latLons = parseLatLons(taLatLon.getText());
    245         Boolean working = true;
    246         int i=0;
    247         while (working && i < latLons.length) {
    248         if (!LatLon.isValidLat(latLons[i].lat()) || !LatLon.isValidLon(latLons[i].lon())) {
     242            Boolean working = true;
     243            int i = 0;
     244            while (working && i < latLons.length) {
     245                if (!LatLon.isValidLat(latLons[i].lat()) || !LatLon.isValidLon(latLons[i].lon())) {
    249246                    latLons = null;
    250             working = false;
     247                    working = false;
    251248                }
    252         i++;
    253         }
     249                i++;
     250            }
    254251        } catch (IllegalArgumentException e) {
    255252            latLons = null;
     
    260257            setOkEnabled(false);
    261258        } else {
    262             clearErrorFeedback(taLatLon,tr("Please enter a GPS coordinates"));
     259            clearErrorFeedback(taLatLon, tr("Please enter a GPS coordinates"));
    263260            latLonCoordinates = latLons;
    264261            setOkEnabled(true);
     
    279276                    preferenceKey,
    280277                    WindowGeometry.centerInWindow(getParent(), getSize())
    281             ).applySafe(this);
     278                    ).applySafe(this);
    282279        } else {
    283280            new WindowGeometry(this).remember(preferenceKey);
     
    301298
    302299    static class TextFieldFocusHandler implements FocusListener {
    303         @Override 
     300        @Override
    304301        public void focusGained(FocusEvent e) {
    305302            Component c = e.getComponent();
    306303            if (c instanceof JTextArea) {
    307                 JTextArea tf = (JTextArea)c;
     304                JTextArea tf = (JTextArea) c;
    308305                tf.selectAll();
    309306            }
    310307        }
    311         @Override
     308
     309        @Override
    312310        public void focusLost(FocusEvent e) {}
    313311    }
    314312
    315313    private static LatLon[] parseLatLons(final String text) {
    316         String lines[] = text.split("\\r?\\n");
     314        String[] lines = text.split("\\r?\\n");
    317315        List<LatLon> latLons = new ArrayList<>();
    318316        for (String line : lines) {
     
    426424    }
    427425
    428     private static void setLatLon(final LatLonHolder latLon, final double coordDeg, final double coordMin, final double coordSec, final String card) {
     426    private static void setLatLon(final LatLonHolder latLon, final double coordDeg, final double coordMin, final double coordSec,
     427            final String card) {
    429428        if (coordDeg < -180 || coordDeg > 180 || coordMin < 0 || coordMin >= 60 || coordSec < 0 || coordSec > 60) {
    430429            throw new IllegalArgumentException("out of range");
     
    452451            //not fired
    453452        }
     453
    454454        @Override public void insertUpdate(DocumentEvent e) {
    455455            updateButtons();
    456456        }
     457
    457458        @Override public void removeUpdate(DocumentEvent e) {
    458459            updateButtons();
    459460        }
     461
    460462        private void updateButtons() {
    461463            String text = taLatLon.getText();
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.multitagger;
    23
     
    2021     */
    2122    public MultiTagAction() {
    22         super(tr("Tag multiple objects [alpha]"), (String)null, tr("Edit tags of object list in table"),
     23        super(tr("Tag multiple objects [alpha]"), (String) null, tr("Edit tags of object list in table"),
    2324                Shortcut.registerShortcut("multitag", tr("Edit: {0}", tr("Tag multiple objects")), KeyEvent.VK_T, Shortcut.CTRL),
    2425                true, "multitag", true);
     
    3738    @Override
    3839    protected void updateEnabledState() {
    39         setEnabled(getLayerManager().getEditLayer()!=null);
     40        setEnabled(getLayerManager().getEditLayer() != null);
    4041    }
    4142
    4243    @Override
    4344    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    44         setEnabled(getLayerManager().getEditLayer()!=null);
    45         if (dlg!=null && dlg.isVisible()) {
     45        setEnabled(getLayerManager().getEditLayer() != null);
     46        if (dlg != null && dlg.isVisible()) {
    4647            dlg.selectionChanged(selection);
    4748        }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagDialog.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.multitagger;
    23
     
    7172
    7273    private static final String HISTORY_KEY = "utilsplugin2.multitaghistory";
    73     String defaultHistory[] = {"addr:street, addr:housenumber, building, ${area}",
    74         "highway, name, ${id}, ${length}",
    75         "name name:en name:ru name:de"};
     74    String[] defaultHistory = {"addr:street, addr:housenumber, building, ${area}",
     75            "highway, name, ${id}, ${length}",
     76    "name name:en name:ru name:de"};
    7677
    7778    public MultiTagDialog() {
    78         super(Main.parent,  tr("Edit tags"), new String[]{tr("Ok"), tr("Cancel")}, false);
     79        super(Main.parent, tr("Edit tags"), new String[]{tr("Ok"), tr("Cancel")}, false);
    7980        JPanel pnl = new JPanel(new GridBagLayout());
    8081        tbl = createTable();
     
    8283        cbTagSet.addItemListener(tagSetChanger);
    8384        cbTagSet.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
    84            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), "applyTagSet");
     85        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true), "applyTagSet");
    8586        cbTagSet.getActionMap().put("applyTagSet", tagSetChanger);
    8687
    8788        tbl.addMouseListener(new PopupMenuLauncher(createPopupMenu()));
    8889
    89         pnl.add(cbTagSet,GBC.std().fill(GBC.HORIZONTAL));
    90         pnl.add(new JButton(new DeleteFromHistoryAction()),GBC.std());
    91         pnl.add(new JButton(new FindMatchingAction()),GBC.std());
     90        pnl.add(cbTagSet, GBC.std().fill(GBC.HORIZONTAL));
     91        pnl.add(new JButton(new DeleteFromHistoryAction()), GBC.std());
     92        pnl.add(new JButton(new FindMatchingAction()), GBC.std());
    9293        final JToggleButton jt = new JToggleButton("", ImageProvider.get("restart"), true);
    9394        jt.setToolTipText(tr("Sync with JOSM selection"));
    94         jt.addActionListener(new ActionListener(){
     95        jt.addActionListener(new ActionListener() {
    9596            @Override public void actionPerformed(ActionEvent e) {
    9697                tableModel.setWatchSelection(jt.isSelected());
    97             };
    98         });
    99         pnl.add(jt,GBC.eol());
    100 
     98            }
     99        });
     100        pnl.add(jt, GBC.eol());
    101101
    102102        pnl.add(createTypeFilterPanel(), GBC.eol().fill(GBC.HORIZONTAL));
    103         pnl.add(tbl.getTableHeader(),GBC.eop().fill(GBC.HORIZONTAL));
     103        pnl.add(tbl.getTableHeader(), GBC.eop().fill(GBC.HORIZONTAL));
    104104
    105105        pnl.add(new JScrollPane(tbl), GBC.eol().fill(GBC.BOTH));
     
    132132        for (final OsmPrimitiveType type: OsmPrimitiveType.values()) {
    133133            final JToggleButton jt = new JToggleButton("", ImageProvider.get(type), true);
    134             jt.addActionListener(new ActionListener(){
     134            jt.addActionListener(new ActionListener() {
    135135                @Override
    136136                public void actionPerformed(ActionEvent e) {
     
    169169    /*private OsmPrimitive getSelectedPrimitive() {
    170170        int idx = tbl.getSelectedRow();
    171         if (idx>=0) {
     171        if (idx>= 0) {
    172172            return tableModel.getPrimitiveAt(tbl.convertRowIndexToModel(idx));
    173173        } else {
     
    176176    }*/
    177177
    178    private final MouseAdapter tableMouseAdapter = new MouseAdapter() {
     178    private final MouseAdapter tableMouseAdapter = new MouseAdapter() {
    179179        @Override
    180180        public void mouseClicked(MouseEvent e) {
    181             if (e.getClickCount()>1 && Main.isDisplayingMapView()) {
     181            if (e.getClickCount() > 1 && Main.isDisplayingMapView()) {
    182182                AutoScaleAction.zoomTo(currentSelection);
    183183            }
     
    189189        public void valueChanged(ListSelectionEvent e) {
    190190            currentSelection = getSelectedPrimitives();
    191             if (currentSelection != null && Main.isDisplayingMapView() ) {
     191            if (currentSelection != null && Main.isDisplayingMapView()) {
    192192                if (highlightHelper.highlightOnly(currentSelection)) {
    193193                    Main.map.mapView.repaint();
     
    210210        OsmDataLayer l = Main.getLayerManager().getEditLayer();
    211211        AutoCompletionManager autocomplete = l.data.getAutoCompletionManager();
    212         for (int i=0; i<tableModel.mainTags.length; i++) {
    213                 if (tableModel.isSpecialTag[i]) continue;
    214                 AutoCompletingTextField tf = new AutoCompletingTextField(0, false);
    215                 AutoCompletionList acList = new AutoCompletionList();
    216                 autocomplete.populateWithTagValues(acList, tableModel.mainTags[i]);
    217                 tf.setAutoCompletionList(acList);
    218                 tbl.getColumnModel().getColumn(i+1).setCellEditor(tf);
     212        for (int i = 0; i < tableModel.mainTags.length; i++) {
     213            if (tableModel.isSpecialTag[i]) continue;
     214            AutoCompletingTextField tf = new AutoCompletingTextField(0, false);
     215            AutoCompletionList acList = new AutoCompletionList();
     216            autocomplete.populateWithTagValues(acList, tableModel.mainTags[i]);
     217            tf.setAutoCompletionList(acList);
     218            tbl.getColumnModel().getColumn(i+1).setCellEditor(tf);
    219219        }
    220220    }
     
    236236            }
    237237        });
    238         menu.add(new AbstractAction(tr("Remove tag"), ImageProvider.get("dialogs", "delete")){
     238        menu.add(new AbstractAction(tr("Remove tag"), ImageProvider.get("dialogs", "delete")) {
    239239            @Override
    240240            public void actionPerformed(ActionEvent e) {
     
    249249            }
    250250        });
    251         menu.add(new AbstractAction(tr("Duplicate tags from the first"), ImageProvider.get("copy")){
     251        menu.add(new AbstractAction(tr("Duplicate tags from the first"), ImageProvider.get("copy")) {
    252252            @Override
    253253            public void actionPerformed(ActionEvent e) {
    254254                tableModel.setAutoCommit(false);
    255255                for (int c: tbl.getSelectedColumns()) {
    256                     if (c==0 || tableModel.isSpecialTag[c-1]) continue;
     256                    if (c == 0 || tableModel.isSpecialTag[c-1]) continue;
    257257                    boolean first = true;
    258258                    String value = "";
     
    261261                            value = (String) tableModel.getValueAt(tbl.convertRowIndexToModel(r), tbl.convertColumnIndexToModel(c));
    262262                        }
    263                         first=false;
     263                        first = false;
    264264                        tableModel.setValueAt(value, tbl.convertRowIndexToModel(r), tbl.convertColumnIndexToModel(c));
    265265                    }
     
    285285
    286286    private class DeleteFromHistoryAction extends AbstractAction {
    287         public DeleteFromHistoryAction() {
    288             super("", ImageProvider.get("dialogs","delete"));
     287        DeleteFromHistoryAction() {
     288            super("", ImageProvider.get("dialogs", "delete"));
    289289            putValue(SHORT_DESCRIPTION, tr("Delete from history"));
    290290        }
     
    305305
    306306    private class FindMatchingAction extends AbstractAction {
    307         public FindMatchingAction() {
    308             super("", ImageProvider.get("dialogs","search"));
     307        FindMatchingAction() {
     308            super("", ImageProvider.get("dialogs", "search"));
    309309            putValue(SHORT_DESCRIPTION, tr("Find primitives with these tags"));
    310310        }
     
    322322        public void itemStateChanged(ItemEvent e) {
    323323            // skip text-changing enevts, we need only combobox-selecting ones
    324             if (cbTagSet.getSelectedIndex()<0) return;
     324            if (cbTagSet.getSelectedIndex() < 0) return;
    325325            actionPerformed(null);
    326326        }
     
    329329        public void actionPerformed(ActionEvent e) {
    330330            String s = cbTagSet.getText();
    331             if (s==null || s.isEmpty() || s.equals(oldTags)) return;
     331            if (s == null || s.isEmpty() || s.equals(oldTags)) return;
    332332            oldTags = s;
    333333            cbTagSet.addCurrentItemToHistory();
     
    335335            specifyTagSet(s);
    336336        }
    337 
    338     };
     337    }
    339338
    340339    private void specifyTagSet(String s) {
     
    346345
    347346        tbl.getColumnModel().getColumn(0).setMaxWidth(20);
    348         for (int i=1; i<tableModel.getColumnCount(); i++) {
     347        for (int i = 1; i < tableModel.getColumnCount(); i++) {
    349348            TableHelper.adjustColumnWidth(tbl, i, 100);
    350349        }
     
    355354    class ColoredRenderer extends DefaultTableCellRenderer {
    356355        private final Color highlightColor =
    357                 Main.pref.getColor( marktr("Multitag Background: highlight"),
    358                         new Color(255,255,200));
     356                Main.pref.getColor(marktr("Multitag Background: highlight"),
     357                        new Color(255, 255, 200));
    359358        @Override
    360359        public Component getTableCellRendererComponent(JTable table, Object value, boolean
     
    362361            int row1 = tbl.convertRowIndexToModel(row);
    363362            JLabel label = (JLabel) super.getTableCellRendererComponent(
    364                 table, value, isSelected, hasFocus, row, column);
     363                    table, value, isSelected, hasFocus, row, column);
    365364            if (tbl.isRowSelected(row1) && !tbl.isColumnSelected(column)) {
    366365                label.setBackground(highlightColor);
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTaggerTableModel.java

    r32333 r32410  
    1 // License: GPL. Copyright 2013 by Alexei Kasatkin
    2 
     1// License: GPL. For details, see LICENSE file.
    32package org.openstreetmap.josm.plugins.utilsplugin2.multitagger;
    4 
    53
    64import java.util.ArrayList;
     
    2422import org.openstreetmap.josm.tools.Geometry;
    2523
    26 /**
    27  *
    28  */
    2924public class MultiTaggerTableModel extends AbstractTableModel implements SelectionChangedListener {
    3025
    3126    ArrayList<OsmPrimitive> list = new ArrayList<>(50);
    32     String mainTags[] = new String[]{};
    33     boolean isSpecialTag[] = new boolean[]{};
     27    String[] mainTags = new String[]{};
     28    boolean[] isSpecialTag = new boolean[]{};
    3429    Set<OsmPrimitiveType> shownTypes = new HashSet<>();
    3530    private boolean autoCommit = true;
     
    4136        Collections.addAll(shownTypes, OsmPrimitiveType.values());
    4237    }
    43    
     38
    4439    @Override
    4540    public int getRowCount() {
     
    5449    public void setWatchSelection(boolean watchSelection) {
    5550        this.watchSelection = watchSelection;
    56         if (watchSelection && Main.getLayerManager().getEditLayer() != null) 
     51        if (watchSelection && Main.getLayerManager().getEditLayer() != null)
    5752            selectionChanged(Main.getLayerManager().getEditDataSet().getSelected());
    5853    }
     
    6055    @Override
    6156    public Object getValueAt(int rowIndex, int columnIndex) {
    62         if (columnIndex==0) {
     57        if (columnIndex == 0) {
    6358            return list.get(rowIndex).getDisplayType();
    6459        }
     
    7166            return String.valueOf(p.getUniqueId());
    7267        } else if (var.equals("type")) {
    73             return OsmPrimitiveType.from(p).getAPIName().substring(0,1).toUpperCase();
     68            return OsmPrimitiveType.from(p).getAPIName().substring(0, 1).toUpperCase();
    7469        } else if (var.equals("area")) {
    7570            if (p.getDisplayType() == OsmPrimitiveType.CLOSEDWAY) {
     
    8277                return String.format("%.1f", ((Way) p).getLength());
    8378            }
    84         } 
     79        }
    8580        return "";
    8681    }
     
    8883    @Override
    8984    public Class<?> getColumnClass(int columnIndex) {
    90         if (columnIndex==0) {
     85        if (columnIndex == 0) {
    9186            return OsmPrimitiveType.class;
    9287        } else {
     
    9489        }
    9590    }
    96    
     91
    9792    @Override
    9893    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     
    10398    @Override
    10499    public boolean isCellEditable(int rowIndex, int columnIndex) {
    105         if (columnIndex==0) return false;
     100        if (columnIndex == 0) return false;
    106101        return !isSpecialTag[columnIndex-1];
    107102    }
     
    109104    @Override
    110105    public void setValueAt(Object value, int rowIndex, int columnIndex) {
    111         if (columnIndex==0 || isSpecialTag[columnIndex-1]) return;
     106        if (columnIndex == 0 || isSpecialTag[columnIndex-1]) return;
    112107        if (columnIndex >= getColumnCount() || rowIndex >= getRowCount()) return;
    113         if (value==null) value="";
     108        if (value == null) value = "";
    114109        String val = ((String) value).trim();
    115110        OsmPrimitive sel = list.get(rowIndex);
    116111        String key = mainTags[columnIndex-1];
    117112        String newValue = sel.get(key);
    118         if (newValue == null) newValue="";
     113        if (newValue == null) newValue = "";
    119114        if (!val.equals(newValue)) {
    120115            Command cmd = new ChangePropertyCommand(sel, key, (String) value);
     
    124119                cmds.add(cmd);
    125120            }
    126            
    127121        }
    128122    }
    129    
    130123
    131124    @Override
    132125    public String getColumnName(int column) {
    133         if (column==0) return "";
     126        if (column == 0) return "";
    134127        return mainTags[column-1];
    135128    }
    136    
     129
    137130    public OsmPrimitive getPrimitiveAt(int number) {
    138         if (number<0 || number>=list.size()) {
     131        if (number < 0 || number >= list.size()) {
    139132            return null;
    140133        } else {
     
    142135        }
    143136    }
    144    
     137
    145138    public void setupColumnsFromText(String txt) {
    146139        String[] tags = txt.trim().split("[\\s,]+");
    147140        mainTags = new String[tags.length];
    148141        isSpecialTag = new boolean[tags.length];
    149         int i=0;
     142        int i = 0;
    150143        for (String t: tags) {
    151144            if (t.startsWith("${") && t.endsWith("}")) {
     
    163156        StringBuilder sb = new StringBuilder();
    164157        boolean notFirst = false;
    165         for (int i=0; i<mainTags.length; i++) {
     158        for (int i = 0; i < mainTags.length; i++) {
    166159            if (!isSpecialTag[i]) {
    167                  if (notFirst) sb.append(" | ");
    168                  sb.append("\"");
    169                  sb.append(mainTags[i]);
    170                  sb.append("\":");
    171                  notFirst = true;
     160                if (notFirst) sb.append(" | ");
     161                sb.append("\"");
     162                sb.append(mainTags[i]);
     163                sb.append("\":");
     164                notFirst = true;
    172165            }
    173         };
     166        }
    174167        return sb.toString();
    175168    }
    176169
    177170    void updateData(Collection<? extends OsmPrimitive> sel) {
    178        if (table.isEditing()) table.getCellEditor().stopCellEditing();
    179        
    180        list.clear();
     171        if (table.isEditing()) table.getCellEditor().stopCellEditing();
     172
     173        list.clear();
    181174        for (OsmPrimitive p : sel) {
    182175            if (shownTypes.contains(p.getDisplayType())) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    25
    36import java.awt.event.ActionEvent;
     
    69import java.util.Collection;
    710import java.util.List;
     11
    812import javax.swing.JOptionPane;
     13
    914import org.openstreetmap.josm.Main;
    1015import org.openstreetmap.josm.actions.JosmAction;
    1116import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1217import org.openstreetmap.josm.gui.Notification;
    13 import static org.openstreetmap.josm.tools.I18n.tr;
    1418import org.openstreetmap.josm.tools.Shortcut;
    1519
     
    2428    public ReplaceGeometryAction() {
    2529        super(TITLE, "dumbutils/replacegeometry", tr("Replace geometry of selected object with a new one"),
    26                 Shortcut.registerShortcut("tools:replacegeometry", tr("Tool: {0}", tr("Replace Geometry")), KeyEvent.VK_G, Shortcut.CTRL_SHIFT)
    27                 , true);
     30                Shortcut.registerShortcut("tools:replacegeometry", tr("Tool: {0}", tr("Replace Geometry")), KeyEvent.VK_G, Shortcut.CTRL_SHIFT),
     31                true);
    2832    }
    2933
     
    3943            new Notification(
    4044                    tr("This tool replaces geometry of one object with another, and so requires exactly two objects to be selected.")
    41                 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 
     45                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    4246            return;
    4347        }
     
    4549        OsmPrimitive firstObject = selection.get(0);
    4650        OsmPrimitive secondObject = selection.get(1);
    47        
     51
    4852        try {
    4953            ReplaceGeometryCommand replaceCommand =
    5054                    ReplaceGeometryUtils.buildReplaceWithNewCommand(firstObject, secondObject);
    51            
     55
    5256            // action was canceled
    5357            if (replaceCommand == null)
    5458                return;
    55            
     59
    5660            Main.main.undoRedo.add(replaceCommand);
    5761        } catch (IllegalArgumentException ex) {
    5862            new Notification(
    59                 ex.getMessage()
    60             ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     63                    ex.getMessage()
     64                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    6165        } catch (ReplaceGeometryException ex) {
    6266            new Notification(
    63                 ex.getMessage()
    64             ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     67                    ex.getMessage()
     68                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    6569        }
    6670    }
     
    7276
    7377    @Override
    74     protected void updateEnabledState( Collection<? extends OsmPrimitive> selection ) {
    75         setEnabled(selection != null && selection.size() >= 2 );
     78    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
     79        setEnabled(selection != null && selection.size() >= 2);
    7680    }
    7781}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryCommand.java

    r28335 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry;
    23
    34import java.util.Collection;
     5
    46import javax.swing.Icon;
     7
    58import org.openstreetmap.josm.command.Command;
    69import org.openstreetmap.josm.command.SequenceCommand;
     
    912/**
    1013 * Command to replace the geometry of one object with another.
    11  * 
     14 *
    1215 * @author joshdoe
    1316 */
    1417public class ReplaceGeometryCommand extends SequenceCommand {
    1518    private final String description;
    16    
     19
    1720    public ReplaceGeometryCommand(String description, Collection<Command> sequence) {
    1821        super(description, sequence);
     
    2427        return description;
    2528    }
    26    
     29
    2730    @Override
    2831    public Icon getDescriptionIcon() {
    2932        return ImageProvider.get("dumbutils", "replacegeometry");
    3033    }
    31    
     34
    3235}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryException.java

    r28335 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry;
    23
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry;
    23
     
    4344 */
    4445public final class ReplaceGeometryUtils {
     46
     47    private ReplaceGeometryUtils() {
     48        // Hide default constructor for utilities classes
     49    }
     50
    4551    /**
    4652     * Replace new or uploaded object with new object
    47      *
    48      * @param firstObject
    49      * @param secondObject
    50      * @return
    5153     */
    5254    public static ReplaceGeometryCommand buildReplaceWithNewCommand(OsmPrimitive firstObject, OsmPrimitive secondObject) {
     
    6062            return buildUpgradeNodeCommand((Node) secondObject, firstObject);
    6163        } else {
    62             throw new IllegalArgumentException(tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way."));
    63         }
    64     }
    65    
     64            throw new IllegalArgumentException(
     65                    tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way."));
     66        }
     67    }
     68
    6669    /**
    6770     * Replace subjectObject geometry with referenceObject geometry and merge tags
    6871     * and relation memberships.
    69      *
    70      * @param subjectObject
    71      * @param referenceSubject
    72      * @return
    7372     */
    7473    public static ReplaceGeometryCommand buildReplaceCommand(OsmPrimitive subjectObject, OsmPrimitive referenceSubject) {
     
    8382            return buildUpgradeNodeCommand((Node) referenceSubject, subjectObject);
    8483        } else {
    85             throw new IllegalArgumentException(tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way."));
     84            throw new IllegalArgumentException(
     85                    tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way."));
    8686        }
    8787    }
     
    8989    /**
    9090     * Replace a new or uploaded node with a new node
    91      * @param firstNode
    92      * @param secondNode
    93      * @return
    9491     */
    9592    public static ReplaceGeometryCommand buildReplaceNodeWithNewCommand(Node firstNode, Node secondNode) {
     
    103100            return buildReplaceNodeCommand(firstNode, secondNode);
    104101    }
    105    
     102
    106103    /**
    107104     * Replace a node with another node (similar to MergeNodesAction)
    108      *
    109      * @param subjectNode
    110      * @param referenceNode
    111      * @return
    112105     */
    113106    public static ReplaceGeometryCommand buildReplaceNodeCommand(Node subjectNode, Node referenceNode) {
     
    128121                commands);
    129122    }
    130    
     123
    131124    /**
    132125     * Upgrade a node to a way or multipolygon
     
    167160
    168161        List<Command> commands = new ArrayList<>();
    169         AbstractMap<String, String> nodeTags = (AbstractMap<String, String>) subjectNode.getKeys();
     162        AbstractMap<String, String> nodeTags = subjectNode.getKeys();
    170163
    171164        // merge tags
     
    210203                commands);
    211204    }
    212    
     205
    213206    public static ReplaceGeometryCommand buildReplaceWayWithNewCommand(List<Way> selection) {
    214207        // determine which way will be replaced and which will provide the geometry
    215208        boolean overrideNewCheck = false;
    216209        int idxNew = selection.get(0).isNew() ? 0 : 1;
    217         if( selection.get(1-idxNew).isNew() ) {
     210        if (selection.get(1-idxNew).isNew()) {
    218211            // if both are new, select the one with all the DB nodes
    219212            boolean areNewNodes = false;
     
    233226        Way referenceWay = selection.get(idxNew);
    234227        Way subjectWay = selection.get(1 - idxNew);
    235        
    236         if( !overrideNewCheck && (subjectWay.isNew() || !referenceWay.isNew()) ) {
     228
     229        if (!overrideNewCheck && (subjectWay.isNew() || !referenceWay.isNew())) {
    237230            throw new ReplaceGeometryException(
    238231                    tr("Please select one way that exists in the database and one new way with correct geometry."));
     
    240233        return buildReplaceWayCommand(subjectWay, referenceWay);
    241234    }
    242    
     235
    243236    public static ReplaceGeometryCommand buildReplaceWayCommand(Way subjectWay, Way referenceWay) {
    244237
     
    247240            throw new ReplaceGeometryException(tr("The ways must be entirely within the downloaded area."));
    248241        }
    249        
     242
    250243        if (hasImportantNode(referenceWay, subjectWay)) {
    251244            throw new ReplaceGeometryException(
     
    254247
    255248        List<Command> commands = new ArrayList<>();
    256                
     249
    257250        // merge tags
    258251        try {
     
    263256            return null;
    264257        }
    265        
     258
    266259        // Prepare a list of nodes that are not used anywhere except in the way
    267260        List<Node> nodePool = getUnimportantNodes(subjectWay);
     
    269262        // And the same for geometry, list nodes that can be freely deleted
    270263        List<Node> geometryPool = new LinkedList<>();
    271         for( Node node : referenceWay.getNodes() ) {
     264        for (Node node : referenceWay.getNodes()) {
    272265            List<OsmPrimitive> referrers = node.getReferrers();
    273             if( node.isNew() && !node.isDeleted() && referrers.size() == 1
     266            if (node.isNew() && !node.isDeleted() && referrers.size() == 1
    274267                    && referrers.get(0).equals(referenceWay) && !subjectWay.containsNode(node)
    275268                    && !hasInterestingKey(node) && !geometryPool.contains(node))
     
    278271
    279272        boolean useRobust = Main.pref.getBoolean("utilsplugin2.replace-geometry.robustAssignment", true);
    280        
     273
    281274        // Find new nodes that are closest to the old ones, remove matching old ones from the pool
    282275        // Assign node moves with least overall distance moved
     
    287280                int nLen = nodePool.size();
    288281                int N = Math.max(gLen, nLen);
    289                 double cost[][] = new double[N][N];
     282                double[][] cost = new double[N][N];
    290283                for (int i = 0; i < N; i++) {
    291284                    for (int j = 0; j < N; j++) {
     
    319312                        nodePool.remove(n);
    320313                    }
    321                 }
    322                 catch (Exception e) {
     314                } catch (Exception e) {
    323315                    useRobust = false;
    324316                    new Notification(
    325                         tr("Exceeded iteration limit for robust method, using simpler method.")
    326                     ).setIcon(JOptionPane.WARNING_MESSAGE).show();     
     317                            tr("Exceeded iteration limit for robust method, using simpler method.")
     318                            ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    327319                    nodeAssoc = new HashMap<>();
    328320                }
     
    341333
    342334        // Now that we have replacement list, move all unused new nodes to nodePool (and delete them afterwards)
    343         for( Node n : geometryPool )
    344             if( nodeAssoc.containsKey(n) )
     335        for (Node n : geometryPool) {
     336            if (nodeAssoc.containsKey(n))
    345337                nodePool.add(n);
     338        }
    346339
    347340        // And prepare a list of nodes with all the replacements
    348341        List<Node> geometryNodes = referenceWay.getNodes();
    349         for( int i = 0; i < geometryNodes.size(); i++ )
    350             if( nodeAssoc.containsKey(geometryNodes.get(i)) )
     342        for (int i = 0; i < geometryNodes.size(); i++) {
     343            if (nodeAssoc.containsKey(geometryNodes.get(i)))
    351344                geometryNodes.set(i, nodeAssoc.get(geometryNodes.get(i)));
     345        }
    352346
    353347        // Now do the replacement
     
    355349
    356350        // Move old nodes to new positions
    357         for( Node node : nodeAssoc.keySet() )
     351        for (Node node : nodeAssoc.keySet()) {
    358352            commands.add(new MoveCommand(nodeAssoc.get(node), node.getCoor()));
     353        }
    359354
    360355        // Remove geometry way from selection
     
    365360
    366361        // Delete nodes that are not used anymore
    367         if( !nodePool.isEmpty() )
     362        if (!nodePool.isEmpty())
    368363            commands.add(new DeleteCommand(nodePool));
    369364
     
    376371    /**
    377372     * Create a list of nodes that are not used anywhere except in the way.
    378      *
    379      * @param way
    380      * @return
    381373     */
    382374    protected static List<Node> getUnimportantNodes(Way way) {
     
    391383        return nodePool;
    392384    }
    393    
     385
    394386    /**
    395387     * Checks if a way has at least one important node (e.g. interesting tag,
    396388     * role membership), and thus cannot be safely modified.
    397      *
    398      * @param way
    399      * @return
    400389     */
    401390    protected static boolean hasImportantNode(Way geometry, Way way) {
     
    417406        return false;
    418407    }
    419    
     408
    420409    protected static boolean hasInterestingKey(OsmPrimitive object) {
    421410        for (String key : object.getKeys().keySet()) {
     
    434423        return false;
    435424    }
    436    
     425
    437426    protected static boolean isInArea(Way way, Area area) {
    438427        if (area == null) {
     
    448437        return true;
    449438    }
    450    
    451      /**
     439
     440    /**
    452441     * Merge tags from source to target object, showing resolution dialog if
    453442     * needed.
     
    464453                TagCollection.unionOfAllPrimitives(primitives), primitives, Collections.singleton(target));
    465454    }
    466    
     455
    467456    /**
    468457     * Find node from the collection which is nearest to <tt>node</tt>. Max distance is taken in consideration.
    469458     * @return null if there is no such node.
    470459     */
    471     protected static Node findNearestNode( Node node, Collection<Node> nodes ) {
    472         if( nodes.contains(node) )
     460    protected static Node findNearestNode(Node node, Collection<Node> nodes) {
     461        if (nodes.contains(node))
    473462            return node;
    474        
     463
    475464        Node nearest = null;
    476465        // TODO: use meters instead of degrees, but do it fast
     
    478467        LatLon coor = node.getCoor();
    479468
    480         for( Node n : nodes ) {
     469        for (Node n : nodes) {
    481470            double d = n.getCoor().distance(coor);
    482             if( d < distance ) {
     471            if (d < distance) {
    483472                distance = d;
    484473                nearest = n;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceMembershipAction.java

    r32333 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry;
    23
     
    5051                    secondObject.getDisplayName(DefaultNameFormatter.getInstance()),
    5152                    affectedRelations
    52             )).setIcon(JOptionPane.INFORMATION_MESSAGE).show();
     53                    )).setIcon(JOptionPane.INFORMATION_MESSAGE).show();
    5354        } else {
    5455            new Notification(tr("The first selected object ''{0}'' is not part of any relation",
    5556                    firstObject.getDisplayName(DefaultNameFormatter.getInstance())
    56             )).setIcon(JOptionPane.WARNING_MESSAGE).show();
     57                    )).setIcon(JOptionPane.WARNING_MESSAGE).show();
    5758        }
    5859    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ChildrenMatch.java

    r30389 r32410  
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.plugins.utilsplugin2.search;
    13
    2 package org.openstreetmap.josm.plugins.utilsplugin2.search;
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import org.openstreetmap.josm.actions.search.PushbackTokenizer;
     
    79import org.openstreetmap.josm.data.osm.Relation;
    810import org.openstreetmap.josm.data.osm.Way;
    9 import static org.openstreetmap.josm.tools.I18n.tr;
    1011
    1112/**
     
    1314 */
    1415public class ChildrenMatch extends RangeMatch {
    15     public ChildrenMatch(PushbackTokenizer.Range range) {super(range);}
     16    public ChildrenMatch(PushbackTokenizer.Range range) {
     17        super(range);
     18    }
     19
    1620    public ChildrenMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
    1721        this(tokenizer.readRange(tr("Range of child primitives count")));
    1822    }
    1923
    20     @Override 
     24    @Override
    2125    protected Long getNumber(OsmPrimitive osm) {
    2226        if (osm instanceof Way) {
    23             return (long) ((Way)osm).getNodesCount();
     27            return (long) ((Way) osm).getNodesCount();
    2428        } else if (osm instanceof Relation) {
    25             return (long) ((Relation)osm).getMembersCount();
     29            return (long) ((Relation) osm).getMembersCount();
    2630        } else {
    2731            return null;
     
    2933    }
    3034
    31     @Override 
     35    @Override
    3236    protected String getString() {
    3337        return "children";
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java

    r32333 r32410  
    1 // License: GPL v2 or later. See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.search;
    33
     
    55import java.util.HashSet;
    66import java.util.Set;
     7
    78import org.openstreetmap.josm.Main;
    89import org.openstreetmap.josm.actions.search.SearchCompiler;
     
    1112import org.openstreetmap.josm.data.osm.Way;
    1213import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils;
    13 
    1414
    1515/**
     
    6262        }
    6363        if (osm instanceof Way) {
    64             return connected.contains((Way) osm);
     64            return connected.contains(osm);
    6565        }
    6666        return false;
    6767    }
    68    
     68
    6969}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java

    r32333 r32410  
    1 /*
    2  * To change this license header, choose License Headers in Project Properties.
    3  * To change this template file, choose Tools | Templates
    4  * and open the template in the editor.
    5  */
    6 
     1// License: GPL. For details, see LICENSE file.
    72package org.openstreetmap.josm.plugins.utilsplugin2.search;
    83
    94import java.util.Collection;
    105import java.util.HashSet;
     6
    117import org.openstreetmap.josm.Main;
    128import org.openstreetmap.josm.actions.search.SearchCompiler;
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java

    r32333 r32410  
    1 // License: GPL v2 or later. See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.search;
    33
     
    55import java.util.HashSet;
    66import java.util.Set;
     7
    78import org.openstreetmap.josm.Main;
    89import org.openstreetmap.josm.actions.search.SearchCompiler;
     
    1213
    1314/**
    14 * Find (all) ways intersecting ways or nodes which match the expression.
    15 */
     15 * Find (all) ways intersecting ways or nodes which match the expression.
     16 */
    1617public class IntersectingMatch extends SearchCompiler.UnaryMatch {
    1718    private Collection<Way> intersecting = null;
     
    5152        }
    5253        if (osm instanceof Way) {
    53             return intersecting.contains((Way) osm);
     54            return intersecting.contains(osm);
    5455        }
    5556        return false;
    5657    }
    57    
     58
    5859}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ParentsMatch.java

    r30389 r32410  
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.plugins.utilsplugin2.search;
    13
    2 package org.openstreetmap.josm.plugins.utilsplugin2.search;
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import org.openstreetmap.josm.actions.search.PushbackTokenizer;
    57import org.openstreetmap.josm.actions.search.SearchCompiler;
    68import org.openstreetmap.josm.data.osm.OsmPrimitive;
    7 import static org.openstreetmap.josm.tools.I18n.tr;
    89
    910/**
     
    1112 */
    1213public class ParentsMatch extends RangeMatch {
    13     public ParentsMatch(PushbackTokenizer.Range range) {super(range);}
     14    public ParentsMatch(PushbackTokenizer.Range range) {
     15        super(range);
     16    }
     17
    1418    public ParentsMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
    1519        this(tokenizer.readRange(tr("Range of parent primitives count")));
    1620    }
    17     @Override
     21
     22    @Override
    1823    protected Long getNumber(OsmPrimitive osm) {
    1924        return new Long(osm.getReferrers().size());
    2025    }
    21     @Override
     26
     27    @Override
    2228    protected String getString() {
    2329        return "parents";
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/RangeMatch.java

    r30384 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.search;
    23
     
    1011public abstract class RangeMatch extends SearchCompiler.Match {
    1112
    12         private final long min;
    13         private final long max;
     13    private final long min;
     14    private final long max;
    1415
    15         public RangeMatch(long min, long max) {
    16             this.min = Math.min(min, max);
    17             this.max = Math.max(min, max);
    18         }
    19 
    20         public RangeMatch(PushbackTokenizer.Range range) {
    21             this(range.getStart(), range.getEnd());
    22         }
    23 
    24         protected abstract Long getNumber(OsmPrimitive osm);
    25 
    26         protected abstract String getString();
    27 
    28         @Override
    29         public boolean match(OsmPrimitive osm) {
    30             Long num = getNumber(osm);
    31             if (num == null)
    32                 return false;
    33             else
    34                 return (num >= min) && (num <= max);
    35         }
    36 
    37         @Override
    38         public String toString() {
    39             return getString() + "=" + min + "-" + max;
    40         }
     16    public RangeMatch(long min, long max) {
     17        this.min = Math.min(min, max);
     18        this.max = Math.max(min, max);
    4119    }
    4220
     21    public RangeMatch(PushbackTokenizer.Range range) {
     22        this(range.getStart(), range.getEnd());
     23    }
     24
     25    protected abstract Long getNumber(OsmPrimitive osm);
     26
     27    protected abstract String getString();
     28
     29    @Override
     30    public boolean match(OsmPrimitive osm) {
     31        Long num = getNumber(osm);
     32        if (num == null)
     33            return false;
     34        else
     35            return (num >= min) && (num <= max);
     36    }
     37
     38    @Override
     39    public String toString() {
     40        return getString() + "=" + min + "-" + max;
     41    }
     42}
     43
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInRelationsMatch.java

    r30389 r32410  
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.plugins.utilsplugin2.search;
    13
    2 package org.openstreetmap.josm.plugins.utilsplugin2.search;
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import org.openstreetmap.josm.actions.search.PushbackTokenizer;
     
    1012import org.openstreetmap.josm.data.osm.Way;
    1113import org.openstreetmap.josm.data.osm.visitor.Visitor;
    12 import static org.openstreetmap.josm.tools.I18n.tr;
    1314
    1415/**
     
    1617 */
    1718public class UsedInRelationsMatch extends RangeMatch {
    18     public UsedInRelationsMatch(PushbackTokenizer.Range range) {super(range);}
     19    public UsedInRelationsMatch(PushbackTokenizer.Range range) {
     20        super(range);
     21    }
     22
    1923    public UsedInRelationsMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
    2024        this(tokenizer.readRange(tr("Range of referencing relation count")));
    2125    }
     26
    2227    private class RelationCounter implements Visitor {
    2328        int count;
    2429        @Override
    25         public void visit(Way w) {  }
    26         @Override   public void visit(Node n) { }
    27         @Override   public void visit(Relation r) { count++;  }
    28         @Override   public void visit(Changeset cs) {   }
     30        public void visit(Way w) {
     31            // Do nothing
     32        }
     33
     34        @Override
     35        public void visit(Node n) {
     36            // Do nothing
     37        }
     38
     39        @Override
     40        public void visit(Relation r) {
     41            count++;
     42        }
     43
     44        @Override
     45        public void visit(Changeset cs) {
     46            // Do nothing
     47        }
    2948    }
     49
    3050    RelationCounter counter = new RelationCounter();
    3151
    32     @Override 
     52    @Override
    3353    protected Long getNumber(OsmPrimitive osm) {
    34         counter.count=0;
     54        counter.count = 0;
    3555        osm.visitReferrers(counter);
    3656        return new Long(counter.count);
    3757    }
    38     @Override
     58
     59    @Override
    3960    protected String getString() {
    4061        return "usedinrelations";
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UsedInWaysMatch.java

    r30389 r32410  
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.plugins.utilsplugin2.search;
    13
    2 package org.openstreetmap.josm.plugins.utilsplugin2.search;
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import org.openstreetmap.josm.actions.search.PushbackTokenizer;
     
    1012import org.openstreetmap.josm.data.osm.Way;
    1113import org.openstreetmap.josm.data.osm.visitor.Visitor;
    12 import static org.openstreetmap.josm.tools.I18n.tr;
    1314
    1415/**
     
    1617 */
    1718public class UsedInWaysMatch extends RangeMatch {
    18     public UsedInWaysMatch(PushbackTokenizer.Range range) {super(range);}
     19    public UsedInWaysMatch(PushbackTokenizer.Range range) {
     20        super(range);
     21    }
     22
    1923    public UsedInWaysMatch(PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
    2024        this(tokenizer.readRange(tr("Range of attached ways count")));
    2125    }
     26
    2227    private class WayCounter implements Visitor {
    2328        int count;
    2429        @Override
    25         public void visit(Way w) { count++; }
    26         @Override   public void visit(Node n) { }
    27         @Override   public void visit(Relation r) {   }
    28         @Override   public void visit(Changeset cs) {   }
     30        public void visit(Way w) {
     31            count++;
     32        }
     33
     34        @Override
     35        public void visit(Node n) {
     36            // Do nothing
     37        }
     38
     39        @Override
     40        public void visit(Relation r) {
     41            // Do nothing
     42        }
     43
     44        @Override
     45        public void visit(Changeset cs) {
     46            // Do nothing
     47        }
    2948    }
     49
    3050    WayCounter counter = new WayCounter();
    3151
    32 @Override protected Long getNumber(OsmPrimitive osm) {
     52    @Override protected Long getNumber(OsmPrimitive osm) {
    3353        if (osm instanceof Node) {
    34             counter.count=0;
     54            counter.count = 0;
    3555            osm.visitReferrers(counter);
    3656            return new Long(counter.count);
    3757        } else return null;
    3858    }
     59
    3960    @Override protected String getString() {
    4061        return "wayrefs";
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsSimpleMatchFactory.java

    r30389 r32410  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.utilsplugin2.search;
    23
    34import java.util.Arrays;
    45import java.util.Collection;
     6
    57import org.openstreetmap.josm.actions.search.PushbackTokenizer;
    68import org.openstreetmap.josm.actions.search.SearchCompiler;
     
    810
    911public class UtilsSimpleMatchFactory implements SimpleMatchFactory {
    10    
     12
    1113    private static Collection<String> keywords = Arrays.asList("usedinways", "usedinrelations", "parents", "children");
    1214
     
    2022        if ("usedinways".equals(keyword)) {
    2123            return new UsedInWaysMatch(tokenizer);
    22         } else
    23         if ("usedinrelations".equals(keyword)) {
    24             return new UsedInRelationsMatch(tokenizer);
    25         } else
    26         if ("parents".equals(keyword)) {
    27             return new ParentsMatch(tokenizer);
    2824        } else
    29         if ("children".equals(keyword)) {
    30             return new ChildrenMatch(tokenizer);
    31         } else
    32             return null;
    33     };
    34    
     25            if ("usedinrelations".equals(keyword)) {
     26                return new UsedInRelationsMatch(tokenizer);
     27            } else
     28                if ("parents".equals(keyword)) {
     29                    return new ParentsMatch(tokenizer);
     30                } else
     31                    if ("children".equals(keyword)) {
     32                        return new ChildrenMatch(tokenizer);
     33                    } else
     34                        return null;
     35    }
    3536}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsUnaryMatchFactory.java

    r30384 r32410  
    1 // License: GPL v2 or later. See LICENSE file for details.
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.search;
    33
    44import java.util.Arrays;
    55import java.util.Collection;
     6
    67import org.openstreetmap.josm.actions.search.PushbackTokenizer;
    78import org.openstreetmap.josm.actions.search.SearchCompiler;
     
    1314
    1415    @Override
    15     public SearchCompiler.UnaryMatch get(String keyword, SearchCompiler.Match matchOperand, PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
     16    public SearchCompiler.UnaryMatch get(String keyword, SearchCompiler.Match matchOperand, PushbackTokenizer tokenizer)
     17            throws SearchCompiler.ParseError {
    1618        if ("inside".equals(keyword)) {
    1719            return new InsideMatch(matchOperand);
     
    2426        } else if ("allintersecting".equals(keyword)) {
    2527            return new IntersectingMatch(matchOperand, true);
    26         } 
     28        }
    2729        return null;
    2830    }
     
    3234        return keywords;
    3335    }
    34 
    3536}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentNodesAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    1010import java.util.HashSet;
    1111import java.util.Set;
     12
    1213import org.openstreetmap.josm.actions.JosmAction;
    13 import org.openstreetmap.josm.data.osm.*;
    14 
     14import org.openstreetmap.josm.data.osm.DataSet;
     15import org.openstreetmap.josm.data.osm.Node;
     16import org.openstreetmap.josm.data.osm.OsmPrimitive;
     17import org.openstreetmap.josm.data.osm.Way;
    1518import org.openstreetmap.josm.tools.Shortcut;
    1619
    1720/**
    18  *    Extends current selection
     21 * Extends current selection
    1922 */
    2023public class AdjacentNodesAction extends JosmAction {
     
    2427    public AdjacentNodesAction() {
    2528        super(tr("Adjacent nodes"), "adjnodes", tr("Select adjacent nodes"),
    26                 Shortcut.registerShortcut("tools:adjnodes", tr("Tool: {0}","Adjacent nodes"),
    27                 KeyEvent.VK_E, Shortcut.DIRECT), true);
     29                Shortcut.registerShortcut("tools:adjnodes", tr("Tool: {0}", "Adjacent nodes"),
     30                        KeyEvent.VK_E, Shortcut.DIRECT), true);
    2831        putValue("help", ht("/Action/AdjacentNodes"));
    2932    }
    3033
    31     private  Set<Way> activeWays = new HashSet<>();
     34    private Set<Way> activeWays = new HashSet<>();
    3235
    3336    @Override
     
    3841
    3942        Set<Way> selectedWays = OsmPrimitive.getFilteredSet(ds.getSelected(), Way.class);
    40        
     43
    4144        // if no nodes and no ways are selected, do nothing
    4245        if (selectedNodes.isEmpty() && selectedWays.isEmpty()) return;
     
    5053            if (selectedNodes.size() == 1) {
    5154                activeWays.clear();
    52 //                System.out.println("Cleared active ways");
     55                //                System.out.println("Cleared active ways");
    5356            }
    5457        } else {
     
    5861
    5962        // selecting nodes of selected ways
    60         if(selectedNodes.isEmpty()) {
     63        if (selectedNodes.isEmpty()) {
    6164            HashSet<Node> newNodes = new HashSet<>();
    6265            NodeWayUtils.addNodesConnectedToWays(selectedWays, newNodes);
     
    7073        }
    7174
    72         Set<Node> newNodes = new HashSet <>();
     75        Set<Node> newNodes = new HashSet<>();
    7376        for (Node node: selectedNodes) {
    7477            for (Way w: activeWays) {
     
    7679            }
    7780        }
    78        
     81
    7982        // select only newly found nodes
    80          newNodes.removeAll(selectedNodes);
     83        newNodes.removeAll(selectedNodes);
    8184
    82 //         System.out.printf("Found %d new nodes\n",newNodes.size());
    83          
    84          // enable branching on next call of this function
    85          // if no new nodes were found, next search will include all touched ways
    86          if (newNodes.isEmpty()) {
    87              activeWays.clear();
    88 //             System.out.println("No more points found, activeways cleared");
    89          }
     85        // enable branching on next call of this function
     86        // if no new nodes were found, next search will include all touched ways
     87        if (newNodes.isEmpty()) {
     88            activeWays.clear();
     89        }
    9090
    91          ds.addSelected(newNodes);
     91        ds.addSelected(newNodes);
    9292    }
    9393
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentWaysAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    1010import java.util.HashSet;
    1111import java.util.Set;
     12
    1213import org.openstreetmap.josm.actions.JosmAction;
    13 import org.openstreetmap.josm.data.osm.*;
    14 
     14import org.openstreetmap.josm.data.osm.DataSet;
     15import org.openstreetmap.josm.data.osm.Node;
     16import org.openstreetmap.josm.data.osm.OsmPrimitive;
     17import org.openstreetmap.josm.data.osm.Way;
    1518import org.openstreetmap.josm.tools.Shortcut;
    1619
    1720/**
    18  *    Extends current selection
     21 * Extends current selection
    1922 */
    2023public class AdjacentWaysAction extends JosmAction {
     
    2528        super(tr("Adjacent ways"), "adjways",
    2629                tr("Adjacent ways will be selected. Nodes will be deselected."),
    27                 Shortcut.registerShortcut("tools:adjways", tr("Tool: {0}","Adjacent ways"),
    28                 KeyEvent.VK_E, Shortcut.SHIFT), true);
     30                Shortcut.registerShortcut("tools:adjways", tr("Tool: {0}", "Adjacent ways"),
     31                        KeyEvent.VK_E, Shortcut.SHIFT), true);
    2932        putValue("help", ht("/Action/AdjacentWays"));
    3033    }
     
    4447
    4548        // selecting ways attached to selected nodes
    46         if(!selectedNodes.isEmpty()) {
     49        if (!selectedNodes.isEmpty()) {
    4750            NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays);
    4851        }
    4952
    50 //        System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size());
     53        //        System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size());
    5154        ds.setSelected(newWays);
    5255    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/ConnectedWaysAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    1010import java.util.HashSet;
    1111import java.util.Set;
     12
    1213import org.openstreetmap.josm.actions.JosmAction;
    13 import org.openstreetmap.josm.data.osm.*;
    14 
     14import org.openstreetmap.josm.data.osm.DataSet;
     15import org.openstreetmap.josm.data.osm.Node;
     16import org.openstreetmap.josm.data.osm.OsmPrimitive;
     17import org.openstreetmap.josm.data.osm.Way;
    1518import org.openstreetmap.josm.tools.Shortcut;
    1619
    1720/**
    18  *    Extends current selection by selecting nodes on all touched ways
     21 * Extends current selection by selecting nodes on all touched ways
    1922 */
    2023public class ConnectedWaysAction extends JosmAction {
     
    2225    public ConnectedWaysAction() {
    2326        super(tr("All connected ways"), "adjwaysall", tr("Select all connected ways"),
    24                 Shortcut.registerShortcut("tools:adjwaysall", tr("Tool: {0}","All connected ways"),
    25                 KeyEvent.VK_E, Shortcut.CTRL_SHIFT), true);
     27                Shortcut.registerShortcut("tools:adjwaysall", tr("Tool: {0}", "All connected ways"),
     28                        KeyEvent.VK_E, Shortcut.CTRL_SHIFT), true);
    2629        putValue("help", ht("/Action/SelectConnectedWays"));
    2730    }
     
    3740
    3841        // selecting ways attached to selected nodes
    39         if(!selectedNodes.isEmpty()) {
     42        if (!selectedNodes.isEmpty()) {
    4043            NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays);
    4144        }
     
    4447        newWays.addAll(selectedWays);
    4548        NodeWayUtils.addWaysConnectedToWaysRecursively(selectedWays, newWays);
    46        
    47 //        System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size());
     49
    4850        ds.setSelected(newWays);
    4951    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    2121
    2222/**
    23  *    Extends current selection by selecting nodes on all touched ways
     23 * Extends current selection by selecting nodes on all touched ways
    2424 */
    2525public class IntersectedWaysAction extends JosmAction {
     
    2727    public IntersectedWaysAction() {
    2828        super(tr("Intersecting ways"), "intway", tr("Select intersecting ways"),
    29                 Shortcut.registerShortcut("tools:intway", tr("Tool: {0}","Intersecting ways"),
    30                 KeyEvent.VK_I, Shortcut.DIRECT), true);
     29                Shortcut.registerShortcut("tools:intway", tr("Tool: {0}", "Intersecting ways"),
     30                        KeyEvent.VK_I, Shortcut.DIRECT), true);
    3131        putValue("help", ht("/Action/SelectIntersectingWays"));
    3232    }
     
    4646            return;
    4747        } else {
    48              new Notification(
    49                tr("Please select some ways to find connected and intersecting ways!")
    50                ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     48            new Notification(
     49                    tr("Please select some ways to find connected and intersecting ways!")
     50                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    5151        }
    5252    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysRecursiveAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin ond others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    2121
    2222/**
    23  *    Extends current selection by selecting nodes on all touched ways
     23 * Extends current selection by selecting nodes on all touched ways
    2424 */
    2525public class IntersectedWaysRecursiveAction extends JosmAction {
    26    
     26
    2727    public IntersectedWaysRecursiveAction() {
    2828        super(tr("All intersecting ways"), "intwayall", tr("Select all intersecting ways"),
    29                 Shortcut.registerShortcut("tools:intwayall", tr("Tool: {0}","All intersecting ways"),
    30                 KeyEvent.VK_MULTIPLY, Shortcut.CTRL), true);
     29                Shortcut.registerShortcut("tools:intwayall", tr("Tool: {0}", "All intersecting ways"),
     30                        KeyEvent.VK_MULTIPLY, Shortcut.CTRL), true);
    3131        putValue("help", ht("/Action/SelectAllIntersectingWays"));
    3232
     
    4545            ds.addSelected(newWays);
    4646        } else {
    47               new Notification(
    48                 tr("Please select some ways to find all connected and intersecting ways!")
    49                 ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     47            new Notification(
     48                    tr("Please select some ways to find all connected and intersecting ways!")
     49                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    5050        }
    5151    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/MiddleNodesAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    2020
    2121/**
    22  *    Selects nodes between two selected
     22 * Selects nodes between two selected
    2323 */
    2424public class MiddleNodesAction extends JosmAction {
     
    2828    public MiddleNodesAction() {
    2929        super(tr("Middle nodes"), "midnodes", tr("Select middle nodes"),
    30                 Shortcut.registerShortcut("tools:midnodes", tr("Tool: {0}","Middle nodes"),
    31                 KeyEvent.VK_E,  Shortcut.ALT_SHIFT), true);
     30                Shortcut.registerShortcut("tools:midnodes", tr("Tool: {0}", "Middle nodes"), KeyEvent.VK_E, Shortcut.ALT_SHIFT), true);
    3231        putValue("help", ht("/Action/MiddleNodes"));
    3332    }
     
    4140        if (selectedNodes.size() != 2) {
    4241            new Notification(
    43                 tr("Please select two nodes connected by way!")
    44             ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     42                    tr("Please select two nodes connected by way!")
     43                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    4544            return;
    4645        }
    4746
    48         Set<Node> newNodes = new HashSet <>();
     47        Set<Node> newNodes = new HashSet<>();
    4948        NodeWayUtils.addMiddle(selectedNodes, newNodes);
    50        
     49
    5150        // select only newly found nodes
    5251        newNodes.removeAll(selectedNodes);
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/NodeWayUtils.java

    r30737 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
    4 import org.openstreetmap.josm.data.osm.Relation;
     4import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.util.ArrayList;
    7 import java.util.Iterator;
    87import java.util.Collection;
    98import java.util.HashSet;
     9import java.util.Iterator;
    1010import java.util.List;
    1111import java.util.Set;
     
    1919import org.openstreetmap.josm.data.osm.Node;
    2020import org.openstreetmap.josm.data.osm.OsmPrimitive;
     21import org.openstreetmap.josm.data.osm.Relation;
    2122import org.openstreetmap.josm.data.osm.Way;
    2223import org.openstreetmap.josm.gui.Notification;
    2324import org.openstreetmap.josm.tools.Geometry;
    24 
    25 import static org.openstreetmap.josm.tools.I18n.tr;
    26 
    2725import org.openstreetmap.josm.tools.Pair;
    28 
    29 
    3026
    3127/**
     
    3834    static final int maxWays = Main.pref.getInteger("selection.maxfoundways", 2000);
    3935    static final int maxWays1 = Main.pref.getInteger("selection.maxfoundways.intersection", 500);
     36
     37    private NodeWayUtils() {
     38        // Hide default constructor for utilities classes
     39    }
    4040
    4141    /**
     
    4747    static void addNeighbours(Way w, Node n, Collection<Node> nodes) {
    4848        List<Node> nodeList = w.getNodes();
    49        
     49
    5050        int idx = nodeList.indexOf(n);
    5151        if (idx == -1) return;
     
    6868            }
    6969        }
    70      }
     70    }
    7171
    7272    /**
     
    7676     */
    7777    static int addWaysConnectedToWay(Way w, Set<Way> ways) {
    78          int s = ways.size();
     78        int s = ways.size();
    7979        List<Node> nodes = w.getNodes();
    8080        boolean flag = ways.contains(w);
     
    103103     * @param newWays set to place the ways we found
    104104     */
    105     static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays,Set<Way> excludeWays) {
     105    static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays, Set<Way> excludeWays) {
    106106        List<Pair<Node, Node>> nodePairs = w.getNodePairs(false);
    107         int count=0;
     107        int count = 0;
    108108        for (Way anyway: ways) {
    109109            if (anyway == w) continue;
    110             if (newWays.contains(anyway) || excludeWays.contains(anyway) ) continue;
     110            if (newWays.contains(anyway) || excludeWays.contains(anyway)) continue;
    111111
    112112            List<Pair<Node, Node>> nodePairs2 = anyway.getNodePairs(false);
    113             loop: for (Pair<Node,Node> p1 : nodePairs) {
    114                 for (Pair<Node,Node> p2 : nodePairs2) {
    115                     if (null!=Geometry.getSegmentSegmentIntersection(
    116                             p1.a.getEastNorth(),p1.b.getEastNorth(),
    117                             p2.a.getEastNorth(),p2.b.getEastNorth())) {
    118                             newWays.add(anyway);
    119                             count++;
    120                             break loop;
     113            loop: for (Pair<Node, Node> p1 : nodePairs) {
     114                for (Pair<Node, Node> p2 : nodePairs2) {
     115                    if (null != Geometry.getSegmentSegmentIntersection(
     116                            p1.a.getEastNorth(), p1.b.getEastNorth(),
     117                            p2.a.getEastNorth(), p2.b.getEastNorth())) {
     118                        newWays.add(anyway);
     119                        count++;
     120                        break loop;
    121121                    }
    122122                }
     
    126126    }
    127127
    128 
    129         static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays) {
     128    static int addWaysIntersectingWay(Collection<Way> ways, Way w, Set<Way> newWays) {
    130129        List<Pair<Node, Node>> nodePairs = w.getNodePairs(false);
    131         int count=0;
     130        int count = 0;
    132131        for (Way anyway: ways) {
    133132            if (anyway == w) continue;
    134133            if (newWays.contains(anyway)) continue;
    135134            List<Pair<Node, Node>> nodePairs2 = anyway.getNodePairs(false);
    136             loop: for (Pair<Node,Node> p1 : nodePairs) {
    137                 for (Pair<Node,Node> p2 : nodePairs2) {
    138                     if (null!=Geometry.getSegmentSegmentIntersection(
    139                             p1.a.getEastNorth(),p1.b.getEastNorth(),
    140                             p2.a.getEastNorth(),p2.b.getEastNorth())) {
    141                             newWays.add(anyway);
    142                             count++;
    143                             break loop;
     135            loop: for (Pair<Node, Node> p1 : nodePairs) {
     136                for (Pair<Node, Node> p2 : nodePairs2) {
     137                    if (null != Geometry.getSegmentSegmentIntersection(
     138                            p1.a.getEastNorth(), p1.b.getEastNorth(),
     139                            p2.a.getEastNorth(), p2.b.getEastNorth())) {
     140                        newWays.add(anyway);
     141                        count++;
     142                        break loop;
    144143                    }
    145144                }
     
    156155     */
    157156    public static int addWaysIntersectingWays(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) {
    158         int count=0;
    159         for (Way w : initWays){
    160             count+=addWaysIntersectingWay(allWays, w, newWays);
     157        int count = 0;
     158        for (Way w : initWays) {
     159            count += addWaysIntersectingWay(allWays, w, newWays);
    161160        }
    162161        return count;
    163162    }
    164    
     163
    165164    public static void addWaysConnectedToWays(Collection<Way> ways, Set<Way> newWays) {
    166         for (Way w : ways){
     165        for (Way w : ways) {
    167166            NodeWayUtils.addWaysConnectedToWay(w, newWays);
    168167        }
     
    185184    }
    186185
    187     public static void addWaysIntersectingWaysRecursively
    188         (Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) {
     186    public static void addWaysIntersectingWaysRecursively(Collection<Way> allWays, Collection<Way> initWays, Set<Way> newWays) {
    189187        Set<Way> foundWays = new HashSet<>();
    190188        foundWays.addAll(initWays);
     
    192190        Set<Way> newFoundWays;
    193191
    194         int level=0,c;
     192        int level = 0, c;
    195193        do {
    196              c=0;
    197              newFoundWays = new HashSet<>();
    198              for (Way w : foundWays){
    199                   c+=addWaysIntersectingWay(allWays, w, newFoundWays,newWays);
    200              }
    201              foundWays = newFoundWays;
    202              newWays.addAll(newFoundWays);
    203              level++;
    204 //                 System.out.printf("%d: %d ways added to selection intersectiong\n",level,c);
    205              if (c>maxWays1) {
    206                     new Notification(
    207                         tr("Too many ways are added: {0}!",c)
    208                         ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 
    209                    return;
    210              }
    211         } while ( c >0 && level < maxLevel );
    212     }
    213 
    214     public static void addWaysConnectedToWaysRecursively
    215             (Collection<Way> initWays, Set<Way> newWays)
    216     {
    217         //long t = System.currentTimeMillis();
    218         int level=0,c;
     194            c = 0;
     195            newFoundWays = new HashSet<>();
     196            for (Way w : foundWays) {
     197                c += addWaysIntersectingWay(allWays, w, newFoundWays, newWays);
     198            }
     199            foundWays = newFoundWays;
     200            newWays.addAll(newFoundWays);
     201            level++;
     202            if (c > maxWays1) {
     203                new Notification(
     204                        tr("Too many ways are added: {0}!", c)
     205                        ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     206                return;
     207            }
     208        } while (c > 0 && level < maxLevel);
     209    }
     210
     211    public static void addWaysConnectedToWaysRecursively(Collection<Way> initWays, Set<Way> newWays) {
     212        int level = 0, c;
    219213        newWays.addAll(initWays);
    220214        do {
    221              c=0;
    222              Set<Way> foundWays = new HashSet<>();
    223              foundWays.addAll(newWays);
    224              for (Way w : foundWays){
    225                   c+=addWaysConnectedToWay(w, newWays);
    226              }
    227              level++;
    228 //                 System.out.printf("%d: %d ways added to selection\n",level,c);
    229              if (c>maxWays) {
     215            c = 0;
     216            Set<Way> foundWays = new HashSet<>();
     217            foundWays.addAll(newWays);
     218            for (Way w : foundWays) {
     219                c += addWaysConnectedToWay(w, newWays);
     220            }
     221            level++;
     222            if (c > maxWays) {
    230223                new Notification(
    231                     tr("Too many ways are added: {0}!",c)
    232                     ).setIcon(JOptionPane.WARNING_MESSAGE).show();                       
    233                return;
    234              }
    235         } while ( c >0 && level < maxLevel );
    236        // System.out.println("time = "+(System.currentTimeMillis()-t)+" ways = "+newWays.size());
     224                        tr("Too many ways are added: {0}!", c)
     225                        ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     226                return;
     227            }
     228        } while (c > 0 && level < maxLevel);
    237229    }
    238230
    239231    static void addMiddle(Set<Node> selectedNodes, Set<Node> newNodes) {
    240         Iterator<Node> it=selectedNodes.iterator();
     232        Iterator<Node> it = selectedNodes.iterator();
    241233        Node n1 = it.next();
    242234        Node n2 = it.next();
    243         Set<Way> ways=new HashSet<>();
     235        Set<Way> ways = new HashSet<>();
    244236        ways.addAll(OsmPrimitive.getFilteredList(n1.getReferrers(), Way.class));
    245237        for (Way w: ways) {
     
    247239            if (w.isUsable() && w.containsNode(n2) && w.containsNode(n1)) {
    248240                // Way w goes from n1 to n2
    249                 List <Node> nodes= w.getNodes();
     241                List<Node> nodes = w.getNodes();
    250242                int i1 = nodes.indexOf(n1);
    251243                int i2 = nodes.indexOf(n2);
    252244                int n = nodes.size();
    253                 if (i1>i2) { int p=i2; i2=i1; i1=p; } // now i1<i2
     245                if (i1 > i2) {
     246                    int p = i2; i2 = i1; i1 = p; // now i1<i2
     247                }
    254248                if (w.isClosed()) {
    255                         if ((i2-i1)*2 <= n ) { // i1 ... i2
    256                             for (int i=i1+1;i!=i2; i++) {
    257                                 newNodes.add(nodes.get(i));
    258                             }
    259                         } else { // i2 ... n-1 0 1 ... i1
    260                             for (int i=i2+1;i!=i1; i=(i+1)%n) {
    261                                 newNodes.add(nodes.get(i));
    262                             }
    263                         }
    264                     } else {
    265                         for (int i=i1+1;i<i2;i++) {
     249                    if ((i2-i1)*2 <= n) { // i1 ... i2
     250                        for (int i = i1+1; i != i2; i++) {
    266251                            newNodes.add(nodes.get(i));
    267252                        }
    268                     }
     253                    } else { // i2 ... n-1 0 1 ... i1
     254                        for (int i = i2+1; i != i1; i = (i+1) % n) {
     255                            newNodes.add(nodes.get(i));
     256                        }
     257                    }
     258                } else {
     259                    for (int i = i1+1; i < i2; i++) {
     260                        newNodes.add(nodes.get(i));
     261                    }
     262                }
    269263            }
    270264        }
    271265        if (newNodes.isEmpty()) {
    272                 new Notification(
     266            new Notification(
    273267                    tr("Please select two nodes connected by way!")
    274                 ).setIcon(JOptionPane.WARNING_MESSAGE).show(); 
    275             }
    276     }
    277    
     268                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     269        }
     270    }
     271
    278272    static boolean addAreaBoundary(Way firstWay, Set<Way> newWays, boolean goingLeft) {
    279         Way w=firstWay;
     273        Way w = firstWay;
    280274        Node curNode = w.lastNode();
    281275        Node prevNode = w.getNode(w.getNodes().size()-2);
    282276        Set<Way> newestWays = new HashSet<>();
    283         while(true) {
     277        while (true) {
    284278
    285279            Node nextNode, endNode, otherEnd, preLast;
     
    287281
    288282            EastNorth en;
    289             double startHeading,bestAngle;
     283            double startHeading, bestAngle;
    290284
    291285            en = curNode.getEastNorth();
    292             startHeading = prevNode.getEastNorth().heading( en );
    293 
    294             bestAngle = goingLeft ? -1e5 : 1e5 ;
    295             otherEnd=null; nextWay=null;
    296            
     286            startHeading = prevNode.getEastNorth().heading(en);
     287
     288            bestAngle = goingLeft ? -1e5 : 1e5;
     289            otherEnd = null;
     290            nextWay = null;
     291
    297292            for (OsmPrimitive ref : curNode.getReferrers()) {
    298                 if (ref instanceof Way && ref!=w && ref.isSelectable()) {
     293                if (ref instanceof Way && ref != w && ref.isSelectable()) {
    299294                    //
    300295                    Way w2 = (Way) ref;
    301296                    //  -----[prevNode]-(curNode)-[nextNode]------[preLast]-(endNode)
    302297                    //          w           |              w2
    303                     if (w2.getNodesCount()<2 || w2.isClosed()) continue;
    304 
     298                    if (w2.getNodesCount() < 2 || w2.isClosed()) continue;
    305299
    306300                    if (curNode == w2.firstNode()) {
    307301                        nextNode = w2.getNode(1);
    308302                        preLast = w2.getNode(w2.getNodesCount()-2);
    309                         endNode = w2.lastNode();
    310                     } // forward direction
    311                     else if (curNode == w2.lastNode()) {
     303                        endNode = w2.lastNode(); // forward direction
     304                    } else if (curNode == w2.lastNode()) {
    312305                        nextNode = w2.getNode(w2.getNodesCount()-2);
    313306                        preLast = w2.getNode(1);
    314                         endNode = w2.firstNode();
    315                     } // backward direction
    316                         else continue; // we came to some way middle node
     307                        endNode = w2.firstNode(); // backward direction
     308                    } else continue; // we came to some way middle node
    317309
    318310                    double angle = startHeading -Math.PI - en.heading(nextNode.getEastNorth());
    319                     while (angle<0) angle+=2*Math.PI;
    320                    
     311                    while (angle < 0) {
     312                        angle += 2*Math.PI;
     313                    }
     314
    321315                    if (angle < bestAngle ^ goingLeft) {
    322316                        bestAngle = angle;
     
    327321                }
    328322            }
    329             if (firstWay == nextWay ) {
    330                 //we came to starting way, but not not the right end 
    331                 if (otherEnd==firstWay.firstNode()) return false;
     323            if (firstWay == nextWay) {
     324                //we came to starting way, but not not the right end
     325                if (otherEnd == firstWay.firstNode()) return false;
    332326                newWays.addAll(newestWays);
    333                 return true; // correct loop found 
     327                return true; // correct loop found
    334328            }
    335329            if (newestWays.contains(nextWay)) {
     
    337331                return false;
    338332            }
    339             if (nextWay != null) { 
     333            if (nextWay != null) {
    340334                newestWays.add(nextWay);
    341335                curNode = otherEnd;
     
    345339                // no closed loop found
    346340                return false;
    347             } 
    348         }
    349     }
    350    
     341            }
     342        }
     343    }
     344
    351345    static boolean isPointInsideMultipolygon(EastNorth p, Relation rel) {
    352346        Set<Way> usedWays = OsmPrimitive.getFilteredSet(rel.getMemberPrimitives(), Way.class);
    353347        return isPointInsidePolygon(p, buildPointList(usedWays));
    354348    }
    355            
     349
    356350    static void addAllInsideMultipolygon(DataSet data, Relation rel, Set<Way> newWays, Set<Node> newNodes) {
    357351        if (!rel.isMultipolygon()) return;
     
    359353        Collection<Way> usedWays = rel.getMemberPrimitives(Way.class);
    360354        List<EastNorth> polyPoints = buildPointList(usedWays);
    361        
     355
    362356        List<Node> searchNodes = data.searchNodes(box);
    363357        Set<Node> newestNodes = new HashSet<>();
     
    369363            }
    370364        }
    371        
     365
    372366        List<Way> searchWays = data.searchWays(box);
    373367        for (Way w : searchWays) {
     
    380374            // do not select nodes of already selected ways
    381375        }
    382        
     376
    383377        newNodes.addAll(newestNodes);
    384378        newWays.addAll(newestWays);
     
    389383        BBox box = way.getBBox();
    390384        Iterable<EastNorth> polyPoints = getWayPoints(way);
    391        
     385
    392386        List<Node> searchNodes = data.searchNodes(box);
    393387        Set<Node> newestNodes = new HashSet<>();
     
    399393            }
    400394        }
    401        
     395
    402396        List<Way> searchWays = data.searchWays(box);
    403397        for (Way w : searchWays) {
     
    406400            }
    407401        }
    408        
     402
    409403        newNodes.addAll(newestNodes);
    410404        newWays.addAll(newestWays);
    411405    }
    412    
     406
    413407    public static boolean isPointInsidePolygon(EastNorth point, Iterable<EastNorth> polygonPoints) {
    414408        int n = getRayIntersectionsCount(point, polygonPoints);
    415         if (n<0) return true; // we are near node or near edge
    416         return (n%2==1);
     409        if (n < 0) return true; // we are near node or near edge
     410        return (n % 2 == 1);
    417411    }
    418412
     
    423417     */
    424418    public static int getRayIntersectionsCount(EastNorth point, Iterable<EastNorth> polygonPoints) {
    425         if (point==null) return 0;
     419        if (point == null) return 0;
    426420        EastNorth oldPoint = null;
    427         double n1,n2,n3,e1,e2,e3,d;
    428         int interCount=0;
    429        
     421        double n1, n2, n3, e1, e2, e3, d;
     422        int interCount = 0;
     423
    430424        for (EastNorth curPoint : polygonPoints) {
    431             if (oldPoint==null || curPoint==null) {
     425            if (oldPoint == null || curPoint == null) {
    432426                oldPoint = curPoint;
    433427                continue;
    434428            }
    435             n1 = curPoint.north(); n2 = oldPoint.north();  n3 = point.north();
    436             e1 = curPoint.east(); e2 = oldPoint.east();  e3 = point.east();
    437            
    438             if (Math.abs(n1-n3)<1e-5 && Math.abs(e1-e3)<1e-5) return -3; // vertex
    439             if (Math.abs(n2-n3)<1e-5 && Math.abs(e2-e3)<1e-5) return -3; // vertex
    440            
     429            n1 = curPoint.north(); n2 = oldPoint.north(); n3 = point.north();
     430            e1 = curPoint.east(); e2 = oldPoint.east(); e3 = point.east();
     431
     432            if (Math.abs(n1-n3) < 1e-5 && Math.abs(e1-e3) < 1e-5) return -3; // vertex
     433            if (Math.abs(n2-n3) < 1e-5 && Math.abs(e2-e3) < 1e-5) return -3; // vertex
     434
    441435            // looking at oldPoint-curPoint segment
    442             if ( n1 > n2) {
     436            if (n1 > n2) {
    443437                if (n1 > n3 && n3 >= n2) {
    444                     n1-=n3; n2-=n3; e1-=e3; e2-=e3;
     438                    n1 -= n3; n2 -= n3; e1 -= e3; e2 -= e3;
    445439                    d = e1*n2 - n1*e2;
    446                     if (d<-1e-5) {
    447                         interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0
    448                     } else if (d<=1e-5) return -2; // boundary detected
     440                    if (d < -1e-5) {
     441                        interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >= 0
     442                    } else if (d <= 1e-5) return -2; // boundary detected
    449443                }
    450444            } else if (n1 == n2) {
    451445                if (n1 == n3) {
    452                     e1-=e3; e2-=e3;
    453                     if ((e1 <=0 && e2 >= 0) || (e1 >=0 && e2 <= 0)) return -2;// boundary detected
     446                    e1 -= e3; e2 -= e3;
     447                    if ((e1 <= 0 && e2 >= 0) || (e1 >= 0 && e2 <= 0)) return -2; // boundary detected
    454448                }
    455449            } else {
    456450                if (n1 <= n3 && n3 < n2) {
    457                     n1-=n3; n2-=n3; e1-=e3; e2-=e3;
     451                    n1 -= n3; n2 -= n3; e1 -= e3; e2 -= e3;
    458452                    d = e1*n2 - n1*e2;
    459                     if (d>1e-5) {
    460                         interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >=0
    461                     } else if (d>=-1e-5) return -2; // boundary detected
     453                    if (d > 1e-5) {
     454                        interCount++; // there is OX intersecthion at e = (e1n2-e2n1)/(n2-n1) >= 0
     455                    } else if (d >= -1e-5) return -2; // boundary detected
    462456                }
    463457            }
     
    467461        return interCount;
    468462    }
    469    
     463
    470464    public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset) {
    471465        return selectAllInside(selected, dataset, true);
    472466    }
    473    
     467
    474468    public static Collection<OsmPrimitive> selectAllInside(Collection<OsmPrimitive> selected, DataSet dataset, boolean ignoreNodesOfFoundWays) {
    475469        Set<Way> selectedWays = OsmPrimitive.getFilteredSet(selected, Way.class);
     
    488482        if (!selectedWays.isEmpty()) {
    489483            for (Way w: selectedWays) {
    490                 addAllInsideWay(dataset,w,newWays,newNodes);
     484                addAllInsideWay(dataset, w, newWays, newNodes);
    491485            }
    492486        }
    493487        if (!selectedRels.isEmpty()) {
    494488            for (Relation r: selectedRels) {
    495                 addAllInsideMultipolygon(dataset,r,newWays,newNodes);
     489                addAllInsideMultipolygon(dataset, r, newWays, newNodes);
    496490            }
    497491        }
     
    500494                newNodes.removeAll(w.getNodes());
    501495                // do not select nodes of already selected ways
    502             }           
    503         }
    504        
     496            }
     497        }
     498
    505499        Set<OsmPrimitive> insideSelection = new HashSet<>();
    506500        if (!newWays.isEmpty() || !newNodes.isEmpty()) {
     
    521515        return points;
    522516    }
    523    
     517
    524518    public static Iterable<EastNorth> getWayPoints(final Way w) {
    525519        return new Iterable<EastNorth>() {
     
    531525                        return idx < w.getNodesCount();
    532526                    }
     527
    533528                    @Override public EastNorth next() {
    534529                        return w.getNode(idx++).getEastNorth();
    535530                    }
     531
    536532                    @Override public void remove() {
    537533                        throw new UnsupportedOperationException();
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectAllInsideAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    1818
    1919/**
    20  *    Extends current selection by selecting nodes on all touched ways
     20 * Extends current selection by selecting nodes on all touched ways
    2121 */
    2222public class SelectAllInsideAction extends JosmAction {
     
    2424    public SelectAllInsideAction() {
    2525        super(tr("All inside [testing]"), "selinside", tr("Select all inside selected polygons"),
    26                 Shortcut.registerShortcut("tools:selinside", tr("Tool: {0}","All inside"),
    27                 KeyEvent.VK_I, Shortcut.ALT_SHIFT), true);
     26                Shortcut.registerShortcut("tools:selinside", tr("Tool: {0}", "All inside"),
     27                        KeyEvent.VK_I, Shortcut.ALT_SHIFT), true);
    2828        putValue("help", ht("/Action/SelectAllInside"));
    2929    }
    30    
     30
    3131    @Override
    3232    public void actionPerformed(ActionEvent e) {
    3333        DataSet ds = getLayerManager().getEditDataSet();
    3434        Collection<OsmPrimitive> insideSelected = NodeWayUtils.selectAllInside(ds.getSelected(), ds, true);
    35        
     35
    3636        if (!insideSelected.isEmpty()) {
    3737            ds.addSelected(insideSelected);
    38         } else{
     38        } else {
    3939            new Notification(
    40                 tr("Nothing found. Please select some closed ways or multipolygons to find all primitives inside them!"))
    41                 .setIcon(JOptionPane.WARNING_MESSAGE)
    42                 .show(); 
     40                    tr("Nothing found. Please select some closed ways or multipolygons to find all primitives inside them!"))
     41            .setIcon(JOptionPane.WARNING_MESSAGE)
     42            .show();
    4343        }
    4444    }
     
    5757        setEnabled(!selection.isEmpty());
    5858    }
    59 
    60 
    6159}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectBoundaryAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
    4 import java.awt.Point;
    54import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    65import static org.openstreetmap.josm.tools.I18n.tr;
    76
     7import java.awt.Point;
    88import java.awt.event.ActionEvent;
    99import java.awt.event.KeyEvent;
     
    1313
    1414import javax.swing.JOptionPane;
     15
    1516import org.openstreetmap.josm.Main;
    16 
    1717import org.openstreetmap.josm.actions.JosmAction;
    1818import org.openstreetmap.josm.actions.SelectByInternalPointAction;
     
    2121import org.openstreetmap.josm.data.osm.Way;
    2222import org.openstreetmap.josm.gui.Notification;
    23 
    2423import org.openstreetmap.josm.tools.Shortcut;
    2524
    2625/**
    27  *    Extends current selection by selecting nodes on all touched ways
     26 * Extends current selection by selecting nodes on all touched ways
    2827 */
    2928public class SelectBoundaryAction extends JosmAction {
     
    3332    public SelectBoundaryAction() {
    3433        super(tr("Area boundary [testing]"), "selboundary", tr("Select relation or all ways that forms area boundary"),
    35                 Shortcut.registerShortcut("tools:selboundary", tr("Tool: {0}","Area boundary [testing]"),
    36                 KeyEvent.VK_SLASH, Shortcut.SHIFT), true);
     34                Shortcut.registerShortcut("tools:selboundary", tr("Tool: {0}", "Area boundary [testing]"),
     35                        KeyEvent.VK_SLASH, Shortcut.SHIFT), true);
    3736        putValue("help", ht("/Action/SelectAreaBoundary"));
    3837    }
     
    4241        Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getLayerManager().getEditDataSet().getSelected(), Way.class);
    4342        Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(getLayerManager().getEditDataSet().getSelected(), Node.class);
    44        
     43
    4544        Set<Way> newWays = new HashSet<>();
    46        
    47         Way w=null;
    48        
     45
     46        Way w = null;
     47
    4948        if (selectedWays.isEmpty()) {
    50             if (selectedNodes.size()==1 ) {
     49            if (selectedNodes.size() == 1) {
    5150                for (OsmPrimitive p : selectedNodes.iterator().next().getReferrers()) {
    5251                    if (p instanceof Way && p.isSelectable()) {
    53                         //if (w!=null) return; // if we want only one way
    54                         w=(Way) p;
     52                        w = (Way) p;
    5553                        break;
    5654                    }
     
    6159                return;
    6260            }
    63         } else if (selectedWays.size()==1) {
     61        } else if (selectedWays.size() == 1) {
    6462            w = selectedWays.iterator().next();
    65         } else if (selectedWays.contains(lastUsedStartingWay)) { 
    66             w=lastUsedStartingWay; //repeated call for selected way
     63        } else if (selectedWays.contains(lastUsedStartingWay)) {
     64            w = lastUsedStartingWay; //repeated call for selected way
    6765            lastUsedLeft = !lastUsedLeft;
    6866        }
    6967
    70        
    71         if (w==null) return; //no starting way found
     68
     69        if (w == null) return; //no starting way found
    7270        if (!w.isSelectable()) return;
    7371        if (w.isClosed()) return;
    74         if (w.getNodesCount()<2) return;
     72        if (w.getNodesCount() < 2) return;
    7573
    7674        newWays.add(w);
    7775        lastUsedStartingWay = w;
    78                        
     76
    7977        // try going left at each turn
    80         if (! NodeWayUtils.addAreaBoundary(w, newWays, lastUsedLeft) ) {
     78        if (!NodeWayUtils.addAreaBoundary(w, newWays, lastUsedLeft)) {
    8179            NodeWayUtils.addAreaBoundary(w, newWays, !lastUsedLeft); // try going right at each turn
    8280        }
    83        
    84         if (!newWays.isEmpty() ) {
     81
     82        if (!newWays.isEmpty()) {
    8583            getLayerManager().getEditDataSet().setSelected(newWays);
    86         } else{
     84        } else {
    8785            new Notification(tr("Nothing found. Please select way that is a part of some polygon formed by connected ways"))
    88                 .setIcon(JOptionPane.WARNING_MESSAGE).show();           
     86            .setIcon(JOptionPane.WARNING_MESSAGE).show();
    8987        }
    9088    }
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectHighwayAction.java

    r32333 r32410  
    1 // License: PD
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    2828 * Select all connected ways for a street if one way is selected (determine by name/ref),
    2929 * select highway ways between two selected ways.
    30  * 
     30 *
    3131 * @author zverik
    3232 */
     
    3535    public SelectHighwayAction() {
    3636        super(tr("Select Highway"), "selecthighway", tr("Select highway for the name/ref given"),
    37                 Shortcut.registerShortcut("tools:selecthighway", tr("Tool: {0}","Select Highway"),
    38                 KeyEvent.VK_W, Shortcut.ALT_CTRL), true);
     37                Shortcut.registerShortcut("tools:selecthighway", tr("Tool: {0}", "Select Highway"),
     38                        KeyEvent.VK_W, Shortcut.ALT_CTRL), true);
    3939    }
    4040
     
    4444        List<Way> selectedWays = OsmPrimitive.getFilteredList(ds.getSelected(), Way.class);
    4545
    46         if( selectedWays.size() == 1 ) {
     46        if (selectedWays.size() == 1) {
    4747            ds.setSelected(selectNamedRoad(selectedWays.get(0)));
    48         } else if( selectedWays.size() == 2 ) {
     48        } else if (selectedWays.size() == 2) {
    4949            ds.setSelected(selectHighwayBetween(selectedWays.get(0), selectedWays.get(1)));
    5050        } else {
    5151            new Notification(
    52                 tr("Please select one or two ways for this action")
    53             ).setIcon(JOptionPane.WARNING_MESSAGE).show();
    54         }
    55     }
    56 
    57     private Set<Way> selectNamedRoad( Way firstWay ) {
     52                    tr("Please select one or two ways for this action")
     53                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
     54        }
     55    }
     56
     57    private Set<Way> selectNamedRoad(Way firstWay) {
    5858        Set<Way> newWays = new HashSet<>();
    5959        String key = firstWay.hasKey("name") ? "name" : "ref";
    60         if( firstWay.hasKey(key) ) {
     60        if (firstWay.hasKey(key)) {
    6161            String value = firstWay.get(key);
    6262            Queue<Node> nodeQueue = new LinkedList<>();
    6363            nodeQueue.add(firstWay.firstNode());
    64             while( !nodeQueue.isEmpty() ) {
     64            while (!nodeQueue.isEmpty()) {
    6565                Node node = nodeQueue.remove();
    66                 for( Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class) ) {
    67                     if( !newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value) ) {
     66                for (Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {
     67                    if (!newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value)) {
    6868                        newWays.add(p);
    6969                        nodeQueue.add(p.firstNode().equals(node) ? p.lastNode() : p.firstNode());
     
    7474        return newWays;
    7575    }
    76    
    77     private Set<Way> selectHighwayBetween( Way firstWay, Way lastWay ) {
     76
     77    private Set<Way> selectHighwayBetween(Way firstWay, Way lastWay) {
    7878        int minRank = Math.min(getHighwayRank(firstWay), getHighwayRank(lastWay));
    79         HighwayTree firstTree = new HighwayTree(firstWay, minRank);
    80         HighwayTree secondTree = new HighwayTree(lastWay, minRank);
    81         Way intersection = firstTree.getIntersection(secondTree);
    82         while( intersection == null && (firstTree.canMoveOn() || secondTree.canMoveOn()) ) {
    83             firstTree.processNextLevel();
    84             secondTree.processNextLevel();
    85             intersection = firstTree.getIntersection(secondTree);
    86         }
    87         Set<Way> newWays = new HashSet<>();
    88         newWays.addAll(firstTree.getPath(intersection));
    89         newWays.addAll(secondTree.getPath(intersection));
    90         return newWays;
    91     }
    92    
    93     private static int getHighwayRank( OsmPrimitive way ) {
    94         if( !way.hasKey("highway") )
     79        HighwayTree firstTree = new HighwayTree(firstWay, minRank);
     80        HighwayTree secondTree = new HighwayTree(lastWay, minRank);
     81        Way intersection = firstTree.getIntersection(secondTree);
     82        while (intersection == null && (firstTree.canMoveOn() || secondTree.canMoveOn())) {
     83            firstTree.processNextLevel();
     84            secondTree.processNextLevel();
     85            intersection = firstTree.getIntersection(secondTree);
     86        }
     87        Set<Way> newWays = new HashSet<>();
     88        newWays.addAll(firstTree.getPath(intersection));
     89        newWays.addAll(secondTree.getPath(intersection));
     90        return newWays;
     91    }
     92
     93    private static int getHighwayRank(OsmPrimitive way) {
     94        if (!way.hasKey("highway"))
    9595            return 0;
    9696        String highway = way.get("highway");
    97         if( highway.equals("path") || highway.equals("footway") || highway.equals("cycleway") )
     97        if (highway.equals("path") || highway.equals("footway") || highway.equals("cycleway"))
    9898            return 1;
    99         else if( highway.equals("track") || highway.equals("service") )
     99        else if (highway.equals("track") || highway.equals("service"))
    100100            return 2;
    101         else if( highway.equals("unclassified") || highway.equals("residential") )
     101        else if (highway.equals("unclassified") || highway.equals("residential"))
    102102            return 3;
    103         else if( highway.equals("tertiary") || highway.equals("tertiary_link") )
     103        else if (highway.equals("tertiary") || highway.equals("tertiary_link"))
    104104            return 4;
    105         else if( highway.equals("secondary") || highway.equals("secondary_link") )
     105        else if (highway.equals("secondary") || highway.equals("secondary_link"))
    106106            return 5;
    107         else if( highway.equals("primary") || highway.equals("primary_link") )
     107        else if (highway.equals("primary") || highway.equals("primary_link"))
    108108            return 6;
    109         else if( highway.equals("trunk") || highway.equals("trunk_link") || highway.equals("motorway") || highway.equals("motorway_link") )
     109        else if (highway.equals("trunk") || highway.equals("trunk_link") || highway.equals("motorway") || highway.equals("motorway_link"))
    110110            return 7;
    111111        return 0;
    112112    }
    113    
     113
    114114    @Override
    115115    protected void updateEnabledState() {
     
    124124        }
    125125        int count = 0, rank = 100;
    126         for( OsmPrimitive p : selection ) {
    127             if( p instanceof Way ) {
     126        for (OsmPrimitive p : selection) {
     127            if (p instanceof Way) {
    128128                count++;
    129129                rank = Math.min(rank, getHighwayRank(p));
     
    132132        setEnabled(count == 1 || (count == 2 && rank > 0));
    133133    }
    134    
     134
    135135    private static class HighwayTree {
    136         private List<Way> tree;
    137         private List<Integer> refs;
    138         private List<Node> nodesToCheck;
    139         private List<Integer> nodeRefs;
    140         private int minHighwayRank;
    141 
    142         public HighwayTree( Way from, int minHighwayRank ) {
    143             tree = new ArrayList<>(1);
    144             refs = new ArrayList<>(1);
    145             tree.add(from);
    146             refs.add(Integer.valueOf(-1));
    147             this.minHighwayRank = minHighwayRank;
    148             nodesToCheck = new ArrayList<>(2);
    149             nodeRefs = new ArrayList<>(2);
    150             nodesToCheck.add(from.firstNode());
    151             nodesToCheck.add(from.lastNode());
    152             nodeRefs.add(Integer.valueOf(0));
    153             nodeRefs.add(Integer.valueOf(0));
    154         }
    155        
    156         public void processNextLevel() {
    157             List<Node> newNodes = new ArrayList<>();
    158             List<Integer> newIdx = new ArrayList<>();
    159             for( int i = 0; i < nodesToCheck.size(); i++ ) {
    160                 Node node = nodesToCheck.get(i);
    161                 Integer nodeRef = nodeRefs.get(i);
    162                 for( Way way : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class) ) {
    163                     if( (way.firstNode().equals(node) || way.lastNode().equals(node)) &&
    164                         !tree.contains(way) && suits(way) ) {
    165                         tree.add(way);
    166                         refs.add(nodeRef);
    167                         Node newNode = way.firstNode().equals(node) ? way.lastNode() : way.firstNode();
    168                         newNodes.add(newNode);
    169                         newIdx.add(Integer.valueOf(tree.size() - 1));
    170                     }
    171                 }
    172             }
    173             nodesToCheck = newNodes;
    174             nodeRefs = newIdx;
    175         }
    176        
    177         private boolean suits( Way w ) {
    178             return getHighwayRank(w) >= minHighwayRank;
    179         }
    180        
    181         public boolean canMoveOn() {
    182             return !nodesToCheck.isEmpty() && tree.size() < 10000;
    183         }
    184        
    185         public Way getIntersection( HighwayTree other ) {
    186             for( Way w : other.tree )
    187                 if( tree.contains(w) )
    188                     return w;
    189             return null;
    190         }
    191        
    192         public List<Way> getPath( Way to ) {
    193             if( to == null )
    194                 return Collections.singletonList(tree.get(0));
    195             int pos = tree.indexOf(to);
    196             if( pos < 0 )
    197                 throw new ArrayIndexOutOfBoundsException("Way " + to + " is not in the tree.");
    198             List<Way> result = new ArrayList<>(1);
    199             while( pos >= 0 ) {
    200                 result.add(tree.get(pos));
    201                 pos = refs.get(pos);
    202             }
    203             return result;
    204         }
     136        private List<Way> tree;
     137        private List<Integer> refs;
     138        private List<Node> nodesToCheck;
     139        private List<Integer> nodeRefs;
     140        private int minHighwayRank;
     141
     142        HighwayTree(Way from, int minHighwayRank) {
     143            tree = new ArrayList<>(1);
     144            refs = new ArrayList<>(1);
     145            tree.add(from);
     146            refs.add(Integer.valueOf(-1));
     147            this.minHighwayRank = minHighwayRank;
     148            nodesToCheck = new ArrayList<>(2);
     149            nodeRefs = new ArrayList<>(2);
     150            nodesToCheck.add(from.firstNode());
     151            nodesToCheck.add(from.lastNode());
     152            nodeRefs.add(Integer.valueOf(0));
     153            nodeRefs.add(Integer.valueOf(0));
     154        }
     155
     156        public void processNextLevel() {
     157            List<Node> newNodes = new ArrayList<>();
     158            List<Integer> newIdx = new ArrayList<>();
     159            for (int i = 0; i < nodesToCheck.size(); i++) {
     160                Node node = nodesToCheck.get(i);
     161                Integer nodeRef = nodeRefs.get(i);
     162                for (Way way : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class)) {
     163                    if ((way.firstNode().equals(node) || way.lastNode().equals(node)) &&
     164                            !tree.contains(way) && suits(way)) {
     165                        tree.add(way);
     166                        refs.add(nodeRef);
     167                        Node newNode = way.firstNode().equals(node) ? way.lastNode() : way.firstNode();
     168                        newNodes.add(newNode);
     169                        newIdx.add(Integer.valueOf(tree.size() - 1));
     170                    }
     171                }
     172            }
     173            nodesToCheck = newNodes;
     174            nodeRefs = newIdx;
     175        }
     176
     177        private boolean suits(Way w) {
     178            return getHighwayRank(w) >= minHighwayRank;
     179        }
     180
     181        public boolean canMoveOn() {
     182            return !nodesToCheck.isEmpty() && tree.size() < 10000;
     183        }
     184
     185        public Way getIntersection(HighwayTree other) {
     186            for (Way w : other.tree) {
     187                if (tree.contains(w))
     188                    return w;
     189            }
     190            return null;
     191        }
     192
     193        public List<Way> getPath(Way to) {
     194            if (to == null)
     195                return Collections.singletonList(tree.get(0));
     196            int pos = tree.indexOf(to);
     197            if (pos < 0)
     198                throw new ArrayIndexOutOfBoundsException("Way " + to + " is not in the tree.");
     199            List<Way> result = new ArrayList<>(1);
     200            while (pos >= 0) {
     201                result.add(tree.get(pos));
     202                pos = refs.get(pos);
     203            }
     204            return result;
     205        }
    205206    }
    206207}
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModNodesAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
    4 import org.openstreetmap.josm.command.Command;
    54import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    65import static org.openstreetmap.josm.tools.I18n.tr;
     
    1110import java.util.HashSet;
    1211import java.util.Set;
     12
    1313import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.actions.JosmAction;
    15 import org.openstreetmap.josm.data.osm.*;
    16 
     15import org.openstreetmap.josm.command.Command;
     16import org.openstreetmap.josm.data.osm.DataSet;
     17import org.openstreetmap.josm.data.osm.Node;
     18import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1719import org.openstreetmap.josm.tools.Shortcut;
    1820
    1921/**
    20  *    Unselects all nodes
     22 * Unselects all nodes
    2123 */
    2224public class SelectModNodesAction extends JosmAction {
     
    2729        super(tr("Select last modified nodes"), "selmodnodes",
    2830                tr("Select last modified nodes"),
    29                 Shortcut.registerShortcut("tools:selmodnodes", tr("Tool: {0}","Select last modified nodes"),
    30                 KeyEvent.VK_Z, Shortcut.SHIFT), true);
     31                Shortcut.registerShortcut("tools:selmodnodes", tr("Tool: {0}", "Select last modified nodes"),
     32                        KeyEvent.VK_Z, Shortcut.SHIFT), true);
    3133        putValue("help", ht("/Action/SelectLastModifiedNodes"));
    3234    }
    3335
    3436    @Override
    35      public void actionPerformed(ActionEvent e) {
     37    public void actionPerformed(ActionEvent e) {
    3638        DataSet ds = getLayerManager().getEditDataSet();
    3739        Collection<OsmPrimitive> selection = ds.getSelected();
    3840        Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class);
    3941        ds.clearSelection(selectedNodes);
    40         Command cmd =null;
     42        Command cmd = null;
    4143
    4244        if (Main.main.undoRedo.commands == null) return;
    43         int num=Main.main.undoRedo.commands.size();
    44         if (num==0) return;
    45         int k=0,idx;
    46         if (selection!=null && !selection.isEmpty() && selection.hashCode() == lastHash) {
     45        int num = Main.main.undoRedo.commands.size();
     46        if (num == 0) return;
     47        int k = 0, idx;
     48        if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) {
    4749            // we are selecting next command in history if nothing is selected
    4850            idx = Main.main.undoRedo.commands.indexOf(lastCmd);
    49            // System.out.println("My previous selection found "+idx);
    5051        } else {
    51             idx=num;
    52            // System.out.println("last history item taken");
     52            idx = num;
    5353        }
    5454
    5555        Set<Node> nodes = new HashSet<>(10);
    5656        do {  //  select next history element
    57             if (idx>0) idx--; else idx=num-1;
     57            if (idx > 0) idx--; else idx = num-1;
    5858            cmd = Main.main.undoRedo.commands.get(idx);
    5959            Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives();
    6060            nodes.clear();
    61             for ( OsmPrimitive p : pp) {  // find all affected ways
    62                 if (p instanceof Node && !p.isDeleted()) nodes.add((Node)p);
     61            for (OsmPrimitive p : pp) {  // find all affected ways
     62                if (p instanceof Node && !p.isDeleted()) nodes.add((Node) p);
    6363            }
    6464            if (!nodes.isEmpty()) {
     
    6767                lastHash = ds.getSelected().hashCode();
    6868                return;
    69                 }
     69            }
    7070            k++;
    7171            //System.out.println("no nodes found, previous...");
    72         } while ( k < num ); // try to find previous command if this affects nothing
    73         lastCmd=null; lastHash=0;
     72        } while (k < num); // try to find previous command if this affects nothing
     73        lastCmd = null; lastHash = 0;
    7474    }
    7575
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModWaysAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
     3
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.tr;
    36
    47import java.awt.event.ActionEvent;
     
    710import java.util.HashSet;
    811import java.util.Set;
     12
    913import org.openstreetmap.josm.Main;
    1014import org.openstreetmap.josm.actions.JosmAction;
     
    1418import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1519import org.openstreetmap.josm.data.osm.Way;
    16 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    17 import static org.openstreetmap.josm.tools.I18n.tr;
    1820import org.openstreetmap.josm.tools.Shortcut;
    1921
    2022/**
    21  *    Unselects all nodes
     23 * Unselects all nodes
    2224 */
    2325public class SelectModWaysAction extends JosmAction {
     
    2830        super(tr("Select last modified ways"), "selmodways",
    2931                tr("Select last modified ways"),
    30                 Shortcut.registerShortcut("tools:selmodways", tr("Tool: {0}","Select last modified ways"),
    31                 KeyEvent.VK_Z, Shortcut.ALT_SHIFT), true);
     32                Shortcut.registerShortcut("tools:selmodways", tr("Tool: {0}", "Select last modified ways"),
     33                        KeyEvent.VK_Z, Shortcut.ALT_SHIFT), true);
    3234        putValue("help", ht("/Action/SelectLastModifiedWays"));
    3335    }
     
    4244
    4345        if (Main.main.undoRedo.commands == null) return;
    44         int num=Main.main.undoRedo.commands.size();
    45         if (num==0) return;
    46         int k=0,idx;
    47         if (selection!=null && !selection.isEmpty() && selection.hashCode() == lastHash) {
     46        int num = Main.main.undoRedo.commands.size();
     47        if (num == 0) return;
     48        int k = 0, idx;
     49        if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) {
    4850            // we are selecting next command in history if nothing is selected
    4951            idx = Main.main.undoRedo.commands.indexOf(lastCmd);
    50            // System.out.println("My previous selection found "+idx);
    5152        } else {
    52             idx=num;
    53            // System.out.println("last history item taken");
     53            idx = num;
    5454        }
    5555
    5656        Set<Way> ways = new HashSet<>(10);
    5757        do {  //  select next history element
    58             if (idx>0) idx--; else idx=num-1;
     58            if (idx > 0) idx--; else idx = num-1;
    5959            cmd = Main.main.undoRedo.commands.get(idx);
    6060            Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives();
    6161            ways.clear();
    62             for ( OsmPrimitive p : pp) {  // find all affected ways
    63                 if (p instanceof Way && !p.isDeleted()) ways.add((Way)p);
     62            for (OsmPrimitive p : pp) {  // find all affected ways
     63                if (p instanceof Way && !p.isDeleted()) ways.add((Way) p);
    6464            }
    6565            if (!ways.isEmpty() && !ds.getSelected().containsAll(ways)) {
     
    6868                lastHash = ds.getSelected().hashCode();
    6969                return;
    70                 }
     70            }
    7171            k++;
    72         } while ( k < num ); // try to find previous command if this affects nothing
    73         lastCmd=null; lastHash=0;
     72        } while (k < num); // try to find previous command if this affects nothing
     73        lastCmd = null;
     74        lastHash = 0;
    7475    }
    7576
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectWayNodesAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2010 by Hanno Hecker
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    1818/**
    1919 * Select all nodes of a selected way.
    20  *
    2120 */
    22 
    2321public class SelectWayNodesAction extends JosmAction {
    2422
     
    2927     */
    3028    public SelectWayNodesAction() {
    31         super(tr("Select Way Nodes"),"selectwaynodes" , tr("Select all nodes of a selected way."),
    32                 Shortcut.registerShortcut("tools:selectwaynodes", tr("Tool: {0}", tr("Select Way Nodes")), KeyEvent.VK_N, Shortcut.CTRL_SHIFT), true);
     29        super(tr("Select Way Nodes"), "selectwaynodes", tr("Select all nodes of a selected way."),
     30                Shortcut.registerShortcut("tools:selectwaynodes", tr("Tool: {0}", tr("Select Way Nodes")),
     31                        KeyEvent.VK_N, Shortcut.CTRL_SHIFT), true);
    3332        putValue("help", ht("/Action/SelectWayNodes"));
    3433    }
     
    5049                }
    5150                selectWayNodes(w);
    52             }
    53             else if (p instanceof Node) {
     51            } else if (p instanceof Node) {
    5452                Node n = (Node) p;
    5553                if (selectedNodes == null) {
     
    5957            }
    6058        }
    61            
     59
    6260        getLayerManager().getEditDataSet().setSelected(selectedNodes);
    6361        selectedNodes = null;
     
    6563
    6664    private void selectWayNodes(Way w) {
    67        
     65
    6866        for (Node n : w.getNodes()) {
    6967            if (selectedNodes == null) {
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UndoSelectionAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    1111import java.util.LinkedList;
    1212import java.util.Set;
     13
    1314import org.openstreetmap.josm.actions.JosmAction;
    14 import org.openstreetmap.josm.data.osm.*;
    15 
     15import org.openstreetmap.josm.data.osm.DataSet;
     16import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1617import org.openstreetmap.josm.tools.Shortcut;
    1718
    1819/**
    19  *    Use selection istory to restore previous selection
     20 * Use selection istory to restore previous selection
    2021 */
    2122public class UndoSelectionAction extends JosmAction {
    22    
     23
    2324    public UndoSelectionAction() {
    2425        super(tr("Undo selection"), "undoselection",
    2526                tr("Reselect last added object or selection form history"),
    26                 Shortcut.registerShortcut("tools:undoselection", tr("Tool: {0}","Undo selection"),
    27                 KeyEvent.VK_Z, Shortcut.CTRL_SHIFT), true);
     27                Shortcut.registerShortcut("tools:undoselection", tr("Tool: {0}", "Undo selection"),
     28                        KeyEvent.VK_Z, Shortcut.CTRL_SHIFT), true);
    2829        putValue("help", ht("/Action/UndoSelection"));
    2930    }
     
    3637        DataSet ds = getLayerManager().getEditDataSet();
    3738        LinkedList<Collection<? extends OsmPrimitive>> history = ds.getSelectionHistory();
    38         if (history==null || history.isEmpty()) return; // empty history
    39         int num=history.size();
    40        
     39        if (history == null || history.isEmpty()) return; // empty history
     40        int num = history.size();
     41
    4142        Collection<OsmPrimitive> selection = ds.getSelected();
    4243
    43         if (selection!= null && selection.hashCode() != myAutomaticSelectionHash) {
     44        if (selection != null && selection.hashCode() != myAutomaticSelectionHash) {
    4445            // manual selection or another pluging selection noticed
    45             index=history.indexOf(lastSel);
     46            index = history.indexOf(lastSel);
    4647            // first is selected, next list is previous selection
    4748        }
    48         int k=0;
     49        int k = 0;
    4950        Set<OsmPrimitive> newsel = new HashSet<>();
    5051        do {
    51             if (index+1<history.size()) index++; else index=0;
     52            if (index+1 < history.size()) index++; else index = 0;
    5253            Collection<? extends OsmPrimitive> histsel = history.get(index);
    5354            // remove deleted entities from selection
     
    5556            newsel.addAll(histsel);
    5657            newsel.retainAll(ds.allNonDeletedPrimitives());
    57             if (newsel.size() > 0 ) break;
     58            if (newsel.size() > 0) break;
    5859            k++;
    59         } while ( k < num );
     60        } while (k < num);
    6061
    6162        ds.setSelected(newsel);
  • applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/UnselectNodesAction.java

    r32333 r32410  
    1 // License: GPL. Copyright 2011 by Alexei Kasatkin and Martin Ždila
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.utilsplugin2.selection;
    33
     
    99import java.util.Collection;
    1010import java.util.Set;
     11
    1112import org.openstreetmap.josm.actions.JosmAction;
    12 import org.openstreetmap.josm.data.osm.*;
    13 
     13import org.openstreetmap.josm.data.osm.Node;
     14import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.tools.Shortcut;
    1516
     
    2526        super(tr("Unselect nodes"), "unsnodes",
    2627                tr("Removes all nodes from selection"),
    27                 Shortcut.registerShortcut("tools:unsnodes", tr("Tool: {0}","Unselect nodes"),
    28                 KeyEvent.VK_U, Shortcut.SHIFT), true);
     28                Shortcut.registerShortcut("tools:unsnodes", tr("Tool: {0}", "Unselect nodes"),
     29                        KeyEvent.VK_U, Shortcut.SHIFT), true);
    2930        putValue("help", ht("/Action/UnselectNodes"));
    3031    }
Note: See TracChangeset for help on using the changeset viewer.