Changeset 32519 in osm for applications/editors/josm/plugins/turnrestrictions
- Timestamp:
- 2016-07-02T01:10:44+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions
- Files:
-
- 1 added
- 67 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/.project
r32286 r32519 12 12 </buildCommand> 13 13 <buildCommand> 14 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 15 <arguments> 16 </arguments> 17 </buildCommand> 18 <buildCommand> 14 19 <name>org.sonarlint.eclipse.core.sonarlintBuilder</name> 15 20 <arguments> … … 20 25 <nature>org.eclipse.jdt.groovy.core.groovyNature</nature> 21 26 <nature>org.eclipse.jdt.core.javanature</nature> 27 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 22 28 </natures> 23 29 </projectDescription> -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/CreateOrEditTurnRestrictionAction.java
r32375 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions; 2 3 … … 29 30 /** 30 31 * Replies the unique instance of this action 31 *32 * @return33 32 */ 34 33 public static CreateOrEditTurnRestrictionAction getInstance() { 35 if (instance == null){ 34 if (instance == null) { 36 35 instance = new CreateOrEditTurnRestrictionAction(); 37 36 } … … 44 43 null, 45 44 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."), 47 46 KeyEvent.VK_2, Shortcut.ALT_SHIFT), 48 47 false … … 55 54 if (layer == null) return; 56 55 Collection<Relation> trs = TurnRestrictionSelectionPopupPanel.getTurnRestrictionsParticipatingIn(layer.data.getSelected()); 57 if (trs.isEmpty()){ 56 if (trs.isEmpty()) { 58 57 // current selection isn't participating in turn restrictions. Launch 59 58 // an editor for a new turn restriction 60 59 // 61 60 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); 63 62 TurnRestrictionEditorManager.getInstance().positionOnScreen(editor); 64 63 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions; 2 3 … … 24 25 */ 25 26 public class TurnRestrictionBuilder { 26 27 27 28 /** 28 29 * Replies the angle phi in the polar coordinates (r,phi) representing the first 29 30 * 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 34 35 * @throws IllegalArgumentException thrown if w is null 35 36 * @throws IllegalArgumentException thrown if w is too short (at least two nodes required) 36 37 */ 37 static public double phi(Way w) throws IllegalArgumentException{38 public static double phi(Way w) throws IllegalArgumentException { 38 39 return phi(w, false /* not inverse */); 39 40 } 40 41 41 42 /** 42 43 * <p>Replies the angle phi in the polar coordinates (r,phi) representing the first 43 44 * 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 * 46 47 * <p>If {@code doInvert} is true, computes phi for the way in reversed direction.</p> 47 * 48 * 48 49 * @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 51 52 * @throws IllegalArgumentException thrown if w is null 52 53 * @throws IllegalArgumentException thrown if w is too short (at least two nodes required) 53 54 */ 54 static public double phi(Way w, boolean doInvert) throws IllegalArgumentException {55 public static double phi(Way w, boolean doInvert) throws IllegalArgumentException { 55 56 CheckParameterUtil.ensureParameterNotNull(w, "w"); 56 57 if (w.getNodesCount() < 2) { … … 61 62 Node n0 = nodes.get(0); 62 63 Node n1 = nodes.get(1); 63 64 64 65 double x = n1.getCoor().getX() - n0.getCoor().getX(); 65 66 double y = n1.getCoor().getY() - n0.getCoor().getY(); 66 return Math.atan2(y, x); 67 } 67 return Math.atan2(y, x); 68 } 68 69 69 70 /** 70 71 * Replies the unique common node of two ways, or null, if either no 71 72 * such node or multiple common nodes exist. 72 * 73 * 73 74 * @param w1 the first way 74 75 * @param w2 the second way … … 76 77 * w1 and w2 don't share exactly one node 77 78 */ 78 static public Node getUniqueCommonNode(Way w1, Way w2) throws IllegalArgumentException{79 public static Node getUniqueCommonNode(Way w1, Way w2) throws IllegalArgumentException { 79 80 Set<Node> w1Nodes = new HashSet<>(w1.getNodes()); 80 81 w1Nodes.retainAll(w2.getNodes()); 81 82 if (w1Nodes.size() != 1) return null; 82 83 return w1Nodes.iterator().next(); 83 } 84 84 } 85 85 86 /** 86 87 * Replies true, if {@code n} is the start node of the way {@code w}. 87 * 88 * 88 89 * @param w the way. Must not be null. 89 90 * @param n the node. Must not be null. 90 91 * @return true, if {@code n} is the start node of the way {@code w}. 91 92 */ 92 static public boolean isStartNode(Way w, Node n) {93 public static boolean isStartNode(Way w, Node n) { 93 94 if (w.getNodesCount() == 0) return false; 94 95 return w.getNode(0).equals(n); 95 96 } 96 97 97 98 /** 98 99 * Replies true, if {@code n} is the end node of the way {@code w}. 99 * 100 * 100 101 * @param w the way. Must not be null. 101 102 * @param n the node. Must not be null. 102 103 * @return true, if {@code n} is the end node of the way {@code w}. 103 104 */ 104 static public boolean isEndNode(Way w, Node n){105 public static boolean isEndNode(Way w, Node n) { 105 106 if (w.getNodesCount() == 0) return false; 106 107 return w.getNode(w.getNodesCount()-1).equals(n); 107 108 } 108 109 109 110 /** 110 111 * Replies true, if {@code n} is a node in the way {@code w} but {@code n} 111 112 * 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 115 116 * @return true if {@code n} is an "inner" node 116 117 */ 117 static public boolean isInnerNode(Way w, Node n){118 public static boolean isInnerNode(Way w, Node n) { 118 119 if (!w.getNodes().contains(n)) return false; 119 120 if (isStartNode(w, n)) return false; 120 121 if (isEndNode(w, n)) return false; 121 return true; 122 } 123 122 return true; 123 } 124 124 125 /** 125 126 * <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 * 128 129 * <p>If the result is positive, the way {@code from} bends to the right, if it 129 130 * 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 132 133 * common node. They must <strong>not intersect</code> at this node.</p>. 133 * 134 * 134 135 * @param from the from way 135 136 * @param to the to way 136 * @return the intersection angle 137 * @return the intersection angle 137 138 * @throws IllegalArgumentException thrown if the two nodes don't have exactly one common 138 139 * 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 { 142 143 Node via = getUniqueCommonNode(from, to); 143 144 if (via == null) 144 145 throw new IllegalArgumentException("the two ways must share exactly one common node"); // no I18n required 145 if (!isStartNode(from, via) && ! 146 if (!isStartNode(from, via) && !isEndNode(from, via)) 146 147 throw new IllegalArgumentException("via node must be start or end node of from-way"); // no I18n required 147 if (!isStartNode(to, via) && ! 148 if (!isStartNode(to, via) && !isEndNode(to, via)) 148 149 throw new IllegalArgumentException("via node must be start or end node of to-way"); // no I18n required 149 150 double phi1 = phi(from, isStartNode(from, via)); 150 151 double phi2 = phi(to, isEndNode(to, via)); 151 152 return phi1 - phi2; 152 } 153 154 staticpublic enum RelativeWayJoinOrientation {153 } 154 155 public enum RelativeWayJoinOrientation { 155 156 LEFT, 156 157 RIGHT 157 158 } 159 158 160 /** 159 161 * <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 * 162 164 * <p>The following preconditions must be met: 163 165 * <ul> … … 169 171 * </ul> 170 172 * </p> 171 * 173 * 172 174 * <p>Here's a typical configuration:</p> 173 175 * <pre> … … 178 180 * | 179 181 * </pre> 180 * 182 * 181 183 * <p>Replies null, if the preconditions aren't met and the method fails to 182 184 * determine the join orientation.</p> 183 * 185 * 184 186 * @param from the "from"-way 185 187 * @param to the "to"-way … … 187 189 * join orientation 188 190 */ 189 public static RelativeWayJoinOrientation determineWayJoinOrientation(Way from, Way to){ 191 public static RelativeWayJoinOrientation determineWayJoinOrientation(Way from, Way to) { 190 192 Node via = getUniqueCommonNode(from, to); 191 193 if (via == null) return null; … … 195 197 if (isClosedAt(from, via)) return null; 196 198 if (isClosedAt(to, via)) return null; 197 199 198 200 double phi = intersectionAngle(from, to); 199 if (phi >=0 && phi <= Math.PI) { 201 if (phi >= 0 && phi <= Math.PI) { 200 202 return RelativeWayJoinOrientation.RIGHT; 201 203 } else { 202 204 return RelativeWayJoinOrientation.LEFT; 203 } 204 } 205 205 } 206 } 207 206 208 /** 207 209 * <p>Selects either of the two ways resulting from the split of a way 208 210 * in the role {@link TurnRestrictionLegRole#TO TO}.</p> 209 * 211 * 210 212 * <p>This methods operates on three ways for which the following 211 213 * preconditions must be met: … … 216 218 * </ul> 217 219 * </p> 218 * 220 * 219 221 * <p>Here's a typical configuration:</p> 220 222 * <pre> … … 225 227 * | 226 228 * </pre> 227 * 229 * 228 230 * <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 230 232 * "left turn", {@code to1} is replied. If our context is a "right turn", {@code to2} 231 233 * is returned.</p> 232 * 234 * 233 235 * <p>Replies null, if the expected preconditions aren't met or if we can't infer 234 236 * from {@code restrictionType} whether our context is a "left turn" or a "right turn".</p> 235 * 237 * 236 238 * @param from the from-way 237 239 * @param to1 the first part of the split to-way … … 240 242 * @return either {@code to1}, {@code to2}, or {@code null}. 241 243 */ 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) { 243 245 if (restrictionType == null) return null; 244 246 Node cn1 = TurnRestrictionBuilder.getUniqueCommonNode(from, to1); … … 247 249 if (cn2 == null) return null; 248 250 if (cn1 != cn2) return null; 249 250 if (! 251 252 if (!isStartNode(from, cn1) && !isEndNode(from, cn1)) { 251 253 /* 252 254 * the now split to-way still *intersects* the from-way. We … … 255 257 return null; 256 258 } 257 259 258 260 RelativeWayJoinOrientation o1 = determineWayJoinOrientation(from, to1); 259 261 RelativeWayJoinOrientation o2 = determineWayJoinOrientation(from, to2); 260 261 switch(restrictionType){ 262 263 switch(restrictionType) { 262 264 case NO_LEFT_TURN: 263 265 case ONLY_LEFT_TURN: … … 265 267 else if (RelativeWayJoinOrientation.LEFT.equals(o2)) return to2; 266 268 else return null; 267 269 268 270 case NO_RIGHT_TURN: 269 271 case ONLY_RIGHT_TURN: … … 271 273 else if (RelativeWayJoinOrientation.RIGHT.equals(o2)) return to2; 272 274 else return null; 273 275 274 276 default: 275 277 /* … … 280 282 } 281 283 } 282 283 public TurnRestrictionBuilder(){ 284 } 285 284 285 public TurnRestrictionBuilder() { 286 } 287 286 288 /** 287 289 * Creates and initializes a new turn restriction based on the primitives 288 290 * currently selected in layer {@code layer}. 289 * 291 * 290 292 * @param layer the layer. Must not be null. 291 293 * @return the new initialized turn restriction. The turn restriction isn't … … 300 302 301 303 /** 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 303 305 * <code>primitives</code>. If successful, replies true, otherwise false. 304 * 305 * @param primitives the primitives 306 * 307 * @param primitives the primitives 306 308 * @return true, if we can propose a U-turn restriction for the primitives 307 309 * in <code>primitives</code> … … 309 311 protected Relation initNoUTurnRestriction(List<OsmPrimitive> primitives) { 310 312 if (primitives.size() != 2) return null; 311 313 312 314 // we need exactly one node and one way in the selection ... 313 315 List<Node> nodes = OsmPrimitive.getFilteredList(primitives, Node.class); 314 316 List<Way> ways = OsmPrimitive.getFilteredList(primitives, Way.class); 315 317 if (nodes.size() != 1 || ways.size() != 1) return null; 316 318 317 319 // .. and the node has to be the start or the node of the way 318 320 Way way = ways.get(0); … … 320 322 List<Node> wayNodes = way.getNodes(); 321 323 if (wayNodes.size() < 2) return null; // shouldn't happen - just in case 322 if (! 324 if (!(wayNodes.get(0).equals(node) || wayNodes.get(wayNodes.size()-1).equals(node))) return null; 323 325 324 326 Relation tr = new Relation(); … … 334 336 * <p>Replies true, if the ways {@code w1} and {@code w2} are connected 335 337 * at the node {@code n}.</p> 336 * 338 * 337 339 * <p>If {@code w1} and {@code w2} <em>intersect</em> at the node {@code n}, 338 340 * this method replies false.</p> 339 * 341 * 340 342 * @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) { 346 347 if (isStartNode(w1, n)) { 347 return isStartNode(w2, n) 348 } else if (isEndNode(w1, n)){ 349 return isStartNode(w2, n) 348 return isStartNode(w2, n) | isEndNode(w2, n); 349 } else if (isEndNode(w1, n)) { 350 return isStartNode(w2, n) | isEndNode(w2, n); 350 351 } 351 352 return false; 352 353 } 353 354 354 355 /** 355 356 * Replies true, if the way {@code w} is closed at the node {@code n}. 356 * 357 * 357 358 * @param w the way 358 * @param n the node 359 * @param n the node 359 360 * @return true, if the way {@code w} is closed at the node {@code n}. 360 361 */ 361 public static boolean isClosedAt(Way w, Node n){ 362 public static boolean isClosedAt(Way w, Node n) { 362 363 List<Node> nodes = w.getNodes(); 363 364 nodes.retainAll(Collections.singletonList(n)); 364 365 return nodes.size() >= 2; 365 366 } 366 367 367 368 protected Relation initTurnRestrictionFromTwoWays(List<OsmPrimitive> primitives) { 368 369 Way w1 = null; … … 370 371 Node via = null; 371 372 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. 373 374 // See initNoUTurnRestriction() for the case where we have a selected way 374 375 // and a selected node … … 378 379 w2 = selWays.get(1); 379 380 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 383 384 List<Way> selWays = OsmPrimitive.getFilteredList(primitives, Way.class); 384 385 List<Node> selNodes = OsmPrimitive.getFilteredList(primitives, Node.class); … … 388 389 w2 = selWays.get(1); 389 390 via = selNodes.get(0); 390 if (! 391 if (!w1.getNodes().contains(via) || !w2.getNodes().contains(via)) { 391 392 // the selected node is not an acceptable via node 392 393 via = null; … … 394 395 } else { 395 396 // the selection doesn't consists of primitives for which we can build 396 // a turn restriction 397 // a turn restriction 397 398 return null; 398 399 } 399 400 400 401 // if we get here, we know the two "legs" of the turn restriction. We may 401 402 // or may not know a via node, though 402 403 assert w1 != null; 403 404 assert w2 != null; 404 405 405 406 Relation tr = new Relation(); 406 407 tr.put("type", "restriction"); 407 408 tr.addMember(new RelationMember("from", w1)); 408 409 tr.addMember(new RelationMember("to", w2)); 409 410 if (via != null){ 410 411 if (via != null) { 411 412 tr.addMember(new RelationMember("via", via)); 412 413 RelativeWayJoinOrientation orientation = determineWayJoinOrientation(w1, w2); 413 if (orientation != null){ 414 switch(orientation){ 414 if (orientation != null) { 415 switch(orientation) { 415 416 case LEFT: 416 417 tr.put("restriction", TurnRestrictionType.NO_LEFT_TURN.getTagValue()); … … 418 419 case RIGHT: 419 420 tr.put("restriction", TurnRestrictionType.NO_RIGHT_TURN.getTagValue()); 420 break; 421 break; 421 422 } 422 423 } … … 424 425 return tr; 425 426 } 426 427 427 428 protected Relation initEmptyTurnRestriction() { 428 429 Relation tr = new Relation(); … … 430 431 return tr; 431 432 } 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 435 436 * in {@code primitives}. 436 * 437 * @param primitives the primitives 437 * 438 * @param primitives the primitives 438 439 * @return the new initialized turn restriction. The turn restriction isn't 439 440 * added to the layer yet. 440 441 */ 441 public synchronized Relation build(List<OsmPrimitive> primitives){ 442 public synchronized Relation build(List<OsmPrimitive> primitives) { 442 443 if (primitives == null || primitives.isEmpty()) { 443 444 return initEmptyTurnRestriction(); 444 445 } 445 446 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: 449 450 tr = initEmptyTurnRestriction(); 450 if (OsmPrimitive.getFilteredList(primitives, Way.class).size() == 1) { 451 if (OsmPrimitive.getFilteredList(primitives, Way.class).size() == 1) { 451 452 // we have exactly one selected way? -> init the "from" leg 452 453 // of the turn restriction with it … … 454 455 } 455 456 return tr; 456 457 457 458 case 2: 458 459 tr = initNoUTurnRestriction(primitives); … … 461 462 if (tr != null) return tr; 462 463 return initEmptyTurnRestriction(); 463 464 464 465 default: 465 466 tr = initTurnRestrictionFromTwoWays(primitives); 466 467 if (tr != null) return tr; 467 return initEmptyTurnRestriction(); 468 } 469 } 468 return initEmptyTurnRestriction(); 469 } 470 } 470 471 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/TurnRestrictionsPlugin.java
r27891 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions; 2 3 … … 10 11 /** 11 12 * This is the main class for the turnrestrictions plugin. 12 * 13 * 13 14 */ 14 public class TurnRestrictionsPlugin extends Plugin{ 15 15 public class TurnRestrictionsPlugin extends Plugin { 16 16 17 public TurnRestrictionsPlugin(PluginInformation info) { 17 super(info); 18 super(info); 18 19 } 19 20 20 21 /** 21 * Called when the JOSM map frame is created or destroyed. 22 * Called when the JOSM map frame is created or destroyed. 22 23 */ 23 24 @Override 24 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 25 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 25 26 if (oldFrame == null && newFrame != null) { // map frame added 26 TurnRestrictionsListDialog dialog 27 TurnRestrictionsListDialog dialog = new TurnRestrictionsListDialog(); 27 28 // add the dialog 28 29 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.dnd; 2 3 … … 8 9 * Replies the list of currently selected primitive IDs. Replies an empty list if no primitive IDs 9 10 * are selected. 10 * 11 * 11 12 * @return the list of currently selected primitive IDs 12 13 */ -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/dnd/PrimitiveIdListTransferHandler.java
r30454 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.dnd; 2 3 … … 11 12 12 13 /** 13 * <p>PrimitiveIdListTransferHandler is a transfer handler for components which 14 * <p>PrimitiveIdListTransferHandler is a transfer handler for components which 14 15 * provide and/or accept a list of {@link PrimitiveId} via copy/paste or 15 16 * drag-and-drop.</p> 16 * 17 * 17 18 * <p>It creates a {@link Transferable} by retrieving the list of primitive IDs 18 19 * from a {@link PrimitiveIdListProvider}.</p> 19 * 20 * 20 21 */ 21 22 public class PrimitiveIdListTransferHandler extends TransferHandler { 22 //static private final Logger logger = Logger.getLogger(PrimitiveIdListTransferHandler.class.getName());23 23 private PrimitiveIdListProvider provider; 24 24 25 25 /** 26 26 * Replies true if {@code transferFlavors} includes the data flavor {@link PrimitiveIdTransferable#PRIMITIVE_ID_LIST_FLAVOR}. … … 35 35 return false; 36 36 } 37 37 38 38 /** 39 * Creates the transfer handler 40 * 39 * Creates the transfer handler 40 * 41 41 * @param provider the provider of the primitive IDs. Must not be null. 42 42 * @throws IllegalArgumentException thrown if provider is null. 43 43 */ 44 public PrimitiveIdListTransferHandler(PrimitiveIdListProvider provider) throws IllegalArgumentException{ 44 public PrimitiveIdListTransferHandler(PrimitiveIdListProvider provider) throws IllegalArgumentException { 45 45 CheckParameterUtil.ensureParameterNotNull(provider, "provider"); 46 46 this.provider = provider; 47 47 } 48 48 49 @Override 49 50 protected Transferable createTransferable(JComponent c) { 50 return new PrimitiveIdTransferable(provider.getSelectedPrimitiveIds()); 51 return new PrimitiveIdTransferable(provider.getSelectedPrimitiveIds()); 51 52 } 52 53 54 @Override 53 55 public int getSourceActions(JComponent c) { 54 56 return COPY; … … 57 59 @Override 58 60 public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { 59 return isSupportedFlavor(transferFlavors); 60 } 61 return isSupportedFlavor(transferFlavors); 62 } 61 63 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/dnd/PrimitiveIdTransferable.java
r30737 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.dnd; 2 3 … … 14 15 /** 15 16 * To be used for Drag-and-Drop of a set of {@link PrimitiveId}s between 16 * two components. 17 * two components. 17 18 * 18 19 */ 19 public class PrimitiveIdTransferable implements Transferable{ 20 20 public class PrimitiveIdTransferable implements Transferable { 21 21 22 /** 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 = 23 24 new DataFlavor(Set.class, "a set of OSM primitive ids"); 24 25 /** 25 26 /** 26 27 * this transferable supports two flavors: (1) {@link #PRIMITIVE_ID_LIST_FLAVOR} and 27 28 * (2) {@link DataFlavor#stringFlavor}. 28 * 29 * 29 30 * See also {@link #getPrimitiveIds()} and {@link #getAsString()} 30 31 */ 31 static public final DataFlavor[] SUPPORTED_FLAVORS = new DataFlavor[] {32 public static final DataFlavor[] SUPPORTED_FLAVORS = new DataFlavor[] { 32 33 PRIMITIVE_ID_LIST_FLAVOR, 33 34 DataFlavor.stringFlavor 34 35 }; 35 36 36 37 37 38 private List<PrimitiveId> ids = new ArrayList<>(); 38 39 39 40 /** 40 41 * Creates a transferable from a collection of {@link PrimitiveId}s 41 *42 * @param ids43 42 */ 44 43 public PrimitiveIdTransferable(List<PrimitiveId> ids) { 45 44 if (ids == null) return; 46 for(PrimitiveId id: ids) { 45 for (PrimitiveId id: ids) { 47 46 this.ids.add(new SimplePrimitiveId(id.getUniqueId(), id.getType())); 48 47 } 49 48 } 50 49 51 50 /** 52 51 * <p>If flavor is {@link #PRIMITIVE_ID_SET_FLAVOR}, replies a the list of 53 52 * transferred {@link PrimitiveId}s</p> 54 * 53 * 55 54 * <p>If flavor is {@link DataFlavor#stringFlavor}, replies a string representation 56 55 * of the list of transferred {@link PrimitiveId}s</p> 57 56 */ 57 @Override 58 58 public Object getTransferData(DataFlavor flavor) 59 59 throws UnsupportedFlavorException, IOException { … … 65 65 throw new UnsupportedFlavorException(flavor); 66 66 } 67 67 68 68 /** 69 69 * Replies the list of OSM primitive ids 70 * 70 * 71 71 * @return the list of OSM primitive ids 72 72 */ … … 74 74 return ids; 75 75 } 76 76 77 77 /** 78 78 * Replies a string representation of the list of OSM primitive ids 79 * 79 * 80 80 * @return a string representation of the list of OSM primitive ids 81 81 */ 82 82 public String getAsString() { 83 83 StringBuffer sb = new StringBuffer(); 84 for(PrimitiveId id: ids) { 84 for (PrimitiveId id: ids) { 85 85 if (sb.length() > 0) sb.append(","); 86 86 sb.append(id.getType().getAPIName()).append("/").append(id.getUniqueId()); … … 89 89 } 90 90 91 @Override 91 92 public DataFlavor[] getTransferDataFlavors() { 92 93 return SUPPORTED_FLAVORS; 93 94 } 94 95 96 @Override 95 97 public boolean isDataFlavorSupported(DataFlavor flavor) { 96 for(DataFlavor df: SUPPORTED_FLAVORS) { 98 for (DataFlavor df: SUPPORTED_FLAVORS) { 97 99 if (df.equals(flavor)) return true; 98 100 } 99 101 return false; 100 } 102 } 101 103 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/AdvancedEditorPanel.java
r31562 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 22 23 */ 23 24 public class AdvancedEditorPanel extends JPanel { 24 //private static final Logger logger = Logger.getLogger(AdvancedEditorPanel.class.getName());25 25 26 26 private TurnRestrictionEditorModel model; … … 31 31 /** 32 32 * Creates the panel with the tag editor 33 *34 * @return35 33 */ 36 34 protected JPanel buildTagEditorPanel() { … … 51 49 /** 52 50 * Builds the panel with the table for editing relation members 53 *54 * @return55 51 */ 56 52 protected JPanel buildMemberEditorPanel() { … … 73 69 /** 74 70 * Creates the main split panel 75 * @return76 71 */ 77 72 protected JSplitPane buildSplitPane() { … … 99 94 * @throws IllegalArgumentException thrown if model is null 100 95 */ 101 public AdvancedEditorPanel(TurnRestrictionEditorModel model) throws IllegalArgumentException{ 96 public AdvancedEditorPanel(TurnRestrictionEditorModel model) throws IllegalArgumentException { 102 97 CheckParameterUtil.ensureParameterNotNull(model, "model"); 103 98 this.model = model; … … 111 106 */ 112 107 class SplitPaneDividerInitializer implements HierarchyListener { 108 @Override 113 109 public void hierarchyChanged(HierarchyEvent e) { 114 110 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 25 26 * BasicEditorPanel provides a UI for editing the basic elements of a turn restriction, 26 27 * i.e. its restriction type, the from, the to, and the via objects. 27 * 28 * 28 29 */ 29 30 public class BasicEditorPanel extends VerticallyScrollablePanel { … … 31 32 /** the turn restriction model */ 32 33 private TurnRestrictionEditorModel model; 33 34 34 35 /** the UI widgets */ 35 36 private TurnRestrictionLegEditor fromEditor; … … 40 41 private TurnRestrictionComboBox cbTurnRestrictions; 41 42 private VehicleExceptionEditor vehicleExceptionsEditor; 42 43 43 44 /** 44 45 * builds the UI … … 50 51 gc.fill = GridBagConstraints.HORIZONTAL; 51 52 gc.weightx = 0.0; 52 53 53 54 // 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); 55 56 add(new JLabel(tr("Type:")), gc); 56 57 57 58 gc.gridx = 1; 58 59 gc.weightx = 1.0; … … 61 62 // the editor for selecting the 'from' leg 62 63 gc.gridx = 0; 63 gc.gridy = 1; 64 gc.gridy = 1; 64 65 gc.weightx = 0.0; 65 66 add(new JLabel(tr("From:")), gc); 66 67 67 68 gc.gridx = 1; 68 69 gc.weightx = 1.0; 69 add(fromEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM),gc); 70 add(fromEditor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM), gc); 70 71 71 72 // the editor for selecting the 'to' leg … … 73 74 gc.gridy = 2; 74 75 gc.weightx = 0.0; 75 gc.insets = new Insets(0, 0,5,5);76 gc.insets = new Insets(0, 0, 5, 5); 76 77 add(new JLabel(tr("To:")), gc); 77 78 78 79 gc.gridx = 1; 79 80 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' 83 84 gc.gridx = 0; 84 85 gc.gridy = 3; 85 86 gc.weightx = 0.0; 86 gc.insets = new Insets(0, 0,5,5);87 gc.insets = new Insets(0, 0, 5, 5); 87 88 add(lblVias = new JLabel(tr("Vias:")), gc); 88 89 89 90 gc.gridx = 1; 90 91 gc.weightx = 1.0; … … 93 94 spVias = new JScrollPane(lstVias = new ViaList(new ViaListModel(model, selectionModel), selectionModel)) { 94 95 // fixes #6016 : Scrollbar hides field entry 96 @Override 95 97 public Dimension getPreferredSize() { 96 98 return new Dimension(100, 80); // only height is relevant, 80 is just a heuristical value 97 99 } 98 100 }; 99 add(spVias,gc); 101 add(spVias, gc); 100 102 if (!Main.pref.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false)) { 101 103 lblVias.setVisible(false); 102 104 spVias.setVisible(false); 103 105 } 104 106 105 107 // the editor for vehicle exceptions 106 108 vehicleExceptionsEditor = new VehicleExceptionEditor(model); … … 110 112 gc.weighty = 0.0; 111 113 gc.gridwidth = 2; 112 gc.insets = new Insets(0, 0,5,5);114 gc.insets = new Insets(0, 0, 5, 5); 113 115 add(vehicleExceptionsEditor, gc); 114 115 // just a filler - grabs remaining space 116 117 // just a filler - grabs remaining space 116 118 gc.gridx = 0; 117 119 gc.gridy = 5; … … 120 122 gc.fill = GridBagConstraints.BOTH; 121 123 add(new JPanel(), gc); 122 123 setBorder(BorderFactory.createEmptyBorder(5, 5,5,5));124 125 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 124 126 } 125 126 127 128 127 129 /** 128 * Creates the panel. 129 * 130 * Creates the panel. 131 * 130 132 * @param model the editor model. Must not be null. 131 133 * @throws IllegalArgumentException thrown if model is null … … 137 139 HelpUtil.setHelpContext(this, HelpUtil.ht("/Plugin/TurnRestrictions#BasicEditor")); 138 140 } 139 141 140 142 /** 141 143 * Requests the focus on one of the input widgets for turn 142 144 * restriction data. 143 * 145 * 144 146 * @param focusTarget the target component to request focus for. 145 147 * Ignored if null. 146 148 */ 147 public void requestFocus For(BasicEditorFokusTargets focusTarget){149 public void requestFocusfor(BasicEditorFokusTargets focusTarget) { 148 150 if (focusTarget == null) return; 149 switch(focusTarget){ 151 switch(focusTarget) { 150 152 case RESTRICION_TYPE: 151 153 cbTurnRestrictions.requestFocusInWindow(); … … 161 163 break; 162 164 } 163 } 164 165 } 166 165 167 /** 166 168 * Initializes the set of icons used from the preference key 167 169 * {@link PreferenceKeys#ROAD_SIGNS}. 168 * 169 * @param prefs the JOSM preferences 170 * 171 * @param prefs the JOSM preferences 170 172 */ 171 public void initIconSetFromPreferences(Preferences prefs) {173 public void initIconSetFromPreferences(Preferences prefs) { 172 174 cbTurnRestrictions.initIconSetFromPreferences(prefs); 173 175 } 174 176 175 177 /** 176 178 * Initializes the visibility of the list of via-objects depending 177 179 * on values in the JOSM preferences 178 * 180 * 179 181 * @param prefs the JOSM preferences 180 182 */ 181 public void initViasVisibilityFromPreferences(Preferences prefs){ 183 public void initViasVisibilityFromPreferences(Preferences prefs) { 182 184 boolean value = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false); 183 if (value != lblVias.isVisible()){ 185 if (value != lblVias.isVisible()) { 184 186 lblVias.setVisible(value); 185 187 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 10 11 /** 11 12 * ExceptValueModel is a model for the value of the tag 'except' in a turn 12 * restriction. 13 * restriction. 13 14 * 14 15 */ … … 16 17 /** 17 18 * 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; 21 22 static { 22 23 HashSet<String> s = new HashSet<>(); … … 28 29 STANDARD_VEHICLE_EXCEPTION_VALUES = Collections.unmodifiableSet(s); 29 30 } 30 31 31 32 /** 32 33 * Replies true, if {@code v} is a standard vehicle type. Replies 33 34 * false if {@code v} is null 34 * 35 * @param v the vehicle type. 35 * 36 * @param v the vehicle type. 36 37 * @return true, if {@code v} is a standard vehicle type. 37 38 */ 38 static public boolean isStandardVehicleExceptionValue(String v){39 public static boolean isStandardVehicleExceptionValue(String v) { 39 40 if (v == null) return false; 40 41 v = v.trim().toLowerCase(); 41 42 return STANDARD_VEHICLE_EXCEPTION_VALUES.contains(v); 42 43 } 43 44 44 45 private String value = ""; 45 46 private boolean isStandard = true; 46 47 private final Set<String> vehicleExceptions = new HashSet<>(); 47 48 48 49 protected void parseValue(String value) { 49 50 if (value == null || value.trim().equals("")) value = ""; … … 53 54 if (value.equals("")) return; 54 55 String[] values = value.split(";"); 55 for (String v: values){ 56 for (String v: values) { 56 57 v = v.trim().toLowerCase(); 57 58 if (isStandardVehicleExceptionValue(v)) { … … 62 63 } 63 64 } 64 65 /** 66 * Creates a new model for an empty standard value 65 66 /** 67 * Creates a new model for an empty standard value 67 68 */ 68 69 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 * 73 74 * @param value the tag value 74 75 * @see #parseValue(String) 75 76 */ 76 public ExceptValueModel(String value){ 77 if (value == null || value.trim().equals("")) 77 public ExceptValueModel(String value) { 78 if (value == null || value.trim().equals("")) 78 79 return; 79 80 parseValue(value); … … 82 83 /** 83 84 * Replies the tag value representing the state of this model. 84 *85 * @return86 85 */ 87 86 public String getValue() { 88 if (isStandard){ 87 if (isStandard) { 89 88 StringBuffer sb = new StringBuffer(); 90 89 // we use an ordered list because equals() … … 93 92 List<String> values = new ArrayList<>(vehicleExceptions); 94 93 Collections.sort(values); 95 for (String v: values){ 94 for (String v: values) { 96 95 if (sb.length() > 0) { 97 96 sb.append(";"); … … 107 106 /** 108 107 * Sets the value in this model 109 *110 * @param value111 108 */ 112 109 public void setValue(String value) { … … 116 113 /** 117 114 * Replies true if this model currently holds a standard 'except' value 118 *119 * @return120 115 */ 121 116 public boolean isStandard() { 122 117 return isStandard; 123 } 124 118 } 119 125 120 /** 126 121 * Tells this model to use standard values only. 127 * 122 * 128 123 */ 129 124 public void setStandard(boolean isStandard) { 130 125 this.isStandard = isStandard; 131 126 } 132 127 133 128 /** 134 129 * Replies true if {@code vehicleType} is currently set as exception in this 135 130 * model. 136 * 131 * 137 132 * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES} 138 133 * @return true if {@code vehicleType} is currently set as exception in this 139 134 * 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 { 143 138 if (vehicleType == null) return false; 144 139 if (!isStandardVehicleExceptionValue(vehicleType)) { … … 148 143 return vehicleExceptions.contains(vehicleType); 149 144 } 150 145 151 146 /** 152 147 * 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 { 158 153 if (!isStandardVehicleExceptionValue(vehicleType)) { 159 154 throw new IllegalArgumentException(MessageFormat.format("vehicleType ''{0}'' isn''t a valid standard vehicle type", vehicleType)); … … 161 156 vehicleExceptions.add(vehicleType.trim().toLowerCase()); 162 157 } 163 158 164 159 165 160 /** 166 161 * Sets or removes the {@code vehicleType} as exception in this turn restriction, depending 167 162 * on whether {@code setOrRemove} is true or false, respectively. 168 * 163 * 169 164 * @param vehicleType one of the standard vehicle types from {@see #STANDARD_VEHICLE_EXCEPTION_VALUES} 170 165 * @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) { 175 170 setVehicleException(vehicleType); 176 171 } else { … … 178 173 } 179 174 } 180 175 181 176 /** 182 177 * 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 { 188 183 if (!isStandardVehicleExceptionValue(vehicleType)) { 189 184 throw new IllegalArgumentException(MessageFormat.format("vehicleType ''{0}'' isn''t a valid standard vehicle type", vehicleType)); … … 210 205 ExceptValueModel other = (ExceptValueModel) obj; 211 206 return getValue().equals(other.getValue()); 212 } 207 } 213 208 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java
r32375 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 35 36 * 36 37 */ 37 public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive> implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider{38 //static private final Logger logger = Logger.getLogger(JosmSelectionListModel.class.getName());38 public class JosmSelectionListModel extends AbstractListModel<OsmPrimitive> 39 implements ActiveLayerChangeListener, SelectionChangedListener, DataSetListener, PrimitiveIdListProvider { 39 40 40 41 private final List<OsmPrimitive> selection = new ArrayList<>(); … … 73 74 public Collection<OsmPrimitive> getSelected() { 74 75 Set<OsmPrimitive> sel = new HashSet<>(); 75 for (int i=0; i< getSize();i++) {76 for (int i = 0; i < getSize(); i++) { 76 77 if (selectionModel.isSelectedIndex(i)) { 77 78 sel.add(selection.get(i)); … … 89 90 selectionModel.clearSelection(); 90 91 if (sel == null) return; 91 for (OsmPrimitive p: sel){ 92 for (OsmPrimitive p: sel) { 92 93 int i = selection.indexOf(p); 93 if (i >= 0){ 94 if (i >= 0) { 94 95 selectionModel.addSelectionInterval(i, i); 95 96 } … … 136 137 if (toUpdate.isEmpty()) return; 137 138 Collection<OsmPrimitive> sel = getSelected(); 138 for (OsmPrimitive p: toUpdate){ 139 for (OsmPrimitive p: toUpdate) { 139 140 int i = selection.indexOf(p); 140 141 if (i >= 0) { 141 super.fireContentsChanged(this, i,i); 142 super.fireContentsChanged(this, i, i); 142 143 } 143 144 } … … 158 159 // don't show a JOSM selection if we don't have a data layer 159 160 setJOSMSelection(null); 160 } else if (newLayer != layer){ 161 } else if (newLayer != layer) { 161 162 // don't show a JOSM selection if this turn restriction editor doesn't 162 163 // manipulate data in the current data layer … … 175 176 // this turn restriction editor is working on 176 177 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 177 if(layer == null) return; 178 if (layer == null) return; 178 179 if (layer != this.layer) return; 179 180 setJOSMSelection(newSelection); … … 226 227 @Override 227 228 public void primitivesAdded(PrimitivesAddedEvent event) {/* ignored - handled by SelectionChangeListener */} 229 228 230 @Override 229 231 public void primitivesRemoved(PrimitivesRemovedEvent event) {/* ignored - handled by SelectionChangeListener*/} … … 235 237 public List<PrimitiveId> getSelectedPrimitiveIds() { 236 238 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++) { 238 240 if (selectionModel.isSelectedIndex(i)) { 239 241 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 64 65 add(new JLabel(tr("Selection")), BorderLayout.NORTH); 65 66 66 setBorder(BorderFactory.createEmptyBorder(5, 5,5,5));67 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 67 68 actCopy = new CopyAction(); 68 69 lstSelection.addMouseListener(new PopupLauncher()); … … 75 76 * @exception IllegalArgumentException thrown if {@code layer} is null 76 77 */ 77 public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException{ 78 public JosmSelectionPanel(OsmDataLayer layer, JosmSelectionListModel model) throws IllegalArgumentException { 78 79 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 79 80 this.model = model; … … 107 108 108 109 class PopupMenu extends JPopupMenu { 109 publicPopupMenu() {110 PopupMenu() { 110 111 JMenuItem item = add(actCopy); 111 112 item.setTransferHandler(transferHandler); … … 117 118 private Action delegate; 118 119 119 publicCopyAction(){120 CopyAction() { 120 121 putValue(NAME, tr("Copy")); 121 122 putValue(SHORT_DESCRIPTION, tr("Copy to the clipboard")); … … 131 132 } 132 133 133 staticprivate class JosmSelectionTransferHandler extends PrimitiveIdListTransferHandler {134 publicJosmSelectionTransferHandler(PrimitiveIdListProvider provider) {134 private static class JosmSelectionTransferHandler extends PrimitiveIdListTransferHandler { 135 JosmSelectionTransferHandler(PrimitiveIdListProvider provider) { 135 136 super(provider); 136 137 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/MemberRoleCellEditor.java
r30938 r32519 15 15 /** 16 16 * The cell editor for member roles of relation members in a turn restriction. 17 * 17 * 18 18 */ 19 19 public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor { 20 // staticprivate Logger logger = Logger.getLogger(MemberRoleCellEditor.class.getName());20 //private static Logger logger = Logger.getLogger(MemberRoleCellEditor.class.getName()); 21 21 22 22 private AutoCompletingTextField editor = null; … … 41 41 * replies the table cell editor 42 42 */ 43 @Override 43 44 public Component getTableCellEditorComponent(JTable table, 44 45 Object value, boolean isSelected, int row, int column) { 45 46 46 String role = (String)value; 47 editor.setText(role); 47 String role = (String) value; 48 editor.setText(role); 48 49 return editor; 49 50 } 50 51 52 @Override 51 53 public Object getCellEditorValue() { 52 54 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 3 4 public interface NavigationControler { 4 publicenum BasicEditorFokusTargets {5 enum BasicEditorFokusTargets { 5 6 RESTRICION_TYPE, 6 7 FROM, 7 8 TO, 8 9 VIA 9 } 10 void gotoBasicEditor(); 10 } 11 12 void gotoBasicEditor(); 13 11 14 void gotoAdvancedEditor(); 12 void gotoBasicEditor(BasicEditorFokusTargets focusTarget); 15 16 void gotoBasicEditor(BasicEditorFokusTargets focusTarget); 13 17 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberColumnModel.java
r23526 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 14 15 * displayed in the {@link AdvancedEditorPanel}. 15 16 */ 16 public class RelationMemberColumnModel extends DefaultTableColumnModel{ 17 public class RelationMemberColumnModel extends DefaultTableColumnModel { 17 18 protected void build() { 18 19 TableColumn col = new TableColumn(); 19 20 20 21 // the role column 21 22 col.setHeaderValue(tr("Role")); 22 23 col.setResizable(true); 23 col.setPreferredWidth(100); 24 col.setPreferredWidth(100); 24 25 col.setCellEditor(new MemberRoleCellEditor()); 25 26 addColumn(col); 26 27 27 28 // column 1 - the member 28 29 col = new TableColumn(1); … … 31 32 col.setPreferredWidth(300); 32 33 col.setCellRenderer(new OsmPrimitivRenderer()); 33 addColumn(col); 34 addColumn(col); 34 35 } 35 36 36 37 /** 37 38 * Creates the column model with a given column selection model. 38 * 39 * 39 40 * @param colSelectionModel the column selection model. Must not be null. 40 41 * @throws IllegalArgumentException thrown if {@code colSelectionModel} is null 41 42 */ 42 public RelationMemberColumnModel(DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException{ 43 public RelationMemberColumnModel(DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException { 43 44 CheckParameterUtil.ensureParameterNotNull(colSelectionModel, "colSelectionModel"); 44 45 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; … … 23 23 import org.openstreetmap.josm.tools.CheckParameterUtil; 24 24 25 public class RelationMemberEditorModel extends AbstractTableModel{ 26 //static private final Logger logger = Logger.getLogger(RelationMemberEditorModel.class.getName()); 25 public class RelationMemberEditorModel extends AbstractTableModel { 27 26 private final ArrayList<RelationMemberModel> members = new ArrayList<>(); 28 27 private OsmDataLayer layer; 29 28 private DefaultListSelectionModel rowSelectionModel; 30 29 private DefaultListSelectionModel colSelectionModel; 31 30 32 31 /** 33 32 * 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 35 34 * {@link #getColSelectionModel()}. 36 * 35 * 37 36 * @param layer the data layer. Must not be null. 38 37 * @exception IllegalArgumentException thrown if layer is null 39 38 */ 40 public RelationMemberEditorModel(OsmDataLayer layer) throws IllegalArgumentException{ 39 public RelationMemberEditorModel(OsmDataLayer layer) throws IllegalArgumentException { 41 40 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 42 41 this.layer = layer; … … 47 46 /** 48 47 * Creates a new model in the context of an {@link OsmDataLayer} 49 * 48 * 50 49 * @param layer layer the data layer. Must not be null. 51 50 * @param rowSelectionModel the row selection model. Must not be null. … … 55 54 * @throws IllegalArgumentException thrown if colSelectionModel is null 56 55 */ 57 public RelationMemberEditorModel(OsmDataLayer layer, DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException{ 56 public RelationMemberEditorModel(OsmDataLayer layer, DefaultListSelectionModel rowSelectionModel, 57 DefaultListSelectionModel colSelectionModel) throws IllegalArgumentException { 58 58 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 59 59 CheckParameterUtil.ensureParameterNotNull(rowSelectionModel, "rowSelectionModel"); … … 66 66 /** 67 67 * Replies the row selection model used in this table model. 68 * 69 * @return the row selection model 68 * 69 * @return the row selection model 70 70 */ 71 71 public DefaultListSelectionModel getRowSelectionModel() { 72 72 return rowSelectionModel; 73 73 } 74 74 75 75 /** 76 76 * Replies the column selection model used in this table model. 77 * 77 * 78 78 * @return the col selection model 79 79 */ … … 81 81 return colSelectionModel; 82 82 } 83 83 84 84 /** 85 85 * Replies the set of {@link OsmPrimitive}s with the role {@code role}. If no 86 86 * such primitives exists, the empty set is returned. 87 * 87 * 88 88 * @return the set of {@link OsmPrimitive}s with the role {@code role} 89 89 */ 90 90 protected Set<OsmPrimitive> getPrimitivesWithRole(String role) { 91 91 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)) { 94 94 OsmPrimitive p = layer.data.getPrimitiveById(rm.getTarget()); 95 if (p != null){ 95 if (p != null) { 96 96 ret.add(p); 97 97 } … … 100 100 return ret; 101 101 } 102 102 103 103 /** 104 104 * Replies the list of {@link RelationMemberModel}s with the role {@code role}. If no 105 105 * such primitives exists, the empty set is returned. 106 * 106 * 107 107 * @return the set of {@link RelationMemberModel}s with the role {@code role} 108 108 */ 109 109 protected List<RelationMemberModel> getRelationMembersWithRole(String role) { 110 110 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)) { 113 113 ret.add(rm); 114 114 } … … 116 116 return ret; 117 117 } 118 118 119 119 /** 120 120 * Removes all members with role {@code role}. 121 * 121 * 122 122 * @param role the role. Ignored if null. 123 123 * @return true if the list of members was modified; false, otherwise 124 124 */ 125 protected boolean removeMembersWithRole(String role){ 125 protected boolean removeMembersWithRole(String role) { 126 126 if (role == null) return false; 127 127 boolean isChanged = false; 128 for(Iterator<RelationMemberModel> it = members.iterator(); it.hasNext(); ){128 for (Iterator<RelationMemberModel> it = members.iterator(); it.hasNext();) { 129 129 RelationMemberModel rm = it.next(); 130 130 if (rm.getRole().equals(role)) { … … 135 135 return isChanged; 136 136 } 137 137 138 138 /** 139 139 * Replies the set of {@link OsmPrimitive}s with the role 'from'. If no 140 140 * such primitives exists, the empty set is returned. 141 * 141 * 142 142 * @return the set of {@link OsmPrimitive}s with the role 'from' 143 143 */ 144 144 public Set<OsmPrimitive> getFromPrimitives() { 145 return getPrimitivesWithRole("from"); 146 } 147 145 return getPrimitivesWithRole("from"); 146 } 147 148 148 /** 149 149 * Replies the set of {@link OsmPrimitive}s with the role 'to'. If no 150 150 * such primitives exists, the empty set is returned. 151 * 151 * 152 152 * @return the set of {@link OsmPrimitive}s with the role 'from' 153 153 */ … … 155 155 return getPrimitivesWithRole("to"); 156 156 } 157 157 158 158 /** 159 159 * Replies the list of 'via' objects in the order they occur in the 160 160 * member list. Replies an empty list if no vias exist 161 *162 * @return163 161 */ 164 162 public List<OsmPrimitive> getVias() { 165 163 ArrayList<OsmPrimitive> ret = new ArrayList<>(); 166 for (RelationMemberModel rm: getRelationMembersWithRole("via")){ 164 for (RelationMemberModel rm: getRelationMembersWithRole("via")) { 167 165 ret.add(layer.data.getPrimitiveById(rm.getTarget())); 168 166 } 169 167 return ret; 170 168 } 171 169 172 170 /** 173 171 * Sets the list of vias. Removes all 'vias' if {@code vias} is null. 174 * 172 * 175 173 * null vias are skipped. A via must belong to the dataset of the layer in whose context 176 174 * this editor is working, otherwise an {@link IllegalArgumentException} is thrown. 177 * 175 * 178 176 * @param vias the vias. 179 177 * @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 { 183 181 boolean viasDeleted = removeMembersWithRole("via"); 184 if (vias == null || vias.isEmpty()){ 185 if (viasDeleted){ 182 if (vias == null || vias.isEmpty()) { 183 if (viasDeleted) { 186 184 fireTableDataChanged(); 187 185 } 188 186 return; 189 187 } 190 // check vias 188 // check vias 191 189 for (OsmPrimitive via: vias) { 192 190 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 198 197 for (OsmPrimitive via: vias) { 199 198 if (via == null) continue; … … 203 202 fireTableDataChanged(); 204 203 } 205 204 206 205 /** 207 206 * Sets the turn restriction member with role {@code role}. Removes all 208 207 * members with role {@code role} if {@code id} is null. 209 * 210 * @param id the id 208 * 209 * @param id the id 211 210 * @return true if the model was modified; false, otherwise 212 211 */ 213 protected boolean setPrimitiveWithRole(PrimitiveId id, String role){ 214 if (id == null){ 212 protected boolean setPrimitiveWithRole(PrimitiveId id, String role) { 213 if (id == null) { 215 214 return removeMembersWithRole(role); 216 215 } 217 216 218 217 List<RelationMemberModel> fromMembers = getRelationMembersWithRole(role); 219 if (fromMembers.isEmpty()){ 218 if (fromMembers.isEmpty()) { 220 219 RelationMemberModel rm = new RelationMemberModel(role, id); 221 220 members.add(rm); 222 221 return true; 223 } else if (fromMembers.size() == 1){ 222 } else if (fromMembers.size() == 1) { 224 223 RelationMemberModel rm = fromMembers.get(0); 225 if (!rm.getTarget().equals(id)){ 224 if (!rm.getTarget().equals(id)) { 226 225 rm.setTarget(id); 227 226 return true; … … 235 234 } 236 235 } 237 236 238 237 /** 239 238 * Sets the turn restriction member with role 'from'. Removes all 240 239 * 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) { 245 244 if (setPrimitiveWithRole(id, "from")) { 246 245 fireTableDataChanged(); 247 246 } 248 247 } 249 248 250 249 /** 251 250 * Sets the turn restriction member with role 'to'. Removes all 252 251 * 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) { 257 256 if (setPrimitiveWithRole(id, "to")) { 258 257 fireTableDataChanged(); 259 258 } 260 259 } 261 260 262 261 /** 263 262 * Replies the set of {@link OsmPrimitive}s referred to by members in 264 263 * this model. 265 * 264 * 266 265 * @return the set of {@link OsmPrimitive}s referred to by members in 267 266 * this model. … … 269 268 public Set<OsmPrimitive> getMemberPrimitives() { 270 269 Set<OsmPrimitive> ret = new HashSet<>(); 271 for (RelationMemberModel rm: members){ 270 for (RelationMemberModel rm: members) { 272 271 OsmPrimitive p = layer.data.getPrimitiveById(rm.getTarget()); 273 272 if (p != null) ret.add(p); … … 275 274 return ret; 276 275 } 277 276 278 277 /** 279 278 * 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 * 282 281 * @param tr the turn restriction 283 282 */ 284 public void populate(Relation tr){ 283 public void populate(Relation tr) { 285 284 members.clear(); 286 if (tr == null){ 285 if (tr == null) { 287 286 fireTableDataChanged(); 288 287 return; 289 288 } 290 for(RelationMember rm: tr.getMembers()){ 289 for (RelationMember rm: tr.getMembers()) { 291 290 members.add(new RelationMemberModel(rm)); 292 291 } 293 292 fireTableDataChanged(); 294 293 } 295 294 296 295 /** 297 296 * Replaces the member of turn restriction {@code tr} by the relation members currently 298 297 * edited in this model. 299 * 298 * 300 299 * @param tr the turn restriction. Ignored if null. 301 300 */ 302 public void applyTo(Relation tr){ 301 public void applyTo(Relation tr) { 303 302 if (tr == null) return; 304 303 List<RelationMember> newMembers = new ArrayList<>(); 305 for(RelationMemberModel model: members){ 304 for (RelationMemberModel model: members) { 306 305 RelationMember rm = new RelationMember(model.getRole(), layer.data.getPrimitiveById(model.getTarget())); 307 306 newMembers.add(rm); … … 309 308 tr.setMembers(newMembers); 310 309 } 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 314 313 * table. 315 314 */ 316 protected void clearSelectedRoles(){ 317 for (int i=0; i < getRowCount();i++){315 protected void clearSelectedRoles() { 316 for (int i = 0; i < getRowCount(); i++) { 318 317 if (rowSelectionModel.isSelectedIndex(i)) { 319 318 members.get(i).setRole(""); 320 319 } 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 326 325 */ 327 326 protected void removedSelectedMembers() { 328 for (int i=getRowCount()-1; i >= 0;i--){327 for (int i = getRowCount()-1; i >= 0; i--) { 329 328 if (rowSelectionModel.isSelectedIndex(i)) { 330 329 members.remove(i); … … 332 331 } 333 332 } 334 333 335 334 /** 336 335 * Deletes the current selection. 337 * 336 * 338 337 * If only cells in the first column are selected, the roles of the selected 339 338 * members are reset to the empty string. Otherwise the selected members are 340 * removed from the model. 341 * 339 * removed from the model. 340 * 342 341 */ 343 342 public void deleteSelected() { 344 343 if (colSelectionModel.isSelectedIndex(0) && !colSelectionModel.isSelectedIndex(1)) { 345 344 clearSelectedRoles(); 346 } else if (rowSelectionModel.getMinSelectionIndex() >= 0){ 345 } else if (rowSelectionModel.getMinSelectionIndex() >= 0) { 347 346 removedSelectedMembers(); 348 347 } 349 348 fireTableDataChanged(); 350 349 } 351 350 352 351 protected List<Integer> getSelectedIndices() { 353 352 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)) 356 355 ret.add(i); 357 356 } 358 357 return ret; 359 358 } 360 359 361 360 public boolean canMoveUp() { 362 361 List<Integer> sel = getSelectedIndices(); … … 364 363 return sel.get(0) > 0; 365 364 } 366 365 367 366 public boolean canMoveDown() { 368 367 List<Integer> sel = getSelectedIndices(); … … 370 369 return sel.get(sel.size()-1) < members.size()-1; 371 370 } 372 371 373 372 public void moveUpSelected() { 374 373 if (!canMoveUp()) return; 375 374 List<Integer> sel = getSelectedIndices(); 376 for (int idx: sel){ 375 for (int idx: sel) { 377 376 RelationMemberModel m = members.remove(idx); 378 377 members.add(idx-1, m); … … 381 380 rowSelectionModel.clearSelection(); 382 381 colSelectionModel.setSelectionInterval(0, 1); 383 for (int idx: sel){ 382 for (int idx: sel) { 384 383 rowSelectionModel.addSelectionInterval(idx-1, idx-1); 385 384 } 386 385 } 387 386 388 387 public void moveDownSelected() { 389 388 if (!canMoveDown()) return; 390 389 List<Integer> sel = getSelectedIndices(); 391 for (int i = sel.size()-1; i >=0;i--){390 for (int i = sel.size()-1; i >= 0; i--) { 392 391 int idx = sel.get(i); 393 392 RelationMemberModel m = members.remove(idx); … … 397 396 rowSelectionModel.clearSelection(); 398 397 colSelectionModel.setSelectionInterval(0, 1); 399 for (int idx: sel){ 398 for (int idx: sel) { 400 399 rowSelectionModel.addSelectionInterval(idx+1, idx+1); 401 400 } 402 401 } 403 402 404 403 /** 405 404 * <p>Inserts a list of new relation members with the empty role for the primitives 406 405 * with id in {@code ids}. Inserts the new primitives at the position of the first 407 406 * 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 410 409 * layer, if the primitive is deleted or invisible, an {@link IllegalArgumentException} 411 410 * is thrown and nothing is inserted.</p> 412 * 411 * 413 412 * @param ids the list of ids. Ignored if null. 414 413 * @throws IllegalArgumentException thrown if one of the ids can't be inserted 415 414 */ 416 415 public void insertMembers(Collection<PrimitiveId> ids) throws IllegalArgumentException { 417 if (ids == null) return; 416 if (ids == null) return; 418 417 ArrayList<RelationMemberModel> newMembers = new ArrayList<>(); 419 for (PrimitiveId id: ids){ 418 for (PrimitiveId id: ids) { 420 419 OsmPrimitive p = layer.data.getPrimitiveById(id); 421 if (p == null){ 420 if (p == null) { 422 421 throw new IllegalArgumentException(tr("Cannot find object with id ''{0}'' in layer ''{1}''", id.toString(), layer.getName())); 423 422 } 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)); 428 429 } 429 430 if (newMembers.isEmpty()) return; 430 431 int insertPos = rowSelectionModel.getMinSelectionIndex(); 431 if ( 0){432 if (insertPos >= 0) { 432 433 members.addAll(insertPos, newMembers); 433 434 } else { … … 435 436 } 436 437 fireTableDataChanged(); 437 if (insertPos < 0) insertPos = 0; 438 if (insertPos < 0) insertPos = 0; 438 439 colSelectionModel.setSelectionInterval(0, 1); // select both columns 439 440 rowSelectionModel.setSelectionInterval(insertPos, insertPos + newMembers.size()-1); 440 441 } 441 442 443 @Override 442 444 public int getColumnCount() { 443 445 return 2; 444 446 } 445 447 448 @Override 446 449 public int getRowCount() { 447 450 return members.size(); 448 451 } 449 452 453 @Override 450 454 public Object getValueAt(int rowIndex, int columnIndex) { 451 switch(columnIndex){ 455 switch(columnIndex) { 452 456 case 0: return members.get(rowIndex).getRole(); 453 457 case 1: return layer.data.getPrimitiveById(members.get(rowIndex).getTarget()); … … 464 468 @Override 465 469 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; 468 472 RelationMemberModel model = members.get(rowIndex); 469 473 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 15 16 * 16 17 */ 17 public class RelationMemberModel implements Serializable{ 18 public class RelationMemberModel implements Serializable { 18 19 private String role; 19 20 private SimplePrimitiveId target; 20 21 21 22 /** 22 23 * Creates a new relation member model 23 * 24 * 24 25 * @param role the member role. Reset to "" if null. 25 26 * @param target the id of the target object. Must not be null. … … 28 29 public RelationMemberModel(String role, PrimitiveId target) throws IllegalArgumentException { 29 30 CheckParameterUtil.ensureParameterNotNull(target, "target"); 30 this.role = role == null? "" : role; 31 this.role = role == null ? "" : role; 31 32 this.target = new SimplePrimitiveId(target.getUniqueId(), target.getType()); 32 33 } 33 34 34 35 /** 35 * Creates a new relation member model from a relation member 36 * 36 * Creates a new relation member model from a relation member 37 * 37 38 * @param member the relation member. Must not be null. 38 39 * @throws IllegalArgumentException thrown if {@code member} is null 39 40 */ 40 public RelationMemberModel(RelationMember member) throws IllegalArgumentException{ 41 public RelationMemberModel(RelationMember member) throws IllegalArgumentException { 41 42 CheckParameterUtil.ensureParameterNotNull(member, "member"); 42 43 this.role = member.getRole(); … … 46 47 /** 47 48 * Replies the current role in this model. Never null. 48 * 49 * 49 50 * @return the current role in this model 50 51 */ … … 54 55 55 56 /** 56 * Sets the current role in this model. 57 * 57 * Sets the current role in this model. 58 * 58 59 * @param role the role. Reset to "" if null. 59 60 */ 60 61 public void setRole(String role) { 61 this.role = role == null? "" : role; 62 this.role = role == null ? "" : role; 62 63 } 63 64 64 65 /** 65 66 * Replies the id of the target object of this relation member. 66 * 67 * 67 68 * @return the id of the target object of this relation member. 68 69 */ … … 72 73 73 74 /** 74 * Sets the id of the target object. 75 * 75 * Sets the id of the target object. 76 * 76 77 * @param target the id of the target object. Must not be null. 77 78 * @throws IllegalArgumentException thrown if {@code target} is null 78 79 */ 79 public void setTarget(PrimitiveId target) throws IllegalArgumentException{ 80 public void setTarget(PrimitiveId target) throws IllegalArgumentException { 80 81 CheckParameterUtil.ensureParameterNotNull(target, "target"); 81 82 this.target = new SimplePrimitiveId(target.getUniqueId(), target.getType()); 82 83 } 83 84 84 85 @Override 85 86 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 74 75 actDelete = new DeleteAction(); 75 76 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); 77 78 78 79 // initialize the paste action (will be used in the popup, the action map already includes … … 82 83 actMoveUp = new MoveUpAction(); 83 84 model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actMoveUp); 84 registerKeyboardAction(actMoveUp,actMoveUp.getKeyStroke(), WHEN_FOCUSED); 85 registerKeyboardAction(actMoveUp, actMoveUp.getKeyStroke(), WHEN_FOCUSED); 85 86 86 87 actMoveDown = new MoveDownAction(); … … 93 94 * 94 95 */ 95 class DeleteAction extends AbstractAction implements ListSelectionListener{ 96 publicDeleteAction() {96 class DeleteAction extends AbstractAction implements ListSelectionListener { 97 DeleteAction() { 97 98 putValue(NAME, tr("Delete")); 98 99 putValue(SHORT_DESCRIPTION, tr("Clear the selected roles or delete the selected members")); 99 100 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)); 101 102 updateEnabledState(); 102 103 } 103 104 104 105 public void updateEnabledState() { 105 setEnabled(model.getRelationMemberEditorModel().getRowSelectionModel().getMinSelectionIndex()>=0); 106 } 107 106 setEnabled(model.getRelationMemberEditorModel().getRowSelectionModel().getMinSelectionIndex() >= 0); 107 } 108 109 @Override 108 110 public void actionPerformed(ActionEvent e) { 109 111 model.getRelationMemberEditorModel().deleteSelected(); 110 112 } 111 113 114 @Override 112 115 public void valueChanged(ListSelectionEvent e) { 113 116 updateEnabledState(); … … 119 122 * 120 123 */ 121 class PasteAction extends AbstractAction{ 122 publicPasteAction() {124 class PasteAction extends AbstractAction { 125 PasteAction() { 123 126 putValue(NAME, tr("Paste")); 124 127 putValue(SHORT_DESCRIPTION, tr("Insert new relation members from object in the clipboard")); … … 133 136 } 134 137 138 @Override 135 139 @SuppressWarnings("unchecked") 136 140 public void actionPerformed(ActionEvent evt) { … … 143 147 try { 144 148 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); 146 150 try { 147 151 model.getRelationMemberEditorModel().insertMembers(ids); 148 } catch(IllegalArgumentException e){ 152 } catch (IllegalArgumentException e) { 149 153 e.printStackTrace(); 150 154 // FIXME: provide user feedback 151 155 } 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 { 161 165 private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK); 162 publicMoveDownAction(){166 MoveDownAction() { 163 167 putValue(NAME, tr("Move down")); 164 168 putValue(SHORT_DESCRIPTION, tr("Move the selected relation members down by one position")); 165 putValue(ACCELERATOR_KEY,keyStroke); 169 putValue(ACCELERATOR_KEY, keyStroke); 166 170 new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this); 167 171 updateEnabledState(); 168 172 } 169 173 174 @Override 170 175 public void actionPerformed(ActionEvent e) { 171 176 model.getRelationMemberEditorModel().moveDownSelected(); 172 177 } 173 178 174 public void updateEnabledState(){ 179 public void updateEnabledState() { 175 180 setEnabled(model.getRelationMemberEditorModel().canMoveDown()); 176 181 } 177 182 183 @Override 178 184 public void valueChanged(ListSelectionEvent e) { 179 185 updateEnabledState(); 180 186 } 181 public KeyStroke getKeyStroke() { 187 188 KeyStroke getKeyStroke() { 182 189 return keyStroke; 183 190 } 184 191 } 185 192 186 class MoveUpAction extends AbstractAction implements ListSelectionListener{ 193 class MoveUpAction extends AbstractAction implements ListSelectionListener { 187 194 private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK); 188 195 189 publicMoveUpAction() {196 MoveUpAction() { 190 197 putValue(NAME, tr("Move up")); 191 198 putValue(SHORT_DESCRIPTION, tr("Move the selected relation members up by one position")); 192 putValue(ACCELERATOR_KEY,keyStroke); 199 putValue(ACCELERATOR_KEY, keyStroke); 193 200 new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this); 194 201 updateEnabledState(); 195 202 } 196 203 204 @Override 197 205 public void actionPerformed(ActionEvent e) { 198 206 model.getRelationMemberEditorModel().moveUpSelected(); 199 207 } 200 208 201 public void updateEnabledState(){ 209 public void updateEnabledState() { 202 210 setEnabled(model.getRelationMemberEditorModel().canMoveUp()); 203 211 } 204 212 213 @Override 205 214 public void valueChanged(ListSelectionEvent e) { 206 215 updateEnabledState(); 207 216 } 208 public KeyStroke getKeyStroke() { 217 218 KeyStroke getKeyStroke() { 209 219 return keyStroke; 210 220 } … … 215 225 public void launch(MouseEvent evt) { 216 226 int row = rowAtPoint(evt.getPoint()); 217 if (getSelectionModel().getMinSelectionIndex() < 0 && row >= 0){227 if (getSelectionModel().getMinSelectionIndex() < 0 && row >= 0) { 218 228 getSelectionModel().setSelectionInterval(row, row); 219 229 getColumnModel().getSelectionModel().setSelectionInterval(0, 1); … … 224 234 225 235 class PopupMenu extends JPopupMenu { 226 publicPopupMenu() {236 PopupMenu() { 227 237 JMenuItem item = add(actPaste); 228 238 item.setTransferHandler(transferHandler); … … 252 262 try { 253 263 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); 255 265 try { 256 266 model.getRelationMemberEditorModel().insertMembers(ids); 257 } catch(IllegalArgumentException e){ 267 } catch (IllegalArgumentException e) { 258 268 e.printStackTrace(); 259 269 // FIXME: provide user feedback … … 261 271 } 262 272 return true; 263 } catch(IOException e){ 264 e.printStackTrace(); 265 } catch(UnsupportedFlavorException e){ 273 } catch (IOException e) { 274 e.printStackTrace(); 275 } catch (UnsupportedFlavorException e) { 266 276 e.printStackTrace(); 267 277 } … … 271 281 @Override 272 282 public int getSourceActions(JComponent c) { 273 return 283 return COPY_OR_MOVE; 274 284 } 275 285 } … … 280 290 * 281 291 */ 282 class RelationMemberTableDropTarget extends DropTarget{ 292 class RelationMemberTableDropTarget extends DropTarget { 283 293 private boolean dropAccepted = false; 284 294 … … 287 297 288 298 * @param transferFlavors an array of transferFlavors 289 * @return290 299 */ 291 300 protected boolean isSupportedFlavor(DataFlavor[] transferFlavors) { … … 296 305 } 297 306 307 @Override 298 308 public synchronized void dragEnter(DropTargetDragEvent dtde) { 299 309 if (isSupportedFlavor(dtde.getCurrentDataFlavors())) { 300 if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) != 0){ 310 if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) { 301 311 dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); 302 312 setColumnSelectionAllowed(false); 303 dropAccepted 313 dropAccepted = true; 304 314 } else { 305 315 dtde.rejectDrag(); … … 310 320 } 311 321 322 @Override 312 323 public synchronized void dragExit(DropTargetEvent dte) { 313 324 setColumnSelectionAllowed(true); … … 319 330 int row = rowAtPoint(dtde.getLocation()); 320 331 int selectedRow = getSelectionModel().getMinSelectionIndex(); 321 if (row >= 0 && row != selectedRow){ 332 if (row >= 0 && row != selectedRow) { 322 333 getSelectionModel().setSelectionInterval(row, row); 323 334 } 324 335 } 325 336 337 @Override 326 338 @SuppressWarnings("unchecked") 327 339 public synchronized void drop(DropTargetDropEvent dtde) { … … 332 344 } 333 345 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); 335 347 try { 336 348 model.getRelationMemberEditorModel().insertMembers(ids); 337 } catch(IllegalArgumentException e){ 349 } catch (IllegalArgumentException e) { 338 350 e.printStackTrace(); 339 351 // FIXME: provide user feedback 340 352 } 341 } catch(IOException e){ 342 e.printStackTrace(); 343 } catch(UnsupportedFlavorException e){ 353 } catch (IOException e) { 354 e.printStackTrace(); 355 } catch (UnsupportedFlavorException e) { 344 356 e.printStackTrace(); 345 357 } finally { … … 348 360 } 349 361 362 @Override 350 363 public synchronized void dropActionChanged(DropTargetDragEvent dtde) { 351 364 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 9 10 */ 10 11 public class TurnRestrictionComboBox extends JComboBox<Object> { 11 12 12 13 /** 13 * Constructor 14 * 14 * Constructor 15 * 15 16 * @param model the combo box model. Must not be null. 16 17 */ 17 public TurnRestrictionComboBox(TurnRestrictionComboBoxModel model){ 18 public TurnRestrictionComboBox(TurnRestrictionComboBoxModel model) { 18 19 super(model); 19 20 setEditable(false); 20 21 setRenderer(new TurnRestrictionTypeRenderer()); 21 22 } 22 23 23 24 /** 24 * Replies the turn restriction combo box model 25 * 25 * Replies the turn restriction combo box model 26 * 26 27 * @return the turn restriction combo box model 27 28 */ 28 29 public TurnRestrictionComboBoxModel getTurnRestrictionComboBoxModel() { 29 return (TurnRestrictionComboBoxModel)getModel(); 30 return (TurnRestrictionComboBoxModel) getModel(); 30 31 } 31 32 32 33 /** 33 34 * Initializes the set of icons used from the preference key 34 35 * {@link PreferenceKeys#ROAD_SIGNS}. 35 * 36 * @param prefs the JOSM preferences 36 * 37 * @param prefs the JOSM preferences 37 38 */ 38 public void initIconSetFromPreferences(Preferences prefs){ 39 TurnRestrictionTypeRenderer renderer = (TurnRestrictionTypeRenderer)getRenderer(); 39 public void initIconSetFromPreferences(Preferences prefs) { 40 TurnRestrictionTypeRenderer renderer = (TurnRestrictionTypeRenderer) getRenderer(); 40 41 renderer.initIconSetFromPreferences(prefs); 41 42 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 16 17 * This is a model for a combo box to select a turn restriction type. The 17 18 * 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. 19 20 * 20 21 */ 21 public class TurnRestrictionComboBoxModel implements ComboBoxModel<Object>, Observer{ 22 //static private final Logger logger = Logger.getLogger(TurnRestrictionComboBoxModel.class.getName()); 23 22 public class TurnRestrictionComboBoxModel implements ComboBoxModel<Object>, Observer { 23 24 24 private TurnRestrictionEditorModel model; 25 finalprivate List<Object> values = new ArrayList<>();25 private final List<Object> values = new ArrayList<>(); 26 26 private String selectedTagValue = null; 27 27 private final transient EventListenerList listeners = new EventListenerList(); 28 28 29 29 /** 30 30 * Populates the model with the list of standard values. If the 31 31 * data contains a non-standard value it is displayed in the combo 32 * box as an additional element. 32 * box as an additional element. 33 33 */ 34 34 protected void populate() { … … 36 36 for (TurnRestrictionType type: TurnRestrictionType.values()) { 37 37 values.add(type); 38 } 39 38 } 39 40 40 String tagValue = model.getRestrictionTagValue(); 41 41 if (tagValue.trim().equals("")) { … … 52 52 fireContentsChanged(); 53 53 } 54 54 55 55 /** 56 * Creates the combo box model. 57 * 56 * Creates the combo box model. 57 * 58 58 * @param model the turn restriction editor model. Must not be null. 59 59 */ 60 public TurnRestrictionComboBoxModel(TurnRestrictionEditorModel model){ 60 public TurnRestrictionComboBoxModel(TurnRestrictionEditorModel model) { 61 61 CheckParameterUtil.ensureParameterNotNull(model, "model"); 62 62 this.model = model; … … 65 65 } 66 66 67 @Override 67 68 public Object getSelectedItem() { 68 69 TurnRestrictionType type = TurnRestrictionType.fromTagValue(selectedTagValue); … … 71 72 } 72 73 74 @Override 73 75 public void setSelectedItem(Object anItem) { 74 76 String tagValue = null; 75 77 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(); 79 81 } 80 82 model.setRestrictionTagValue(tagValue); 81 83 } 82 84 85 @Override 83 86 public Object getElementAt(int index) { 84 87 return values.get(index); 85 88 } 86 89 90 @Override 87 91 public int getSize() { 88 92 return values.size(); 89 93 } 90 94 95 @Override 91 96 public void addListDataListener(ListDataListener l) { 92 listeners.add(ListDataListener.class, l); 97 listeners.add(ListDataListener.class, l); 93 98 } 94 99 100 @Override 95 101 public void removeListDataListener(ListDataListener l) { 96 listeners.remove(ListDataListener.class, l); 102 listeners.remove(ListDataListener.class, l); 97 103 } 98 104 99 105 protected void fireContentsChanged() { 100 for(ListDataListener l: listeners.getListeners(ListDataListener.class)) { 106 for (ListDataListener l: listeners.getListeners(ListDataListener.class)) { 101 107 l.contentsChanged(new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, getSize())); 102 108 } 103 109 } 104 110 105 111 /* ------------------------------------------------------------------------------------ */ 106 112 /* interface Observer */ 107 113 /* ------------------------------------------------------------------------------------ */ 108 public void update(Observable o, Object arg) { 114 @Override 115 public void update(Observable o, Object arg) { 109 116 String tagValue = model.getRestrictionTagValue(); 110 117 if (tagValue == null && selectedTagValue != null) { 111 118 populate(); 112 } else if (tagValue != null && selectedTagValue == null){ 119 } else if (tagValue != null && selectedTagValue == null) { 113 120 populate(); 114 121 } else if (tagValue != null) { … … 116 123 populate(); 117 124 } 118 } 125 } 119 126 } 120 127 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r32386 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 56 57 import org.openstreetmap.josm.tools.ImageProvider; 57 58 58 public class TurnRestrictionEditor extends JDialog implements NavigationControler{ 59 //final private static Logger logger = Logger.getLogger(TurnRestrictionEditor.class.getName()); 59 public class TurnRestrictionEditor extends JDialog implements NavigationControler { 60 60 61 61 /** the property name for the current turn restriction … … 63 63 * @link #getRelation() 64 64 */ 65 static public final String TURN_RESTRICION_PROP = RelationEditor.class.getName() + ".turnRestriction";65 public static final String TURN_RESTRICION_PROP = RelationEditor.class.getName() + ".turnRestriction"; 66 66 67 67 /** the property name for the current relation snapshot 68 68 * @link #getRelationSnapshot() 69 69 */ 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"; 71 71 72 72 /** … … 111 111 /** 112 112 * builds the panel which displays the JOSM selection 113 * @return114 113 */ 115 114 protected JPanel buildJOSMSelectionPanel() { 116 pnlJosmSelection = new JosmSelectionPanel(layer,editorModel.getJosmSelectionListModel()); 115 pnlJosmSelection = new JosmSelectionPanel(layer, editorModel.getJosmSelectionListModel()); 117 116 return pnlJosmSelection; 118 117 } … … 121 120 * Builds the panel with the editor forms (the left panel in the split pane of 122 121 * this dialog) 123 *124 * @return125 122 */ 126 123 protected JPanel buildEditorPanel() { 127 124 JPanel pnl = new JPanel(new BorderLayout()); 128 125 tpEditors = new JTabbedPane(); 129 JScrollPane pane = new JScrollPane(pnlBasicEditor =new BasicEditorPanel(editorModel)); 126 JScrollPane pane = new JScrollPane(pnlBasicEditor = new BasicEditorPanel(editorModel)); 130 127 pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 131 128 pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); … … 149 146 * Builds the content panel, i.e. the core area of the dialog with the editor 150 147 * masks and the JOSM selection view 151 *152 * @return153 148 */ 154 149 protected JPanel buildContentPanel() { … … 176 171 */ 177 172 protected JToolBar buildToolBar() { 178 JToolBar tb 173 JToolBar tb = new JToolBar(); 179 174 tb.setFloatable(false); 180 175 tb.add(new ApplyAction()); … … 206 201 207 202 editorModel.getIssuesModel().addObserver(new IssuesModelObserver()); 208 setSize(600,600); 203 setSize(600, 600); 209 204 } 210 205 … … 228 223 * @throws IllegalArgumentException thrown if layer is null 229 224 */ 230 public TurnRestrictionEditor(Component owner, OsmDataLayer layer, Relation turnRestriction) 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 */); 232 227 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 233 228 this.layer = layer; … … 324 319 */ 325 320 protected boolean isDirtyTurnRestriction() { 326 return ! 321 return !turnRestriction.hasEqualSemanticAttributes(turnRestrictionSnapshot); 327 322 } 328 323 … … 336 331 @Override 337 332 public void setVisible(boolean visible) { 338 if (visible && ! 333 if (visible && !isVisible()) { 339 334 pnlJosmSelection.wireListeners(); 340 335 editorModel.registerAsEventListener(); … … 347 342 } 348 343 super.setVisible(visible); 349 if (!visible){ 344 if (!visible) { 350 345 dispose(); 351 346 } … … 355 350 /* property change support */ 356 351 /* ----------------------------------------------------------------------- */ 357 finalprivate PropertyChangeSupport support = new PropertyChangeSupport(this);352 private final PropertyChangeSupport support = new PropertyChangeSupport(this); 358 353 359 354 @Override … … 383 378 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 384 379 tpEditors.setSelectedIndex(0); 385 pnlBasicEditor.requestFocus For(focusTarget);380 pnlBasicEditor.requestFocusfor(focusTarget); 386 381 } 387 382 … … 391 386 */ 392 387 abstract class SavingAction extends AbstractAction { 393 protected boolean confirmSaveDespiteOfErrorsAndWarnings(){ 388 protected boolean confirmSaveDespiteOfErrorsAndWarnings() { 394 389 int numErrors = editorModel.getIssuesModel().getNumErrors(); 395 390 int numWarnings = editorModel.getIssuesModel().getNumWarnings(); … … 446 441 protected List<RelationMember> getDeletedRelationMembers(Relation r) { 447 442 List<RelationMember> ret = new ArrayList<>(); 448 for(RelationMember rm: r.getMembers()) { 443 for (RelationMember rm: r.getMembers()) { 449 444 if (rm.getMember().isDeleted() || !rm.getMember().isVisible()) { 450 445 ret.add(rm); … … 462 457 protected void removeDeletedMembers(Relation tr) { 463 458 List<RelationMember> members = tr.getMembers(); 464 for(Iterator<RelationMember> it = members.iterator(); it.hasNext();) { 459 for (Iterator<RelationMember> it = members.iterator(); it.hasNext();) { 465 460 RelationMember rm = it.next(); 466 461 if (rm.getMember().isDeleted() || !rm.getMember().isVisible()) { … … 490 485 + "of this turn restriction editor:", deletedMembers.size(), deletedMembers.size())); 491 486 sb.append("<ul>"); 492 for(RelationMember rm: deletedMembers){ 487 for (RelationMember rm: deletedMembers) { 493 488 sb.append("<li>"); 494 489 if (!rm.getRole().equals("")) { … … 550 545 } 551 546 552 Main.main.undoRedo.add(new AddCommand(getLayer(),newTurnRestriction)); 547 Main.main.undoRedo.add(new AddCommand(getLayer(), newTurnRestriction)); 553 548 554 549 // make sure everybody is notified about the changes … … 572 567 editorModel.apply(toUpdate); 573 568 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)); 575 570 } 576 571 … … 594 589 595 590 protected boolean confirmClosingBecauseOfDirtyState() { 596 ButtonSpec 591 ButtonSpec[] options = new ButtonSpec[] { 597 592 new ButtonSpec( 598 593 tr("Yes, create a conflict and close"), 599 594 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"), 601 596 null /* no specific help topic */ 602 597 ), … … 604 599 tr("No, continue editing"), 605 600 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"), 607 602 null /* no specific help topic */ 608 603 ) … … 641 636 642 637 class ApplyAction extends SavingAction { 643 publicApplyAction() {638 ApplyAction() { 644 639 putValue(SHORT_DESCRIPTION, tr("Apply the current updates")); 645 640 new ImageProvider("save").getResource().attachImageIcon(this); … … 649 644 650 645 public void run() { 651 if (!confirmSaveDespiteOfErrorsAndWarnings()){ 646 if (!confirmSaveDespiteOfErrorsAndWarnings()) { 652 647 tpEditors.setSelectedIndex(2); // show the errors and warnings 653 648 return; … … 685 680 686 681 class OKAction extends SavingAction { 687 publicOKAction() {682 OKAction() { 688 683 putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog")); 689 684 new ImageProvider("ok").getResource().attachImageIcon(this); … … 693 688 694 689 public void run() { 695 if (!confirmSaveDespiteOfErrorsAndWarnings()){ 690 if (!confirmSaveDespiteOfErrorsAndWarnings()) { 696 691 tpEditors.setSelectedIndex(2); // show the errors and warnings 697 692 return; … … 707 702 Relation toUpdate = new Relation(getTurnRestriction()); 708 703 editorModel.apply(toUpdate); 709 if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction())){ 704 if (TurnRestrictionEditorModel.hasSameMembersAndTags(toUpdate, getTurnRestriction())) { 710 705 // nothing to update 711 706 setVisible(false); … … 740 735 */ 741 736 class CancelAction extends AbstractAction { 742 publicCancelAction() {737 CancelAction() { 743 738 putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog")); 744 739 new ImageProvider("cancel").getResource().attachImageIcon(this); 745 740 putValue(NAME, tr("Cancel")); 746 741 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); 748 744 setEnabled(true); 749 745 } … … 755 751 } 756 752 757 class DeleteAction extends AbstractAction implements PropertyChangeListener{ 758 publicDeleteAction() {753 class DeleteAction extends AbstractAction implements PropertyChangeListener { 754 DeleteAction() { 759 755 putValue(NAME, tr("Delete")); 760 756 putValue(SHORT_DESCRIPTION, tr("Delete this turn restriction")); … … 781 777 @Override 782 778 public void propertyChange(PropertyChangeEvent evt) { 783 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ 779 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)) { 784 780 updateEnabledState(); 785 781 } … … 787 783 } 788 784 789 class SelectAction extends AbstractAction implements PropertyChangeListener{ 790 publicSelectAction() {785 class SelectAction extends AbstractAction implements PropertyChangeListener { 786 SelectAction() { 791 787 putValue(NAME, tr("Select")); 792 788 putValue(SHORT_DESCRIPTION, tr("Select this turn restriction")); … … 809 805 @Override 810 806 public void propertyChange(PropertyChangeEvent evt) { 811 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ 807 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)) { 812 808 updateEnabledState(); 813 809 } … … 815 811 } 816 812 817 class ZoomToAction extends AbstractAction implements PropertyChangeListener{ 818 publicZoomToAction() {813 class ZoomToAction extends AbstractAction implements PropertyChangeListener { 814 ZoomToAction() { 819 815 putValue(NAME, tr("Zoom to")); 820 816 putValue(SHORT_DESCRIPTION, tr("Activate the layer this turn restriction belongs to and zoom to it")); … … 830 826 @Override 831 827 public void actionPerformed(ActionEvent e) { 832 if (Main.getLayerManager().getActiveLayer() != getLayer()){ 828 if (Main.getLayerManager().getActiveLayer() != getLayer()) { 833 829 Main.getLayerManager().setActiveLayer(getLayer()); 834 830 } … … 841 837 @Override 842 838 public void propertyChange(PropertyChangeEvent evt) { 843 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)){ 839 if (evt.getPropertyName().equals(TURN_RESTRICION_PROP)) { 844 840 updateEnabledState(); 845 841 } … … 853 849 int numErrors = editorModel.getIssuesModel().getNumErrors(); 854 850 String warningText = null; 855 if (numWarnings > 0){ 851 if (numWarnings > 0) { 856 852 warningText = trn("{0} warning", "{0} warnings", numWarnings, numWarnings); 857 853 } 858 854 String errorText = null; 859 if (numErrors > 0){ 855 if (numErrors > 0) { 860 856 errorText = trn("{0} error", "{0} errors", numErrors, numErrors); 861 857 } … … 864 860 title += errorText; 865 861 } 866 if (warningText != null){ 867 if (title.length() > 0){ 862 if (warningText != null) { 863 if (title.length() > 0) { 868 864 title += "/"; 869 865 } 870 866 title += warningText; 871 867 } 872 if (title.length() == 0){ 868 if (title.length() == 0) { 873 869 title = tr("no issues"); 874 870 } … … 894 890 @Override 895 891 public void preferenceChanged(PreferenceChangeEvent evt) { 896 if (evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)){ 892 if (evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)) { 897 893 refreshIconSet(); 898 894 } 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 26 26 */ 27 27 public class TurnRestrictionEditorManager extends WindowAdapter implements LayerChangeListener { 28 // staticprivate final Logger logger = Logger.getLogger(TurnRestrictionEditorManager.class.getName());28 //private static final Logger logger = Logger.getLogger(TurnRestrictionEditorManager.class.getName()); 29 29 30 30 /** keeps track of open relation editors */ … … 36 36 * @return the singleton {@link TurnRestrictionEditorManager} 37 37 */ 38 static public TurnRestrictionEditorManager getInstance() {38 public static TurnRestrictionEditorManager getInstance() { 39 39 if (TurnRestrictionEditorManager.instance == null) { 40 40 TurnRestrictionEditorManager.instance = new TurnRestrictionEditorManager(); … … 48 48 * restriction editor is open for turn restriction in a {@link OsmDataLayer} 49 49 */ 50 staticprivate class DialogContext {50 private static class DialogContext { 51 51 public final PrimitiveId primitiveId; 52 52 public final OsmDataLayer layer; 53 53 54 publicDialogContext(OsmDataLayer layer, PrimitiveId id) {54 DialogContext(OsmDataLayer layer, PrimitiveId id) { 55 55 this.layer = layer; 56 56 this.primitiveId = id; … … 101 101 102 102 /** the map of open dialogs */ 103 private final HashMap<DialogContext, TurnRestrictionEditor> openDialogs = 103 private final HashMap<DialogContext, TurnRestrictionEditor> openDialogs = new HashMap<>(); 104 104 105 105 /** 106 106 * constructor 107 107 */ 108 public TurnRestrictionEditorManager(){} 108 public TurnRestrictionEditorManager() {} 109 109 110 110 /** … … 190 190 @Override 191 191 public void windowClosed(WindowEvent e) { 192 TurnRestrictionEditor editor = (TurnRestrictionEditor)e.getWindow(); 192 TurnRestrictionEditor editor = (TurnRestrictionEditor) e.getWindow(); 193 193 DialogContext context = null; 194 194 for (DialogContext c : openDialogs.keySet()) { … … 209 209 */ 210 210 protected void centerOnScreen(TurnRestrictionEditor editor) { 211 Point p = new Point(0,0); 211 Point p = new Point(0, 0); 212 212 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 213 213 p.x = (d.width - editor.getSize().width)/2; 214 214 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); 217 217 editor.setLocation(p); 218 218 } … … 239 239 * Positions a {@link TurnRestrictionEditor} close to the center of the screen, in such 240 240 * a way, that it doesn't entirely cover another {@link TurnRestrictionEditor} 241 *242 * @param editor243 241 */ 244 242 protected void positionCloseToScreenCenter(TurnRestrictionEditor editor) { 245 Point p = new Point(0,0); 243 Point p = new Point(0, 0); 246 244 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 247 245 p.x = (d.width - editor.getSize().width)/2; 248 246 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)) { 252 250 p.x += 20; 253 251 p.y += 20; … … 280 278 public void layerRemoving(LayerRemoveEvent e) { 281 279 Layer oldLayer = e.getRemovedLayer(); 282 if (oldLayer == null || ! 280 if (oldLayer == null || !(oldLayer instanceof OsmDataLayer)) 283 281 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(); 289 287 if (entry.getKey().matchesLayer(dataLayer)) { 290 288 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 35 36 /** 36 37 * 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 * 39 40 */ 40 public class TurnRestrictionEditorModel extends Observable implements DataSetListener{ 41 //static private final Logger logger = Logger.getLogger(TurnRestrictionEditorModel.class.getName()); 42 41 public class TurnRestrictionEditorModel extends Observable implements DataSetListener { 42 43 43 /** 44 44 * 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. 48 48 * @param tp2 a turn restriction . Must not be null. 49 49 * @return true if {@code tp1} and {@code tp2} have the same tags and … … 52 52 * @throws IllegalArgumentException thrown if {@code tp2} is null 53 53 */ 54 static public boolean hasSameMembersAndTags(Relation tp1, Relation tp2) throws IllegalArgumentException {54 public static boolean hasSameMembersAndTags(Relation tp1, Relation tp2) throws IllegalArgumentException { 55 55 CheckParameterUtil.ensureParameterNotNull(tp1, "tp1"); 56 56 CheckParameterUtil.ensureParameterNotNull(tp2, "tp2"); 57 57 if (!TagCollection.from(tp1).asSet().equals(TagCollection.from(tp2).asSet())) return false; 58 58 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++) { 60 60 if (!tp1.getMember(i).equals(tp2.getMember(i))) return false; 61 61 } 62 62 return true; 63 63 } 64 64 65 65 private OsmDataLayer layer; 66 66 private final TagEditorModel tagEditorModel = new TagEditorModel(); 67 private 68 private 67 private RelationMemberEditorModel memberModel; 68 private IssuesModel issuesModel; 69 69 private NavigationControler navigationControler; 70 70 private JosmSelectionListModel selectionModel; 71 71 72 72 /** 73 73 * Creates a model in the context of a {@link OsmDataLayer} 74 * 74 * 75 75 * @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 77 77 * @throws IllegalArgumentException thrown if {@code layer} is null 78 78 */ 79 public TurnRestrictionEditorModel(OsmDataLayer layer, NavigationControler navigationControler) throws IllegalArgumentException{ 79 public TurnRestrictionEditorModel(OsmDataLayer layer, NavigationControler navigationControler) throws IllegalArgumentException { 80 80 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 81 81 CheckParameterUtil.ensureParameterNotNull(navigationControler, "navigationControler"); … … 89 89 selectionModel = new JosmSelectionListModel(layer); 90 90 } 91 91 92 92 /** 93 93 * Replies the model for the currently selected JOSM primitives … … 96 96 return selectionModel; 97 97 } 98 98 99 99 /** 100 100 * 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. 103 103 * @param way the way which participates in the turn restriction in the respective role. 104 104 * null, to remove the way with the given role. 105 105 * @exception IllegalArgumentException thrown if role is null 106 106 */ 107 public void setTurnRestrictionLeg(TurnRestrictionLegRole role, Way way) throws IllegalArgumentException{ 107 public void setTurnRestrictionLeg(TurnRestrictionLegRole role, Way way) throws IllegalArgumentException { 108 108 CheckParameterUtil.ensureParameterNotNull(role, "role"); 109 switch(role){ 109 switch(role) { 110 110 case FROM: 111 111 memberModel.setFromPrimitive(way); … … 115 115 break; 116 116 } 117 } 118 117 } 118 119 119 /** 120 120 * 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. 123 123 * @param wayId the id of the way to set 124 124 * @exception IllegalArgumentException thrown if role is null 125 125 * @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 127 127 */ 128 128 public void setTurnRestrictionLeg(TurnRestrictionLegRole role, PrimitiveId wayId) { 129 129 CheckParameterUtil.ensureParameterNotNull(role, "role"); 130 130 if (wayId == null) { 131 setTurnRestrictionLeg(role, (Way)null); 131 setTurnRestrictionLeg(role, (Way) null); 132 132 return; 133 133 } 134 134 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())); 136 137 } 137 138 138 139 OsmPrimitive p = layer.data.getPrimitiveById(wayId); 139 140 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 147 148 * role {@link TurnRestrictionLegRole#FROM FROM} and one member with role {@link TurnRestrictionLegRole#TO TO}, 148 149 * both referring to an OSM {@link Way}. In order to deals with turn restrictions where these 149 150 * integrity constraints are violated, this model also supports relation with multiple or no 150 151 * 'from' or 'to' members.</p> 151 * 152 * 152 153 * <p>Replies the turn restriction legs with role {@code role}. If no leg with this 153 154 * 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 * 156 157 * @param role the role. Must not be null. 157 158 * @return the set of turn restriction legs with role {@code role}. The empty set, if … … 159 160 * @throws IllegalArgumentException thrown if role is null 160 161 */ 161 public Set<OsmPrimitive>getTurnRestrictionLeg(TurnRestrictionLegRole role){ 162 public Set<OsmPrimitive> getTurnRestrictionLeg(TurnRestrictionLegRole role) { 162 163 CheckParameterUtil.ensureParameterNotNull(role, "role"); 163 switch(role){ 164 switch(role) { 164 165 case FROM: return memberModel.getFromPrimitives(); 165 166 case TO: return memberModel.getToPrimitives(); … … 168 169 return null; 169 170 } 170 171 171 172 /** 172 173 * Initializes the model from a relation representing a turn 173 174 * restriction 174 * 175 * 175 176 * @param turnRestriction the turn restriction 176 177 */ 177 178 protected void initFromTurnRestriction(Relation turnRestriction) { 178 179 179 180 // populate the member model 180 181 memberModel.populate(turnRestriction); 181 182 182 183 // make sure we have a restriction tag 183 184 TagCollection tags = TagCollection.from(turnRestriction); 184 185 tags.setUniqueForKey("type", "restriction"); 185 186 tagEditorModel.initFromTags(tags); 186 187 187 188 setChanged(); 188 189 notifyObservers(); 189 190 } 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. 193 194 * {@code turnRestriction} is an arbitrary relation. A tag type=restriction 194 195 * 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 * 197 198 * @param turnRestriction the turn restriction 198 199 * @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 200 201 */ 201 202 public void populate(Relation turnRestriction) { 202 203 CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction"); 203 if (turnRestriction.getDataSet() != null && turnRestriction.getDataSet() != layer.data) { 204 if (turnRestriction.getDataSet() != null && turnRestriction.getDataSet() != layer.data) { 204 205 throw new IllegalArgumentException( 205 206 // 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()) 207 209 ); 208 210 } 209 211 initFromTurnRestriction(turnRestriction); 210 212 } 211 212 213 214 213 215 /** 214 216 * Applies the current state in the model to a turn restriction 215 * 217 * 216 218 * @param turnRestriction the turn restriction. Must not be null. 217 219 */ 218 220 public void apply(Relation turnRestriction) { 219 CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction"); 221 CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction"); 220 222 TagCollection tags = tagEditorModel.getTagCollection(); 221 223 turnRestriction.removeAll(); 222 224 tags.applyTo(turnRestriction); 223 memberModel.applyTo(turnRestriction); 224 } 225 225 memberModel.applyTo(turnRestriction); 226 } 227 226 228 /** 227 229 * 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 * 230 232 * @return the tag value 231 233 */ … … 235 237 return tags.getJoinedValues("restriction"); 236 238 } 237 239 238 240 /** 239 241 * 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) { 245 247 if (value == null || value.trim().equals("")) { 246 tagEditorModel.delete("restriction"); 248 tagEditorModel.delete("restriction"); 247 249 } else { 248 TagModel 249 if (tm != null){ 250 TagModel tm = tagEditorModel.get("restriction"); 251 if (tm != null) { 250 252 tm.setValue(value); 251 253 } else { … … 256 258 notifyObservers(); 257 259 } 258 260 259 261 /** 260 262 * Replies the list of 'via' objects. The return value is an 261 263 * unmodifiable list. 262 * 264 * 263 265 * @return the list of 'via' objects 264 266 */ … … 266 268 return memberModel.getVias(); 267 269 } 268 270 269 271 /** 270 272 * <p>Sets the list of vias for the edited turn restriction.</p> 271 * 273 * 272 274 * <p>If {@code vias} is null, all vias are removed. All primitives 273 275 * in {@code vias} must be assigned to a dataset and the dataset 274 276 * must be equal to the dataset of this editor model, see {@link #getDataSet()}</p> 275 * 277 * 276 278 * <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 { 282 284 memberModel.setVias(vias); 283 285 } 284 286 285 287 /** 286 288 * Replies the layer in whose context this editor is working 287 * 289 * 288 290 * @return the layer in whose context this editor is working 289 291 */ … … 291 293 return layer; 292 294 } 293 295 294 296 /** 295 297 * Registers this model with global event sources like {@link DatasetEventManager} 296 298 */ 297 public void registerAsEventListener(){ 299 public void registerAsEventListener() { 298 300 DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT); 299 301 } 300 302 301 303 /** 302 304 * Removes this model as listener from global event sources like {@link DatasetEventManager} … … 305 307 DatasetEventManager.getInstance().removeDatasetListener(this); 306 308 } 307 308 /** 309 * Replies the tag editor model 310 * 309 310 /** 311 * Replies the tag editor model 312 * 311 313 * @return the tag editor model 312 314 */ … … 314 316 return tagEditorModel; 315 317 } 316 318 317 319 /** 318 320 * Replies the editor model for the relation members 319 * 321 * 320 322 * @return the editor model for the relation members 321 323 */ … … 323 325 return memberModel; 324 326 } 325 327 326 328 /** 327 329 * Replies the model for the open issues in this turn restriction 328 330 * editor. 329 * 331 * 330 332 * @return the model for the open issues in this turn restriction 331 333 * editor … … 334 336 return issuesModel; 335 337 } 336 338 337 339 public NavigationControler getNavigationControler() { 338 340 return navigationControler; 339 341 } 340 342 341 343 /** 342 344 * Replies the current value of the tag "except", or the empty string 343 345 * if the tag doesn't exist. 344 *345 * @return346 346 */ 347 347 public ExceptValueModel getExcept() { … … 350 350 return new ExceptValueModel(tag.getValue()); 351 351 } 352 352 353 353 /** 354 354 * Sets the current value of the tag "except". Removes the 355 355 * tag is {@code value} is null or consists of white 356 * space only. 357 * 356 * space only. 357 * 358 358 * @param value the new value for 'except' 359 359 */ 360 public void setExcept(ExceptValueModel value){ 360 public void setExcept(ExceptValueModel value) { 361 361 if (value == null || value.getValue().equals("")) { 362 if (tagEditorModel.get("except") != null){ 362 if (tagEditorModel.get("except") != null) { 363 363 tagEditorModel.delete("except"); 364 364 setChanged(); 365 notifyObservers(); 365 notifyObservers(); 366 366 } 367 return; 367 return; 368 368 } 369 369 TagModel tag = tagEditorModel.get("except"); … … 378 378 notifyObservers(); 379 379 } 380 } 380 } 381 381 } 382 382 383 383 /* ----------------------------------------------------------------------------------------- */ 384 384 /* interface DataSetListener */ 385 /* ----------------------------------------------------------------------------------------- */ 385 /* ----------------------------------------------------------------------------------------- */ 386 386 protected boolean isAffectedByDataSetUpdate(DataSet ds, List<? extends OsmPrimitive> updatedPrimitives) { 387 387 if (ds != layer.data) return false; … … 392 392 return size1 != myPrimitives.size(); 393 393 } 394 394 395 @Override 395 396 public void dataChanged(DataChangedEvent event) { 396 397 // refresh the views 397 398 setChanged(); 398 notifyObservers(); 399 } 400 399 notifyObservers(); 400 } 401 402 @Override 401 403 public void nodeMoved(NodeMovedEvent event) { 402 404 // may affect the display name of node in the list of vias … … 407 409 } 408 410 411 @Override 409 412 public void otherDatasetChange(AbstractDatasetChangedEvent event) {/* irrelevant in this context */} 410 413 414 @Override 411 415 public void primitivesAdded(PrimitivesAddedEvent event) {/* irrelevant in this context */} 416 417 @Override 412 418 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 418 425 public void relationMembersChanged(RelationMembersChangedEvent event) {/* irrelevant in this context */} 426 427 @Override 419 428 public void tagsChanged(TagsChangedEvent event) { 420 429 // may affect the display name of 'from', 'to' or 'via' elements … … 425 434 } 426 435 436 @Override 427 437 public void wayNodesChanged(WayNodesChangedEvent event) { 428 438 // may affect the display name of 'from', 'to' or 'via' elements … … 430 440 setChanged(); 431 441 notifyObservers(); 432 } 433 } 434 442 } 443 } 444 435 445 class RelationMemberModelListener implements TableModelListener { 446 @Override 436 447 public void tableChanged(TableModelEvent e) { 437 448 setChanged(); 438 449 notifyObservers(); 439 } 450 } 440 451 } 441 452 442 453 /* ----------------------------------------------------------------------------------------- */ 443 454 /* inner classes */ 444 /* ----------------------------------------------------------------------------------------- */ 455 /* ----------------------------------------------------------------------------------------- */ 445 456 class TagEditorModelObserver implements TableModelListener { 457 @Override 446 458 public void tableChanged(TableModelEvent e) { 447 459 setChanged(); 448 460 notifyObservers(); 449 } 461 } 450 462 } 451 463 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java
r32386 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 59 60 */ 60 61 public class TurnRestrictionLegEditor extends JPanel implements Observer, PrimitiveIdListProvider { 61 // staticprivate final Logger logger = Logger.getLogger(TurnRestrictionLegEditor.class.getName());62 //private static final Logger logger = Logger.getLogger(TurnRestrictionLegEditor.class.getName()); 62 63 63 64 private JLabel lblOsmObject; … … 82 83 BorderFactory.createCompoundBorder( 83 84 BorderFactory.createEtchedBorder(), 84 BorderFactory.createEmptyBorder(1, 1,1,1)85 BorderFactory.createEmptyBorder(1, 1, 1, 1) 85 86 ) 86 87 ); 87 88 88 JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT, 0,0));89 JPanel pnlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); 89 90 pnlButtons.setBorder(null); 90 91 JButton btn; … … 103 104 104 105 // focus handling 105 FocusHandler fh 106 FocusHandler fh = new FocusHandler(); 106 107 lblOsmObject.setFocusable(true); 107 108 lblOsmObject.addFocusListener(fh); … … 115 116 116 117 // 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); 118 119 119 120 getInputMap().put(Shortcut.getCopyKeyStroke(), TransferHandler.getCopyAction().getValue(Action.NAME));; … … 122 123 getActionMap().put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction()); 123 124 lblOsmObject.setTransferHandler(transferHandler = new LegEditorTransferHandler(this)); 124 lblOsmObject.addMouseMotionListener(new MouseMotionAdapter(){ 125 lblOsmObject.addMouseMotionListener(new MouseMotionAdapter() { 125 126 @Override 126 127 public void mouseDragged(MouseEvent e) { 127 JComponent c = (JComponent)e.getSource(); 128 JComponent c = (JComponent) e.getSource(); 128 129 TransferHandler th = c.getTransferHandler(); 129 130 th.exportAsDrag(c, e, TransferHandler.COPY); … … 153 154 } 154 155 155 protected void refresh(){ 156 protected void refresh() { 156 157 legs.clear(); 157 158 legs.addAll(model.getTurnRestrictionLeg(role)); … … 161 162 lblOsmObject.setText(tr("please select a way")); 162 163 lblOsmObject.setToolTipText(null); 163 } else if (legs.size() == 1){ 164 } else if (legs.size() == 1) { 164 165 OsmPrimitive leg = legs.iterator().next(); 165 166 lblOsmObject.setFont(UIManager.getFont("Label.font")); … … 170 171 lblOsmObject.setFont(UIManager.getFont("Label.font").deriveFont(Font.ITALIC)); 171 172 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())); 173 174 lblOsmObject.setToolTipText(null); 174 175 } … … 213 214 /* interface Observer */ 214 215 /* ----------------------------------------------------------------------------- */ 216 @Override 215 217 public void update(Observable o, Object arg) { 216 218 refresh(); … … 220 222 /* interface PrimitiveIdListProvider */ 221 223 /* ----------------------------------------------------------------------------- */ 224 @Override 222 225 public List<PrimitiveId> getSelectedPrimitiveIds() { 223 226 if (legs.size() == 1) { … … 256 259 */ 257 260 class DeleteAction extends AbstractAction { 258 publicDeleteAction() {261 DeleteAction() { 259 262 putValue(SHORT_DESCRIPTION, tr("Delete from turn restriction")); 260 263 putValue(NAME, tr("Delete")); 261 264 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)); 263 266 updateEnabledState(); 264 267 } 265 268 269 @Override 266 270 public void actionPerformed(ActionEvent e) { 267 271 model.setTurnRestrictionLeg(role, null); … … 269 273 270 274 public void updateEnabledState() { 271 setEnabled(legs.size() >0);275 setEnabled(legs.size() > 0); 272 276 } 273 277 } … … 279 283 class AcceptAction extends AbstractAction implements ListSelectionListener { 280 284 281 publicAcceptAction() {285 AcceptAction() { 282 286 putValue(SHORT_DESCRIPTION, tr("Accept the currently selected way")); 283 287 putValue(NAME, tr("Accept")); … … 287 291 } 288 292 289 public void actionPerformed(ActionEvent e) { 293 @Override 294 public void actionPerformed(ActionEvent e) { 290 295 List<Way> selWays = OsmPrimitive.getFilteredList(model.getJosmSelectionListModel().getSelected(), Way.class); 291 296 if (selWays.size() != 1) return; … … 310 315 Logger logger = Logger.getLogger(LegEditorTransferHandler.class.getName()); 311 316 312 publicLegEditorTransferHandler(PrimitiveIdListProvider provider){317 LegEditorTransferHandler(PrimitiveIdListProvider provider) { 313 318 super(provider); 314 319 } … … 318 323 public boolean importData(JComponent comp, Transferable t) { 319 324 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) { 322 327 return false; 323 328 } … … 326 331 model.setTurnRestrictionLeg(role, id); 327 332 return true; 328 } catch(IOException e) { 333 } catch (IOException e) { 329 334 // ignore 330 335 return false; 331 } catch(UnsupportedFlavorException e) { 336 } catch (UnsupportedFlavorException e) { 332 337 // ignore 333 338 return false; … … 350 355 351 356 class PopupMenu extends JPopupMenu { 352 publicPopupMenu() {357 PopupMenu() { 353 358 actCopy.updateEnabledState(); 354 359 JMenuItem item = add(actCopy); … … 365 370 private Action delegate; 366 371 367 publicCopyAction(){372 CopyAction() { 368 373 putValue(NAME, tr("Copy")); 369 374 putValue(SHORT_DESCRIPTION, tr("Copy to the clipboard")); … … 374 379 } 375 380 381 @Override 376 382 public void actionPerformed(ActionEvent e) { 377 383 delegate.actionPerformed(e); … … 395 401 } 396 402 397 publicPasteAction(){403 PasteAction() { 398 404 putValue(NAME, tr("Paste")); 399 405 putValue(SHORT_DESCRIPTION, tr("Paste from the clipboard")); … … 407 413 } 408 414 415 @Override 409 416 public void actionPerformed(ActionEvent e) { 410 417 delegate.actionPerformed(e); 411 418 } 412 419 } 413 414 415 420 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegRole.java
r23192 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 4 5 * Enumerates the two roles a "leg" in a turn restriction can have. 5 6 */ 6 public enum TurnRestrictionLegRole { 7 public enum TurnRestrictionLegRole { 7 8 FROM("from"), 8 9 TO("to"); 9 10 10 11 private String osmRoleName; 11 12 privateTurnRestrictionLegRole(String osmRoleName) {12 13 TurnRestrictionLegRole(String osmRoleName) { 13 14 this.osmRoleName = osmRoleName; 14 15 } 15 16 16 17 public String getOsmRole() { 17 18 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 48 49 * 49 50 */ 50 public class TurnRestrictionSelectionPopupPanel extends JPanel{ 51 //static private final Logger logger = Logger.getLogger(TurnRestrictionSelectionPopupPanel.class.getName()); 51 public class TurnRestrictionSelectionPopupPanel extends JPanel { 52 52 53 53 /** the parent popup */ … … 66 66 * @return the collection of "parent" turn restrictions. 67 67 */ 68 static public Collection<Relation> getTurnRestrictionsParticipatingIn(Collection<OsmPrimitive> primitives){68 public static Collection<Relation> getTurnRestrictionsParticipatingIn(Collection<OsmPrimitive> primitives) { 69 69 HashSet<Relation> ret = new HashSet<>(); 70 70 if (primitives == null) return ret; 71 for (OsmPrimitive p: primitives){ 71 for (OsmPrimitive p: primitives) { 72 72 if (p == null) continue; 73 73 if (p.isDeleted() || !p.isVisible()) continue; 74 for (OsmPrimitive parent: p.getReferrers()){ 74 for (OsmPrimitive parent: p.getReferrers()) { 75 75 if (!(parent instanceof Relation)) continue; 76 76 String type = parent.get("type"); 77 if (type == null || ! 78 if (parent.isDeleted() || ! 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); 80 80 } 81 81 } … … 89 89 * @param editCandiates the edit candidates 90 90 */ 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++) { 93 93 int vkey = 0; 94 switch(i){ 94 switch(i) { 95 95 case 1: vkey = KeyEvent.VK_1; break; 96 96 case 2: vkey = KeyEvent.VK_2; break; … … 103 103 case 9: vkey = KeyEvent.VK_9; break; 104 104 } 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 108 109 /** 109 110 * Builds the panel with the turn restrictions table … … 117 118 tblTurnRestrictions.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); 118 119 TurnRestrictionCellRenderer renderer = new TurnRestrictionCellRenderer(); 119 tblTurnRestrictions.setRowHeight((int)renderer.getPreferredSize().getHeight()); 120 tblTurnRestrictions.setRowHeight((int) renderer.getPreferredSize().getHeight()); 120 121 121 122 // create a scroll pane, remove the table header … … 129 130 EditSelectedTurnRestrictionAction action = new EditSelectedTurnRestrictionAction(); 130 131 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); 132 133 133 134 tblTurnRestrictions.addFocusListener(new FocusHandler()); … … 150 151 add(btnNew = new JButton(new NewAction()), BorderLayout.NORTH); 151 152 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); 155 156 156 157 btnNew.addFocusListener(new FocusHandler()); 157 158 158 if (editCandiates != null && ! 159 if (editCandiates != null && !editCandiates.isEmpty()) { 159 160 add(buildTurnRestrictionTablePanel(editCandiates), BorderLayout.CENTER); 160 161 registerEditShortcuts(editCandiates); … … 193 194 * Launches a popup with this panel as content 194 195 */ 195 public void launch(){ 196 public void launch() { 196 197 PointerInfo info = MouseInfo.getPointerInfo(); 197 198 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); 199 200 parentPopup.show(); 200 201 btnNew.requestFocusInWindow(); … … 203 204 @Override 204 205 public Dimension getPreferredSize() { 205 int bestheight = (int)btnNew.getPreferredSize().getHeight() 206 int bestheight = (int) btnNew.getPreferredSize().getHeight() 206 207 + Math.min(2, tblTurnRestrictions.getRowCount()) * tblTurnRestrictions.getRowHeight() 207 208 + 5; … … 214 215 215 216 private class NewAction extends AbstractAction { 216 publicNewAction() {217 NewAction() { 217 218 putValue(NAME, tr("Create new turn restriction")); 218 219 putValue(SHORT_DESCRIPTION, tr("Launch the turn restriction editor to create a new turn restriction")); … … 221 222 } 222 223 224 @Override 223 225 public void actionPerformed(ActionEvent e) { 224 226 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); 226 228 TurnRestrictionEditorManager.getInstance().positionOnScreen(editor); 227 229 TurnRestrictionEditorManager.getInstance().register(layer, tr, editor); 228 if (parentPopup != null){ 230 if (parentPopup != null) { 229 231 parentPopup.hide(); 230 232 } … … 233 235 } 234 236 235 abstract privateclass AbstractEditTurnRestrictionAction extends AbstractAction {236 protected void launchEditor(Relation tr){ 237 private abstract class AbstractEditTurnRestrictionAction extends AbstractAction { 238 protected void launchEditor(Relation tr) { 237 239 TurnRestrictionEditorManager manager = TurnRestrictionEditorManager.getInstance(); 238 240 TurnRestrictionEditor editor = manager.getEditorForRelation(layer, tr); 239 if (parentPopup != null){ 241 if (parentPopup != null) { 240 242 parentPopup.hide(); 241 243 } … … 244 246 editor.toFront(); 245 247 } else { 246 editor = new TurnRestrictionEditor(Main.map.mapView, layer,tr); 248 editor = new TurnRestrictionEditor(Main.map.mapView, layer, tr); 247 249 manager.positionOnScreen(editor); 248 manager.register(layer, tr,editor); 250 manager.register(layer, tr, editor); 249 251 editor.setVisible(true); 250 252 } … … 255 257 private int idx; 256 258 257 publicEditTurnRestrictionAction(int idx){259 EditTurnRestrictionAction(int idx) { 258 260 this.idx = idx; 259 261 } 260 262 263 @Override 261 264 public void actionPerformed(ActionEvent e) { 262 Relation tr = (Relation)tblTurnRestrictions.getModel().getValueAt(idx, 1); 265 Relation tr = (Relation) tblTurnRestrictions.getModel().getValueAt(idx, 1); 263 266 launchEditor(tr); 264 267 } 265 268 } 266 269 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) { 269 272 if (row < 0) return; 270 Relation tr = (Relation)tblTurnRestrictions.getModel().getValueAt(row, 1); 273 Relation tr = (Relation) tblTurnRestrictions.getModel().getValueAt(row, 1); 271 274 launchEditor(tr); 272 275 } 276 277 @Override 273 278 public void actionPerformed(ActionEvent e) { 274 279 int row = tblTurnRestrictions.getSelectedRow(); 275 280 editTurnRestrictionAtRow(row); 276 281 } 282 283 @Override 277 284 public void mouseClicked(MouseEvent e) { 278 285 if (!(SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2)) return; … … 281 288 editTurnRestrictionAtRow(row); 282 289 } 290 291 @Override 283 292 public void mouseEntered(MouseEvent e) {} 293 294 @Override 284 295 public void mouseExited(MouseEvent e) {} 296 297 @Override 285 298 public void mousePressed(MouseEvent e) {} 299 300 @Override 286 301 public void mouseReleased(MouseEvent e) {} 287 302 } 288 303 289 304 private class CloseAction extends AbstractAction { 305 @Override 290 306 public void actionPerformed(ActionEvent e) { 291 if (parentPopup != null){ 307 if (parentPopup != null) { 292 308 parentPopup.hide(); 293 309 } … … 298 314 private final ArrayList<Relation> turnrestrictions = new ArrayList<>(); 299 315 300 publicTurnRestrictionTableModel(Collection<Relation> turnrestrictions){316 TurnRestrictionTableModel(Collection<Relation> turnrestrictions) { 301 317 this.turnrestrictions.clear(); 302 if (turnrestrictions != null){ 318 if (turnrestrictions != null) { 303 319 this.turnrestrictions.addAll(turnrestrictions); 304 320 } … … 306 322 } 307 323 324 @Override 308 325 public int getRowCount() { 309 326 return turnrestrictions.size(); 310 327 } 311 328 329 @Override 312 330 public int getColumnCount() { 313 331 return 2; 314 332 } 315 333 334 @Override 316 335 public Object getValueAt(int rowIndex, int columnIndex) { 317 switch(columnIndex){ 336 switch(columnIndex) { 318 337 case 0: 319 if (rowIndex <= 8) {338 if (rowIndex <= 8) { 320 339 return Integer.toString(rowIndex+1); 321 340 } else { … … 331 350 332 351 private static class TurnRestrictionTableColumnModel extends DefaultTableColumnModel { 333 publicTurnRestrictionTableColumnModel() {352 TurnRestrictionTableColumnModel() { 334 353 // the idx column 335 354 TableColumn col = new TableColumn(0); … … 352 371 // if we loose the focus to a component outside of the popup panel 353 372 // 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) { 356 376 parentPopup.hide(); 357 377 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionType.java
r23192 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 4 5 5 6 /** 6 * This is the enumeration of turn restriction types, see 7 * This is the enumeration of turn restriction types, see 7 8 * <a href="http://wiki.openstreetmap.org/wiki/Turn_restriction">OSM Wiki</a> 8 * 9 * 9 10 */ 10 11 public enum TurnRestrictionType { … … 12 13 NO_LEFT_TURN("no_left_turn", tr("No Left Turn")), 13 14 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")), 15 16 ONLY_RIGHT_TURN("only_right_turn", tr("Only Right Turn")), 16 17 ONLY_LEFT_TURN("only_left_turn", tr("Only Left Turn")), 17 18 ONLY_STRAIGHT_ON("only_straight_on", tr("Only Straight On")); 18 19 19 20 private String tagValue; 20 21 private String displayName; 21 22 22 23 TurnRestrictionType(String tagValue, String displayName) { 23 24 this.tagValue = tagValue; 24 25 this.displayName = displayName; 25 26 } 26 27 27 28 /** 28 29 * Replies the tag value for a specific turn restriction type 29 * 30 * 30 31 * @return the tag value for a specific turn restriction type 31 32 */ … … 33 34 return tagValue; 34 35 } 35 36 36 37 /** 37 38 * Replies the localized display name for a turn restriction type … … 39 40 public String getDisplayName() { 40 41 return displayName; 41 } 42 42 } 43 43 44 /** 44 45 * Replies the enumeration value for a given tag value. null, 45 46 * if {@code tagValue} is null or if there isnt an enumeration value 46 47 * for this {@code tagValue} 47 * 48 * 48 49 * @param tagValue the tag value, i.e. <tt>no_left_turn</tt> 49 50 * @return the enumeration value 50 51 */ 51 static public TurnRestrictionType fromTagValue(String tagValue) {52 public static TurnRestrictionType fromTagValue(String tagValue) { 52 53 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; 55 56 } 56 57 return null; … … 58 59 59 60 /** 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 63 64 * @return true if {@code tagValue} is a standard restriction type 64 65 */ 65 static public boolean isStandardTagValue(String tagValue){66 public static boolean isStandardTagValue(String tagValue) { 66 67 return fromTagValue(tagValue) != null; 67 68 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionTypeRenderer.java
r30737 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 18 19 import org.openstreetmap.josm.tools.ImageProvider; 19 20 21 public class TurnRestrictionTypeRenderer extends JLabel implements ListCellRenderer<Object> { 20 22 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<>(); 24 24 private String iconSet = "set-a"; 25 25 26 26 /** 27 * Loads the image icons for the rendered turn restriction types 27 * Loads the image icons for the rendered turn restriction types 28 28 */ 29 29 protected void loadImages() { 30 for(TurnRestrictionType type: TurnRestrictionType.values()) { 30 for (TurnRestrictionType type: TurnRestrictionType.values()) { 31 31 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) { 35 36 System.out.println(tr("Warning: failed to load icon for turn restriction type ''{0}''", type.getTagValue())); 36 e.printStackTrace(); 37 e.printStackTrace(); 37 38 } 38 39 } 39 40 } 40 41 41 42 public TurnRestrictionTypeRenderer() { 42 43 setOpaque(true); 43 44 loadImages(); 44 45 } 45 46 protected void renderColors(boolean isSelected){ 47 if (isSelected){ 46 47 protected void renderColors(boolean isSelected) { 48 if (isSelected) { 48 49 setBackground(UIManager.getColor("List.selectionBackground")); 49 50 setForeground(UIManager.getColor("List.selectionForeground")); 50 51 } else { 51 52 setBackground(UIManager.getColor("List.background")); 52 setForeground(UIManager.getColor("List.foreground")); 53 setForeground(UIManager.getColor("List.foreground")); 53 54 } 54 55 } 55 56 56 57 /** 57 58 * Initializes the set of icons used from the preference key 58 59 * {@link PreferenceKeys#ROAD_SIGNS}. 59 * 60 * @param prefs the JOSM preferences 60 * 61 * @param prefs the JOSM preferences 61 62 */ 62 public void initIconSetFromPreferences(Preferences prefs) {63 public void initIconSetFromPreferences(Preferences prefs) { 63 64 iconSet = prefs.get(PreferenceKeys.ROAD_SIGNS, "set-a"); 64 65 iconSet = iconSet.trim().toLowerCase(); … … 68 69 loadImages(); 69 70 } 70 71 72 @Override 71 73 public Component getListCellRendererComponent(JList<? extends Object> list, Object value, 72 74 int index, boolean isSelected, boolean cellHasFocus) { 73 75 74 76 renderColors(isSelected); 75 77 if (value == null) { 76 78 setText(tr("please select a turn restriction type")); 77 79 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; 83 85 setText(type.getDisplayName()); 84 86 setIcon(icons.get(type)); 85 87 } 86 88 return this; 87 } 89 } 88 90 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/VehicleExceptionEditor.java
r30651 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 32 33 * VehicleExceptionEditor is UI widget for editing exceptions to a turn restriction 33 34 * based on vehicle types. 34 * 35 * 35 36 */ 36 public class VehicleExceptionEditor extends JPanel implements Observer{ 37 //static private final Logger logger = Logger.getLogger(VehicleExceptionEditor.class.getName()); 38 37 public class VehicleExceptionEditor extends JPanel implements Observer { 38 39 39 private TurnRestrictionEditorModel model; 40 40 private JCheckBox cbPsv; … … 50 50 private JPanel pnlNonStandard; 51 51 private ExceptValueModel exceptValue = new ExceptValueModel(); 52 52 53 53 private StandardVehicleTypeChangeListener svtChangeListener; 54 54 55 55 private JPanel buildMessagePanel() { 56 56 JPanel pnl = new JPanel(new BorderLayout()); … … 64 64 return pnl; 65 65 } 66 66 67 67 private JPanel buildStandardInputPanel() { 68 68 if (pnlStandard != null) 69 69 return pnlStandard; 70 70 71 71 svtChangeListener = new StandardVehicleTypeChangeListener(); 72 72 73 73 GridBagConstraints gc = new GridBagConstraints(); 74 74 gc.anchor = GridBagConstraints.NORTHWEST; … … 76 76 gc.gridx = 0; 77 77 gc.gridy = 0; 78 78 79 79 pnlStandard = new JPanel(new GridBagLayout()); 80 80 JLabel lbl; … … 85 85 lbl.setToolTipText(tr("Public service vehicles like buses, tramways, etc.")); 86 86 lbl.setIcon(ImageProvider.get("vehicle", "psv")); 87 87 88 88 gc.weightx = 0.0; 89 89 pnlStandard.add(cbPsv, gc); … … 91 91 gc.gridx++; 92 92 pnlStandard.add(lbl, gc); 93 93 94 94 cbHgv = new JCheckBox(); 95 95 cbHgv.addItemListener(svtChangeListener); … … 110 110 lbl.setText(tr("Motorcars")); 111 111 lbl.setIcon(ImageProvider.get("vehicle", "motorcar")); 112 112 113 113 gc.weightx = 0.0; 114 114 gc.gridx = 0; … … 118 118 gc.gridx++; 119 119 pnlStandard.add(lbl, gc); 120 120 121 121 cbBicyle = new JCheckBox(); 122 122 cbBicyle.addItemListener(svtChangeListener); … … 124 124 lbl.setText(tr("Bicycles")); 125 125 lbl.setIcon(ImageProvider.get("vehicle", "bicycle")); 126 126 127 127 gc.weightx = 0.0; 128 128 gc.gridx++; … … 131 131 gc.gridx++; 132 132 pnlStandard.add(lbl, gc); 133 133 134 134 cbMoped = new JCheckBox(); 135 135 cbMoped.addItemListener(svtChangeListener); 136 136 lbl = new JLabel(tr("Mopeds")); 137 137 lbl.setIcon(ImageProvider.get("vehicle", "moped")); 138 138 139 139 gc.weightx = 0.0; 140 140 gc.gridx = 0; … … 144 144 gc.gridx++; 145 145 pnlStandard.add(lbl, gc); 146 146 147 147 return pnlStandard; 148 148 } 149 149 150 150 private JPanel buildNonStandardInputPanel() { 151 151 if (pnlNonStandard != null) … … 159 159 gc.gridx = 0; 160 160 gc.gridy = 0; 161 161 162 162 pnlNonStandard.add(new JLabel(tr("Value:")), gc); 163 163 gc.gridx = 1; … … 165 165 pnlNonStandard.add(tfNonStandardValue = new JTextField(), gc); 166 166 SelectAllOnFocusGainedDecorator.decorate(tfNonStandardValue); 167 167 168 168 NonStandardVehicleTypesHandler inputChangedHandler = new NonStandardVehicleTypesHandler(); 169 169 tfNonStandardValue.addActionListener(inputChangedHandler); … … 171 171 return pnlNonStandard; 172 172 } 173 173 174 174 /** 175 * Builds the UI for entering standard values 175 * Builds the UI for entering standard values 176 176 */ 177 177 protected void buildStandard() { … … 184 184 gc.gridy = 0; 185 185 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 191 191 /** 192 * Builds the UI for entering either standard or non-standard values 192 * Builds the UI for entering either standard or non-standard values 193 193 */ 194 194 protected void buildNonStandard() { … … 201 201 gc.gridy = 0; 202 202 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); 207 207 add(rbStandardException = new JRadioButton(tr("Use standard exceptions")), gc); 208 208 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); 212 212 add(buildStandardInputPanel(), gc); 213 213 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); 217 217 add(rbNonStandardException = new JRadioButton(tr("Use non-standard exceptions")), gc); 218 218 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); 222 222 add(buildNonStandardInputPanel(), gc); 223 223 224 224 bgStandardOrNonStandard = new ButtonGroup(); 225 225 bgStandardOrNonStandard.add(rbNonStandardException); 226 226 bgStandardOrNonStandard.add(rbStandardException); 227 227 228 228 StandardNonStandardChangeHandler changeHandler = new StandardNonStandardChangeHandler(); 229 229 rbNonStandardException.addItemListener(changeHandler); 230 230 rbStandardException.addItemListener(changeHandler); 231 231 } 232 232 233 233 protected void build() { 234 234 removeAll(); 235 235 buildNonStandardInputPanel(); 236 236 buildStandardInputPanel(); 237 if (exceptValue.isStandard()){ 237 if (exceptValue.isStandard()) { 238 238 buildStandard(); 239 239 } else { … … 243 243 invalidate(); 244 244 } 245 245 246 246 protected void init() { 247 247 try { … … 257 257 this.svtChangeListener.setEnabled(true); 258 258 } 259 if (!exceptValue.isStandard()){ 259 if (!exceptValue.isStandard()) { 260 260 rbNonStandardException.setSelected(true); 261 261 tfNonStandardValue.setText(exceptValue.getValue()); … … 267 267 } 268 268 } 269 269 270 270 protected void setEnabledStandardInputPanel(boolean enabled) { 271 for (Component c: pnlStandard.getComponents()){ 271 for (Component c: pnlStandard.getComponents()) { 272 272 c.setEnabled(enabled); 273 273 } 274 274 } 275 275 276 276 protected void setEnabledNonStandardInputPanel(boolean enabled) { 277 for (Component c: pnlNonStandard.getComponents()){ 277 for (Component c: pnlNonStandard.getComponents()) { 278 278 c.setEnabled(enabled); 279 279 } 280 280 } 281 281 282 282 283 283 /** 284 * Creates the editor 285 * 284 * Creates the editor 285 * 286 286 * @param model the editor model. Must not be null. 287 287 * @throws IllegalArgumentException thrown if {@code model} is null … … 293 293 model.addObserver(this); 294 294 } 295 295 296 296 /* ------------------------------------------------------------------------------------ */ 297 297 /* interface Observer */ 298 298 /* ------------------------------------------------------------------------------------ */ 299 @Override 299 300 public void update(Observable o, Object arg) { 300 301 if (!this.exceptValue.equals(model.getExcept())) { … … 308 309 /* ------------------------------------------------------------------------------------ */ 309 310 class StandardNonStandardChangeHandler implements ItemListener { 311 @Override 310 312 public void itemStateChanged(ItemEvent e) { 311 if (rbNonStandardException.isSelected()){ 313 if (rbNonStandardException.isSelected()) { 312 314 setEnabledNonStandardInputPanel(true); 313 315 setEnabledStandardInputPanel(false); … … 321 323 } 322 324 } 323 325 324 326 class StandardVehicleTypeChangeListener implements ItemListener { 325 327 private boolean enabled = true; 326 327 public void setEnabled(boolean enabled){ 328 329 public void setEnabled(boolean enabled) { 328 330 this.enabled = enabled; 329 331 } 330 332 333 @Override 331 334 public void itemStateChanged(ItemEvent e) { 332 335 if (!enabled) return; … … 335 338 exceptValue.setVehicleException("hgv", cbHgv.isSelected()); 336 339 exceptValue.setVehicleException("psv", cbPsv.isSelected()); 337 exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected()); 340 exceptValue.setVehicleException("motorcar", cbMotorcar.isSelected()); 338 341 model.setExcept(exceptValue); 339 342 } 340 343 } 341 344 342 345 class NonStandardVehicleTypesHandler implements ActionListener, FocusListener { 343 346 public void persist() { … … 345 348 model.setExcept(exceptValue); 346 349 } 347 350 351 @Override 348 352 public void focusGained(FocusEvent e) {} 353 354 @Override 349 355 public void focusLost(FocusEvent e) { 350 356 persist(); 351 357 } 352 358 359 @Override 353 360 public void actionPerformed(ActionEvent e) { 354 persist(); 361 persist(); 355 362 } 356 363 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ViaList.java
r32386 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 48 49 public class ViaList extends JList<OsmPrimitive> { 49 50 50 // staticprivate final Logger logger = Logger.getLogger(ViaList.class.getName());51 //private static final Logger logger = Logger.getLogger(ViaList.class.getName()); 51 52 52 53 private ViaListModel model; … … 72 73 setCellRenderer(new OsmPrimitivRenderer()); 73 74 setDragEnabled(true); 74 setTransferHandler(transferHandler =new ViaListTransferHandler(model)); 75 setTransferHandler(transferHandler = new ViaListTransferHandler(model)); 75 76 setVisibleRowCount(4); 76 77 77 78 actDelete = new DeleteAction(); 78 79 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); 80 81 81 82 actMoveDown = new MoveDownAction(); 82 83 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); 84 86 85 87 actMoveUp = new MoveUpAction(); 86 88 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); 88 91 89 92 actCopy = new CopyAction(); … … 103 106 private List<Integer> selectedRowsMemento = null; 104 107 105 publicViaListTransferHandler(PrimitiveIdListProvider provider) {108 ViaListTransferHandler(PrimitiveIdListProvider provider) { 106 109 super(provider); 107 110 } … … 121 124 // this is a drag operation on itself 122 125 int targetRow = getSelectedIndex(); 123 if (targetRow <0) return true; 126 if (targetRow < 0) return true; 124 127 model.moveVias(selectedRowsMemento, targetRow); 125 128 } else { 126 129 // this is a drag operation from another component 127 130 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); 129 132 model.insertVias(idsToAdd); 130 } catch(IOException e){ 133 } catch (IOException e) { 131 134 e.printStackTrace(); 132 } catch(UnsupportedFlavorException e){ 135 } catch (UnsupportedFlavorException e) { 133 136 e.printStackTrace(); 134 137 } … … 152 155 153 156 class DeleteAction extends AbstractAction implements ListSelectionListener { 154 publicDeleteAction() {157 DeleteAction() { 155 158 putValue(NAME, tr("Remove")); 156 159 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 162 166 public void valueChanged(ListSelectionEvent e) { 163 167 updateEnabledState(); … … 168 172 } 169 173 174 @Override 170 175 public void actionPerformed(ActionEvent e) { 171 176 model.removeSelectedVias(); … … 173 178 } 174 179 175 class MoveDownAction extends AbstractAction implements ListSelectionListener{ 176 publicMoveDownAction(){180 class MoveDownAction extends AbstractAction implements ListSelectionListener { 181 MoveDownAction() { 177 182 putValue(NAME, tr("Move down")); 178 183 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)); 180 185 new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this); 181 186 updateEnabledState(); 182 187 } 183 188 189 @Override 184 190 public void actionPerformed(ActionEvent e) { 185 191 model.moveDown(); 186 192 } 187 193 188 public void updateEnabledState(){ 194 public void updateEnabledState() { 189 195 if (getSelectedIndex() < 0) { 190 196 setEnabled(false); … … 194 200 } 195 201 202 @Override 196 203 public void valueChanged(ListSelectionEvent e) { 197 204 updateEnabledState(); … … 199 206 } 200 207 201 class MoveUpAction extends AbstractAction implements ListSelectionListener{ 202 publicMoveUpAction() {208 class MoveUpAction extends AbstractAction implements ListSelectionListener { 209 MoveUpAction() { 203 210 putValue(NAME, tr("Move up")); 204 211 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)); 206 213 new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this); 207 214 updateEnabledState(); 208 215 } 209 216 217 @Override 210 218 public void actionPerformed(ActionEvent e) { 211 219 model.moveUp(); 212 220 } 213 221 214 public void updateEnabledState(){ 222 public void updateEnabledState() { 215 223 if (getSelectedIndex() < 0) { 216 224 setEnabled(false); … … 220 228 } 221 229 230 @Override 222 231 public void valueChanged(ListSelectionEvent e) { 223 232 updateEnabledState(); … … 228 237 private Action delegate; 229 238 230 publicCopyAction(){239 CopyAction() { 231 240 putValue(NAME, tr("Copy")); 232 241 putValue(SHORT_DESCRIPTION, tr("Copy the selected vias to the clipboard")); … … 236 245 } 237 246 247 @Override 238 248 public void actionPerformed(ActionEvent e) { 239 249 delegate.actionPerformed(e); … … 244 254 } 245 255 256 @Override 246 257 public void valueChanged(ListSelectionEvent e) { 247 258 updateEnabledState(); … … 261 272 } 262 273 263 publicPasteAction(){274 PasteAction() { 264 275 putValue(NAME, tr("Paste")); 265 276 putValue(SHORT_DESCRIPTION, tr("Insert ''via'' objects from the clipboard")); … … 274 285 } 275 286 287 @Override 276 288 public void actionPerformed(ActionEvent e) { 277 289 delegate.actionPerformed(e); … … 280 292 281 293 class ViaListPopupMenu extends JPopupMenu { 282 publicViaListPopupMenu() {294 ViaListPopupMenu() { 283 295 JMenuItem item = add(actCopy); 284 296 item.setTransferHandler(transferHandler); … … 297 309 @Override 298 310 public void launch(MouseEvent evt) { 299 if (getSelectedIndex() <0) { 311 if (getSelectedIndex() < 0) { 300 312 int idx = locationToIndex(evt.getPoint()); 301 if (idx >=0) { 313 if (idx >= 0) { 302 314 setSelectedIndex(idx); 303 315 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ViaListModel.java
r30737 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 20 21 /** 21 22 * ViaListModel is a model for the list of 'via' objects of a turn restriction. 22 * 23 * 23 24 */ 24 public class ViaListModel extends AbstractListModel<OsmPrimitive> implements PrimitiveIdListProvider, Observer{ 25 //static private final Logger logger = Logger.getLogger(ViaListModel.class.getName()); 26 25 public class ViaListModel extends AbstractListModel<OsmPrimitive> implements PrimitiveIdListProvider, Observer { 26 27 27 private DefaultListSelectionModel selectionModel; 28 28 private final ArrayList<OsmPrimitive> vias = new ArrayList<>(); 29 29 private TurnRestrictionEditorModel model; 30 31 /** 32 * Constructor 33 * 30 31 /** 32 * Constructor 33 * 34 34 * @param model the turn restriction editor model. Must not be null. 35 35 * @param selectionModel the selection model. Must not be null. … … 48 48 /** 49 49 * Replies the list of currently selected vias 50 * 50 * 51 51 * @return the list of currently selected vias 52 52 */ 53 53 public List<OsmPrimitive> getSelectedVias() { 54 54 ArrayList<OsmPrimitive> ret = new ArrayList<>(); 55 for (int i =0; i < getSize(); i++) {55 for (int i = 0; i < getSize(); i++) { 56 56 if (selectionModel.isSelectedIndex(i)) { 57 57 ret.add(vias.get(i)); … … 60 60 return ret; 61 61 } 62 62 63 63 /** 64 64 * Sets the collection of currently selected vias 65 * 66 * @param vias a collection of vias 65 * 66 * @param vias a collection of vias 67 67 */ 68 68 public void setSelectedVias(Collection<OsmPrimitive> vias) { 69 69 selectionModel.clearSelection(); 70 70 if (vias == null) return; 71 for(OsmPrimitive via: vias) { 71 for (OsmPrimitive via: vias) { 72 72 int idx = this.vias.indexOf(via); 73 73 if (idx < 0) continue; … … 75 75 } 76 76 } 77 78 /** 79 * Replies the list of selected rows 80 * 77 78 /** 79 * Replies the list of selected rows 80 * 81 81 * @return the list of selected rows 82 82 */ 83 83 public List<Integer> getSelectedRows() { 84 84 ArrayList<Integer> ret = new ArrayList<>(); 85 for (int i =0; i < getSize(); i++) {85 for (int i = 0; i < getSize(); i++) { 86 86 if (selectionModel.isSelectedIndex(i)) { 87 87 ret.add(i); … … 90 90 return ret; 91 91 } 92 92 93 93 protected List<Integer> moveUp(List<Integer> rows, int targetRow) { 94 94 List<Integer> ret = new ArrayList<>(rows.size()); 95 95 int delta = rows.get(0) - targetRow; 96 for(int row: rows) { 96 for (int row: rows) { 97 97 OsmPrimitive via = vias.remove(row); 98 98 vias.add(row - delta, via); … … 101 101 return ret; 102 102 } 103 103 104 104 protected List<Integer> moveDown(List<Integer> rows, int targetRow) { 105 105 List<Integer> ret = new ArrayList<>(rows.size()); 106 106 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--) { 108 108 int row = rows.get(i); 109 109 OsmPrimitive via = vias.remove(row); … … 113 113 return ret; 114 114 } 115 116 public void moveVias(List<Integer> selectedRows, int targetRow){ 115 116 public void moveVias(List<Integer> selectedRows, int targetRow) { 117 117 if (selectedRows == null) return; 118 if (selectedRows.size() == 1){ 118 if (selectedRows.size() == 1) { 119 119 int sourceRow = selectedRows.get(0); 120 120 if (sourceRow == targetRow) return; … … 124 124 selectionModel.setSelectionInterval(targetRow, targetRow); 125 125 return; 126 } 126 } 127 127 int min = selectedRows.get(0); 128 128 int max = selectedRows.get(selectedRows.size()-1); 129 129 if (targetRow < min) { 130 130 selectedRows = moveUp(selectedRows, targetRow); 131 } else if (targetRow == min){ 131 } else if (targetRow == min) { 132 132 // do nothing 133 } else if (targetRow - min < getSize() - max){ 133 } else if (targetRow - min < getSize() - max) { 134 134 int delta = Math.min(targetRow - min, getSize()-1 - max); 135 135 targetRow = min + delta; … … 137 137 selectedRows = moveDown(selectedRows, targetRow); 138 138 } 139 } 139 } 140 140 fireContentsChanged(this, 0, getSize()); 141 141 selectionModel.clearSelection(); 142 for(int row: selectedRows) { 142 for (int row: selectedRows) { 143 143 selectionModel.addSelectionInterval(row, row); 144 } 145 } 146 144 } 145 } 146 147 147 /** 148 148 * Move the currently selected vias up by one position … … 162 162 moveVias(sel, sel.get(sel.size()-1)+1); 163 163 } 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 * 168 168 * @param idsToInsert the ids of the objects to insert 169 169 */ … … 172 172 List<OsmPrimitive> primitives = new ArrayList<>(idsToInsert.size()); 173 173 DataSet ds = model.getLayer().data; 174 for(PrimitiveId id: idsToInsert){ 174 for (PrimitiveId id: idsToInsert) { 175 175 OsmPrimitive p = ds.getPrimitiveById(id); 176 if (p == null){ 176 if (p == null) { 177 177 System.out.println(tr("Failed to retrieve OSM object with id {0} from dataset {1}. Cannot add it as ''via''.", id, ds)); 178 178 continue; … … 180 180 primitives.add(p); 181 181 } 182 int targetRow = Math.max(selectionModel.getMinSelectionIndex(),0); 182 int targetRow = Math.max(selectionModel.getMinSelectionIndex(), 0); 183 183 List<OsmPrimitive> newVias = new ArrayList<>(vias); 184 184 newVias.addAll(targetRow, primitives); … … 186 186 fireContentsChanged(this, 0, getSize()); 187 187 selectionModel.clearSelection(); 188 for (int i=targetRow; i< targetRow + primitives.size();i++) {188 for (int i = targetRow; i < targetRow + primitives.size(); i++) { 189 189 selectionModel.addSelectionInterval(i, i); 190 } 190 } 191 191 } 192 192 … … 197 197 ArrayList<OsmPrimitive> newVias = new ArrayList<>(vias); 198 198 int j = 0; 199 for (int i=0; i< getSize();i++){199 for (int i = 0; i < getSize(); i++) { 200 200 if (!selectionModel.isSelectedIndex(i)) continue; 201 201 newVias.remove(i-j); … … 205 205 model.setVias(newVias); 206 206 } 207 207 208 208 /** 209 209 * 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. 211 211 */ 212 212 protected void refresh() { 213 213 List<OsmPrimitive> sel = getSelectedVias(); 214 214 vias.clear(); 215 vias.addAll(model.getVias()); 215 vias.addAll(model.getVias()); 216 216 fireContentsChanged(this, 0, getSize()); 217 217 setSelectedVias(sel); 218 218 } 219 219 220 @Override 220 221 public OsmPrimitive getElementAt(int index) { 221 222 return vias.get(index); 222 223 } 223 224 225 @Override 224 226 public int getSize() { 225 227 return vias.size(); 226 228 } 227 229 228 230 /* ----------------------------------------------------------------------- */ 229 231 /* interface PrimitiveIdListProvider */ 230 232 /* ----------------------------------------------------------------------- */ 233 @Override 231 234 public List<PrimitiveId> getSelectedPrimitiveIds() { 232 235 ArrayList<PrimitiveId> ids = new ArrayList<>(); … … 240 243 /* interface Observer */ 241 244 /* ----------------------------------------------------------------------- */ 245 @Override 242 246 public void update(Observable o, Object arg) { 243 247 refresh(); 244 } 248 } 245 249 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/AbstractTurnRestrictionsListView.java
r30454 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 10 11 /** 11 12 * The abstract base class for two views of turn restriction lists. 12 * 13 * 13 14 * @see TurnRestrictionsInSelectionView 14 15 * @see TurnRestrictionsInDatasetView … … 18 19 protected TurnRestrictionsListModel model; 19 20 protected JList<Relation> lstTurnRestrictions; 20 21 public TurnRestrictionsListModel getModel(){ 21 22 public TurnRestrictionsListModel getModel() { 22 23 return model; 23 24 } 24 25 25 26 public JList<Relation> getList() { 26 27 return lstTurnRestrictions; 27 28 } 28 29 29 30 public void addListSelectionListener(ListSelectionListener listener) { 30 31 lstTurnRestrictions.addListSelectionListener(listener); 31 32 } 32 33 33 34 public void removeListSelectionListener(ListSelectionListener listener) { 34 35 lstTurnRestrictions.addListSelectionListener(listener); 35 36 } 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(); 39 40 renderer.initIconSetFromPreferences(prefs); 40 41 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionCellRenderer.java
r30737 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 34 35 /** 35 36 * This is a cell renderer for turn restrictions. 36 * 37 * 37 38 * 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 * 40 41 */ 41 public class TurnRestrictionCellRenderer extends JPanel implements ListCellRenderer<Relation>, TableCellRenderer{ 42 //static private final Logger logger = Logger.getLogger(TurnRestrictionCellRenderer.class.getName()); 43 42 public class TurnRestrictionCellRenderer extends JPanel implements ListCellRenderer<Relation>, TableCellRenderer { 43 44 44 /** the names of restriction types */ 45 staticprivate Set<String> RESTRICTION_TYPES = new HashSet<>(45 private static Set<String> RESTRICTION_TYPES = new HashSet<>( 46 46 Arrays.asList(new String[] { 47 47 "no_left_turn", … … 54 54 }) 55 55 ); 56 56 57 57 /** components used to render the turn restriction */ 58 58 private JLabel icon; … … 60 60 private JLabel to; 61 61 private String iconSet = "set-a"; 62 62 63 63 public TurnRestrictionCellRenderer() { 64 64 build(); … … 68 68 * Replies true if {@code restrictionType} is a valid restriction 69 69 * type. 70 * 71 * @param restrictionType the restriction type 70 * 71 * @param restrictionType the restriction type 72 72 * @return true if {@code restrictionType} is a valid restriction 73 73 * type … … 78 78 return RESTRICTION_TYPES.contains(restrictionType); 79 79 } 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 86 86 */ 87 87 protected String buildImageName(String restrictionType) { 88 88 return "types/" + iconSet + "/" + restrictionType; 89 89 } 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 95 95 */ 96 96 protected ImageIcon getIcon(String restrictionType) { … … 100 100 return ImageProvider.get(buildImageName(restrictionType)); 101 101 } 102 103 /** 104 * Builds the UI used to render turn restrictions 102 103 /** 104 * Builds the UI used to render turn restrictions 105 105 */ 106 106 protected void build() { 107 107 setLayout(new GridBagLayout()); 108 108 GridBagConstraints gc = new GridBagConstraints(); 109 110 // the turn restriction icon 109 110 // the turn restriction icon 111 111 gc.fill = GridBagConstraints.HORIZONTAL; 112 112 gc.weightx = 0.0; 113 113 gc.gridheight = 2; 114 114 gc.anchor = GridBagConstraints.CENTER; 115 gc.insets = new Insets(0, 0,2,2);115 gc.insets = new Insets(0, 0, 2, 2); 116 116 add(icon = new JLabel(), gc); 117 118 117 118 119 119 // the name of the way with role "from" 120 120 gc.anchor = GridBagConstraints.NORTHWEST; … … 122 122 gc.gridheight = 1; 123 123 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 126 126 gc.gridx = 2; 127 gc.weightx = 1.0; 127 gc.weightx = 1.0; 128 128 add(from = new JLabel(), gc); 129 129 130 130 // the name of the way with role "to" 131 131 gc.anchor = GridBagConstraints.NORTHWEST; … … 133 133 gc.gridy = 1; 134 134 gc.weightx = 0.0; 135 add(new JMultilineLabel("<html><strong>" + trc("turnrestriction", "To:") 136 135 add(new JMultilineLabel("<html><strong>" + trc("turnrestriction", "To:") + "</strong></html>"), gc); 136 137 137 gc.gridx = 2; 138 138 gc.weightx = 1.0; … … 141 141 142 142 /** 143 * Renders the icon for the turn restriction 144 * 143 * Renders the icon for the turn restriction 144 * 145 145 * @param tr the turn restriction 146 146 */ … … 152 152 /** 153 153 * 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 156 156 * @param role the role (either "from" or "to") 157 157 * @return the participating way; null, if no way is participating in this role 158 158 */ 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()) { 161 161 if (rm.getRole().trim().toLowerCase().equals(role) && rm.getType().equals(OsmPrimitiveType.WAY)) { 162 return (Way)rm.getMember(); 162 return (Way) rm.getMember(); 163 163 } 164 164 } 165 165 return null; 166 166 } 167 167 168 168 protected void renderFrom(Relation tr) { 169 169 Way from = getParticipatingWay(tr, "from"); … … 172 172 this.from.setText(tr("no participating way with role ''from''")); 173 173 return; 174 } 174 } 175 175 this.from.setText(DefaultNameFormatter.getInstance().format(from)); 176 176 } … … 182 182 this.to.setText(tr("no participating way with role ''to''")); 183 183 return; 184 } 184 } 185 185 this.to.setText(DefaultNameFormatter.getInstance().format(to)); 186 186 } … … 189 189 * Renders the foreground and background color depending on whether 190 190 * the turn restriction is selected 191 * 191 * 192 192 * @param isSelected true if the turn restriction is selected; false, 193 193 * otherwise … … 207 207 this.from.setBackground(bg); 208 208 this.to.setBackground(bg); 209 209 210 210 setForeground(fg); 211 211 this.icon.setForeground(fg); … … 217 217 * Initializes the set of icons used from the preference key 218 218 * {@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 224 224 iconSet = prefs.get(PreferenceKeys.ROAD_SIGNS, "set-a"); 225 225 iconSet = iconSet.trim().toLowerCase(); … … 228 228 } 229 229 } 230 230 231 231 /* ---------------------------------------------------------------------------------- */ 232 232 /* interface ListCellRenderer */ 233 233 /* ---------------------------------------------------------------------------------- */ 234 @Override 234 235 public Component getListCellRendererComponent(JList<? extends Relation> list, Relation value, 235 236 int index, boolean isSelected, boolean cellHasFocus) { 236 237 237 238 renderColor(isSelected); 238 Relation tr = (Relation)value;239 Relation tr = value; 239 240 renderIcon(tr); 240 241 renderFrom(tr); 241 renderTo(tr); 242 renderTo(tr); 242 243 return this; 243 244 } … … 246 247 /* interface TableCellRenderer */ 247 248 /* ---------------------------------------------------------------------------------- */ 249 @Override 248 250 public Component getTableCellRendererComponent(JTable table, Object value, 249 251 boolean isSelected, boolean hasFocus, int row, int column) { 250 renderColor(isSelected); 251 Relation tr = (Relation)value; 252 renderColor(isSelected); 253 Relation tr = (Relation) value; 252 254 renderIcon(tr); 253 255 renderFrom(tr); 254 renderTo(tr); 256 renderTo(tr); 255 257 return this; 256 } 258 } 257 259 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInDatasetListModel.java
r32375 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 50 51 List<Relation> ret = new LinkedList<>(); 51 52 if (primitives == null) return ret; 52 for(OsmPrimitive p: primitives){ 53 for (OsmPrimitive p: primitives) { 53 54 if (!isTurnRestriction(p)) continue; 54 ret.add((Relation)p); 55 ret.add((Relation) p); 55 56 } 56 57 return ret; … … 111 112 if (!turnRestrictions.isEmpty()) { 112 113 List<Relation> sel = getSelectedTurnRestrictions(); 113 for(Relation tr: turnRestrictions) { 114 for (Relation tr: turnRestrictions) { 114 115 // enforce a repaint of the respective turn restriction 115 116 int idx = getTurnRestrictionIndex(tr); 116 fireContentsChanged(this, idx,idx); 117 fireContentsChanged(this, idx, idx); 117 118 } 118 119 setSelectedTurnRestrictions(sel); … … 125 126 if (!turnRestrictions.isEmpty()) { 126 127 List<Relation> sel = getSelectedTurnRestrictions(); 127 for(Relation tr: turnRestrictions) { 128 for (Relation tr: turnRestrictions) { 128 129 // enforce a repaint of the respective turn restriction 129 130 int idx = getTurnRestrictionIndex(tr); 130 fireContentsChanged(this, idx,idx); 131 fireContentsChanged(this, idx, idx); 131 132 } 132 133 setSelectedTurnRestrictions(sel); … … 136 137 @Override 137 138 public void wayNodesChanged(WayNodesChangedEvent event) {/* ignore */} 139 138 140 @Override 139 141 public void nodeMoved(NodeMovedEvent event) {/* ignore */} 142 140 143 @Override 141 144 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 31 32 32 33 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); 35 36 if (Main.getLayerManager().getEditLayer() != null) { 36 37 model.setTurnRestrictions(Main.getLayerManager().getEditLayer().data.getRelations()); … … 39 40 40 41 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); 43 44 } 44 45 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionListModel.java
r32375 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 19 20 * objects in the current selection. 20 21 */ 21 public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel implements ActiveLayerChangeListener, SelectionChangedListener {22 //private static final Logger logger = Logger.getLogger(TurnRestrictionsInSelectionListModel.class.getName());22 public class TurnRestrictionsInSelectionListModel extends TurnRestrictionsListModel 23 implements ActiveLayerChangeListener, SelectionChangedListener { 23 24 24 25 public TurnRestrictionsInSelectionListModel( … … 39 40 for (OsmPrimitive parent: p.getReferrers()) { 40 41 if (isTurnRestriction(parent)) 41 turnRestrictions.add((Relation)parent); 42 turnRestrictions.add((Relation) parent); 42 43 } 43 44 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsInSelectionView.java
r32375 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 36 37 37 38 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) { 42 43 m.initFromSelection(Main.getLayerManager().getEditLayer().data.getSelected()); 43 44 } else { … … 47 48 48 49 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); 51 52 } 52 53 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/list/TurnRestrictionsListDialog.java
r32386 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 51 52 * 52 53 */ 53 public class TurnRestrictionsListDialog extends ToggleDialog{ 54 //private static final Logger logger = Logger.getLogger(TurnRestrictionsListDialog.class.getName()); 54 public class TurnRestrictionsListDialog extends ToggleDialog { 55 55 56 56 /** checkbox for switching between the two list views */ … … 97 97 */ 98 98 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)); 100 100 pnl.setBorder(null); 101 101 pnl.add(cbInSelectionOnly = new JCheckBox(tr("Only participating in selection"))); … … 104 104 + "Deselect to display all turn restrictions in the current data set.</html>")); 105 105 106 pnlContent = new JPanel(new BorderLayout(0,0)); 106 pnlContent = new JPanel(new BorderLayout(0, 0)); 107 107 pnlContent.setBorder(null); 108 pnlContent.add(pnl, 108 pnlContent.add(pnl, BorderLayout.NORTH); 109 109 110 110 actNew = new NewAction(); … … 165 165 pnlContent.remove(currentListView); 166 166 } 167 pnlContent.add(view,BorderLayout.CENTER); 167 pnlContent.add(view, BorderLayout.CENTER); 168 168 currentListView = view; 169 169 view.addListSelectionListener(actEdit); … … 197 197 * 198 198 */ 199 class EditAction extends AbstractAction implements ListSelectionListener{ 200 publicEditAction() {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")); 202 202 new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this, true); 203 203 putValue(NAME, tr("Edit")); 204 204 setEnabled(false); 205 205 } 206 206 207 protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) { 207 208 Collection<RelationMember> members = new HashSet<>(); … … 226 227 } else { 227 228 editor = new TurnRestrictionEditor( 228 TurnRestrictionsListDialog.this, layer,toEdit); 229 TurnRestrictionsListDialog.this, layer, toEdit); 229 230 manager.positionOnScreen(editor); 230 manager.register(layer, toEdit,editor); 231 manager.register(layer, toEdit, editor); 231 232 editor.setVisible(true); 232 233 } … … 243 244 244 245 public void updateEnabledState() { 245 setEnabled(currentListView!= null && currentListView.getModel().getSelectedTurnRestrictions().size() == 1); 246 setEnabled(currentListView != null && currentListView.getModel().getSelectedTurnRestrictions().size() == 1); 246 247 } 247 248 … … 259 260 class AbortException extends Exception {} 260 261 261 publicDeleteAction() {262 putValue(SHORT_DESCRIPTION,tr("Delete the selected turn restriction")); 262 DeleteAction() { 263 putValue(SHORT_DESCRIPTION, tr("Delete the selected turn restriction")); 263 264 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true); 264 265 putValue(NAME, tr("Delete")); … … 299 300 */ 300 301 class NewAction extends AbstractAction implements ActiveLayerChangeListener { 301 publicNewAction() {302 putValue(SHORT_DESCRIPTION,tr("Create a new turn restriction")); 302 NewAction() { 303 putValue(SHORT_DESCRIPTION, tr("Create a new turn restriction")); 303 304 new ImageProvider("new").getResource().attachImageIcon(this, true); 304 305 putValue(NAME, tr("New")); … … 339 340 class AbortException extends Exception {} 340 341 341 publicSelectSelectedTurnRestrictions() {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")); 343 344 new ImageProvider("selectall").getResource().attachImageIcon(this); 344 345 putValue(NAME, tr("Select in current data layer")); … … 351 352 List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions(); 352 353 if (toSelect.isEmpty()) return; 353 OsmDataLayer layer= Main.getLayerManager().getEditLayer(); 354 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 354 355 if (layer == null) return; 355 356 layer.data.setSelected(toSelect); … … 374 375 class AbortException extends Exception {} 375 376 376 publicZoomToAction() {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")); 378 379 new ImageProvider("dialogs/autoscale/selection").getResource().attachImageIcon(this); 379 380 putValue(NAME, tr("Zoom to")); … … 386 387 List<Relation> toSelect = currentListView.getModel().getSelectedTurnRestrictions(); 387 388 if (toSelect.isEmpty()) return; 388 OsmDataLayer layer= Main.getLayerManager().getEditLayer(); 389 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 389 390 if (layer == null) return; 390 391 layer.data.setSelected(toSelect); … … 412 413 if (lst.getSelectedIndices().length == 0) { 413 414 int idx = lst.locationToIndex(evt.getPoint()); 414 if (idx >=0) { 415 if (idx >= 0) { 415 416 lst.getSelectionModel().addSelectionInterval(idx, idx); 416 417 } … … 426 427 */ 427 428 class TurnRestrictionsPopupMenu extends JPopupMenu { 428 publicTurnRestrictionsPopupMenu() {429 TurnRestrictionsPopupMenu() { 429 430 add(actNew); 430 431 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.list; 2 3 … … 19 20 /** 20 21 * This is a list model for a list of turn restrictions. 21 * 22 * 22 23 */ 23 24 public class TurnRestrictionsListModel extends AbstractListModel<Relation> { … … 27 28 /** 28 29 * Creates the model 29 * 30 * 30 31 * @param selectionModel the selection model used in the turn restriction list 31 32 */ … … 36 37 /** 37 38 * Replies the turn restriction at position {@code idx} in the list. 38 * 39 * @param idx the index 39 * 40 * @param idx the index 40 41 * @return the turn restriction at position {@code idx} in the list. 41 42 */ … … 45 46 46 47 /** 47 * Sorts the turn restrictions in this model 48 * Sorts the turn restrictions in this model 48 49 */ 49 50 public void sort() { … … 53 54 NameFormatter formatter = DefaultNameFormatter.getInstance(); 54 55 56 @Override 55 57 public int compare(Relation r1, Relation r2) { 56 58 return r1.getDisplayName(formatter).compareTo(r2.getDisplayName(formatter)); … … 63 65 return !r.isDeleted() && r.isVisible() && !r.isIncomplete(); 64 66 } 65 67 66 68 /** 67 69 * 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 71 73 * @return true if the primitive {@code primitive} represents 72 74 * an OSM turn restriction; false, otherwise … … 74 76 protected boolean isTurnRestriction(OsmPrimitive primitive) { 75 77 if (primitive == null) return false; 76 if (! 78 if (!(primitive instanceof Relation)) return false; 77 79 String type = primitive.get("type"); 78 if (type == null || ! 80 if (type == null || !type.equals("restriction")) return false; 79 81 return true; 80 82 } 81 83 82 84 /** 83 85 * Populates the model with the turn restrictions in {@code turnrestrictions}. 84 * 85 * @param turnrestrictions the turn restrictions 86 * 87 * @param turnrestrictions the turn restrictions 86 88 */ 87 89 public void setTurnRestrictions(Collection<Relation> turnrestrictions) { 88 List<Relation> sel = 90 List<Relation> sel = getSelectedTurnRestrictions(); 89 91 this.turnrestrictions.clear(); 90 92 if (turnrestrictions == null) { 91 93 selectionModel.clearSelection(); 92 fireContentsChanged(this, 0,getSize());94 fireContentsChanged(this, 0, getSize()); 93 95 return; 94 96 } … … 113 115 boolean added = false; 114 116 for (OsmPrimitive p: addedPrimitives) { 115 if (! 116 continue; 117 } 118 119 Relation r = (Relation)p; 117 if (!isTurnRestriction(p)) { 118 continue; 119 } 120 121 Relation r = (Relation) p; 120 122 if (!isValid(r)) continue; 121 123 if (turnrestrictions.contains(r)) { … … 144 146 for (OsmPrimitive p: removedPrimitives) { 145 147 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; 149 151 int size = turnrestrictions.size(); 150 152 turnrestrictions.removeAll(removedTurnRestrictions); … … 157 159 } 158 160 161 @Override 159 162 public Relation getElementAt(int index) { 160 163 return turnrestrictions.get(index); 161 164 } 162 165 166 @Override 163 167 public int getSize() { 164 168 return turnrestrictions.size(); … … 173 177 public List<Relation> getSelectedNonNewRelations() { 174 178 ArrayList<Relation> ret = new ArrayList<>(); 175 for (int i =0; i<getSize();i++) {179 for (int i = 0; i < getSize(); i++) { 176 180 if (!selectionModel.isSelectedIndex(i)) { 177 181 continue; … … 193 197 public List<Relation> getSelectedTurnRestrictions() { 194 198 ArrayList<Relation> ret = new ArrayList<>(); 195 for (int i =0; i<getSize();i++) {199 for (int i = 0; i < getSize(); i++) { 196 200 if (!selectionModel.isSelectedIndex(i)) { 197 201 continue; … … 213 217 for (Relation r: sel) { 214 218 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 224 228 * 225 229 * @return index of relation (-1, if not found) … … 227 231 public int getTurnRestrictionIndex(Relation tr) { 228 232 int i = turnrestrictions.indexOf(tr); 229 if (i <0)return -1;233 if (i < 0) return -1; 230 234 return i; 231 235 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceEditor.java
r27857 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.preferences; 2 3 … … 42 43 /** 43 44 * builds the panel with the sponsoring information 44 *45 * @return46 45 */ 47 46 protected JPanel buildCreditPanel() { 48 47 JPanel pnl = new JPanel(new GridBagLayout()); 49 pnl.setBorder(BorderFactory.createEmptyBorder(5, 5,5,5));48 pnl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 50 49 GridBagConstraints gc = new GridBagConstraints(); 51 50 gc.anchor = GridBagConstraints.NORTHWEST; 52 51 gc.fill = GridBagConstraints.HORIZONTAL; 53 gc.insets = new Insets(0, 0,0, 5); 52 gc.insets = new Insets(0, 0, 0, 5); 54 53 gc.weightx = 0.0; 55 54 JLabel lbl = new JLabel(); … … 59 58 gc.gridx = 1; 60 59 gc.weightx = 1.0; 61 HtmlPanel msg =new HtmlPanel();60 HtmlPanel msg = new HtmlPanel(); 62 61 msg.setText("<html><body>" 63 62 + tr("Development of the turn restriction plugin was sponsored " … … 101 100 tp.add(buildCreditPanel()); 102 101 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")); 104 103 tp.setTitleAt(1, tr("Sponsor")); 105 104 mainPanel.add(tp, BorderLayout.CENTER); 106 105 } 107 106 107 @Override 108 108 public void addGui(PreferenceTabbedPane gui) { 109 109 JPanel tab = gui.createPreferenceTab(this); … … 111 111 } 112 112 113 @Override 113 114 public boolean ok() { 114 115 pnlIconPreferences.saveToPreferences(Main.pref); … … 124 125 } 125 126 127 @Override 126 128 public void hyperlinkUpdate(HyperlinkEvent e) { 127 129 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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.preferences; 2 3 … … 6 7 /** 7 8 * Defines the preference keys used for preferences of the turnrestrictions 8 * plugin 9 * plugin 9 10 * 10 11 */ … … 17 18 * <li><tt>set-b</tt> - the set of icons in the directory <tt>/images/types/set-b</tt></li> 18 19 * </ul> 19 * 20 * 20 21 */ 21 22 String ROAD_SIGNS = "turnrestrictions.road-signs"; 22 23 23 24 /** 24 25 * Indicates whether the Basic Editor should include a widget for for displaying 25 26 * and editing the via-objects of a turn restriction. 26 * 27 * 27 28 * Supported values are: 28 29 * <ul> … … 32 33 */ 33 34 String SHOW_VIAS_IN_BASIC_EDITOR = "turnrestrictions.show-vias-in-basic-editor"; 34 35 35 36 /** 36 37 * The shortcut which triggers creating a new or editing and existing turn … … 38 39 * If missing, the default value "ctrl shift T" is assumed. 39 40 */ 40 String EDIT_SHORTCUT= "turnrestrictions.edit-shortcut"; 41 String EDIT_SHORTCUT = "turnrestrictions.edit-shortcut"; 41 42 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferencesPanel.java
r29854 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.preferences; 2 3 … … 25 26 * IconPreferencePanel allows to configure a set of road sign icons to be 26 27 * used in the turnrestrictions plugin. 27 * 28 * 28 29 */ 29 30 public class PreferencesPanel extends VerticallyScrollablePanel { … … 33 34 private ButtonGroup bgIconSet; 34 35 private JCheckBox cbShowViaListInBasicEditor; 35 36 36 37 protected JPanel buildShowViaListInBasicEditorPanel() { 37 38 JPanel pnl = new JPanel(new GridBagLayout()); … … 42 43 gc.gridx = 0; 43 44 gc.gridy = 0; 44 45 45 46 HtmlPanel msg = new HtmlPanel(); 46 47 msg.setText("<html><body>" … … 53 54 ); 54 55 pnl.add(msg, gc); 55 56 56 57 gc.gridy++; 57 58 pnl.add(cbShowViaListInBasicEditor = new JCheckBox(tr("Display and edit list of via-objects in the Basic Editor")), gc); 58 59 return pnl; 59 60 } 60 61 61 62 /** 62 63 * Builds the panel for the icon set "set-a" 63 *64 * @return65 64 */ 66 65 protected JPanel buildSetAPanel() { … … 72 71 gc.gridx = 0; 73 72 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 77 76 JPanel icons = new JPanel(new FlowLayout(FlowLayout.LEFT)); 78 for (TurnRestrictionType type: TurnRestrictionType.values()){ 77 for (TurnRestrictionType type: TurnRestrictionType.values()) { 79 78 JLabel lbl = new JLabel(); 80 79 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 84 83 gc.gridy = 1; 85 gc.insets = new Insets(0, 20,0,0);84 gc.insets = new Insets(0, 20, 0, 0); 86 85 pnl.add(icons, gc); 87 return pnl; 88 } 89 86 return pnl; 87 } 88 90 89 /** 91 90 * Builds the panel for the icon set "set-b" 92 *93 * @return94 91 */ 95 92 protected JPanel buildSetBPanel() { … … 101 98 gc.gridx = 0; 102 99 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 106 103 JPanel icons = new JPanel(new FlowLayout(FlowLayout.LEFT)); 107 for (TurnRestrictionType type: TurnRestrictionType.values()){ 104 for (TurnRestrictionType type: TurnRestrictionType.values()) { 108 105 JLabel lbl = new JLabel(); 109 106 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 113 110 gc.gridy = 1; 114 gc.insets = new Insets(0, 20,0,0);111 gc.insets = new Insets(0, 20, 0, 0); 115 112 pnl.add(icons, gc); 116 return pnl; 117 } 118 113 return pnl; 114 } 115 119 116 /** 120 117 * Builds the message panel at the top 121 *122 * @return123 118 */ 124 119 protected JPanel buildMessagePanel() { … … 131 126 return pnl; 132 127 } 133 128 134 129 /** 135 130 * Builds the UI 136 * 137 * @return 138 */ 139 protected void build() { 131 */ 132 protected void build() { 140 133 setLayout(new GridBagLayout()); 141 134 GridBagConstraints gc = new GridBagConstraints(); … … 145 138 gc.gridx = 0; 146 139 gc.gridy = 0; 147 140 148 141 add(buildMessagePanel(), gc); 149 142 gc.gridy++; … … 152 145 add(buildSetBPanel(), gc); 153 146 gc.gridy++; 154 add(new JSeparator(), gc); 147 add(new JSeparator(), gc); 155 148 gc.gridy++; 156 149 add(buildShowViaListInBasicEditorPanel(), gc); … … 158 151 add(new JSeparator(), gc); 159 152 gc.gridy++; 160 153 161 154 // filler - just grab remaining space 162 155 gc.gridy++; 163 156 gc.fill = GridBagConstraints.BOTH; 164 157 gc.weighty = 1.0; 165 add(new JPanel(), gc); 166 158 add(new JPanel(), gc); 159 167 160 bgIconSet = new ButtonGroup(); 168 161 bgIconSet.add(rbSetA); 169 162 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 174 167 /** 175 168 * Initializes the UI from the current settings in the JOSM preferences 176 169 * {@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) { 181 174 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)); 184 179 set = "set-a"; 185 180 } 186 if (set.equals("set-a")){ 181 if (set.equals("set-a")) { 187 182 rbSetA.setSelected(true); 188 183 } else { 189 184 rbSetB.setSelected(true); 190 185 } 191 186 192 187 boolean b = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false); 193 188 cbShowViaListInBasicEditor.setSelected(b); 194 189 } 195 190 196 191 /** 197 192 * 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) { 202 197 prefs.put(PreferenceKeys.ROAD_SIGNS, rbSetA.isSelected() ? "set-a" : "set-b"); 203 198 prefs.put(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, cbShowViaListInBasicEditor.isSelected()); 204 199 } 205 200 206 201 public PreferencesPanel() { 207 202 build(); 208 } 203 } 209 204 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IdenticalTurnRestrictionLegsError.java
r23593 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 12 13 /** 13 14 * Issue when the 'from' and 'to' leg are identical. 14 * 15 * 15 16 */ 16 public class IdenticalTurnRestrictionLegsError extends Issue{ 17 public class IdenticalTurnRestrictionLegsError extends Issue { 17 18 private OsmPrimitive leg; 18 19 19 20 public IdenticalTurnRestrictionLegsError(IssuesModel parent, OsmPrimitive leg) { 20 21 super(parent, Severity.ERROR); … … 26 27 27 28 @Override 28 public String getText() { 29 public String getText() { 30 // CHECKSTYLE.OFF: LineLength 29 31 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>. " 30 32 + "In a turn restriction, the way with role <tt>from</tt> should be different from the way with role <tt>to</tt>, though.", 31 33 leg.getDisplayName(DefaultNameFormatter.getInstance()) 32 ); 34 ); 35 // CHECKSTYLE.ON: LineLength 33 36 } 34 37 35 38 class DeleteFromAction extends AbstractAction { 36 publicDeleteFromAction() {39 DeleteFromAction() { 37 40 putValue(NAME, tr("Delete ''from''")); 38 41 putValue(SHORT_DESCRIPTION, tr("Removes the member with role ''from''")); 39 42 } 43 44 @Override 40 45 public void actionPerformed(ActionEvent e) { 41 getIssuesModel().getEditorModel().getRelationMemberEditorModel().setFromPrimitive(null); 42 } 46 getIssuesModel().getEditorModel().getRelationMemberEditorModel().setFromPrimitive(null); 47 } 43 48 } 44 49 45 50 class DeleteToAction extends AbstractAction { 46 publicDeleteToAction() {51 DeleteToAction() { 47 52 putValue(NAME, tr("Delete ''to''")); 48 53 putValue(SHORT_DESCRIPTION, tr("Removes the member with role ''to''")); 49 54 } 55 56 @Override 50 57 public void actionPerformed(ActionEvent e) { 51 getIssuesModel().getEditorModel().getRelationMemberEditorModel().setToPrimitive(null); 52 } 58 getIssuesModel().getEditorModel().getRelationMemberEditorModel().setToPrimitive(null); 59 } 53 60 } 54 61 55 62 class FixInEditorAction extends AbstractAction { 56 publicFixInEditorAction() {63 FixInEditorAction() { 57 64 putValue(NAME, tr("Fix in editor")); 58 65 putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually choose members with roles ''from'' and ''to''")); 59 66 } 67 68 @Override 60 69 public void actionPerformed(ActionEvent e) { 61 getIssuesModel().getNavigationControler().gotoBasicEditor(); 62 } 70 getIssuesModel().getNavigationControler().gotoBasicEditor(); 71 } 63 72 } 64 73 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IllegalRestrictionTypeError.java
r23192 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 12 13 * Issue when the restriction type isn't a standard value. Can't be fixed 13 14 * automatically, user is directed to the Basic editor. 14 * 15 * 15 16 */ 16 public class IllegalRestrictionTypeError extends Issue{ 17 public class IllegalRestrictionTypeError extends Issue { 17 18 private String value; 18 19 19 20 public IllegalRestrictionTypeError(IssuesModel parent, String value) { 20 21 super(parent, Severity.ERROR); … … 24 25 25 26 @Override 26 public String getText() { 27 public String getText() { 27 28 return tr("This turn restriction uses a non-standard restriction type <tt>{0}</tt> for the tag key <tt>restriction</tt>. " 28 29 + "It is recommended to use standard values only. Please select one in the Basic editor.", 29 30 value 30 ); 31 ); 31 32 } 32 33 33 34 class FixInEditorAction extends AbstractAction { 34 publicFixInEditorAction() {35 FixInEditorAction() { 35 36 putValue(NAME, tr("Fix in editor")); 36 37 putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually choose a turn restriction type")); 37 38 } 39 40 @Override 38 41 public void actionPerformed(ActionEvent e) { 39 getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE); 40 } 42 getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE); 43 } 41 44 } 42 45 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IntersectionMissingAsViaError.java
r26796 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 15 16 16 17 /** 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 * 20 20 */ 21 public class IntersectionMissingAsViaError extends Issue{ 21 public class IntersectionMissingAsViaError extends Issue { 22 22 private Way from; 23 23 private Way to; 24 24 private Node intersect; 25 25 26 26 public IntersectionMissingAsViaError(IssuesModel parent, Way from, Way to, Node intersect) { 27 27 super(parent, Severity.ERROR); … … 34 34 35 35 @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> " 38 39 + "intersect at node <span class=\"object-name\">{2}</span> but this node isn''t a <strong>via</strong>-object.<br> " 39 40 + "It is recommended to set it as unique <strong>via</strong>-object.", … … 42 43 this.intersect.getDisplayName(DefaultNameFormatter.getInstance()) 43 44 ); 44 return msg;45 // CHECKSTYLE.ON: LineLength 45 46 } 46 47 47 48 class SetVia extends AbstractAction { 48 publicSetVia() {49 SetVia() { 49 50 putValue(NAME, tr("Set via-Object")); 50 51 putValue(SHORT_DESCRIPTION, tr("Replaces the currently configured via-objects with the node at the intersection")); 51 52 } 53 54 @Override 52 55 public void actionPerformed(ActionEvent e) { 53 56 getIssuesModel().getEditorModel().setVias(Collections.<OsmPrimitive>singletonList(intersect)); 54 } 57 } 55 58 } 56 59 57 60 class FixInEditorAction extends AbstractAction { 58 publicFixInEditorAction() {61 FixInEditorAction() { 59 62 putValue(NAME, tr("Fix in editor")); 60 63 putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually fix the list of via-objects")); 61 64 } 65 66 @Override 62 67 public void actionPerformed(ActionEvent e) { 63 getIssuesModel().getNavigationControler().gotoBasicEditor(BasicEditorFokusTargets.VIA); 64 } 68 getIssuesModel().getNavigationControler().gotoBasicEditor(BasicEditorFokusTargets.VIA); 69 } 65 70 } 66 71 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/Issue.java
r30737 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 10 11 11 12 /** 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 * 14 15 * The issue has a {@see Severity}. It is described to the user with a HTML formatted 15 16 * text (see {@see #getText()}) and it suggests a list of possible actions to fix 16 17 * the issue (see {@see #getActions()}). 17 * 18 * 18 19 */ 19 abstract publicclass Issue {20 public abstract class Issue { 20 21 /** the parent model for this issue */ 21 22 protected IssuesModel parent; 22 23 protected Severity severity; 23 24 protected final ArrayList<Action> actions = new ArrayList<>(); 24 25 25 26 /** 26 27 * Creates a new issue associated with a parent model. Severity is 27 28 * initialized to {@see Severity#WARNING}. 28 * 29 * 29 30 * @param parent the parent model. Must not be null. 30 31 * @throws IllegalArgumentException thrown if parent is null 31 32 */ 32 public Issue(IssuesModel parent) throws IllegalArgumentException{ 33 public Issue(IssuesModel parent) throws IllegalArgumentException { 33 34 CheckParameterUtil.ensureParameterNotNull(parent, "parent"); 34 35 this.parent = parent; 35 36 this.severity = Severity.WARNING; 36 37 } 37 38 38 39 /** 39 40 * Creates a new issue of severity {@code severity} associated with 40 41 * the parent model {@code parent}. 41 * 42 * 42 43 * @param parent the parent model. Must not be null. 43 44 * @param severity the severity. Must not be null. 44 45 * @throws IllegalArgumentException thrown if parent is null 45 * @throws IllegalArgumentException thrown if severity is null 46 * @throws IllegalArgumentException thrown if severity is null 46 47 */ 47 public Issue(IssuesModel parent, Severity severity){ 48 public Issue(IssuesModel parent, Severity severity) { 48 49 CheckParameterUtil.ensureParameterNotNull(parent, "parent"); 49 50 CheckParameterUtil.ensureParameterNotNull(severity, "severity"); … … 53 54 54 55 /** 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 58 59 */ 59 60 public IssuesModel getIssuesModel() { … … 62 63 63 64 /** 64 * Replies the severity of this issue 65 * 66 * @return the severity 65 * Replies the severity of this issue 66 * 67 * @return the severity 67 68 */ 68 69 public Severity getSeverity() { … … 71 72 72 73 /** 73 * Sets the severity of this issue. 74 * 74 * Sets the severity of this issue. 75 * 75 76 * @param severity the severity. Must not be null. 76 77 * @throws IllegalArgumentException thrown if severity is null … … 83 84 /** 84 85 * Replies the HTML formatted description of the issue. The text should neither include 85 * the <html>, nor the <body> tag. 86 * 86 * the <html>, nor the <body> tag. 87 * 87 88 * @return the HTML formatted description of the issue. 88 89 */ 89 90 public abstract String getText(); 90 91 91 92 /** 92 93 * Replies a list of actions which can be applied to this issue in order to fix 93 94 * it. The default implementation replies an empty list. 94 * 95 * 95 96 * @return a list of action 96 97 */ -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssueView.java
r30454 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 24 25 * An IssueView is a view on an individual {@see Issue}. 25 26 */ 26 public class IssueView extends JPanel{ 27 public class IssueView extends JPanel { 27 28 28 29 private HtmlPanel pnlMessage; … … 30 31 private Issue issue; 31 32 private JLabel lblIcon; 32 33 33 34 /** 34 35 * Builds the style sheet used in the internal help browser … … 37 38 */ 38 39 protected void initStyleSheet(HtmlPanel view) { 39 StyleSheet ss = ((HTMLEditorKit)view.getEditorPane().getEditorKit()).getStyleSheet(); 40 StyleSheet ss = ((HTMLEditorKit) view.getEditorPane().getEditorKit()).getStyleSheet(); 40 41 ss.addRule("em {font-style: italic}"); 41 42 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;}"); 43 44 } 44 45 45 46 protected void build() { 46 47 setLayout(new GridBagLayout()); 47 48 setBackground(Color.WHITE); 48 49 setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1)); 49 50 // add the icon for the severity 50 51 // add the icon for the severity 51 52 GridBagConstraints gc = new GridBagConstraints(); 52 53 gc.anchor = GridBagConstraints.NORTHWEST; … … 57 58 gc.gridx = 0; 58 59 gc.gridy = 0; 59 gc.insets = new Insets(2, 2,2,2);60 gc.insets = new Insets(2, 2, 2, 2); 60 61 add(lblIcon = new JLabel(), gc); 61 62 lblIcon.setVerticalAlignment(SwingConstants.TOP); 62 63 lblIcon.setHorizontalAlignment(SwingConstants.CENTER); 63 lblIcon.setBorder(BorderFactory.createEmptyBorder(2, 2,2,2));64 lblIcon.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 64 65 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); 67 68 gc.anchor = GridBagConstraints.NORTHWEST; 68 69 gc.fill = GridBagConstraints.BOTH; … … 77 78 pnlMessage.setText("<html><body>" + issue.getText() + "</html></bod>"); 78 79 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 81 82 if (!issue.getActions().isEmpty()) { 82 83 pnlActions = new JPanel(new FlowLayout(FlowLayout.LEFT)); 83 84 pnlActions.setBackground(Color.WHITE); 84 for (Action action: issue.getActions()){ 85 for (Action action: issue.getActions()) { 85 86 JButton btn = new JButton(action); 86 pnlActions.add(btn); 87 pnlActions.add(btn); 87 88 } 88 89 gc.gridx = 1; 90 gc.gridy = 1; 89 90 gc.gridx = 1; 91 gc.gridy = 1; 91 92 gc.fill = GridBagConstraints.HORIZONTAL; 92 93 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: 99 100 lblIcon.setIcon(ImageProvider.get("warning-small")); 100 101 break; … … 102 103 lblIcon.setIcon(ImageProvider.get("error")); 103 104 break; 104 } 105 } 105 106 } 106 107 107 108 /** 108 109 * Creates an issue view for an issue. 109 * 110 * 110 111 * @param issue the issue. Must not be null. 111 112 * @throws IllegalArgumentException thrown if issue is null. 112 113 */ 113 public IssueView(Issue issue) throws IllegalArgumentException{ 114 public IssueView(Issue issue) throws IllegalArgumentException { 114 115 CheckParameterUtil.ensureParameterNotNull(issue, "issue"); 115 116 this.issue = issue; 116 build(); 117 build(); 117 118 } 118 119 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java
r30737 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 26 27 * <p>IssuesModel is a model for an observable list of {@code Issues} 27 28 * related to turn restriction.</p> 28 * 29 * 29 30 * <p>It is also an {@link Observer} to an {@link TurnRestrictionEditorModel} 30 31 * and populates itself with issues it derives from the current state 31 32 * in the {@link TurnRestrictionEditorModel}.</p> 32 * 33 * 33 34 */ 34 public class IssuesModel extends Observable implements Observer{ 35 public class IssuesModel extends Observable implements Observer { 35 36 private final ArrayList<Issue> issues = new ArrayList<>(); 36 37 private TurnRestrictionEditorModel editorModel; 37 38 /** 39 * Creates the model 40 * 38 39 /** 40 * Creates the model 41 * 41 42 * @param editorModel the editor model. Must not be null. 42 43 * @throws IllegalArgumentException thrown if controler is null 43 44 */ 44 public IssuesModel(TurnRestrictionEditorModel editorModel) throws IllegalArgumentException{ 45 public IssuesModel(TurnRestrictionEditorModel editorModel) throws IllegalArgumentException { 45 46 CheckParameterUtil.ensureParameterNotNull(editorModel, "editorModel"); 46 47 this.editorModel = editorModel; 47 48 this.editorModel.addObserver(this); 48 49 } 49 50 50 51 /** 51 52 * 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) { 57 58 this.issues.clear(); 58 if (issues != null){ 59 if (issues != null) { 59 60 this.issues.addAll(issues); 60 61 } … … 62 63 notifyObservers(); 63 64 } 64 65 65 66 /** 66 67 * Replies the (unmodifiable) list of issues in this model. 67 * 68 * 68 69 * @return the (unmodifiable) list of issues in this model. 69 70 */ … … 71 72 return Collections.unmodifiableList(issues); 72 73 } 73 74 /** 75 * Replies the turn restriction editor model 76 * 77 * @return 74 75 /** 76 * Replies the turn restriction editor model 78 77 */ 79 78 public TurnRestrictionEditorModel getEditorModel() { 80 79 return editorModel; 81 80 } 82 81 83 82 /** 84 83 * Populates this model with issues derived from the state of the 85 84 * turn restriction editor model. If {@code editorModel} is null, the 86 85 * list of issues is cleared. 87 * 88 * @param editorModel the editor model. 86 * 87 * @param editorModel the editor model. 89 88 */ 90 89 public void populate() { … … 100 99 notifyObservers(); 101 100 } 102 103 /** 104 * Checks whether there are required tags missing. 105 * 106 * @param editorModel 101 102 /** 103 * Checks whether there are required tags missing. 107 104 */ 108 105 protected void checkTags(TurnRestrictionEditorModel editorModel) { 109 106 TagEditorModel tagEditorModel = editorModel.getTagEditorModel(); 110 107 TagModel tag = tagEditorModel.get("type"); 111 108 112 109 // missing marker tag for a turn restriction 113 if (tag == null || ! 110 if (tag == null || !tag.getValue().trim().equals("restriction")) { 114 111 issues.add(new RequiredTagMissingError(this, "type", "restriction")); 115 112 } 116 113 117 114 // missing or illegal restriction type ? 118 115 tag = tagEditorModel.get("restriction"); … … 123 120 } 124 121 125 // non-standard value for the 'except' tag? 122 // non-standard value for the 'except' tag? 126 123 ExceptValueModel except = getEditorModel().getExcept(); 127 124 if (!except.isStandard()) { … … 129 126 } 130 127 } 131 128 132 129 /** 133 130 * Checks various data integrity restriction for the relation member with 134 131 * role 'from'. 135 * 132 * 136 133 */ 137 134 protected void checkFromLeg(TurnRestrictionEditorModel editorModel) { 138 135 Set<OsmPrimitive> froms = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM); 139 if (froms.isEmpty()){ 136 if (froms.isEmpty()) { 140 137 issues.add(new MissingTurnRestrictionLegError(this, TurnRestrictionLegRole.FROM)); 141 138 return; 142 } else if (froms.size() > 1){ 139 } else if (froms.size() > 1) { 143 140 issues.add(new MultipleTurnRestrictionLegError(this, TurnRestrictionLegRole.FROM, froms.size())); 144 141 return; 145 } 142 } 146 143 OsmPrimitive p = froms.iterator().next(); 147 if (! 144 if (!(p instanceof Way)) { 148 145 issues.add(new WrongTurnRestrictionLegTypeError(this, TurnRestrictionLegRole.FROM, p)); 149 146 } 150 147 } 151 148 152 149 /** 153 150 * Checks various data integrity restriction for the relation member with 154 151 * role 'to'. 155 * 152 * 156 153 */ 157 154 protected void checkToLeg(TurnRestrictionEditorModel editorModel) { 158 155 Set<OsmPrimitive> toLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.TO); 159 if (toLegs.isEmpty()){ 156 if (toLegs.isEmpty()) { 160 157 issues.add(new MissingTurnRestrictionLegError(this, TurnRestrictionLegRole.TO)); 161 158 return; 162 } else if (toLegs.size() > 1){ 159 } else if (toLegs.size() > 1) { 163 160 issues.add(new MultipleTurnRestrictionLegError(this, TurnRestrictionLegRole.TO, toLegs.size())); 164 161 return; 165 } 162 } 166 163 OsmPrimitive p = toLegs.iterator().next(); 167 if (! 164 if (!(p instanceof Way)) { 168 165 issues.add(new WrongTurnRestrictionLegTypeError(this, TurnRestrictionLegRole.TO, p)); 169 166 } 170 167 } 171 168 172 169 /** 173 170 * 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) { 178 173 Set<OsmPrimitive> toLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.TO); 179 174 Set<OsmPrimitive> fromLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM); 180 175 if (toLegs.size() != 1 || fromLegs.size() != 1) return; 181 176 182 177 OsmPrimitive from = fromLegs.iterator().next(); 183 178 OsmPrimitive to = toLegs.iterator().next(); 184 185 if (! 186 if (! 187 if (from.equals(to) && ! 179 180 if (!(from instanceof Way)) return; 181 if (!(to instanceof Way)) return; 182 if (from.equals(to) && !"no_u_turn".equals(editorModel.getRestrictionTagValue())) { 188 183 // identical from and to allowed for "no_u_turn" only 189 184 // 190 185 issues.add(new IdenticalTurnRestrictionLegsError(this, from)); 191 } 192 } 193 186 } 187 } 188 194 189 /** 195 190 * Checks the 'via' members in the turn restriction 196 * 191 * 197 192 * @param editorModel the editor model 198 193 */ 199 protected void checkVias(TurnRestrictionEditorModel editorModel){ 194 protected void checkVias(TurnRestrictionEditorModel editorModel) { 200 195 Set<OsmPrimitive> toLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.TO); 201 196 Set<OsmPrimitive> fromLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM); 202 197 // we only check vias if 'to' and 'from' are already OK 203 198 if (toLegs.size() != 1 || fromLegs.size() != 1) return; 204 if (! 205 if (! 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) { 211 206 if (!editorModel.getVias().contains(intersect)) { 212 207 issues.add(new IntersectionMissingAsViaError(this, from, to, intersect)); … … 214 209 if (isInnerNode(from, intersect) && isInnerNode(to, intersect)) { 215 210 issues.add(new TurnRestrictionLegSplitRequiredError(this, from, to)); 216 } else if (isInnerNode(from, intersect) && ! 211 } else if (isInnerNode(from, intersect) && !isInnerNode(to, intersect)) { 217 212 issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect)); 218 213 } else if (!isInnerNode(from, intersect) && isInnerNode(to, intersect)) { … … 220 215 } 221 216 } else { 222 if (editorModel.getVias().isEmpty() && ! 217 if (editorModel.getVias().isEmpty() && !from.equals(to)) { 223 218 // the two turn restriction legs aren't connected and we don't have configured 224 // via objects 219 // via objects 225 220 issues.add(new MissingViaError(this)); 226 221 } 227 } 228 } 229 222 } 223 } 224 230 225 public NavigationControler getNavigationControler() { 231 226 return editorModel.getNavigationControler(); 232 227 } 233 228 234 229 public int getNumWarnings() { 235 230 int ret = 0; 236 for (Issue issue: issues){ 231 for (Issue issue: issues) { 237 232 if (issue.getSeverity().equals(Severity.WARNING)) ret++; 238 233 } … … 242 237 public int getNumErrors() { 243 238 int ret = 0; 244 for (Issue issue: issues){ 239 for (Issue issue: issues) { 245 240 if (issue.getSeverity().equals(Severity.ERROR)) ret++; 246 241 } … … 251 246 /* interface Observer */ 252 247 /* ------------------------------------------------------------------------------------- */ 248 @Override 253 249 public void update(Observable o, Object arg) { 254 populate(); 250 populate(); 255 251 } 256 252 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesView.java
r29854 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 15 16 * IssuesView provides a view on a {@see IssuesModel}. 16 17 */ 17 public class IssuesView extends VerticallyScrollablePanel implements Observer{ 18 // staticprivate final Logger logger = Logger.getLogger(IssuesView.class.getName());19 18 public class IssuesView extends VerticallyScrollablePanel implements Observer { 19 //private static final Logger logger = Logger.getLogger(IssuesView.class.getName()); 20 20 21 /** the issues model */ 21 22 private IssuesModel model; 22 23 protected void build(){ 23 24 protected void build() { 24 25 setLayout(new GridBagLayout()); 25 26 } 26 27 27 28 /** 28 * Creates the view 29 * 29 * Creates the view 30 * 30 31 * @param model the model. Must not be null. 31 32 * @exception IllegalArgumentException thrown if model is null 32 33 */ 33 public IssuesView(IssuesModel model) throws IllegalArgumentException{ 34 public IssuesView(IssuesModel model) throws IllegalArgumentException { 34 35 CheckParameterUtil.ensureParameterNotNull(model, "model"); 35 36 this.model = model; … … 38 39 HelpUtil.setHelpContext(this, HelpUtil.ht("/Plugin/TurnRestrictions#ErrorsAndWarnings")); 39 40 } 40 41 41 42 /** 42 43 * Refreshes the view with the current state in the model … … 44 45 public void refresh() { 45 46 removeAll(); 46 if (! 47 if (!model.getIssues().isEmpty()) { 47 48 GridBagConstraints gc = new GridBagConstraints(); 48 49 gc.anchor = GridBagConstraints.NORTHWEST; … … 52 53 gc.gridx = 0; 53 54 gc.gridy = 0; 54 for (Issue issue: model.getIssues()){ 55 for (Issue issue: model.getIssues()) { 55 56 add(new IssueView(issue), gc); 56 57 gc.gridy++; 57 58 } 58 59 // filler - grabs remaining space 59 gc.weighty = 1.0; 60 gc.weighty = 1.0; 60 61 add(new JPanel(), gc); 61 62 } … … 66 67 /* interface Observer */ 67 68 /* ------------------------------------------------------------------------------- */ 69 @Override 68 70 public void update(Observable o, Object arg) { 69 refresh(); 71 refresh(); 70 72 } 71 73 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingRestrictionTypeError.java
r23192 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 12 13 * Issue when the restriction type is missing. Can't be fixed automatically, user 13 14 * is redirected to the Basic Editor. 14 * 15 * 15 16 */ 16 public class MissingRestrictionTypeError extends Issue{ 17 17 public class MissingRestrictionTypeError extends Issue { 18 18 19 public MissingRestrictionTypeError(IssuesModel parent) { 19 20 super(parent, Severity.ERROR); … … 23 24 @Override 24 25 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."); 26 27 } 27 28 28 29 class FixInEditorAction extends AbstractAction { 29 publicFixInEditorAction() {30 FixInEditorAction() { 30 31 putValue(NAME, tr("Fix in editor")); 31 32 putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and manually choose a turn restriction type")); 32 33 } 34 35 @Override 33 36 public void actionPerformed(ActionEvent e) { 34 getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE); 35 } 37 getIssuesModel().getNavigationControler().gotoBasicEditor(NavigationControler.BasicEditorFokusTargets.RESTRICION_TYPE); 38 } 36 39 } 37 40 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingTurnRestrictionLegError.java
r29854 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 14 15 * A member with role 'from' or 'to' is missing. Can't be fixed automatically. 15 16 * Redirect the user to the Basic editor panel. 16 * 17 * 17 18 */ 18 19 public class MissingTurnRestrictionLegError extends Issue { … … 20 21 21 22 /** 22 * Creates the issue. 23 * 24 * @param parent the parent model 23 * Creates the issue. 24 * 25 * @param parent the parent model 25 26 * @param role the role of the missing way 26 27 */ … … 34 35 public String getText() { 35 36 String msg = ""; 36 switch(role){ 37 case FROM: 37 switch(role) { 38 case FROM: 38 39 msg = tr("A way with role <tt>from</tt> is required in a turn restriction."); 39 40 break; 40 case TO: 41 case TO: 41 42 msg = tr("A way with role <tt>to</tt> is required in a turn restriction."); 42 43 break; … … 47 48 48 49 class FixAction extends AbstractAction { 49 publicFixAction() {50 FixAction() { 50 51 putValue(NAME, tr("Add in editor")); 51 switch(role){ 52 switch(role) { 52 53 case FROM: 53 54 putValue(SHORT_DESCRIPTION, tr("Add a way with role ''from''")); … … 55 56 case TO: 56 57 putValue(SHORT_DESCRIPTION, tr("Add a way with role ''to''")); 57 break; 58 } 58 break; 59 } 59 60 } 61 62 @Override 60 63 public void actionPerformed(ActionEvent e) { 61 switch(role){ 64 switch(role) { 62 65 case FROM: 63 66 getIssuesModel().getNavigationControler().gotoBasicEditor(FROM); … … 65 68 case TO: 66 69 getIssuesModel().getNavigationControler().gotoBasicEditor(TO); 67 break; 68 } 69 } 70 break; 71 } 72 } 70 73 } 71 74 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingViaError.java
r30365 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 8 9 9 10 /** 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 * 13 14 */ 14 15 public class MissingViaError extends Issue { … … 21 22 @Override 22 23 public String getText() { 23 String msg = 24 String msg = 24 25 tr("The two ways participating in the turn restriction <strong>aren''t connected.</strong>") 25 26 + "<p>" … … 29 30 30 31 class FixAction extends AbstractAction { 31 publicFixAction() {32 FixAction() { 32 33 putValue(NAME, tr("Fix in editor")); 33 34 putValue(SHORT_DESCRIPTION, tr("Go to the Advanced Editor and add via objects")); 34 35 } 36 37 @Override 35 38 public void actionPerformed(ActionEvent e) { 36 39 getIssuesModel().getNavigationControler().gotoAdvancedEditor(); 37 } 40 } 38 41 } 39 42 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MultipleTurnRestrictionLegError.java
r23192 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 11 12 /** 12 13 * Issue when a turn restriction has multiple members with role 'from' or 'to'. 13 * 14 * 14 15 */ 15 16 public class MultipleTurnRestrictionLegError extends Issue { 16 17 private TurnRestrictionLegRole role; 17 18 private int numLegs; 18 19 19 20 /** 20 21 * 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 24 25 * @param numLegs the number of legs 25 26 */ … … 33 34 @Override 34 35 public String getText() { 35 switch(role){ 36 case FROM: 36 switch(role) { 37 case FROM: 37 38 return tr("A turn restriction requires exactly one way with role <tt>from</tt>. " 38 39 + "This turn restriction has {0} ways in this role. Please remove " … … 41 42 numLegs -1 42 43 ); 43 case TO: 44 case TO: 44 45 return tr("A turn restriction requires exactly one way with role <tt>to</tt>. " 45 46 + "This turn restriction has {0} ways in this role. Please remove " … … 53 54 54 55 class FixAction extends AbstractAction { 55 publicFixAction() {56 FixAction() { 56 57 putValue(NAME, tr("Fix in editor")); 57 58 putValue(SHORT_DESCRIPTION, tr("Go to the Advanced Editor and remove the members")); 58 59 } 60 61 @Override 59 62 public void actionPerformed(ActionEvent e) { 60 63 getIssuesModel().getNavigationControler().gotoAdvancedEditor(); 61 } 64 } 62 65 } 63 66 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/NonStandardExceptWarning.java
r23192 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 11 12 /** 12 13 * Issue when the 'except' tag consists of non-standard values 13 * 14 * 14 15 */ 15 public class NonStandardExceptWarning extends Issue{ 16 public class NonStandardExceptWarning extends Issue { 16 17 private ExceptValueModel value; 17 18 public NonStandardExceptWarning(IssuesModel parent, ExceptValueModel value) { 18 19 super(parent, Severity.WARNING); 19 20 actions.add(new FixInEditorAction()); 20 this.value 21 this.value = value; 21 22 } 22 23 23 24 @Override 24 public String getText() { 25 public String getText() { 25 26 return tr("The tag <tt>except</tt> has the non-standard value <tt>{0}</tt>. " 26 27 + "It is recommended to use standard values for <tt>except</tt> only.", 27 28 value.getValue() 28 ); 29 ); 29 30 } 30 31 31 32 class FixInEditorAction extends AbstractAction { 32 publicFixInEditorAction() {33 FixInEditorAction() { 33 34 putValue(NAME, tr("Fix in editor")); 34 35 putValue(SHORT_DESCRIPTION, tr("Go to Basic Editor and select standard vehicle type based exceptions")); 35 36 } 37 38 @Override 36 39 public void actionPerformed(ActionEvent e) { 37 getIssuesModel().getNavigationControler().gotoBasicEditor(); 38 } 40 getIssuesModel().getNavigationControler().gotoBasicEditor(); 41 } 39 42 } 40 43 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/RequiredTagMissingError.java
r30454 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 14 15 */ 15 16 public class RequiredTagMissingError extends Issue { 16 // staticprivate final Logger logger = Logger.getLogger(RequiredTagMissingError.class.getName());17 //private static final Logger logger = Logger.getLogger(RequiredTagMissingError.class.getName()); 17 18 private String tagKey; 18 19 private String tagValue; 19 20 20 21 /** 21 * Create the issue 22 * 22 * Create the issue 23 * 23 24 * @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 26 27 */ 27 28 public RequiredTagMissingError(IssuesModel parent, String tagKey, String tagValue) { … … 33 34 34 35 @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.", 37 38 this.tagKey, 38 39 this.tagValue … … 41 42 42 43 private class AddTagAction extends AbstractAction { 43 publicAddTagAction(){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)); 46 47 } 47 48 49 @Override 48 50 public void actionPerformed(ActionEvent e) { 49 51 TagEditorModel model = getIssuesModel().getEditorModel().getTagEditorModel(); 50 52 TagModel t = model.get(tagKey); 51 if (t == null){ 53 if (t == null) { 52 54 t = new TagModel(tagKey, tagValue); 53 55 model.prepend(t); 54 } 55 } 56 } 57 } 56 58 } 57 59 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/Severity.java
r23192 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/TurnRestrictionLegSplitRequiredError.java
r30454 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 26 27 * 27 28 */ 28 public class TurnRestrictionLegSplitRequiredError extends Issue{ 29 //static private final Logger logger = Logger.getLogger(TurnRestrictionLegSplitRequiredError.class.getName()); 30 29 public class TurnRestrictionLegSplitRequiredError extends Issue { 30 31 31 private TurnRestrictionLegRole role; 32 32 private Way from; 33 33 private Way to; 34 34 private Node intersect; 35 35 36 36 /** 37 37 * <p>Creates the issue for a pair of ways {@code from} and {@code to} which intersect 38 38 * at node {@code intersect}.</p> 39 * 40 * @param parent the parent model 39 * 40 * @param parent the parent model 41 41 * @param from the way with role "from" 42 42 * @param to the way with role "to" 43 * @param intersect the intersection node 43 * @param intersect the intersection node 44 44 */ 45 public TurnRestrictionLegSplitRequiredError(IssuesModel parent, Way from, Way to){ 45 public TurnRestrictionLegSplitRequiredError(IssuesModel parent, Way from, Way to) { 46 46 super(parent, Severity.ERROR); 47 47 CheckParameterUtil.ensureParameterNotNull(from, "from"); 48 48 CheckParameterUtil.ensureParameterNotNull(to, "to"); 49 50 intersect= TurnRestrictionBuilder.getUniqueCommonNode(from, to); 49 50 intersect = TurnRestrictionBuilder.getUniqueCommonNode(from, to); 51 51 if (intersect == null) 52 52 throw new IllegalArgumentException("exactly one intersecting node required"); 53 53 54 54 this.from = from; 55 55 this.to = to; … … 79 79 public String getText() { 80 80 String msg = null; 81 if (role == null){ 81 if (role == null) { 82 82 /* 83 83 * from and to intersect at a common node. Both have to be split. 84 84 */ 85 85 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 " 87 87 + "at node <span class=\"object-name\">{2}</span>. " 88 88 + "<p> " … … 93 93 ); 94 94 } 95 switch(role){ 95 switch(role) { 96 96 case FROM: 97 97 /* … … 123 123 124 124 class SplitAction extends AbstractAction { 125 publicSplitAction() {125 SplitAction() { 126 126 putValue(NAME, tr("Split now")); 127 127 putValue(SHORT_DESCRIPTION, tr("Split the ways")); 128 128 } 129 129 130 @Override 130 131 public void actionPerformed(ActionEvent e) { 131 132 132 133 SplitWayResult result = null; 133 if (role == null || role.equals(TurnRestrictionLegRole.FROM)){ 134 if (role == null || role.equals(TurnRestrictionLegRole.FROM)) { 134 135 result = SplitWayAction.split( 135 136 parent.getEditorModel().getLayer(), … … 138 139 Collections.<OsmPrimitive>emptyList() 139 140 ); 140 if (result != null){ 141 if (result != null) { 141 142 Main.main.undoRedo.add(result.getCommand()); 142 143 } 143 144 } 144 145 145 146 if (role == null || role.equals(TurnRestrictionLegRole.TO)) { 146 147 result = SplitWayAction.split( … … 150 151 Collections.<OsmPrimitive>emptyList() 151 152 ); 152 if (result != null){ 153 if (result != null) { 153 154 Main.main.undoRedo.add(result.getCommand()); 154 155 } 155 156 if (result == null) return; 156 TurnRestrictionType restrictionType = TurnRestrictionType.fromTagValue(getIssuesModel().getEditorModel().getRestrictionTagValue()); 157 TurnRestrictionType restrictionType = TurnRestrictionType.fromTagValue( 158 getIssuesModel().getEditorModel().getRestrictionTagValue()); 157 159 if (restrictionType == null) return; 158 160 Way adjustedTo = TurnRestrictionBuilder.selectToWayAfterSplit( … … 162 164 restrictionType 163 165 ); 164 166 165 167 if (adjustedTo == null) return; 166 168 getIssuesModel().getEditorModel().setTurnRestrictionLeg( 167 169 TurnRestrictionLegRole.TO, 168 170 adjustedTo 169 ); 171 ); 170 172 getIssuesModel().getEditorModel().getLayer().data.setSelected( 171 173 Arrays.asList(from, adjustedTo) 172 ); 174 ); 173 175 } else { 174 176 getIssuesModel().getEditorModel().getLayer().data.setSelected( 175 177 Arrays.asList(from, to) 176 178 ); 177 } 179 } 178 180 } 179 181 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/WrongTurnRestrictionLegTypeError.java
r30454 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 16 17 /** 17 18 * Issue if the type of a turn restriction leg is either an OSM node or an OSM relation. 18 * 19 * 19 20 */ 20 21 public class WrongTurnRestrictionLegTypeError extends Issue { … … 23 24 24 25 /** 25 * Create the issue 26 * 27 * @param parent the parent model 26 * Create the issue 27 * 28 * @param parent the parent model 28 29 * @param role the role of the turn restriction leg 29 * @param leg the leg 30 * @param leg the leg 30 31 */ 31 32 public WrongTurnRestrictionLegTypeError(IssuesModel parent, TurnRestrictionLegRole role, OsmPrimitive leg) { … … 38 39 39 40 @Override 40 public String getText() { 41 public String getText() { 41 42 String msg = null; 42 switch(leg.getType()){ 43 switch(leg.getType()) { 43 44 case NODE: 44 45 msg = tr( … … 52 53 leg.getDisplayName(DefaultNameFormatter.getInstance()), 53 54 role.toString() 54 ); 55 break; 55 ); 56 break; 56 57 default: 57 58 throw new AssertionError("Unexpected type for leg: "+leg.getType()); … … 61 62 62 63 class DeleteAction extends AbstractAction { 63 publicDeleteAction() {64 DeleteAction() { 64 65 putValue(NAME, tr("Delete")); 65 66 putValue(SHORT_DESCRIPTION, tr("Delete the member from the turn restriction")); 66 67 } 68 69 @Override 67 70 public void actionPerformed(ActionEvent e) { 68 71 RelationMemberEditorModel model = getIssuesModel().getEditorModel().getRelationMemberEditorModel(); 69 switch(role){ 70 case FROM: 72 switch(role) { 73 case FROM: 71 74 model.setFromPrimitive(null); 72 75 break; … … 75 78 break; 76 79 } 77 } 80 } 78 81 } 79 82 80 83 class FixInEditorAction extends AbstractAction { 81 publicFixInEditorAction() {84 FixInEditorAction() { 82 85 putValue(NAME, tr("Fix in editor")); 83 86 putValue(SHORT_DESCRIPTION, tr("Change to the Basic Editor and select a way")); 84 87 } 88 89 @Override 85 90 public void actionPerformed(ActionEvent e) { 86 91 NavigationControler controler = getIssuesModel().getNavigationControler(); 87 switch(role){ 88 case FROM: 92 switch(role) { 93 case FROM: 89 94 controler.gotoBasicEditor(BasicEditorFokusTargets.FROM); 90 95 break; … … 93 98 break; 94 99 } 95 } 100 } 96 101 } 97 102 } -
applications/editors/josm/plugins/turnrestrictions/test/unit/org/openstreetmap/josm/plugins/turnrestrictions/AllUnitTests.java
r30365 r32519 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions; 2 3 -
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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 import junit.framework.TestCase;4 3 5 4 import org.junit.runner.RunWith; 6 5 import org.junit.runners.Suite; 6 7 import junit.framework.TestCase; 7 8 8 9 @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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 11 12 12 13 /** 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 * 15 16 */ 16 17 @Ignore("no test") … … 19 20 private TurnRestrictionEditorModel model; 20 21 private DataSet ds; 21 22 22 23 public BasicEditorPanelTest() { 23 24 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 26 27 NavigationControler controler = new NavigationControler() { 28 @Override 27 29 public void gotoAdvancedEditor() { 28 30 } 29 31 32 @Override 30 33 public void gotoBasicEditor() { 31 34 } 32 35 36 @Override 33 37 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 34 } 38 } 35 39 }; 36 40 model = new TurnRestrictionEditorModel(layer, controler); 37 41 38 42 BasicEditorPanel panel = new BasicEditorPanel(model); 39 43 40 44 Container c = getContentPane(); 41 45 c.setLayout(new BorderLayout()); 42 c.add(panel, BorderLayout.CENTER); 43 setSize(600,600); 46 c.add(panel, BorderLayout.CENTER); 47 setSize(600, 600); 44 48 setDefaultCloseOperation(EXIT_ON_CLOSE); 45 49 } 46 47 48 static public void main(String args[]) { 50 51 public static void main(String[] args) { 49 52 new BasicEditorPanelTest().setVisible(true); 50 53 } -
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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 12 13 13 14 /** 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 15 16 * the {@see TurnRestrictionComboBox} 16 * 17 * 17 18 */ 18 19 @Ignore("no test") 19 20 public class TurnRestrictionComboBoxTest extends JFrame { 20 21 21 22 private TurnRestrictionEditorModel model; 22 23 private DataSet ds = new DataSet(); 23 24 24 25 protected void build() { 25 26 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 28 29 NavigationControler controler = new NavigationControler() { 30 @Override 29 31 public void gotoAdvancedEditor() { 30 32 } 31 33 34 @Override 32 35 public void gotoBasicEditor() { 33 36 } 34 37 38 @Override 35 39 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 36 } 40 } 37 41 }; 38 42 model = new TurnRestrictionEditorModel(layer, controler); 39 43 40 44 Container c = getContentPane(); 41 45 c.setLayout(new GridBagLayout()); … … 44 48 gc.fill = GridBagConstraints.HORIZONTAL; 45 49 gc.weightx = 1.0; 46 50 47 51 TurnRestrictionComboBox cb = new TurnRestrictionComboBox( 48 52 new TurnRestrictionComboBoxModel(model) 49 53 ); 50 add(cb, gc); 54 add(cb, gc); 51 55 } 52 56 53 57 public TurnRestrictionComboBoxTest() { 54 58 build(); 55 setSize(600,600); 59 setSize(600, 600); 56 60 setDefaultCloseOperation(EXIT_ON_CLOSE); 57 61 } 58 59 public static void main(String args[]) {62 63 public static void main(String[] args) { 60 64 new TurnRestrictionComboBoxTest().setVisible(true); 61 65 } 62 63 66 } -
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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 12 13 @Ignore("no test") 13 14 public class TurnRestrictionEditorTest extends JFrame { 14 15 15 16 public TurnRestrictionEditorTest() { 16 setSize(10,10); 17 setSize(10, 10); 17 18 TurnRestrictionEditor editor = new TurnRestrictionEditor(this, new OsmDataLayer(new DataSet(), "test", null)); 18 editor.setSize(600,600); 19 editor.setSize(600, 600); 19 20 editor.setVisible(true); 20 21 21 22 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 22 23 } 23 24 static public void main(Stringargs[]) {24 25 public static void main(String[] args) { 25 26 new TurnRestrictionEditorTest().setVisible(true); 26 27 } -
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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 30 31 31 32 /** 32 * Simple test application to test functionality and layout of the 33 * Simple test application to test functionality and layout of the 33 34 * {@see TurnRestrictionLegEditor} 34 35 */ 35 36 @Ignore("no test") 36 37 public class TurnRestrictionLegEditorTest extends JFrame { 37 38 38 39 private TurnRestrictionLegEditor editor; 39 40 private TurnRestrictionEditorModel model; … … 41 42 private DefaultListModel<OsmPrimitive> listModel; 42 43 private DataSet dataSet; 43 44 44 45 protected JPanel buildLegEditorPanel() { 45 46 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 48 49 NavigationControler controler = new NavigationControler() { 50 @Override 49 51 public void gotoAdvancedEditor() { 50 52 } 51 53 54 @Override 52 55 public void gotoBasicEditor() { 53 56 } 54 57 58 @Override 55 59 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 56 } 60 } 57 61 }; 58 62 JPanel pnl = new JPanel(new GridBagLayout()); … … 60 64 gc.anchor = GridBagConstraints.NORTHWEST; 61 65 gc.fill = GridBagConstraints.HORIZONTAL; 62 gc.weightx = 0.0; 66 gc.weightx = 0.0; 63 67 pnl.add(new JLabel("From"), gc); 64 68 65 69 gc.weightx = 1.0; 66 70 gc.gridx = 1; … … 69 73 model.populate(new Relation()); 70 74 pnl.add(editor = new TurnRestrictionLegEditor(model, TurnRestrictionLegRole.FROM), gc); 71 75 72 76 return pnl; 73 77 } 74 78 75 79 protected JPanel buildObjectListPanel() { 76 80 JPanel pnl = new JPanel(new BorderLayout()); 77 81 listModel = new DefaultListModel<>(); 78 82 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 82 87 public List<PrimitiveId> getSelectedPrimitiveIds() { 83 88 List<PrimitiveId> ret = new ArrayList<>(); 84 int 85 for (int i: sel){ 89 int[] sel = lstObjects.getSelectedIndices(); 90 for (int i: sel) { 86 91 ret.add((lstObjects.getModel().getElementAt(i)).getPrimitiveId()); 87 92 } … … 89 94 } 90 95 }; 91 96 92 97 lstObjects.setTransferHandler(new PrimitiveIdListTransferHandler(provider)); 93 98 lstObjects.setDragEnabled(true); 94 99 return pnl; 95 100 } 96 101 97 102 protected void build() { 98 103 Container c = getContentPane(); 99 104 c.setLayout(new GridBagLayout()); 100 105 101 106 GridBagConstraints gc = new GridBagConstraints(); 102 107 gc.anchor = GridBagConstraints.NORTHWEST; 103 gc.fill = GridBagConstraints.HORIZONTAL; 108 gc.fill = GridBagConstraints.HORIZONTAL; 104 109 gc.insets = new Insets(20, 0, 20, 0); 105 gc.weightx = 1.0; 110 gc.weightx = 1.0; 106 111 gc.weighty = 0.0; 107 112 add(buildLegEditorPanel(), gc); 108 113 109 114 gc.gridy = 1; 110 115 gc.weightx = 1.0; … … 112 117 gc.fill = GridBagConstraints.BOTH; 113 118 add(buildObjectListPanel(), gc); 114 setSize(600, 600);119 setSize(600, 600); 115 120 } 116 121 117 122 protected void initForTest1() { 118 123 Way w = new Way(1); 119 124 w.put("name", "way-1"); 120 125 121 126 editor.getModel().setTurnRestrictionLeg(TurnRestrictionLegRole.FROM, w); 122 127 } 123 128 124 129 protected void initForTest2() { 125 130 Way w = new Way(1); 126 w.put("name", "way-1"); 131 w.put("name", "way-1"); 127 132 dataSet.addPrimitive(w); 128 133 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)); 131 136 n.setOsmId(1, 1); 132 137 n.put("name", "node.1"); 133 138 dataSet.addPrimitive(n); 134 139 listModel.addElement(n); 135 140 136 141 w = new Way(); 137 w.setOsmId(2,1); 142 w.setOsmId(2, 1); 138 143 w.put("name", "way.1"); 139 144 dataSet.addPrimitive(w); 140 145 listModel.addElement(w); 141 146 142 147 Relation r = new Relation(); 143 r.setOsmId(3,1); 148 r.setOsmId(3, 1); 144 149 r.put("name", "relation.1"); 145 150 dataSet.addPrimitive(r); … … 147 152 } 148 153 149 public TurnRestrictionLegEditorTest(){ 154 public TurnRestrictionLegEditorTest() { 150 155 build(); 151 156 initForTest2(); 152 157 } 153 154 static public void main(Stringargs[]) {158 159 public static void main(String[] args) { 155 160 new TurnRestrictionLegEditorTest().setVisible(true); 156 161 } -
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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 13 14 /** 14 15 * Simple test application to test the vehicle exception editor 15 * 16 * 16 17 */ 17 18 @Ignore("no test") … … 20 21 OsmDataLayer layer; 21 22 VehicleExceptionEditor editor; 22 23 23 24 protected void build() { 24 25 Container c = getContentPane(); … … 26 27 layer = new OsmDataLayer(new DataSet(), "test", null); 27 28 28 model = new TurnRestrictionEditorModel(layer, new MockNavigationControler()); 29 model = new TurnRestrictionEditorModel(layer, new MockNavigationControler()); 29 30 editor = new VehicleExceptionEditor(model); 30 31 c.add(editor, BorderLayout.CENTER); 31 32 32 33 model.getTagEditorModel().add(new TagModel("except", "non-standard-value")); 33 34 } 34 35 public VehicleExceptionEditorTest(){ 35 36 public VehicleExceptionEditorTest() { 36 37 build(); 37 38 setDefaultCloseOperation(EXIT_ON_CLOSE); 38 setSize(500, 500);39 setSize(500, 500); 39 40 } 40 41 public static void main(String args[]){41 42 public static void main(String[] args) { 42 43 new VehicleExceptionEditorTest().setVisible(true); 43 44 } 44 45 static private class MockNavigationControler implements NavigationControler{46 45 46 private static class MockNavigationControler implements NavigationControler { 47 48 @Override 47 49 public void gotoAdvancedEditor() { 48 50 // TODO Auto-generated method stub 49 51 50 52 } 51 53 54 @Override 52 55 public void gotoBasicEditor() { 53 56 // TODO Auto-generated method stub 54 57 55 58 } 56 59 60 @Override 57 61 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 58 62 // TODO Auto-generated method stub 59 63 60 64 } 61 65 } -
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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.editor; 2 3 … … 24 25 @Ignore("no test") 25 26 public class ViaListTest extends JFrame { 26 27 27 28 private TurnRestrictionEditorModel model; 28 29 29 30 protected void build() { 30 31 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 33 34 NavigationControler controler = new NavigationControler() { 35 @Override 34 36 public void gotoAdvancedEditor() { 35 37 } 36 38 39 @Override 37 40 public void gotoBasicEditor() { 38 41 } 39 42 43 @Override 40 44 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 41 } 45 } 42 46 }; 43 47 model = new TurnRestrictionEditorModel(layer, controler); 44 48 Container c = getContentPane(); 45 49 46 50 c.setLayout(new GridBagLayout()); 47 51 GridBagConstraints gc = new GridBagConstraints(); 48 52 gc.anchor = GridBagConstraints.NORTHWEST; 49 gc.insets = new Insets(5, 5,5,20);53 gc.insets = new Insets(5, 5, 5, 20); 50 54 gc.fill = GridBagConstraints.BOTH; 51 55 gc.weightx = 0.5; 52 56 gc.weighty = 1.0; 53 57 54 58 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 55 59 c.add(new ViaList(new ViaListModel(model, selectionModel), selectionModel), gc); 56 60 57 61 gc.gridx = 1; 58 62 c.add(new JList<>(), gc); 59 60 setSize(600, 600);63 64 setSize(600, 600); 61 65 setDefaultCloseOperation(EXIT_ON_CLOSE); 62 66 } 63 67 64 68 protected void initTest1() { 65 69 DataSet ds = new DataSet(); 66 70 Relation r = new Relation(); 67 71 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)); 70 74 n.put("name", "node." + i); 71 75 ds.addPrimitive(n); 72 r.addMember(new RelationMember("via",n)); 73 } 76 r.addMember(new RelationMember("via", n)); 77 } 74 78 model.populate(r); 75 79 } 76 80 77 81 public ViaListTest() { 78 build(); 82 build(); 79 83 initTest1(); 80 84 } 81 82 static public void main(Stringargs[]) {85 86 public static void main(String[] args) { 83 87 new ViaListTest().setVisible(true); 84 88 } -
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. 1 2 package org.openstreetmap.josm.plugins.turnrestrictions.qa; 2 3 … … 22 23 public class IssuesViewTest extends JFrame { 23 24 private IssuesModel model; 24 25 25 26 protected void build() { 26 27 Container c = getContentPane(); 27 28 c.setLayout(new GridBagLayout()); 28 // mock a controler 29 // mock a controler 29 30 NavigationControler controler = new NavigationControler() { 31 @Override 30 32 public void gotoAdvancedEditor() { 31 33 } 32 34 35 @Override 33 36 public void gotoBasicEditor() { 34 37 } 35 38 39 @Override 36 40 public void gotoBasicEditor(BasicEditorFokusTargets focusTarget) { 37 } 41 } 38 42 }; 39 43 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "test", null); … … 49 53 pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 50 54 c.add(pane, gc); 51 55 52 56 List<Issue> issues = new ArrayList<>(); 53 57 issues.add(new RequiredTagMissingError(model, "type", "restriction")); … … 55 59 model.populate(issues); 56 60 } 57 61 58 62 public IssuesViewTest() { 59 63 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 60 setSize(400,600); 64 setSize(400, 600); 61 65 build(); 62 66 } 63 64 public static void main(String args[]) {67 68 public static void main(String[] args) { 65 69 new IssuesViewTest().setVisible(true); 66 70 }
Note:
See TracChangeset
for help on using the changeset viewer.