Ignore:
Timestamp:
31.01.2009 19:09:46 (3 years ago)
Author:
stoecker
Message:

apply patch by xeen - #2114

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r1268 r1353  
    5959import org.openstreetmap.josm.gui.MapFrame; 
    6060import 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; 
    6561import org.openstreetmap.josm.tools.AutoCompleteComboBox; 
    6662import org.openstreetmap.josm.tools.GBC; 
     
    128124     */ 
    129125    void propertyEdit(int row) { 
     126        Collection<OsmPrimitive> sel = Main.ds.getSelected(); 
     127        if (sel.isEmpty()) return; 
     128 
    130129        String key = propertyData.getValueAt(row, 0).toString(); 
    131130        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 
    137132        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>"; 
    138133 
     
    304299    void add() { 
    305300        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; 
    310302 
    311303        JPanel p = new JPanel(new BorderLayout()); 
     
    402394        Main.ds.fireSelectionChanged(sel); 
    403395        selectionChanged(sel); // update table 
    404            
     396 
    405397        int rowCount = propertyTable.getRowCount(); 
    406398        propertyTable.changeSelection((row < rowCount ? row : (rowCount-1)), 0, false, false); 
     
    439431    public JComboBox taggingPresets = new JComboBox(); 
    440432 
     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.")); 
    441441 
    442442    /** 
     
    448448        Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 
    449449 
    450         // --------------------------------------- 
    451         // This drop-down is really deprecated but we offer people a chance to 
    452         // activate it if they really want. Presets should be used from the 
    453         // 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  
    478450        // setting up the properties table 
    479  
    480451        propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 
    481452        propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
     
    548519        JPanel bothTables = new JPanel(); 
    549520        bothTables.setLayout(new GridBagLayout()); 
     521        bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10)); 
    550522        bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 
    551523        bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH)); 
     
    601573                { 
    602574                    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); 
    616581                } 
    617582            } 
     
    620585        Shortcut s = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, 
    621586        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); 
    624590 
    625591        s = Shortcut.registerShortcut("properties:edit", tr("Edit Properties"), KeyEvent.VK_I, 
    626592        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); 
    629596 
    630597        s = Shortcut.registerShortcut("properties:delete", tr("Delete Properties"), KeyEvent.VK_Q, 
    631598        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); 
    634602        add(buttonPanel, BorderLayout.SOUTH); 
    635603 
     
    652620 
    653621        // re-load property data 
    654  
    655622        propertyData.setRowCount(0); 
    656623 
     
    681648        } 
    682649 
     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 
    683660        // re-load membership data 
    684661        // this is rather expensive since we have to walk through all members of all existing relationships. 
     
    708685 
    709686        membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 
     687        membershipTable.setVisible(membershipData.getRowCount() > 0); 
    710688 
    711689        if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) { 
    712             setTitle(tr("Properties: {0} / Memberships: {1}",  
     690            setTitle(tr("Properties: {0} / Memberships: {1}", 
    713691                propertyData.getRowCount(), membershipData.getRowCount()), true); 
    714692        } else { 
    715693            setTitle(tr("Properties / Memberships"), false); 
    716694        } 
    717  
    718695    } 
    719696} 
Note: See TracChangeset for help on using the changeset viewer.