Ignore:
Timestamp:
2016-07-02T01:10:44+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/turnrestrictions
Files:
1 added
67 edited

Legend:

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

    r32286 r32519  
    1212                </buildCommand>
    1313                <buildCommand>
     14                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     15                        <arguments>
     16                        </arguments>
     17                </buildCommand>
     18                <buildCommand>
    1419                        <name>org.sonarlint.eclipse.core.sonarlintBuilder</name>
    1520                        <arguments>
     
    2025                <nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
    2126                <nature>org.eclipse.jdt.core.javanature</nature>
     27                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2228        </natures>
    2329</projectDescription>
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/CreateOrEditTurnRestrictionAction.java

    r32375 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions;
    23
     
    2930    /**
    3031     * Replies the unique instance of this action
    31      *
    32      * @return
    3332     */
    3433    public static CreateOrEditTurnRestrictionAction getInstance() {
    35         if (instance == null){
     34        if (instance == null) {
    3635            instance = new CreateOrEditTurnRestrictionAction();
    3736        }
     
    4443            null,
    4544            tr("Create or edit a turn restriction."),
    46             Shortcut.registerShortcut("tools:turnrestriction", tr("Tool: {0}","Create or edit a turn restriction."),
     45            Shortcut.registerShortcut("tools:turnrestriction", tr("Tool: {0}", "Create or edit a turn restriction."),
    4746                KeyEvent.VK_2, Shortcut.ALT_SHIFT),
    4847            false
     
    5554        if (layer == null) return;
    5655        Collection<Relation> trs = TurnRestrictionSelectionPopupPanel.getTurnRestrictionsParticipatingIn(layer.data.getSelected());
    57         if (trs.isEmpty()){
     56        if (trs.isEmpty()) {
    5857            // current selection isn't participating in turn restrictions. Launch
    5958            // an editor for a new turn restriction
    6059            //
    6160            Relation tr = new TurnRestrictionBuilder().buildFromSelection(layer);
    62             TurnRestrictionEditor editor = new TurnRestrictionEditor(Main.map.mapView,layer,tr);
     61            TurnRestrictionEditor editor = new TurnRestrictionEditor(Main.map.mapView, layer, tr);
    6362            TurnRestrictionEditorManager.getInstance().positionOnScreen(editor);
    6463            TurnRestrictionEditorManager.getInstance().register(layer, tr, editor);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilder.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions;
    23
     
    2425 */
    2526public class TurnRestrictionBuilder {
    26    
     27
    2728    /**
    2829     * Replies the angle phi in the polar coordinates (r,phi) representing the first
    2930     * segment of the way {@code w}, where w is moved such that the start node of {@code w} is
    30      * in the origin (0,0).
    31      * 
    32      * @param w the way.  Must not be null. At least two nodes required. 
    33      * @return phi in the polar coordinates 
     31     * in the origin (0, 0).
     32     *
     33     * @param w the way.  Must not be null. At least two nodes required.
     34     * @return phi in the polar coordinates
    3435     * @throws IllegalArgumentException thrown if w is null
    3536     * @throws IllegalArgumentException thrown if w is too short (at least two nodes required)
    3637     */
    37     static public double phi(Way w) throws IllegalArgumentException{
     38    public static double phi(Way w) throws IllegalArgumentException {
    3839        return phi(w, false /* not inverse */);
    3940    }
    40    
     41
    4142    /**
    4243     * <p>Replies the angle phi in the polar coordinates (r,phi) representing the first
    4344     * segment of the way {@code w}, where w is moved such that the start node of {@code w} is
    44      * in the origin (0,0).</p>
    45      * 
     45     * in the origin (0, 0).</p>
     46     *
    4647     * <p>If {@code doInvert} is true, computes phi for the way in reversed direction.</p>
    47      * 
     48     *
    4849     * @param w the way.  Must not be null. At least two nodes required.
    49      * @param doInvert if true, computes phi for the reversed way 
    50      * @return phi in the polar coordinates 
     50     * @param doInvert if true, computes phi for the reversed way
     51     * @return phi in the polar coordinates
    5152     * @throws IllegalArgumentException thrown if w is null
    5253     * @throws IllegalArgumentException thrown if w is too short (at least two nodes required)
    5354     */
    54     static public double phi(Way w, boolean doInvert) throws IllegalArgumentException {
     55    public static double phi(Way w, boolean doInvert) throws IllegalArgumentException {
    5556        CheckParameterUtil.ensureParameterNotNull(w, "w");
    5657        if (w.getNodesCount() < 2) {
     
    6162        Node n0 = nodes.get(0);
    6263        Node n1 = nodes.get(1);
    63        
     64
    6465        double x = n1.getCoor().getX() - n0.getCoor().getX();
    6566        double y = n1.getCoor().getY() - n0.getCoor().getY();
    66         return Math.atan2(y, x);     
    67     }   
     67        return Math.atan2(y, x);
     68    }
    6869
    6970    /**
    7071     * Replies the unique common node of two ways, or null, if either no
    7172     * such node or multiple common nodes exist.
    72      * 
     73     *
    7374     * @param w1 the first way
    7475     * @param w2 the second way
     
    7677     * w1 and w2 don't share exactly one node
    7778     */
    78     static public Node getUniqueCommonNode(Way w1, Way w2) throws IllegalArgumentException{
     79    public static Node getUniqueCommonNode(Way w1, Way w2) throws IllegalArgumentException {
    7980        Set<Node> w1Nodes = new HashSet<>(w1.getNodes());
    8081        w1Nodes.retainAll(w2.getNodes());
    8182        if (w1Nodes.size() != 1) return null;
    8283        return w1Nodes.iterator().next();
    83     }   
    84        
     84    }
     85
    8586    /**
    8687     * Replies true, if {@code n} is the start node of the way {@code w}.
    87      * 
     88     *
    8889     * @param w the way. Must not be null.
    8990     * @param n the node. Must not be null.
    9091     * @return true, if {@code n} is the start node of the way {@code w}.
    9192     */
    92     static public boolean isStartNode(Way w, Node n) {
     93    public static boolean isStartNode(Way w, Node n) {
    9394        if (w.getNodesCount() == 0) return false;
    9495        return w.getNode(0).equals(n);
    9596    }
    96        
     97
    9798    /**
    9899     * Replies true, if {@code n} is the end node of the way {@code w}.
    99      * 
     100     *
    100101     * @param w the way. Must not be null.
    101102     * @param n the node. Must not be null.
    102103     * @return true, if {@code n} is the end node of the way {@code w}.
    103104     */
    104     static public boolean isEndNode(Way w, Node n){
     105    public static boolean isEndNode(Way w, Node n) {
    105106        if (w.getNodesCount() == 0) return false;
    106107        return w.getNode(w.getNodesCount()-1).equals(n);
    107108    }
    108    
     109
    109110    /**
    110111     * Replies true, if {@code n} is a node in the way {@code w} but {@code n}
    111112     * is neither the start nor the end node.
    112      * 
    113      * @param w the way 
    114      * @param n the node 
     113     *
     114     * @param w the way
     115     * @param n the node
    115116     * @return true if {@code n} is an "inner" node
    116117     */
    117     static public boolean isInnerNode(Way w, Node n){
     118    public static boolean isInnerNode(Way w, Node n) {
    118119        if (!w.getNodes().contains(n)) return false;
    119120        if (isStartNode(w, n)) return false;
    120121        if (isEndNode(w, n)) return false;
    121         return true;         
    122     }
    123    
     122        return true;
     123    }
     124
    124125    /**
    125126     * <p>Replies the angle at which way {@code from} and {@code to} are connected
    126      * at exactly one common node.</p> 
    127      * 
     127     * at exactly one common node.</p>
     128     *
    128129     * <p>If the result is positive, the way {@code from} bends to the right, if it
    129130     * is negative, the {@code to} bends to the left.</p>
    130      * 
    131      * <p>The two ways must not be null and they must be connected at exactly one 
     131     *
     132     * <p>The two ways must not be null and they must be connected at exactly one
    132133     * common node. They must <strong>not intersect</code> at this node.</p>.
    133      * 
     134     *
    134135     * @param from the from way
    135136     * @param to the to way
    136      * @return the intersection angle 
     137     * @return the intersection angle
    137138     * @throws IllegalArgumentException thrown if the two nodes don't have exactly one common
    138139     * node at which they are connected
    139      * 
    140      */
    141     static public double intersectionAngle(Way from, Way to) throws IllegalArgumentException {
     140     *
     141     */
     142    public static double intersectionAngle(Way from, Way to) throws IllegalArgumentException {
    142143        Node via = getUniqueCommonNode(from, to);
    143144        if (via == null)
    144145            throw new IllegalArgumentException("the two ways must share exactly one common node"); // no I18n required
    145         if (!isStartNode(from, via) && ! isEndNode(from, via))
     146        if (!isStartNode(from, via) && !isEndNode(from, via))
    146147            throw new IllegalArgumentException("via node must be start or end node of from-way"); // no I18n required
    147         if (!isStartNode(to, via) && ! isEndNode(to, via))
     148        if (!isStartNode(to, via) && !isEndNode(to, via))
    148149            throw new IllegalArgumentException("via node must be start or end node of to-way"); // no I18n required
    149150        double phi1 = phi(from, isStartNode(from, via));
    150151        double phi2 = phi(to, isEndNode(to, via));
    151152        return phi1 - phi2;
    152     }   
    153        
    154     static public enum RelativeWayJoinOrientation {
     153    }
     154
     155    public enum RelativeWayJoinOrientation {
    155156        LEFT,
    156157        RIGHT
    157158    }
     159
    158160    /**
    159161     * <p>Determines the orientation in which two ways {@code from} and {@code to}
    160      * are connected, with respect to the direction of the way {@code from}.</p> 
    161      * 
     162     * are connected, with respect to the direction of the way {@code from}.</p>
     163     *
    162164     * <p>The following preconditions must be met:
    163165     *   <ul>
     
    169171     *   </ul>
    170172     * </p>
    171      * 
     173     *
    172174     * <p>Here's a typical configuration:</p>
    173175     * <pre>
     
    178180     *                     |
    179181     * </pre>
    180      * 
     182     *
    181183     * <p>Replies null, if the preconditions aren't met and the method fails to
    182184     *  determine the join orientation.</p>
    183      * 
     185     *
    184186     * @param from the "from"-way
    185187     * @param to the "to"-way
     
    187189     * join orientation
    188190     */
    189     public static RelativeWayJoinOrientation determineWayJoinOrientation(Way from, Way to){
     191    public static RelativeWayJoinOrientation determineWayJoinOrientation(Way from, Way to) {
    190192        Node via = getUniqueCommonNode(from, to);
    191193        if (via == null) return null;
     
    195197        if (isClosedAt(from, via)) return null;
    196198        if (isClosedAt(to, via)) return null;
    197        
     199
    198200        double phi = intersectionAngle(from, to);
    199         if (phi >=0 && phi <= Math.PI) {
     201        if (phi >= 0 && phi <= Math.PI) {
    200202            return RelativeWayJoinOrientation.RIGHT;
    201203        } else {
    202204            return RelativeWayJoinOrientation.LEFT;
    203         } 
    204     }
    205    
     205        }
     206    }
     207
    206208    /**
    207209     * <p>Selects either of the two ways resulting from the split of a way
    208210     * in the role {@link TurnRestrictionLegRole#TO TO}.</p>
    209      * 
     211     *
    210212     * <p>This methods operates on three ways for which the following
    211213     * preconditions must be met:
     
    216218     * </ul>
    217219     * </p>
    218      * 
     220     *
    219221     * <p>Here's a typical configuration:</p>
    220222     * <pre>
     
    225227     *                     |
    226228     * </pre>
    227      * 
     229     *
    228230     * <p>Depending on {@code restrictionType}, this method either returns {@code to1}
    229      * or {@code to2}. If {@code restrictionType} indicates that our context is a 
     231     * or {@code to2}. If {@code restrictionType} indicates that our context is a
    230232     * "left turn", {@code to1} is replied. If our context is a "right turn", {@code to2}
    231233     * is returned.</p>
    232      * 
     234     *
    233235     * <p>Replies null, if the expected preconditions aren't met or if we can't infer
    234236     * from {@code restrictionType} whether our context is a "left turn" or a "right turn".</p>
    235      * 
     237     *
    236238     * @param from the from-way
    237239     * @param to1 the first part of the split to-way
     
    240242     * @return either {@code to1}, {@code to2}, or {@code null}.
    241243     */
    242     static public Way selectToWayAfterSplit(Way from, Way to1, Way to2, TurnRestrictionType restrictionType){
     244    public static Way selectToWayAfterSplit(Way from, Way to1, Way to2, TurnRestrictionType restrictionType) {
    243245        if (restrictionType == null) return null;
    244246        Node cn1 = TurnRestrictionBuilder.getUniqueCommonNode(from, to1);
     
    247249        if (cn2 == null) return null;
    248250        if (cn1 != cn2) return null;
    249        
    250         if (! isStartNode(from, cn1) && ! isEndNode(from, cn1)) {
     251
     252        if (!isStartNode(from, cn1) && !isEndNode(from, cn1)) {
    251253            /*
    252254             * the now split to-way still *intersects* the from-way. We
     
    255257            return null;
    256258        }
    257        
     259
    258260        RelativeWayJoinOrientation o1 = determineWayJoinOrientation(from, to1);
    259261        RelativeWayJoinOrientation o2 = determineWayJoinOrientation(from, to2);
    260        
    261         switch(restrictionType){
     262
     263        switch(restrictionType) {
    262264        case NO_LEFT_TURN:
    263265        case ONLY_LEFT_TURN:
     
    265267            else if (RelativeWayJoinOrientation.LEFT.equals(o2)) return to2;
    266268            else return null;
    267            
     269
    268270        case NO_RIGHT_TURN:
    269271        case ONLY_RIGHT_TURN:
     
    271273            else if (RelativeWayJoinOrientation.RIGHT.equals(o2)) return to2;
    272274            else return null;
    273            
     275
    274276        default:
    275277                /*
     
    280282        }
    281283    }
    282    
    283     public TurnRestrictionBuilder(){
    284     }
    285    
     284
     285    public TurnRestrictionBuilder() {
     286    }
     287
    286288    /**
    287289     * Creates and initializes a new turn restriction based on the primitives
    288290     * currently selected in layer {@code layer}.
    289      * 
     291     *
    290292     * @param layer the layer. Must not be null.
    291293     * @return the new initialized turn restriction. The turn restriction isn't
     
    300302
    301303    /**
    302      * Tries to initialize a No-U-Turn restriction from the primitives in 
     304     * Tries to initialize a No-U-Turn restriction from the primitives in
    303305     * <code>primitives</code>. If successful, replies true, otherwise false.
    304      * 
    305      * @param primitives the primitives 
     306     *
     307     * @param primitives the primitives
    306308     * @return true, if we can propose a U-turn restriction for the primitives
    307309     * in <code>primitives</code>
     
    309311    protected Relation initNoUTurnRestriction(List<OsmPrimitive> primitives) {
    310312        if (primitives.size() != 2) return null;
    311                
     313
    312314        // we need exactly one node and one way in the selection ...
    313315        List<Node> nodes = OsmPrimitive.getFilteredList(primitives, Node.class);
    314316        List<Way> ways = OsmPrimitive.getFilteredList(primitives, Way.class);
    315317        if (nodes.size() != 1 || ways.size() != 1) return null;
    316        
     318
    317319        // .. and the node has to be the start or the node of the way
    318320        Way way = ways.get(0);
     
    320322        List<Node> wayNodes = way.getNodes();
    321323        if (wayNodes.size() < 2) return null; // shouldn't happen - just in case
    322         if (! (wayNodes.get(0).equals(node) ||wayNodes.get(wayNodes.size()-1).equals(node))) return null;
     324        if (!(wayNodes.get(0).equals(node) || wayNodes.get(wayNodes.size()-1).equals(node))) return null;
    323325
    324326        Relation tr = new Relation();
     
    334336     * <p>Replies true, if the ways {@code w1} and {@code w2} are connected
    335337     * at the node {@code n}.</p>
    336      * 
     338     *
    337339     * <p>If {@code w1} and {@code w2} <em>intersect</em> at the node {@code n},
    338340     * this method replies false.</p>
    339      * 
     341     *
    340342     * @param w1 the first way
    341      * @param w2 the second way
    342      * @param n the node
    343      * @return
    344      */
    345     public static boolean isConnectingNode(Way w1, Way w2, Node n){
     343     * @param w2 the second way
     344     * @param n the node
     345     */
     346    public static boolean isConnectingNode(Way w1, Way w2, Node n) {
    346347        if (isStartNode(w1, n)) {
    347             return isStartNode(w2, n)  | isEndNode(w2, n);
    348         } else if (isEndNode(w1, n)){
    349             return isStartNode(w2, n)  | isEndNode(w2, n);
     348            return isStartNode(w2, n) | isEndNode(w2, n);
     349        } else if (isEndNode(w1, n)) {
     350            return isStartNode(w2, n) | isEndNode(w2, n);
    350351        }
    351352        return false;
    352353    }
    353    
     354
    354355    /**
    355356     * Replies true, if the way {@code w} is closed at the node {@code n}.
    356      * 
     357     *
    357358     * @param w the way
    358      * @param n the node 
     359     * @param n the node
    359360     * @return true, if the way {@code w} is closed at the node {@code n}.
    360361     */
    361     public static boolean isClosedAt(Way w, Node n){
     362    public static boolean isClosedAt(Way w, Node n) {
    362363        List<Node> nodes = w.getNodes();
    363364        nodes.retainAll(Collections.singletonList(n));
    364365        return nodes.size() >= 2;
    365366    }
    366    
     367
    367368    protected Relation initTurnRestrictionFromTwoWays(List<OsmPrimitive> primitives) {
    368369        Way w1 = null;
     
    370371        Node via = null;
    371372        if (primitives.size() == 2) {
    372             // if we have exactly two selected primitives, we expect two ways. 
     373            // if we have exactly two selected primitives, we expect two ways.
    373374            // See initNoUTurnRestriction() for the case where we have a selected way
    374375            // and a selected node
     
    378379            w2 = selWays.get(1);
    379380            via = getUniqueCommonNode(w1, w2);
    380         } else if (primitives.size() == 3){
    381             // if we have exactly three selected primitives, we need two ways and a 
    382             // node, which should be an acceptable via node 
     381        } else if (primitives.size() == 3) {
     382            // if we have exactly three selected primitives, we need two ways and a
     383            // node, which should be an acceptable via node
    383384            List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class);
    384385            List<Node> selNodes = OsmPrimitive.getFilteredList(primitives, Node.class);
     
    388389            w2 = selWays.get(1);
    389390            via = selNodes.get(0);
    390             if (! w1.getNodes().contains(via) || ! w2.getNodes().contains(via)){
     391            if (!w1.getNodes().contains(via) || !w2.getNodes().contains(via)) {
    391392                // the selected node is not an acceptable via node
    392393                via = null;
     
    394395        } else {
    395396            // the selection doesn't consists of primitives for which we can build
    396             // a turn restriction 
     397            // a turn restriction
    397398            return null;
    398399        }
    399        
     400
    400401        // if we get here, we know the two "legs" of the turn restriction. We may
    401402        // or may not know a via node, though
    402403        assert w1 != null;
    403404        assert w2 != null;
    404        
     405
    405406        Relation tr = new Relation();
    406407        tr.put("type", "restriction");
    407408        tr.addMember(new RelationMember("from", w1));
    408409        tr.addMember(new RelationMember("to", w2));
    409        
    410         if (via != null){
     410
     411        if (via != null) {
    411412            tr.addMember(new RelationMember("via", via));
    412413            RelativeWayJoinOrientation orientation = determineWayJoinOrientation(w1, w2);
    413             if (orientation != null){
    414                 switch(orientation){
     414            if (orientation != null) {
     415                switch(orientation) {
    415416                case LEFT:
    416417                    tr.put("restriction", TurnRestrictionType.NO_LEFT_TURN.getTagValue());
     
    418419                case RIGHT:
    419420                    tr.put("restriction", TurnRestrictionType.NO_RIGHT_TURN.getTagValue());
    420                     break;                   
     421                    break;
    421422                }
    422423            }
     
    424425        return tr;
    425426    }
    426        
     427
    427428    protected Relation initEmptyTurnRestriction() {
    428429       Relation tr = new Relation();
     
    430431       return tr;
    431432    }
    432    
    433     /**
    434      * Creates and initializes a new turn restriction based on primitives 
     433
     434    /**
     435     * Creates and initializes a new turn restriction based on primitives
    435436     * in {@code primitives}.
    436      * 
    437      * @param primitives the primitives 
     437     *
     438     * @param primitives the primitives
    438439     * @return the new initialized turn restriction. The turn restriction isn't
    439440     * added to the layer yet.
    440441     */
    441     public synchronized Relation build(List<OsmPrimitive> primitives){
     442    public synchronized Relation build(List<OsmPrimitive> primitives) {
    442443        if (primitives == null || primitives.isEmpty()) {
    443444            return initEmptyTurnRestriction();
    444445        }
    445446        Relation tr;
    446         switch(primitives.size()){
    447         // case 0 already handled 
    448         case 1: 
     447        switch(primitives.size()) {
     448        // case 0 already handled
     449        case 1:
    449450            tr = initEmptyTurnRestriction();
    450             if (OsmPrimitive.getFilteredList(primitives, Way.class).size() == 1) {     
     451            if (OsmPrimitive.getFilteredList(primitives, Way.class).size() == 1) {
    451452                // we have exactly one selected way? -> init the "from" leg
    452453                // of the turn restriction with it
     
    454455            }
    455456            return tr;
    456            
     457
    457458        case 2:
    458459            tr = initNoUTurnRestriction(primitives);
     
    461462            if (tr != null) return tr;
    462463            return initEmptyTurnRestriction();
    463            
     464
    464465        default:
    465466            tr = initTurnRestrictionFromTwoWays(primitives);
    466467            if (tr != null) return tr;
    467             return initEmptyTurnRestriction();       
    468         }
    469     }       
     468            return initEmptyTurnRestriction();
     469        }
     470    }
    470471}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionsPlugin.java

    r27891 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions;
    23
     
    1011/**
    1112 * This is the main class for the turnrestrictions plugin.
    12  * 
     13 *
    1314 */
    14 public class TurnRestrictionsPlugin extends Plugin{
    15    
     15public class TurnRestrictionsPlugin extends Plugin {
     16
    1617    public TurnRestrictionsPlugin(PluginInformation info) {
    17         super(info);       
     18        super(info);
    1819    }
    19    
     20
    2021    /**
    21      * Called when the JOSM map frame is created or destroyed. 
     22     * Called when the JOSM map frame is created or destroyed.
    2223     */
    2324    @Override
    24     public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {             
     25    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    2526        if (oldFrame == null && newFrame != null) { // map frame added
    26             TurnRestrictionsListDialog dialog  = new TurnRestrictionsListDialog();
     27            TurnRestrictionsListDialog dialog = new TurnRestrictionsListDialog();
    2728            // add the dialog
    2829            newFrame.addToggleDialog(dialog);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/dnd/PrimitiveIdListProvider.java

    r29854 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.dnd;
    23
     
    89     * Replies the list of currently selected primitive IDs. Replies an empty list if no primitive IDs
    910     * are selected.
    10      * 
     11     *
    1112     * @return the list of currently selected primitive IDs
    1213     */
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/dnd/PrimitiveIdListTransferHandler.java

    r30454 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.dnd;
    23
     
    1112
    1213/**
    13  * <p>PrimitiveIdListTransferHandler is a transfer handler for components which 
     14 * <p>PrimitiveIdListTransferHandler is a transfer handler for components which
    1415 * provide and/or accept a list of {@link PrimitiveId} via copy/paste or
    1516 * drag-and-drop.</p>
    16  * 
     17 *
    1718 * <p>It creates a {@link Transferable} by retrieving the list of primitive IDs
    1819 * from a {@link PrimitiveIdListProvider}.</p>
    19  * 
     20 *
    2021 */
    2122public class PrimitiveIdListTransferHandler extends TransferHandler {
    22     //static private final Logger logger = Logger.getLogger(PrimitiveIdListTransferHandler.class.getName());
    2323    private PrimitiveIdListProvider provider;
    24    
     24
    2525    /**
    2626     * Replies true if {@code transferFlavors} includes the data flavor {@link PrimitiveIdTransferable#PRIMITIVE_ID_LIST_FLAVOR}.
     
    3535        return false;
    3636    }
    37    
     37
    3838    /**
    39      * Creates the transfer handler 
    40      * 
     39     * Creates the transfer handler
     40     *
    4141     * @param provider the provider of the primitive IDs. Must not be null.
    4242     * @throws IllegalArgumentException thrown if provider is null.
    4343     */
    44     public PrimitiveIdListTransferHandler(PrimitiveIdListProvider provider) throws IllegalArgumentException{
     44    public PrimitiveIdListTransferHandler(PrimitiveIdListProvider provider) throws IllegalArgumentException {
    4545        CheckParameterUtil.ensureParameterNotNull(provider, "provider");
    4646        this.provider = provider;
    4747    }
    48    
     48
     49    @Override
    4950    protected Transferable createTransferable(JComponent c) {
    50         return new PrimitiveIdTransferable(provider.getSelectedPrimitiveIds());         
     51        return new PrimitiveIdTransferable(provider.getSelectedPrimitiveIds());
    5152    }
    5253
     54    @Override
    5355    public int getSourceActions(JComponent c) {
    5456        return COPY;
     
    5759    @Override
    5860    public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
    59         return isSupportedFlavor(transferFlavors); 
    60     }   
     61        return isSupportedFlavor(transferFlavors);
     62    }
    6163}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/dnd/PrimitiveIdTransferable.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.dnd;
    23
     
    1415/**
    1516 * To be used for Drag-and-Drop of a set of {@link PrimitiveId}s between
    16  * two components. 
     17 * two components.
    1718 *
    1819 */
    19 public class PrimitiveIdTransferable implements Transferable{
    20    
     20public class PrimitiveIdTransferable implements Transferable {
     21
    2122    /** the data flower for the set of of primitive ids */
    22     static public final DataFlavor PRIMITIVE_ID_LIST_FLAVOR =
     23    public static final DataFlavor PRIMITIVE_ID_LIST_FLAVOR =
    2324        new DataFlavor(Set.class, "a set of OSM primitive ids");
    24    
    25     /** 
     25
     26    /**
    2627     * this transferable supports two flavors: (1) {@link #PRIMITIVE_ID_LIST_FLAVOR} and
    2728     * (2) {@link DataFlavor#stringFlavor}.
    28      * 
     29     *
    2930     * See also {@link #getPrimitiveIds()} and {@link #getAsString()}
    3031     */
    31     static public final DataFlavor[] SUPPORTED_FLAVORS = new DataFlavor[] {
     32    public static final DataFlavor[] SUPPORTED_FLAVORS = new DataFlavor[] {
    3233        PRIMITIVE_ID_LIST_FLAVOR,
    3334        DataFlavor.stringFlavor
    3435    };
    3536
    36    
     37
    3738    private List<PrimitiveId> ids = new ArrayList<>();
    38    
     39
    3940    /**
    4041     * Creates a transferable from a collection of {@link PrimitiveId}s
    41      *
    42      * @param ids
    4342     */
    4443    public PrimitiveIdTransferable(List<PrimitiveId> ids) {
    4544        if (ids == null) return;
    46         for(PrimitiveId id: ids) {
     45        for (PrimitiveId id: ids) {
    4746            this.ids.add(new SimplePrimitiveId(id.getUniqueId(), id.getType()));
    4847        }
    4948    }
    50    
     49
    5150    /**
    5251     * <p>If flavor is {@link #PRIMITIVE_ID_SET_FLAVOR}, replies a the list of
    5352     * transferred {@link PrimitiveId}s</p>
    54      * 
     53     *
    5554     * <p>If flavor is {@link DataFlavor#stringFlavor}, replies a string representation
    5655     * of the list of transferred {@link PrimitiveId}s</p>
    5756     */
     57    @Override
    5858    public Object getTransferData(DataFlavor flavor)
    5959            throws UnsupportedFlavorException, IOException {
     
    6565        throw new UnsupportedFlavorException(flavor);
    6666    }
    67    
     67
    6868    /**
    6969     * Replies the list of OSM primitive ids
    70      * 
     70     *
    7171     * @return the list of OSM primitive ids
    7272     */
     
    7474        return ids;
    7575    }
    76    
     76
    7777    /**
    7878     * Replies a string representation of the list of OSM primitive ids
    79      * 
     79     *
    8080     * @return a string representation of the list of OSM primitive ids
    8181     */
    8282    public String getAsString() {
    8383        StringBuffer sb = new StringBuffer();
    84         for(PrimitiveId id: ids) {
     84        for (PrimitiveId id: ids) {
    8585            if (sb.length() > 0) sb.append(",");
    8686            sb.append(id.getType().getAPIName()).append("/").append(id.getUniqueId());
     
    8989    }
    9090
     91    @Override
    9192    public DataFlavor[] getTransferDataFlavors() {
    9293        return SUPPORTED_FLAVORS;
    9394    }
    9495
     96    @Override
    9597    public boolean isDataFlavorSupported(DataFlavor flavor) {
    96         for(DataFlavor df: SUPPORTED_FLAVORS) {
     98        for (DataFlavor df: SUPPORTED_FLAVORS) {
    9799            if (df.equals(flavor)) return true;
    98100        }
    99101        return false;
    100     }           
     102    }
    101103}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AdvancedEditorPanel.java

    r31562 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    2223 */
    2324public class AdvancedEditorPanel extends JPanel {
    24     //private static final Logger logger = Logger.getLogger(AdvancedEditorPanel.class.getName());
    2525
    2626    private TurnRestrictionEditorModel model;
     
    3131    /**
    3232     * Creates the panel with the tag editor
    33      *
    34      * @return
    3533     */
    3634    protected JPanel buildTagEditorPanel() {
     
    5149    /**
    5250     * Builds the panel with the table for editing relation members
    53      *
    54      * @return
    5551     */
    5652    protected JPanel buildMemberEditorPanel() {
     
    7369    /**
    7470     * Creates the main split panel
    75      * @return
    7671     */
    7772    protected JSplitPane buildSplitPane() {
     
    9994     * @throws IllegalArgumentException thrown if model is null
    10095     */
    101     public AdvancedEditorPanel(TurnRestrictionEditorModel model) throws IllegalArgumentException{
     96    public AdvancedEditorPanel(TurnRestrictionEditorModel model) throws IllegalArgumentException {
    10297        CheckParameterUtil.ensureParameterNotNull(model, "model");
    10398        this.model = model;
     
    111106     */
    112107    class SplitPaneDividerInitializer implements HierarchyListener {
     108        @Override
    113109        public void hierarchyChanged(HierarchyEvent e) {
    114110            if (isShowing()) {
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/BasicEditorPanel.java

    r30365 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    2526 * BasicEditorPanel provides a UI for editing the basic elements of a turn restriction,
    2627 * i.e. its restriction type, the from, the to, and the via objects.
    27  * 
     28 *
    2829 */
    2930public class BasicEditorPanel extends VerticallyScrollablePanel {
     
    3132    /** the turn restriction model */
    3233    private TurnRestrictionEditorModel model;
    33    
     34
    3435    /** the UI widgets */
    3536    private TurnRestrictionLegEditor fromEditor;
     
    4041    private TurnRestrictionComboBox cbTurnRestrictions;
    4142    private VehicleExceptionEditor vehicleExceptionsEditor;
    42    
     43
    4344    /**
    4445     * builds the UI
     
    5051        gc.fill = GridBagConstraints.HORIZONTAL;
    5152        gc.weightx = 0.0;
    52        
     53
    5354        // the editor for selecting the 'from' leg
    54         gc.insets = new Insets(0,0,5,5);   
     55        gc.insets = new Insets(0, 0, 5, 5);
    5556        add(new JLabel(tr("Type:")), gc);
    56        
     57
    5758        gc.gridx = 1;
    5859        gc.weightx = 1.0;
     
    6162        // the editor for selecting the 'from' leg
    6263        gc.gridx = 0;
    63         gc.gridy = 1;   
     64        gc.gridy = 1;
    6465        gc.weightx = 0.0;
    6566        add(new JLabel(tr("From:")), gc);
    66        
     67
    6768        gc.gridx = 1;
    6869        gc.weightx = 1.0;
    69         add(fromEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM),gc);
     70        add(fromEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM), gc);
    7071
    7172        // the editor for selecting the 'to' leg
     
    7374        gc.gridy = 2;
    7475        gc.weightx = 0.0;
    75         gc.insets = new Insets(0,0,5,5);   
     76        gc.insets = new Insets(0, 0, 5, 5);
    7677        add(new JLabel(tr("To:")), gc);
    77        
     78
    7879        gc.gridx = 1;
    7980        gc.weightx = 1.0;
    80         add(toEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.TO),gc);
    81        
    82         // the editor for selecting the 'vias' 
     81        add(toEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.TO), gc);
     82
     83        // the editor for selecting the 'vias'
    8384        gc.gridx = 0;
    8485        gc.gridy = 3;
    8586        gc.weightx = 0.0;
    86         gc.insets = new Insets(0,0,5,5);   
     87        gc.insets = new Insets(0, 0, 5, 5);
    8788        add(lblVias = new JLabel(tr("Vias:")), gc);
    88        
     89
    8990        gc.gridx = 1;
    9091        gc.weightx = 1.0;
     
    9394        spVias = new JScrollPane(lstVias = new ViaList(new ViaListModel(model, selectionModel), selectionModel)) {
    9495            // fixes #6016 : Scrollbar hides field entry
     96            @Override
    9597            public Dimension getPreferredSize() {
    9698                return new Dimension(100, 80); // only height is relevant, 80 is just a heuristical value
    9799             }
    98100        };
    99         add(spVias,gc);
     101        add(spVias, gc);
    100102        if (!Main.pref.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false)) {
    101103            lblVias.setVisible(false);
    102104            spVias.setVisible(false);
    103105        }
    104        
     106
    105107        // the editor for vehicle exceptions
    106108        vehicleExceptionsEditor = new VehicleExceptionEditor(model);
     
    110112        gc.weighty = 0.0;
    111113        gc.gridwidth = 2;
    112         gc.insets = new Insets(0,0,5,5);   
     114        gc.insets = new Insets(0, 0, 5, 5);
    113115        add(vehicleExceptionsEditor, gc);
    114        
    115         // just a filler - grabs remaining space 
     116
     117        // just a filler - grabs remaining space
    116118        gc.gridx = 0;
    117119        gc.gridy = 5;
     
    120122        gc.fill = GridBagConstraints.BOTH;
    121123        add(new JPanel(), gc);
    122            
    123         setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     124
     125        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    124126    }
    125    
    126    
     127
     128
    127129    /**
    128      * Creates the panel. 
    129      * 
     130     * Creates the panel.
     131     *
    130132     * @param model the editor model. Must not be null.
    131133     * @throws IllegalArgumentException thrown if model is null
     
    137139        HelpUtil.setHelpContext(this, HelpUtil.ht("/Plugin/TurnRestrictions#BasicEditor"));
    138140    }
    139    
     141
    140142    /**
    141143     * Requests the focus on one of the input widgets for turn
    142144     * restriction data.
    143      * 
     145     *
    144146     * @param focusTarget the target component to request focus for.
    145147     * Ignored if null.
    146148     */
    147     public void requestFocusFor(BasicEditorFokusTargets focusTarget){
     149    public void requestFocusfor(BasicEditorFokusTargets focusTarget) {
    148150        if (focusTarget == null) return;
    149         switch(focusTarget){
     151        switch(focusTarget) {
    150152        case RESTRICION_TYPE:
    151153            cbTurnRestrictions.requestFocusInWindow();
     
    161163            break;
    162164        }
    163     }   
    164    
     165    }
     166
    165167    /**
    166168     * Initializes the set of icons used from the preference key
    167169     * {@link PreferenceKeys#ROAD_SIGNS}.
    168      * 
    169      * @param prefs the JOSM preferences 
     170     *
     171     * @param prefs the JOSM preferences
    170172     */
    171     public void initIconSetFromPreferences(Preferences prefs){     
     173    public void initIconSetFromPreferences(Preferences prefs) {
    172174        cbTurnRestrictions.initIconSetFromPreferences(prefs);
    173175    }
    174    
     176
    175177    /**
    176178     * Initializes the visibility of the list of via-objects depending
    177179     * on values in the JOSM preferences
    178      * 
     180     *
    179181     * @param prefs the JOSM preferences
    180182     */
    181     public void initViasVisibilityFromPreferences(Preferences prefs){
     183    public void initViasVisibilityFromPreferences(Preferences prefs) {
    182184        boolean value = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false);
    183         if (value != lblVias.isVisible()){
     185        if (value != lblVias.isVisible()) {
    184186            lblVias.setVisible(value);
    185187            spVias.setVisible(value);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ExceptValueModel.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1011/**
    1112 * ExceptValueModel is a model for the value of the tag 'except' in a turn
    12  * restriction. 
     13 * restriction.
    1314 *
    1415 */
     
    1617    /**
    1718     * The set of standard vehicle types which can be used in the
    18      * 'except' tag 
    19      */
    20     static public final Set<String> STANDARD_VEHICLE_EXCEPTION_VALUES;
     19     * 'except' tag
     20     */
     21    public static final Set<String> STANDARD_VEHICLE_EXCEPTION_VALUES;
    2122    static {
    2223        HashSet<String> s = new HashSet<>();
     
    2829        STANDARD_VEHICLE_EXCEPTION_VALUES = Collections.unmodifiableSet(s);
    2930    }
    30    
     31
    3132    /**
    3233     * Replies true, if {@code v} is a standard vehicle type. Replies
    3334     * false if {@code v} is null
    34      * 
    35      * @param v the vehicle type. 
     35     *
     36     * @param v the vehicle type.
    3637     * @return true, if {@code v} is a standard vehicle type.
    3738     */
    38     static public boolean isStandardVehicleExceptionValue(String v){
     39    public static boolean isStandardVehicleExceptionValue(String v) {
    3940        if (v == null) return false;
    4041        v = v.trim().toLowerCase();
    4142        return STANDARD_VEHICLE_EXCEPTION_VALUES.contains(v);
    4243    }
    43        
     44
    4445    private String value = "";
    4546    private boolean isStandard = true;
    4647    private final Set<String> vehicleExceptions = new HashSet<>();
    47    
     48
    4849    protected void parseValue(String value) {
    4950        if (value == null || value.trim().equals("")) value = "";
     
    5354        if (value.equals("")) return;
    5455        String[] values = value.split(";");
    55         for (String v: values){
     56        for (String v: values) {
    5657            v = v.trim().toLowerCase();
    5758            if (isStandardVehicleExceptionValue(v)) {
     
    6263        }
    6364    }
    64    
    65     /**
    66      * Creates a new model for an empty standard value 
     65
     66    /**
     67     * Creates a new model for an empty standard value
    6768     */
    6869    public ExceptValueModel() {}
    69    
    70     /**
    71      * Creates a new model for the tag value {@code value}. 
    72      * 
     70
     71    /**
     72     * Creates a new model for the tag value {@code value}.
     73     *
    7374     * @param value the tag value
    7475     * @see #parseValue(String)
    7576     */
    76     public ExceptValueModel(String value){
    77         if (value == null || value.trim().equals("")) 
     77    public ExceptValueModel(String value) {
     78        if (value == null || value.trim().equals(""))
    7879            return;
    7980        parseValue(value);
     
    8283    /**
    8384     * Replies the tag value representing the state of this model.
    84      *
    85      * @return
    8685     */
    8786    public String getValue() {
    88         if (isStandard){
     87        if (isStandard) {
    8988            StringBuffer sb = new StringBuffer();
    9089            // we use an ordered list because equals()
     
    9392            List<String> values = new ArrayList<>(vehicleExceptions);
    9493            Collections.sort(values);
    95             for (String v: values){
     94            for (String v: values) {
    9695                if (sb.length() > 0) {
    9796                    sb.append(";");
     
    107106    /**
    108107     * Sets the value in this model
    109      *
    110      * @param value
    111108     */
    112109    public void setValue(String value) {
     
    116113    /**
    117114     * Replies true if this model currently holds a standard 'except' value
    118      *
    119      * @return
    120115     */
    121116    public boolean isStandard() {
    122117        return isStandard;
    123     }   
    124    
     118    }
     119
    125120    /**
    126121     * Tells this model to use standard values only.
    127      * 
     122     *
    128123     */
    129124    public void setStandard(boolean isStandard) {
    130125        this.isStandard = isStandard;
    131126    }
    132    
     127
    133128    /**
    134129     * Replies true if {@code vehicleType} is currently set as exception in this
    135130     * model.
    136      * 
     131     *
    137132     * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES}
    138133     * @return true if {@code vehicleType} is currently set as exception in this
    139134     * model.
    140      * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type 
    141      */
    142     public boolean isVehicleException(String vehicleType) throws IllegalArgumentException{
     135     * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type
     136     */
     137    public boolean isVehicleException(String vehicleType) throws IllegalArgumentException {
    143138        if (vehicleType == null) return false;
    144139        if (!isStandardVehicleExceptionValue(vehicleType)) {
     
    148143        return vehicleExceptions.contains(vehicleType);
    149144    }
    150    
     145
    151146    /**
    152147     * Sets the {@code vehicleType} as exception in this turn restriction.
    153      * 
    154      * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES}
    155      * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type 
    156      */
    157     public void setVehicleException(String vehicleType) throws IllegalArgumentException{
     148     *
     149     * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES}
     150     * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type
     151     */
     152    public void setVehicleException(String vehicleType) throws IllegalArgumentException {
    158153        if (!isStandardVehicleExceptionValue(vehicleType)) {
    159154            throw new IllegalArgumentException(MessageFormat.format("vehicleType ''{0}'' isn''t a valid standard vehicle type", vehicleType));
     
    161156        vehicleExceptions.add(vehicleType.trim().toLowerCase());
    162157    }
    163    
     158
    164159
    165160    /**
    166161     * Sets or removes the {@code vehicleType} as exception in this turn restriction, depending
    167162     * on whether {@code setOrRemove} is true or false, respectively.
    168      * 
     163     *
    169164     * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES}
    170165     * @param setOrRemove if true, the exception is set; otherwise, it is removed
    171      * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type 
    172      */
    173     public void setVehicleException(String vehicleType, boolean setOrRemove) throws IllegalArgumentException{
    174         if (setOrRemove){
     166     * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type
     167     */
     168    public void setVehicleException(String vehicleType, boolean setOrRemove) throws IllegalArgumentException {
     169        if (setOrRemove) {
    175170            setVehicleException(vehicleType);
    176171        } else {
     
    178173        }
    179174    }
    180    
     175
    181176    /**
    182177     * Removes the {@code vehicleType} as exception in this turn restriction
    183      * 
    184      * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES}
    185      * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type 
    186      */
    187     public void removeVehicleException(String vehicleType) throws IllegalArgumentException{
     178     *
     179     * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES}
     180     * @exception IllegalArgumentException thrown if {@code vehicleType} isn't a standard vehicle type
     181     */
     182    public void removeVehicleException(String vehicleType) throws IllegalArgumentException {
    188183        if (!isStandardVehicleExceptionValue(vehicleType)) {
    189184            throw new IllegalArgumentException(MessageFormat.format("vehicleType ''{0}'' isn''t a valid standard vehicle type", vehicleType));
     
    210205        ExceptValueModel other = (ExceptValueModel) obj;
    211206        return getValue().equals(other.getValue());
    212     }       
     207    }
    213208}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java

    r32375 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    3536 *
    3637 */
    37 public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive> implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider{
    38     //static private final Logger logger = Logger.getLogger(JosmSelectionListModel.class.getName());
     38public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive>
     39    implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider {
    3940
    4041    private final List<OsmPrimitive> selection = new ArrayList<>();
     
    7374    public Collection<OsmPrimitive> getSelected() {
    7475        Set<OsmPrimitive> sel = new HashSet<>();
    75         for(int i=0; i< getSize();i++) {
     76        for (int i = 0; i < getSize(); i++) {
    7677            if (selectionModel.isSelectedIndex(i)) {
    7778                sel.add(selection.get(i));
     
    8990        selectionModel.clearSelection();
    9091        if (sel == null) return;
    91         for (OsmPrimitive p: sel){
     92        for (OsmPrimitive p: sel) {
    9293            int i = selection.indexOf(p);
    93             if (i >= 0){
     94            if (i >= 0) {
    9495                selectionModel.addSelectionInterval(i, i);
    9596            }
     
    136137        if (toUpdate.isEmpty()) return;
    137138        Collection<OsmPrimitive> sel = getSelected();
    138         for (OsmPrimitive p: toUpdate){
     139        for (OsmPrimitive p: toUpdate) {
    139140            int i = selection.indexOf(p);
    140141            if (i >= 0) {
    141                 super.fireContentsChanged(this, i,i);
     142                super.fireContentsChanged(this, i, i);
    142143            }
    143144        }
     
    158159            // don't show a JOSM selection if we don't have a data layer
    159160            setJOSMSelection(null);
    160         } else if (newLayer != layer){
     161        } else if (newLayer != layer) {
    161162            // don't show a JOSM selection if this turn restriction editor doesn't
    162163            // manipulate data in the current data layer
     
    175176        // this turn restriction editor is working on
    176177        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    177         if(layer == null) return;
     178        if (layer == null) return;
    178179        if (layer != this.layer) return;
    179180        setJOSMSelection(newSelection);
     
    226227    @Override
    227228    public void primitivesAdded(PrimitivesAddedEvent event) {/* ignored - handled by SelectionChangeListener */}
     229
    228230    @Override
    229231    public void primitivesRemoved(PrimitivesRemovedEvent event) {/* ignored - handled by SelectionChangeListener*/}
     
    235237    public List<PrimitiveId> getSelectedPrimitiveIds() {
    236238        List<PrimitiveId> ret = new ArrayList<>(getSelected().size());
    237         for(int i=0; i< selection.size(); i++) {
     239        for (int i = 0; i < selection.size(); i++) {
    238240            if (selectionModel.isSelectedIndex(i)) {
    239241                ret.add(selection.get(i).getPrimitiveId());
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java

    r32386 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    6465        add(new JLabel(tr("Selection")), BorderLayout.NORTH);
    6566
    66         setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     67        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    6768        actCopy = new CopyAction();
    6869        lstSelection.addMouseListener(new PopupLauncher());
     
    7576     * @exception IllegalArgumentException thrown if {@code layer} is null
    7677     */
    77     public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException{
     78    public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException {
    7879        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    7980        this.model = model;
     
    107108
    108109    class PopupMenu extends JPopupMenu {
    109         public PopupMenu() {
     110        PopupMenu() {
    110111            JMenuItem item = add(actCopy);
    111112            item.setTransferHandler(transferHandler);
     
    117118        private Action delegate;
    118119
    119         public CopyAction(){
     120        CopyAction() {
    120121            putValue(NAME, tr("Copy"));
    121122            putValue(SHORT_DESCRIPTION, tr("Copy to the clipboard"));
     
    131132    }
    132133
    133     static private class JosmSelectionTransferHandler extends PrimitiveIdListTransferHandler {
    134         public JosmSelectionTransferHandler(PrimitiveIdListProvider provider) {
     134    private static class JosmSelectionTransferHandler extends PrimitiveIdListTransferHandler {
     135        JosmSelectionTransferHandler(PrimitiveIdListProvider provider) {
    135136            super(provider);
    136137        }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/MemberRoleCellEditor.java

    r30938 r32519  
    1515/**
    1616 * The cell editor for member roles of relation members in a turn restriction.
    17  * 
     17 *
    1818 */
    1919public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor {
    20     //static private Logger logger = Logger.getLogger(MemberRoleCellEditor.class.getName());
     20    //private static Logger logger = Logger.getLogger(MemberRoleCellEditor.class.getName());
    2121
    2222    private AutoCompletingTextField editor = null;
     
    4141     * replies the table cell editor
    4242     */
     43    @Override
    4344    public Component getTableCellEditorComponent(JTable table,
    4445            Object value, boolean isSelected, int row, int column) {
    4546
    46         String role = (String)value;
    47         editor.setText(role);       
     47        String role = (String) value;
     48        editor.setText(role);
    4849        return editor;
    4950    }
    5051
     52    @Override
    5153    public Object getCellEditorValue() {
    5254        return editor.getText();
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/NavigationControler.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
    34public interface NavigationControler {
    4     public enum BasicEditorFokusTargets {
     5    enum BasicEditorFokusTargets {
    56        RESTRICION_TYPE,
    67        FROM,
    78        TO,
    89        VIA
    9     }   
    10     void gotoBasicEditor();
     10    }
     11
     12    void gotoBasicEditor();
     13
    1114    void gotoAdvancedEditor();
    12     void gotoBasicEditor(BasicEditorFokusTargets focusTarget); 
     15
     16    void gotoBasicEditor(BasicEditorFokusTargets focusTarget);
    1317}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberColumnModel.java

    r23526 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1415 * displayed in the {@link AdvancedEditorPanel}.
    1516 */
    16 public class RelationMemberColumnModel extends DefaultTableColumnModel{
     17public class RelationMemberColumnModel extends DefaultTableColumnModel {
    1718    protected void build() {
    1819        TableColumn col = new TableColumn();
    19        
     20
    2021         // the role column
    2122         col.setHeaderValue(tr("Role"));
    2223         col.setResizable(true);
    23          col.setPreferredWidth(100);   
     24         col.setPreferredWidth(100);
    2425         col.setCellEditor(new MemberRoleCellEditor());
    2526         addColumn(col);
    26          
     27
    2728          // column 1 - the member
    2829          col = new TableColumn(1);
     
    3132          col.setPreferredWidth(300);
    3233          col.setCellRenderer(new OsmPrimitivRenderer());
    33           addColumn(col);         
     34          addColumn(col);
    3435    }
    35    
     36
    3637    /**
    3738     * Creates the column model with a given column selection model.
    38      * 
     39     *
    3940     * @param colSelectionModel the column selection model. Must not be null.
    4041     * @throws IllegalArgumentException thrown if {@code colSelectionModel} is null
    4142     */
    42     public RelationMemberColumnModel(DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException{
     43    public RelationMemberColumnModel(DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException {
    4344        CheckParameterUtil.ensureParameterNotNull(colSelectionModel, "colSelectionModel");
    4445        setSelectionModel(colSelectionModel);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberEditorModel.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    2 
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     
    2323import org.openstreetmap.josm.tools.CheckParameterUtil;
    2424
    25 public class RelationMemberEditorModel extends AbstractTableModel{ 
    26     //static private final Logger logger = Logger.getLogger(RelationMemberEditorModel.class.getName());
     25public class RelationMemberEditorModel extends AbstractTableModel {
    2726    private final ArrayList<RelationMemberModel> members = new ArrayList<>();
    2827    private OsmDataLayer layer;
    2928    private DefaultListSelectionModel rowSelectionModel;
    3029    private DefaultListSelectionModel colSelectionModel;
    31    
     30
    3231    /**
    3332     * Creates a new model in the context of an {@link OsmDataLayer}. Internally allocates
    34      * a row and a column selection model, see {@link #getRowSelectionModel()} and 
     33     * a row and a column selection model, see {@link #getRowSelectionModel()} and
    3534     * {@link #getColSelectionModel()}.
    36      * 
     35     *
    3736     * @param layer the data layer. Must not be null.
    3837     * @exception IllegalArgumentException thrown if layer is null
    3938     */
    40     public RelationMemberEditorModel(OsmDataLayer layer) throws IllegalArgumentException{
     39    public RelationMemberEditorModel(OsmDataLayer layer) throws IllegalArgumentException {
    4140        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    4241        this.layer = layer;
     
    4746    /**
    4847     *  Creates a new model in the context of an {@link OsmDataLayer}
    49      * 
     48     *
    5049     * @param layer layer the data layer. Must not be null.
    5150     * @param rowSelectionModel the row selection model. Must not be null.
     
    5554     * @throws IllegalArgumentException thrown if colSelectionModel is null
    5655     */
    57     public RelationMemberEditorModel(OsmDataLayer layer, DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException{
     56    public RelationMemberEditorModel(OsmDataLayer layer, DefaultListSelectionModel rowSelectionModel,
     57            DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException {
    5858        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    5959        CheckParameterUtil.ensureParameterNotNull(rowSelectionModel, "rowSelectionModel");
     
    6666    /**
    6767     * Replies the row selection model used in this table model.
    68      * 
    69      * @return the row selection model 
     68     *
     69     * @return the row selection model
    7070     */
    7171    public DefaultListSelectionModel getRowSelectionModel() {
    7272        return rowSelectionModel;
    7373    }
    74    
     74
    7575    /**
    7676     * Replies the column selection model used in this table model.
    77      * 
     77     *
    7878     * @return the col selection model
    7979     */
     
    8181        return colSelectionModel;
    8282    }
    83    
     83
    8484    /**
    8585     * Replies the set of {@link OsmPrimitive}s with the role {@code role}. If no
    8686     * such primitives exists, the empty set is returned.
    87      * 
     87     *
    8888     * @return the set of {@link OsmPrimitive}s with the role {@code role}
    8989     */
    9090    protected Set<OsmPrimitive> getPrimitivesWithRole(String role) {
    9191        HashSet<OsmPrimitive> ret = new HashSet<>();
    92         for (RelationMemberModel rm: members){
    93             if (rm.getRole().equals(role)){
     92        for (RelationMemberModel rm: members) {
     93            if (rm.getRole().equals(role)) {
    9494                OsmPrimitive p = layer.data.getPrimitiveById(rm.getTarget());
    95                 if (p != null){
     95                if (p != null) {
    9696                    ret.add(p);
    9797                }
     
    100100        return ret;
    101101    }
    102    
     102
    103103    /**
    104104     * Replies the list of {@link RelationMemberModel}s with the role {@code role}. If no
    105105     * such primitives exists, the empty set is returned.
    106      * 
     106     *
    107107     * @return the set of {@link RelationMemberModel}s with the role {@code role}
    108108     */
    109109    protected List<RelationMemberModel> getRelationMembersWithRole(String role) {
    110110        ArrayList<RelationMemberModel> ret = new ArrayList<>();
    111         for (RelationMemberModel rm: members){
    112             if (rm.getRole().equals(role)){
     111        for (RelationMemberModel rm: members) {
     112            if (rm.getRole().equals(role)) {
    113113                ret.add(rm);
    114114            }
     
    116116        return ret;
    117117    }
    118    
     118
    119119    /**
    120120     * Removes all members with role {@code role}.
    121      * 
     121     *
    122122     * @param role the role. Ignored if null.
    123123     * @return true if the list of members was modified; false, otherwise
    124124     */
    125     protected boolean removeMembersWithRole(String role){
     125    protected boolean removeMembersWithRole(String role) {
    126126        if (role == null) return false;
    127127        boolean isChanged = false;
    128         for(Iterator<RelationMemberModel> it = members.iterator(); it.hasNext(); ){
     128        for (Iterator<RelationMemberModel> it = members.iterator(); it.hasNext();) {
    129129            RelationMemberModel rm = it.next();
    130130            if (rm.getRole().equals(role)) {
     
    135135        return isChanged;
    136136    }
    137        
     137
    138138    /**
    139139     * Replies the set of {@link OsmPrimitive}s with the role 'from'. If no
    140140     * such primitives exists, the empty set is returned.
    141      * 
     141     *
    142142     * @return the set of {@link OsmPrimitive}s with the role 'from'
    143143     */
    144144    public Set<OsmPrimitive> getFromPrimitives() {
    145         return getPrimitivesWithRole("from");       
    146     }
    147    
     145        return getPrimitivesWithRole("from");
     146    }
     147
    148148    /**
    149149     * Replies the set of {@link OsmPrimitive}s with the role 'to'. If no
    150150     * such primitives exists, the empty set is returned.
    151      * 
     151     *
    152152     * @return the set of {@link OsmPrimitive}s with the role 'from'
    153153     */
     
    155155        return getPrimitivesWithRole("to");
    156156    }
    157    
     157
    158158    /**
    159159     * Replies the list of 'via' objects in the order they occur in the
    160160     * member list. Replies an empty list if no vias exist
    161      *
    162      * @return
    163161     */
    164162    public List<OsmPrimitive> getVias() {
    165163        ArrayList<OsmPrimitive> ret = new ArrayList<>();
    166         for (RelationMemberModel rm: getRelationMembersWithRole("via")){
     164        for (RelationMemberModel rm: getRelationMembersWithRole("via")) {
    167165            ret.add(layer.data.getPrimitiveById(rm.getTarget()));
    168166        }
    169167        return ret;
    170168    }
    171    
     169
    172170    /**
    173171     * Sets the list of vias. Removes all 'vias' if {@code vias} is null.
    174      * 
     172     *
    175173     * null vias are skipped. A via must belong to the dataset of the layer in whose context
    176174     * this editor is working, otherwise an {@link IllegalArgumentException} is thrown.
    177      * 
     175     *
    178176     * @param vias the vias.
    179177     * @exception IllegalArgumentException thrown if a via doesn't belong to the dataset of the layer
    180      * in whose context this editor is working 
    181      */
    182     public void setVias(List<OsmPrimitive> vias) throws IllegalArgumentException{
     178     * in whose context this editor is working
     179     */
     180    public void setVias(List<OsmPrimitive> vias) throws IllegalArgumentException {
    183181        boolean viasDeleted = removeMembersWithRole("via");
    184         if (vias == null || vias.isEmpty()){
    185             if (viasDeleted){
     182        if (vias == null || vias.isEmpty()) {
     183            if (viasDeleted) {
    186184                fireTableDataChanged();
    187185            }
    188186            return;
    189187        }
    190         // check vias 
     188        // check vias
    191189        for (OsmPrimitive via: vias) {
    192190            if (via == null) continue;
    193             if (via.getDataSet() == null || via.getDataSet() != layer.data){
    194                 throw new IllegalArgumentException(MessageFormat.format("via object ''{0}'' must belong to dataset of layer ''{1}''", via.getDisplayName(DefaultNameFormatter.getInstance()), layer.getName()));
    195             }
    196         }
    197         // add vias
     191            if (via.getDataSet() == null || via.getDataSet() != layer.data) {
     192                throw new IllegalArgumentException(MessageFormat.format("via object ''{0}'' must belong to dataset of layer ''{1}''",
     193                        via.getDisplayName(DefaultNameFormatter.getInstance()), layer.getName()));
     194            }
     195        }
     196        // add vias
    198197        for (OsmPrimitive via: vias) {
    199198            if (via == null) continue;
     
    203202        fireTableDataChanged();
    204203    }
    205    
     204
    206205    /**
    207206     * Sets the turn restriction member with role {@code role}. Removes all
    208207     * members with role {@code role} if {@code id} is null.
    209      * 
    210      * @param id the id 
     208     *
     209     * @param id the id
    211210     * @return true if the model was modified; false, otherwise
    212211     */
    213     protected boolean setPrimitiveWithRole(PrimitiveId id, String role){
    214         if (id == null){
     212    protected boolean setPrimitiveWithRole(PrimitiveId id, String role) {
     213        if (id == null) {
    215214            return removeMembersWithRole(role);
    216215        }
    217        
     216
    218217        List<RelationMemberModel> fromMembers = getRelationMembersWithRole(role);
    219         if (fromMembers.isEmpty()){
     218        if (fromMembers.isEmpty()) {
    220219            RelationMemberModel rm = new RelationMemberModel(role, id);
    221220            members.add(rm);
    222221            return true;
    223         } else if (fromMembers.size() == 1){
     222        } else if (fromMembers.size() == 1) {
    224223            RelationMemberModel rm = fromMembers.get(0);
    225             if (!rm.getTarget().equals(id)){
     224            if (!rm.getTarget().equals(id)) {
    226225                rm.setTarget(id);
    227226                return true;
     
    235234        }
    236235    }
    237    
     236
    238237    /**
    239238     * Sets the turn restriction member with role 'from'. Removes all
    240239     * members with role 'from' if {@code id} is null.
    241      * 
    242      * @param id the id 
    243      */
    244     public void setFromPrimitive(PrimitiveId id){
     240     *
     241     * @param id the id
     242     */
     243    public void setFromPrimitive(PrimitiveId id) {
    245244        if (setPrimitiveWithRole(id, "from")) {
    246245            fireTableDataChanged();
    247246        }
    248247    }
    249    
     248
    250249    /**
    251250     * Sets the turn restriction member with role 'to'. Removes all
    252251     * members with role 'to' if {@code id} is null.
    253      * 
    254      * @param id the id 
    255      */
    256     public void setToPrimitive(PrimitiveId id){
     252     *
     253     * @param id the id
     254     */
     255    public void setToPrimitive(PrimitiveId id) {
    257256        if (setPrimitiveWithRole(id, "to")) {
    258257            fireTableDataChanged();
    259258        }
    260259    }
    261    
     260
    262261    /**
    263262     * Replies the set of {@link OsmPrimitive}s referred to by members in
    264263     * this model.
    265      * 
     264     *
    266265     * @return the set of {@link OsmPrimitive}s referred to by members in
    267266     * this model.
     
    269268    public Set<OsmPrimitive> getMemberPrimitives() {
    270269        Set<OsmPrimitive> ret = new HashSet<>();
    271         for (RelationMemberModel rm: members){
     270        for (RelationMemberModel rm: members) {
    272271            OsmPrimitive p = layer.data.getPrimitiveById(rm.getTarget());
    273272            if (p != null) ret.add(p);
     
    275274        return ret;
    276275    }
    277    
     276
    278277    /**
    279278     * Populates the model with the relation member of a turn restriction. Clears
    280      * the model if {@code tr} is null. 
    281      * 
     279     * the model if {@code tr} is null.
     280     *
    282281     * @param tr the turn restriction
    283282     */
    284     public void populate(Relation tr){
     283    public void populate(Relation tr) {
    285284        members.clear();
    286         if (tr == null){
     285        if (tr == null) {
    287286            fireTableDataChanged();
    288287            return;
    289288        }
    290         for(RelationMember rm: tr.getMembers()){
     289        for (RelationMember rm: tr.getMembers()) {
    291290            members.add(new RelationMemberModel(rm));
    292291        }
    293292        fireTableDataChanged();
    294293    }
    295    
     294
    296295    /**
    297296     * Replaces the member of turn restriction {@code tr} by the relation members currently
    298297     * edited in this model.
    299      * 
     298     *
    300299     * @param tr the turn restriction. Ignored if null.
    301300     */
    302     public void applyTo(Relation tr){
     301    public void applyTo(Relation tr) {
    303302        if (tr == null) return;
    304303        List<RelationMember> newMembers = new ArrayList<>();
    305         for(RelationMemberModel model: members){
     304        for (RelationMemberModel model: members) {
    306305            RelationMember rm = new RelationMember(model.getRole(), layer.data.getPrimitiveById(model.getTarget()));
    307306            newMembers.add(rm);
     
    309308        tr.setMembers(newMembers);
    310309    }
    311    
    312     /**
    313      * Clears the roles of all relation members currently selected in the 
     310
     311    /**
     312     * Clears the roles of all relation members currently selected in the
    314313     * table.
    315314     */
    316     protected void clearSelectedRoles(){
    317         for(int i=0; i < getRowCount();i++){
     315    protected void clearSelectedRoles() {
     316        for (int i = 0; i < getRowCount(); i++) {
    318317            if (rowSelectionModel.isSelectedIndex(i)) {
    319318                members.get(i).setRole("");
    320319            }
    321         }       
    322     }
    323    
    324     /**
    325      * Removes the currently selected rows from the model 
     320        }
     321    }
     322
     323    /**
     324     * Removes the currently selected rows from the model
    326325     */
    327326    protected void removedSelectedMembers() {
    328         for(int i=getRowCount()-1; i >= 0;i--){
     327        for (int i = getRowCount()-1; i >= 0; i--) {
    329328            if (rowSelectionModel.isSelectedIndex(i)) {
    330329                members.remove(i);
     
    332331        }
    333332    }
    334    
     333
    335334    /**
    336335     * Deletes the current selection.
    337      * 
     336     *
    338337     * If only cells in the first column are selected, the roles of the selected
    339338     * members are reset to the empty string. Otherwise the selected members are
    340      * removed from the model. 
    341      * 
     339     * removed from the model.
     340     *
    342341     */
    343342    public void deleteSelected() {
    344343        if (colSelectionModel.isSelectedIndex(0) && !colSelectionModel.isSelectedIndex(1)) {
    345344            clearSelectedRoles();
    346         } else if (rowSelectionModel.getMinSelectionIndex() >= 0){
     345        } else if (rowSelectionModel.getMinSelectionIndex() >= 0) {
    347346            removedSelectedMembers();
    348347        }
    349348        fireTableDataChanged();
    350349    }
    351    
     350
    352351    protected List<Integer> getSelectedIndices() {
    353352        ArrayList<Integer> ret = new ArrayList<>();
    354         for(int i =0; i < members.size(); i++){
    355             if (rowSelectionModel.isSelectedIndex(i)) 
     353        for (int i = 0; i < members.size(); i++) {
     354            if (rowSelectionModel.isSelectedIndex(i))
    356355                ret.add(i);
    357356        }
    358357        return ret;
    359358    }
    360    
     359
    361360    public boolean canMoveUp() {
    362361        List<Integer> sel = getSelectedIndices();
     
    364363        return sel.get(0) > 0;
    365364    }
    366    
     365
    367366    public boolean canMoveDown() {
    368367        List<Integer> sel = getSelectedIndices();
     
    370369        return sel.get(sel.size()-1) < members.size()-1;
    371370    }
    372    
     371
    373372    public void moveUpSelected() {
    374373        if (!canMoveUp()) return;
    375374        List<Integer> sel = getSelectedIndices();
    376         for (int idx: sel){
     375        for (int idx: sel) {
    377376            RelationMemberModel m = members.remove(idx);
    378377            members.add(idx-1, m);
     
    381380        rowSelectionModel.clearSelection();
    382381        colSelectionModel.setSelectionInterval(0, 1);
    383         for (int idx: sel){
     382        for (int idx: sel) {
    384383            rowSelectionModel.addSelectionInterval(idx-1, idx-1);
    385384        }
    386385    }
    387    
     386
    388387    public void moveDownSelected() {
    389388        if (!canMoveDown()) return;
    390389        List<Integer> sel = getSelectedIndices();
    391         for (int i = sel.size()-1; i>=0;i--){
     390        for (int i = sel.size()-1; i >= 0; i--) {
    392391            int idx = sel.get(i);
    393392            RelationMemberModel m = members.remove(idx);
     
    397396        rowSelectionModel.clearSelection();
    398397        colSelectionModel.setSelectionInterval(0, 1);
    399         for (int idx: sel){
     398        for (int idx: sel) {
    400399            rowSelectionModel.addSelectionInterval(idx+1, idx+1);
    401400        }
    402401    }
    403    
     402
    404403    /**
    405404     * <p>Inserts a list of new relation members with the empty role for the primitives
    406405     * with id in {@code ids}. Inserts the new primitives at the position of the first
    407406     * selected row. If no row is selected, at the end of the list.</p>
    408      * 
    409      * <p> null values are skipped. If there is an id for which there is no primitive in the context 
     407     *
     408     * <p> null values are skipped. If there is an id for which there is no primitive in the context
    410409     *  layer, if the primitive is deleted or invisible, an {@link IllegalArgumentException}
    411410     *  is thrown and nothing is inserted.</p>
    412      * 
     411     *
    413412     * @param ids the list of ids. Ignored if null.
    414413     * @throws IllegalArgumentException thrown if one of the ids can't be inserted
    415414     */
    416415    public void insertMembers(Collection<PrimitiveId> ids) throws IllegalArgumentException {
    417         if (ids == null) return;   
     416        if (ids == null) return;
    418417        ArrayList<RelationMemberModel> newMembers = new ArrayList<>();
    419         for (PrimitiveId id: ids){
     418        for (PrimitiveId id: ids) {
    420419            OsmPrimitive p = layer.data.getPrimitiveById(id);
    421             if (p == null){
     420            if (p == null) {
    422421                throw new IllegalArgumentException(tr("Cannot find object with id ''{0}'' in layer ''{1}''", id.toString(), layer.getName()));
    423422            }
    424             if (p.isDeleted() || ! p.isVisible()) {
    425                 throw new IllegalArgumentException(tr("Cannot add object ''{0}'' as relation member because it is deleted or invisible in layer ''{1}''", p.getDisplayName(DefaultNameFormatter.getInstance()), layer.getName()));             
    426             }
    427             newMembers.add(new RelationMemberModel("",id));
     423            if (p.isDeleted() || !p.isVisible()) {
     424                throw new IllegalArgumentException(
     425                        tr("Cannot add object ''{0}'' as relation member because it is deleted or invisible in layer ''{1}''",
     426                        p.getDisplayName(DefaultNameFormatter.getInstance()), layer.getName()));
     427            }
     428            newMembers.add(new RelationMemberModel("", id));
    428429        }
    429430        if (newMembers.isEmpty()) return;
    430431        int insertPos = rowSelectionModel.getMinSelectionIndex();
    431         if ( insertPos >=0){
     432        if (insertPos >= 0) {
    432433            members.addAll(insertPos, newMembers);
    433434        } else {
     
    435436        }
    436437        fireTableDataChanged();
    437         if (insertPos < 0) insertPos = 0;       
     438        if (insertPos < 0) insertPos = 0;
    438439        colSelectionModel.setSelectionInterval(0, 1); // select both columns
    439440        rowSelectionModel.setSelectionInterval(insertPos, insertPos + newMembers.size()-1);
    440441    }
    441442
     443    @Override
    442444    public int getColumnCount() {
    443445        return 2;
    444446    }
    445447
     448    @Override
    446449    public int getRowCount() {
    447450        return members.size();
    448451    }
    449452
     453    @Override
    450454    public Object getValueAt(int rowIndex, int columnIndex) {
    451         switch(columnIndex){
     455        switch(columnIndex) {
    452456        case 0: return members.get(rowIndex).getRole();
    453457        case 1: return layer.data.getPrimitiveById(members.get(rowIndex).getTarget());
     
    464468    @Override
    465469    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    466         if (columnIndex !=0)return;
    467         String role = (String)aValue;
     470        if (columnIndex != 0) return;
     471        String role = (String) aValue;
    468472        RelationMemberModel model = members.get(rowIndex);
    469473        model.setRole(role);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberModel.java

    r23510 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1516 *
    1617 */
    17 public class RelationMemberModel implements Serializable{
     18public class RelationMemberModel implements Serializable {
    1819    private String role;
    1920    private SimplePrimitiveId target;
    20    
     21
    2122    /**
    2223     * Creates a new relation member model
    23      * 
     24     *
    2425     * @param role the member role. Reset to "" if null.
    2526     * @param target the id of the target object. Must not be null.
     
    2829    public RelationMemberModel(String role, PrimitiveId target) throws IllegalArgumentException {
    2930        CheckParameterUtil.ensureParameterNotNull(target, "target");
    30         this.role = role == null? "" : role;
     31        this.role = role == null ? "" : role;
    3132        this.target = new SimplePrimitiveId(target.getUniqueId(), target.getType());
    3233    }
    33    
     34
    3435    /**
    35      * Creates a new relation member model from a relation member 
    36      * 
     36     * Creates a new relation member model from a relation member
     37     *
    3738     * @param member the relation member. Must not be null.
    3839     * @throws IllegalArgumentException thrown if {@code member} is null
    3940     */
    40     public RelationMemberModel(RelationMember member) throws IllegalArgumentException{
     41    public RelationMemberModel(RelationMember member) throws IllegalArgumentException {
    4142        CheckParameterUtil.ensureParameterNotNull(member, "member");
    4243        this.role = member.getRole();
     
    4647    /**
    4748     * Replies the current role in this model. Never null.
    48      * 
     49     *
    4950     * @return the current role in this model
    5051     */
     
    5455
    5556    /**
    56      * Sets the current role in this model. 
    57      * 
     57     * Sets the current role in this model.
     58     *
    5859     * @param role the role. Reset to "" if null.
    5960     */
    6061    public void setRole(String role) {
    61         this.role = role == null? "" : role;
     62        this.role = role == null ? "" : role;
    6263    }
    6364
    6465    /**
    6566     * Replies the id of the target object of this relation member.
    66      * 
     67     *
    6768     * @return the id of the target object of this relation member.
    6869     */
     
    7273
    7374    /**
    74      * Sets the id of the target object. 
    75      * 
     75     * Sets the id of the target object.
     76     *
    7677     * @param target the id of the target object. Must not be null.
    7778     * @throws IllegalArgumentException thrown if {@code target} is null
    7879     */
    79     public void setTarget(PrimitiveId target) throws IllegalArgumentException{
     80    public void setTarget(PrimitiveId target) throws IllegalArgumentException {
    8081        CheckParameterUtil.ensureParameterNotNull(target, "target");
    8182        this.target = new SimplePrimitiveId(target.getUniqueId(), target.getType());
    8283    }
    83    
     84
    8485    @Override
    8586    public int hashCode() {
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberTable.java

    r32386 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    7475        actDelete = new DeleteAction();
    7576        model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actDelete);
    76         registerKeyboardAction(actDelete, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     77        registerKeyboardAction(actDelete, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    7778
    7879        // initialize the paste action (will be used in the popup, the action map already includes
     
    8283        actMoveUp = new MoveUpAction();
    8384        model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actMoveUp);
    84         registerKeyboardAction(actMoveUp,actMoveUp.getKeyStroke(), WHEN_FOCUSED);
     85        registerKeyboardAction(actMoveUp, actMoveUp.getKeyStroke(), WHEN_FOCUSED);
    8586
    8687        actMoveDown = new MoveDownAction();
     
    9394     *
    9495     */
    95     class DeleteAction extends AbstractAction implements ListSelectionListener{
    96         public DeleteAction() {
     96    class DeleteAction extends AbstractAction implements ListSelectionListener {
     97        DeleteAction() {
    9798            putValue(NAME, tr("Delete"));
    9899            putValue(SHORT_DESCRIPTION, tr("Clear the selected roles or delete the selected members"));
    99100            new ImageProvider("deletesmall").getResource().attachImageIcon(this);
    100             putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0));
     101            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
    101102            updateEnabledState();
    102103        }
    103104
    104105        public void updateEnabledState() {
    105             setEnabled(model.getRelationMemberEditorModel().getRowSelectionModel().getMinSelectionIndex()>=0);
    106         }
    107 
     106            setEnabled(model.getRelationMemberEditorModel().getRowSelectionModel().getMinSelectionIndex() >= 0);
     107        }
     108
     109        @Override
    108110        public void actionPerformed(ActionEvent e) {
    109111            model.getRelationMemberEditorModel().deleteSelected();
    110112        }
    111113
     114        @Override
    112115        public void valueChanged(ListSelectionEvent e) {
    113116            updateEnabledState();
     
    119122     *
    120123     */
    121     class PasteAction extends AbstractAction{
    122         public PasteAction() {
     124    class PasteAction extends AbstractAction {
     125        PasteAction() {
    123126            putValue(NAME, tr("Paste"));
    124127            putValue(SHORT_DESCRIPTION, tr("Insert new relation members from object in the clipboard"));
     
    133136        }
    134137
     138        @Override
    135139        @SuppressWarnings("unchecked")
    136140        public void actionPerformed(ActionEvent evt) {
     
    143147            try {
    144148                List<PrimitiveId> ids;
    145                 ids = (List<PrimitiveId>)cp.getData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
     149                ids = (List<PrimitiveId>) cp.getData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
    146150                try {
    147151                    model.getRelationMemberEditorModel().insertMembers(ids);
    148                 } catch(IllegalArgumentException e){
     152                } catch (IllegalArgumentException e) {
    149153                    e.printStackTrace();
    150154                    // FIXME: provide user feedback
    151155                }
    152             } catch(IOException e){
    153                 e.printStackTrace();
    154             } catch(UnsupportedFlavorException e){
    155                 e.printStackTrace();
    156             }
    157         }
    158     }
    159 
    160     class MoveDownAction extends AbstractAction implements ListSelectionListener{
     156            } catch (IOException e) {
     157                e.printStackTrace();
     158            } catch (UnsupportedFlavorException e) {
     159                e.printStackTrace();
     160            }
     161        }
     162    }
     163
     164    class MoveDownAction extends AbstractAction implements ListSelectionListener {
    161165        private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK);
    162         public MoveDownAction(){
     166        MoveDownAction() {
    163167            putValue(NAME, tr("Move down"));
    164168            putValue(SHORT_DESCRIPTION, tr("Move the selected relation members down by one position"));
    165             putValue(ACCELERATOR_KEY,keyStroke);
     169            putValue(ACCELERATOR_KEY, keyStroke);
    166170            new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this);
    167171            updateEnabledState();
    168172        }
    169173
     174        @Override
    170175        public void actionPerformed(ActionEvent e) {
    171176            model.getRelationMemberEditorModel().moveDownSelected();
    172177        }
    173178
    174         public void updateEnabledState(){
     179        public void updateEnabledState() {
    175180            setEnabled(model.getRelationMemberEditorModel().canMoveDown());
    176181        }
    177182
     183        @Override
    178184        public void valueChanged(ListSelectionEvent e) {
    179185            updateEnabledState();
    180186        }
    181         public KeyStroke getKeyStroke() {
     187
     188        KeyStroke getKeyStroke() {
    182189            return keyStroke;
    183190        }
    184191    }
    185192
    186     class MoveUpAction extends AbstractAction implements ListSelectionListener{
     193    class MoveUpAction extends AbstractAction implements ListSelectionListener {
    187194        private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK);
    188195
    189         public MoveUpAction() {
     196        MoveUpAction() {
    190197            putValue(NAME, tr("Move up"));
    191198            putValue(SHORT_DESCRIPTION, tr("Move the selected relation members up by one position"));
    192             putValue(ACCELERATOR_KEY,keyStroke);
     199            putValue(ACCELERATOR_KEY, keyStroke);
    193200            new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this);
    194201            updateEnabledState();
    195202        }
    196203
     204        @Override
    197205        public void actionPerformed(ActionEvent e) {
    198206            model.getRelationMemberEditorModel().moveUpSelected();
    199207        }
    200208
    201         public void updateEnabledState(){
     209        public void updateEnabledState() {
    202210            setEnabled(model.getRelationMemberEditorModel().canMoveUp());
    203211        }
    204212
     213        @Override
    205214        public void valueChanged(ListSelectionEvent e) {
    206215            updateEnabledState();
    207216        }
    208         public KeyStroke getKeyStroke() {
     217
     218        KeyStroke getKeyStroke() {
    209219            return keyStroke;
    210220        }
     
    215225        public void launch(MouseEvent evt) {
    216226            int row = rowAtPoint(evt.getPoint());
    217             if (getSelectionModel().getMinSelectionIndex() < 0 && row >=0){
     227            if (getSelectionModel().getMinSelectionIndex() < 0 && row >= 0) {
    218228                getSelectionModel().setSelectionInterval(row, row);
    219229                getColumnModel().getSelectionModel().setSelectionInterval(0, 1);
     
    224234
    225235    class PopupMenu extends JPopupMenu {
    226         public PopupMenu() {
     236        PopupMenu() {
    227237            JMenuItem item = add(actPaste);
    228238            item.setTransferHandler(transferHandler);
     
    252262            try {
    253263                List<PrimitiveId> ids;
    254                 ids = (List<PrimitiveId>)t.getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
     264                ids = (List<PrimitiveId>) t.getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
    255265                try {
    256266                    model.getRelationMemberEditorModel().insertMembers(ids);
    257                 } catch(IllegalArgumentException e){
     267                } catch (IllegalArgumentException e) {
    258268                    e.printStackTrace();
    259269                    // FIXME: provide user feedback
     
    261271                }
    262272                return true;
    263             } catch(IOException e){
    264                 e.printStackTrace();
    265             } catch(UnsupportedFlavorException e){
     273            } catch (IOException e) {
     274                e.printStackTrace();
     275            } catch (UnsupportedFlavorException e) {
    266276                e.printStackTrace();
    267277            }
     
    271281        @Override
    272282        public int getSourceActions(JComponent c) {
    273             return  COPY_OR_MOVE;
     283            return COPY_OR_MOVE;
    274284        }
    275285    }
     
    280290     *
    281291     */
    282     class RelationMemberTableDropTarget extends DropTarget{
     292    class RelationMemberTableDropTarget extends DropTarget {
    283293        private boolean dropAccepted = false;
    284294
     
    287297
    288298         * @param transferFlavors an array of transferFlavors
    289          * @return
    290299         */
    291300        protected boolean isSupportedFlavor(DataFlavor[] transferFlavors) {
     
    296305        }
    297306
     307        @Override
    298308        public synchronized void dragEnter(DropTargetDragEvent dtde) {
    299309            if (isSupportedFlavor(dtde.getCurrentDataFlavors())) {
    300                 if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) != 0){
     310                if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
    301311                    dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
    302312                    setColumnSelectionAllowed(false);
    303                     dropAccepted  = true;
     313                    dropAccepted = true;
    304314                } else {
    305315                    dtde.rejectDrag();
     
    310320        }
    311321
     322        @Override
    312323        public synchronized void dragExit(DropTargetEvent dte) {
    313324            setColumnSelectionAllowed(true);
     
    319330            int row = rowAtPoint(dtde.getLocation());
    320331            int selectedRow = getSelectionModel().getMinSelectionIndex();
    321             if (row >= 0 && row != selectedRow){
     332            if (row >= 0 && row != selectedRow) {
    322333                getSelectionModel().setSelectionInterval(row, row);
    323334            }
    324335        }
    325336
     337        @Override
    326338        @SuppressWarnings("unchecked")
    327339        public synchronized void drop(DropTargetDropEvent dtde) {
     
    332344                }
    333345                List<PrimitiveId> ids;
    334                 ids = (List<PrimitiveId>)dtde.getTransferable().getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
     346                ids = (List<PrimitiveId>) dtde.getTransferable().getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
    335347                try {
    336348                    model.getRelationMemberEditorModel().insertMembers(ids);
    337                 } catch(IllegalArgumentException e){
     349                } catch (IllegalArgumentException e) {
    338350                    e.printStackTrace();
    339351                    // FIXME: provide user feedback
    340352                }
    341             } catch(IOException e){
    342                 e.printStackTrace();
    343             } catch(UnsupportedFlavorException e){
     353            } catch (IOException e) {
     354                e.printStackTrace();
     355            } catch (UnsupportedFlavorException e) {
    344356                e.printStackTrace();
    345357            } finally {
     
    348360        }
    349361
     362        @Override
    350363        public synchronized void dropActionChanged(DropTargetDragEvent dtde) {
    351364            if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionComboBox.java

    r30454 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    910 */
    1011public class TurnRestrictionComboBox extends JComboBox<Object> {
    11    
     12
    1213    /**
    13      * Constructor 
    14      * 
     14     * Constructor
     15     *
    1516     * @param model the combo box model. Must not be null.
    1617     */
    17     public TurnRestrictionComboBox(TurnRestrictionComboBoxModel model){
     18    public TurnRestrictionComboBox(TurnRestrictionComboBoxModel model) {
    1819        super(model);
    1920        setEditable(false);
    2021        setRenderer(new TurnRestrictionTypeRenderer());
    2122    }
    22    
     23
    2324    /**
    24      * Replies the turn restriction combo box model 
    25      * 
     25     * Replies the turn restriction combo box model
     26     *
    2627     * @return the turn restriction combo box model
    2728     */
    2829    public TurnRestrictionComboBoxModel getTurnRestrictionComboBoxModel() {
    29         return (TurnRestrictionComboBoxModel)getModel();
     30        return (TurnRestrictionComboBoxModel) getModel();
    3031    }
    31    
     32
    3233    /**
    3334     * Initializes the set of icons used from the preference key
    3435     * {@link PreferenceKeys#ROAD_SIGNS}.
    35      * 
    36      * @param prefs the JOSM preferences 
     36     *
     37     * @param prefs the JOSM preferences
    3738     */
    38     public void initIconSetFromPreferences(Preferences prefs){
    39         TurnRestrictionTypeRenderer renderer = (TurnRestrictionTypeRenderer)getRenderer();
     39    public void initIconSetFromPreferences(Preferences prefs) {
     40        TurnRestrictionTypeRenderer renderer = (TurnRestrictionTypeRenderer) getRenderer();
    4041        renderer.initIconSetFromPreferences(prefs);
    4142        repaint();
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionComboBoxModel.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1617 * This is a model for a combo box to select a turn restriction type. The
    1718 * user can choose from a list of standard types but the model also supports
    18  * non-standard tag values in the OSM data. 
     19 * non-standard tag values in the OSM data.
    1920 *
    2021 */
    21 public class TurnRestrictionComboBoxModel implements ComboBoxModel<Object>, Observer{
    22     //static private final Logger logger = Logger.getLogger(TurnRestrictionComboBoxModel.class.getName());
    23    
     22public class TurnRestrictionComboBoxModel implements ComboBoxModel<Object>, Observer {
     23
    2424    private TurnRestrictionEditorModel model;
    25     final private List<Object> values = new ArrayList<>();
     25    private final List<Object> values = new ArrayList<>();
    2626    private String selectedTagValue = null;
    2727    private final transient EventListenerList listeners = new EventListenerList();
    28    
     28
    2929    /**
    3030     * Populates the model with the list of standard values. If the
    3131     * data contains a non-standard value it is displayed in the combo
    32      * box as an additional element. 
     32     * box as an additional element.
    3333     */
    3434    protected void populate() {
     
    3636        for (TurnRestrictionType type: TurnRestrictionType.values()) {
    3737            values.add(type);
    38         }       
    39        
     38        }
     39
    4040        String tagValue = model.getRestrictionTagValue();
    4141        if (tagValue.trim().equals("")) {
     
    5252        fireContentsChanged();
    5353    }
    54    
     54
    5555    /**
    56      * Creates the combo box model. 
    57      * 
     56     * Creates the combo box model.
     57     *
    5858     * @param model the turn restriction editor model. Must not be null.
    5959     */
    60     public TurnRestrictionComboBoxModel(TurnRestrictionEditorModel model){
     60    public TurnRestrictionComboBoxModel(TurnRestrictionEditorModel model) {
    6161        CheckParameterUtil.ensureParameterNotNull(model, "model");
    6262        this.model = model;
     
    6565    }
    6666
     67    @Override
    6768    public Object getSelectedItem() {
    6869        TurnRestrictionType type = TurnRestrictionType.fromTagValue(selectedTagValue);
     
    7172    }
    7273
     74    @Override
    7375    public void setSelectedItem(Object anItem) {
    7476        String tagValue = null;
    7577        if (anItem instanceof String) {
    76             tagValue = (String)anItem;
    77         } else if (anItem instanceof TurnRestrictionType){
    78             tagValue = ((TurnRestrictionType)anItem).getTagValue();
     78            tagValue = (String) anItem;
     79        } else if (anItem instanceof TurnRestrictionType) {
     80            tagValue = ((TurnRestrictionType) anItem).getTagValue();
    7981        }
    8082        model.setRestrictionTagValue(tagValue);
    8183    }
    8284
     85    @Override
    8386    public Object getElementAt(int index) {
    8487        return values.get(index);
    8588    }
    8689
     90    @Override
    8791    public int getSize() {
    8892        return values.size();
    8993    }
    90    
     94
     95    @Override
    9196    public void addListDataListener(ListDataListener l) {
    92         listeners.add(ListDataListener.class, l);       
     97        listeners.add(ListDataListener.class, l);
    9398    }
    94    
     99
     100    @Override
    95101    public void removeListDataListener(ListDataListener l) {
    96         listeners.remove(ListDataListener.class, l);       
     102        listeners.remove(ListDataListener.class, l);
    97103    }
    98    
     104
    99105    protected void fireContentsChanged() {
    100         for(ListDataListener l: listeners.getListeners(ListDataListener.class)) {
     106        for (ListDataListener l: listeners.getListeners(ListDataListener.class)) {
    101107            l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, getSize()));
    102108        }
    103109    }
    104    
     110
    105111    /* ------------------------------------------------------------------------------------ */
    106112    /* interface Observer                                                                   */
    107113    /* ------------------------------------------------------------------------------------ */
    108     public void update(Observable o, Object arg) {     
     114    @Override
     115    public void update(Observable o, Object arg) {
    109116        String tagValue = model.getRestrictionTagValue();
    110117        if (tagValue == null && selectedTagValue != null) {
    111118            populate();
    112         } else if (tagValue != null && selectedTagValue == null){
     119        } else if (tagValue != null && selectedTagValue == null) {
    113120            populate();
    114121        } else if (tagValue != null) {
     
    116123                populate();
    117124            }
    118         } 
     125        }
    119126    }
    120127}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java

    r32386 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    5657import org.openstreetmap.josm.tools.ImageProvider;
    5758
    58 public class TurnRestrictionEditor extends JDialog implements NavigationControler{
    59     //final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName());
     59public class TurnRestrictionEditor extends JDialog implements NavigationControler {
    6060
    6161    /** the property name for the current turn restriction
     
    6363     * @link #getRelation()
    6464     */
    65     static public final String TURN_RESTRICION_PROP = RelationEditor.class.getName() + ".turnRestriction";
     65    public static final String TURN_RESTRICION_PROP = RelationEditor.class.getName() + ".turnRestriction";
    6666
    6767    /** the property name for the current relation snapshot
    6868     * @link #getRelationSnapshot()
    6969     */
    70     static public final String TURN_RESTRICION_SNAPSHOT_PROP = RelationEditor.class.getName() + ".turnRestrictionSnapshot";
     70    public static final String TURN_RESTRICION_SNAPSHOT_PROP = RelationEditor.class.getName() + ".turnRestrictionSnapshot";
    7171
    7272    /**
     
    111111    /**
    112112     * builds the panel which displays the JOSM selection
    113      * @return
    114113     */
    115114    protected JPanel buildJOSMSelectionPanel() {
    116         pnlJosmSelection = new JosmSelectionPanel(layer,editorModel.getJosmSelectionListModel());
     115        pnlJosmSelection = new JosmSelectionPanel(layer, editorModel.getJosmSelectionListModel());
    117116        return pnlJosmSelection;
    118117    }
     
    121120     * Builds the panel with the editor forms (the left panel in the split pane of
    122121     * this dialog)
    123      *
    124      * @return
    125122     */
    126123    protected JPanel buildEditorPanel() {
    127124        JPanel pnl = new JPanel(new BorderLayout());
    128125        tpEditors = new JTabbedPane();
    129         JScrollPane pane = new JScrollPane(pnlBasicEditor =new BasicEditorPanel(editorModel));
     126        JScrollPane pane = new JScrollPane(pnlBasicEditor = new BasicEditorPanel(editorModel));
    130127        pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    131128        pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
     
    149146     * Builds the content panel, i.e. the core area of the dialog with the editor
    150147     * masks and the JOSM selection view
    151      *
    152      * @return
    153148     */
    154149    protected JPanel buildContentPanel() {
     
    176171     */
    177172    protected JToolBar buildToolBar() {
    178         JToolBar tb  = new JToolBar();
     173        JToolBar tb = new JToolBar();
    179174        tb.setFloatable(false);
    180175        tb.add(new ApplyAction());
     
    206201
    207202        editorModel.getIssuesModel().addObserver(new IssuesModelObserver());
    208         setSize(600,600);
     203        setSize(600, 600);
    209204    }
    210205
     
    228223     * @throws IllegalArgumentException thrown if layer is null
    229224     */
    230     public TurnRestrictionEditor(Component owner, OsmDataLayer layer, Relation turnRestriction)  throws IllegalArgumentException{
    231         super(JOptionPane.getFrameForComponent(owner),false /* not modal */);
     225    public TurnRestrictionEditor(Component owner, OsmDataLayer layer, Relation turnRestriction) throws IllegalArgumentException {
     226        super(JOptionPane.getFrameForComponent(owner), false /* not modal */);
    232227        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    233228        this.layer = layer;
     
    324319     */
    325320    protected boolean isDirtyTurnRestriction() {
    326         return ! turnRestriction.hasEqualSemanticAttributes(turnRestrictionSnapshot);
     321        return !turnRestriction.hasEqualSemanticAttributes(turnRestrictionSnapshot);
    327322    }
    328323
     
    336331    @Override
    337332    public void setVisible(boolean visible) {
    338         if (visible && ! isVisible()) {
     333        if (visible && !isVisible()) {
    339334            pnlJosmSelection.wireListeners();
    340335            editorModel.registerAsEventListener();
     
    347342        }
    348343        super.setVisible(visible);
    349         if (!visible){
     344        if (!visible) {
    350345            dispose();
    351346        }
     
    355350    /* property change support                                                 */
    356351    /* ----------------------------------------------------------------------- */
    357     final private PropertyChangeSupport support = new PropertyChangeSupport(this);
     352    private final PropertyChangeSupport support = new PropertyChangeSupport(this);
    358353
    359354    @Override
     
    383378    public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    384379        tpEditors.setSelectedIndex(0);
    385         pnlBasicEditor.requestFocusFor(focusTarget);
     380        pnlBasicEditor.requestFocusfor(focusTarget);
    386381    }
    387382
     
    391386     */
    392387    abstract class SavingAction extends AbstractAction {
    393         protected boolean confirmSaveDespiteOfErrorsAndWarnings(){
     388        protected boolean confirmSaveDespiteOfErrorsAndWarnings() {
    394389            int numErrors = editorModel.getIssuesModel().getNumErrors();
    395390            int numWarnings = editorModel.getIssuesModel().getNumWarnings();
     
    446441        protected List<RelationMember> getDeletedRelationMembers(Relation r) {
    447442            List<RelationMember> ret = new ArrayList<>();
    448             for(RelationMember rm: r.getMembers()) {
     443            for (RelationMember rm: r.getMembers()) {
    449444                if (rm.getMember().isDeleted() || !rm.getMember().isVisible()) {
    450445                    ret.add(rm);
     
    462457        protected void removeDeletedMembers(Relation tr) {
    463458            List<RelationMember> members = tr.getMembers();
    464             for(Iterator<RelationMember> it = members.iterator(); it.hasNext();) {
     459            for (Iterator<RelationMember> it = members.iterator(); it.hasNext();) {
    465460                RelationMember rm = it.next();
    466461                if (rm.getMember().isDeleted() || !rm.getMember().isVisible()) {
     
    490485                       + "of this turn restriction editor:", deletedMembers.size(), deletedMembers.size()));
    491486            sb.append("<ul>");
    492             for(RelationMember rm: deletedMembers){
     487            for (RelationMember rm: deletedMembers) {
    493488                sb.append("<li>");
    494489                if (!rm.getRole().equals("")) {
     
    550545            }
    551546
    552             Main.main.undoRedo.add(new AddCommand(getLayer(),newTurnRestriction));
     547            Main.main.undoRedo.add(new AddCommand(getLayer(), newTurnRestriction));
    553548
    554549            // make sure everybody is notified about the changes
     
    572567            editorModel.apply(toUpdate);
    573568            Conflict<Relation> conflict = new Conflict<>(getTurnRestriction(), toUpdate);
    574             Main.main.undoRedo.add(new ConflictAddCommand(getLayer(),conflict));
     569            Main.main.undoRedo.add(new ConflictAddCommand(getLayer(), conflict));
    575570        }
    576571
     
    594589
    595590        protected boolean confirmClosingBecauseOfDirtyState() {
    596             ButtonSpec [] options = new ButtonSpec[] {
     591            ButtonSpec[] options = new ButtonSpec[] {
    597592                    new ButtonSpec(
    598593                            tr("Yes, create a conflict and close"),
    599594                            ImageProvider.get("ok"),
    600                             tr("Create a conflict and close this turn restriction editor") ,
     595                            tr("Create a conflict and close this turn restriction editor"),
    601596                            null /* no specific help topic */
    602597                    ),
     
    604599                            tr("No, continue editing"),
    605600                            ImageProvider.get("cancel"),
    606                             tr("Return to the turn restriction editor and resume editing") ,
     601                            tr("Return to the turn restriction editor and resume editing"),
    607602                            null /* no specific help topic */
    608603                    )
     
    641636
    642637    class ApplyAction extends SavingAction {
    643         public ApplyAction() {
     638        ApplyAction() {
    644639            putValue(SHORT_DESCRIPTION, tr("Apply the current updates"));
    645640            new ImageProvider("save").getResource().attachImageIcon(this);
     
    649644
    650645        public void run() {
    651             if (!confirmSaveDespiteOfErrorsAndWarnings()){
     646            if (!confirmSaveDespiteOfErrorsAndWarnings()) {
    652647                tpEditors.setSelectedIndex(2); // show the errors and warnings
    653648                return;
     
    685680
    686681    class OKAction extends SavingAction {
    687         public OKAction() {
     682        OKAction() {
    688683            putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog"));
    689684            new ImageProvider("ok").getResource().attachImageIcon(this);
     
    693688
    694689        public void run() {
    695             if (!confirmSaveDespiteOfErrorsAndWarnings()){
     690            if (!confirmSaveDespiteOfErrorsAndWarnings()) {
    696691                tpEditors.setSelectedIndex(2); // show the errors and warnings
    697692                return;
     
    707702            Relation toUpdate = new Relation(getTurnRestriction());
    708703            editorModel.apply(toUpdate);
    709             if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction())){
     704            if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction())) {
    710705                // nothing to update
    711706                setVisible(false);
     
    740735     */
    741736    class CancelAction extends AbstractAction {
    742         public CancelAction() {
     737        CancelAction() {
    743738            putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog"));
    744739            new ImageProvider("cancel").getResource().attachImageIcon(this);
    745740            putValue(NAME, tr("Cancel"));
    746741            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("ESCAPE"));
    747             TurnRestrictionEditor.this.getRootPane().registerKeyboardAction(this,KeyStroke.getKeyStroke("ESCAPE"), JComponent.WHEN_IN_FOCUSED_WINDOW);
     742            TurnRestrictionEditor.this.getRootPane().registerKeyboardAction(this,
     743                    KeyStroke.getKeyStroke("ESCAPE"), JComponent.WHEN_IN_FOCUSED_WINDOW);
    748744            setEnabled(true);
    749745        }
     
    755751    }
    756752
    757     class DeleteAction extends AbstractAction implements PropertyChangeListener{
    758         public DeleteAction() {
     753    class DeleteAction extends AbstractAction implements PropertyChangeListener {
     754        DeleteAction() {
    759755            putValue(NAME, tr("Delete"));
    760756            putValue(SHORT_DESCRIPTION, tr("Delete this turn restriction"));
     
    781777        @Override
    782778        public void propertyChange(PropertyChangeEvent evt) {
    783             if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     779            if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)) {
    784780                updateEnabledState();
    785781            }
     
    787783    }
    788784
    789     class SelectAction extends AbstractAction implements PropertyChangeListener{
    790         public SelectAction() {
     785    class SelectAction extends AbstractAction implements PropertyChangeListener {
     786        SelectAction() {
    791787            putValue(NAME, tr("Select"));
    792788            putValue(SHORT_DESCRIPTION, tr("Select this turn restriction"));
     
    809805        @Override
    810806        public void propertyChange(PropertyChangeEvent evt) {
    811             if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     807            if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)) {
    812808                updateEnabledState();
    813809            }
     
    815811    }
    816812
    817     class ZoomToAction extends AbstractAction implements PropertyChangeListener{
    818         public ZoomToAction() {
     813    class ZoomToAction extends AbstractAction implements PropertyChangeListener {
     814        ZoomToAction() {
    819815            putValue(NAME, tr("Zoom to"));
    820816            putValue(SHORT_DESCRIPTION, tr("Activate the layer this turn restriction belongs to and zoom to it"));
     
    830826        @Override
    831827        public void actionPerformed(ActionEvent e) {
    832             if (Main.getLayerManager().getActiveLayer() != getLayer()){
     828            if (Main.getLayerManager().getActiveLayer() != getLayer()) {
    833829                Main.getLayerManager().setActiveLayer(getLayer());
    834830            }
     
    841837        @Override
    842838        public void propertyChange(PropertyChangeEvent evt) {
    843             if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){
     839            if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)) {
    844840                updateEnabledState();
    845841            }
     
    853849            int numErrors = editorModel.getIssuesModel().getNumErrors();
    854850            String warningText = null;
    855             if (numWarnings > 0){
     851            if (numWarnings > 0) {
    856852                warningText = trn("{0} warning", "{0} warnings", numWarnings, numWarnings);
    857853            }
    858854            String errorText = null;
    859             if (numErrors > 0){
     855            if (numErrors > 0) {
    860856                errorText = trn("{0} error", "{0} errors", numErrors, numErrors);
    861857            }
     
    864860                title += errorText;
    865861            }
    866             if (warningText != null){
    867                 if (title.length() > 0){
     862            if (warningText != null) {
     863                if (title.length() > 0) {
    868864                    title += "/";
    869865                }
    870866                title += warningText;
    871867            }
    872             if (title.length() == 0){
     868            if (title.length() == 0) {
    873869                title = tr("no issues");
    874870            }
     
    894890        @Override
    895891        public void preferenceChanged(PreferenceChangeEvent evt) {
    896             if (evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)){
     892            if (evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)) {
    897893                refreshIconSet();
    898894            } else if (evt.getKey().equals(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR)) {
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorManager.java

    r32375 r32519  
    2626 */
    2727public class TurnRestrictionEditorManager extends WindowAdapter implements LayerChangeListener {
    28     //static private final Logger logger = Logger.getLogger(TurnRestrictionEditorManager.class.getName());
     28    //private static final Logger logger = Logger.getLogger(TurnRestrictionEditorManager.class.getName());
    2929
    3030    /** keeps track of open relation editors */
     
    3636     * @return the singleton {@link TurnRestrictionEditorManager}
    3737     */
    38     static public TurnRestrictionEditorManager getInstance() {
     38    public static TurnRestrictionEditorManager getInstance() {
    3939        if (TurnRestrictionEditorManager.instance == null) {
    4040            TurnRestrictionEditorManager.instance = new TurnRestrictionEditorManager();
     
    4848     * restriction editor is open for turn restriction in a  {@link OsmDataLayer}
    4949     */
    50     static private class DialogContext {
     50    private static class DialogContext {
    5151        public final PrimitiveId primitiveId;
    5252        public final OsmDataLayer layer;
    5353
    54         public DialogContext(OsmDataLayer layer, PrimitiveId id) {
     54        DialogContext(OsmDataLayer layer, PrimitiveId id) {
    5555            this.layer = layer;
    5656            this.primitiveId = id;
     
    101101
    102102    /** the map of open dialogs */
    103     private final HashMap<DialogContext, TurnRestrictionEditor> openDialogs =  new HashMap<>();
     103    private final HashMap<DialogContext, TurnRestrictionEditor> openDialogs = new HashMap<>();
    104104
    105105    /**
    106106     * constructor
    107107     */
    108     public TurnRestrictionEditorManager(){}
     108    public TurnRestrictionEditorManager() {}
    109109
    110110    /**
     
    190190    @Override
    191191    public void windowClosed(WindowEvent e) {
    192         TurnRestrictionEditor editor = (TurnRestrictionEditor)e.getWindow();
     192        TurnRestrictionEditor editor = (TurnRestrictionEditor) e.getWindow();
    193193        DialogContext context = null;
    194194        for (DialogContext c : openDialogs.keySet()) {
     
    209209     */
    210210    protected void centerOnScreen(TurnRestrictionEditor editor) {
    211         Point p = new Point(0,0);
     211        Point p = new Point(0, 0);
    212212        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    213213        p.x = (d.width - editor.getSize().width)/2;
    214214        p.y = (d.height - editor.getSize().height)/2;
    215         p.x = Math.max(p.x,0);
    216         p.y = Math.max(p.y,0);
     215        p.x = Math.max(p.x, 0);
     216        p.y = Math.max(p.y, 0);
    217217        editor.setLocation(p);
    218218    }
     
    239239     * Positions a {@link TurnRestrictionEditor} close to the center of the screen, in such
    240240     * a way, that it doesn't entirely cover another {@link TurnRestrictionEditor}
    241      *
    242      * @param editor
    243241     */
    244242    protected void positionCloseToScreenCenter(TurnRestrictionEditor editor) {
    245         Point p = new Point(0,0);
     243        Point p = new Point(0, 0);
    246244        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    247245        p.x = (d.width - editor.getSize().width)/2;
    248246        p.y = (d.height - editor.getSize().height)/2;
    249         p.x = Math.max(p.x,0);
    250         p.y = Math.max(p.y,0);
    251         while(hasEditorWithCloseUpperLeftCorner(p)) {
     247        p.x = Math.max(p.x, 0);
     248        p.y = Math.max(p.y, 0);
     249        while (hasEditorWithCloseUpperLeftCorner(p)) {
    252250            p.x += 20;
    253251            p.y += 20;
     
    280278    public void layerRemoving(LayerRemoveEvent e) {
    281279        Layer oldLayer = e.getRemovedLayer();
    282         if (oldLayer == null || ! (oldLayer instanceof OsmDataLayer))
     280        if (oldLayer == null || !(oldLayer instanceof OsmDataLayer))
    283281            return;
    284         OsmDataLayer dataLayer = (OsmDataLayer)oldLayer;
    285 
    286         Iterator<Entry<DialogContext,TurnRestrictionEditor>> it = openDialogs.entrySet().iterator();
    287         while(it.hasNext()) {
    288             Entry<DialogContext,TurnRestrictionEditor> entry = it.next();
     282        OsmDataLayer dataLayer = (OsmDataLayer) oldLayer;
     283
     284        Iterator<Entry<DialogContext, TurnRestrictionEditor>> it = openDialogs.entrySet().iterator();
     285        while (it.hasNext()) {
     286            Entry<DialogContext, TurnRestrictionEditor> entry = it.next();
    289287            if (entry.getKey().matchesLayer(dataLayer)) {
    290288                TurnRestrictionEditor editor = entry.getValue();
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java

    r30365 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    3536/**
    3637 * This is the model for the turn restriction editor. It keeps the editing state
    37  * for a single turn restriction. 
    38  * 
     38 * for a single turn restriction.
     39 *
    3940 */
    40 public class TurnRestrictionEditorModel extends Observable implements DataSetListener{
    41     //static private final Logger logger = Logger.getLogger(TurnRestrictionEditorModel.class.getName());
    42    
     41public class TurnRestrictionEditorModel extends Observable implements DataSetListener {
     42
    4343    /**
    4444     * Replies true if {@code tp1} and {@code tp2} have the same tags and
    45      * the same members 
    46      * 
    47      * @param tp1 a turn restriction. Must not be null. 
     45     * the same members
     46     *
     47     * @param tp1 a turn restriction. Must not be null.
    4848     * @param tp2 a turn restriction . Must not be null.
    4949     * @return true if {@code tp1} and {@code tp2} have the same tags and
     
    5252     * @throws IllegalArgumentException thrown if {@code tp2} is null
    5353     */
    54     static public boolean hasSameMembersAndTags(Relation tp1, Relation tp2) throws IllegalArgumentException {
     54    public static boolean hasSameMembersAndTags(Relation tp1, Relation tp2) throws IllegalArgumentException {
    5555        CheckParameterUtil.ensureParameterNotNull(tp1, "tp1");
    5656        CheckParameterUtil.ensureParameterNotNull(tp2, "tp2");
    5757        if (!TagCollection.from(tp1).asSet().equals(TagCollection.from(tp2).asSet())) return false;
    5858        if (tp1.getMembersCount() != tp2.getMembersCount()) return false;
    59         for(int i=0; i < tp1.getMembersCount();i++){
     59        for (int i = 0; i < tp1.getMembersCount(); i++) {
    6060            if (!tp1.getMember(i).equals(tp2.getMember(i))) return false;
    6161        }
    6262        return true;
    6363    }
    64    
     64
    6565    private OsmDataLayer layer;
    6666    private final TagEditorModel tagEditorModel = new TagEditorModel();
    67     private  RelationMemberEditorModel memberModel;
    68     private  IssuesModel issuesModel;
     67    private RelationMemberEditorModel memberModel;
     68    private IssuesModel issuesModel;
    6969    private NavigationControler navigationControler;
    7070    private JosmSelectionListModel selectionModel;
    71    
     71
    7272    /**
    7373     * Creates a model in the context of a {@link OsmDataLayer}
    74      * 
     74     *
    7575     * @param layer the layer. Must not be null.
    76      * @param navigationControler control to direct the user to specific UI components. Must not be null 
     76     * @param navigationControler control to direct the user to specific UI components. Must not be null
    7777     * @throws IllegalArgumentException thrown if {@code layer} is null
    7878     */
    79     public TurnRestrictionEditorModel(OsmDataLayer layer, NavigationControler navigationControler) throws IllegalArgumentException{
     79    public TurnRestrictionEditorModel(OsmDataLayer layer, NavigationControler navigationControler) throws IllegalArgumentException {
    8080        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    8181        CheckParameterUtil.ensureParameterNotNull(navigationControler, "navigationControler");
     
    8989        selectionModel = new JosmSelectionListModel(layer);
    9090    }
    91    
     91
    9292    /**
    9393     * Replies the model for the currently selected JOSM primitives
     
    9696        return selectionModel;
    9797    }
    98    
     98
    9999    /**
    100100     * Sets the way participating in the turn restriction in a given role.
    101      * 
    102      * @param role the role. Must not be null. 
     101     *
     102     * @param role the role. Must not be null.
    103103     * @param way the way which participates in the turn restriction in the respective role.
    104104     * null, to remove the way with the given role.
    105105     * @exception IllegalArgumentException thrown if role is null
    106106     */
    107     public void setTurnRestrictionLeg(TurnRestrictionLegRole role, Way way) throws IllegalArgumentException{
     107    public void setTurnRestrictionLeg(TurnRestrictionLegRole role, Way way) throws IllegalArgumentException {
    108108        CheckParameterUtil.ensureParameterNotNull(role, "role");
    109         switch(role){
     109        switch(role) {
    110110        case FROM:
    111111            memberModel.setFromPrimitive(way);
     
    115115            break;
    116116        }
    117     }   
    118        
     117    }
     118
    119119    /**
    120120     * Sets the way participating in the turn restriction in a given role.
    121      * 
    122      * @param role the role. Must not be null. 
     121     *
     122     * @param role the role. Must not be null.
    123123     * @param wayId the id of the way to set
    124124     * @exception IllegalArgumentException thrown if role is null
    125125     * @exception IllegalArgumentException thrown if wayId != null isn't the id of a way
    126      * @exception IllegalStateException thrown the no way with this id was found in the dataset 
     126     * @exception IllegalStateException thrown the no way with this id was found in the dataset
    127127     */
    128128    public void setTurnRestrictionLeg(TurnRestrictionLegRole role, PrimitiveId wayId) {
    129129        CheckParameterUtil.ensureParameterNotNull(role, "role");
    130130        if (wayId == null) {
    131             setTurnRestrictionLeg(role, (Way)null);
     131            setTurnRestrictionLeg(role, (Way) null);
    132132            return;
    133133        }
    134134        if (!wayId.getType().equals(OsmPrimitiveType.WAY)) {
    135             throw new IllegalArgumentException(MessageFormat.format("parameter ''wayId'' of type {0} expected, got {1}", OsmPrimitiveType.WAY, wayId.getType()));
     135            throw new IllegalArgumentException(
     136                    MessageFormat.format("parameter ''wayId'' of type {0} expected, got {1}", OsmPrimitiveType.WAY, wayId.getType()));
    136137        }
    137138
    138139        OsmPrimitive p = layer.data.getPrimitiveById(wayId);
    139140        if (p == null) {
    140             throw new IllegalStateException(MessageFormat.format("didn''t find way with id {0} in layer ''{1}''", wayId, layer.getName()));         
    141         }
    142         setTurnRestrictionLeg(role, (Way)p);
    143     }   
    144    
    145     /**
    146      * <p>"Officially" a turn restriction should have exactly one member with 
     141            throw new IllegalStateException(MessageFormat.format("didn''t find way with id {0} in layer ''{1}''", wayId, layer.getName()));
     142        }
     143        setTurnRestrictionLeg(role, (Way) p);
     144    }
     145
     146    /**
     147     * <p>"Officially" a turn restriction should have exactly one member with
    147148     * role {@link TurnRestrictionLegRole#FROM FROM} and one member with role {@link TurnRestrictionLegRole#TO TO},
    148149     * both referring to an OSM {@link Way}. In order to deals with turn restrictions where these
    149150     * integrity constraints are violated, this model also supports relation with multiple or no
    150151     * 'from' or 'to' members.</p>
    151      * 
     152     *
    152153     * <p>Replies the turn restriction legs with role {@code role}. If no leg with this
    153154     * role exists, an empty set is returned. If multiple legs exists, the set of referred
    154      * primitives is returned.</p> 
    155      * 
     155     * primitives is returned.</p>
     156     *
    156157     * @param role the role. Must not be null.
    157158     * @return the set of turn restriction legs with role {@code role}. The empty set, if
     
    159160     * @throws IllegalArgumentException thrown if role is null
    160161     */
    161     public Set<OsmPrimitive>getTurnRestrictionLeg(TurnRestrictionLegRole role){
     162    public Set<OsmPrimitive> getTurnRestrictionLeg(TurnRestrictionLegRole role) {
    162163        CheckParameterUtil.ensureParameterNotNull(role, "role");
    163         switch(role){
     164        switch(role) {
    164165        case FROM: return memberModel.getFromPrimitives();
    165166        case TO: return memberModel.getToPrimitives();
     
    168169        return null;
    169170    }
    170    
     171
    171172    /**
    172173     * Initializes the model from a relation representing a turn
    173174     * restriction
    174      * 
     175     *
    175176     * @param turnRestriction the turn restriction
    176177     */
    177178    protected void initFromTurnRestriction(Relation turnRestriction) {
    178        
     179
    179180        // populate the member model
    180181        memberModel.populate(turnRestriction);
    181        
     182
    182183        // make sure we have a restriction tag
    183184        TagCollection tags = TagCollection.from(turnRestriction);
    184185        tags.setUniqueForKey("type", "restriction");
    185186        tagEditorModel.initFromTags(tags);
    186                
     187
    187188        setChanged();
    188189        notifyObservers();
    189190    }
    190    
    191     /**
    192      * Populates the turn restriction editor model with a turn restriction. 
     191
     192    /**
     193     * Populates the turn restriction editor model with a turn restriction.
    193194     * {@code turnRestriction} is an arbitrary relation. A tag type=restriction
    194195     * isn't required. If it is missing, it is added here. {@code turnRestriction}
    195      * must not be null and it must belong to a dataset. 
    196      * 
     196     * must not be null and it must belong to a dataset.
     197     *
    197198     * @param turnRestriction the turn restriction
    198199     * @throws IllegalArgumentException thrown if turnRestriction is null
    199      * @throws IllegalArgumentException thrown if turnRestriction doesn't belong to a dataset 
     200     * @throws IllegalArgumentException thrown if turnRestriction doesn't belong to a dataset
    200201     */
    201202    public void populate(Relation turnRestriction) {
    202203        CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");
    203         if (turnRestriction.getDataSet() != null && turnRestriction.getDataSet() != layer.data) {           
     204        if (turnRestriction.getDataSet() != null && turnRestriction.getDataSet() != layer.data) {
    204205            throw new IllegalArgumentException(
    205206                // don't translate - it's a technical message
    206                 MessageFormat.format("turnRestriction {0} must not belong to a different dataset than the dataset of layer ''{1}''", turnRestriction.getId(), layer.getName())
     207                MessageFormat.format("turnRestriction {0} must not belong to a different dataset than the dataset of layer ''{1}''",
     208                        turnRestriction.getId(), layer.getName())
    207209            );
    208210        }
    209211        initFromTurnRestriction(turnRestriction);
    210212    }
    211    
    212    
     213
     214
    213215    /**
    214216     * Applies the current state in the model to a turn restriction
    215      * 
     217     *
    216218     * @param turnRestriction the turn restriction. Must not be null.
    217219     */
    218220    public void apply(Relation turnRestriction) {
    219         CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");     
     221        CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");
    220222        TagCollection tags = tagEditorModel.getTagCollection();
    221223        turnRestriction.removeAll();
    222224        tags.applyTo(turnRestriction);
    223         memberModel.applyTo(turnRestriction);       
    224     }
    225    
     225        memberModel.applyTo(turnRestriction);
     226    }
     227
    226228    /**
    227229     * Replies the current tag value for the tag <tt>restriction</tt>.
    228      * The empty tag, if there isn't a tag <tt>restriction</tt>. 
    229      * 
     230     * The empty tag, if there isn't a tag <tt>restriction</tt>.
     231     *
    230232     * @return the tag value
    231233     */
     
    235237        return tags.getJoinedValues("restriction");
    236238    }
    237    
     239
    238240    /**
    239241     * Sets the current value for the restriction tag. If {@code value} is
    240      * null or an empty string, the restriction tag is removed. 
    241      * 
    242      * @param value the value of the restriction tag 
    243      */
    244     public void setRestrictionTagValue(String value){
     242     * null or an empty string, the restriction tag is removed.
     243     *
     244     * @param value the value of the restriction tag
     245     */
     246    public void setRestrictionTagValue(String value) {
    245247        if (value == null || value.trim().equals("")) {
    246             tagEditorModel.delete("restriction");           
     248            tagEditorModel.delete("restriction");
    247249        } else {
    248             TagModel  tm = tagEditorModel.get("restriction");
    249             if (tm != null){
     250            TagModel tm = tagEditorModel.get("restriction");
     251            if (tm != null) {
    250252                tm.setValue(value);
    251253            } else {
     
    256258        notifyObservers();
    257259    }
    258    
     260
    259261    /**
    260262     * Replies the list of 'via' objects. The return value is an
    261263     * unmodifiable list.
    262      * 
     264     *
    263265     * @return the list of 'via' objects
    264266     */
     
    266268        return memberModel.getVias();
    267269    }
    268    
     270
    269271    /**
    270272     * <p>Sets the list of vias for the edited turn restriction.</p>
    271      * 
     273     *
    272274     * <p>If {@code vias} is null, all vias are removed. All primitives
    273275     * in {@code vias} must be assigned to a dataset and the dataset
    274276     * must be equal to the dataset of this editor model, see {@link #getDataSet()}</p>
    275      * 
     277     *
    276278     * <p>null values in {@link vias} are skipped.</p>
    277      * 
    278      * @param vias the list of vias 
    279      * @throws IllegalArgumentException thrown if one of the via objects belongs to the wrong dataset 
    280      */
    281     public void setVias(List<OsmPrimitive> vias) throws IllegalArgumentException{
     279     *
     280     * @param vias the list of vias
     281     * @throws IllegalArgumentException thrown if one of the via objects belongs to the wrong dataset
     282     */
     283    public void setVias(List<OsmPrimitive> vias) throws IllegalArgumentException {
    282284        memberModel.setVias(vias);
    283285    }
    284    
     286
    285287    /**
    286288     * Replies the layer in whose context this editor is working
    287      * 
     289     *
    288290     * @return the layer in whose context this editor is working
    289291     */
     
    291293        return layer;
    292294    }
    293    
     295
    294296    /**
    295297     * Registers this model with global event sources like {@link DatasetEventManager}
    296298     */
    297     public void registerAsEventListener(){
     299    public void registerAsEventListener() {
    298300        DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT);
    299301    }
    300    
     302
    301303    /**
    302304     * Removes this model as listener from global event sources like  {@link DatasetEventManager}
     
    305307        DatasetEventManager.getInstance().removeDatasetListener(this);
    306308    }
    307    
    308     /**
    309      * Replies the tag  editor model 
    310      * 
     309
     310    /**
     311     * Replies the tag  editor model
     312     *
    311313     * @return the tag  editor model
    312314     */
     
    314316        return tagEditorModel;
    315317    }
    316    
     318
    317319    /**
    318320     * Replies the editor model for the relation members
    319      * 
     321     *
    320322     * @return the editor model for the relation members
    321323     */
     
    323325        return memberModel;
    324326    }
    325    
     327
    326328    /**
    327329     * Replies the model for the open issues in this turn restriction
    328330     * editor.
    329      * 
     331     *
    330332     * @return the model for the open issues in this turn restriction
    331333     * editor
     
    334336        return issuesModel;
    335337    }
    336    
     338
    337339    public NavigationControler getNavigationControler() {
    338340        return navigationControler;
    339341    }
    340    
     342
    341343    /**
    342344     * Replies the current value of the tag "except", or the empty string
    343345     * if the tag doesn't exist.
    344      *
    345      * @return
    346346     */
    347347    public ExceptValueModel getExcept() {
     
    350350        return new ExceptValueModel(tag.getValue());
    351351    }
    352    
     352
    353353    /**
    354354     * Sets the current value of the tag "except". Removes the
    355355     * tag is {@code value} is null or consists of white
    356      * space only. 
    357      * 
     356     * space only.
     357     *
    358358     * @param value the new value for 'except'
    359359     */
    360     public void setExcept(ExceptValueModel value){
     360    public void setExcept(ExceptValueModel value) {
    361361        if (value == null || value.getValue().equals("")) {
    362             if (tagEditorModel.get("except") != null){
     362            if (tagEditorModel.get("except") != null) {
    363363                tagEditorModel.delete("except");
    364364                setChanged();
    365                 notifyObservers();             
     365                notifyObservers();
    366366            }
    367             return;         
     367            return;
    368368        }
    369369        TagModel tag = tagEditorModel.get("except");
     
    378378                notifyObservers();
    379379            }
    380         }       
     380        }
    381381    }
    382382
    383383    /* ----------------------------------------------------------------------------------------- */
    384384    /* interface DataSetListener                                                                 */
    385     /* ----------------------------------------------------------------------------------------- */ 
     385    /* ----------------------------------------------------------------------------------------- */
    386386    protected boolean isAffectedByDataSetUpdate(DataSet ds, List<? extends OsmPrimitive> updatedPrimitives) {
    387387        if (ds != layer.data) return false;
     
    392392        return size1 != myPrimitives.size();
    393393    }
    394    
     394
     395    @Override
    395396    public void dataChanged(DataChangedEvent event) {
    396397        // refresh the views
    397398        setChanged();
    398         notifyObservers();     
    399     }
    400 
     399        notifyObservers();
     400    }
     401
     402    @Override
    401403    public void nodeMoved(NodeMovedEvent event) {
    402404        // may affect the display name of node in the list of vias
     
    407409    }
    408410
     411    @Override
    409412    public void otherDatasetChange(AbstractDatasetChangedEvent event) {/* irrelevant in this context */}
    410413
     414    @Override
    411415    public void primitivesAdded(PrimitivesAddedEvent event) {/* irrelevant in this context */}
     416
     417    @Override
    412418    public void primitivesRemoved(PrimitivesRemovedEvent event) {
    413         // relevant for the state of this model but not handled here. When the
    414         // state of this model is applied to the dataset we check whether the
    415         // the turn restriction refers to deleted or invisible primitives
    416     }
    417 
     419        // relevant for the state of this model but not handled here. When the
     420        // state of this model is applied to the dataset we check whether the
     421        // the turn restriction refers to deleted or invisible primitives
     422    }
     423
     424    @Override
    418425    public void relationMembersChanged(RelationMembersChangedEvent event) {/* irrelevant in this context */}
     426
     427    @Override
    419428    public void tagsChanged(TagsChangedEvent event) {
    420429        // may affect the display name of 'from', 'to' or 'via' elements
     
    425434    }
    426435
     436    @Override
    427437    public void wayNodesChanged(WayNodesChangedEvent event) {
    428438        // may affect the display name of 'from', 'to' or 'via' elements
     
    430440            setChanged();
    431441            notifyObservers();
    432         }       
    433     }   
    434    
     442        }
     443    }
     444
    435445    class RelationMemberModelListener implements TableModelListener {
     446        @Override
    436447        public void tableChanged(TableModelEvent e) {
    437448            setChanged();
    438449            notifyObservers();
    439         }       
     450        }
    440451    }
    441452
    442453    /* ----------------------------------------------------------------------------------------- */
    443454    /* inner classes                                                                             */
    444     /* ----------------------------------------------------------------------------------------- */ 
     455    /* ----------------------------------------------------------------------------------------- */
    445456    class TagEditorModelObserver implements TableModelListener {
     457        @Override
    446458        public void tableChanged(TableModelEvent e) {
    447459            setChanged();
    448460            notifyObservers();
    449         }       
     461        }
    450462    }
    451463}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java

    r32386 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    5960 */
    6061public class TurnRestrictionLegEditor extends JPanel implements Observer, PrimitiveIdListProvider {
    61     //static private final Logger logger = Logger.getLogger(TurnRestrictionLegEditor.class.getName());
     62    //private static final Logger logger = Logger.getLogger(TurnRestrictionLegEditor.class.getName());
    6263
    6364    private JLabel lblOsmObject;
     
    8283                BorderFactory.createCompoundBorder(
    8384                        BorderFactory.createEtchedBorder(),
    84                         BorderFactory.createEmptyBorder(1,1,1,1)
     85                        BorderFactory.createEmptyBorder(1, 1, 1, 1)
    8586                )
    8687        );
    8788
    88         JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
     89        JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    8990        pnlButtons.setBorder(null);
    9091        JButton btn;
     
    103104
    104105        // focus handling
    105         FocusHandler fh  = new FocusHandler();
     106        FocusHandler fh = new FocusHandler();
    106107        lblOsmObject.setFocusable(true);
    107108        lblOsmObject.addFocusListener(fh);
     
    115116
    116117        // enable DEL to remove the object from the turn restriction
    117         registerKeyboardAction(actDelete,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0) , JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     118        registerKeyboardAction(actDelete, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    118119
    119120        getInputMap().put(Shortcut.getCopyKeyStroke(), TransferHandler.getCopyAction().getValue(Action.NAME));;
     
    122123        getActionMap().put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
    123124        lblOsmObject.setTransferHandler(transferHandler = new LegEditorTransferHandler(this));
    124         lblOsmObject.addMouseMotionListener(new MouseMotionAdapter(){
     125        lblOsmObject.addMouseMotionListener(new MouseMotionAdapter() {
    125126            @Override
    126127            public void mouseDragged(MouseEvent e) {
    127                 JComponent c = (JComponent)e.getSource();
     128                JComponent c = (JComponent) e.getSource();
    128129                TransferHandler th = c.getTransferHandler();
    129130                th.exportAsDrag(c, e, TransferHandler.COPY);
     
    153154    }
    154155
    155     protected void refresh(){
     156    protected void refresh() {
    156157        legs.clear();
    157158        legs.addAll(model.getTurnRestrictionLeg(role));
     
    161162            lblOsmObject.setText(tr("please select a way"));
    162163            lblOsmObject.setToolTipText(null);
    163         } else if (legs.size() == 1){
     164        } else if (legs.size() == 1) {
    164165            OsmPrimitive leg = legs.iterator().next();
    165166            lblOsmObject.setFont(UIManager.getFont("Label.font"));
     
    170171            lblOsmObject.setFont(UIManager.getFont("Label.font").deriveFont(Font.ITALIC));
    171172            lblOsmObject.setIcon(null);
    172             lblOsmObject.setText(tr("multiple objects with role ''{0}''",this.role.getOsmRole()));
     173            lblOsmObject.setText(tr("multiple objects with role ''{0}''", this.role.getOsmRole()));
    173174            lblOsmObject.setToolTipText(null);
    174175        }
     
    213214    /* interface Observer                                                            */
    214215    /* ----------------------------------------------------------------------------- */
     216    @Override
    215217    public void update(Observable o, Object arg) {
    216218        refresh();
     
    220222    /* interface PrimitiveIdListProvider                                                            */
    221223    /* ----------------------------------------------------------------------------- */
     224    @Override
    222225    public List<PrimitiveId> getSelectedPrimitiveIds() {
    223226        if (legs.size() == 1) {
     
    256259     */
    257260    class DeleteAction extends AbstractAction {
    258         public DeleteAction() {
     261        DeleteAction() {
    259262            putValue(SHORT_DESCRIPTION, tr("Delete from turn restriction"));
    260263            putValue(NAME, tr("Delete"));
    261264            new ImageProvider("deletesmall").getResource().attachImageIcon(this);
    262             putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0));
     265            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
    263266            updateEnabledState();
    264267        }
    265268
     269        @Override
    266270        public void actionPerformed(ActionEvent e) {
    267271            model.setTurnRestrictionLeg(role, null);
     
    269273
    270274        public void updateEnabledState() {
    271             setEnabled(legs.size()>0);
     275            setEnabled(legs.size() > 0);
    272276        }
    273277    }
     
    279283    class AcceptAction extends AbstractAction implements ListSelectionListener {
    280284
    281         public AcceptAction() {
     285        AcceptAction() {
    282286             putValue(SHORT_DESCRIPTION, tr("Accept the currently selected way"));
    283287             putValue(NAME, tr("Accept"));
     
    287291        }
    288292
    289          public void actionPerformed(ActionEvent e) {
     293         @Override
     294        public void actionPerformed(ActionEvent e) {
    290295             List<Way> selWays = OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class);
    291296             if (selWays.size() != 1) return;
     
    310315        Logger logger = Logger.getLogger(LegEditorTransferHandler.class.getName());
    311316
    312         public LegEditorTransferHandler(PrimitiveIdListProvider provider){
     317        LegEditorTransferHandler(PrimitiveIdListProvider provider) {
    313318            super(provider);
    314319        }
     
    318323        public boolean importData(JComponent comp, Transferable t) {
    319324            try {
    320                 List<PrimitiveId> ids = (List<PrimitiveId>)t.getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
    321                 if (ids.size() !=1) {
     325                List<PrimitiveId> ids = (List<PrimitiveId>) t.getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
     326                if (ids.size() != 1) {
    322327                    return false;
    323328                }
     
    326331                model.setTurnRestrictionLeg(role, id);
    327332                return true;
    328             } catch(IOException e) {
     333            } catch (IOException e) {
    329334                // ignore
    330335                return false;
    331             } catch(UnsupportedFlavorException e) {
     336            } catch (UnsupportedFlavorException e) {
    332337                // ignore
    333338                return false;
     
    350355
    351356    class PopupMenu extends JPopupMenu {
    352         public PopupMenu() {
     357        PopupMenu() {
    353358            actCopy.updateEnabledState();
    354359            JMenuItem item = add(actCopy);
     
    365370        private Action delegate;
    366371
    367         public CopyAction(){
     372        CopyAction() {
    368373            putValue(NAME, tr("Copy"));
    369374            putValue(SHORT_DESCRIPTION, tr("Copy to the clipboard"));
     
    374379        }
    375380
     381        @Override
    376382        public void actionPerformed(ActionEvent e) {
    377383            delegate.actionPerformed(e);
     
    395401        }
    396402
    397         public PasteAction(){
     403        PasteAction() {
    398404            putValue(NAME, tr("Paste"));
    399405            putValue(SHORT_DESCRIPTION, tr("Paste from the clipboard"));
     
    407413        }
    408414
     415        @Override
    409416        public void actionPerformed(ActionEvent e) {
    410417            delegate.actionPerformed(e);
    411418        }
    412419    }
    413 
    414 
    415420}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegRole.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    45 * Enumerates the two roles a "leg" in a turn restriction can have.
    56 */
    6 public enum TurnRestrictionLegRole {   
     7public enum TurnRestrictionLegRole {
    78    FROM("from"),
    89    TO("to");
    9    
     10
    1011    private String osmRoleName;
    11    
    12     private TurnRestrictionLegRole(String osmRoleName) {
     12
     13    TurnRestrictionLegRole(String osmRoleName) {
    1314        this.osmRoleName = osmRoleName;
    1415    }
    15    
     16
    1617    public String getOsmRole() {
    1718        return osmRoleName;
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionSelectionPopupPanel.java

    r32386 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    4849 *
    4950 */
    50 public class TurnRestrictionSelectionPopupPanel extends JPanel{
    51     //static private final Logger logger = Logger.getLogger(TurnRestrictionSelectionPopupPanel.class.getName());
     51public class TurnRestrictionSelectionPopupPanel extends JPanel {
    5252
    5353    /** the parent popup */
     
    6666     * @return the collection of "parent" turn restrictions.
    6767     */
    68     static public Collection<Relation> getTurnRestrictionsParticipatingIn(Collection<OsmPrimitive> primitives){
     68    public static Collection<Relation> getTurnRestrictionsParticipatingIn(Collection<OsmPrimitive> primitives) {
    6969        HashSet<Relation> ret = new HashSet<>();
    7070        if (primitives == null) return ret;
    71         for (OsmPrimitive p: primitives){
     71        for (OsmPrimitive p: primitives) {
    7272            if (p == null) continue;
    7373            if (p.isDeleted() || !p.isVisible()) continue;
    74             for (OsmPrimitive parent: p.getReferrers()){
     74            for (OsmPrimitive parent: p.getReferrers()) {
    7575                if (!(parent instanceof Relation)) continue;
    7676                String type = parent.get("type");
    77                 if (type == null || ! type.equals("restriction")) continue;
    78                 if (parent.isDeleted() || ! parent.isVisible()) continue;
    79                 ret.add((Relation)parent);
     77                if (type == null || !type.equals("restriction")) continue;
     78                if (parent.isDeleted() || !parent.isVisible()) continue;
     79                ret.add((Relation) parent);
    8080            }
    8181        }
     
    8989     * @param editCandiates the edit candidates
    9090     */
    91     protected void registerEditShortcuts(Collection<Relation> editCandiates){
    92         for(int i=1; i <= Math.min(editCandiates.size(),9);i++){
     91    protected void registerEditShortcuts(Collection<Relation> editCandiates) {
     92        for (int i = 1; i <= Math.min(editCandiates.size(), 9); i++) {
    9393            int vkey = 0;
    94             switch(i){
     94            switch(i) {
    9595            case 1: vkey = KeyEvent.VK_1; break;
    9696            case 2: vkey = KeyEvent.VK_2; break;
     
    103103            case 9: vkey = KeyEvent.VK_9; break;
    104104            }
    105             registerKeyboardAction(new EditTurnRestrictionAction(i-1), KeyStroke.getKeyStroke(vkey,0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    106         }
    107     }
     105            registerKeyboardAction(new EditTurnRestrictionAction(i-1), KeyStroke.getKeyStroke(vkey, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     106        }
     107    }
     108
    108109    /**
    109110     * Builds the panel with the turn restrictions table
     
    117118        tblTurnRestrictions.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    118119        TurnRestrictionCellRenderer renderer = new TurnRestrictionCellRenderer();
    119         tblTurnRestrictions.setRowHeight((int)renderer.getPreferredSize().getHeight());
     120        tblTurnRestrictions.setRowHeight((int) renderer.getPreferredSize().getHeight());
    120121
    121122        // create a scroll pane, remove the table header
     
    129130        EditSelectedTurnRestrictionAction action = new EditSelectedTurnRestrictionAction();
    130131        tblTurnRestrictions.addMouseListener(action);
    131         tblTurnRestrictions.registerKeyboardAction(action, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), WHEN_FOCUSED);
     132        tblTurnRestrictions.registerKeyboardAction(action, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), WHEN_FOCUSED);
    132133
    133134        tblTurnRestrictions.addFocusListener(new FocusHandler());
     
    150151        add(btnNew = new JButton(new NewAction()), BorderLayout.NORTH);
    151152        btnNew.setFocusable(true);
    152         btnNew.registerKeyboardAction(btnNew.getAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), WHEN_FOCUSED);
    153         registerKeyboardAction(new CloseAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    154         registerKeyboardAction(btnNew.getAction(), KeyStroke.getKeyStroke(KeyEvent.VK_N,0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     153        btnNew.registerKeyboardAction(btnNew.getAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), WHEN_FOCUSED);
     154        registerKeyboardAction(new CloseAction(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     155        registerKeyboardAction(btnNew.getAction(), KeyStroke.getKeyStroke(KeyEvent.VK_N, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    155156
    156157        btnNew.addFocusListener(new FocusHandler());
    157158
    158         if (editCandiates != null && ! editCandiates.isEmpty()) {
     159        if (editCandiates != null && !editCandiates.isEmpty()) {
    159160            add(buildTurnRestrictionTablePanel(editCandiates), BorderLayout.CENTER);
    160161            registerEditShortcuts(editCandiates);
     
    193194     * Launches a popup with this panel as content
    194195     */
    195     public void launch(){
     196    public void launch() {
    196197        PointerInfo info = MouseInfo.getPointerInfo();
    197198        Point pt = info.getLocation();
    198         parentPopup = PopupFactory.getSharedInstance().getPopup(Main.map.mapView,this, pt.x, pt.y);
     199        parentPopup = PopupFactory.getSharedInstance().getPopup(Main.map.mapView, this, pt.x, pt.y);
    199200        parentPopup.show();
    200201        btnNew.requestFocusInWindow();
     
    203204    @Override
    204205    public Dimension getPreferredSize() {
    205         int bestheight = (int)btnNew.getPreferredSize().getHeight()
     206        int bestheight = (int) btnNew.getPreferredSize().getHeight()
    206207              + Math.min(2, tblTurnRestrictions.getRowCount()) * tblTurnRestrictions.getRowHeight()
    207208              + 5;
     
    214215
    215216    private class NewAction extends AbstractAction {
    216         public NewAction() {
     217        NewAction() {
    217218            putValue(NAME, tr("Create new turn restriction"));
    218219            putValue(SHORT_DESCRIPTION, tr("Launch the turn restriction editor to create a new turn restriction"));
     
    221222        }
    222223
     224        @Override
    223225        public void actionPerformed(ActionEvent e) {
    224226            Relation tr = new TurnRestrictionBuilder().buildFromSelection(layer);
    225             TurnRestrictionEditor editor = new TurnRestrictionEditor(Main.map.mapView,layer,tr);
     227            TurnRestrictionEditor editor = new TurnRestrictionEditor(Main.map.mapView, layer, tr);
    226228            TurnRestrictionEditorManager.getInstance().positionOnScreen(editor);
    227229            TurnRestrictionEditorManager.getInstance().register(layer, tr, editor);
    228             if (parentPopup != null){
     230            if (parentPopup != null) {
    229231                parentPopup.hide();
    230232            }
     
    233235    }
    234236
    235     abstract private class AbstractEditTurnRestrictionAction extends AbstractAction {
    236         protected void launchEditor(Relation tr){
     237    private abstract class AbstractEditTurnRestrictionAction extends AbstractAction {
     238        protected void launchEditor(Relation tr) {
    237239            TurnRestrictionEditorManager manager = TurnRestrictionEditorManager.getInstance();
    238240            TurnRestrictionEditor editor = manager.getEditorForRelation(layer, tr);
    239             if (parentPopup != null){
     241            if (parentPopup != null) {
    240242                parentPopup.hide();
    241243            }
     
    244246                editor.toFront();
    245247            } else {
    246                 editor = new TurnRestrictionEditor(Main.map.mapView, layer,tr);
     248                editor = new TurnRestrictionEditor(Main.map.mapView, layer, tr);
    247249                manager.positionOnScreen(editor);
    248                 manager.register(layer, tr,editor);
     250                manager.register(layer, tr, editor);
    249251                editor.setVisible(true);
    250252            }
     
    255257        private int idx;
    256258
    257         public EditTurnRestrictionAction(int idx){
     259        EditTurnRestrictionAction(int idx) {
    258260            this.idx = idx;
    259261        }
    260262
     263        @Override
    261264        public void actionPerformed(ActionEvent e) {
    262             Relation tr = (Relation)tblTurnRestrictions.getModel().getValueAt(idx, 1);
     265            Relation tr = (Relation) tblTurnRestrictions.getModel().getValueAt(idx, 1);
    263266            launchEditor(tr);
    264267        }
    265268    }
    266269
    267     private class EditSelectedTurnRestrictionAction extends AbstractEditTurnRestrictionAction implements MouseListener{
    268         public void editTurnRestrictionAtRow(int row){
     270    private class EditSelectedTurnRestrictionAction extends AbstractEditTurnRestrictionAction implements MouseListener {
     271        public void editTurnRestrictionAtRow(int row) {
    269272            if (row < 0) return;
    270             Relation tr = (Relation)tblTurnRestrictions.getModel().getValueAt(row, 1);
     273            Relation tr = (Relation) tblTurnRestrictions.getModel().getValueAt(row, 1);
    271274            launchEditor(tr);
    272275        }
     276
     277        @Override
    273278        public void actionPerformed(ActionEvent e) {
    274279            int row = tblTurnRestrictions.getSelectedRow();
    275280            editTurnRestrictionAtRow(row);
    276281        }
     282
     283        @Override
    277284        public void mouseClicked(MouseEvent e) {
    278285            if (!(SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2)) return;
     
    281288            editTurnRestrictionAtRow(row);
    282289        }
     290
     291        @Override
    283292        public void mouseEntered(MouseEvent e) {}
     293
     294        @Override
    284295        public void mouseExited(MouseEvent e) {}
     296
     297        @Override
    285298        public void mousePressed(MouseEvent e) {}
     299
     300        @Override
    286301        public void mouseReleased(MouseEvent e) {}
    287302    }
    288303
    289304    private class CloseAction extends AbstractAction {
     305        @Override
    290306        public void actionPerformed(ActionEvent e) {
    291             if (parentPopup != null){
     307            if (parentPopup != null) {
    292308                parentPopup.hide();
    293309            }
     
    298314        private final ArrayList<Relation> turnrestrictions = new ArrayList<>();
    299315
    300         public TurnRestrictionTableModel(Collection<Relation> turnrestrictions){
     316        TurnRestrictionTableModel(Collection<Relation> turnrestrictions) {
    301317            this.turnrestrictions.clear();
    302             if (turnrestrictions != null){
     318            if (turnrestrictions != null) {
    303319                this.turnrestrictions.addAll(turnrestrictions);
    304320            }
     
    306322        }
    307323
     324        @Override
    308325        public int getRowCount() {
    309326            return turnrestrictions.size();
    310327        }
    311328
     329        @Override
    312330        public int getColumnCount() {
    313331            return 2;
    314332        }
    315333
     334        @Override
    316335        public Object getValueAt(int rowIndex, int columnIndex) {
    317             switch(columnIndex){
     336            switch(columnIndex) {
    318337            case 0:
    319                 if (rowIndex <=8 ) {
     338                if (rowIndex <= 8) {
    320339                    return Integer.toString(rowIndex+1);
    321340                } else {
     
    331350
    332351    private static class TurnRestrictionTableColumnModel extends DefaultTableColumnModel {
    333         public TurnRestrictionTableColumnModel() {
     352        TurnRestrictionTableColumnModel() {
    334353            // the idx column
    335354            TableColumn col = new TableColumn(0);
     
    352371            // if we loose the focus to a component outside of the popup panel
    353372            // we hide the popup
    354             if (e.getOppositeComponent() == null ||!SwingUtilities.isDescendingFrom(e.getOppositeComponent(), TurnRestrictionSelectionPopupPanel.this)) {
    355                 if (parentPopup != null){
     373            if (e.getOppositeComponent() == null ||
     374                    !SwingUtilities.isDescendingFrom(e.getOppositeComponent(), TurnRestrictionSelectionPopupPanel.this)) {
     375                if (parentPopup != null) {
    356376                    parentPopup.hide();
    357377                }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionType.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    45
    56/**
    6  * This is the enumeration of turn restriction types, see 
     7 * This is the enumeration of turn restriction types, see
    78 * <a href="http://wiki.openstreetmap.org/wiki/Turn_restriction">OSM Wiki</a>
    8  * 
     9 *
    910 */
    1011public enum TurnRestrictionType {
     
    1213    NO_LEFT_TURN("no_left_turn", tr("No Left Turn")),
    1314    NO_U_TURN("no_u_turn", tr("No U-Turn")),
    14     NO_STRAIGHT_ON("no_straight_on", tr("No Straight On")), 
     15    NO_STRAIGHT_ON("no_straight_on", tr("No Straight On")),
    1516    ONLY_RIGHT_TURN("only_right_turn", tr("Only Right Turn")),
    1617    ONLY_LEFT_TURN("only_left_turn", tr("Only Left Turn")),
    1718    ONLY_STRAIGHT_ON("only_straight_on", tr("Only Straight On"));
    18    
     19
    1920    private String tagValue;
    2021    private String displayName;
    21    
     22
    2223    TurnRestrictionType(String tagValue, String displayName) {
    2324        this.tagValue = tagValue;
    2425        this.displayName = displayName;
    2526    }
    26    
     27
    2728    /**
    2829     * Replies the tag value for a specific turn restriction type
    29      * 
     30     *
    3031     * @return the tag value for a specific turn restriction type
    3132     */
     
    3334        return tagValue;
    3435    }
    35    
     36
    3637    /**
    3738     * Replies the localized display name for a turn restriction type
     
    3940    public String getDisplayName() {
    4041        return displayName;
    41     }   
    42    
     42    }
     43
    4344    /**
    4445     * Replies the enumeration value for a given tag value. null,
    4546     * if {@code tagValue} is null or if there isnt an enumeration value
    4647     * for this {@code tagValue}
    47      * 
     48     *
    4849     * @param tagValue the tag value, i.e. <tt>no_left_turn</tt>
    4950     * @return the enumeration value
    5051     */
    51     static public TurnRestrictionType fromTagValue(String tagValue) {
     52    public static TurnRestrictionType fromTagValue(String tagValue) {
    5253        if (tagValue == null) return null;
    53         for(TurnRestrictionType type: values()) {
    54             if(type.getTagValue().equals(tagValue)) return type;
     54        for (TurnRestrictionType type: values()) {
     55            if (type.getTagValue().equals(tagValue)) return type;
    5556        }
    5657        return null;
     
    5859
    5960    /**
    60      * Replies true if {@code tagValue} is a standard restriction type. 
    61      * 
    62      * @param tagValue the tag value 
     61     * Replies true if {@code tagValue} is a standard restriction type.
     62     *
     63     * @param tagValue the tag value
    6364     * @return true if {@code tagValue} is a standard restriction type
    6465     */
    65     static public boolean isStandardTagValue(String tagValue){
     66    public static boolean isStandardTagValue(String tagValue) {
    6667        return fromTagValue(tagValue) != null;
    6768    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeRenderer.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1819import org.openstreetmap.josm.tools.ImageProvider;
    1920
     21public class TurnRestrictionTypeRenderer extends JLabel implements ListCellRenderer<Object> {
    2022
    21 public class TurnRestrictionTypeRenderer extends JLabel implements ListCellRenderer<Object> {
    22  
    23     final private Map<TurnRestrictionType, ImageIcon> icons = new HashMap<>();
     23    private final Map<TurnRestrictionType, ImageIcon> icons = new HashMap<>();
    2424    private String iconSet = "set-a";
    25    
     25
    2626    /**
    27      * Loads the image icons for the rendered turn restriction types 
     27     * Loads the image icons for the rendered turn restriction types
    2828     */
    2929    protected void loadImages() {
    30         for(TurnRestrictionType type: TurnRestrictionType.values()) {
     30        for (TurnRestrictionType type: TurnRestrictionType.values()) {
    3131            try {
    32                 ImageIcon icon = new ImageIcon(ImageProvider.get("types/" + iconSet, type.getTagValue()).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
    33                 icons.put(type,icon);
    34             } catch(Exception e){
     32                ImageIcon icon = new ImageIcon(ImageProvider.get("types/" + iconSet,
     33                        type.getTagValue()).getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH));
     34                icons.put(type, icon);
     35            } catch (Exception e) {
    3536                System.out.println(tr("Warning: failed to load icon for turn restriction type ''{0}''", type.getTagValue()));
    36                 e.printStackTrace();               
     37                e.printStackTrace();
    3738            }
    3839        }
    3940    }
    40    
     41
    4142    public TurnRestrictionTypeRenderer() {
    4243        setOpaque(true);
    4344        loadImages();
    4445    }
    45    
    46     protected void renderColors(boolean isSelected){
    47         if (isSelected){
     46
     47    protected void renderColors(boolean isSelected) {
     48        if (isSelected) {
    4849            setBackground(UIManager.getColor("List.selectionBackground"));
    4950            setForeground(UIManager.getColor("List.selectionForeground"));
    5051        } else {
    5152            setBackground(UIManager.getColor("List.background"));
    52             setForeground(UIManager.getColor("List.foreground"));           
     53            setForeground(UIManager.getColor("List.foreground"));
    5354        }
    5455    }
    55    
     56
    5657    /**
    5758     * Initializes the set of icons used from the preference key
    5859     * {@link PreferenceKeys#ROAD_SIGNS}.
    59      * 
    60      * @param prefs the JOSM preferences 
     60     *
     61     * @param prefs the JOSM preferences
    6162     */
    62     public void initIconSetFromPreferences(Preferences prefs){     
     63    public void initIconSetFromPreferences(Preferences prefs) {
    6364        iconSet = prefs.get(PreferenceKeys.ROAD_SIGNS, "set-a");
    6465        iconSet = iconSet.trim().toLowerCase();
     
    6869        loadImages();
    6970    }
    70    
     71
     72    @Override
    7173    public Component getListCellRendererComponent(JList<? extends Object> list, Object value,
    7274            int index, boolean isSelected, boolean cellHasFocus) {
    73        
     75
    7476        renderColors(isSelected);
    7577        if (value == null) {
    7678            setText(tr("please select a turn restriction type"));
    7779            setIcon(null);
    78         } else if (value instanceof String){
    79             setText((String)value);
    80             setIcon(null); // FIXME: special icon for non-standard types? 
    81         } else if (value instanceof TurnRestrictionType){
    82             TurnRestrictionType type = (TurnRestrictionType)value;
     80        } else if (value instanceof String) {
     81            setText((String) value);
     82            setIcon(null); // FIXME: special icon for non-standard types?
     83        } else if (value instanceof TurnRestrictionType) {
     84            TurnRestrictionType type = (TurnRestrictionType) value;
    8385            setText(type.getDisplayName());
    8486            setIcon(icons.get(type));
    8587        }
    8688        return this;
    87     }   
     89    }
    8890}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java

    r30651 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    3233 * VehicleExceptionEditor is UI widget for editing exceptions to a turn restriction
    3334 * based on vehicle types.
    34  * 
     35 *
    3536 */
    36 public class VehicleExceptionEditor extends JPanel implements Observer{
    37     //static private final Logger logger = Logger.getLogger(VehicleExceptionEditor.class.getName());
    38    
     37public class VehicleExceptionEditor extends JPanel implements Observer {
     38
    3939    private TurnRestrictionEditorModel model;
    4040    private JCheckBox cbPsv;
     
    5050    private JPanel pnlNonStandard;
    5151    private ExceptValueModel exceptValue = new ExceptValueModel();
    52    
     52
    5353    private StandardVehicleTypeChangeListener svtChangeListener;
    54    
     54
    5555    private JPanel buildMessagePanel() {
    5656        JPanel pnl = new JPanel(new BorderLayout());
     
    6464        return pnl;
    6565    }
    66    
     66
    6767    private JPanel buildStandardInputPanel() {
    6868        if (pnlStandard != null)
    6969            return pnlStandard;
    70        
     70
    7171        svtChangeListener = new StandardVehicleTypeChangeListener();
    72        
     72
    7373        GridBagConstraints gc = new GridBagConstraints();
    7474        gc.anchor = GridBagConstraints.NORTHWEST;
     
    7676        gc.gridx = 0;
    7777        gc.gridy = 0;
    78        
     78
    7979        pnlStandard = new JPanel(new GridBagLayout());
    8080        JLabel lbl;
     
    8585        lbl.setToolTipText(tr("Public service vehicles like buses, tramways, etc."));
    8686        lbl.setIcon(ImageProvider.get("vehicle", "psv"));
    87        
     87
    8888        gc.weightx = 0.0;
    8989        pnlStandard.add(cbPsv, gc);
     
    9191        gc.gridx++;
    9292        pnlStandard.add(lbl, gc);
    93        
     93
    9494        cbHgv = new JCheckBox();
    9595        cbHgv.addItemListener(svtChangeListener);
     
    110110        lbl.setText(tr("Motorcars"));
    111111        lbl.setIcon(ImageProvider.get("vehicle", "motorcar"));
    112        
     112
    113113        gc.weightx = 0.0;
    114114        gc.gridx = 0;
     
    118118        gc.gridx++;
    119119        pnlStandard.add(lbl, gc);
    120        
     120
    121121        cbBicyle = new JCheckBox();
    122122        cbBicyle.addItemListener(svtChangeListener);
     
    124124        lbl.setText(tr("Bicycles"));
    125125        lbl.setIcon(ImageProvider.get("vehicle", "bicycle"));
    126        
     126
    127127        gc.weightx = 0.0;
    128128        gc.gridx++;
     
    131131        gc.gridx++;
    132132        pnlStandard.add(lbl, gc);
    133        
     133
    134134        cbMoped = new JCheckBox();
    135135        cbMoped.addItemListener(svtChangeListener);
    136136        lbl = new JLabel(tr("Mopeds"));
    137137        lbl.setIcon(ImageProvider.get("vehicle", "moped"));
    138        
     138
    139139        gc.weightx = 0.0;
    140140        gc.gridx = 0;
     
    144144        gc.gridx++;
    145145        pnlStandard.add(lbl, gc);
    146        
     146
    147147        return pnlStandard;
    148148    }
    149    
     149
    150150    private JPanel buildNonStandardInputPanel() {
    151151        if (pnlNonStandard != null)
     
    159159        gc.gridx = 0;
    160160        gc.gridy = 0;
    161        
     161
    162162        pnlNonStandard.add(new JLabel(tr("Value:")), gc);
    163163        gc.gridx = 1;
     
    165165        pnlNonStandard.add(tfNonStandardValue = new JTextField(), gc);
    166166        SelectAllOnFocusGainedDecorator.decorate(tfNonStandardValue);
    167        
     167
    168168        NonStandardVehicleTypesHandler inputChangedHandler = new NonStandardVehicleTypesHandler();
    169169        tfNonStandardValue.addActionListener(inputChangedHandler);
     
    171171        return pnlNonStandard;
    172172    }
    173        
     173
    174174    /**
    175      * Builds the UI for entering standard values 
     175     * Builds the UI for entering standard values
    176176     */
    177177    protected void buildStandard() {
     
    184184        gc.gridy = 0;
    185185        add(buildMessagePanel(), gc);
    186        
    187         gc.gridy=1;
    188         add(buildStandardInputPanel(), gc);     
    189     }
    190    
     186
     187        gc.gridy = 1;
     188        add(buildStandardInputPanel(), gc);
     189    }
     190
    191191    /**
    192      * Builds the UI for entering either standard or non-standard values 
     192     * Builds the UI for entering either standard or non-standard values
    193193     */
    194194    protected void buildNonStandard() {
     
    201201        gc.gridy = 0;
    202202        add(buildMessagePanel(), gc);
    203                
    204         gc.gridx=0;
    205         gc.gridy=1;
    206         gc.insets = new Insets(0,0,0,0);
     203
     204        gc.gridx = 0;
     205        gc.gridy = 1;
     206        gc.insets = new Insets(0, 0, 0, 0);
    207207        add(rbStandardException = new JRadioButton(tr("Use standard exceptions")), gc);
    208208
    209         gc.gridx=0;
    210         gc.gridy=2;
    211         gc.insets = new Insets(0, 20, 0,0);
     209        gc.gridx = 0;
     210        gc.gridy = 2;
     211        gc.insets = new Insets(0, 20, 0, 0);
    212212        add(buildStandardInputPanel(), gc);
    213213
    214         gc.gridx=0;
    215         gc.gridy=3;
    216         gc.insets = new Insets(0,0,0,0);
     214        gc.gridx = 0;
     215        gc.gridy = 3;
     216        gc.insets = new Insets(0, 0, 0, 0);
    217217        add(rbNonStandardException = new JRadioButton(tr("Use non-standard exceptions")), gc);
    218218
    219         gc.gridx=0;
    220         gc.gridy=4;
    221         gc.insets = new Insets(0, 20, 0,0);
     219        gc.gridx = 0;
     220        gc.gridy = 4;
     221        gc.insets = new Insets(0, 20, 0, 0);
    222222        add(buildNonStandardInputPanel(), gc);
    223        
     223
    224224        bgStandardOrNonStandard = new ButtonGroup();
    225225        bgStandardOrNonStandard.add(rbNonStandardException);
    226226        bgStandardOrNonStandard.add(rbStandardException);
    227        
     227
    228228        StandardNonStandardChangeHandler changeHandler = new StandardNonStandardChangeHandler();
    229229        rbNonStandardException.addItemListener(changeHandler);
    230230        rbStandardException.addItemListener(changeHandler);
    231231    }
    232    
     232
    233233    protected void build() {
    234234        removeAll();
    235235        buildNonStandardInputPanel();
    236236        buildStandardInputPanel();
    237         if (exceptValue.isStandard()){
     237        if (exceptValue.isStandard()) {
    238238            buildStandard();
    239239        } else {
     
    243243        invalidate();
    244244    }
    245    
     245
    246246    protected void init() {
    247247        try {
     
    257257            this.svtChangeListener.setEnabled(true);
    258258        }
    259         if (!exceptValue.isStandard()){
     259        if (!exceptValue.isStandard()) {
    260260            rbNonStandardException.setSelected(true);
    261261            tfNonStandardValue.setText(exceptValue.getValue());
     
    267267        }
    268268    }
    269    
     269
    270270    protected void setEnabledStandardInputPanel(boolean enabled) {
    271         for (Component c: pnlStandard.getComponents()){
     271        for (Component c: pnlStandard.getComponents()) {
    272272            c.setEnabled(enabled);
    273273        }
    274274    }
    275    
     275
    276276    protected void setEnabledNonStandardInputPanel(boolean enabled) {
    277         for (Component c: pnlNonStandard.getComponents()){
     277        for (Component c: pnlNonStandard.getComponents()) {
    278278            c.setEnabled(enabled);
    279279        }
    280280    }
    281281
    282    
     282
    283283    /**
    284      * Creates the editor 
    285      * 
     284     * Creates the editor
     285     *
    286286     * @param model the editor model. Must not be null.
    287287     * @throws IllegalArgumentException thrown if {@code model} is null
     
    293293        model.addObserver(this);
    294294    }
    295    
     295
    296296    /* ------------------------------------------------------------------------------------ */
    297297    /* interface Observer                                                                   */
    298298    /* ------------------------------------------------------------------------------------ */
     299    @Override
    299300    public void update(Observable o, Object arg) {
    300301        if (!this.exceptValue.equals(model.getExcept())) {
     
    308309    /* ------------------------------------------------------------------------------------ */
    309310    class StandardNonStandardChangeHandler implements ItemListener {
     311        @Override
    310312        public void itemStateChanged(ItemEvent e) {
    311             if (rbNonStandardException.isSelected()){
     313            if (rbNonStandardException.isSelected()) {
    312314                setEnabledNonStandardInputPanel(true);
    313315                setEnabledStandardInputPanel(false);
     
    321323        }
    322324    }
    323    
     325
    324326    class StandardVehicleTypeChangeListener implements ItemListener {
    325327        private boolean enabled = true;
    326        
    327         public void setEnabled(boolean enabled){
     328
     329        public void setEnabled(boolean enabled) {
    328330            this.enabled = enabled;
    329331        }
    330        
     332
     333        @Override
    331334        public void itemStateChanged(ItemEvent e) {
    332335            if (!enabled) return;
     
    335338            exceptValue.setVehicleException("hgv", cbHgv.isSelected());
    336339            exceptValue.setVehicleException("psv", cbPsv.isSelected());
    337             exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected());           
     340            exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected());
    338341            model.setExcept(exceptValue);
    339342        }
    340343    }
    341    
     344
    342345    class NonStandardVehicleTypesHandler implements ActionListener, FocusListener {
    343346        public void persist() {
     
    345348            model.setExcept(exceptValue);
    346349        }
    347        
     350
     351        @Override
    348352        public void focusGained(FocusEvent e) {}
     353
     354        @Override
    349355        public void focusLost(FocusEvent e) {
    350356            persist();
    351357        }
    352358
     359        @Override
    353360        public void actionPerformed(ActionEvent e) {
    354             persist();         
     361            persist();
    355362        }
    356363    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ViaList.java

    r32386 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    4849public class ViaList extends JList<OsmPrimitive> {
    4950
    50     //static private final Logger logger = Logger.getLogger(ViaList.class.getName());
     51    //private static final Logger logger = Logger.getLogger(ViaList.class.getName());
    5152
    5253    private ViaListModel model;
     
    7273        setCellRenderer(new OsmPrimitivRenderer());
    7374        setDragEnabled(true);
    74         setTransferHandler(transferHandler =new ViaListTransferHandler(model));
     75        setTransferHandler(transferHandler = new ViaListTransferHandler(model));
    7576        setVisibleRowCount(4);
    7677
    7778        actDelete = new DeleteAction();
    7879        selectionModel.addListSelectionListener(actDelete);
    79         registerKeyboardAction(actDelete, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     80        registerKeyboardAction(actDelete, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    8081
    8182        actMoveDown = new MoveDownAction();
    8283        selectionModel.addListSelectionListener(actMoveDown);
    83         registerKeyboardAction(actMoveDown, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     84        registerKeyboardAction(actMoveDown,
     85                KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    8486
    8587        actMoveUp = new MoveUpAction();
    8688        selectionModel.addListSelectionListener(actMoveUp);
    87         registerKeyboardAction(actMoveUp, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     89        registerKeyboardAction(actMoveUp,
     90                KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    8891
    8992        actCopy = new CopyAction();
     
    103106        private List<Integer> selectedRowsMemento = null;
    104107
    105         public ViaListTransferHandler(PrimitiveIdListProvider provider) {
     108        ViaListTransferHandler(PrimitiveIdListProvider provider) {
    106109            super(provider);
    107110        }
     
    121124                // this is a drag operation on itself
    122125                int targetRow = getSelectedIndex();
    123                 if (targetRow <0) return true;
     126                if (targetRow < 0) return true;
    124127                model.moveVias(selectedRowsMemento, targetRow);
    125128            } else {
    126129                // this is a drag operation from another component
    127130                try {
    128                     List<PrimitiveId> idsToAdd = (List<PrimitiveId>)t.getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
     131                    List<PrimitiveId> idsToAdd = (List<PrimitiveId>) t.getTransferData(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR);
    129132                    model.insertVias(idsToAdd);
    130                 } catch(IOException e){
     133                } catch (IOException e) {
    131134                    e.printStackTrace();
    132                 } catch(UnsupportedFlavorException e){
     135                } catch (UnsupportedFlavorException e) {
    133136                    e.printStackTrace();
    134137                }
     
    152155
    153156    class DeleteAction extends AbstractAction implements ListSelectionListener {
    154         public DeleteAction() {
     157        DeleteAction() {
    155158            putValue(NAME, tr("Remove"));
    156159            new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this);
    157             putValue(SHORT_DESCRIPTION,tr("Remove the currently selected vias"));
    158             putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0));
    159             updateEnabledState();
    160         }
    161 
     160            putValue(SHORT_DESCRIPTION, tr("Remove the currently selected vias"));
     161            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
     162            updateEnabledState();
     163        }
     164
     165        @Override
    162166        public void valueChanged(ListSelectionEvent e) {
    163167            updateEnabledState();
     
    168172        }
    169173
     174        @Override
    170175        public void actionPerformed(ActionEvent e) {
    171176            model.removeSelectedVias();
     
    173178    }
    174179
    175     class MoveDownAction extends AbstractAction implements ListSelectionListener{
    176         public MoveDownAction(){
     180    class MoveDownAction extends AbstractAction implements ListSelectionListener {
     181        MoveDownAction() {
    177182            putValue(NAME, tr("Move down"));
    178183            putValue(SHORT_DESCRIPTION, tr("Move the selected vias down by one position"));
    179             putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK));
     184            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK));
    180185            new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this);
    181186            updateEnabledState();
    182187        }
    183188
     189        @Override
    184190        public void actionPerformed(ActionEvent e) {
    185191            model.moveDown();
    186192        }
    187193
    188         public void updateEnabledState(){
     194        public void updateEnabledState() {
    189195            if (getSelectedIndex() < 0) {
    190196                setEnabled(false);
     
    194200        }
    195201
     202        @Override
    196203        public void valueChanged(ListSelectionEvent e) {
    197204            updateEnabledState();
     
    199206    }
    200207
    201     class MoveUpAction extends AbstractAction implements ListSelectionListener{
    202         public MoveUpAction() {
     208    class MoveUpAction extends AbstractAction implements ListSelectionListener {
     209        MoveUpAction() {
    203210            putValue(NAME, tr("Move up"));
    204211            putValue(SHORT_DESCRIPTION, tr("Move the selected vias up by one position"));
    205             putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK));
     212            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK));
    206213            new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this);
    207214            updateEnabledState();
    208215        }
    209216
     217        @Override
    210218        public void actionPerformed(ActionEvent e) {
    211219            model.moveUp();
    212220        }
    213221
    214         public void updateEnabledState(){
     222        public void updateEnabledState() {
    215223            if (getSelectedIndex() < 0) {
    216224                setEnabled(false);
     
    220228        }
    221229
     230        @Override
    222231        public void valueChanged(ListSelectionEvent e) {
    223232            updateEnabledState();
     
    228237        private Action delegate;
    229238
    230         public CopyAction(){
     239        CopyAction() {
    231240            putValue(NAME, tr("Copy"));
    232241            putValue(SHORT_DESCRIPTION, tr("Copy the selected vias to the clipboard"));
     
    236245        }
    237246
     247        @Override
    238248        public void actionPerformed(ActionEvent e) {
    239249            delegate.actionPerformed(e);
     
    244254        }
    245255
     256        @Override
    246257        public void valueChanged(ListSelectionEvent e) {
    247258            updateEnabledState();
     
    261272        }
    262273
    263         public PasteAction(){
     274        PasteAction() {
    264275            putValue(NAME, tr("Paste"));
    265276            putValue(SHORT_DESCRIPTION, tr("Insert ''via'' objects from the clipboard"));
     
    274285        }
    275286
     287        @Override
    276288        public void actionPerformed(ActionEvent e) {
    277289            delegate.actionPerformed(e);
     
    280292
    281293    class ViaListPopupMenu extends JPopupMenu {
    282         public ViaListPopupMenu() {
     294        ViaListPopupMenu() {
    283295            JMenuItem item = add(actCopy);
    284296            item.setTransferHandler(transferHandler);
     
    297309        @Override
    298310        public void launch(MouseEvent evt) {
    299             if (getSelectedIndex() <0) {
     311            if (getSelectedIndex() < 0) {
    300312                int idx = locationToIndex(evt.getPoint());
    301                 if (idx >=0) {
     313                if (idx >= 0) {
    302314                    setSelectedIndex(idx);
    303315                }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ViaListModel.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    2021/**
    2122 * ViaListModel is a model for the list of 'via' objects of a turn restriction.
    22  * 
     23 *
    2324 */
    24 public class ViaListModel extends AbstractListModel<OsmPrimitive> implements PrimitiveIdListProvider, Observer{
    25     //static private final Logger logger = Logger.getLogger(ViaListModel.class.getName());
    26    
     25public class ViaListModel extends AbstractListModel<OsmPrimitive> implements PrimitiveIdListProvider, Observer {
     26
    2727    private DefaultListSelectionModel selectionModel;
    2828    private final ArrayList<OsmPrimitive> vias = new ArrayList<>();
    2929    private TurnRestrictionEditorModel model;
    30    
    31     /**
    32      * Constructor 
    33      * 
     30
     31    /**
     32     * Constructor
     33     *
    3434     * @param model the turn restriction editor model. Must not be null.
    3535     * @param selectionModel the selection model. Must not be null.
     
    4848    /**
    4949     * Replies the list of currently selected vias
    50      * 
     50     *
    5151     * @return the list of currently selected vias
    5252     */
    5353    public List<OsmPrimitive> getSelectedVias() {
    5454        ArrayList<OsmPrimitive> ret = new ArrayList<>();
    55         for (int i=0; i < getSize(); i++) {
     55        for (int i = 0; i < getSize(); i++) {
    5656            if (selectionModel.isSelectedIndex(i)) {
    5757                ret.add(vias.get(i));
     
    6060        return ret;
    6161    }
    62    
     62
    6363    /**
    6464     * Sets the collection of currently selected vias
    65      * 
    66      *  @param vias a collection of vias 
     65     *
     66     *  @param vias a collection of vias
    6767     */
    6868    public void setSelectedVias(Collection<OsmPrimitive> vias) {
    6969        selectionModel.clearSelection();
    7070        if (vias == null) return;
    71         for(OsmPrimitive via: vias) {
     71        for (OsmPrimitive via: vias) {
    7272            int idx = this.vias.indexOf(via);
    7373            if (idx < 0) continue;
     
    7575        }
    7676    }
    77    
    78     /**
    79      * Replies the list of selected rows 
    80      * 
     77
     78    /**
     79     * Replies the list of selected rows
     80     *
    8181     * @return the list of selected rows
    8282     */
    8383    public List<Integer> getSelectedRows() {
    8484        ArrayList<Integer> ret = new ArrayList<>();
    85         for (int i=0; i < getSize(); i++) {
     85        for (int i = 0; i < getSize(); i++) {
    8686            if (selectionModel.isSelectedIndex(i)) {
    8787                ret.add(i);
     
    9090        return ret;
    9191    }
    92    
     92
    9393    protected List<Integer> moveUp(List<Integer> rows, int targetRow) {
    9494        List<Integer> ret = new ArrayList<>(rows.size());
    9595        int delta = rows.get(0) - targetRow;
    96         for(int row: rows) {
     96        for (int row: rows) {
    9797            OsmPrimitive via = vias.remove(row);
    9898            vias.add(row - delta, via);
     
    101101        return ret;
    102102    }
    103    
     103
    104104    protected List<Integer> moveDown(List<Integer> rows, int targetRow) {
    105105        List<Integer> ret = new ArrayList<>(rows.size());
    106106        int delta = targetRow - rows.get(0);
    107         for(int i = rows.size()-1; i >=0; i--) {
     107        for (int i = rows.size()-1; i >= 0; i--) {
    108108            int row = rows.get(i);
    109109            OsmPrimitive via = vias.remove(row);
     
    113113        return ret;
    114114    }
    115    
    116     public void moveVias(List<Integer> selectedRows, int targetRow){
     115
     116    public void moveVias(List<Integer> selectedRows, int targetRow) {
    117117        if (selectedRows == null) return;
    118         if (selectedRows.size() == 1){
     118        if (selectedRows.size() == 1) {
    119119            int sourceRow = selectedRows.get(0);
    120120            if (sourceRow == targetRow) return;
     
    124124            selectionModel.setSelectionInterval(targetRow, targetRow);
    125125            return;
    126         } 
     126        }
    127127        int min = selectedRows.get(0);
    128128        int max = selectedRows.get(selectedRows.size()-1);
    129129        if (targetRow < min) {
    130130            selectedRows = moveUp(selectedRows, targetRow);
    131         } else if (targetRow == min){
     131        } else if (targetRow == min) {
    132132            // do nothing
    133         } else if (targetRow - min < getSize() - max){
     133        } else if (targetRow - min < getSize() - max) {
    134134            int delta = Math.min(targetRow - min, getSize()-1 - max);
    135135            targetRow = min + delta;
     
    137137                selectedRows = moveDown(selectedRows, targetRow);
    138138            }
    139         } 
     139        }
    140140        fireContentsChanged(this, 0, getSize());
    141141        selectionModel.clearSelection();
    142         for(int row: selectedRows) {
     142        for (int row: selectedRows) {
    143143            selectionModel.addSelectionInterval(row, row);
    144         }       
    145     }
    146    
     144        }
     145    }
     146
    147147    /**
    148148     * Move the currently selected vias up by one position
     
    162162        moveVias(sel, sel.get(sel.size()-1)+1);
    163163    }
    164    
    165     /**
    166      * Inserts a list of OSM objects given by OSM primitive ids. 
    167      * 
     164
     165    /**
     166     * Inserts a list of OSM objects given by OSM primitive ids.
     167     *
    168168     * @param idsToInsert the ids of the objects to insert
    169169     */
     
    172172        List<OsmPrimitive> primitives = new ArrayList<>(idsToInsert.size());
    173173        DataSet ds = model.getLayer().data;
    174         for(PrimitiveId id: idsToInsert){
     174        for (PrimitiveId id: idsToInsert) {
    175175            OsmPrimitive p = ds.getPrimitiveById(id);
    176             if (p == null){
     176            if (p == null) {
    177177                System.out.println(tr("Failed to retrieve OSM object with id {0} from dataset {1}. Cannot add it as ''via''.", id, ds));
    178178                continue;
     
    180180            primitives.add(p);
    181181        }
    182         int targetRow = Math.max(selectionModel.getMinSelectionIndex(),0);
     182        int targetRow = Math.max(selectionModel.getMinSelectionIndex(), 0);
    183183        List<OsmPrimitive> newVias = new ArrayList<>(vias);
    184184        newVias.addAll(targetRow, primitives);
     
    186186        fireContentsChanged(this, 0, getSize());
    187187        selectionModel.clearSelection();
    188         for(int i=targetRow; i< targetRow + primitives.size();i++) {
     188        for (int i = targetRow; i < targetRow + primitives.size(); i++) {
    189189            selectionModel.addSelectionInterval(i, i);
    190         }           
     190        }
    191191    }
    192192
     
    197197        ArrayList<OsmPrimitive> newVias = new ArrayList<>(vias);
    198198        int j = 0;
    199         for(int i=0; i< getSize();i++){
     199        for (int i = 0; i < getSize(); i++) {
    200200            if (!selectionModel.isSelectedIndex(i)) continue;
    201201            newVias.remove(i-j);
     
    205205        model.setVias(newVias);
    206206    }
    207    
     207
    208208    /**
    209209     * Refreshes the list of 'vias' in this model with the current list of
    210      * vias from the turn restriction model. 
     210     * vias from the turn restriction model.
    211211     */
    212212    protected void refresh() {
    213213        List<OsmPrimitive> sel = getSelectedVias();
    214214        vias.clear();
    215         vias.addAll(model.getVias());       
     215        vias.addAll(model.getVias());
    216216        fireContentsChanged(this, 0, getSize());
    217217        setSelectedVias(sel);
    218218    }
    219219
     220    @Override
    220221    public OsmPrimitive getElementAt(int index) {
    221222        return vias.get(index);
    222223    }
    223224
     225    @Override
    224226    public int getSize() {
    225227        return vias.size();
    226228    }
    227    
     229
    228230    /* ----------------------------------------------------------------------- */
    229231    /* interface PrimitiveIdListProvider                                       */
    230232    /* ----------------------------------------------------------------------- */
     233    @Override
    231234    public List<PrimitiveId> getSelectedPrimitiveIds() {
    232235        ArrayList<PrimitiveId> ids = new ArrayList<>();
     
    240243    /* interface Observer                                                      */
    241244    /* ----------------------------------------------------------------------- */
     245    @Override
    242246    public void update(Observable o, Object arg) {
    243247        refresh();
    244     }   
     248    }
    245249}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/AbstractTurnRestrictionsListView.java

    r30454 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    1011/**
    1112 * The abstract base class for two views of turn restriction lists.
    12  * 
     13 *
    1314 * @see TurnRestrictionsInSelectionView
    1415 * @see TurnRestrictionsInDatasetView
     
    1819    protected TurnRestrictionsListModel model;
    1920    protected JList<Relation> lstTurnRestrictions;
    20    
    21     public TurnRestrictionsListModel getModel(){
     21
     22    public TurnRestrictionsListModel getModel() {
    2223        return model;
    2324    }
    24    
     25
    2526    public JList<Relation> getList() {
    2627        return lstTurnRestrictions;
    2728    }
    28    
     29
    2930    public void addListSelectionListener(ListSelectionListener listener) {
    3031        lstTurnRestrictions.addListSelectionListener(listener);
    3132    }
    32      
     33
    3334    public void removeListSelectionListener(ListSelectionListener listener) {
    3435        lstTurnRestrictions.addListSelectionListener(listener);
    3536    }
    36    
    37     public void initIconSetFromPreferences(Preferences prefs){
    38         TurnRestrictionCellRenderer renderer = (TurnRestrictionCellRenderer)lstTurnRestrictions.getCellRenderer();
     37
     38    public void initIconSetFromPreferences(Preferences prefs) {
     39        TurnRestrictionCellRenderer renderer = (TurnRestrictionCellRenderer) lstTurnRestrictions.getCellRenderer();
    3940        renderer.initIconSetFromPreferences(prefs);
    4041    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionCellRenderer.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    3435/**
    3536 * This is a cell renderer for turn restrictions.
    36  * 
     37 *
    3738 * It can be used a cell renderer in lists of turn restrictions and as cell renderer in
    38  * {@link JTable}s displaying turn restrictions. 
    39  * 
     39 * {@link JTable}s displaying turn restrictions.
     40 *
    4041 */
    41 public class TurnRestrictionCellRenderer extends JPanel implements ListCellRenderer<Relation>, TableCellRenderer{
    42     //static private final Logger logger = Logger.getLogger(TurnRestrictionCellRenderer.class.getName());
    43    
     42public class TurnRestrictionCellRenderer extends JPanel implements ListCellRenderer<Relation>, TableCellRenderer {
     43
    4444    /** the names of restriction types */
    45     static private Set<String> RESTRICTION_TYPES = new HashSet<>(
     45    private static Set<String> RESTRICTION_TYPES = new HashSet<>(
    4646            Arrays.asList(new String[] {
    4747                    "no_left_turn",
     
    5454            })
    5555    );
    56    
     56
    5757    /** components used to render the turn restriction */
    5858    private JLabel icon;
     
    6060    private JLabel to;
    6161    private String iconSet = "set-a";
    62    
     62
    6363    public TurnRestrictionCellRenderer() {
    6464        build();
     
    6868     * Replies true if {@code restrictionType} is a valid restriction
    6969     * type.
    70      * 
    71      * @param restrictionType the restriction type 
     70     *
     71     * @param restrictionType the restriction type
    7272     * @return true if {@code restrictionType} is a valid restriction
    7373     * type
     
    7878        return RESTRICTION_TYPES.contains(restrictionType);
    7979    }
    80    
    81     /**
    82      * Builds the icon name for a given restriction type 
    83      * 
    84      * @param restrictionType the restriction type 
    85      * @return the icon name 
     80
     81    /**
     82     * Builds the icon name for a given restriction type
     83     *
     84     * @param restrictionType the restriction type
     85     * @return the icon name
    8686     */
    8787    protected String buildImageName(String restrictionType) {
    8888        return "types/" + iconSet + "/" + restrictionType;
    8989    }
    90    
    91     /**
    92      * Replies the icon for a given restriction type 
    93      * @param restrictionType the restriction type 
    94      * @return the icon 
     90
     91    /**
     92     * Replies the icon for a given restriction type
     93     * @param restrictionType the restriction type
     94     * @return the icon
    9595     */
    9696    protected ImageIcon getIcon(String restrictionType) {
     
    100100        return ImageProvider.get(buildImageName(restrictionType));
    101101    }
    102    
    103     /**
    104      * Builds the UI used to render turn restrictions 
     102
     103    /**
     104     * Builds the UI used to render turn restrictions
    105105     */
    106106    protected void build() {
    107107        setLayout(new GridBagLayout());
    108108        GridBagConstraints gc = new GridBagConstraints();
    109        
    110         // the turn restriction icon       
     109
     110        // the turn restriction icon
    111111        gc.fill = GridBagConstraints.HORIZONTAL;
    112112        gc.weightx = 0.0;
    113113        gc.gridheight = 2;
    114114        gc.anchor = GridBagConstraints.CENTER;
    115         gc.insets = new Insets(0,0,2,2);
     115        gc.insets = new Insets(0, 0, 2, 2);
    116116        add(icon = new JLabel(), gc);
    117        
    118        
     117
     118
    119119        // the name of the way with role "from"
    120120        gc.anchor = GridBagConstraints.NORTHWEST;
     
    122122        gc.gridheight = 1;
    123123        gc.weightx = 0.0;
    124         add(new JMultilineLabel("<html><strong>" + trc("turnrestrictions","From:") + "</strong></html>"), gc);
    125        
     124        add(new JMultilineLabel("<html><strong>" + trc("turnrestrictions", "From:") + "</strong></html>"), gc);
     125
    126126        gc.gridx = 2;
    127         gc.weightx = 1.0; 
     127        gc.weightx = 1.0;
    128128        add(from = new JLabel(), gc);
    129        
     129
    130130        // the name of the way with role "to"
    131131        gc.anchor = GridBagConstraints.NORTHWEST;
     
    133133        gc.gridy = 1;
    134134        gc.weightx = 0.0;
    135         add(new JMultilineLabel("<html><strong>" + trc("turnrestriction", "To:")  + "</strong></html>"), gc);
    136        
     135        add(new JMultilineLabel("<html><strong>" + trc("turnrestriction", "To:") + "</strong></html>"), gc);
     136
    137137        gc.gridx = 2;
    138138        gc.weightx = 1.0;
     
    141141
    142142    /**
    143      * Renders the icon for the turn restriction 
    144      * 
     143     * Renders the icon for the turn restriction
     144     *
    145145     * @param tr the turn restriction
    146146     */
     
    152152    /**
    153153     * Replies a way participating in this turn restriction in a given role
    154      * 
    155      * @param tr the turn restriction 
     154     *
     155     * @param tr the turn restriction
    156156     * @param role the role (either "from" or "to")
    157157     * @return the participating way; null, if no way is participating in this role
    158158     */
    159     private Way getParticipatingWay(Relation tr, String role){
    160         for(RelationMember rm: tr.getMembers()){
     159    private Way getParticipatingWay(Relation tr, String role) {
     160        for (RelationMember rm: tr.getMembers()) {
    161161            if (rm.getRole().trim().toLowerCase().equals(role) && rm.getType().equals(OsmPrimitiveType.WAY)) {
    162                 return (Way)rm.getMember();
     162                return (Way) rm.getMember();
    163163            }
    164164        }
    165165        return null;
    166166    }
    167    
     167
    168168    protected void renderFrom(Relation tr) {
    169169        Way from = getParticipatingWay(tr, "from");
     
    172172            this.from.setText(tr("no participating way with role ''from''"));
    173173            return;
    174         } 
     174        }
    175175        this.from.setText(DefaultNameFormatter.getInstance().format(from));
    176176    }
     
    182182            this.to.setText(tr("no participating way with role ''to''"));
    183183            return;
    184         } 
     184        }
    185185        this.to.setText(DefaultNameFormatter.getInstance().format(to));
    186186    }
     
    189189     * Renders the foreground and background color depending on whether
    190190     * the turn restriction is selected
    191      * 
     191     *
    192192     * @param isSelected true if the turn restriction is selected; false,
    193193     * otherwise
     
    207207        this.from.setBackground(bg);
    208208        this.to.setBackground(bg);
    209        
     209
    210210        setForeground(fg);
    211211        this.icon.setForeground(fg);
     
    217217     * Initializes the set of icons used from the preference key
    218218     * {@link PreferenceKeys#ROAD_SIGNS}.
    219      * 
    220      * @param prefs the JOSM preferences 
    221      */
    222     public void initIconSetFromPreferences(Preferences prefs){
    223        
     219     *
     220     * @param prefs the JOSM preferences
     221     */
     222    public void initIconSetFromPreferences(Preferences prefs) {
     223
    224224        iconSet = prefs.get(PreferenceKeys.ROAD_SIGNS, "set-a");
    225225        iconSet = iconSet.trim().toLowerCase();
     
    228228        }
    229229    }
    230    
     230
    231231    /* ---------------------------------------------------------------------------------- */
    232232    /* interface ListCellRenderer                                                         */
    233233    /* ---------------------------------------------------------------------------------- */
     234    @Override
    234235    public Component getListCellRendererComponent(JList<? extends Relation> list, Relation value,
    235236            int index, boolean isSelected, boolean cellHasFocus) {
    236237
    237238        renderColor(isSelected);
    238         Relation tr = (Relation)value;
     239        Relation tr = value;
    239240        renderIcon(tr);
    240241        renderFrom(tr);
    241         renderTo(tr);       
     242        renderTo(tr);
    242243        return this;
    243244    }
     
    246247    /* interface TableCellRenderer                                                        */
    247248    /* ---------------------------------------------------------------------------------- */
     249    @Override
    248250    public Component getTableCellRendererComponent(JTable table, Object value,
    249251            boolean isSelected, boolean hasFocus, int row, int column) {
    250         renderColor(isSelected);       
    251         Relation tr = (Relation)value;
     252        renderColor(isSelected);
     253        Relation tr = (Relation) value;
    252254        renderIcon(tr);
    253255        renderFrom(tr);
    254         renderTo(tr);       
     256        renderTo(tr);
    255257        return this;
    256     }   
     258    }
    257259}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetListModel.java

    r32375 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    5051        List<Relation> ret = new LinkedList<>();
    5152        if (primitives == null) return ret;
    52         for(OsmPrimitive p: primitives){
     53        for (OsmPrimitive p: primitives) {
    5354            if (!isTurnRestriction(p)) continue;
    54             ret.add((Relation)p);
     55            ret.add((Relation) p);
    5556        }
    5657        return ret;
     
    111112        if (!turnRestrictions.isEmpty()) {
    112113            List<Relation> sel = getSelectedTurnRestrictions();
    113             for(Relation tr: turnRestrictions) {
     114            for (Relation tr: turnRestrictions) {
    114115                // enforce a repaint of the respective turn restriction
    115116                int idx = getTurnRestrictionIndex(tr);
    116                 fireContentsChanged(this, idx,idx);
     117                fireContentsChanged(this, idx, idx);
    117118            }
    118119            setSelectedTurnRestrictions(sel);
     
    125126        if (!turnRestrictions.isEmpty()) {
    126127            List<Relation> sel = getSelectedTurnRestrictions();
    127             for(Relation tr: turnRestrictions) {
     128            for (Relation tr: turnRestrictions) {
    128129                // enforce a repaint of the respective turn restriction
    129130                int idx = getTurnRestrictionIndex(tr);
    130                 fireContentsChanged(this, idx,idx);
     131                fireContentsChanged(this, idx, idx);
    131132            }
    132133            setSelectedTurnRestrictions(sel);
     
    136137    @Override
    137138    public void wayNodesChanged(WayNodesChangedEvent event) {/* ignore */}
     139
    138140    @Override
    139141    public void nodeMoved(NodeMovedEvent event) {/* ignore */}
     142
    140143    @Override
    141144    public void otherDatasetChange(AbstractDatasetChangedEvent event) {/* ignore */}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetView.java

    r32375 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    3132
    3233    protected void registerAsListener() {
    33         Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener)model);
    34         DatasetEventManager.getInstance().addDatasetListener((DataSetListener)model, FireMode.IN_EDT);
     34        Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener) model);
     35        DatasetEventManager.getInstance().addDatasetListener((DataSetListener) model, FireMode.IN_EDT);
    3536        if (Main.getLayerManager().getEditLayer() != null) {
    3637            model.setTurnRestrictions(Main.getLayerManager().getEditLayer().data.getRelations());
     
    3940
    4041    protected void unregisterAsListener() {
    41         Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener)model);
    42         DatasetEventManager.getInstance().removeDatasetListener((DataSetListener)model);
     42        Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener) model);
     43        DatasetEventManager.getInstance().removeDatasetListener((DataSetListener) model);
    4344    }
    4445
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionListModel.java

    r32375 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    1920 * objects in the current selection.
    2021 */
    21 public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel implements ActiveLayerChangeListener, SelectionChangedListener {
    22     //private static final Logger logger = Logger.getLogger(TurnRestrictionsInSelectionListModel.class.getName());
     22public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel
     23    implements ActiveLayerChangeListener, SelectionChangedListener {
    2324
    2425    public TurnRestrictionsInSelectionListModel(
     
    3940            for (OsmPrimitive parent: p.getReferrers()) {
    4041                if (isTurnRestriction(parent))
    41                     turnRestrictions.add((Relation)parent);
     42                    turnRestrictions.add((Relation) parent);
    4243            }
    4344        }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionView.java

    r32375 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    3637
    3738    protected void registerAsListener() {
    38         Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener)model);
    39         SelectionEventManager.getInstance().addSelectionListener((SelectionChangedListener)model, FireMode.IN_EDT_CONSOLIDATED);
    40         TurnRestrictionsInSelectionListModel m = (TurnRestrictionsInSelectionListModel)model;
    41         if (Main.getLayerManager().getEditLayer() != null){
     39        Main.getLayerManager().addActiveLayerChangeListener((ActiveLayerChangeListener) model);
     40        SelectionEventManager.getInstance().addSelectionListener((SelectionChangedListener) model, FireMode.IN_EDT_CONSOLIDATED);
     41        TurnRestrictionsInSelectionListModel m = (TurnRestrictionsInSelectionListModel) model;
     42        if (Main.getLayerManager().getEditLayer() != null) {
    4243            m.initFromSelection(Main.getLayerManager().getEditLayer().data.getSelected());
    4344        } else {
     
    4748
    4849    protected void unregisterAsListener() {
    49         Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener)model);
    50         SelectionEventManager.getInstance().removeSelectionListener((SelectionChangedListener)model);
     50        Main.getLayerManager().removeActiveLayerChangeListener((ActiveLayerChangeListener) model);
     51        SelectionEventManager.getInstance().removeSelectionListener((SelectionChangedListener) model);
    5152    }
    5253
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java

    r32386 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    5152 *
    5253 */
    53 public class TurnRestrictionsListDialog extends ToggleDialog{
    54     //private static final Logger logger = Logger.getLogger(TurnRestrictionsListDialog.class.getName());
     54public class TurnRestrictionsListDialog extends ToggleDialog {
    5555
    5656    /** checkbox for switching between the two list views */
     
    9797     */
    9898    protected void build() {
    99         JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
     99        JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    100100        pnl.setBorder(null);
    101101        pnl.add(cbInSelectionOnly = new JCheckBox(tr("Only participating in selection")));
     
    104104         + "Deselect to display all turn restrictions in the current data set.</html>"));
    105105
    106         pnlContent = new JPanel(new BorderLayout(0,0));
     106        pnlContent = new JPanel(new BorderLayout(0, 0));
    107107        pnlContent.setBorder(null);
    108         pnlContent.add(pnl,  BorderLayout.NORTH);
     108        pnlContent.add(pnl, BorderLayout.NORTH);
    109109
    110110        actNew = new NewAction();
     
    165165                pnlContent.remove(currentListView);
    166166            }
    167             pnlContent.add(view,BorderLayout.CENTER);
     167            pnlContent.add(view, BorderLayout.CENTER);
    168168            currentListView = view;
    169169            view.addListSelectionListener(actEdit);
     
    197197     *
    198198     */
    199     class EditAction extends AbstractAction implements ListSelectionListener{
    200         public EditAction() {
    201             putValue(SHORT_DESCRIPTION,tr("Open an editor for the selected turn restriction"));
     199    class EditAction extends AbstractAction implements ListSelectionListener {
     200        EditAction() {
     201            putValue(SHORT_DESCRIPTION, tr("Open an editor for the selected turn restriction"));
    202202            new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this, true);
    203203            putValue(NAME, tr("Edit"));
    204204            setEnabled(false);
    205205        }
     206
    206207        protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) {
    207208            Collection<RelationMember> members = new HashSet<>();
     
    226227            } else {
    227228                editor = new TurnRestrictionEditor(
    228                         TurnRestrictionsListDialog.this, layer,toEdit);
     229                        TurnRestrictionsListDialog.this, layer, toEdit);
    229230                manager.positionOnScreen(editor);
    230                 manager.register(layer, toEdit,editor);
     231                manager.register(layer, toEdit, editor);
    231232                editor.setVisible(true);
    232233            }
     
    243244
    244245        public void updateEnabledState() {
    245             setEnabled(currentListView!= null && currentListView.getModel().getSelectedTurnRestrictions().size() == 1);
     246            setEnabled(currentListView != null && currentListView.getModel().getSelectedTurnRestrictions().size() == 1);
    246247        }
    247248
     
    259260        class AbortException extends Exception {}
    260261
    261         public DeleteAction() {
    262             putValue(SHORT_DESCRIPTION,tr("Delete the selected turn restriction"));
     262        DeleteAction() {
     263            putValue(SHORT_DESCRIPTION, tr("Delete the selected turn restriction"));
    263264            new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true);
    264265            putValue(NAME, tr("Delete"));
     
    299300     */
    300301     class NewAction extends AbstractAction implements ActiveLayerChangeListener {
    301         public NewAction() {
    302             putValue(SHORT_DESCRIPTION,tr("Create a new turn restriction"));
     302        NewAction() {
     303            putValue(SHORT_DESCRIPTION, tr("Create a new turn restriction"));
    303304            new ImageProvider("new").getResource().attachImageIcon(this, true);
    304305            putValue(NAME, tr("New"));
     
    339340        class AbortException extends Exception {}
    340341
    341         public SelectSelectedTurnRestrictions() {
    342             putValue(SHORT_DESCRIPTION,tr("Set the current JOSM selection to the selected turn restrictions"));
     342        SelectSelectedTurnRestrictions() {
     343            putValue(SHORT_DESCRIPTION, tr("Set the current JOSM selection to the selected turn restrictions"));
    343344            new ImageProvider("selectall").getResource().attachImageIcon(this);
    344345            putValue(NAME, tr("Select in current data layer"));
     
    351352            List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions();
    352353            if (toSelect.isEmpty()) return;
    353             OsmDataLayer layer= Main.getLayerManager().getEditLayer();
     354            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    354355            if (layer == null) return;
    355356            layer.data.setSelected(toSelect);
     
    374375        class AbortException extends Exception {}
    375376
    376         public ZoomToAction() {
    377             putValue(SHORT_DESCRIPTION,tr("Zoom to the currently selected turn restrictions"));
     377        ZoomToAction() {
     378            putValue(SHORT_DESCRIPTION, tr("Zoom to the currently selected turn restrictions"));
    378379            new ImageProvider("dialogs/autoscale/selection").getResource().attachImageIcon(this);
    379380            putValue(NAME, tr("Zoom to"));
     
    386387            List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions();
    387388            if (toSelect.isEmpty()) return;
    388             OsmDataLayer layer= Main.getLayerManager().getEditLayer();
     389            OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    389390            if (layer == null) return;
    390391            layer.data.setSelected(toSelect);
     
    412413            if (lst.getSelectedIndices().length == 0) {
    413414                int idx = lst.locationToIndex(evt.getPoint());
    414                 if (idx >=0) {
     415                if (idx >= 0) {
    415416                    lst.getSelectionModel().addSelectionInterval(idx, idx);
    416417                }
     
    426427     */
    427428    class TurnRestrictionsPopupMenu extends JPopupMenu {
    428         public TurnRestrictionsPopupMenu() {
     429        TurnRestrictionsPopupMenu() {
    429430            add(actNew);
    430431            add(actEdit);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListModel.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.list;
    23
     
    1920/**
    2021 * This is a list model for a list of turn restrictions.
    21  * 
     22 *
    2223 */
    2324public class TurnRestrictionsListModel extends AbstractListModel<Relation> {
     
    2728    /**
    2829     * Creates the model
    29      * 
     30     *
    3031     * @param selectionModel the selection model used in the turn restriction list
    3132     */
     
    3637    /**
    3738     * Replies the turn restriction at position {@code idx} in the list.
    38      * 
    39      * @param idx the index 
     39     *
     40     * @param idx the index
    4041     * @return the turn restriction at position {@code idx} in the list.
    4142     */
     
    4546
    4647    /**
    47      * Sorts the turn restrictions in this model 
     48     * Sorts the turn restrictions in this model
    4849     */
    4950    public void sort() {
     
    5354                    NameFormatter formatter = DefaultNameFormatter.getInstance();
    5455
     56                    @Override
    5557                    public int compare(Relation r1, Relation r2) {
    5658                        return r1.getDisplayName(formatter).compareTo(r2.getDisplayName(formatter));
     
    6365        return !r.isDeleted() && r.isVisible() && !r.isIncomplete();
    6466    }
    65    
     67
    6668    /**
    6769     * Replies true if the primitive {@code primitive} represents
    68      * an OSM turn restriction. 
    69      * 
    70      * @param primitive the primitive 
     70     * an OSM turn restriction.
     71     *
     72     * @param primitive the primitive
    7173     * @return true if the primitive {@code primitive} represents
    7274     * an OSM turn restriction; false, otherwise
     
    7476    protected boolean isTurnRestriction(OsmPrimitive primitive) {
    7577        if (primitive == null) return false;
    76         if (! (primitive instanceof Relation)) return false;
     78        if (!(primitive instanceof Relation)) return false;
    7779        String type = primitive.get("type");
    78         if (type == null || ! type.equals("restriction")) return false;
     80        if (type == null || !type.equals("restriction")) return false;
    7981        return true;
    8082    }
    81    
     83
    8284    /**
    8385     * Populates the model with the turn restrictions in {@code turnrestrictions}.
    84      * 
    85      * @param turnrestrictions the turn restrictions 
     86     *
     87     * @param turnrestrictions the turn restrictions
    8688     */
    8789    public void setTurnRestrictions(Collection<Relation> turnrestrictions) {
    88         List<Relation> sel =  getSelectedTurnRestrictions();
     90        List<Relation> sel = getSelectedTurnRestrictions();
    8991        this.turnrestrictions.clear();
    9092        if (turnrestrictions == null) {
    9193            selectionModel.clearSelection();
    92             fireContentsChanged(this,0,getSize());
     94            fireContentsChanged(this, 0, getSize());
    9395            return;
    9496        }
     
    113115        boolean added = false;
    114116        for (OsmPrimitive p: addedPrimitives) {
    115             if (! isTurnRestriction(p)) {
    116                 continue;
    117             }
    118 
    119             Relation r = (Relation)p;
     117            if (!isTurnRestriction(p)) {
     118                continue;
     119            }
     120
     121            Relation r = (Relation) p;
    120122            if (!isValid(r)) continue;
    121123            if (turnrestrictions.contains(r)) {
     
    144146        for (OsmPrimitive p: removedPrimitives) {
    145147            if (!isTurnRestriction(p)) continue;
    146             removedTurnRestrictions.add((Relation)p);
    147         }
    148         if (removedTurnRestrictions.isEmpty())return;
     148            removedTurnRestrictions.add((Relation) p);
     149        }
     150        if (removedTurnRestrictions.isEmpty()) return;
    149151        int size = turnrestrictions.size();
    150152        turnrestrictions.removeAll(removedTurnRestrictions);
     
    157159    }
    158160
     161    @Override
    159162    public Relation getElementAt(int index) {
    160163        return turnrestrictions.get(index);
    161164    }
    162165
     166    @Override
    163167    public int getSize() {
    164168        return turnrestrictions.size();
     
    173177    public List<Relation> getSelectedNonNewRelations() {
    174178        ArrayList<Relation> ret = new ArrayList<>();
    175         for (int i=0; i<getSize();i++) {
     179        for (int i = 0; i < getSize(); i++) {
    176180            if (!selectionModel.isSelectedIndex(i)) {
    177181                continue;
     
    193197    public List<Relation> getSelectedTurnRestrictions() {
    194198        ArrayList<Relation> ret = new ArrayList<>();
    195         for (int i=0; i<getSize();i++) {
     199        for (int i = 0; i < getSize(); i++) {
    196200            if (!selectionModel.isSelectedIndex(i)) {
    197201                continue;
     
    213217        for (Relation r: sel) {
    214218            int i = turnrestrictions.indexOf(r);
    215             if (i<0) {
    216                 continue;
    217             }
    218             selectionModel.addSelectionInterval(i,i);
    219         }
    220     }
    221 
    222     /**
    223      * Returns the index of a turn restriction 
     219            if (i < 0) {
     220                continue;
     221            }
     222            selectionModel.addSelectionInterval(i, i);
     223        }
     224    }
     225
     226    /**
     227     * Returns the index of a turn restriction
    224228     *
    225229     * @return index of relation (-1, if not found)
     
    227231    public int getTurnRestrictionIndex(Relation tr) {
    228232        int i = turnrestrictions.indexOf(tr);
    229         if (i<0)return -1;
     233        if (i < 0) return -1;
    230234        return i;
    231235    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceEditor.java

    r27857 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.preferences;
    23
     
    4243    /**
    4344     * builds the panel with the sponsoring information
    44      *
    45      * @return
    4645     */
    4746    protected JPanel buildCreditPanel() {
    4847        JPanel pnl = new JPanel(new GridBagLayout());
    49         pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     48        pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    5049        GridBagConstraints gc = new GridBagConstraints();
    5150        gc.anchor = GridBagConstraints.NORTHWEST;
    5251        gc.fill = GridBagConstraints.HORIZONTAL;
    53         gc.insets = new Insets(0, 0,0, 5);
     52        gc.insets = new Insets(0, 0, 0, 5);
    5453        gc.weightx = 0.0;
    5554        JLabel lbl = new JLabel();
     
    5958        gc.gridx = 1;
    6059        gc.weightx = 1.0;
    61         HtmlPanel msg  =new HtmlPanel();
     60        HtmlPanel msg = new HtmlPanel();
    6261        msg.setText("<html><body>"
    6362                + tr("Development of the turn restriction plugin was sponsored "
     
    101100        tp.add(buildCreditPanel());
    102101        tp.setTitleAt(0, tr("Preferences"));
    103         tp.setToolTipTextAt(0,tr("Configure the preferences for the turnrestrictions plugin"));
     102        tp.setToolTipTextAt(0, tr("Configure the preferences for the turnrestrictions plugin"));
    104103        tp.setTitleAt(1, tr("Sponsor"));
    105104        mainPanel.add(tp, BorderLayout.CENTER);
    106105    }
    107106
     107    @Override
    108108    public void addGui(PreferenceTabbedPane gui) {
    109109        JPanel tab = gui.createPreferenceTab(this);
     
    111111    }
    112112
     113    @Override
    113114    public boolean ok() {
    114115        pnlIconPreferences.saveToPreferences(Main.pref);
     
    124125        }
    125126
     127        @Override
    126128        public void hyperlinkUpdate(HyperlinkEvent e) {
    127129            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceKeys.java

    r29854 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.preferences;
    23
     
    67/**
    78 * Defines the preference keys used for preferences of the turnrestrictions
    8  * plugin 
     9 * plugin
    910 *
    1011 */
     
    1718     *   <li><tt>set-b</tt> - the set of icons in the directory <tt>/images/types/set-b</tt></li>
    1819     * </ul>
    19      * 
     20     *
    2021     */
    2122    String ROAD_SIGNS = "turnrestrictions.road-signs";
    22    
     23
    2324    /**
    2425     * Indicates whether the Basic Editor should include a widget for for displaying
    2526     * and editing the via-objects of a turn restriction.
    26      * 
     27     *
    2728     * Supported values are:
    2829     * <ul>
     
    3233     */
    3334    String SHOW_VIAS_IN_BASIC_EDITOR = "turnrestrictions.show-vias-in-basic-editor";
    34    
     35
    3536    /**
    3637     * The shortcut which triggers creating a new or editing and existing turn
     
    3839     * If missing, the default value "ctrl shift T" is assumed.
    3940     */
    40     String EDIT_SHORTCUT= "turnrestrictions.edit-shortcut";
     41    String EDIT_SHORTCUT = "turnrestrictions.edit-shortcut";
    4142}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferencesPanel.java

    r29854 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.preferences;
    23
     
    2526 * IconPreferencePanel allows to configure a set of road sign icons to be
    2627 * used in the turnrestrictions plugin.
    27  * 
     28 *
    2829 */
    2930public class PreferencesPanel extends VerticallyScrollablePanel {
     
    3334    private ButtonGroup bgIconSet;
    3435    private JCheckBox cbShowViaListInBasicEditor;
    35    
     36
    3637    protected JPanel buildShowViaListInBasicEditorPanel() {
    3738        JPanel pnl = new JPanel(new GridBagLayout());
     
    4243        gc.gridx = 0;
    4344        gc.gridy = 0;
    44        
     45
    4546        HtmlPanel msg = new HtmlPanel();
    4647        msg.setText("<html><body>"
     
    5354        );
    5455        pnl.add(msg, gc);
    55        
     56
    5657        gc.gridy++;
    5758        pnl.add(cbShowViaListInBasicEditor = new JCheckBox(tr("Display and edit list of via-objects in the Basic Editor")), gc);
    5859        return pnl;
    5960    }
    60    
     61
    6162    /**
    6263     * Builds the panel for the icon set "set-a"
    63      *
    64      * @return
    6564     */
    6665    protected JPanel buildSetAPanel() {
     
    7271        gc.gridx = 0;
    7372        gc.gridy = 0;
    74        
    75         pnl.add(rbSetA = new JRadioButton(tr("Road signs - Set A")),gc);
    76        
     73
     74        pnl.add(rbSetA = new JRadioButton(tr("Road signs - Set A")), gc);
     75
    7776        JPanel icons = new JPanel(new FlowLayout(FlowLayout.LEFT));
    78         for (TurnRestrictionType type: TurnRestrictionType.values()){
     77        for (TurnRestrictionType type: TurnRestrictionType.values()) {
    7978            JLabel lbl = new JLabel();
    8079            icons.add(lbl);
    81             lbl.setIcon(ImageProvider.get("types/set-a",type.getTagValue()));
    82         }
    83        
     80            lbl.setIcon(ImageProvider.get("types/set-a", type.getTagValue()));
     81        }
     82
    8483        gc.gridy = 1;
    85         gc.insets = new Insets(0,20,0,0);
     84        gc.insets = new Insets(0, 20, 0, 0);
    8685        pnl.add(icons, gc);
    87         return pnl;     
    88     }
    89    
     86        return pnl;
     87    }
     88
    9089    /**
    9190     * Builds the panel for the icon set "set-b"
    92      *
    93      * @return
    9491     */
    9592    protected JPanel buildSetBPanel() {
     
    10198        gc.gridx = 0;
    10299        gc.gridy = 0;
    103        
    104         pnl.add(rbSetB = new JRadioButton(tr("Road signs - Set B")),gc);
    105        
     100
     101        pnl.add(rbSetB = new JRadioButton(tr("Road signs - Set B")), gc);
     102
    106103        JPanel icons = new JPanel(new FlowLayout(FlowLayout.LEFT));
    107         for (TurnRestrictionType type: TurnRestrictionType.values()){
     104        for (TurnRestrictionType type: TurnRestrictionType.values()) {
    108105            JLabel lbl = new JLabel();
    109106            icons.add(lbl);
    110             lbl.setIcon(ImageProvider.get("types/set-b",type.getTagValue()));
    111         }
    112        
     107            lbl.setIcon(ImageProvider.get("types/set-b", type.getTagValue()));
     108        }
     109
    113110        gc.gridy = 1;
    114         gc.insets = new Insets(0,20,0,0);
     111        gc.insets = new Insets(0, 20, 0, 0);
    115112        pnl.add(icons, gc);
    116         return pnl;     
    117     }
    118    
     113        return pnl;
     114    }
     115
    119116    /**
    120117     * Builds the message panel at the top
    121      *
    122      * @return
    123118     */
    124119    protected JPanel buildMessagePanel() {
     
    131126        return pnl;
    132127    }
    133    
     128
    134129    /**
    135130     * Builds the UI
    136      *
    137      * @return
    138      */
    139     protected void build() {           
     131     */
     132    protected void build() {
    140133        setLayout(new GridBagLayout());
    141134        GridBagConstraints gc = new GridBagConstraints();
     
    145138        gc.gridx = 0;
    146139        gc.gridy = 0;
    147        
     140
    148141        add(buildMessagePanel(), gc);
    149142        gc.gridy++;
     
    152145        add(buildSetBPanel(), gc);
    153146        gc.gridy++;
    154         add(new JSeparator(), gc);     
     147        add(new JSeparator(), gc);
    155148        gc.gridy++;
    156149        add(buildShowViaListInBasicEditorPanel(), gc);
     
    158151        add(new JSeparator(), gc);
    159152        gc.gridy++;
    160        
     153
    161154        // filler - just grab remaining space
    162155        gc.gridy++;
    163156        gc.fill = GridBagConstraints.BOTH;
    164157        gc.weighty = 1.0;
    165         add(new JPanel(), gc);       
    166        
     158        add(new JPanel(), gc);
     159
    167160        bgIconSet = new ButtonGroup();
    168161        bgIconSet.add(rbSetA);
    169162        bgIconSet.add(rbSetB);
    170        
    171         setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    172     }
    173    
     163
     164        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     165    }
     166
    174167    /**
    175168     * Initializes the UI from the current settings in the JOSM preferences
    176169     * {@code prefs}
    177      * 
    178      * @param prefs the preferences 
    179      */
    180     public void initFromPreferences(Preferences prefs){
     170     *
     171     * @param prefs the preferences
     172     */
     173    public void initFromPreferences(Preferences prefs) {
    181174        String set = prefs.get(PreferenceKeys.ROAD_SIGNS, "set-a");
    182         if (! set.equals("set-a") && ! set.equals("set-b")) {
    183             System.out.println(tr("Warning: the preference with key ''{0}'' has an unsupported value ''{1}''. Assuming the default value ''set-a''.", PreferenceKeys.ROAD_SIGNS, set));
     175        if (!set.equals("set-a") && !set.equals("set-b")) {
     176            System.out.println(
     177                    tr("Warning: the preference with key ''{0}'' has an unsupported value ''{1}''. Assuming the default value ''set-a''.",
     178                    PreferenceKeys.ROAD_SIGNS, set));
    184179            set = "set-a";
    185180        }
    186         if (set.equals("set-a")){
     181        if (set.equals("set-a")) {
    187182            rbSetA.setSelected(true);
    188183        } else {
    189184            rbSetB.setSelected(true);
    190185        }
    191        
     186
    192187        boolean b = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false);
    193188        cbShowViaListInBasicEditor.setSelected(b);
    194189    }
    195    
     190
    196191    /**
    197192     * Saves the current settings to the JOSM preferences {@code prefs}.
    198      * 
    199      * @param prefs the preferences 
    200      */
    201     public void saveToPreferences(Preferences prefs){
     193     *
     194     * @param prefs the preferences
     195     */
     196    public void saveToPreferences(Preferences prefs) {
    202197        prefs.put(PreferenceKeys.ROAD_SIGNS, rbSetA.isSelected() ? "set-a" : "set-b");
    203198        prefs.put(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, cbShowViaListInBasicEditor.isSelected());
    204199    }
    205    
     200
    206201    public PreferencesPanel() {
    207202        build();
    208     }   
     203    }
    209204}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IdenticalTurnRestrictionLegsError.java

    r23593 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1213/**
    1314 * Issue when the 'from' and 'to' leg are identical.
    14  * 
     15 *
    1516 */
    16 public class IdenticalTurnRestrictionLegsError extends Issue{
     17public class IdenticalTurnRestrictionLegsError extends Issue {
    1718    private OsmPrimitive leg;
    18    
     19
    1920    public IdenticalTurnRestrictionLegsError(IssuesModel parent, OsmPrimitive leg) {
    2021        super(parent, Severity.ERROR);
     
    2627
    2728    @Override
    28     public String getText() {       
     29    public String getText() {
     30        // CHECKSTYLE.OFF: LineLength
    2931        return tr("This turn restriction uses the way <span class=\"object-name\">{0}</span> with role <tt>from</tt> <strong>and</strong> with role <tt>to</tt>. "
    3032                + "In a turn restriction, the way with role <tt>from</tt> should be different from the way with role <tt>to</tt>, though.",
    3133                leg.getDisplayName(DefaultNameFormatter.getInstance())
    32                 );             
     34                );
     35        // CHECKSTYLE.ON: LineLength
    3336    }
    34    
     37
    3538    class DeleteFromAction extends AbstractAction {
    36         public DeleteFromAction() {
     39        DeleteFromAction() {
    3740            putValue(NAME, tr("Delete ''from''"));
    3841            putValue(SHORT_DESCRIPTION, tr("Removes the member with role ''from''"));
    3942        }
     43
     44        @Override
    4045        public void actionPerformed(ActionEvent e) {
    41             getIssuesModel().getEditorModel().getRelationMemberEditorModel().setFromPrimitive(null);           
    42         }       
     46            getIssuesModel().getEditorModel().getRelationMemberEditorModel().setFromPrimitive(null);
     47        }
    4348    }
    44    
     49
    4550    class DeleteToAction extends AbstractAction {
    46         public DeleteToAction() {
     51        DeleteToAction() {
    4752            putValue(NAME, tr("Delete ''to''"));
    4853            putValue(SHORT_DESCRIPTION, tr("Removes the member with role ''to''"));
    4954        }
     55
     56        @Override
    5057        public void actionPerformed(ActionEvent e) {
    51             getIssuesModel().getEditorModel().getRelationMemberEditorModel().setToPrimitive(null);         
    52         }       
     58            getIssuesModel().getEditorModel().getRelationMemberEditorModel().setToPrimitive(null);
     59        }
    5360    }
    54    
     61
    5562    class FixInEditorAction extends AbstractAction {
    56         public FixInEditorAction() {
     63        FixInEditorAction() {
    5764            putValue(NAME, tr("Fix in editor"));
    5865            putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually choose members with roles ''from'' and ''to''"));
    5966        }
     67
     68        @Override
    6069        public void actionPerformed(ActionEvent e) {
    61             getIssuesModel().getNavigationControler().gotoBasicEditor();       
    62         }       
     70            getIssuesModel().getNavigationControler().gotoBasicEditor();
     71        }
    6372    }
    6473}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IllegalRestrictionTypeError.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1213 * Issue when the restriction type isn't a standard value. Can't be fixed
    1314 * automatically, user is directed to the Basic editor.
    14  * 
     15 *
    1516 */
    16 public class IllegalRestrictionTypeError extends Issue{
     17public class IllegalRestrictionTypeError extends Issue {
    1718    private String value;
    18    
     19
    1920    public IllegalRestrictionTypeError(IssuesModel parent, String value) {
    2021        super(parent, Severity.ERROR);
     
    2425
    2526    @Override
    26     public String getText() {       
     27    public String getText() {
    2728        return tr("This turn restriction uses a non-standard restriction type <tt>{0}</tt> for the tag key <tt>restriction</tt>. "
    2829                + "It is recommended to use standard values only. Please select one in the Basic editor.",
    2930                value
    30                 );             
     31                );
    3132    }
    32    
     33
    3334    class FixInEditorAction extends AbstractAction {
    34         public FixInEditorAction() {
     35        FixInEditorAction() {
    3536            putValue(NAME, tr("Fix in editor"));
    3637            putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually choose a turn restriction type"));
    3738        }
     39
     40        @Override
    3841        public void actionPerformed(ActionEvent e) {
    39             getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE);         
    40         }       
     42            getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE);
     43        }
    4144    }
    4245}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IntersectionMissingAsViaError.java

    r26796 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1516
    1617/**
    17  * Issue when 'from' and 'to' intersect at node n and n isn't
    18  * a via.
    19  *
     18 * Issue when 'from' and 'to' intersect at node n and n isn't a via.
     19 *
    2020 */
    21 public class IntersectionMissingAsViaError extends Issue{
     21public class IntersectionMissingAsViaError extends Issue {
    2222    private Way from;
    2323    private Way to;
    2424    private Node intersect;
    25    
     25
    2626    public IntersectionMissingAsViaError(IssuesModel parent, Way from, Way to, Node intersect) {
    2727        super(parent, Severity.ERROR);
     
    3434
    3535    @Override
    36     public String getText() {       
    37         String msg = tr("The <strong>from</strong>-way <span class=\"object-name\">{0}</span> and the <strong>to</strong>-way <span class=\"object-name\">{1}</span> "
     36    public String getText() {
     37        // CHECKSTYLE.OFF: LineLength
     38        return tr("The <strong>from</strong>-way <span class=\"object-name\">{0}</span> and the <strong>to</strong>-way <span class=\"object-name\">{1}</span> "
    3839               + "intersect at node <span class=\"object-name\">{2}</span> but this node isn''t a <strong>via</strong>-object.<br> "
    3940               + "It is recommended to set it as unique <strong>via</strong>-object.",
     
    4243               this.intersect.getDisplayName(DefaultNameFormatter.getInstance())
    4344        );
    44         return msg;
     45        // CHECKSTYLE.ON: LineLength
    4546    }
    46    
     47
    4748    class SetVia extends AbstractAction {
    48         public SetVia() {
     49        SetVia() {
    4950            putValue(NAME, tr("Set via-Object"));
    5051            putValue(SHORT_DESCRIPTION, tr("Replaces the currently configured via-objects with the node at the intersection"));
    5152        }
     53
     54        @Override
    5255        public void actionPerformed(ActionEvent e) {
    5356            getIssuesModel().getEditorModel().setVias(Collections.<OsmPrimitive>singletonList(intersect));
    54         }       
     57        }
    5558    }
    56    
     59
    5760    class FixInEditorAction extends AbstractAction {
    58         public FixInEditorAction() {
     61        FixInEditorAction() {
    5962            putValue(NAME, tr("Fix in editor"));
    6063            putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually fix the list of via-objects"));
    6164        }
     65
     66        @Override
    6267        public void actionPerformed(ActionEvent e) {
    63             getIssuesModel().getNavigationControler().gotoBasicEditor(BasicEditorFokusTargets.VIA); 
    64         }       
     68            getIssuesModel().getNavigationControler().gotoBasicEditor(BasicEditorFokusTargets.VIA);
     69        }
    6570    }
    6671}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/Issue.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1011
    1112/**
    12  * An issue represents a data integrity violation in a turn restriction. 
    13  * 
     13 * An issue represents a data integrity violation in a turn restriction.
     14 *
    1415 * The issue has a {@see Severity}. It is described to the user with a HTML formatted
    1516 * text (see {@see #getText()}) and it suggests a list of possible actions to fix
    1617 * the issue (see {@see #getActions()}).
    17  * 
     18 *
    1819 */
    19 abstract public class Issue {
     20public abstract class Issue {
    2021    /** the parent model for this issue */
    2122    protected IssuesModel parent;
    2223    protected Severity severity;
    2324    protected final ArrayList<Action> actions = new ArrayList<>();
    24    
     25
    2526    /**
    2627     * Creates a new issue associated with a parent model. Severity is
    2728     * initialized to {@see Severity#WARNING}.
    28      * 
     29     *
    2930     * @param parent the parent model. Must not be null.
    3031     * @throws IllegalArgumentException thrown if parent is null
    3132     */
    32     public Issue(IssuesModel parent) throws IllegalArgumentException{
     33    public Issue(IssuesModel parent) throws IllegalArgumentException {
    3334        CheckParameterUtil.ensureParameterNotNull(parent, "parent");
    3435        this.parent = parent;
    3536        this.severity = Severity.WARNING;
    3637    }
    37    
     38
    3839    /**
    3940     * Creates a new issue of severity {@code severity} associated with
    4041     * the parent model {@code parent}.
    41      * 
     42     *
    4243     * @param parent the parent model. Must not be null.
    4344     * @param severity the severity. Must not be null.
    4445     * @throws IllegalArgumentException thrown if parent is null
    45      * @throws IllegalArgumentException thrown if severity is null 
     46     * @throws IllegalArgumentException thrown if severity is null
    4647     */
    47     public Issue(IssuesModel parent, Severity severity){
     48    public Issue(IssuesModel parent, Severity severity) {
    4849        CheckParameterUtil.ensureParameterNotNull(parent, "parent");
    4950        CheckParameterUtil.ensureParameterNotNull(severity, "severity");
     
    5354
    5455    /**
    55      * Replies the parent model this issue is associated with 
    56      * 
    57      * @return the parent model 
     56     * Replies the parent model this issue is associated with
     57     *
     58     * @return the parent model
    5859     */
    5960    public IssuesModel getIssuesModel() {
     
    6263
    6364    /**
    64      * Replies the severity of this issue 
    65      * 
    66      * @return the severity 
     65     * Replies the severity of this issue
     66     *
     67     * @return the severity
    6768     */
    6869    public Severity getSeverity() {
     
    7172
    7273    /**
    73      * Sets the severity of this issue. 
    74      * 
     74     * Sets the severity of this issue.
     75     *
    7576     * @param severity the severity. Must not be null.
    7677     * @throws IllegalArgumentException thrown if severity is null
     
    8384    /**
    8485     * Replies the HTML formatted description of the issue. The text should neither include
    85      * the &lt;html&gt;, nor the &lt;body&gt; tag. 
    86      * 
     86     * the &lt;html&gt;, nor the &lt;body&gt; tag.
     87     *
    8788     * @return the HTML formatted description of the issue.
    8889     */
    8990    public abstract String getText();
    90    
     91
    9192    /**
    9293     * Replies a list of actions which can be applied to this issue in order to fix
    9394     * it. The default implementation replies an empty list.
    94      * 
     95     *
    9596     * @return a list of action
    9697     */
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssueView.java

    r30454 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    2425 * An IssueView is a view on an individual {@see Issue}.
    2526 */
    26 public class IssueView extends JPanel{
     27public class IssueView extends JPanel {
    2728
    2829    private HtmlPanel pnlMessage;
     
    3031    private Issue issue;
    3132    private JLabel lblIcon;
    32    
     33
    3334     /**
    3435     * Builds the style sheet used in the internal help browser
     
    3738     */
    3839    protected void initStyleSheet(HtmlPanel view) {
    39         StyleSheet ss = ((HTMLEditorKit)view.getEditorPane().getEditorKit()).getStyleSheet();
     40        StyleSheet ss = ((HTMLEditorKit) view.getEditorPane().getEditorKit()).getStyleSheet();
    4041        ss.addRule("em {font-style: italic}");
    4142        ss.addRule("tt {font-family: Courier New}");
    42         ss.addRule(".object-name {background-color:rgb(240,240,240); color: blue;}");
     43        ss.addRule(".object-name {background-color:rgb(240, 240, 240); color: blue;}");
    4344    }
    44    
     45
    4546    protected void build() {
    4647        setLayout(new GridBagLayout());
    4748        setBackground(Color.WHITE);
    4849        setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1));
    49        
    50         // add the icon for the severity 
     50
     51        // add the icon for the severity
    5152        GridBagConstraints gc = new GridBagConstraints();
    5253        gc.anchor = GridBagConstraints.NORTHWEST;
     
    5758        gc.gridx = 0;
    5859        gc.gridy = 0;
    59         gc.insets = new Insets(2,2,2,2);
     60        gc.insets = new Insets(2, 2, 2, 2);
    6061        add(lblIcon = new JLabel(), gc);
    6162        lblIcon.setVerticalAlignment(SwingConstants.TOP);
    6263        lblIcon.setHorizontalAlignment(SwingConstants.CENTER);
    63         lblIcon.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
     64        lblIcon.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    6465
    65         // add the html panel with the issue description 
    66         gc.insets = new Insets(0,0,0,0);
     66        // add the html panel with the issue description
     67        gc.insets = new Insets(0, 0, 0, 0);
    6768        gc.anchor = GridBagConstraints.NORTHWEST;
    6869        gc.fill = GridBagConstraints.BOTH;
     
    7778        pnlMessage.setText("<html><body>" + issue.getText() + "</html></bod>");
    7879
    79        
    80         // if there are any actions available to resolve the issue, add a panel with action buttons 
     80
     81        // if there are any actions available to resolve the issue, add a panel with action buttons
    8182        if (!issue.getActions().isEmpty()) {
    8283            pnlActions = new JPanel(new FlowLayout(FlowLayout.LEFT));
    8384            pnlActions.setBackground(Color.WHITE);
    84             for (Action action: issue.getActions()){
     85            for (Action action: issue.getActions()) {
    8586                JButton btn = new JButton(action);
    86                 pnlActions.add(btn);               
     87                pnlActions.add(btn);
    8788            }
    88            
    89             gc.gridx = 1;           
    90             gc.gridy = 1;           
     89
     90            gc.gridx = 1;
     91            gc.gridy = 1;
    9192            gc.fill = GridBagConstraints.HORIZONTAL;
    9293            gc.weighty = 0.0;
    93             add(pnlActions,gc);
    94         }   
    95        
    96         // set the severity icon 
    97         switch(issue.getSeverity()){
    98         case WARNING: 
     94            add(pnlActions, gc);
     95        }
     96
     97        // set the severity icon
     98        switch(issue.getSeverity()) {
     99        case WARNING:
    99100            lblIcon.setIcon(ImageProvider.get("warning-small"));
    100101            break;
     
    102103            lblIcon.setIcon(ImageProvider.get("error"));
    103104            break;
    104         }       
     105        }
    105106    }
    106    
     107
    107108    /**
    108109     * Creates an issue view for an issue.
    109      * 
     110     *
    110111     * @param issue the issue. Must not be null.
    111112     * @throws IllegalArgumentException thrown if issue is null.
    112113     */
    113     public IssueView(Issue issue) throws IllegalArgumentException{
     114    public IssueView(Issue issue) throws IllegalArgumentException {
    114115        CheckParameterUtil.ensureParameterNotNull(issue, "issue");
    115116        this.issue = issue;
    116         build();       
     117        build();
    117118    }
    118119
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    2627 * <p>IssuesModel is a model for an observable list of {@code Issues}
    2728 * related to turn restriction.</p>
    28  * 
     29 *
    2930 * <p>It is also an {@link Observer} to an {@link TurnRestrictionEditorModel}
    3031 * and populates itself with issues it derives from the current state
    3132 * in the {@link TurnRestrictionEditorModel}.</p>
    32  * 
     33 *
    3334 */
    34 public class IssuesModel extends Observable implements Observer{
     35public class IssuesModel extends Observable implements Observer {
    3536    private final ArrayList<Issue> issues = new ArrayList<>();
    3637    private TurnRestrictionEditorModel editorModel;
    37    
    38     /**
    39      * Creates the model 
    40      * 
     38
     39    /**
     40     * Creates the model
     41     *
    4142     * @param editorModel the editor model. Must not be null.
    4243     * @throws IllegalArgumentException thrown if controler is null
    4344     */
    44     public IssuesModel(TurnRestrictionEditorModel editorModel) throws IllegalArgumentException{
     45    public IssuesModel(TurnRestrictionEditorModel editorModel) throws IllegalArgumentException {
    4546        CheckParameterUtil.ensureParameterNotNull(editorModel, "editorModel");
    4647        this.editorModel = editorModel;
    4748        this.editorModel.addObserver(this);
    4849    }
    49    
     50
    5051    /**
    5152     * Populates the model with a list of issues. Just clears the model
    52      * if {@code issues} is null or empty. 
    53      * 
    54      * @param issues the list of issues. 
    55      */
    56     public void populate(List<Issue> issues){
     53     * if {@code issues} is null or empty.
     54     *
     55     * @param issues the list of issues.
     56     */
     57    public void populate(List<Issue> issues) {
    5758        this.issues.clear();
    58         if (issues != null){
     59        if (issues != null) {
    5960            this.issues.addAll(issues);
    6061        }
     
    6263        notifyObservers();
    6364    }
    64    
     65
    6566    /**
    6667     * Replies the (unmodifiable) list of issues in this model.
    67      * 
     68     *
    6869     * @return the (unmodifiable) list of issues in this model.
    6970     */
     
    7172        return Collections.unmodifiableList(issues);
    7273    }
    73    
    74     /**
    75      * Replies the turn restriction editor model
    76      *
    77      * @return
     74
     75    /**
     76     * Replies the turn restriction editor model
    7877     */
    7978    public TurnRestrictionEditorModel getEditorModel() {
    8079        return editorModel;
    8180    }
    82    
     81
    8382    /**
    8483     * Populates this model with issues derived from the state of the
    8584     * turn restriction editor model. If {@code editorModel} is null, the
    8685     * list of issues is cleared.
    87      * 
    88      * @param editorModel the editor model. 
     86     *
     87     * @param editorModel the editor model.
    8988     */
    9089    public void populate() {
     
    10099        notifyObservers();
    101100    }
    102    
    103     /**
    104      * Checks whether there are required tags missing.
    105      *
    106      * @param editorModel
     101
     102    /**
     103     * Checks whether there are required tags missing.
    107104     */
    108105    protected void checkTags(TurnRestrictionEditorModel editorModel) {
    109106        TagEditorModel tagEditorModel = editorModel.getTagEditorModel();
    110107        TagModel tag = tagEditorModel.get("type");
    111        
     108
    112109        // missing marker tag for a turn restriction
    113         if (tag == null || ! tag.getValue().trim().equals("restriction")) {
     110        if (tag == null || !tag.getValue().trim().equals("restriction")) {
    114111            issues.add(new RequiredTagMissingError(this, "type", "restriction"));
    115112        }
    116        
     113
    117114        // missing or illegal restriction type ?
    118115        tag = tagEditorModel.get("restriction");
     
    123120        }
    124121
    125         // non-standard value for the 'except' tag? 
     122        // non-standard value for the 'except' tag?
    126123        ExceptValueModel except = getEditorModel().getExcept();
    127124        if (!except.isStandard()) {
     
    129126        }
    130127    }
    131    
     128
    132129    /**
    133130     * Checks various data integrity restriction for the relation member with
    134131     * role 'from'.
    135      * 
     132     *
    136133     */
    137134    protected void checkFromLeg(TurnRestrictionEditorModel editorModel) {
    138135        Set<OsmPrimitive> froms = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM);
    139         if (froms.isEmpty()){
     136        if (froms.isEmpty()) {
    140137            issues.add(new MissingTurnRestrictionLegError(this, TurnRestrictionLegRole.FROM));
    141138            return;
    142         } else if (froms.size() > 1){
     139        } else if (froms.size() > 1) {
    143140            issues.add(new MultipleTurnRestrictionLegError(this, TurnRestrictionLegRole.FROM, froms.size()));
    144141            return;
    145         } 
     142        }
    146143        OsmPrimitive p = froms.iterator().next();
    147         if (! (p instanceof Way)) {
     144        if (!(p instanceof Way)) {
    148145            issues.add(new WrongTurnRestrictionLegTypeError(this, TurnRestrictionLegRole.FROM, p));
    149146        }
    150147    }
    151    
     148
    152149    /**
    153150     * Checks various data integrity restriction for the relation member with
    154151     * role 'to'.
    155      * 
     152     *
    156153     */
    157154    protected void checkToLeg(TurnRestrictionEditorModel editorModel) {
    158155        Set<OsmPrimitive> toLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.TO);
    159         if (toLegs.isEmpty()){
     156        if (toLegs.isEmpty()) {
    160157            issues.add(new MissingTurnRestrictionLegError(this, TurnRestrictionLegRole.TO));
    161158            return;
    162         } else if (toLegs.size() > 1){
     159        } else if (toLegs.size() > 1) {
    163160            issues.add(new MultipleTurnRestrictionLegError(this, TurnRestrictionLegRole.TO, toLegs.size()));
    164161            return;
    165         } 
     162        }
    166163        OsmPrimitive p = toLegs.iterator().next();
    167         if (! (p instanceof Way)) {
     164        if (!(p instanceof Way)) {
    168165            issues.add(new WrongTurnRestrictionLegTypeError(this, TurnRestrictionLegRole.TO, p));
    169166        }
    170167    }
    171    
     168
    172169    /**
    173170     * Creates an issue if this turn restriction has identical 'from' and to'.
    174      *
    175      * @param editorModel
    176      */
    177     protected void checkFromAndToEquals(TurnRestrictionEditorModel editorModel){
     171     */
     172    protected void checkFromAndToEquals(TurnRestrictionEditorModel editorModel) {
    178173        Set<OsmPrimitive> toLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.TO);
    179174        Set<OsmPrimitive> fromLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM);
    180175        if (toLegs.size() != 1 || fromLegs.size() != 1) return;
    181        
     176
    182177        OsmPrimitive from = fromLegs.iterator().next();
    183178        OsmPrimitive to = toLegs.iterator().next();
    184        
    185         if (! (from instanceof Way)) return;
    186         if (! (to instanceof Way)) return;
    187         if (from.equals(to) && ! "no_u_turn".equals(editorModel.getRestrictionTagValue())){
     179
     180        if (!(from instanceof Way)) return;
     181        if (!(to instanceof Way)) return;
     182        if (from.equals(to) && !"no_u_turn".equals(editorModel.getRestrictionTagValue())) {
    188183            // identical from and to allowed for "no_u_turn" only
    189184            //
    190185            issues.add(new IdenticalTurnRestrictionLegsError(this, from));
    191         }       
    192     }
    193    
     186        }
     187    }
     188
    194189    /**
    195190     * Checks the 'via' members in the turn restriction
    196      * 
     191     *
    197192     * @param editorModel the editor model
    198193     */
    199     protected void checkVias(TurnRestrictionEditorModel editorModel){
     194    protected void checkVias(TurnRestrictionEditorModel editorModel) {
    200195        Set<OsmPrimitive> toLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.TO);
    201196        Set<OsmPrimitive> fromLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM);
    202197        // we only check vias if 'to' and 'from' are already OK
    203198        if (toLegs.size() != 1 || fromLegs.size() != 1) return;
    204         if (! (toLegs.iterator().next() instanceof Way)) return;
    205         if (! (fromLegs.iterator().next() instanceof Way)) return;
    206        
    207         Way from = (Way)fromLegs.iterator().next();
    208         Way to = (Way)toLegs.iterator().next();
    209         Node intersect = TurnRestrictionBuilder.getUniqueCommonNode(from, to);       
    210         if (intersect != null){
     199        if (!(toLegs.iterator().next() instanceof Way)) return;
     200        if (!(fromLegs.iterator().next() instanceof Way)) return;
     201
     202        Way from = (Way) fromLegs.iterator().next();
     203        Way to = (Way) toLegs.iterator().next();
     204        Node intersect = TurnRestrictionBuilder.getUniqueCommonNode(from, to);
     205        if (intersect != null) {
    211206            if (!editorModel.getVias().contains(intersect)) {
    212207                issues.add(new IntersectionMissingAsViaError(this, from, to, intersect));
     
    214209            if (isInnerNode(from, intersect) && isInnerNode(to, intersect)) {
    215210                issues.add(new TurnRestrictionLegSplitRequiredError(this, from, to));
    216             } else if (isInnerNode(from, intersect) && ! isInnerNode(to, intersect)) {
     211            } else if (isInnerNode(from, intersect) && !isInnerNode(to, intersect)) {
    217212                issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect));
    218213            } else if (!isInnerNode(from, intersect) && isInnerNode(to, intersect)) {
     
    220215            }
    221216        } else {
    222             if (editorModel.getVias().isEmpty() && ! from.equals(to)){
     217            if (editorModel.getVias().isEmpty() && !from.equals(to)) {
    223218                // the two turn restriction legs aren't connected and we don't have configured
    224                 // via objects 
     219                // via objects
    225220                issues.add(new MissingViaError(this));
    226221            }
    227         }               
    228     }
    229    
     222        }
     223    }
     224
    230225    public NavigationControler getNavigationControler() {
    231226        return editorModel.getNavigationControler();
    232227    }
    233    
     228
    234229    public int getNumWarnings() {
    235230        int ret = 0;
    236         for (Issue issue: issues){
     231        for (Issue issue: issues) {
    237232            if (issue.getSeverity().equals(Severity.WARNING)) ret++;
    238233        }
     
    242237    public int getNumErrors() {
    243238        int ret = 0;
    244         for (Issue issue: issues){
     239        for (Issue issue: issues) {
    245240            if (issue.getSeverity().equals(Severity.ERROR)) ret++;
    246241        }
     
    251246    /* interface Observer                                                                    */
    252247    /* ------------------------------------------------------------------------------------- */
     248    @Override
    253249    public void update(Observable o, Object arg) {
    254         populate();     
     250        populate();
    255251    }
    256252}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesView.java

    r29854 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1516 * IssuesView provides a view on a {@see IssuesModel}.
    1617 */
    17 public class IssuesView extends VerticallyScrollablePanel implements Observer{
    18     //static private final Logger logger = Logger.getLogger(IssuesView.class.getName());
    19    
     18public class IssuesView extends VerticallyScrollablePanel implements Observer {
     19    //private static final Logger logger = Logger.getLogger(IssuesView.class.getName());
     20
    2021    /** the issues model */
    2122    private IssuesModel model;
    22    
    23     protected void build(){
     23
     24    protected void build() {
    2425        setLayout(new GridBagLayout());
    2526    }
    26    
     27
    2728    /**
    28      * Creates the view 
    29      * 
     29     * Creates the view
     30     *
    3031     * @param model the model. Must not be null.
    3132     * @exception IllegalArgumentException thrown if model is null
    3233     */
    33     public IssuesView(IssuesModel model) throws IllegalArgumentException{
     34    public IssuesView(IssuesModel model) throws IllegalArgumentException {
    3435        CheckParameterUtil.ensureParameterNotNull(model, "model");
    3536        this.model = model;
     
    3839        HelpUtil.setHelpContext(this, HelpUtil.ht("/Plugin/TurnRestrictions#ErrorsAndWarnings"));
    3940    }
    40    
     41
    4142    /**
    4243     * Refreshes the view with the current state in the model
     
    4445    public void refresh() {
    4546        removeAll();
    46         if (! model.getIssues().isEmpty()){
     47        if (!model.getIssues().isEmpty()) {
    4748            GridBagConstraints gc = new GridBagConstraints();
    4849            gc.anchor = GridBagConstraints.NORTHWEST;
     
    5253            gc.gridx = 0;
    5354            gc.gridy = 0;
    54             for (Issue issue: model.getIssues()){
     55            for (Issue issue: model.getIssues()) {
    5556                add(new IssueView(issue), gc);
    5657                gc.gridy++;
    5758            }
    5859            // filler - grabs remaining space
    59             gc.weighty = 1.0;           
     60            gc.weighty = 1.0;
    6061            add(new JPanel(), gc);
    6162        }
     
    6667    /* interface Observer                                                              */
    6768    /* ------------------------------------------------------------------------------- */
     69    @Override
    6870    public void update(Observable o, Object arg) {
    69         refresh();     
     71        refresh();
    7072    }
    7173}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingRestrictionTypeError.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1213 * Issue when the restriction type is missing. Can't be fixed automatically, user
    1314 * is redirected to the Basic Editor.
    14  * 
     15 *
    1516 */
    16 public class MissingRestrictionTypeError extends Issue{
    17    
     17public class MissingRestrictionTypeError extends Issue {
     18
    1819    public MissingRestrictionTypeError(IssuesModel parent) {
    1920        super(parent, Severity.ERROR);
     
    2324    @Override
    2425    public String getText() {
    25         return tr("A turn restriction must declare the type of restriction. Please select a type in the Basic Editor.");               
     26        return tr("A turn restriction must declare the type of restriction. Please select a type in the Basic Editor.");
    2627    }
    27    
     28
    2829    class FixInEditorAction extends AbstractAction {
    29         public FixInEditorAction() {
     30        FixInEditorAction() {
    3031            putValue(NAME, tr("Fix in editor"));
    3132            putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually choose a turn restriction type"));
    3233        }
     34
     35        @Override
    3336        public void actionPerformed(ActionEvent e) {
    34             getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE);         
    35         }       
     37            getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE);
     38        }
    3639    }
    3740}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingTurnRestrictionLegError.java

    r29854 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1415 * A member with role 'from' or 'to' is missing. Can't be fixed automatically.
    1516 * Redirect the user to the Basic editor panel.
    16  * 
     17 *
    1718 */
    1819public class MissingTurnRestrictionLegError extends Issue {
     
    2021
    2122    /**
    22      * Creates the issue. 
    23      * 
    24      * @param parent the parent model 
     23     * Creates the issue.
     24     *
     25     * @param parent the parent model
    2526     * @param role the role of the missing way
    2627     */
     
    3435    public String getText() {
    3536        String msg = "";
    36         switch(role){
    37         case FROM: 
     37        switch(role) {
     38        case FROM:
    3839            msg = tr("A way with role <tt>from</tt> is required in a turn restriction.");
    3940            break;
    40         case TO: 
     41        case TO:
    4142            msg = tr("A way with role <tt>to</tt> is required in a turn restriction.");
    4243            break;
     
    4748
    4849    class FixAction extends AbstractAction {
    49         public FixAction() {
     50        FixAction() {
    5051            putValue(NAME, tr("Add in editor"));
    51             switch(role){
     52            switch(role) {
    5253            case FROM:
    5354                putValue(SHORT_DESCRIPTION, tr("Add a way with role ''from''"));
     
    5556            case TO:
    5657                putValue(SHORT_DESCRIPTION, tr("Add a way with role ''to''"));
    57                 break;             
    58             }           
     58                break;
     59            }
    5960        }
     61
     62        @Override
    6063        public void actionPerformed(ActionEvent e) {
    61             switch(role){
     64            switch(role) {
    6265            case FROM:
    6366                getIssuesModel().getNavigationControler().gotoBasicEditor(FROM);
     
    6568            case TO:
    6669                getIssuesModel().getNavigationControler().gotoBasicEditor(TO);
    67                 break;             
    68             }           
    69         }       
     70                break;
     71            }
     72        }
    7073    }
    7174}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingViaError.java

    r30365 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    89
    910/**
    10  * Issue if the legs of a turn restriction aren't connected and if there 
    11  * are no via objects configured. 
    12  * 
     11 * Issue if the legs of a turn restriction aren't connected and if there
     12 * are no via objects configured.
     13 *
    1314 */
    1415public class MissingViaError extends Issue {
     
    2122    @Override
    2223    public String getText() {
    23          String msg = 
     24         String msg =
    2425             tr("The two ways participating in the turn restriction <strong>aren''t connected.</strong>")
    2526            + "<p>"
     
    2930
    3031    class FixAction extends AbstractAction {
    31         public FixAction() {
     32        FixAction() {
    3233            putValue(NAME, tr("Fix in editor"));
    3334            putValue(SHORT_DESCRIPTION, tr("Go to the Advanced Editor and add via objects"));
    3435        }
     36
     37        @Override
    3538        public void actionPerformed(ActionEvent e) {
    3639            getIssuesModel().getNavigationControler().gotoAdvancedEditor();
    37         }       
     40        }
    3841    }
    3942}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MultipleTurnRestrictionLegError.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1112/**
    1213 * Issue when a turn restriction has multiple members with role 'from' or 'to'.
    13  * 
     14 *
    1415 */
    1516public class MultipleTurnRestrictionLegError extends Issue {
    1617    private TurnRestrictionLegRole role;
    1718    private int numLegs;
    18    
     19
    1920    /**
    2021     * Create the issue
    21      * 
    22      * @param parent the parent model 
    23      * @param role the role of the turn restriction leg with multiple entries 
     22     *
     23     * @param parent the parent model
     24     * @param role the role of the turn restriction leg with multiple entries
    2425     * @param numLegs the number of legs
    2526     */
     
    3334    @Override
    3435    public String getText() {
    35         switch(role){
    36         case FROM: 
     36        switch(role) {
     37        case FROM:
    3738            return tr("A turn restriction requires exactly one way with role <tt>from</tt>. "
    3839                + "This turn restriction has {0} ways in this role. Please remove "
     
    4142                numLegs -1
    4243            );
    43         case TO: 
     44        case TO:
    4445            return tr("A turn restriction requires exactly one way with role <tt>to</tt>. "
    4546                    + "This turn restriction has {0} ways in this role. Please remove "
     
    5354
    5455    class FixAction extends AbstractAction {
    55         public FixAction() {
     56        FixAction() {
    5657            putValue(NAME, tr("Fix in editor"));
    5758            putValue(SHORT_DESCRIPTION, tr("Go to the Advanced Editor and remove the members"));
    5859        }
     60
     61        @Override
    5962        public void actionPerformed(ActionEvent e) {
    6063            getIssuesModel().getNavigationControler().gotoAdvancedEditor();
    61         }       
     64        }
    6265    }
    6366}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/NonStandardExceptWarning.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1112/**
    1213 * Issue when the 'except' tag consists of non-standard values
    13  * 
     14 *
    1415 */
    15 public class NonStandardExceptWarning extends Issue{
     16public class NonStandardExceptWarning extends Issue {
    1617    private ExceptValueModel value;
    1718    public NonStandardExceptWarning(IssuesModel parent, ExceptValueModel value) {
    1819        super(parent, Severity.WARNING);
    1920        actions.add(new FixInEditorAction());
    20         this.value  = value;
     21        this.value = value;
    2122    }
    2223
    2324    @Override
    24     public String getText() {       
     25    public String getText() {
    2526        return tr("The tag <tt>except</tt> has the non-standard value <tt>{0}</tt>. "
    2627                + "It is recommended to use standard values for <tt>except</tt> only.",
    2728                value.getValue()
    28                 );             
     29                );
    2930    }
    30    
     31
    3132    class FixInEditorAction extends AbstractAction {
    32         public FixInEditorAction() {
     33        FixInEditorAction() {
    3334            putValue(NAME, tr("Fix in editor"));
    3435            putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and select standard vehicle type based exceptions"));
    3536        }
     37
     38        @Override
    3639        public void actionPerformed(ActionEvent e) {
    37             getIssuesModel().getNavigationControler().gotoBasicEditor();       
    38         }       
     40            getIssuesModel().getNavigationControler().gotoBasicEditor();
     41        }
    3942    }
    4043}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/RequiredTagMissingError.java

    r30454 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1415 */
    1516public class RequiredTagMissingError extends Issue {
    16     //static private final Logger logger = Logger.getLogger(RequiredTagMissingError.class.getName());
     17    //private static final Logger logger = Logger.getLogger(RequiredTagMissingError.class.getName());
    1718    private String tagKey;
    1819    private String tagValue;
    19    
     20
    2021    /**
    21      * Create the issue 
    22      * 
     22     * Create the issue
     23     *
    2324     * @param parent the issues model
    24      * @param tagKey the tag key 
    25      * @param tagValue the tag value 
     25     * @param tagKey the tag key
     26     * @param tagValue the tag value
    2627     */
    2728    public RequiredTagMissingError(IssuesModel parent, String tagKey, String tagValue) {
     
    3334
    3435    @Override
    35     public String getText() {   
    36         return tr("The required tag <tt>{0}={1}</tt> is missing.",             
     36    public String getText() {
     37        return tr("The required tag <tt>{0}={1}</tt> is missing.",
    3738                this.tagKey,
    3839                this.tagValue
     
    4142
    4243    private class AddTagAction extends AbstractAction {
    43         public AddTagAction(){
    44             putValue(NAME,tr("Add missing tag"));
    45             putValue(SHORT_DESCRIPTION, tr("Add the missing tag {0}={1}", tagKey, tagValue));       
     44        AddTagAction() {
     45            putValue(NAME, tr("Add missing tag"));
     46            putValue(SHORT_DESCRIPTION, tr("Add the missing tag {0}={1}", tagKey, tagValue));
    4647        }
    47        
     48
     49        @Override
    4850        public void actionPerformed(ActionEvent e) {
    4951            TagEditorModel model = getIssuesModel().getEditorModel().getTagEditorModel();
    5052            TagModel t = model.get(tagKey);
    51             if (t == null){
     53            if (t == null) {
    5254                t = new TagModel(tagKey, tagValue);
    5355                model.prepend(t);
    54             }           
    55         }       
     56            }
     57        }
    5658    }
    5759}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/Severity.java

    r23192 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/TurnRestrictionLegSplitRequiredError.java

    r30454 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    2627 *
    2728 */
    28 public class TurnRestrictionLegSplitRequiredError extends Issue{
    29     //static private final Logger logger = Logger.getLogger(TurnRestrictionLegSplitRequiredError.class.getName());
    30    
     29public class TurnRestrictionLegSplitRequiredError extends Issue {
     30
    3131    private TurnRestrictionLegRole role;
    3232    private Way from;
    3333    private Way to;
    3434    private Node intersect;
    35    
     35
    3636    /**
    3737     * <p>Creates the issue for a pair of ways {@code from} and {@code to} which intersect
    3838     * at node {@code intersect}.</p>
    39      * 
    40      * @param parent the parent model 
     39     *
     40     * @param parent the parent model
    4141     * @param from the way with role "from"
    4242     * @param to the way with role "to"
    43      * @param intersect the intersection node 
     43     * @param intersect the intersection node
    4444     */
    45     public TurnRestrictionLegSplitRequiredError(IssuesModel parent, Way from, Way to){
     45    public TurnRestrictionLegSplitRequiredError(IssuesModel parent, Way from, Way to) {
    4646        super(parent, Severity.ERROR);
    4747        CheckParameterUtil.ensureParameterNotNull(from, "from");
    4848        CheckParameterUtil.ensureParameterNotNull(to, "to");
    49        
    50         intersect= TurnRestrictionBuilder.getUniqueCommonNode(from, to);
     49
     50        intersect = TurnRestrictionBuilder.getUniqueCommonNode(from, to);
    5151        if (intersect == null)
    5252            throw new IllegalArgumentException("exactly one intersecting node required");
    53        
     53
    5454        this.from = from;
    5555        this.to = to;
     
    7979    public String getText() {
    8080        String msg = null;
    81         if (role == null){
     81        if (role == null) {
    8282            /*
    8383             * from and to intersect at a common node. Both have to be split.
    8484             */
    8585            return tr("The way <span class=\"object-name\">{0}</span> with role <tt>from</tt> and the "
    86                     + "way <span class=\"object-name\">{1}</span> with role <tt>to</tt> intersect "                   
     86                    + "way <span class=\"object-name\">{1}</span> with role <tt>to</tt> intersect "
    8787                    + "at node <span class=\"object-name\">{2}</span>. "
    8888                    + "<p> "
     
    9393                );
    9494        }
    95         switch(role){
     95        switch(role) {
    9696        case FROM:
    9797            /*
     
    123123
    124124    class SplitAction extends AbstractAction {
    125         public SplitAction() {
     125        SplitAction() {
    126126            putValue(NAME, tr("Split now"));
    127127            putValue(SHORT_DESCRIPTION, tr("Split the ways"));
    128128        }
    129        
     129
     130        @Override
    130131        public void actionPerformed(ActionEvent e) {
    131132
    132133            SplitWayResult result = null;
    133             if (role == null || role.equals(TurnRestrictionLegRole.FROM)){
     134            if (role == null || role.equals(TurnRestrictionLegRole.FROM)) {
    134135                  result = SplitWayAction.split(
    135136                          parent.getEditorModel().getLayer(),
     
    138139                          Collections.<OsmPrimitive>emptyList()
    139140                  );
    140                   if (result != null){
     141                  if (result != null) {
    141142                      Main.main.undoRedo.add(result.getCommand());
    142143                  }
    143144            }
    144            
     145
    145146            if (role == null || role.equals(TurnRestrictionLegRole.TO)) {
    146147                result = SplitWayAction.split(
     
    150151                        Collections.<OsmPrimitive>emptyList()
    151152                );
    152                 if (result != null){
     153                if (result != null) {
    153154                    Main.main.undoRedo.add(result.getCommand());
    154155                }
    155156                if (result == null) return;
    156                 TurnRestrictionType restrictionType = TurnRestrictionType.fromTagValue(getIssuesModel().getEditorModel().getRestrictionTagValue());
     157                TurnRestrictionType restrictionType = TurnRestrictionType.fromTagValue(
     158                        getIssuesModel().getEditorModel().getRestrictionTagValue());
    157159                if (restrictionType == null) return;
    158160                Way adjustedTo = TurnRestrictionBuilder.selectToWayAfterSplit(
     
    162164                         restrictionType
    163165                );
    164    
     166
    165167                if (adjustedTo == null) return;
    166168                getIssuesModel().getEditorModel().setTurnRestrictionLeg(
    167169                         TurnRestrictionLegRole.TO,
    168170                         adjustedTo
    169                 );         
     171                );
    170172                getIssuesModel().getEditorModel().getLayer().data.setSelected(
    171173                           Arrays.asList(from, adjustedTo)
    172                  );   
     174                 );
    173175            } else {
    174176                getIssuesModel().getEditorModel().getLayer().data.setSelected(
    175177                           Arrays.asList(from, to)
    176178                 );
    177             }           
     179            }
    178180        }
    179181    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/WrongTurnRestrictionLegTypeError.java

    r30454 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    1617/**
    1718 * Issue if the type of a turn restriction leg is either an OSM node or an OSM relation.
    18  * 
     19 *
    1920 */
    2021public class WrongTurnRestrictionLegTypeError extends Issue {
     
    2324
    2425    /**
    25      * Create the issue 
    26      * 
    27      * @param parent the parent model 
     26     * Create the issue
     27     *
     28     * @param parent the parent model
    2829     * @param role the role of the turn restriction leg
    29      * @param leg the leg 
     30     * @param leg the leg
    3031     */
    3132    public WrongTurnRestrictionLegTypeError(IssuesModel parent, TurnRestrictionLegRole role, OsmPrimitive leg) {
     
    3839
    3940    @Override
    40     public String getText() {       
     41    public String getText() {
    4142        String msg = null;
    42         switch(leg.getType()){
     43        switch(leg.getType()) {
    4344        case NODE:
    4445            msg = tr(
     
    5253                    leg.getDisplayName(DefaultNameFormatter.getInstance()),
    5354                    role.toString()
    54                 );             
    55             break;         
     55                );
     56            break;
    5657        default:
    5758            throw new AssertionError("Unexpected type for leg: "+leg.getType());
     
    6162
    6263    class DeleteAction extends AbstractAction {
    63         public DeleteAction() {
     64        DeleteAction() {
    6465            putValue(NAME, tr("Delete"));
    6566            putValue(SHORT_DESCRIPTION, tr("Delete the member from the turn restriction"));
    6667        }
     68
     69        @Override
    6770        public void actionPerformed(ActionEvent e) {
    6871            RelationMemberEditorModel model = getIssuesModel().getEditorModel().getRelationMemberEditorModel();
    69             switch(role){
    70             case FROM: 
     72            switch(role) {
     73            case FROM:
    7174                model.setFromPrimitive(null);
    7275                break;
     
    7578                break;
    7679            }
    77         }       
     80        }
    7881    }
    79    
     82
    8083    class FixInEditorAction extends AbstractAction {
    81         public FixInEditorAction() {
     84        FixInEditorAction() {
    8285            putValue(NAME, tr("Fix in editor"));
    8386            putValue(SHORT_DESCRIPTION, tr("Change to the Basic Editor and select a way"));
    8487        }
     88
     89        @Override
    8590        public void actionPerformed(ActionEvent e) {
    8691            NavigationControler controler = getIssuesModel().getNavigationControler();
    87             switch(role){
    88             case FROM: 
     92            switch(role) {
     93            case FROM:
    8994                controler.gotoBasicEditor(BasicEditorFokusTargets.FROM);
    9095                break;
     
    9398                break;
    9499            }
    95         }       
     100        }
    96101    }
    97102}
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/AllUnitTests.java

    r30365 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions;
    23
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/AllEditorTests.java

    r30365 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    2 
    3 import junit.framework.TestCase;
    43
    54import org.junit.runner.RunWith;
    65import org.junit.runners.Suite;
     6
     7import junit.framework.TestCase;
    78
    89@RunWith(Suite.class)
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/BasicEditorPanelTest.java

    r30557 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1112
    1213/**
    13  * Simple functional test for the layout / basic functionality of {@see BasicEditorPanel} 
    14  *   
     14 * Simple functional test for the layout / basic functionality of {@see BasicEditorPanel}
     15 *
    1516 */
    1617@Ignore("no test")
     
    1920    private TurnRestrictionEditorModel model;
    2021    private DataSet ds;
    21    
     22
    2223    public BasicEditorPanelTest() {
    2324        ds = new DataSet();
    24         OsmDataLayer layer =new OsmDataLayer(ds, "test",null);
    25         // mock a controler 
     25        OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
     26        // mock a controler
    2627        NavigationControler controler = new NavigationControler() {
     28            @Override
    2729            public void gotoAdvancedEditor() {
    2830            }
    2931
     32            @Override
    3033            public void gotoBasicEditor() {
    3134            }
    3235
     36            @Override
    3337            public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    34             }           
     38            }
    3539        };
    3640        model = new TurnRestrictionEditorModel(layer, controler);
    37        
     41
    3842        BasicEditorPanel panel = new BasicEditorPanel(model);
    39        
     43
    4044        Container c = getContentPane();
    4145        c.setLayout(new BorderLayout());
    42         c.add(panel, BorderLayout.CENTER);     
    43         setSize(600,600);
     46        c.add(panel, BorderLayout.CENTER);
     47        setSize(600, 600);
    4448        setDefaultCloseOperation(EXIT_ON_CLOSE);
    4549    }
    46    
    47    
    48     static public void main(String args[]) {
     50
     51    public static void main(String[] args) {
    4952        new BasicEditorPanelTest().setVisible(true);
    5053    }
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionComboBoxTest.java

    r30557 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1213
    1314/**
    14  * This is a simple test application to test the functionality/layout of 
     15 * This is a simple test application to test the functionality/layout of
    1516 * the {@see TurnRestrictionComboBox}
    16  * 
     17 *
    1718 */
    1819@Ignore("no test")
    1920public class TurnRestrictionComboBoxTest extends JFrame {
    20    
     21
    2122    private TurnRestrictionEditorModel model;
    2223    private DataSet ds = new DataSet();
    23    
     24
    2425    protected void build() {
    2526        ds = new DataSet();
    26         OsmDataLayer layer =new OsmDataLayer(ds, "test",null);
    27         // mock a controler 
     27        OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
     28        // mock a controler
    2829        NavigationControler controler = new NavigationControler() {
     30            @Override
    2931            public void gotoAdvancedEditor() {
    3032            }
    3133
     34            @Override
    3235            public void gotoBasicEditor() {
    3336            }
    3437
     38            @Override
    3539            public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    36             }           
     40            }
    3741        };
    3842        model = new TurnRestrictionEditorModel(layer, controler);
    39        
     43
    4044        Container c = getContentPane();
    4145        c.setLayout(new GridBagLayout());
     
    4448        gc.fill = GridBagConstraints.HORIZONTAL;
    4549        gc.weightx = 1.0;
    46        
     50
    4751        TurnRestrictionComboBox cb = new TurnRestrictionComboBox(
    4852                new TurnRestrictionComboBoxModel(model)
    4953        );
    50         add(cb, gc);       
     54        add(cb, gc);
    5155    }
    52    
     56
    5357    public TurnRestrictionComboBoxTest() {
    5458        build();
    55         setSize(600,600);
     59        setSize(600, 600);
    5660        setDefaultCloseOperation(EXIT_ON_CLOSE);
    5761    }
    58    
    59     public static void main(String args[]) {
     62
     63    public static void main(String[] args) {
    6064        new TurnRestrictionComboBoxTest().setVisible(true);
    6165    }
    62 
    6366}
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorTest.java

    r30557 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1213@Ignore("no test")
    1314public class TurnRestrictionEditorTest extends JFrame {
    14    
     15
    1516    public TurnRestrictionEditorTest() {
    16         setSize(10,10);
     17        setSize(10, 10);
    1718        TurnRestrictionEditor editor = new TurnRestrictionEditor(this, new OsmDataLayer(new DataSet(), "test", null));
    18         editor.setSize(600,600);
     19        editor.setSize(600, 600);
    1920        editor.setVisible(true);
    20        
     21
    2122        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    2223    }
    23    
    24     static public void main(String args[]) {
     24
     25    public static void main(String[] args) {
    2526        new TurnRestrictionEditorTest().setVisible(true);
    2627    }
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditorTest.java

    r31944 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    3031
    3132/**
    32  * Simple test application to test functionality and layout of the 
     33 * Simple test application to test functionality and layout of the
    3334 * {@see TurnRestrictionLegEditor}
    3435 */
    3536@Ignore("no test")
    3637public class TurnRestrictionLegEditorTest extends JFrame {
    37    
     38
    3839    private TurnRestrictionLegEditor editor;
    3940    private TurnRestrictionEditorModel model;
     
    4142    private DefaultListModel<OsmPrimitive> listModel;
    4243    private DataSet dataSet;
    43    
     44
    4445    protected JPanel buildLegEditorPanel() {
    4546        DataSet ds = new DataSet();
    46         OsmDataLayer layer =new OsmDataLayer(ds, "test",null);
    47         // mock a controler 
     47        OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
     48        // mock a controler
    4849        NavigationControler controler = new NavigationControler() {
     50            @Override
    4951            public void gotoAdvancedEditor() {
    5052            }
    5153
     54            @Override
    5255            public void gotoBasicEditor() {
    5356            }
    5457
     58            @Override
    5559            public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    56             }           
     60            }
    5761        };
    5862        JPanel pnl = new JPanel(new GridBagLayout());
     
    6064        gc.anchor = GridBagConstraints.NORTHWEST;
    6165        gc.fill = GridBagConstraints.HORIZONTAL;
    62         gc.weightx = 0.0;       
     66        gc.weightx = 0.0;
    6367        pnl.add(new JLabel("From"), gc);
    64        
     68
    6569        gc.weightx = 1.0;
    6670        gc.gridx = 1;
     
    6973        model.populate(new Relation());
    7074        pnl.add(editor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM), gc);
    71        
     75
    7276        return pnl;
    7377    }
    74    
     78
    7579    protected JPanel buildObjectListPanel() {
    7680        JPanel pnl = new JPanel(new BorderLayout());
    7781        listModel = new DefaultListModel<>();
    7882        pnl.add(new JScrollPane(lstObjects = new JList<>(listModel)), BorderLayout.CENTER);
    79         lstObjects.setCellRenderer(new OsmPrimitivRenderer());     
    80        
    81         PrimitiveIdListProvider provider = new PrimitiveIdListProvider() {         
     83        lstObjects.setCellRenderer(new OsmPrimitivRenderer());
     84
     85        PrimitiveIdListProvider provider = new PrimitiveIdListProvider() {
     86            @Override
    8287            public List<PrimitiveId> getSelectedPrimitiveIds() {
    8388                List<PrimitiveId> ret = new ArrayList<>();
    84                 int [] sel = lstObjects.getSelectedIndices();
    85                 for (int i: sel){
     89                int[] sel = lstObjects.getSelectedIndices();
     90                for (int i: sel) {
    8691                    ret.add((lstObjects.getModel().getElementAt(i)).getPrimitiveId());
    8792                }
     
    8994            }
    9095        };
    91        
     96
    9297        lstObjects.setTransferHandler(new PrimitiveIdListTransferHandler(provider));
    9398        lstObjects.setDragEnabled(true);
    9499        return pnl;
    95100    }
    96    
     101
    97102    protected void build() {
    98103        Container c = getContentPane();
    99104        c.setLayout(new GridBagLayout());
    100        
     105
    101106        GridBagConstraints gc = new GridBagConstraints();
    102107        gc.anchor = GridBagConstraints.NORTHWEST;
    103         gc.fill = GridBagConstraints.HORIZONTAL;   
     108        gc.fill = GridBagConstraints.HORIZONTAL;
    104109        gc.insets = new Insets(20, 0, 20, 0);
    105         gc.weightx = 1.0;       
     110        gc.weightx = 1.0;
    106111        gc.weighty = 0.0;
    107112        add(buildLegEditorPanel(), gc);
    108        
     113
    109114        gc.gridy = 1;
    110115        gc.weightx = 1.0;
     
    112117        gc.fill = GridBagConstraints.BOTH;
    113118        add(buildObjectListPanel(), gc);
    114         setSize(600,600);   
     119        setSize(600, 600);
    115120    }
    116    
     121
    117122    protected void initForTest1() {
    118123        Way w = new Way(1);
    119124        w.put("name", "way-1");
    120        
     125
    121126        editor.getModel().setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, w);
    122127    }
    123    
     128
    124129    protected void initForTest2() {
    125130        Way w = new Way(1);
    126         w.put("name", "way-1");     
     131        w.put("name", "way-1");
    127132        dataSet.addPrimitive(w);
    128133        editor.getModel().setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, w);
    129        
    130         Node n = new Node(new LatLon(1,1));
     134
     135        Node n = new Node(new LatLon(1, 1));
    131136        n.setOsmId(1, 1);
    132137        n.put("name", "node.1");
    133138        dataSet.addPrimitive(n);
    134139        listModel.addElement(n);
    135        
     140
    136141        w = new Way();
    137         w.setOsmId(2,1);
     142        w.setOsmId(2, 1);
    138143        w.put("name", "way.1");
    139144        dataSet.addPrimitive(w);
    140145        listModel.addElement(w);
    141        
     146
    142147        Relation r = new Relation();
    143         r.setOsmId(3,1);
     148        r.setOsmId(3, 1);
    144149        r.put("name", "relation.1");
    145150        dataSet.addPrimitive(r);
     
    147152    }
    148153
    149     public TurnRestrictionLegEditorTest(){
     154    public TurnRestrictionLegEditorTest() {
    150155        build();
    151156        initForTest2();
    152157    }
    153    
    154     static public void main(String args[]) {
     158
     159    public static void main(String[] args) {
    155160        new TurnRestrictionLegEditorTest().setVisible(true);
    156161    }
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditorTest.java

    r30557 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    1314/**
    1415 * Simple test application to test the vehicle exception editor
    15  * 
     16 *
    1617 */
    1718@Ignore("no test")
     
    2021    OsmDataLayer layer;
    2122    VehicleExceptionEditor editor;
    22    
     23
    2324    protected void build() {
    2425        Container c = getContentPane();
     
    2627        layer = new OsmDataLayer(new DataSet(), "test", null);
    2728
    28         model = new TurnRestrictionEditorModel(layer, new MockNavigationControler());       
     29        model = new TurnRestrictionEditorModel(layer, new MockNavigationControler());
    2930        editor = new VehicleExceptionEditor(model);
    3031        c.add(editor, BorderLayout.CENTER);
    31        
     32
    3233        model.getTagEditorModel().add(new TagModel("except", "non-standard-value"));
    3334    }
    34    
    35     public VehicleExceptionEditorTest(){
     35
     36    public VehicleExceptionEditorTest() {
    3637        build();
    3738        setDefaultCloseOperation(EXIT_ON_CLOSE);
    38         setSize(500,500);       
     39        setSize(500, 500);
    3940    }
    40    
    41     public static void main(String args[]){
     41
     42    public static void main(String[] args) {
    4243        new VehicleExceptionEditorTest().setVisible(true);
    4344    }
    44    
    45     static private class MockNavigationControler implements NavigationControler{
    4645
     46    private static class MockNavigationControler implements NavigationControler {
     47
     48        @Override
    4749        public void gotoAdvancedEditor() {
    4850            // TODO Auto-generated method stub
    49            
     51
    5052        }
    5153
     54        @Override
    5255        public void gotoBasicEditor() {
    5356            // TODO Auto-generated method stub
    54            
     57
    5558        }
    5659
     60        @Override
    5761        public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    5862            // TODO Auto-generated method stub
    59            
     63
    6064        }
    6165    }
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/editor/ViaListTest.java

    r30557 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.editor;
    23
     
    2425@Ignore("no test")
    2526public class ViaListTest extends JFrame {
    26    
     27
    2728    private TurnRestrictionEditorModel model;
    28    
     29
    2930    protected void build() {
    3031        DataSet ds = new DataSet();
    31         OsmDataLayer layer =new OsmDataLayer(ds, "test", null);
    32         // mock a controler 
     32        OsmDataLayer layer = new OsmDataLayer(ds, "test", null);
     33        // mock a controler
    3334        NavigationControler controler = new NavigationControler() {
     35            @Override
    3436            public void gotoAdvancedEditor() {
    3537            }
    3638
     39            @Override
    3740            public void gotoBasicEditor() {
    3841            }
    3942
     43            @Override
    4044            public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    41             }           
     45            }
    4246        };
    4347        model = new TurnRestrictionEditorModel(layer, controler);
    4448        Container c = getContentPane();
    45        
     49
    4650        c.setLayout(new GridBagLayout());
    4751        GridBagConstraints gc = new GridBagConstraints();
    4852        gc.anchor = GridBagConstraints.NORTHWEST;
    49         gc.insets = new Insets(5,5,5,20);
     53        gc.insets = new Insets(5, 5, 5, 20);
    5054        gc.fill = GridBagConstraints.BOTH;
    5155        gc.weightx = 0.5;
    5256        gc.weighty = 1.0;
    53        
     57
    5458        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    5559        c.add(new ViaList(new ViaListModel(model, selectionModel), selectionModel), gc);
    56        
     60
    5761        gc.gridx = 1;
    5862        c.add(new JList<>(), gc);
    59        
    60         setSize(600,600);       
     63
     64        setSize(600, 600);
    6165        setDefaultCloseOperation(EXIT_ON_CLOSE);
    6266    }
    63    
     67
    6468    protected void initTest1() {
    6569        DataSet ds = new DataSet();
    6670        Relation r = new Relation();
    6771        Node n;
    68         for (int i = 1; i<10; i++){
    69             n = new Node(new LatLon(i,i)); 
     72        for (int i = 1; i < 10; i++) {
     73            n = new Node(new LatLon(i, i));
    7074            n.put("name", "node." + i);
    7175            ds.addPrimitive(n);
    72             r.addMember(new RelationMember("via",n));
    73         }       
     76            r.addMember(new RelationMember("via", n));
     77        }
    7478        model.populate(r);
    7579    }
    76    
     80
    7781    public ViaListTest() {
    78         build();       
     82        build();
    7983        initTest1();
    8084    }
    81    
    82     static public void main(String args[]) {
     85
     86    public static void main(String[] args) {
    8387        new ViaListTest().setVisible(true);
    8488    }
  • applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesViewTest.java

    r30737 r32519  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.turnrestrictions.qa;
    23
     
    2223public class IssuesViewTest extends JFrame {
    2324    private IssuesModel model;
    24    
     25
    2526    protected void build() {
    2627        Container c = getContentPane();
    2728        c.setLayout(new GridBagLayout());
    28         // mock a controler 
     29        // mock a controler
    2930        NavigationControler controler = new NavigationControler() {
     31            @Override
    3032            public void gotoAdvancedEditor() {
    3133            }
    3234
     35            @Override
    3336            public void gotoBasicEditor() {
    3437            }
    3538
     39            @Override
    3640            public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) {
    37             }           
     41            }
    3842        };
    3943        OsmDataLayer layer = new OsmDataLayer(new DataSet(), "test", null);
     
    4953        pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    5054        c.add(pane, gc);
    51        
     55
    5256        List<Issue> issues = new ArrayList<>();
    5357        issues.add(new RequiredTagMissingError(model, "type", "restriction"));
     
    5559        model.populate(issues);
    5660    }
    57    
     61
    5862    public IssuesViewTest() {
    5963        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    60         setSize(400,600);
     64        setSize(400, 600);
    6165        build();
    6266    }
    63    
    64     public static void main(String args[]) {
     67
     68    public static void main(String[] args) {
    6569        new IssuesViewTest().setVisible(true);
    6670    }
Note: See TracChangeset for help on using the changeset viewer.