Changeset 19085 in osm for applications
- Timestamp:
- 2009-12-13T23:55:13+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/terracer/src/terracer
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java
r19084 r19085 1 1 /** 2 * 2 * Terracer: A JOSM Plugin for terraced houses. 3 * 4 * Copyright 2009 CloudMade Ltd. 5 * 6 * Released under the GPLv2, see LICENSE file for details. 3 7 */ 4 8 package terracer; … … 30 34 * Created with the Eclipse Visual Editor. 31 35 * 32 * This dialog is concerned with the layout. 36 * This dialog is concerned with the layout, all logic goes into the 37 * HouseNumberinputHandler class. 33 38 * 34 39 * @author casualwalker … … 256 261 } 257 262 263 /** 264 * Registers the handler as a listener to all relevant events. 265 * 266 * @param handler the handler 267 */ 258 268 public void addHandler(HouseNumberInputHandler handler) { 259 269 this.hi.addActionListener(handler); -
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
r19084 r19085 1 1 /** 2 * 2 * Terracer: A JOSM Plugin for terraced houses. 3 * 4 * Copyright 2009 CloudMade Ltd. 5 * 6 * Released under the GPLv2, see LICENSE file for details. 3 7 */ 4 8 package terracer; … … 27 31 * From a refactoring viewpoint, this class is indeed more interested in the fields 28 32 * of the HouseNumberInputDialog. This is desired design, as the HouseNumberInputDialog 29 * is already cluttered with auto-generated layout code. 33 * is already cluttered with auto-generated layout code. 30 34 * 31 35 * @author casualwalker … … 34 38 ActionListener, FocusListener { 35 39 36 TerracerAction terracerAction; 37 Way way; 38 HouseNumberInputDialog dialog; 39 40 public HouseNumberInputHandler(TerracerAction terracerAction, Way way, 41 String title) { 40 private TerracerAction terracerAction; 41 private Way way; 42 private HouseNumberInputDialog dialog; 43 44 /** 45 * Instantiates a new house number input handler. 46 * 47 * @param terracerAction the terracer action 48 * @param way the way 49 * @param title the title 50 */ 51 public HouseNumberInputHandler(final TerracerAction terracerAction, 52 final Way way, final String title) { 42 53 this.terracerAction = terracerAction; 43 54 this.way = way; … … 50 61 } 51 62 63 /** 64 * Validate the current input fields. 65 * When the validation fails, a red message is 66 * displayed and the OK button is disabled. 67 * 68 * Should be triggered each time the input changes. 69 */ 52 70 private void validateInput() { 53 71 boolean isOk = true; … … 58 76 isOk = isOk && checkSegments(message); 59 77 isOk = isOk 60 && checkNumberStringField(dialog.lo, "Lowest number", message); 78 && checkNumberStringField(dialog.lo, tr("Lowest number"), 79 message); 61 80 isOk = isOk 62 && checkNumberStringField(dialog.hi, "Highest number", message); 81 && checkNumberStringField(dialog.hi, tr("Highest number"), 82 message); 63 83 isOk = isOk 64 && checkNumberStringField(dialog.segments, "Segments", message); 84 && checkNumberStringField(dialog.segments, tr("Segments"), 85 message); 65 86 66 87 if (isOk) { 67 88 dialog.okButton.setEnabled(true); 68 89 dialog.messageLabel.setForeground(Color.black); 69 dialog.messageLabel.setText(HouseNumberInputDialog.DEFAULT_MESSAGE); 90 dialog.messageLabel 91 .setText(tr(HouseNumberInputDialog.DEFAULT_MESSAGE)); 70 92 71 93 } else { … … 76 98 } 77 99 78 private boolean checkNumberOrder(StringBuffer message) { 100 /** 101 * Checks, if the lowest house number is indeed lower than the 102 * highest house number. 103 * This check applies only, if the house number fields are used at all. 104 * 105 * @param message the message 106 * 107 * @return true, if successful 108 */ 109 private boolean checkNumberOrder(final StringBuffer message) { 79 110 if (numberFrom() != null && numberTo() != null) { 80 111 if (numberFrom().intValue() > numberTo().intValue()) { 81 112 appendMessageNewLine(message); 82 113 message 83 .append( "Lowest housenumber cannot be higher than highest housenumber");114 .append(tr("Lowest housenumber cannot be higher than highest housenumber")); 84 115 return false; 85 116 } … … 88 119 } 89 120 90 private boolean checkSegmentsFromHousenumber(StringBuffer message) { 121 /** 122 * Obtain the number segments from the house number fields and check, 123 * if they are valid. 124 * 125 * Also disables the segments field, if the house numbers contain 126 * valid information. 127 * 128 * @param message the message 129 * 130 * @return true, if successful 131 */ 132 private boolean checkSegmentsFromHousenumber(final StringBuffer message) { 91 133 dialog.segments.setEditable(true); 92 134 93 135 if (numberFrom() != null && numberTo() != null) { 136 94 137 int segments = numberTo().intValue() - numberFrom().intValue(); 95 138 96 139 if (segments % stepSize() != 0) { 97 140 appendMessageNewLine(message); 98 message.append("Housenumbers do not match odd/even setting"); 141 message 142 .append(tr("Housenumbers do not match odd/even setting")); 99 143 return false; 100 144 } 101 145 102 146 int steps = segments / stepSize(); 147 steps++; // difference 0 means 1 building, see 148 // TerracerActon.terraceBuilding 103 149 dialog.segments.setText(String.valueOf(steps)); 104 150 dialog.segments.setEditable(false); … … 108 154 } 109 155 110 private boolean checkSegments(StringBuffer message) { 156 /** 157 * Check the number of segments. 158 * It must be a number and greater than 1. 159 * 160 * @param message the message 161 * 162 * @return true, if successful 163 */ 164 private boolean checkSegments(final StringBuffer message) { 111 165 if (segments() == null || segments().intValue() < 1) { 112 166 appendMessageNewLine(message); 113 message.append( "Segment must be a number greater 1");167 message.append(tr("Segment must be a number greater 1")); 114 168 return false; 115 169 … … 127 181 * @return true, if successful 128 182 */ 129 private boolean checkNumberStringField( JTextField field, String label,130 StringBuffer message) {131 String content = field.getText();183 private boolean checkNumberStringField(final JTextField field, 184 final String label, final StringBuffer message) { 185 final String content = field.getText(); 132 186 if (content != null && !content.isEmpty()) { 133 187 try { … … 135 189 if (i < 0) { 136 190 appendMessageNewLine(message); 137 message.append(label + " must be greater than 0");191 message.append(label + tr(" must be greater than 0")); 138 192 return false; 139 193 } 140 194 } catch (NumberFormatException e) { 141 195 appendMessageNewLine(message); 142 message.append(label + " is not a number");196 message.append(label + tr(" is not a number")); 143 197 return false; 144 198 } … … 149 203 150 204 /** 151 * @param message 152 */ 153 private void appendMessageNewLine(StringBuffer message) { 205 * Append a new line to the message, if the message is not empty. 206 * 207 * @param message the message 208 */ 209 private void appendMessageNewLine(final StringBuffer message) { 154 210 if (message.length() > 0) { 155 211 message.append("\n"); … … 157 213 } 158 214 215 /* (non-Javadoc) 216 * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) 217 */ 159 218 @Override 160 219 public void stateChanged(ChangeEvent e) { … … 163 222 } 164 223 224 /* (non-Javadoc) 225 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) 226 */ 165 227 @Override 166 228 public void itemStateChanged(ItemEvent e) { … … 168 230 } 169 231 170 @Override 171 public void actionPerformed(ActionEvent e) { 172 232 /* (non-Javadoc) 233 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) 234 */ 235 @Override 236 public void actionPerformed(final ActionEvent e) { 237 238 // OK or Cancel button-actions 173 239 if (e.getSource() instanceof JButton) { 174 240 JButton button = (JButton) e.getSource(); … … 182 248 } 183 249 } else { 250 // anything else is a change in the input 184 251 validateInput(); 185 252 } … … 187 254 } 188 255 256 /** 257 * Calculate the step size between two house numbers, 258 * based on the interpolation setting. 259 * 260 * @return the stepSize (1 for all, 2 for odd /even) 261 */ 189 262 public int stepSize() { 190 return (dialog.interpolation.getSelectedItem() == tr("All")) ? 1 : 2; 191 } 192 263 return (dialog.interpolation.getSelectedItem().equals(tr("All"))) ? 1 264 : 2; 265 } 266 267 /** 268 * Gets the number of segments, if set. 269 * 270 * @return the number of segments or null, if not set / invalid. 271 */ 193 272 public Integer segments() { 194 273 try { … … 199 278 } 200 279 280 /** 281 * Gets the lowest house number. 282 * 283 * @return the number of lowest house number or null, if not set / invalid. 284 */ 201 285 public Integer numberFrom() { 202 286 try { … … 207 291 } 208 292 293 /** 294 * Gets the highest house number. 295 * 296 * @return the number of highest house number or null, if not set / invalid. 297 */ 209 298 public Integer numberTo() { 210 299 try { … … 215 304 } 216 305 306 /** 307 * Gets the street name. 308 * 309 * @return the street name or null, if not set / invalid. 310 */ 217 311 public String streetName() { 218 312 // Object selected = street.getSelectedItem(); … … 230 324 } 231 325 326 /* (non-Javadoc) 327 * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent) 328 */ 232 329 @Override 233 330 public void focusGained(FocusEvent e) { … … 235 332 } 236 333 334 /* (non-Javadoc) 335 * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent) 336 */ 237 337 @Override 238 338 public void focusLost(FocusEvent e) { … … 240 340 } 241 341 242 /**243 * Indicates, if house numbers should be used (instead of segments).244 *245 * @return true, if if both number values are set to a number.246 */247 private boolean useHouseNumbers() {248 return numberFrom() != null && numberTo() != null;249 250 }251 342 } -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r19084 r19085 17 17 import java.util.Collections; 18 18 import java.util.LinkedList; 19 import java.util.TreeSet;20 19 21 20 import javax.swing.JOptionPane; … … 80 79 title = tr("Nothing selected!"); 81 80 82 // first ask the user how many buildings to terrace into 83 HouseNumberInputHandler handler = new HouseNumberInputHandler( 84 this, way, title); 85 86 // IntermediateInputDialog inputDialog = new 87 // IntermediateInputDialog( 88 // this, way); 89 // inputDialog.pack(); 90 // inputDialog.setVisible(true); 91 92 // HouseNumberDialog dialog = new HouseNumberDialog(this); 93 // final JOptionPane optionPane = new JOptionPane(dialog, 94 // JOptionPane.PLAIN_MESSAGE, 95 // JOptionPane.OK_CANCEL_OPTION); 96 // 97 // String title = trn("Change {0} object", 98 // "Change {0} objects", sel.size(), sel.size()); 99 // if (sel.size() == 0) 100 // title = tr("Nothing selected!"); 101 // 102 // optionPane.createDialog(Main.parent, title) 103 // .setVisible(true); 104 // Object answerObj = optionPane.getValue(); 105 // if (answerObj != null 106 // && answerObj != JOptionPane.UNINITIALIZED_VALUE 107 // && (answerObj instanceof Integer && (Integer) answerObj 108 // == JOptionPane.OK_OPTION)) { 109 // 110 // // call out to the method which does the actual 111 // // terracing. 112 // terraceBuilding(way, dialog.numberFrom(), dialog 113 // .numberTo(), dialog.stepSize(), dialog 114 // .streetName()); 115 // 116 // } 81 // show input dialog. 82 new HouseNumberInputHandler(this, way, title); 83 117 84 } else { 118 85 badSelect = true; … … 149 116 nb = segments.intValue(); 150 117 } else { 151 // TODO: we're in trouble. 152 // do exception handling. 153 nb = 0; 118 // if we get here, there is is a bug in the input validation. 119 throw new TerracerRuntimeException( 120 "Could not determine segments from parameters, this is a bug. " 121 + "Parameters were: segments " + segments 122 + " from " + from + " to " + to + " step " + step); 154 123 } 155 124 … … 419 388 420 389 /** 421 * Generates a list of all visible names of highways in order to do422 * autocompletion on the road name.423 *424 * TODO: REMOVE this method here!425 */426 TreeSet<String> createAutoCompletionInfo() {427 final TreeSet<String> names = new TreeSet<String>();428 for (OsmPrimitive osm : Main.main.getCurrentDataSet()429 .allNonDeletedPrimitives()) {430 if (osm.getKeys() != null && osm.keySet().contains("highway")431 && osm.keySet().contains("name")) {432 names.add(osm.get("name"));433 }434 }435 return names;436 }437 438 /**439 390 * Creates a new node at the interpolated position between the argument 440 391 * nodes. Interpolates linearly in Lat/Lon coordinates.
Note:
See TracChangeset
for help on using the changeset viewer.