Changeset 23571 in osm for applications/editors/josm/plugins/turnrestrictions/src/org
- Timestamp:
- 2010-10-12T16:31:47+02:00 (14 years ago)
- 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 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collections; 4 5 import java.util.HashSet; 5 6 import java.util.List; … … 11 12 import org.openstreetmap.josm.data.osm.Way; 12 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionType; 13 15 import org.openstreetmap.josm.tools.CheckParameterUtil; 14 16 … … 20 22 */ 21 23 public class TurnRestrictionBuilder { 22 23 private Way from;24 private Way to;25 private final ArrayList<OsmPrimitive> vias = new ArrayList<OsmPrimitive>();26 24 27 25 public TurnRestrictionBuilder(){ 28 }29 30 /**31 * Initializes the 'from' leg. Proposes the first element32 * in {@code primitives} as 'from' leg if this element is a33 * non-deleted, visible way.34 *35 * @param primitives36 */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 element48 * in {@code primitives} as 'to' leg if this element is a49 * non-deleted, visible way.50 *51 * @param primitives52 */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 two65 * legs have to be defined, otherwise no via is proposed. This methods66 * proposes exactly one node as via, if the two turn restriction67 * 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 intersecting72 // node. This node is proposed as via node. The turn restriction73 // node will also provide functionality to split either or both74 // of 'from' and 'to' way if they aren't connected from tail to75 // head76 //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), provided87 * these primitives aren't relations and they are visible and non-deleted.88 *89 * @param primitives90 */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 objects94 // either95 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 builder107 */108 protected void reset() {109 this.from = null;110 this.to = null;111 this.vias.clear();112 26 } 113 27 … … 128 42 129 43 /** 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 /** 130 290 * Creates and initializes a new turn restriction based on primitives 131 291 * in {@code primitives}. … … 136 296 */ 137 297 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(); 149 300 } 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(); 153 324 } 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;161 325 } 162 326 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java
r23510 r23571 10 10 import javax.swing.AbstractListModel; 11 11 import javax.swing.DefaultListSelectionModel; 12 import javax.swing.ListSelectionModel; 12 13 13 14 import org.openstreetmap.josm.Main; … … 38 39 39 40 private final List<OsmPrimitive> selection = new ArrayList<OsmPrimitive>(); 40 private DefaultListSelectionModel selectionModel; 41 private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 41 42 private OsmDataLayer layer; 42 43 … … 46 47 * @param selectionModel the selection model used in the list. Must not be null. 47 48 * @param layer the layer this model is displaying the selection from. Must not be null. 48 * @throws IllegalArgumentException thrown if {@code selectionModel} is null49 49 * @throws IllegalArgumentException thrown if {@code layer} is null 50 50 */ 51 public JosmSelectionListModel(OsmDataLayer layer, DefaultListSelectionModel selectionModel) { 52 CheckParameterUtil.ensureParameterNotNull(selectionModel, "selectionModel"); 51 public JosmSelectionListModel(OsmDataLayer layer) throws IllegalArgumentException{ 53 52 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 54 53 this.layer = layer; 55 this.selectionModel = selectionModel;56 54 setJOSMSelection(layer.data.getSelected()); 57 55 } … … 118 116 this.selection.addAll(selection); 119 117 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 } 121 124 } 122 125 … … 138 141 } 139 142 setSelected(sel); 143 } 144 145 public ListSelectionModel getListSelectionModel() { 146 return selectionModel; 140 147 } 141 148 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionPanel.java
r23510 r23571 54 54 protected void build(OsmDataLayer layer) { 55 55 setLayout(new BorderLayout()); 56 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();57 model = new JosmSelectionListModel(layer,selectionModel);58 56 lstSelection = new JList(model); 59 57 lstSelection.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 60 lstSelection.setSelectionModel( selectionModel);58 lstSelection.setSelectionModel(model.getListSelectionModel()); 61 59 lstSelection.setCellRenderer(new OsmPrimitivRenderer()); 62 60 lstSelection.setTransferHandler(transferHandler = new JosmSelectionTransferHandler(model)); … … 77 75 * @exception IllegalArgumentException thrown if {@code layer} is null 78 76 */ 79 public JosmSelectionPanel(OsmDataLayer layer) throws IllegalArgumentException{ 77 public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException{ 80 78 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 79 this.model = model; 81 80 build(layer); 82 81 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r23510 r23571 114 114 */ 115 115 protected JPanel buildJOSMSelectionPanel() { 116 pnlJosmSelection = new JosmSelectionPanel(layer); 116 pnlJosmSelection = new JosmSelectionPanel(layer,editorModel.getJosmSelectionListModel()); 117 117 return pnlJosmSelection; 118 118 } 119 119 120 120 /** 121 * Builds the panel with the editor masks (the left panel in the split pane of121 * Builds the panel with the editor forms (the left panel in the split pane of 122 122 * this dialog) 123 123 * -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java
r23510 r23571 69 69 private IssuesModel issuesModel; 70 70 private NavigationControler navigationControler; 71 private JosmSelectionListModel selectionModel; 71 72 72 73 /** … … 87 88 addObserver(issuesModel); 88 89 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; 89 98 } 90 99 … … 211 220 CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction"); 212 221 TagCollection tags = tagEditorModel.getTagCollection(); 222 logger.info(tags.toString()); 213 223 turnRestriction.removeAll(); 214 224 tags.applyTo(turnRestriction); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java
r23192 r23571 4 4 5 5 import java.awt.BorderLayout; 6 import java.awt.FlowLayout; 6 7 import java.awt.Font; 7 8 import java.awt.Toolkit; … … 38 39 import javax.swing.TransferHandler; 39 40 import javax.swing.UIManager; 41 import javax.swing.event.ListSelectionEvent; 42 import javax.swing.event.ListSelectionListener; 40 43 41 44 import org.openstreetmap.josm.data.osm.OsmPrimitive; 42 45 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 43 46 import org.openstreetmap.josm.data.osm.PrimitiveId; 47 import org.openstreetmap.josm.data.osm.Way; 44 48 import org.openstreetmap.josm.gui.DefaultNameFormatter; 45 49 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 64 68 private CopyAction actCopy; 65 69 private PasteAction actPaste; 70 private AcceptAction actAccept; 66 71 private TransferHandler transferHandler; 67 72 … … 81 86 ); 82 87 88 JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT,0,0)); 89 pnlButtons.setBorder(null); 83 90 JButton btn; 84 91 actDelete = new DeleteAction(); 85 add(btn = new JButton(actDelete) , BorderLayout.EAST);92 pnlButtons.add(btn = new JButton(actDelete)); 86 93 btn.setFocusable(false); 87 94 btn.setText(null); 88 95 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); 89 103 90 104 // focus handling … … 260 274 261 275 /** 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 /** 262 307 * The transfer handler for Drag-and-Drop. 263 308 */ … … 366 411 } 367 412 } 413 414 368 415 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java
r23192 r23571 51 51 private ExceptValueModel exceptValue = new ExceptValueModel(); 52 52 53 private StandardVehicleTypeChangeListener svtChangeListener; 54 53 55 private JPanel buildMessagePanel() { 54 56 JPanel pnl = new JPanel(new BorderLayout()); … … 67 69 return pnlStandard; 68 70 69 StandardVehicleTypeChangeListener changeHandler = new StandardVehicleTypeChangeListener();71 svtChangeListener = new StandardVehicleTypeChangeListener(); 70 72 71 73 GridBagConstraints gc = new GridBagConstraints(); … … 78 80 JLabel lbl; 79 81 cbPsv = new JCheckBox(); 80 cbPsv.addItemListener( changeHandler);82 cbPsv.addItemListener(svtChangeListener); 81 83 lbl = new JLabel(); 82 84 lbl.setText(tr("Public Service Vehicles")); … … 91 93 92 94 cbHgv = new JCheckBox(); 93 cbHgv.addItemListener( changeHandler);95 cbHgv.addItemListener(svtChangeListener); 94 96 lbl = new JLabel(); 95 97 lbl.setText(tr("Heavy Goods Vehicles")); … … 104 106 105 107 cbMotorcar = new JCheckBox(); 106 cbMotorcar.addItemListener( changeHandler);108 cbMotorcar.addItemListener(svtChangeListener); 107 109 lbl = new JLabel(); 108 110 lbl.setText(tr("Motorcars")); … … 118 120 119 121 cbBicyle = new JCheckBox(); 120 cbBicyle.addItemListener( changeHandler);122 cbBicyle.addItemListener(svtChangeListener); 121 123 lbl = new JLabel(); 122 124 lbl.setText(tr("Bicycles")); … … 212 214 bgStandardOrNonStandard.add(rbStandardException); 213 215 214 StandardNonStandardChangeHander changeHandler = new StandardNonStandardChangeHander(); 216 StandardNonStandardChangeHandler changeHandler = new StandardNonStandardChangeHandler(); 215 217 rbNonStandardException.addItemListener(changeHandler); 216 218 rbStandardException.addItemListener(changeHandler); … … 231 233 232 234 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 } 237 246 if (!exceptValue.isStandard()){ 238 247 rbNonStandardException.setSelected(true); … … 285 294 /* inner classes */ 286 295 /* ------------------------------------------------------------------------------------ */ 287 class StandardNonStandardChangeHander implements ItemListener { 296 class StandardNonStandardChangeHandler implements ItemListener { 288 297 public void itemStateChanged(ItemEvent e) { 289 298 if (rbNonStandardException.isSelected()){ … … 301 310 302 311 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; 304 320 exceptValue.setVehicleException("bicycle", cbBicyle.isSelected()); 305 321 exceptValue.setVehicleException("hgv", cbHgv.isSelected()); 306 322 exceptValue.setVehicleException("psv", cbPsv.isSelected()); 307 exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected()); 323 exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected()); 308 324 model.setExcept(exceptValue); 309 325 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java
r23192 r23571 22 22 23 23 /** 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> 26 26 * 27 * It is also an {@ seeObserver} to an {@seeTurnRestrictionEditorModel}27 * <p>It is also an {@link Observer} to an {@link TurnRestrictionEditorModel} 28 28 * and populates itself with issues it derives from the current state 29 * in the {@ seeTurnRestrictionEditorModel}.29 * in the {@link TurnRestrictionEditorModel}.</p> 30 30 * 31 31 */ … … 36 36 /** 37 37 * Creates the model 38 *39 * {@code controler} is used in resolution actions for issues in40 * this model to direct the user to a specific input field in one41 * of the editor tabs in order to fix an issue.42 38 * 43 39 * @param editorModel the editor model. Must not be null. … … 224 220 issues.add(new IntersectionMissingAsViaError(this, from, to, intersect)); 225 221 } 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 } 236 237 } 237 238
Note:
See TracChangeset
for help on using the changeset viewer.