Changeset 23191 in osm for applications/editors/josm/plugins/terracer/src
- Timestamp:
- 2010-09-15T18:56:19+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/terracer/src/terracer
- Files:
-
- 6 edited
-
HouseNumberInputDialog.java (modified) (7 diffs)
-
HouseNumberInputHandler.java (modified) (9 diffs)
-
ReverseTerraceAction.java (modified) (2 diffs)
-
TerracerAction.java (modified) (8 diffs)
-
TerracerPlugin.java (modified) (3 diffs)
-
TerracerRuntimeException.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java
r22018 r23191 75 75 JCheckBox deleteOutlineCheckBox; 76 76 77 HouseNumberInputHandler inputHandler;77 HouseNumberInputHandler inputHandler; 78 78 79 79 /** … … 102 102 } 103 103 104 /**104 /** 105 105 * This method initializes this 106 106 * … … 111 111 this.hi.addFocusListener(this.inputHandler); 112 112 this.segments.addFocusListener(this.inputHandler); 113 this.interpolation.addItemListener(this.inputHandler);113 this.interpolation.addItemListener(this.inputHandler); 114 114 } 115 115 … … 136 136 if (inputPanel == null) { 137 137 138 GridBagConstraints c = new GridBagConstraints();139 140 messageLabel = new JTextArea();138 GridBagConstraints c = new GridBagConstraints(); 139 140 messageLabel = new JTextArea(); 141 141 messageLabel.setText(DEFAULT_MESSAGE); 142 142 messageLabel.setAutoscrolls(true); … … 168 168 inputPanel.setLayout(new GridBagLayout()); 169 169 c.fill = GridBagConstraints.HORIZONTAL; 170 c.gridwidth = GridBagConstraints.REMAINDER;170 c.gridwidth = GridBagConstraints.REMAINDER; 171 171 inputPanel.add(messageLabel, c); 172 172 … … 191 191 } 192 192 193 /**193 /** 194 194 * Overrides the default actions. Will not close the window when upload trace is clicked 195 195 */ … … 268 268 interpolation.add(tr("Even/Odd")); 269 269 if (Main.pref.getInteger(INTERPOLATION, 2) == 1) { 270 interpolation.select(tr("All"));270 interpolation.select(tr("All")); 271 271 } else { 272 interpolation.select(tr("Even/Odd"));272 interpolation.select(tr("Even/Odd")); 273 273 } 274 274 //return (dialog.interpolation.getSelectedItem().equals(tr("All"))) ? 1 : 2; -
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
r21169 r23191 61 61 this.street = street; 62 62 this.associatedStreet = associatedStreet; 63 63 64 64 // This dialog is started modal 65 65 this.dialog = new HouseNumberInputDialog(this, street, associatedStreet != null); 66 66 67 67 // We're done 68 68 } 69 69 70 /**71 * Find a button with a certain caption.72 * Loops recursively through all objects to find all buttons.73 * Function returns on the first match.74 *75 * @param root A container object that is recursively searched for other containers or buttons76 * @param caption The caption of the button that is being searched77 *78 * @return The first button that matches the caption or null if not found79 */80 private static JButton getButton(Container root, String caption) {81 Component children[] = root.getComponents();70 /** 71 * Find a button with a certain caption. 72 * Loops recursively through all objects to find all buttons. 73 * Function returns on the first match. 74 * 75 * @param root A container object that is recursively searched for other containers or buttons 76 * @param caption The caption of the button that is being searched 77 * 78 * @return The first button that matches the caption or null if not found 79 */ 80 private static JButton getButton(Container root, String caption) { 81 Component children[] = root.getComponents(); 82 82 for (Component child : children) { 83 JButton b;84 if (child instanceof JButton) {85 b = (JButton) child;86 if (caption.equals(b.getText())) return b;87 } else if (child instanceof Container) {83 JButton b; 84 if (child instanceof JButton) { 85 b = (JButton) child; 86 if (caption.equals(b.getText())) return b; 87 } else if (child instanceof Container) { 88 88 b = getButton((Container)child, caption); 89 89 if (b != null) return b; 90 90 } 91 91 } 92 return null;93 }94 92 return null; 93 } 94 95 95 /** 96 96 * Validate the current input fields. … … 110 110 // Allow non numeric characters for the low number as long as there is no high number of the segmentcount is 1 111 111 if (dialog.hi.getText().length() > 0 | segments() > 1) { 112 isOk = isOk113 && checkNumberStringField(dialog.lo, tr("Lowest number"),114 message);115 }112 isOk = isOk 113 && checkNumberStringField(dialog.lo, tr("Lowest number"), 114 message); 115 } 116 116 isOk = isOk 117 117 && checkNumberStringField(dialog.hi, tr("Highest number"), … … 124 124 JButton okButton = getButton(dialog, "OK"); 125 125 if (okButton != null) 126 okButton.setEnabled(true);127 126 okButton.setEnabled(true); 127 128 128 // For some reason the messageLabel doesn't want to show up 129 129 dialog.messageLabel.setForeground(Color.black); … … 133 133 JButton okButton = getButton(dialog, "OK"); 134 134 if (okButton != null) 135 okButton.setEnabled(false);136 137 // For some reason the messageLabel doesn't want to show up, so a MessageDialog is shown instead. Someone more knowledgeable might fix this.138 dialog.messageLabel.setForeground(Color.red);139 dialog.messageLabel.setText(message.toString());140 //JOptionPane.showMessageDialog(null, message.toString(), tr("Error"), JOptionPane.ERROR_MESSAGE);135 okButton.setEnabled(false); 136 137 // For some reason the messageLabel doesn't want to show up, so a MessageDialog is shown instead. Someone more knowledgeable might fix this. 138 dialog.messageLabel.setForeground(Color.red); 139 dialog.messageLabel.setText(message.toString()); 140 //JOptionPane.showMessageDialog(null, message.toString(), tr("Error"), JOptionPane.ERROR_MESSAGE); 141 141 142 142 return false; … … 273 273 JButton button = (JButton) e.getSource(); 274 274 if ("OK".equals(button.getActionCommand()) & button.isEnabled()) { 275 if (validateInput()) {276 saveValues();277 278 terracerAction.terraceBuilding(279 outline,280 street,281 associatedStreet,282 segments(),283 dialog.lo.getText(),284 dialog.hi.getText(),285 stepSize(),286 streetName(),287 doHandleRelation(),288 doDeleteOutline());289 290 this.dialog.dispose();291 }275 if (validateInput()) { 276 saveValues(); 277 278 terracerAction.terraceBuilding( 279 outline, 280 street, 281 associatedStreet, 282 segments(), 283 dialog.lo.getText(), 284 dialog.hi.getText(), 285 stepSize(), 286 streetName(), 287 doHandleRelation(), 288 doDeleteOutline()); 289 290 this.dialog.dispose(); 291 } 292 292 } else if ("Cancel".equals(button.getActionCommand())) { 293 293 this.dialog.dispose(); … … 357 357 if (street != null) 358 358 return null; 359 359 360 360 Object selected = dialog.streetComboBox.getSelectedItem(); 361 361 if (selected == null) { … … 376 376 */ 377 377 public boolean doHandleRelation() { 378 if (this.dialog == null) {379 JOptionPane.showMessageDialog(null, "dialog", "alert", JOptionPane.ERROR_MESSAGE);380 }381 if (this.dialog.handleRelationCheckBox == null) {382 JOptionPane.showMessageDialog(null, "checkbox", "alert", JOptionPane.ERROR_MESSAGE);383 return true;384 } else {385 return this.dialog.handleRelationCheckBox.isSelected();386 } 387 } 388 389 378 if (this.dialog == null) { 379 JOptionPane.showMessageDialog(null, "dialog", "alert", JOptionPane.ERROR_MESSAGE); 380 } 381 if (this.dialog.handleRelationCheckBox == null) { 382 JOptionPane.showMessageDialog(null, "checkbox", "alert", JOptionPane.ERROR_MESSAGE); 383 return true; 384 } else { 385 return this.dialog.handleRelationCheckBox.isSelected(); 386 } 387 } 388 389 390 390 /** 391 391 * Whether the user likes to delete the outline way. … … 394 394 return dialog.deleteOutlineCheckBox.isSelected(); 395 395 } 396 396 397 397 /* (non-Javadoc) 398 398 * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent) 399 399 */ 400 400 public void focusGained(FocusEvent e) { 401 // Empty, but placeholder is required401 // Empty, but placeholder is required 402 402 } 403 403 … … 406 406 */ 407 407 public void focusLost(FocusEvent e) { 408 if (e.getOppositeComponent() == null)409 return;408 if (e.getOppositeComponent() == null) 409 return; 410 410 411 411 validateInput(); -
applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java
r19678 r23191 78 78 } 79 79 } 80 80 81 81 if (front.isEmpty()) { 82 82 JOptionPane.showMessageDialog(Main.parent, 83 83 tr("Cannot reverse!")); 84 84 return; 85 } 85 } 86 86 87 87 // This is like a visitedWays set, but in a linear order. … … 130 130 protected void updateEnabledState() { 131 131 setEnabled(getCurrentDataSet() != null); 132 } 132 } 133 133 } -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r21376 r23191 58 58 // repeated terraces. this is the easiest, but not necessarily nicest, way. 59 59 // private static String lastSelectedValue = ""; 60 61 Collection<Command> commands;62 60 61 Collection<Command> commands; 62 63 63 public TerracerAction() { 64 64 super(tr("Terrace a building"), "terrace", … … 152 152 } 153 153 154 public Integer getNumber(String number) {155 try {154 public Integer getNumber(String number) { 155 try { 156 156 return Integer.parseInt(number); 157 157 } catch (NumberFormatException ex) { 158 158 return null; 159 159 } 160 }161 160 } 161 162 162 /** 163 163 * Terraces a single, closed, quadrilateral way. … … 178 178 */ 179 179 public void terraceBuilding(Way outline, 180 Way street,181 Relation associatedStreet,182 Integer segments,183 String From,184 String To,185 int step,186 String streetName,187 boolean handleRelations,188 boolean deleteOutline) {180 Way street, 181 Relation associatedStreet, 182 Integer segments, 183 String From, 184 String To, 185 int step, 186 String streetName, 187 boolean handleRelations, 188 boolean deleteOutline) { 189 189 final int nb; 190 190 191 191 Integer to, from; 192 192 to = getNumber(To); … … 210 210 Collection<Way> ways = new LinkedList<Way>(); 211 211 212 // Should this building be terraced (i.e. is there more then one section?)213 if (nb > 1) {214 // create intermediate nodes by interpolating.215 216 // now find which is the longest side connecting the first node217 Pair<Way, Way> interp = findFrontAndBack(outline);218 219 final double frontLength = wayLength(interp.a);220 final double backLength = wayLength(interp.b);221 222 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);225 this.commands.add(new AddCommand(new_nodes[0][i]));226 this.commands.add(new AddCommand(new_nodes[1][i]));227 }228 229 // assemble new quadrilateral, closed ways230 for (int i = 0; i < nb; ++i) {231 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 terr.addNode(new_nodes[0][i]);236 terr.addNode(new_nodes[0][i + 1]);237 terr.addNode(new_nodes[1][i + 1]);238 terr.addNode(new_nodes[1][i]);239 terr.addNode(new_nodes[0][i]);240 241 // add the tags of the outline to each building (e.g. source=*)242 TagCollection.from(outline).applyTo(terr);243 244 String number = null;245 if (from != null) {246 number = Integer.toString(from + i * step);247 }248 terr = addressBuilding(terr, street, streetName, number);249 250 ways.add(terr);251 this.commands.add(new AddCommand(terr));252 }253 254 if (deleteOutline) {255 this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(outline), true, true));256 }257 } else {258 // Single section, just add the address details259 Way newOutline;260 newOutline = addressBuilding(outline, street, streetName, From);261 ways.add(newOutline);262 this.commands.add(new ChangeCommand(outline, newOutline));263 }264 265 if (handleRelations) { // create a new relation or merge with existing266 if (associatedStreet == null) { // create a new relation267 associatedStreet = new Relation();268 associatedStreet.put("type", "associatedStreet");269 if (street != null) { // a street was part of the selection270 associatedStreet.put("name", street.get("name"));271 associatedStreet.addMember(new RelationMember("street", street));272 } else {273 associatedStreet.put("name", streetName);274 }275 for (Way w : ways) {276 associatedStreet.addMember(new RelationMember("house", w));277 }278 this.commands.add(new AddCommand(associatedStreet));279 }280 else { // relation exists already - add new members281 Relation newAssociatedStreet = new Relation(associatedStreet);282 for (Way w : ways) {283 newAssociatedStreet.addMember(new RelationMember("house", w));284 }285 this.commands.add(new ChangeCommand(associatedStreet, newAssociatedStreet));286 }287 }288 Main.main.undoRedo.add(new SequenceCommand(tr("Terrace"), commands));289 if (nb > 1) {290 // Select the new building outlines (for quick reversing)291 Main.main.getCurrentDataSet().setSelected(ways);292 } else if (street != null) {293 // Select the way (for quick selection of a new house (with the same way))294 Main.main.getCurrentDataSet().setSelected(street);295 }212 // Should this building be terraced (i.e. is there more then one section?) 213 if (nb > 1) { 214 // create intermediate nodes by interpolating. 215 216 // now find which is the longest side connecting the first node 217 Pair<Way, Way> interp = findFrontAndBack(outline); 218 219 final double frontLength = wayLength(interp.a); 220 final double backLength = wayLength(interp.b); 221 222 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); 225 this.commands.add(new AddCommand(new_nodes[0][i])); 226 this.commands.add(new AddCommand(new_nodes[1][i])); 227 } 228 229 // assemble new quadrilateral, closed ways 230 for (int i = 0; i < nb; ++i) { 231 Way terr = new Way(); 232 // Using Way.nodes.add rather than Way.addNode because the latter 233 // doesn't 234 // exist in older versions of JOSM. 235 terr.addNode(new_nodes[0][i]); 236 terr.addNode(new_nodes[0][i + 1]); 237 terr.addNode(new_nodes[1][i + 1]); 238 terr.addNode(new_nodes[1][i]); 239 terr.addNode(new_nodes[0][i]); 240 241 // add the tags of the outline to each building (e.g. source=*) 242 TagCollection.from(outline).applyTo(terr); 243 244 String number = null; 245 if (from != null) { 246 number = Integer.toString(from + i * step); 247 } 248 terr = addressBuilding(terr, street, streetName, number); 249 250 ways.add(terr); 251 this.commands.add(new AddCommand(terr)); 252 } 253 254 if (deleteOutline) { 255 this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(outline), true, true)); 256 } 257 } else { 258 // Single section, just add the address details 259 Way newOutline; 260 newOutline = addressBuilding(outline, street, streetName, From); 261 ways.add(newOutline); 262 this.commands.add(new ChangeCommand(outline, newOutline)); 263 } 264 265 if (handleRelations) { // create a new relation or merge with existing 266 if (associatedStreet == null) { // create a new relation 267 associatedStreet = new Relation(); 268 associatedStreet.put("type", "associatedStreet"); 269 if (street != null) { // a street was part of the selection 270 associatedStreet.put("name", street.get("name")); 271 associatedStreet.addMember(new RelationMember("street", street)); 272 } else { 273 associatedStreet.put("name", streetName); 274 } 275 for (Way w : ways) { 276 associatedStreet.addMember(new RelationMember("house", w)); 277 } 278 this.commands.add(new AddCommand(associatedStreet)); 279 } 280 else { // relation exists already - add new members 281 Relation newAssociatedStreet = new Relation(associatedStreet); 282 for (Way w : ways) { 283 newAssociatedStreet.addMember(new RelationMember("house", w)); 284 } 285 this.commands.add(new ChangeCommand(associatedStreet, newAssociatedStreet)); 286 } 287 } 288 Main.main.undoRedo.add(new SequenceCommand(tr("Terrace"), commands)); 289 if (nb > 1) { 290 // Select the new building outlines (for quick reversing) 291 Main.main.getCurrentDataSet().setSelected(ways); 292 } else if (street != null) { 293 // Select the way (for quick selection of a new house (with the same way)) 294 Main.main.getCurrentDataSet().setSelected(street); 295 } 296 296 } 297 297 … … 306 306 */ 307 307 private Way addressBuilding(Way outline, Way street, String streetName, String number) { 308 Way changedOutline = outline;308 Way changedOutline = outline; 309 309 if (number != null) { 310 310 // only, if the user has specified house numbers … … 431 431 return Math.min(positiveModulus(i1 - i2, n), positiveModulus(i2 - i1, n)); 432 432 } 433 433 434 434 /** 435 435 * return the modulus in the range [0, n) 436 436 */ 437 437 private int positiveModulus(int a, int n) { 438 if (n <=0) 438 if (n <=0) 439 439 throw new IllegalArgumentException(); 440 440 int res = a % n; … … 444 444 return res; 445 445 } 446 446 447 447 /** 448 448 * Calculate the length of a side (from node i to i+1) in a way. This assumes that … … 548 548 protected void updateEnabledState() { 549 549 setEnabled(getCurrentDataSet() != null); 550 } 550 } 551 551 } -
applications/editors/josm/plugins/terracer/src/terracer/TerracerPlugin.java
r19658 r23191 1 1 /** 2 2 * Terracer: A JOSM Plugin for terraced houses. 3 * 3 * 4 4 * Copyright 2009 CloudMade Ltd. 5 * 5 * 6 6 * Released under the GPLv2, see LICENSE file for details. 7 7 */ … … 15 15 /** 16 16 * Plugin interface implementation for Terracer. 17 * 17 * 18 18 * @author zere 19 19 */ … … 21 21 public TerracerPlugin(PluginInformation info) { 22 22 super(info); 23 23 24 24 MainMenu.add(Main.main.menu.toolsMenu, new TerracerAction()); 25 25 MainMenu.add(Main.main.menu.toolsMenu, new ReverseTerraceAction()); -
applications/editors/josm/plugins/terracer/src/terracer/TerracerRuntimeException.java
r19085 r23191 10 10 /** 11 11 * The Class TerracerRuntimeException indicates errors from the Terracer Plugin. 12 * 12 * 13 13 * @author casualwalker 14 14 */ 15 15 public class TerracerRuntimeException extends RuntimeException { 16 16 17 /** The Constant serialVersionUID. */18 private static final long serialVersionUID = 857926026580277816L;17 /** The Constant serialVersionUID. */ 18 private static final long serialVersionUID = 857926026580277816L; 19 19 20 /**21 * Default constructor.22 */23 public TerracerRuntimeException() {24 super();25 }20 /** 21 * Default constructor. 22 */ 23 public TerracerRuntimeException() { 24 super(); 25 } 26 26 27 /**28 * @param message29 * @param cause30 */31 public TerracerRuntimeException(String message, Throwable cause) {32 super(message, cause);33 }27 /** 28 * @param message 29 * @param cause 30 */ 31 public TerracerRuntimeException(String message, Throwable cause) { 32 super(message, cause); 33 } 34 34 35 /**36 * @param message37 */38 public TerracerRuntimeException(String message) {39 super(message);40 }35 /** 36 * @param message 37 */ 38 public TerracerRuntimeException(String message) { 39 super(message); 40 } 41 41 42 /**43 * @param cause44 */45 public TerracerRuntimeException(Throwable cause) {46 super(cause);47 }42 /** 43 * @param cause 44 */ 45 public TerracerRuntimeException(Throwable cause) { 46 super(cause); 47 } 48 48 49 49 }
Note:
See TracChangeset
for help on using the changeset viewer.
