Changeset 6939 in josm


Ignore:
Timestamp:
2014-03-28T21:34:47+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #9864 - add "Add/Edit/Delete" entries to tags/memberships contextual menus. Can be disabled with properties.menu.add_edit_delete`.

File:
1 edited

Legend:

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

    r6890 r6939  
    143143    private final JTable membershipTable = new JTable(membershipData);
    144144
     145    /** JPanel containing both previous tables */
     146    private final JPanel bothTables = new JPanel();
     147
    145148    // Popup menus
    146149    private final JPopupMenu tagMenu = new JPopupMenu();
    147150    private final JPopupMenu membershipMenu = new JPopupMenu();
     151    private final JPopupMenu blankSpaceMenu = new JPopupMenu();
    148152
    149153    // Popup menu handlers
    150154    private final PopupMenuHandler tagMenuHandler = new PopupMenuHandler(tagMenu);
    151155    private final PopupMenuHandler membershipMenuHandler = new PopupMenuHandler(membershipMenu);
     156    private final PopupMenuHandler blankSpaceMenuHandler = new PopupMenuHandler(blankSpaceMenu);
    152157
    153158    private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>();
     
    235240
    236241        // combine both tables and wrap them in a scrollPane
    237         JPanel bothTables = new JPanel();
    238242        boolean top = Main.pref.getBoolean("properties.presets.top", true);
    239243        bothTables.setLayout(new GridBagLayout());
     
    251255            bothTables.add(presets, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 2, 5, 2));
    252256        }
    253 
     257       
     258        setupBlankSpaceMenu();
    254259        setupKeyboardShortcuts();
    255260
    256         // Let the action know when selection in the tables change
     261        // Let the actions know when selection in the tables change
    257262        tagTable.getSelectionModel().addListSelectionListener(editAction);
    258263        membershipTable.getSelectionModel().addListSelectionListener(editAction);
     
    260265        membershipTable.getSelectionModel().addListSelectionListener(deleteAction);
    261266
    262 
    263267        JScrollPane scrollPane = (JScrollPane) createLayout(bothTables, true, Arrays.asList(new SideButton[] {
    264268                this.btnAdd, this.btnEdit, this.btnDel
     
    280284    private void buildTagsTable() {
    281285        // setting up the tags table
    282 
    283286        tagData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
    284287        tagTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     
    353356
    354357    /**
    355      * creates the popup menu @field membershipMenu and its launcher on membership table
     358     * Creates the popup menu @field blankSpaceMenu and its launcher on main panel.
     359     */
     360    private void setupBlankSpaceMenu() {
     361        if (Main.pref.getBoolean("properties.menu.add_edit_delete", true)) {
     362            blankSpaceMenuHandler.addAction(addAction);
     363            PopupMenuLauncher launcher = new PopupMenuLauncher(blankSpaceMenu) {
     364                @Override
     365                protected boolean checkSelection(Component component, Point p) {
     366                    if (component instanceof JTable) {
     367                        return ((JTable) component).rowAtPoint(p) == -1;
     368                    }
     369                    return true;
     370                }
     371            };
     372            bothTables.addMouseListener(launcher);
     373            tagTable.addMouseListener(launcher);
     374        }
     375    }
     376
     377    /**
     378     * Creates the popup menu @field membershipMenu and its launcher on membership table.
    356379     */
    357380    private void setupMembershipMenu() {
    358381        // setting up the membership table
     382        if (Main.pref.getBoolean("properties.menu.add_edit_delete", true)) {
     383            membershipMenuHandler.addAction(editAction);
     384            membershipMenuHandler.addAction(deleteAction);
     385            membershipMenu.addSeparator();
     386        }
    359387        membershipMenuHandler.addAction(setRelationSelectionAction);
    360388        membershipMenuHandler.addAction(selectRelationAction);
     
    402430
    403431    /**
    404      * creates the popup menu @field tagMenu and its launcher on tag table
     432     * Creates the popup menu @field tagMenu and its launcher on tag table.
    405433     */
    406434    private void setupTagsMenu() {
     435        if (Main.pref.getBoolean("properties.menu.add_edit_delete", true)) {
     436            tagMenu.add(addAction);
     437            tagMenu.add(editAction);
     438            tagMenu.add(deleteAction);
     439            tagMenu.addSeparator();
     440        }
    407441        tagMenu.add(pasteValueAction);
    408442        tagMenu.add(copyValueAction);
     
    418452
    419453    /**
    420      * Assignas all needed keys like Enter and Spacebar to most important actions
     454     * Assigns all needed keys like Enter and Spacebar to most important actions.
    421455     */
    422456    private void setupKeyboardShortcuts() {
     
    649683        boolean hasTags = hasSelection && tagData.getRowCount() > 0;
    650684        boolean hasMemberships = hasSelection && membershipData.getRowCount() > 0;
    651         btnAdd.setEnabled(hasSelection);
    652         btnEdit.setEnabled(hasTags || hasMemberships);
    653         btnDel.setEnabled(hasTags || hasMemberships);
     685        addAction.setEnabled(hasSelection);
     686        editAction.setEnabled(hasTags || hasMemberships);
     687        deleteAction.setEnabled(hasTags || hasMemberships);
    654688        tagTable.setVisible(hasTags);
    655689        tagTable.getTableHeader().setVisible(hasTags);
     
    707741    }
    708742
     743    /**
     744     * Returns the selected tag.
     745     * @return The current selected tag
     746     */
    709747    @SuppressWarnings("unchecked")
    710748    public Tag getSelectedProperty() {
     
    725763    }
    726764
     765    /**
     766     * Returns the selected relation membership.
     767     * @return The current selected relation membership
     768     */
    727769    public IRelation getSelectedMembershipRelation() {
    728770        int row = membershipTable.getSelectedRow();
     
    774816            }
    775817        }
    776 
    777818    }
    778819
Note: See TracChangeset for help on using the changeset viewer.