Changeset 17762 in osm for applications
- Timestamp:
- 2009-09-22T17:45:22+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation/AddrInterpolationAction.java
r17721 r17762 32 32 33 33 public void actionPerformed(ActionEvent e) { 34 AddrInterpolationDialog addrDialog = new AddrInterpolationDialog(tr("Define Address Interpolation"), "AddrInterpolation", 35 tr("Define Address Interpolation"), null, 100); 34 AddrInterpolationDialog addrDialog = new AddrInterpolationDialog(tr("Define Address Interpolation")); 36 35 37 36 -
applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation/AddrInterpolationDialog.java
r17745 r17762 17 17 import java.awt.event.ActionEvent; 18 18 import java.awt.event.ActionListener; 19 import java.awt.event.FocusAdapter; 20 import java.awt.event.FocusEvent; 19 21 import java.awt.event.KeyAdapter; 20 22 import java.awt.event.KeyEvent; … … 28 30 import javax.swing.JButton; 29 31 import javax.swing.JComboBox; 32 import javax.swing.JDialog; 30 33 import javax.swing.JLabel; 31 34 import javax.swing.JOptionPane; … … 43 46 import org.openstreetmap.josm.data.osm.RelationMember; 44 47 import org.openstreetmap.josm.data.osm.Way; 45 import org.openstreetmap.josm.gui.dialogs.ToggleDialog;46 48 import org.openstreetmap.josm.tools.ImageProvider; 47 import org.openstreetmap.josm.tools.Shortcut;48 49 import org.openstreetmap.josm.tools.UrlLabel; 49 50 … … 56 57 57 58 58 public class AddrInterpolationDialog extends ToggleDialog implements ActionListener {59 public class AddrInterpolationDialog extends JDialog implements ActionListener { 59 60 60 61 private Way selectedStreet = null; … … 82 83 83 84 private boolean relationChanged = false; // Whether to re-trigger data changed for relation 85 // Track whether interpolation method is known so that auto detect doesn't override a previous choice. 86 private boolean interpolationMethodSet = false; 84 87 85 88 … … 90 93 91 94 92 public AddrInterpolationDialog(String name, String iconName, 93 String tooltip, Shortcut shortcut, int preferredHeight) { 94 super(name, iconName, tooltip, shortcut, preferredHeight); 95 public AddrInterpolationDialog(String name) { 95 96 96 97 if (!FindAndSaveSelections()) { … … 120 121 { 121 122 if (addrInterpolationWay != null) { 122 addrInterpolationList.requestFocus();123 startTextField.requestFocus(); 123 124 } 124 125 else { … … 197 198 198 199 199 JLabel[] textLabels = { numberingLabel, startLabel, endLabel};200 Component[] editFields = { addrInterpolationList, startTextField, endTextField};200 JLabel[] textLabels = {startLabel, endLabel, numberingLabel}; 201 Component[] editFields = {startTextField, endTextField, addrInterpolationList}; 201 202 AddEditControlRows(textLabels, editFields, editControlsPane); 202 203 … … 234 235 endTextField.addKeyListener(enterProcessor); 235 236 cityTextField.addKeyListener(enterProcessor); 237 addrInterpolationList.addKeyListener(enterProcessor); 238 239 240 // Watch when Interpolation Method combo box is selected so that 241 // it can auto-detect method based on entered numbers. 242 addrInterpolationList.addFocusListener(new FocusAdapter() { 243 @Override 244 public void focusGained(FocusEvent fe){ 245 if (!interpolationMethodSet) { 246 AutoDetectInterpolationMethod(); 247 interpolationMethodSet = true; // Don't auto detect over a previous choice 248 } 249 } 250 }); 236 251 237 252 … … 270 285 271 286 return editControlsPane; 287 } 288 289 290 291 // Call after both starting and ending housenumbers have been entered - usually when 292 // combo box gets focus. 293 private void AutoDetectInterpolationMethod() { 294 295 String startValueString = ReadTextField(startTextField); 296 String endValueString = ReadTextField(endTextField); 297 if (startValueString.equals("") || endValueString.equals("")) { 298 // Not all values entered yet 299 return; 300 } 301 302 String selectedMethod = GetInterpolationMethod(); // Currently selected method 303 304 // String[] addrInterpolationTags = { "odd", "even", "all", "alphabetic" }; // Tag values for map 305 306 if (isLong(startValueString) && isLong(endValueString)) { 307 // Have 2 numeric values 308 long startValue = Long.parseLong( startValueString ); 309 long endValue = Long.parseLong( endValueString ); 310 311 if (isEven(startValue)) { 312 if (isEven(endValue)) { 313 SelectInterpolationMethod("even"); 314 } 315 else { 316 SelectInterpolationMethod("all"); 317 } 318 } else { 319 if (!isEven(endValue)) { 320 SelectInterpolationMethod("odd"); 321 } 322 else { 323 SelectInterpolationMethod("all"); 324 } 325 } 326 327 328 } else { 329 // Test for possible alpha 330 char startingChar = startValueString.charAt(startValueString.length()-1); 331 char endingChar = endValueString.charAt(endValueString.length()-1); 332 333 if ( (!IsNumeric("" + startingChar)) && (!IsNumeric("" + endingChar)) ) { 334 // Both end with alpha 335 SelectInterpolationMethod("alphabetic"); 336 } 337 338 339 340 } 341 342 343 } 344 345 346 347 // Set Interpolation Method combo box to method specified by 'currentMethod' (an OSM key) 348 private void SelectInterpolationMethod(String currentMethod) { 349 int currentIndex = 0; 350 // Must scan OSM key values because combo box is already loaded with translated strings 351 for (int i=0; i<addrInterpolationTags.length; i++) { 352 if (addrInterpolationTags[i].equals(currentMethod)) { 353 currentIndex = i; 354 break; 355 } 356 } 357 addrInterpolationList.setSelectedIndex(currentIndex); 358 272 359 } 273 360 … … 348 435 if (currentMethod != null) { 349 436 350 int currentIndex = 0; 351 // Must scan key values because combo box is already loaded with translated strings 352 for (int i=0; i<addrInterpolationTags.length; i++) { 353 if (addrInterpolationTags[i].equals(currentMethod)) { 354 currentIndex = i; 355 break; 356 } 357 } 358 addrInterpolationList.setSelectedIndex(currentIndex); 437 SelectInterpolationMethod(currentMethod); 438 interpolationMethodSet = true; // Don't auto detect over a previous choice 359 439 } 360 440
Note:
See TracChangeset
for help on using the changeset viewer.