Changeset 4484 in josm for trunk


Ignore:
Timestamp:
2011-10-02T22:14:54+02:00 (13 years ago)
Author:
Don-vip
Message:

see #6856 - Enable plugins to add actions in popup menus (PropertiesDialog)

File:
1 edited

Legend:

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

    r4454 r4484  
    4040
    4141import javax.swing.AbstractAction;
     42import javax.swing.Action;
    4243import javax.swing.Box;
    4344import javax.swing.DefaultListCellRenderer;
     
    4748import javax.swing.JLabel;
    4849import javax.swing.JList;
     50import javax.swing.JMenuItem;
    4951import javax.swing.JOptionPane;
    5052import javax.swing.JPanel;
     
    163165    // button in the upper right corner of this dialog
    164166    public static JPanel pluginHook = new JPanel();
     167   
     168    private JPopupMenu propertyMenu;
     169    private JPopupMenu membershipMenu;
    165170
    166171    private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>();
     
    610615
    611616        // setting up the properties table
     617        propertyMenu = new JPopupMenu();
     618        propertyMenu.add(copyValueAction);
     619        propertyMenu.add(copyKeyValueAction);
     620        propertyMenu.add(copyAllKeyValueAction);
     621        propertyMenu.addSeparator();
     622        propertyMenu.add(helpAction);
     623       
    612624        propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
    613625        propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     
    620632                if (row > -1) {
    621633                    propertyTable.changeSelection(row, 0, false, false);
    622                     JPopupMenu menu = new JPopupMenu();
    623                     menu.add(copyValueAction);
    624                     menu.add(copyKeyValueAction);
    625                     menu.add(copyAllKeyValueAction);
    626                     menu.addSeparator();
    627                     menu.add(helpAction);
    628                     menu.show(propertyTable, p.x, p.y-3);
     634                    propertyMenu.show(propertyTable, p.x, p.y-3);
    629635                }
    630636            }
     
    658664
    659665        // setting up the membership table
     666        membershipMenu = new JPopupMenu();
     667        membershipMenu.add(new SelectRelationAction(true));
     668        membershipMenu.add(new SelectRelationAction(false));
     669        membershipMenu.add(new SelectRelationMembersAction());
     670        membershipMenu.add(new DownloadIncompleteMembersAction());
     671        membershipMenu.addSeparator();
     672        membershipMenu.add(helpAction);
    660673
    661674        membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role"),tr("Position")});
     
    668681                if (row > -1) {
    669682                    membershipTable.changeSelection(row, 0, false, false);
    670                     JPopupMenu menu = new JPopupMenu();
    671683                    Relation relation = (Relation)membershipData.getValueAt(row, 0);
    672                     menu.add(new SelectRelationAction(relation, true));
    673                     menu.add(new SelectRelationAction(relation, false));
    674                     menu.add(new SelectRelationMembersAction(relation));
    675                     menu.add(new DownloadIncompleteMembersAction(relation));
    676                     menu.addSeparator();
    677                     menu.add(helpAction);
    678                     menu.show(membershipTable, p.x, p.y-3);
     684                    for (Component c : membershipMenu.getComponents()) {
     685                        if (c instanceof JMenuItem) {
     686                            Action action = ((JMenuItem) c).getAction();
     687                            if (action instanceof RelationRelated) {
     688                                ((RelationRelated)action).setRelation(relation);
     689                            }
     690                        }
     691                    }
     692                    membershipMenu.show(membershipTable, p.x, p.y-3);
    679693                }
    680694            }
     
    12231237    }
    12241238
    1225     static class SelectRelationAction extends AbstractAction {
     1239    public void addPropertyPopupMenuSeparator() {
     1240        propertyMenu.addSeparator();
     1241    }
     1242
     1243    public JMenuItem addPropertyPopupMenuAction(Action a) {
     1244        return propertyMenu.add(a);
     1245    }
     1246   
     1247    public void addMembershipPopupMenuSeparator() {
     1248        membershipMenu.addSeparator();
     1249    }
     1250
     1251    public JMenuItem addMembershipPopupMenuAction(Action a) {
     1252        return membershipMenu.add(a);
     1253    }
     1254   
     1255    public static interface RelationRelated {
     1256        public Relation getRelation();
     1257        public void setRelation(Relation relation);
     1258    }
     1259   
     1260    static abstract class AbstractRelationAction extends AbstractAction implements RelationRelated {
     1261        protected Relation relation;
     1262        public Relation getRelation() {
     1263            return this.relation;
     1264        }
     1265        public void setRelation(Relation relation) {
     1266            this.relation = relation;
     1267        }
     1268    }
     1269   
     1270    static class SelectRelationAction extends AbstractRelationAction {
    12261271        boolean selectionmode;
    1227         Relation relation;
    1228         public SelectRelationAction(Relation r, boolean select) {
     1272        public SelectRelationAction(boolean select) {
    12291273            selectionmode = select;
    1230             relation = r;
    12311274            if(select) {
    12321275                putValue(NAME, tr("Select relation"));
     
    12551298     *
    12561299     */
    1257     class SelectRelationMembersAction extends AbstractAction {
    1258         Relation relation;
    1259         public SelectRelationMembersAction(Relation r) {
    1260             relation = r;
     1300    class SelectRelationMembersAction extends AbstractRelationAction {
     1301        public SelectRelationMembersAction() {
    12611302            putValue(SHORT_DESCRIPTION,tr("Select the members of selected relation"));
    12621303            putValue(SMALL_ICON, ImageProvider.get("selectall"));
     
    12761317     *
    12771318     */
    1278     class DownloadIncompleteMembersAction extends AbstractAction {
    1279         Relation relation;
    1280         public DownloadIncompleteMembersAction(Relation r) {
    1281             relation = r;
     1319    class DownloadIncompleteMembersAction extends AbstractRelationAction {
     1320        public DownloadIncompleteMembersAction() {
    12821321            putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));
    12831322            putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));
Note: See TracChangeset for help on using the changeset viewer.