Changeset 24697 in osm for applications/editors/josm/plugins/terracer/src
- Timestamp:
- 2010-12-11T12:52:27+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/terracer/src/terracer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java
r23191 r24697 97 97 getJContentPane(); 98 98 initialize(); 99 setDefaultButton(1); 99 100 setupDialog(); 101 getRootPane().setDefaultButton(defaultButton); 100 102 setVisible(true); 101 103 lo.requestFocus(); -
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
r23191 r24697 28 28 import org.openstreetmap.josm.data.osm.Relation; 29 29 import org.openstreetmap.josm.actions.JosmAction; 30 import org.openstreetmap.josm.data.osm.Node; 30 31 31 32 /** … … 42 43 private TerracerAction terracerAction; 43 44 private Way outline, street; 45 private Node init; 44 46 private Relation associatedStreet; 45 47 public HouseNumberInputDialog dialog; … … 50 52 * @param terracerAction the terracer action 51 53 * @param outline the closed, quadrilateral way to terrace. 54 * @param init The node that hints at which side to start the numbering 52 55 * @param street the street, the buildings belong to (may be null) 53 56 * @param associatedStreet a relation where we can add the houses (may be null) … … 55 58 */ 56 59 public HouseNumberInputHandler(final TerracerAction terracerAction, 57 final Way outline, final Way street, final Relation associatedStreet,60 final Way outline, final Node init, final Way street, final Relation associatedStreet, 58 61 final String title) { 59 62 this.terracerAction = terracerAction; 60 63 this.outline = outline; 64 this.init = init; 61 65 this.street = street; 62 66 this.associatedStreet = associatedStreet; … … 272 276 if (e.getSource() instanceof JButton) { 273 277 JButton button = (JButton) e.getSource(); 274 if ( "OK".equals(button.getActionCommand()) & button.isEnabled()) {278 if (tr("OK").equals(button.getActionCommand()) & button.isEnabled()) { 275 279 if (validateInput()) { 276 280 saveValues(); … … 278 282 terracerAction.terraceBuilding( 279 283 outline, 284 init, 280 285 street, 281 286 associatedStreet, -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r23191 r24697 16 16 import java.util.Collection; 17 17 import java.util.Collections; 18 import java.util.Iterator;19 18 import java.util.LinkedList; 20 19 import java.util.List; … … 30 29 import org.openstreetmap.josm.command.DeleteCommand; 31 30 import org.openstreetmap.josm.command.SequenceCommand; 32 import org.openstreetmap.josm.data.coor.LatLon;33 31 import org.openstreetmap.josm.data.osm.Node; 34 32 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 37 35 import org.openstreetmap.josm.data.osm.TagCollection; 38 36 import org.openstreetmap.josm.data.osm.Way; 37 import org.openstreetmap.josm.gui.ExtendedDialog; 39 38 import org.openstreetmap.josm.tools.Pair; 40 39 import org.openstreetmap.josm.tools.Shortcut; … … 74 73 */ 75 74 public void actionPerformed(ActionEvent e) { 76 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet() 77 .getSelected(); 75 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 78 76 Way outline = null; 79 77 Way street = null; 78 Node init = null; 80 79 81 80 class InvalidUserInputException extends Exception { … … 89 88 90 89 try { 91 if (sel.size() == 2) { 92 Iterator<OsmPrimitive> it = sel.iterator(); 93 OsmPrimitive prim1 = it.next(); 94 OsmPrimitive prim2 = it.next(); 95 if (!(prim1 instanceof Way && prim2 instanceof Way)) 96 throw new InvalidUserInputException(); 97 Way way1 = (Way) prim1; 98 Way way2 = (Way) prim2; 99 if (way2.get("highway") != null) { 100 street = way2; 101 outline = way1; 102 } else if (way1.get("highway") != null) { 103 street = way1; 104 outline = way2; 105 } else 106 throw new InvalidUserInputException(); 107 if (street.get("name") == null) 108 throw new InvalidUserInputException(); 109 110 } else if (sel.size() == 1) { 111 OsmPrimitive prim = sel.iterator().next(); 112 113 if (!(prim instanceof Way)) 114 throw new InvalidUserInputException(); 115 116 outline = (Way)prim; 117 } else 90 for (OsmPrimitive osm : sel) { 91 if (osm instanceof Node) { 92 if (init != null) 93 throw new InvalidUserInputException(); 94 init = (Node) osm; 95 } else if (osm instanceof Way) { 96 if (osm.hasKey("highway")) { 97 if (street != null) 98 throw new InvalidUserInputException(); 99 street = (Way) osm; 100 if (!street.hasKey("name")) 101 throw new InvalidUserInputException(); 102 } else { 103 if (outline != null) 104 throw new InvalidUserInputException(); 105 outline = (Way) osm; 106 } 107 } 108 } 109 if (outline == null) 110 throw new InvalidUserInputException(); 111 112 if (init != null && !init.getReferrers().contains(outline)) 118 113 throw new InvalidUserInputException(); 119 114 … … 124 119 throw new InvalidUserInputException(); 125 120 } catch (InvalidUserInputException ex) { 126 JOptionPane.showMessageDialog(Main.parent, 127 tr("Select a single, closed way of at least four nodes.")); 121 new ExtendedDialog(Main.parent, tr("Invalid selection"), new String[] {"OK"}) 122 .setButtonIcons(new String[] {"ok"}).setIcon(JOptionPane.INFORMATION_MESSAGE) 123 .setContent(tr("Select a single, closed way of at least four nodes. " + 124 "(Optionally you can also select a street for the addr:street tag " + 125 "and a node to mark the start of numbering.)")) 126 .showDialog(); 128 127 return; 129 128 } … … 149 148 String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size()); 150 149 // show input dialog. 151 new HouseNumberInputHandler(this, outline, street, associatedStreet, title);150 new HouseNumberInputHandler(this, outline, init, street, associatedStreet, title); 152 151 } 153 152 … … 169 168 * 170 169 * @param outline The closed, quadrilateral way to terrace. 170 * @param init The node that hints at which side to start the numbering 171 171 * @param street The street, the buildings belong to (may be null) 172 172 * @param associatedStreet … … 178 178 */ 179 179 public void terraceBuilding(Way outline, 180 Node init, 180 181 Way street, 181 182 Relation associatedStreet, … … 217 218 Pair<Way, Way> interp = findFrontAndBack(outline); 218 219 220 boolean swap = false; 221 if (init != null) { 222 if (interp.a.lastNode().equals(init) || interp.b.lastNode().equals(init)) { 223 swap = true; 224 } 225 } 226 219 227 final double frontLength = wayLength(interp.a); 220 228 final double backLength = wayLength(interp.b); 221 229 222 230 for (int i = 0; i <= nb; ++i) { 223 new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i / nb); 224 new_nodes[1][i] = interpolateAlong(interp.b, backLength * i / nb); 231 int i_dir = swap ? nb - i : i; 232 new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i_dir / nb); 233 new_nodes[1][i] = interpolateAlong(interp.b, backLength * i_dir / nb); 225 234 this.commands.add(new AddCommand(new_nodes[0][i])); 226 235 this.commands.add(new AddCommand(new_nodes[1][i])); … … 230 239 for (int i = 0; i < nb; ++i) { 231 240 Way terr = new Way(); 232 // Using Way.nodes.add rather than Way.addNode because the latter233 // doesn't234 // exist in older versions of JOSM.235 241 terr.addNode(new_nodes[0][i]); 236 242 terr.addNode(new_nodes[0][i + 1]);
Note:
See TracChangeset
for help on using the changeset viewer.