Changeset 5639 in josm
- Timestamp:
- 2012-12-28T02:16:10+01:00 (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/defaultpresets.xml
r5628 r5639 35 35 default: default string to display (defaults to "") 36 36 use_last_as_default: true/false/force (default is "false") 37 auto_increment: may contain a comma separated list of integer increments or 38 decrements, e.g. "-2,-1,+1,+2"; a button will be shown next 39 to the text field for each value, allowing the user to select 40 auto-increment with the given stepping. auto-increment only 41 happens if the user selects it. default is no auto-increment; 42 mutually exclusive with use_last_as_default. 37 43 match: none/key/key!/keyvalue (default is "none", see below for more information) 38 44 length: length of input box (number of characters allowed) … … 5727 5733 <label text="Edit Address Information" /> 5728 5734 <space /> 5729 <text key="addr:housenumber" text="House number" match="key" />5735 <text key="addr:housenumber" text="House number" match="key" auto_increment="-2,-1,+1,+2" /> 5730 5736 <optional> 5731 5737 <text key="addr:housename" text="House name" match="key" /> -
trunk/data/tagging-preset.xsd
r5614 r5639 117 117 <attribute name="default" type="string" /> 118 118 <attribute name="use_last_as_default" type="tns:last_default" /> 119 <attribute name="auto_increment" type="string" /> 119 120 <attribute name="match" type="tns:match" /> 120 121 <attribute name="length" type="positiveInteger" /> -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r5624 r5639 12 12 import java.awt.Insets; 13 13 import java.awt.event.ActionEvent; 14 import java.awt.event.ActionListener; 14 15 import java.io.BufferedReader; 15 16 import java.io.File; … … 19 20 import java.io.Reader; 20 21 import java.io.UnsupportedEncodingException; 22 import java.text.NumberFormat; 23 import java.text.ParseException; 21 24 import java.util.ArrayList; 22 25 import java.util.Arrays; … … 34 37 import javax.swing.AbstractAction; 35 38 import javax.swing.Action; 39 import javax.swing.ButtonGroup; 36 40 import javax.swing.ImageIcon; 41 import javax.swing.JButton; 37 42 import javax.swing.JComponent; 38 43 import javax.swing.JLabel; … … 42 47 import javax.swing.JScrollPane; 43 48 import javax.swing.JTextField; 49 import javax.swing.JToggleButton; 44 50 import javax.swing.ListCellRenderer; 45 51 import javax.swing.ListModel; … … 393 399 public String originalValue; 394 400 public String use_last_as_default = "false"; 401 public String auto_increment; 395 402 public String length; 396 403 … … 411 418 if (!"false".equals(use_last_as_default) && lastValue.containsKey(key)) { 412 419 textField.setText(lastValue.get(key)); 420 } else if (auto_increment_selected != 0 && auto_increment != null) { 421 try { 422 textField.setText(Integer.toString(Integer.parseInt(lastValue.get(key)) + auto_increment_selected)); 423 } catch (NumberFormatException ex) { 424 // Ignore - cannot auto-increment if last was non-numeric 425 } 413 426 } else { 414 427 textField.setText(default_); … … 443 456 } 444 457 } 458 459 // if there's an auto_increment setting, then wrap the text field 460 // into a panel, appending a number of buttons. 461 // auto_increment has a format like -2,-1,1,2 462 // the text box being the first component in the panel is relied 463 // on in a rather ugly fashion further down. 464 if (auto_increment != null) { 465 ButtonGroup bg = new ButtonGroup(); 466 JPanel pnl = new JPanel(new GridBagLayout()); 467 pnl.add(value, GBC.std().fill(GBC.HORIZONTAL)); 468 469 // first, one button for each auto_increment value 470 for (final String ai : auto_increment.split(",")) { 471 JToggleButton aibutton = new JToggleButton(ai); 472 aibutton.setToolTipText(tr("Select auto-increment of {0} for this field", ai)); 473 aibutton.setMargin(new java.awt.Insets(0,0,0,0)); 474 bg.add(aibutton); 475 try { 476 // TODO there must be a better way to parse a number like "+3" than this. 477 final int buttonvalue = ((Number)NumberFormat.getIntegerInstance().parse(ai.replace("+", ""))).intValue(); 478 if (auto_increment_selected == buttonvalue) aibutton.setSelected(true); 479 aibutton.addActionListener(new ActionListener() { 480 public void actionPerformed(ActionEvent e) { 481 auto_increment_selected = buttonvalue; 482 } 483 }); 484 pnl.add(aibutton, GBC.std()); 485 } catch (ParseException x) { 486 System.err.println("Cannot parse auto-increment value of '" + ai + "' into an integer"); 487 } 488 } 489 490 // an invisible toggle button for "release" of the button group 491 final JToggleButton clearbutton = new JToggleButton("X"); 492 clearbutton.setVisible(false); 493 bg.add(clearbutton); 494 // and its visible counterpart. - this mechanism allows us to 495 // have *no* button selected after the X is clicked, instead 496 // of the X remaining selected 497 JButton releasebutton = new JButton("X"); 498 releasebutton.setToolTipText(tr("Cancel auto-increment for this field")); 499 releasebutton.setMargin(new java.awt.Insets(0,0,0,0)); 500 releasebutton.addActionListener(new ActionListener() { 501 public void actionPerformed(ActionEvent e) { 502 auto_increment_selected = 0; 503 clearbutton.setSelected(true); 504 } 505 }); 506 pnl.add(releasebutton, GBC.std().eol()); 507 value = pnl; 508 } 445 509 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 446 510 p.add(value, GBC.eol().fill(GBC.HORIZONTAL)); … … 452 516 453 517 // return if unchanged 454 String v = (value instanceof JosmComboBox) 455 ? ((JosmComboBox) value).getEditor().getItem().toString() 456 : ((JTextField) value).getText(); 457 v = v.trim(); 458 459 if (!"false".equals(use_last_as_default)) { 460 lastValue.put(key, v); 461 } 462 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) 463 return; 464 465 changedTags.add(new Tag(key, v)); 518 String v = null; 519 if (value instanceof JosmComboBox) { 520 v = ((JosmComboBox) value).getEditor().getItem().toString(); 521 } else if (value instanceof JTextField) { 522 v = ((JTextField) value).getText(); 523 } else if (value instanceof JPanel) { 524 // this is what was alluded to with "ugly fashion" above. 525 v = ((JTextField) (((JPanel)value).getComponent(0))).getText(); 526 } else { 527 System.err.println("No 'last value' support for component " + value); 528 return; 529 } 530 531 v = v.trim(); 532 533 if (!"false".equals(use_last_as_default) || auto_increment != null) { 534 lastValue.put(key, v); 535 } 536 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) 537 return; 538 539 changedTags.add(new Tag(key, v)); 466 540 } 467 541 … … 1257 1331 public Match nameTemplateFilter; 1258 1332 private static final HashMap<String,String> lastValue = new HashMap<String,String>(); 1333 private static int auto_increment_selected = 0; 1259 1334 1260 1335 /**
Note:
See TracChangeset
for help on using the changeset viewer.