Changeset 1353 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
- Timestamp:
- 31.01.2009 19:09:46 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r1268 r1353 59 59 import org.openstreetmap.josm.gui.MapFrame; 60 60 import org.openstreetmap.josm.gui.SideButton; 61 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;62 import org.openstreetmap.josm.gui.tagging.ForwardActionListener;63 import org.openstreetmap.josm.gui.tagging.TaggingCellRenderer;64 import org.openstreetmap.josm.gui.tagging.TaggingPreset;65 61 import org.openstreetmap.josm.tools.AutoCompleteComboBox; 66 62 import org.openstreetmap.josm.tools.GBC; … … 128 124 */ 129 125 void propertyEdit(int row) { 126 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 127 if (sel.isEmpty()) return; 128 130 129 String key = propertyData.getValueAt(row, 0).toString(); 131 130 objKey=key; 132 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 133 if (sel.isEmpty()) { 134 JOptionPane.showMessageDialog(Main.parent, tr("Please select the objects you want to change properties for.")); 135 return; 136 } 131 137 132 String msg = "<html>"+trn("This will change up to {0} object.", "This will change up to {0} objects.", sel.size(), sel.size())+"<br><br>("+tr("An empty value deletes the key.", key)+")</html>"; 138 133 … … 304 299 void add() { 305 300 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 306 if (sel.isEmpty()) { 307 JOptionPane.showMessageDialog(Main.parent, tr("Please select objects for which you want to change properties.")); 308 return; 309 } 301 if (sel.isEmpty()) return; 310 302 311 303 JPanel p = new JPanel(new BorderLayout()); … … 402 394 Main.ds.fireSelectionChanged(sel); 403 395 selectionChanged(sel); // update table 404 396 405 397 int rowCount = propertyTable.getRowCount(); 406 398 propertyTable.changeSelection((row < rowCount ? row : (rowCount-1)), 0, false, false); … … 439 431 public JComboBox taggingPresets = new JComboBox(); 440 432 433 /** 434 * The Add/Edit/Delete buttons (needed to be able to disable them) 435 */ 436 private final SideButton btnAdd; 437 private final SideButton btnEdit; 438 private final SideButton btnDel; 439 440 private final JLabel selectSth = new JLabel(tr("Please select the objects you want to change properties for.")); 441 441 442 442 /** … … 448 448 Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 449 449 450 // ---------------------------------------451 // This drop-down is really deprecated but we offer people a chance to452 // activate it if they really want. Presets should be used from the453 // menu.454 if (TaggingPresetPreference.taggingPresets.size() > 0 &&455 Main.pref.getBoolean("taggingpreset.in-properties-dialog", false)) {456 Vector<ActionListener> allPresets = new Vector<ActionListener>();457 for (final TaggingPreset p : TaggingPresetPreference.taggingPresets)458 allPresets.add(new ForwardActionListener(this, p));459 460 TaggingPreset empty = new TaggingPreset();461 // empty.setName("this drop-down will be removed soon");462 allPresets.add(0, new ForwardActionListener(this, empty));463 taggingPresets.setModel(new DefaultComboBoxModel(allPresets));464 JPanel north = new JPanel(new GridBagLayout());465 north.add(getComponent(0),GBC.eol().fill(GBC.HORIZONTAL));466 north.add(taggingPresets,GBC.eol().fill(GBC.HORIZONTAL));467 add(north, BorderLayout.NORTH);468 }469 taggingPresets.addActionListener(new ActionListener(){470 public void actionPerformed(ActionEvent e) {471 TaggingPreset preset = ((ForwardActionListener)taggingPresets.getSelectedItem()).preset;472 preset.actionPerformed(e);473 taggingPresets.setSelectedItem(null);474 }475 });476 taggingPresets.setRenderer(new TaggingCellRenderer());477 478 450 // setting up the properties table 479 480 451 propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 481 452 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); … … 548 519 JPanel bothTables = new JPanel(); 549 520 bothTables.setLayout(new GridBagLayout()); 521 bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10)); 550 522 bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 551 523 bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH)); … … 601 573 { 602 574 int sel = propertyTable.getSelectedRow(); 603 if (e.getActionCommand().equals("Edit")) { 604 if(propertyTable.getRowCount() == 1) 605 sel = 0; 606 if (sel == -1) 607 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit.")); 608 else 609 propertyEdit(sel); 610 } else if (e.getActionCommand().equals("Delete")) { 611 if (sel == -1) 612 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete.")); 613 else 614 delete(sel); 615 } 575 // Although we might edit/delete the wrong tag here, chances are still better 576 // than just displaying an error message (which always "fails"). 577 if (e.getActionCommand().equals("Edit")) 578 propertyEdit(sel >= 0 ? sel : 0); 579 else if (e.getActionCommand().equals("Delete")) 580 delete(sel >= 0 ? sel : 0); 616 581 } 617 582 } … … 620 585 Shortcut s = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, 621 586 Shortcut.GROUP_MNEMONIC); 622 buttonPanel.add(new SideButton(marktr("Add"),"add","Properties", 623 tr("Add a new key/value pair to all objects"), s, buttonAction)); 587 this.btnAdd = new SideButton(marktr("Add"),"add","Properties", 588 tr("Add a new key/value pair to all objects"), s, buttonAction); 589 buttonPanel.add(this.btnAdd); 624 590 625 591 s = Shortcut.registerShortcut("properties:edit", tr("Edit Properties"), KeyEvent.VK_I, 626 592 Shortcut.GROUP_MNEMONIC); 627 buttonPanel.add(new SideButton(marktr("Edit"),"edit","Properties", 628 tr("Edit the value of the selected key for all objects"), s, buttonAction)); 593 this.btnEdit = new SideButton(marktr("Edit"),"edit","Properties", 594 tr("Edit the value of the selected key for all objects"), s, buttonAction); 595 buttonPanel.add(this.btnEdit); 629 596 630 597 s = Shortcut.registerShortcut("properties:delete", tr("Delete Properties"), KeyEvent.VK_Q, 631 598 Shortcut.GROUP_MNEMONIC); 632 buttonPanel.add(new SideButton(marktr("Delete"),"delete","Properties", 633 tr("Delete the selected key in all objects"), s, buttonAction)); 599 this.btnDel = new SideButton(marktr("Delete"),"delete","Properties", 600 tr("Delete the selected key in all objects"), s, buttonAction); 601 buttonPanel.add(this.btnDel); 634 602 add(buttonPanel, BorderLayout.SOUTH); 635 603 … … 652 620 653 621 // re-load property data 654 655 622 propertyData.setRowCount(0); 656 623 … … 681 648 } 682 649 650 boolean hasTags = !newSelection.isEmpty() && propertyData.getRowCount() > 0; 651 boolean hasSelection = !newSelection.isEmpty(); 652 btnAdd.setEnabled(hasSelection); 653 btnEdit.setEnabled(hasTags); 654 btnDel.setEnabled(hasTags); 655 propertyTable.setVisible(hasSelection); 656 propertyTable.getTableHeader().setVisible(hasSelection); 657 selectSth.setVisible(!hasSelection); 658 if(hasTags) propertyTable.changeSelection(0, 0, false, false); 659 683 660 // re-load membership data 684 661 // this is rather expensive since we have to walk through all members of all existing relationships. … … 708 685 709 686 membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 687 membershipTable.setVisible(membershipData.getRowCount() > 0); 710 688 711 689 if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) { 712 setTitle(tr("Properties: {0} / Memberships: {1}", 690 setTitle(tr("Properties: {0} / Memberships: {1}", 713 691 propertyData.getRowCount(), membershipData.getRowCount()), true); 714 692 } else { 715 693 setTitle(tr("Properties / Memberships"), false); 716 694 } 717 718 695 } 719 696 }
Note: See TracChangeset
for help on using the changeset viewer.
