Ignore:
Timestamp:
2010-10-12T16:31:47+02:00 (14 years ago)
Author:
guggis
Message:

Fixing #4855 - turnrestrictions plugin: some issues
Reorganized test cases

Location:
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionBuilder.java

    r23510 r23571  
    22
    33import java.util.ArrayList;
     4import java.util.Collections;
    45import java.util.HashSet;
    56import java.util.List;
     
    1112import org.openstreetmap.josm.data.osm.Way;
    1213import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     14import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType;
    1315import org.openstreetmap.josm.tools.CheckParameterUtil;
    1416
     
    2022 */
    2123public class TurnRestrictionBuilder {
    22 
    23     private Way from;
    24     private Way to;
    25     private final ArrayList<OsmPrimitive> vias = new ArrayList<OsmPrimitive>();
    2624   
    2725    public TurnRestrictionBuilder(){
    28     }
    29    
    30     /**
    31      * Initializes the 'from' leg. Proposes the  first element
    32      * in {@code primitives} as 'from' leg if this element is a
    33      * non-deleted, visible way.
    34      *
    35      * @param primitives
    36      */
    37     protected void initFromLeg(List<OsmPrimitive> primitives){
    38         if (primitives == null || primitives.isEmpty()) return;
    39         OsmPrimitive p = primitives.get(0);
    40         if (! (p instanceof Way)) return;
    41         Way fromLeg = (Way)p;
    42         if (fromLeg.isDeleted() || ! fromLeg.isVisible()) return;
    43         this.from = fromLeg;
    44     }
    45 
    46     /**
    47      * Initializes the 'to' leg. Proposes the last element
    48      * in {@code primitives} as 'to' leg if this element is a
    49      * non-deleted, visible way.
    50      *
    51      * @param primitives
    52      */
    53     protected void initToLeg(List<OsmPrimitive> primitives){
    54         if (primitives == null || primitives.isEmpty()) return;
    55         if (primitives.size() < 2) return;
    56         OsmPrimitive p = primitives.get(primitives.size()-1);
    57         if (! (p instanceof Way)) return;
    58         Way toLeg = (Way)p;
    59         if (toLeg.isDeleted() || ! toLeg.isVisible()) return;
    60         this.to = toLeg;
    61     }
    62    
    63     /**
    64      * Initializes the vias from the two turn restriction legs. The two
    65      * legs have to be defined, otherwise no via is proposed. This methods
    66      * proposes exactly one node as via, if the two turn restriction
    67      * legs intersect at exactly one node.
    68      */
    69     protected void initViaFromLegs(){
    70         if (from == null || to == null) return;     
    71         // check whether 'from' and 'to' have exactly one intersecting
    72         // node. This node is proposed as via node. The turn restriction
    73         // node will also provide functionality to split either or both
    74         // of 'from' and 'to' way if they aren't connected from tail to
    75         // head
    76         //
    77         HashSet<Node> nodes = new HashSet<Node>();
    78         nodes.addAll(from.getNodes());
    79         nodes.retainAll(to.getNodes());
    80         if (nodes.size() == 1){
    81             vias.add(nodes.iterator().next());
    82         }       
    83     }
    84    
    85     /**
    86      * Initializes the vias with the primitives (1..size-2), provided
    87      * these primitives aren't relations and they are visible and non-deleted.
    88      *
    89      * @param primitives
    90      */
    91     protected void initViasFromPrimitives(List<OsmPrimitive> primitives) {
    92         if (primitives == null || primitives.size() <=2) return;
    93         // if we didn't find a from or a to way, we don't propose via objects
    94         // either
    95         if (from == null || to == null) return;
    96         for(int i=1; i< primitives.size() -2;i++){
    97             OsmPrimitive p = primitives.get(i);
    98             if (p == null) continue;
    99             if (p instanceof Relation) continue;
    100             if (p.isDeleted() || ! p.isVisible()) continue;
    101             vias.add(p);
    102         }
    103     }
    104    
    105     /**
    106      * Resets the builder
    107      */
    108     protected void reset() {
    109         this.from = null;
    110         this.to = null;
    111         this.vias.clear();
    11226    }
    11327   
     
    12842
    12943    /**
     44     * Tries to initialize a No-U-Turn restriction from the primitives in
     45     * <code>primitives</code>. If successful, replies true, otherwise false.
     46     *
     47     * @param primitives the primitives
     48     * @return true, if we can propose a U-turn restriction for the primitives
     49     * in <code>primitives</code>
     50     */
     51    protected Relation initNoUTurnRestriction(List<OsmPrimitive> primitives) {
     52        if (primitives.size() != 2) return null;
     53               
     54        // we need exactly one node and one way in the selection ...
     55        List<Node> nodes = OsmPrimitive.getFilteredList(primitives, Node.class);
     56        List<Way> ways = OsmPrimitive.getFilteredList(primitives, Way.class);
     57        if (nodes.size() != 1 || ways.size() != 1) return null;
     58       
     59        // .. and the node has to be the start or the node of the way
     60        Way way = ways.get(0);
     61        Node node = nodes.get(0);
     62        List<Node> wayNodes = way.getNodes();
     63        if (wayNodes.size() < 2) return null; // shouldn't happen - just in case
     64        if (! (wayNodes.get(0).equals(node) ||wayNodes.get(wayNodes.size()-1).equals(node))) return null;
     65
     66        Relation tr = new Relation();
     67        tr.put("type", "restriction");
     68        tr.addMember(new RelationMember("from", way));
     69        tr.addMember(new RelationMember("to", way));
     70        tr.addMember(new RelationMember("via", node));
     71        tr.put("restriction", TurnRestrictionType.NO_U_TURN.getTagValue());
     72        return tr;     
     73    }
     74
     75    /**
     76     * Replies the unique common node of two ways, or null, if either no
     77     * such node or multiple common nodes exist.
     78     *
     79     * @param w1 the first way
     80     * @param w2 the second way
     81     * @return the common node
     82     */
     83    protected Node getUniqueCommonNode(Way w1, Way w2){
     84        List<Node> w1Nodes = w1.getNodes();
     85        w1Nodes.retainAll(w2.getNodes());
     86        if (w1Nodes.size() != 1) return null;
     87        return w1Nodes.get(0);
     88    }   
     89   
     90    /**
     91     * Replies true, if {@code n} is the start node of the way {@code w}.
     92     *
     93     * @param w the way
     94     * @param n the node
     95     * @return true, if {@code n} is the start node of the way {@code w}.
     96     */
     97    protected boolean isStartNode(Way w, Node n) {
     98        if (w.getNodesCount() == 0) return false;
     99        return w.getNode(0).equals(n);
     100    }
     101   
     102   
     103    /**
     104     * Replies true, if {@code n} is the end node of the way {@code w}.
     105     *
     106     * @param w the way
     107     * @param n the node
     108     * @return true, if {@code n} is the end node of the way {@code w}.
     109     */
     110    protected boolean isEndNode(Way w, Node n){
     111        if (w.getNodesCount() == 0) return false;
     112        return w.getNode(w.getNodesCount()-1).equals(n);
     113    }
     114   
     115    /**
     116     * <p>Replies true, if the ways {@code w1} and {@code w2} are connected
     117     * at the node {@code n}.</p>
     118     *
     119     * <p>If {@code w1} and {@code w2} <em>intersect</em> at the node {@code n},
     120     * this method replies false.</p>
     121     *
     122     * @param w1 the first way
     123     * @param w2 the second way
     124     * @param n the node
     125     * @return
     126     */
     127    protected boolean isConnectingNode(Way w1, Way w2, Node n){
     128        if (isStartNode(w1, n)) {
     129                return isStartNode(w2, n)  | isEndNode(w2, n);
     130        } else if (isEndNode(w1, n)){
     131                return isStartNode(w2, n)  | isEndNode(w2, n);
     132        }
     133        return false;
     134    }
     135   
     136    /**
     137     * Replies true, if the way {@code w} is closed at the node {@code n}.
     138     *
     139     * @param w the way
     140     * @param n the node
     141     * @return true, if the way {@code w} is closed at the node {@code n}.
     142     */
     143    protected boolean isClosedAt(Way w, Node n){
     144        List<Node> nodes = w.getNodes();
     145        nodes.retainAll(Collections.singletonList(n));
     146        return nodes.size() >= 2;
     147    }
     148   
     149    protected double phi(Way w) {
     150        return phi(w, false /* not inverse */);
     151    }
     152   
     153    protected double phi(Way w, boolean doInvert) {
     154        double x1 = w.getNode(0).getCoor().getX();
     155        double y1 = w.getNode(0).getCoor().getY();
     156        double x2 = w.getNode(w.getNodesCount()-1).getCoor().getX();
     157        double y2 = w.getNode(w.getNodesCount()-1).getCoor().getY();
     158        if (doInvert){
     159                double t = x1; x1 = x2; x2 = t;
     160                t = y1; y1 = y2; y2 = t;
     161        }
     162        x2-=x1;
     163        y2-=y1;
     164        return phi(x2,y2);     
     165    }
     166   
     167    protected double phi(double x, double y) {
     168        return Math.atan2(y, x);
     169    }   
     170   
     171    /**
     172     * <p>Determines the standard turn restriction between from way {@code w1} to
     173     * way {@code w2}.</p>
     174     *
     175     * <p>Replies {@link TurnRestrictionType#NO_LEFT_TURN no_left_turn} or
     176     * {@link TurnRestrictionType#NO_RIGHT_TURN no_right_turn}, if applicable. Or
     177     * null, if neither of these restrictions is applicable, for instance because
     178     * the passed in via node {@code via} isn't a node where the two ways are
     179     * connected.</p>
     180     *
     181     * @param w1 the "from"-way
     182     * @param w2 the "to"-way
     183     * @param via the via node
     184     * @return an applicable turn restriction, or null, if no turn restriction is
     185     * applicable
     186     */
     187    protected String determineRestriction(Way w1, Way w2, Node via){
     188        if (via == null) return null;
     189        if (!isConnectingNode(w1, w2, via)) return null;
     190        // if either w1 or w2 are closed at the via node, we can't determine automatically
     191        // whether the connection at "via" is a "left turn" or a "right turn"
     192        if (isClosedAt(w1, via)) return null;
     193        if (isClosedAt(w2, via)) return null;
     194       
     195        double phi1 = 0, phi2 = 0;
     196        if (isEndNode(w1, via)){
     197                if (isStartNode(w2, via)) {
     198                        phi1 = phi(w1);
     199                        phi2 = phi(w2);
     200                } else if (isEndNode(w2, via)){
     201                        phi1 = phi(w1);
     202                        phi2 = phi(w2, true /* reverse it */);
     203                } else {
     204                        assert false: "Unexpected state: via node is expected to be a start or and end node";
     205                }                       
     206        } else if (isStartNode(w1,via)) {
     207                if (isStartNode(w2, via)) {
     208                        phi1 = phi(w1, true /* reverse it */);
     209                        phi2 = phi(w2);
     210                } else if (isEndNode(w2, via)){
     211                        phi1 = phi(w1, true /* reverse it */);
     212                        phi2 = phi(w2, true /* reverse it */);
     213                } else {
     214                        assert false: "Unexpected state: via node is expected to be a start or and end node";
     215                }           
     216        } else {
     217                assert false: "Unexpected state: via node is expected to be a start or and end node of w1";             
     218        }
     219       
     220        double phi = phi1-phi2;
     221        if (phi >=0 && phi <= Math.PI) {
     222                // looks like a right turn 
     223                return TurnRestrictionType.NO_RIGHT_TURN.getTagValue();
     224        } else {
     225                // looks like a left turn
     226                return TurnRestrictionType.NO_LEFT_TURN.getTagValue();
     227        }
     228    }
     229   
     230    protected Relation initTurnRestrictionFromTwoWays(List<OsmPrimitive> primitives) {
     231        Way w1 = null;
     232        Way w2 = null;
     233        Node via = null;
     234        if (primitives.size() == 2) {
     235                // if we have exactly two selected primitives, we expect two ways.
     236                // See initNoUTurnRestriction() for the case where we have a selected way
     237                // and a selected node
     238                List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class);
     239                if (selWays.size() != 2) return null;
     240                w1 = selWays.get(0);
     241                w2 = selWays.get(1);
     242                via = getUniqueCommonNode(w1, w2);             
     243        } else if (primitives.size() == 3){
     244                // if we have exactly three selected primitives, we need two ways and a
     245                // node, which should be an acceptable via node
     246                List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class);
     247                List<Node> selNodes = OsmPrimitive.getFilteredList(primitives, Node.class);
     248                if (selWays.size() != 2) return null;
     249                if (selNodes.size() != 1) return null;
     250                w1 = selWays.get(0);
     251                w2 = selWays.get(1);
     252                via = selNodes.get(0);
     253                if (! w1.getNodes().contains(via) || ! w2.getNodes().contains(via)){
     254                        // the selected node is not an acceptable via node
     255                        via = null;
     256                }
     257        } else {
     258                // the selection doesn't consists of primitives for which we can build
     259                // a turn restriction
     260                return null;
     261        }
     262       
     263        // if we get here, we know the two "legs" of the turn restriction. We may
     264        // or may not know a via node, though
     265        assert w1 != null;
     266        assert w2 != null;
     267       
     268        Relation tr = new Relation();
     269        tr.put("type", "restriction");
     270        tr.addMember(new RelationMember("from", w1));
     271        tr.addMember(new RelationMember("to", w2));
     272       
     273        if (via != null){
     274                tr.addMember(new RelationMember("via", via));
     275                String restriction = determineRestriction(w1, w2, via);
     276                if (restriction != null){
     277                        tr.put("restriction", restriction);
     278                }
     279        }
     280        return tr;
     281    }
     282       
     283    protected Relation initEmptyTurnRestriction() {
     284           Relation tr = new Relation();
     285       tr.put("type", "restriction");
     286       return tr;
     287    }
     288   
     289    /**
    130290     * Creates and initializes a new turn restriction based on primitives
    131291     * in {@code primitives}.
     
    136296     */
    137297    public synchronized Relation build(List<OsmPrimitive> primitives){
    138         Relation tr = new Relation();
    139         tr.put("type", "restriction");
    140         if (primitives == null || primitives.isEmpty()) return tr;
    141         if (primitives.size() <=2){
    142             initFromLeg(primitives);
    143             initToLeg(primitives);
    144             initViaFromLegs();
    145         } else if (primitives.size() > 2) {
    146             initFromLeg(primitives);
    147             initToLeg(primitives);
    148             initViasFromPrimitives(primitives);
     298        if (primitives == null || primitives.isEmpty()) {
     299                return initEmptyTurnRestriction();
    149300        }
    150        
    151         if (from != null){
    152             tr.addMember(new RelationMember("from", from));
     301        Relation tr;
     302        switch(primitives.size()){
     303        // case 0 already handled
     304        case 1:
     305                tr = initEmptyTurnRestriction();
     306                if (OsmPrimitive.getFilteredList(primitives, Way.class).size() == 1) {     
     307                        // we have exactly one selected way? -> init the "from" leg
     308                        // of the turn restriction with it
     309                        tr.addMember(new RelationMember("from", primitives.get(0)));
     310                }
     311                return tr;
     312               
     313        case 2:
     314                tr = initNoUTurnRestriction(primitives);
     315                if (tr != null) return tr;
     316                tr = initTurnRestrictionFromTwoWays(primitives);
     317                if (tr != null) return tr;
     318                return initEmptyTurnRestriction();       
     319               
     320        default:               
     321                tr = initTurnRestrictionFromTwoWays(primitives);
     322                if (tr != null) return tr;
     323                return initEmptyTurnRestriction();       
    153324        }
    154         if (to != null){
    155             tr.addMember(new RelationMember("to", to));
    156         }
    157         for(OsmPrimitive via: vias){
    158             tr.addMember(new RelationMember("via", via));
    159         }
    160         return tr;
    161325    }       
    162326}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java

    r23510 r23571  
    1010import javax.swing.AbstractListModel;
    1111import javax.swing.DefaultListSelectionModel;
     12import javax.swing.ListSelectionModel;
    1213
    1314import org.openstreetmap.josm.Main;
     
    3839   
    3940    private final List<OsmPrimitive> selection = new ArrayList<OsmPrimitive>();
    40     private DefaultListSelectionModel selectionModel;
     41    private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    4142    private OsmDataLayer layer;
    4243
     
    4647     * @param selectionModel the selection model used in the list. Must not be null.
    4748     * @param layer the layer this model is displaying the selection from. Must not be null.
    48      * @throws IllegalArgumentException thrown if {@code selectionModel} is null
    4949     * @throws IllegalArgumentException thrown if {@code layer} is null
    5050     */
    51     public JosmSelectionListModel(OsmDataLayer layer, DefaultListSelectionModel selectionModel) {
    52         CheckParameterUtil.ensureParameterNotNull(selectionModel, "selectionModel");
     51    public JosmSelectionListModel(OsmDataLayer layer) throws IllegalArgumentException{
    5352        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    5453        this.layer = layer;
    55         this.selectionModel = selectionModel;
    5654        setJOSMSelection(layer.data.getSelected());
    5755    }
     
    118116        this.selection.addAll(selection);
    119117        fireContentsChanged(this, 0, getSize());       
    120         setSelected(sel);
     118        setSelected(sel);       
     119        // if the user selects exactly one primitive (i.e. a way), we automatically
     120        // select it in the list of selected JOSM objects too.
     121        if (getSelected().isEmpty() && this.selection.size() == 1) {
     122                setSelected(this.selection);
     123        }
    121124    }
    122125
     
    138141        }
    139142        setSelected(sel);
     143    }
     144       
     145    public ListSelectionModel getListSelectionModel() {
     146        return selectionModel;
    140147    }
    141148
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java

    r23510 r23571  
    5454    protected void build(OsmDataLayer layer) {
    5555        setLayout(new BorderLayout());
    56         DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    57         model = new JosmSelectionListModel(layer,selectionModel);
    5856        lstSelection = new JList(model);
    5957        lstSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    60         lstSelection.setSelectionModel(selectionModel);
     58        lstSelection.setSelectionModel(model.getListSelectionModel());
    6159        lstSelection.setCellRenderer(new OsmPrimitivRenderer());
    6260        lstSelection.setTransferHandler(transferHandler = new JosmSelectionTransferHandler(model));
     
    7775     * @exception IllegalArgumentException thrown if {@code layer} is null
    7876     */
    79     public JosmSelectionPanel(OsmDataLayer layer) throws IllegalArgumentException{
     77    public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException{
    8078        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
     79        this.model = model;
    8180        build(layer);
    8281    }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java

    r23510 r23571  
    114114     */
    115115    protected JPanel buildJOSMSelectionPanel() {
    116         pnlJosmSelection = new JosmSelectionPanel(layer);
     116        pnlJosmSelection = new JosmSelectionPanel(layer,editorModel.getJosmSelectionListModel());
    117117        return pnlJosmSelection;
    118118    }
    119119   
    120120    /**
    121      * Builds the panel with the editor masks (the left panel in the split pane of
     121     * Builds the panel with the editor forms (the left panel in the split pane of
    122122     * this dialog)
    123123     *
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java

    r23510 r23571  
    6969    private  IssuesModel issuesModel;
    7070    private NavigationControler navigationControler;
     71    private JosmSelectionListModel selectionModel;
    7172   
    7273    /**
     
    8788        addObserver(issuesModel);
    8889        tagEditorModel.addTableModelListener(new TagEditorModelObserver());
     90        selectionModel = new JosmSelectionListModel(layer);
     91    }
     92   
     93    /**
     94     * Replies the model for the currently selected JOSM primitives
     95     */
     96    public JosmSelectionListModel getJosmSelectionListModel() {
     97        return selectionModel;
    8998    }
    9099   
     
    211220        CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");     
    212221        TagCollection tags = tagEditorModel.getTagCollection();
     222        logger.info(tags.toString());
    213223        turnRestriction.removeAll();
    214224        tags.applyTo(turnRestriction);
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java

    r23192 r23571  
    44
    55import java.awt.BorderLayout;
     6import java.awt.FlowLayout;
    67import java.awt.Font;
    78import java.awt.Toolkit;
     
    3839import javax.swing.TransferHandler;
    3940import javax.swing.UIManager;
     41import javax.swing.event.ListSelectionEvent;
     42import javax.swing.event.ListSelectionListener;
    4043
    4144import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4245import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    4346import org.openstreetmap.josm.data.osm.PrimitiveId;
     47import org.openstreetmap.josm.data.osm.Way;
    4448import org.openstreetmap.josm.gui.DefaultNameFormatter;
    4549import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    6468    private CopyAction actCopy;
    6569    private PasteAction actPaste;
     70    private AcceptAction actAccept;
    6671    private TransferHandler transferHandler;
    6772   
     
    8186        );
    8287       
     88        JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0));
     89        pnlButtons.setBorder(null);
    8390        JButton btn;
    8491        actDelete = new DeleteAction();
    85         add(btn = new JButton(actDelete), BorderLayout.EAST);
     92        pnlButtons.add(btn = new JButton(actDelete));
    8693        btn.setFocusable(false);
    8794        btn.setText(null);
    8895        btn.setBorder(BorderFactory.createRaisedBevelBorder());
     96       
     97        actAccept = new AcceptAction();
     98        pnlButtons.add(btn = new JButton(actAccept));
     99        btn.setFocusable(false);
     100        btn.setText(null);
     101        btn.setBorder(BorderFactory.createRaisedBevelBorder());
     102        add(pnlButtons, BorderLayout.EAST);
    89103               
    90104        // focus handling
     
    260274   
    261275    /**
     276     * Accepts the currently selected way as turn restriction leg. Only enabled,
     277     * if there is exactly one way selected
     278     */
     279    class AcceptAction extends AbstractAction implements ListSelectionListener {
     280       
     281        public AcceptAction() {
     282                         putValue(SHORT_DESCRIPTION, tr("Accept the currently selected way"));
     283                 putValue(NAME, tr("Accept"));
     284                 putValue(SMALL_ICON, ImageProvider.get("accept"));
     285                 model.getJosmSelectionListModel().getListSelectionModel().addListSelectionListener(this);
     286                 updateEnabledState();           
     287        }
     288       
     289         public void actionPerformed(ActionEvent e) {
     290                 List<Way> selWays = OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class);
     291                 if (selWays.size() != 1) return;
     292                 Way w = selWays.get(0);                 
     293             model.setTurnRestrictionLeg(role, w);           
     294         }       
     295         
     296         public void updateEnabledState() {
     297                setEnabled(OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class).size() == 1);
     298         }
     299
     300                @Override
     301                public void valueChanged(ListSelectionEvent e) {
     302                        updateEnabledState();
     303                }
     304    }
     305   
     306    /**
    262307     * The transfer handler for Drag-and-Drop.
    263308     */
     
    366411        }
    367412    }
     413   
     414     
    368415}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java

    r23192 r23571  
    5151    private ExceptValueModel exceptValue = new ExceptValueModel();
    5252   
     53    private StandardVehicleTypeChangeListener svtChangeListener;
     54   
    5355    private JPanel buildMessagePanel() {
    5456        JPanel pnl = new JPanel(new BorderLayout());
     
    6769            return pnlStandard;
    6870       
    69         StandardVehicleTypeChangeListener changeHandler = new StandardVehicleTypeChangeListener();
     71        svtChangeListener = new StandardVehicleTypeChangeListener();
    7072       
    7173        GridBagConstraints gc = new GridBagConstraints();
     
    7880        JLabel lbl;
    7981        cbPsv = new JCheckBox();
    80         cbPsv.addItemListener(changeHandler);
     82        cbPsv.addItemListener(svtChangeListener);
    8183        lbl = new JLabel();
    8284        lbl.setText(tr("Public Service Vehicles"));
     
    9193       
    9294        cbHgv = new JCheckBox();
    93         cbHgv.addItemListener(changeHandler);
     95        cbHgv.addItemListener(svtChangeListener);
    9496        lbl = new JLabel();
    9597        lbl.setText(tr("Heavy Goods Vehicles"));
     
    104106
    105107        cbMotorcar = new JCheckBox();
    106         cbMotorcar.addItemListener(changeHandler);
     108        cbMotorcar.addItemListener(svtChangeListener);
    107109        lbl = new JLabel();
    108110        lbl.setText(tr("Motorcars"));
     
    118120       
    119121        cbBicyle = new JCheckBox();
    120         cbBicyle.addItemListener(changeHandler);
     122        cbBicyle.addItemListener(svtChangeListener);
    121123        lbl = new JLabel();
    122124        lbl.setText(tr("Bicycles"));
     
    212214        bgStandardOrNonStandard.add(rbStandardException);
    213215       
    214         StandardNonStandardChangeHander changeHandler = new StandardNonStandardChangeHander();
     216        StandardNonStandardChangeHandler changeHandler = new StandardNonStandardChangeHandler();
    215217        rbNonStandardException.addItemListener(changeHandler);
    216218        rbStandardException.addItemListener(changeHandler);
     
    231233   
    232234    protected void init() {
    233         cbPsv.setSelected(exceptValue.isVehicleException("psv"));
    234         cbBicyle.setSelected(exceptValue.isVehicleException("bicycle"));
    235         cbMotorcar.setSelected(exceptValue.isVehicleException("motorcar"));
    236         cbHgv.setSelected(exceptValue.isVehicleException("hgv"));
     235        try {
     236                // temporarily disable the checkbox listeners while initializing the
     237                // checkboxes with the input value
     238                this.svtChangeListener.setEnabled(false);
     239                cbPsv.setSelected(exceptValue.isVehicleException("psv"));
     240                cbBicyle.setSelected(exceptValue.isVehicleException("bicycle"));
     241                cbMotorcar.setSelected(exceptValue.isVehicleException("motorcar"));
     242                cbHgv.setSelected(exceptValue.isVehicleException("hgv"));
     243        } finally {
     244                this.svtChangeListener.setEnabled(true);
     245        }
    237246        if (!exceptValue.isStandard()){
    238247            rbNonStandardException.setSelected(true);
     
    285294    /* inner classes                                                                        */
    286295    /* ------------------------------------------------------------------------------------ */
    287     class StandardNonStandardChangeHander implements ItemListener {
     296    class StandardNonStandardChangeHandler implements ItemListener {
    288297        public void itemStateChanged(ItemEvent e) {
    289298            if (rbNonStandardException.isSelected()){
     
    301310   
    302311    class StandardVehicleTypeChangeListener implements ItemListener {
    303         public void itemStateChanged(ItemEvent e) {
     312        private boolean enabled = true;
     313       
     314        public void setEnabled(boolean enabled){
     315                this.enabled = enabled;
     316        }
     317       
     318        public void itemStateChanged(ItemEvent e) {             
     319                if (!enabled) return;
    304320            exceptValue.setVehicleException("bicycle", cbBicyle.isSelected());
    305321            exceptValue.setVehicleException("hgv", cbHgv.isSelected());
    306322            exceptValue.setVehicleException("psv", cbPsv.isSelected());
    307             exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected());
     323            exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected());           
    308324            model.setExcept(exceptValue);
    309325        }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java

    r23192 r23571  
    2222
    2323/**
    24  * IssuesModel is a model for an observable list of {@code Issues}
    25  * related to turn restriction.
     24 * <p>IssuesModel is a model for an observable list of {@code Issues}
     25 * related to turn restriction.</p>
    2626 *
    27  * It is also an {@see Observer} to an {@see TurnRestrictionEditorModel}
     27 * <p>It is also an {@link Observer} to an {@link TurnRestrictionEditorModel}
    2828 * and populates itself with issues it derives from the current state
    29  * in the {@see TurnRestrictionEditorModel}.
     29 * in the {@link TurnRestrictionEditorModel}.</p>
    3030 * 
    3131 */
     
    3636    /**
    3737     * Creates the model
    38      *
    39      * {@code controler} is used in resolution actions for issues in
    40      * this model to direct the user to a specific input field in one
    41      * of the editor tabs in order to fix an issue.
    4238     *
    4339     * @param editorModel the editor model. Must not be null.
     
    224220                issues.add(new IntersectionMissingAsViaError(this, from, to, intersect));
    225221            }
    226         }
    227        
    228         // 'from' intersects with 'to' - should be split 
    229         if (intersect != null && from.getNode(0) != intersect && from.getNode(from.getNodesCount()-1) != intersect){
    230             issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect));
    231         }
    232         // 'to' intersects with 'from' - should be split
    233         if (intersect != null && to.getNode(0) != intersect && to.getNode(to.getNodesCount()-1) != intersect){
    234             issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.TO, from, to, intersect));
    235         }       
     222            // 'from' intersects with 'to' - should be split 
     223            if (from.getNode(0) != intersect && from.getNode(from.getNodesCount()-1) != intersect){
     224                issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect));
     225            }
     226            // 'to' intersects with 'from' - should be split
     227            if (to.getNode(0) != intersect && to.getNode(to.getNodesCount()-1) != intersect){
     228                issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.TO, from, to, intersect));
     229            }                 
     230        } else {
     231                if (editorModel.getVias().isEmpty() && ! from.equals(to)){
     232                        // the two turn restriction legs aren't connected and we don't have configured
     233                        // via objects
     234                        issues.add(new MissingViaError(this));
     235                }               
     236        }               
    236237    }
    237238   
Note: See TracChangeset for help on using the changeset viewer.