Changeset 2723 in josm for trunk/src


Ignore:
Timestamp:
2010-01-01T14:17:49+01:00 (15 years ago)
Author:
stoecker
Message:

fixed #4229 - Right click menu for properties relation entry

File:
1 edited

Legend:

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

    r2658 r2723  
    1212import java.awt.GridBagLayout;
    1313import java.awt.GridLayout;
     14import java.awt.Point;
    1415import java.awt.event.ActionEvent;
    1516import java.awt.event.ActionListener;
     
    4142import javax.swing.JOptionPane;
    4243import javax.swing.JPanel;
     44import javax.swing.JPopupMenu;
    4345import javax.swing.JScrollPane;
    4446import javax.swing.JTable;
     
    7577import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    7678import org.openstreetmap.josm.gui.widgets.AutoCompleteComboBox;
     79import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    7780import org.openstreetmap.josm.tools.GBC;
    7881import org.openstreetmap.josm.tools.ImageProvider;
     
    472475        membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role")});
    473476        membershipTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     477        membershipTable.addMouseListener(new PopupMenuLauncher() {
     478            @Override
     479            public void launch(MouseEvent evt) {
     480                Point p = evt.getPoint();
     481                int row = membershipTable.rowAtPoint(p);
     482                if (row > -1) {
     483                    JPopupMenu menu = new JPopupMenu();
     484                    Relation relation = (Relation)membershipData.getValueAt(row, 0);
     485                    menu.add(new SelectRelationAction(relation, true));
     486                    menu.add(new SelectRelationAction(relation, false));
     487                    menu.show(membershipTable, p.x, p.y-3);
     488                }
     489            }
     490        });
    474491
    475492        membershipTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
     
    535552        presets.setSize(scrollPane.getSize());
    536553
    537         JPanel buttonPanel = new JPanel(new GridLayout(1,3));
     554        JPanel buttonPanel = getButtonPanel(3);
    538555
    539556        // -- add action and shortcut
     
    904921        }
    905922    }
     923
     924    class SelectRelationAction extends AbstractAction {
     925        boolean selectionmode;
     926        Relation relation;
     927        public SelectRelationAction(Relation r, boolean select) {
     928            selectionmode = select;
     929            relation = r;
     930            if(select) {
     931              putValue(NAME, tr("Select relation"));
     932              putValue(SHORT_DESCRIPTION, tr("Select relation in main selection."));
     933            } else {
     934              putValue(NAME, tr("Select in relation list"));
     935              putValue(SHORT_DESCRIPTION, tr("Select relation in relation list."));
     936            }
     937        }
     938
     939        public void actionPerformed(ActionEvent e) {
     940            if(selectionmode)
     941                Main.map.mapView.getEditLayer().data.setSelected(relation);
     942            else
     943                Main.map.relationListDialog.selectRelation(relation);
     944        }
     945    }
    906946}
Note: See TracChangeset for help on using the changeset viewer.