Changeset 1814 in josm for trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
- Timestamp:
- 2009-07-19T19:04:49+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r1759 r1814 101 101 for (OsmPrimitive s : sel) { 102 102 String v = s.get(key); 103 if (v != null) 103 if (v != null) { 104 104 returnValue.values.add(v); 105 else105 } else { 106 106 returnValue.hadEmpty = true; 107 if(s.keys != null && s.keys.size() > 0) 107 } 108 if(s.keys != null && s.keys.size() > 0) { 108 109 returnValue.hadKeys = true; 110 } 109 111 } 110 112 return returnValue; … … 149 151 // all objects use the same value 150 152 value = new JTextField(); 151 for (String s : usage.values) ((JTextField) value).setText(s); 153 for (String s : usage.values) { 154 ((JTextField) value).setText(s); 155 } 152 156 originalValue = ((JTextField)value).getText(); 153 157 } else { … … 158 162 originalValue = DIFFERENT; 159 163 } 160 if(locale_text == null) 164 if(locale_text == null) { 161 165 locale_text = tr(text); 166 } 162 167 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 163 168 p.add(value, GBC.eol().fill(GBC.HORIZONTAL)); … … 169 174 // return if unchanged 170 175 String v = (value instanceof JComboBox) ? 171 ((JComboBox)value).getEditor().getItem().toString() : 172 ((JTextField)value).getText(); 173 174 if (use_last_as_default) lastValue.put(key, v); 175 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return; 176 177 if (delete_if_empty && v.length() == 0) 178 v = null; 179 cmds.add(new ChangePropertyCommand(sel, key, v)); 176 ((JComboBox)value).getEditor().getItem().toString() : 177 ((JTextField)value).getText(); 178 179 if (use_last_as_default) { 180 lastValue.put(key, v); 181 } 182 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return; 183 184 if (delete_if_empty && v.length() == 0) { 185 v = null; 186 } 187 cmds.add(new ChangePropertyCommand(sel, key, v)); 180 188 } 181 189 @Override boolean requestFocusInWindow() {return value.requestFocusInWindow();} … … 200 208 def = default_; 201 209 202 if(locale_text == null) 210 if(locale_text == null) { 203 211 locale_text = tr(text); 212 } 204 213 205 214 String oneValue = null; 206 for (String s : usage.values) oneValue = s; 215 for (String s : usage.values) { 216 oneValue = s; 217 } 207 218 if (usage.values.size() < 2 && (oneValue == null || OsmUtils.trueval.equals(oneValue) || OsmUtils.falseval.equals(oneValue))) { 208 219 if(def) 209 220 { 210 221 for (OsmPrimitive s : sel) 211 if(s.keys != null && s.keys.size() > 0) def = false; 222 if(s.keys != null && s.keys.size() > 0) { 223 def = false; 224 } 212 225 } 213 226 … … 215 228 // we can display a standard check box. 216 229 initialState = OsmUtils.trueval.equals(oneValue) ? 217 230 QuadStateCheckBox.State.SELECTED : 218 231 OsmUtils.falseval.equals(oneValue) ? 219 QuadStateCheckBox.State.NOT_SELECTED :220 def ? QuadStateCheckBox.State.SELECTED221 : QuadStateCheckBox.State.UNSET;232 QuadStateCheckBox.State.NOT_SELECTED : 233 def ? QuadStateCheckBox.State.SELECTED 234 : QuadStateCheckBox.State.UNSET; 222 235 check = new QuadStateCheckBox(locale_text, initialState, 223 236 new QuadStateCheckBox.State[] { … … 249 262 cmds.add(new ChangePropertyCommand(sel, key, 250 263 check.getState() == QuadStateCheckBox.State.SELECTED ? OsmUtils.trueval : 251 check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? OsmUtils.falseval :252 null));264 check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? OsmUtils.falseval : 265 null)); 253 266 } 254 267 @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();} … … 280 293 String[] value_array = values.split(","); 281 294 String[] display_array; 282 if(locale_display_values != null) 295 if(locale_display_values != null) { 283 296 display_array = locale_display_values.split(","); 284 else if(display_values != null)297 } else if(display_values != null) { 285 298 display_array = display_values.split(","); 286 else299 } else { 287 300 display_array = value_array; 301 } 288 302 289 303 lhm = new LinkedHashMap<String,String>(); … … 294 308 for (int i=0; i<value_array.length; i++) { 295 309 lhm.put(value_array[i], 296 (locale_display_values == null) ?297 tr(display_array[i]) : display_array[i]);310 (locale_display_values == null) ? 311 tr(display_array[i]) : display_array[i]); 298 312 } 299 313 if(!usage.unused()) 300 314 { 301 315 for (String s : usage.values) { 302 if (!lhm.containsKey(s)) lhm.put(s, s); 303 } 304 } 305 if (default_ != null && !lhm.containsKey(default_)) lhm.put(default_, default_); 306 if(!lhm.containsKey("")) lhm.put("", ""); 316 if (!lhm.containsKey(s)) { 317 lhm.put(s, s); 318 } 319 } 320 } 321 if (default_ != null && !lhm.containsKey(default_)) { 322 lhm.put(default_, default_); 323 } 324 if(!lhm.containsKey("")) { 325 lhm.put("", ""); 326 } 307 327 308 328 combo = new JComboBox(lhm.values().toArray()); … … 330 350 } 331 351 332 if(locale_text == null) 352 if(locale_text == null) { 333 353 locale_text = tr(text); 354 } 334 355 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 335 356 p.add(combo, GBC.eol().fill(GBC.HORIZONTAL)); … … 340 361 String display = (obj == null) ? null : obj.toString(); 341 362 String value = null; 342 if(display == null && combo.isEditable()) 363 if(display == null && combo.isEditable()) { 343 364 display = combo.getEditor().getItem().toString(); 365 } 344 366 345 367 if (display != null) … … 347 369 for (String key : lhm.keySet()) { 348 370 String k = lhm.get(key); 349 if (k != null && k.equals(display)) value=key; 350 } 351 if(value == null) 371 if (k != null && k.equals(display)) { 372 value=key; 373 } 374 } 375 if(value == null) { 352 376 value = display; 353 }354 else377 } 378 } else { 355 379 value = ""; 380 } 356 381 357 382 // no change if same as before 358 383 if (value.equals(originalValue) || (originalValue == null && (value == null || value.length() == 0))) return; 359 384 360 if (delete_if_empty && value != null && value.length() == 0) 385 if (delete_if_empty && value != null && value.length() == 0) { 361 386 value = null; 387 } 362 388 cmds.add(new ChangePropertyCommand(sel, key, value)); 363 389 } … … 370 396 371 397 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 372 if(locale_text == null) 398 if(locale_text == null) { 373 399 locale_text = tr(text); 400 } 374 401 p.add(new JLabel(locale_text), GBC.eol()); 375 402 return false; … … 385 412 386 413 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 387 if(locale_text == null) 414 if(locale_text == null) { 388 415 locale_text = text == null ? tr("More information about this feature") : tr(text); 416 } 389 417 String url = locale_href; 390 418 if (url == null) { … … 449 477 putValue("toolbar", "tagging_" + getRawName()); 450 478 putValue(SHORT_DESCRIPTION, (group != null ? 451 tr("Use preset ''{0}'' of group ''{1}''", getLocaleName(), group.getName()) :452 tr("Use preset ''{0}''", getLocaleName())));479 tr("Use preset ''{0}'' of group ''{1}''", getLocaleName(), group.getName()) : 480 tr("Use preset ''{0}''", getLocaleName()))); 453 481 } 454 482 455 483 public String getLocaleName() { 456 if(locale_name == null) 484 if(locale_name == null) { 457 485 locale_name = tr(name); 486 } 458 487 return locale_name; 459 488 } … … 479 508 icon = new ImageIcon(iconName); 480 509 } 481 if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 16) 510 if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 16) { 482 511 icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)); 512 } 483 513 putValue(Action.SMALL_ICON, icon); 484 514 } … … 488 518 */ 489 519 private static Collection<String> allowedtypes = Arrays.asList(new String[] 490 {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")});520 {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 491 521 public void setType(String types) throws SAXException { 492 522 this.types = Arrays.asList(types.split(",")); … … 517 547 if (o instanceof TaggingPresetMenu) { 518 548 TaggingPresetMenu tp = (TaggingPresetMenu) o; 519 if(tp == lastmenu) 549 if(tp == lastmenu) { 520 550 lastmenu = tp.group; 521 else551 } else 522 552 { 523 553 tp.setDisplayName(); … … 538 568 all.add(tp); 539 569 Main.toolbar.register(tp); 540 } else 570 } else { 541 571 all.getLast().data.add((Item)o); 572 } 542 573 } 543 574 return all; … … 548 579 LinkedList<String> sources = new LinkedList<String>(); 549 580 550 if(Main.pref.getBoolean("taggingpreset.enable-defaults", true)) 581 if(Main.pref.getBoolean("taggingpreset.enable-defaults", true)) { 551 582 sources.add("resource://presets/presets.xml"); 583 } 552 584 sources.addAll(Main.pref.getCollection("taggingpreset.sources", new LinkedList<String>())); 553 585 … … 604 636 for (Item i : data) 605 637 { 606 if(i instanceof Link) 638 if(i instanceof Link) { 607 639 l.add(i); 608 else609 { 610 if(i.addToPanel(p, selected)) 640 } else 641 { 642 if(i.addToPanel(p, selected)) { 611 643 p.hasElements = true; 612 } 613 } 614 for(Item link : l) 644 } 645 } 646 } 647 for(Item link : l) { 615 648 link.addToPanel(p, selected); 649 } 616 650 return p; 617 651 } 618 652 619 653 public void actionPerformed(ActionEvent e) { 620 Collection<OsmPrimitive> sel = createSelection(Main. ds.getSelected());654 Collection<OsmPrimitive> sel = createSelection(Main.main.getCurrentDataSet().getSelected()); 621 655 PresetPanel p = createPanel(sel); 622 656 if (p == null) … … 627 661 String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size()); 628 662 if(sel.size() == 0) { 629 if(originalSelectionEmpty) 663 if(originalSelectionEmpty) { 630 664 title = tr("Nothing selected!"); 631 else665 } else { 632 666 title = tr("Selection unsuitable!"); 667 } 633 668 } 634 669 … … 651 686 if (sel.size() != 0 && answer == 1) { 652 687 Command cmd = createCommand(sel); 653 if (cmd != null) 688 if (cmd != null) { 654 689 Main.main.undoRedo.add(cmd); 655 } 656 Main.ds.setSelected(Main.ds.getSelected()); // force update 690 } 691 } 692 Main.main.getCurrentDataSet().setSelected(Main.main.getCurrentDataSet().getSelected()); // force update 657 693 } 658 694 … … 676 712 if(osm instanceof Relation) 677 713 { 678 if(!types.contains("relation")) continue; 714 if(!types.contains("relation")) { 715 continue; 716 } 679 717 } 680 718 else if(osm instanceof Node) 681 719 { 682 if(!types.contains("node")) continue; 720 if(!types.contains("node")) { 721 continue; 722 } 683 723 } 684 724 else if(osm instanceof Way) 685 725 { 686 726 if(!types.contains("way") && 687 !(types.contains("closedway") && ((Way)osm).isClosed()))727 !(types.contains("closedway") && ((Way)osm).isClosed())) { 688 728 continue; 729 } 689 730 } 690 731 } … … 696 737 private Command createCommand(Collection<OsmPrimitive> sel) { 697 738 List<Command> cmds = new LinkedList<Command>(); 698 for (Item i : data) 739 for (Item i : data) { 699 740 i.addCommands(sel, cmds); 741 } 700 742 if (cmds.size() == 0) 701 743 return null;
Note:
See TracChangeset
for help on using the changeset viewer.