- Timestamp:
- 2009-07-11T10:06:41+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r1613 r1763 105 105 if (e.getClickCount() < 2) 106 106 { 107 if (e.getSource() == propertyTable) 107 if (e.getSource() == propertyTable) { 108 108 membershipTable.clearSelection(); 109 else if (e.getSource() == membershipTable)109 } else if (e.getSource() == membershipTable) { 110 110 propertyTable.clearSelection(); 111 } 111 112 } 112 113 else if (e.getSource() == propertyTable) 113 114 { 114 115 int row = propertyTable.rowAtPoint(e.getPoint()); 115 if (row > -1) 116 if (row > -1) { 116 117 propertyEdit(row); 118 } 117 119 } else if (e.getSource() == membershipTable) { 118 120 int row = membershipTable.rowAtPoint(e.getPoint()); 119 if (row > -1) 121 if (row > -1) { 120 122 membershipEdit(row); 123 } 121 124 } 122 125 else … … 140 143 141 144 String msg = "<html>"+trn("This will change up to {0} object.", 142 "This will change up to {0} objects.", sel.size(), sel.size())143 +"<br><br>("+tr("An empty value deletes the key.", key)+")</html>";145 "This will change up to {0} objects.", sel.size(), sel.size()) 146 +"<br><br>("+tr("An empty value deletes the key.", key)+")</html>"; 144 147 145 148 JPanel panel = new JPanel(new BorderLayout()); … … 163 166 values.setRenderer(new DefaultListCellRenderer() { 164 167 @Override public Component getListCellRendererComponent(JList list, 165 Object value, int index, boolean isSelected, boolean cellHasFocus){168 Object value, int index, boolean isSelected, boolean cellHasFocus){ 166 169 Component c = super.getListCellRendererComponent(list, value, 167 index, isSelected, cellHasFocus);170 index, isSelected, cellHasFocus); 168 171 if (c instanceof JLabel) { 169 172 String str = null; 170 str=(String) value; 171 if (valueCount.containsKey(objKey)){ 172 Map<String, Integer> m=valueCount.get(objKey); 173 if (m.containsKey(str)) { 174 str+="("+m.get(str)+")"; 175 c.setFont(c.getFont().deriveFont(Font.ITALIC+Font.BOLD)); 176 } 173 str=(String) value; 174 if (valueCount.containsKey(objKey)){ 175 Map<String, Integer> m=valueCount.get(objKey); 176 if (m.containsKey(str)) { 177 str+="("+m.get(str)+")"; 178 c.setFont(c.getFont().deriveFont(Font.ITALIC+Font.BOLD)); 177 179 } 180 } 178 181 ((JLabel)c).setText(str); 179 182 } … … 220 223 // is not Java 1.5 221 224 //value = java.text.Normalizer.normalize(value, java.text.Normalizer.Form.NFC); 222 if (value.equals("")) 225 if (value.equals("")) { 223 226 value = null; // delete the key 227 } 224 228 String newkey = keys.getEditor().getItem().toString().trim(); 225 229 //newkey = java.text.Normalizer.normalize(newkey, java.text.Normalizer.Form.NFC); … … 228 232 value = null; // delete the key instead 229 233 } 230 if (key.equals(newkey) || value == null) 234 if (key.equals(newkey) || value == null) { 231 235 Main.main.undoRedo.add(new ChangePropertyCommand(sel, newkey, value)); 232 else {236 } else { 233 237 Collection<Command> commands=new Vector<Command>(); 234 238 commands.add(new ChangePropertyCommand(sel, key, null)); … … 258 262 } 259 263 Main.main.undoRedo.add(new SequenceCommand( 260 trn("Change properties of up to {0} object",261 "Change properties of up to {0} objects", sel.size(), sel.size()),262 commands));264 trn("Change properties of up to {0} object", 265 "Change properties of up to {0} objects", sel.size(), sel.size()), 266 commands)); 263 267 } 264 268 … … 283 287 */ 284 288 private void updateListData(String key, final TreeMap<String, TreeSet<String>> allData, 285 final AutoCompleteComboBox values) {289 final AutoCompleteComboBox values) { 286 290 Collection<String> newItems; 287 291 if (allData.containsKey(key)) { … … 300 304 */ 301 305 void membershipEdit(int row) { 302 RelationEditor.getEditor((Relation)membershipData.getValueAt(row, 0), 306 Relation relation = (Relation)membershipData.getValueAt(row, 0); 307 Main.main.map.relationListDialog.selectRelation(relation); 308 RelationEditor.getEditor(relation, 303 309 (Collection<RelationMember>) membershipData.getValueAt(row, 1) ).setVisible(true); 304 310 } … … 314 320 JPanel p = new JPanel(new BorderLayout()); 315 321 p.add(new JLabel("<html>"+trn("This will change up to {0} object.", 316 "This will change up to {0} objects.", sel.size(),sel.size())317 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH);322 "This will change up to {0} objects.", sel.size(),sel.size()) 323 +"<br><br>"+tr("Please select a key")), BorderLayout.NORTH); 318 324 final TreeMap<String, TreeSet<String>> allData = createAutoCompletionInfo(false); 319 325 final AutoCompleteComboBox keys = new AutoCompleteComboBox(); … … 356 362 */ 357 363 private void addFocusAdapter(final int row, final TreeMap<String, TreeSet<String>> allData, 358 final AutoCompleteComboBox keys, final AutoCompleteComboBox values) {364 final AutoCompleteComboBox keys, final AutoCompleteComboBox values) { 359 365 // get the combo box' editor component 360 366 JTextComponent editor = (JTextComponent)values.getEditor() 361 367 .getEditorComponent(); 362 368 // Refresh the values model when focus is gained 363 369 editor.addFocusListener(new FocusAdapter() { … … 377 383 for (String key : osm.keySet()) { 378 384 TreeSet<String> values = null; 379 if (allData.containsKey(key)) 385 if (allData.containsKey(key)) { 380 386 values = allData.get(key); 381 else {387 } else { 382 388 values = new TreeSet<String>(); 383 389 allData.put(key, values); … … 387 393 } 388 394 if (!edit) { 389 for (int i = 0; i < propertyData.getRowCount(); ++i) 395 for (int i = 0; i < propertyData.getRowCount(); ++i) { 390 396 allData.remove(propertyData.getValueAt(i, 0)); 397 } 391 398 } 392 399 return allData; … … 449 456 450 457 private final JLabel selectSth = new JLabel("<html><p>" 451 + tr("Please select the objects you want to change properties for.") + "</p></html>");458 + tr("Please select the objects you want to change properties for.") + "</p></html>"); 452 459 453 460 /** … … 456 463 public PropertiesDialog(MapFrame mapFrame) { 457 464 super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), 458 Shortcut.registerShortcut("subwindow:properties", tr("Toggle: {0}", tr("Properties/Memberships")), KeyEvent.VK_P,459 Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);465 Shortcut.registerShortcut("subwindow:properties", tr("Toggle: {0}", tr("Properties/Memberships")), KeyEvent.VK_P, 466 Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 460 467 461 468 // setting up the properties table … … 465 472 propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){ 466 473 @Override public Component getTableCellRendererComponent(JTable table, Object value, 467 boolean isSelected, boolean hasFocus, int row, int column) {474 boolean isSelected, boolean hasFocus, int row, int column) { 468 475 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 469 476 if (c instanceof JLabel) { … … 472 479 case 0: 473 480 str = (String) value; 474 break;481 break; 475 482 case 1: 476 483 Map<String, Integer> v = (Map<String,Integer>) value; … … 481 488 str=v.entrySet().iterator().next().getKey(); 482 489 } 483 break;490 break; 484 491 } 485 492 ((JLabel)c).setText(str); … … 496 503 membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() { 497 504 @Override public Component getTableCellRendererComponent(JTable table, Object value, 498 boolean isSelected, boolean hasFocus, int row, int column) {505 boolean isSelected, boolean hasFocus, int row, int column) { 499 506 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 500 507 if (c instanceof JLabel) { … … 508 515 membershipTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() { 509 516 @Override public Component getTableCellRendererComponent(JTable table, Object value, 510 boolean isSelected, boolean hasFocus, int row, int column) {517 boolean isSelected, boolean hasFocus, int row, int column) { 511 518 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 512 519 if (c instanceof JLabel) { … … 554 561 public void actionPerformed(ActionEvent e) { 555 562 int row = membershipTable.getSelectedRow(); 556 if (e.getActionCommand().equals("Add")) 563 if (e.getActionCommand().equals("Add")) { 557 564 add(); 558 else if(row >= 0)565 } else if(row >= 0) 559 566 { 560 if (e.getActionCommand().equals("Edit")) 567 if (e.getActionCommand().equals("Edit")) { 561 568 membershipEdit(row); 562 else if (e.getActionCommand().equals("Delete")) {569 } else if (e.getActionCommand().equals("Delete")) { 563 570 Relation cur = (Relation)membershipData.getValueAt(row, 0); 564 571 NameVisitor n = new NameVisitor(); … … 566 573 567 574 int result = new ExtendedDialog(Main.parent, 568 tr("Change relation"),569 tr("Really delete selection from relation {0}?", n.name),570 new String[] {tr("Delete from relation"), tr("Cancel")},571 new String[] {"dialogs/delete.png", "cancel.png"}).getValue();575 tr("Change relation"), 576 tr("Really delete selection from relation {0}?", n.name), 577 new String[] {tr("Delete from relation"), tr("Cancel")}, 578 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 572 579 573 580 if(result == 1) … … 599 606 // Although we might edit/delete the wrong tag here, chances are still better 600 607 // than just displaying an error message (which always "fails"). 601 if (e.getActionCommand().equals("Edit")) 608 if (e.getActionCommand().equals("Edit")) { 602 609 propertyEdit(sel >= 0 ? sel : 0); 603 else if (e.getActionCommand().equals("Delete"))610 } else if (e.getActionCommand().equals("Delete")) { 604 611 delete(sel >= 0 ? sel : 0); 612 } 605 613 } 606 614 } … … 608 616 609 617 Shortcut s = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, 610 Shortcut.GROUP_MNEMONIC);618 Shortcut.GROUP_MNEMONIC); 611 619 this.btnAdd = new SideButton(marktr("Add"),"add","Properties", 612 620 tr("Add a new key/value pair to all objects"), s, buttonAction); … … 614 622 615 623 s = Shortcut.registerShortcut("properties:edit", tr("Edit Properties"), KeyEvent.VK_I, 616 Shortcut.GROUP_MNEMONIC);624 Shortcut.GROUP_MNEMONIC); 617 625 this.btnEdit = new SideButton(marktr("Edit"),"edit","Properties", 618 626 tr("Edit the value of the selected key for all objects"), s, buttonAction); … … 620 628 621 629 s = Shortcut.registerShortcut("properties:delete", tr("Delete Properties"), KeyEvent.VK_Q, 622 Shortcut.GROUP_MNEMONIC);630 Shortcut.GROUP_MNEMONIC); 623 631 this.btnDel = new SideButton(marktr("Delete"),"delete","Properties", 624 632 tr("Delete the selected key in all objects"), s, buttonAction); … … 631 639 @Override public void setVisible(boolean b) { 632 640 super.setVisible(b); 633 if (b) 641 if (b) { 634 642 selectionChanged(Main.ds.getSelected()); 643 } 635 644 } 636 645 … … 677 686 for(TaggingPreset t : TaggingPresetPreference.taggingPresets) { 678 687 if(t.types == null || !((relations > 0 && !t.types.contains("relation")) && 679 (nodes > 0 && !t.types.contains("node")) &&680 (ways+closedways > 0 && !t.types.contains("way")) &&681 (closedways > 0 && !t.types.contains("closedway"))))688 (nodes > 0 && !t.types.contains("node")) && 689 (ways+closedways > 0 && !t.types.contains("way")) && 690 (closedways > 0 && !t.types.contains("closedway")))) 682 691 { 683 692 int found = 0; 684 693 for(TaggingPreset.Item i : t.data) { 685 if(!(i instanceof TaggingPreset.Key)) 694 if(!(i instanceof TaggingPreset.Key)) { 686 695 continue; 696 } 687 697 String val = ((TaggingPreset.Key)i).value; 688 698 String key = ((TaggingPreset.Key)i).key; 689 699 // we subtract 100 if not found and add 1 if found 690 700 found -= 100; 691 if(!valueCount.containsKey(key)) 701 if(!valueCount.containsKey(key)) { 692 702 continue; 703 } 693 704 694 705 Map<String, Integer> v = valueCount.get(key); 695 if(v.size() == 1 && v.containsKey(val) && v.get(val) == total) 706 if(v.size() == 1 && v.containsKey(val) && v.get(val) == total) { 696 707 found += 101; 697 } 698 699 if(found <= 0) 708 } 709 } 710 711 if(found <= 0) { 700 712 continue; 713 } 701 714 702 715 JLabel lbl = new JLabel(t.getName()); … … 713 726 presets.setMaximumSize(size); 714 727 presets.setMinimumSize(size); 715 } else 728 } else { 716 729 presets.setVisible(false); 730 } 717 731 } 718 732 … … 722 736 if (propertyTable == null) 723 737 return; // selection changed may be received in base class constructor before init 724 if (propertyTable.getCellEditor() != null) 738 if (propertyTable.getCellEditor() != null) { 725 739 propertyTable.getCellEditor().cancelCellEditing(); 740 } 726 741 727 742 // re-load property data … … 735 750 valueCount.clear(); 736 751 for (OsmPrimitive osm : newSelection) { 737 if(osm instanceof Node) ++nodes; 738 else if(osm instanceof Relation) ++relations; 739 else if(((Way)osm).isClosed()) ++closedways; 740 else ++ways; 752 if(osm instanceof Node) { 753 ++nodes; 754 } else if(osm instanceof Relation) { 755 ++relations; 756 } else if(((Way)osm).isClosed()) { 757 ++closedways; 758 } else { 759 ++ways; 760 } 741 761 for (Entry<String, String> e : osm.entrySet()) { 742 762 keyCount.put(e.getKey(), keyCount.containsKey(e.getKey()) ? keyCount.get(e.getKey())+1 : 1); … … 802 822 propertyTable.getTableHeader().setVisible(hasSelection); 803 823 selectSth.setVisible(!hasSelection); 804 if(hasTags) propertyTable.changeSelection(0, 0, false, false); 805 else if(hasMemberships) membershipTable.changeSelection(0, 0, false, false); 824 if(hasTags) { 825 propertyTable.changeSelection(0, 0, false, false); 826 } else if(hasMemberships) { 827 membershipTable.changeSelection(0, 0, false, false); 828 } 806 829 807 830 if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) { 808 831 setTitle(tr("Properties: {0} / Memberships: {1}", 809 propertyData.getRowCount(), membershipData.getRowCount()), true);832 propertyData.getRowCount(), membershipData.getRowCount()), true); 810 833 } else { 811 834 setTitle(tr("Properties / Memberships"), false); -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1677 r1763 76 76 public RelationListDialog() { 77 77 super(tr("Relations"), "relationlist", tr("Open a list of all relations."), 78 Shortcut.registerShortcut("subwindow:relations", tr("Toggle: {0}", tr("Relations")), KeyEvent.VK_R, Shortcut.GROUP_LAYER), 150);78 Shortcut.registerShortcut("subwindow:relations", tr("Toggle: {0}", tr("Relations")), KeyEvent.VK_R, Shortcut.GROUP_LAYER), 150); 79 79 displaylist.setCellRenderer(new OsmPrimitivRenderer()); 80 80 displaylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 81 81 displaylist.addMouseListener(new MouseAdapter(){ 82 82 @Override public void mouseClicked(MouseEvent e) { 83 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) 83 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { 84 84 Main.ds.setSelected((Relation)displaylist.getSelectedValue()); 85 } 85 86 } 86 87 }); … … 105 106 displaylist.addListSelectionListener(new ListSelectionListener() { 106 107 public void valueChanged(ListSelectionEvent e) { 107 sbEdit.setEnabled(getSelected() != null);108 sbDel.setEnabled(getSelected() != null);108 sbEdit.setEnabled(getSelected() != null); 109 sbDel.setEnabled(getSelected() != null); 109 110 } 110 111 }); … … 113 114 @Override public void setVisible(boolean b) { 114 115 super.setVisible(b); 115 if (b) updateList(); 116 if (b) { 117 updateList(); 118 } 116 119 } 117 120 … … 120 123 int i = 0; 121 124 for (OsmPrimitive e : DataSet.sort(Main.ds.relations)) { 122 if (!e.deleted && !e.incomplete) 125 if (!e.deleted && !e.incomplete) { 123 126 list.setElementAt(e, i++); 127 } 124 128 } 125 129 list.setSize(i); … … 137 141 public void activeLayerChange(Layer a, Layer b) { 138 142 if ((a == null || a instanceof OsmDataLayer) && b instanceof OsmDataLayer) { 139 if (a != null) ((OsmDataLayer)a).listenerDataChanged.remove(this); 143 if (a != null) { 144 ((OsmDataLayer)a).listenerDataChanged.remove(this); 145 } 140 146 ((OsmDataLayer)b).listenerDataChanged.add(this); 141 147 updateList(); … … 190 196 */ 191 197 private Relation getSelected() { 192 if(list.size() == 1) 198 if(list.size() == 1) { 193 199 displaylist.setSelectedIndex(0); 200 } 194 201 return (Relation) displaylist.getSelectedValue(); 195 202 } 203 204 /** 205 * Selects the relation <code>relation</code> in the list of relations. 206 * 207 * @param relation the relation 208 */ 209 public void selectRelation(Relation relation) { 210 if (relation == null) return; 211 int i = -1; 212 for (i=0; i < list.getSize(); i++) { 213 Relation r = (Relation)list.get(i); 214 if (r == relation) { 215 break; 216 } 217 } 218 if (i >= 0 && i < list.getSize()) { 219 displaylist.setSelectedIndex(i); 220 } 221 } 196 222 }
Note:
See TracChangeset
for help on using the changeset viewer.