Changeset 4459 in josm


Ignore:
Timestamp:
2011-09-24T12:19:54+02:00 (10 years ago)
Author:
bastiK
Message:

applied #6856 - Enable plugins to add actions in popup menus (patch by Don-vip)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
3 edited

Legend:

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

    r4369 r4459  
    2121
    2222import javax.swing.AbstractAction;
     23import javax.swing.Action;
    2324import javax.swing.DefaultListSelectionModel;
    2425import javax.swing.JCheckBox;
    2526import javax.swing.JList;
     27import javax.swing.JMenuItem;
    2628import javax.swing.JPanel;
    27 import javax.swing.JPopupMenu;
    2829import javax.swing.JScrollPane;
    2930import javax.swing.ListSelectionModel;
     
    5152import org.openstreetmap.josm.gui.help.HelpUtil;
    5253import org.openstreetmap.josm.gui.io.CloseChangesetTask;
     54import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
    5355import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    5456import org.openstreetmap.josm.tools.BugReportExceptionHandler;
     
    8385    private CloseOpenChangesetsAction closeChangesetAction;
    8486    private LaunchChangesetManagerAction launchChangesetManagerAction;
     87   
     88    private ChangesetDialogPopup popupMenu;
    8589
    8690    protected void buildChangesetsLists() {
     
    188192        selectObjectsAction = new SelectObjectsAction();
    189193        cbInSelectionOnly.addItemListener(selectObjectsAction);
    190         lstInActiveDataLayer.getSelectionModel().addListSelectionListener(selectObjectsAction);
    191         lstInSelection.getSelectionModel().addListSelectionListener(selectObjectsAction);
    192194
    193195        // -- read changesets action
    194196        readChangesetAction = new ReadChangesetsAction();
    195197        cbInSelectionOnly.addItemListener(readChangesetAction);
    196         lstInActiveDataLayer.getSelectionModel().addListSelectionListener(readChangesetAction);
    197         lstInSelection.getSelectionModel().addListSelectionListener(readChangesetAction);
    198198
    199199        // -- close changesets action
    200200        closeChangesetAction = new CloseOpenChangesetsAction();
    201201        cbInSelectionOnly.addItemListener(closeChangesetAction);
    202         lstInActiveDataLayer.getSelectionModel().addListSelectionListener(closeChangesetAction);
    203         lstInSelection.getSelectionModel().addListSelectionListener(closeChangesetAction);
    204202
    205203        // -- show info action
    206204        showChangesetInfoAction = new ShowChangesetInfoAction();
    207205        cbInSelectionOnly.addItemListener(showChangesetInfoAction);
    208         lstInActiveDataLayer.getSelectionModel().addListSelectionListener(showChangesetInfoAction);
    209         lstInSelection.getSelectionModel().addListSelectionListener(showChangesetInfoAction);
    210206
    211207        // -- launch changeset manager action
    212208        launchChangesetManagerAction = new LaunchChangesetManagerAction();
    213209        cbInSelectionOnly.addItemListener(launchChangesetManagerAction);
    214         lstInActiveDataLayer.getSelectionModel().addListSelectionListener(launchChangesetManagerAction);
    215         lstInSelection.getSelectionModel().addListSelectionListener(launchChangesetManagerAction);
     210       
     211        popupMenu = new ChangesetDialogPopup(lstInActiveDataLayer, lstInSelection);
    216212
    217213        createLayout(pnl, false, Arrays.asList(new SideButton[] {
     
    536532                }
    537533            }
    538             ChangesetDialogPopup popup = new ChangesetDialogPopup();
    539             popup.show(lst, evt.getX(), evt.getY());
    540 
    541         }
    542     }
    543 
    544     class ChangesetDialogPopup extends JPopupMenu {
    545         public ChangesetDialogPopup() {
     534            popupMenu.show(lst, evt.getX(), evt.getY());
     535        }
     536    }
     537
     538    class ChangesetDialogPopup extends ListPopupMenu {
     539        public ChangesetDialogPopup(JList ... lists) {
     540            super(lists);
    546541            add(selectObjectsAction);
    547542            addSeparator();
     
    552547        }
    553548    }
     549
     550    public void addPopupMenuSeparator() {
     551        popupMenu.addSeparator();
     552    }
     553
     554    public JMenuItem addPopupMenuAction(Action a) {
     555        return popupMenu.add(a);
     556    }
    554557}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r4353 r4459  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
    7 import java.awt.BorderLayout;
    87import java.awt.Point;
    98import java.awt.event.ActionEvent;
     
    2221import javax.swing.AbstractAction;
    2322import javax.swing.AbstractListModel;
     23import javax.swing.Action;
    2424import javax.swing.DefaultListSelectionModel;
    2525import javax.swing.JList;
    26 import javax.swing.JPopupMenu;
     26import javax.swing.JMenuItem;
    2727import javax.swing.KeyStroke;
    2828import javax.swing.ListSelectionModel;
     
    5656import org.openstreetmap.josm.gui.layer.Layer;
    5757import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     58import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
    5859import org.openstreetmap.josm.tools.ImageProvider;
    5960import org.openstreetmap.josm.tools.Shortcut;
     
    142143        displaylist.getActionMap().put("deleteRelation", deleteAction);
    143144
    144         popupMenu = new RelationDialogPopupMenu();
     145        popupMenu = new RelationDialogPopupMenu(displaylist);
    145146    }
    146147
     
    777778    }
    778779
    779     class RelationDialogPopupMenu extends JPopupMenu {
    780         protected void build() {
     780    class RelationDialogPopupMenu extends ListPopupMenu {
     781
     782        public RelationDialogPopupMenu(JList list) {
     783            super(list);
     784           
    781785            // -- download members action
    782786            //
    783             DownloadMembersAction downloadMembersAction = new DownloadMembersAction();
    784             displaylist.addListSelectionListener(downloadMembersAction);
    785             add(downloadMembersAction);
     787            add(new DownloadMembersAction());
    786788
    787789            // -- download incomplete members action
    788790            //
    789             DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction();
    790             displaylist.addListSelectionListener(downloadSelectedIncompleteMembers);
    791             add(downloadSelectedIncompleteMembers);
     791            add(new DownloadSelectedIncompleteMembersAction());
    792792
    793793            addSeparator();
     
    795795            // -- select members action
    796796            //
    797             SelectMembersAction selectMembersAction = new SelectMembersAction(false);
    798             displaylist.addListSelectionListener(selectMembersAction);
    799             add(selectMembersAction);
    800 
    801             selectMembersAction = new SelectMembersAction(true);
    802             displaylist.addListSelectionListener(selectMembersAction);
    803             add(selectMembersAction);
     797            add(new SelectMembersAction(false));
     798            add(new SelectMembersAction(true));
    804799
    805800            // -- select action
    806801            //
    807             SelectAction selectAction = new SelectAction(false);
    808             displaylist.addListSelectionListener(selectAction);
    809             add(selectAction);
    810 
    811             selectAction = new SelectAction(true);
    812             displaylist.addListSelectionListener(selectAction);
    813             add(selectAction);
    814         }
    815 
    816         public RelationDialogPopupMenu() {
    817             build();
    818         }
     802            add(new SelectAction(false));
     803            add(new SelectAction(true));
     804        }
     805    }
     806
     807    public void addPopupMenuSeparator() {
     808        popupMenu.addSeparator();
     809    }
     810
     811    public JMenuItem addPopupMenuAction(Action a) {
     812        return popupMenu.add(a);
    819813    }
    820814
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r4408 r4459  
    2424import javax.swing.AbstractAction;
    2525import javax.swing.AbstractListModel;
     26import javax.swing.Action;
    2627import javax.swing.DefaultListSelectionModel;
    2728import javax.swing.JList;
     
    6768import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    6869import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     70import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
    6971import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    7072import org.openstreetmap.josm.tools.ImageProvider;
     
    8688    private EditRelationSelection actEditRelationSelection;
    8789    private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers;
     90
     91    private SelectionPopup popupMenu;
    8892
    8993    /**
     
    134138
    135139        actZoomToListSelection = new ZoomToListSelection();
    136         lstPrimitives.getSelectionModel().addListSelectionListener(actZoomToListSelection);
    137 
    138140        actSetRelationSelection = new SetRelationSelection();
    139         lstPrimitives.getSelectionModel().addListSelectionListener(actSetRelationSelection);
    140 
    141141        actEditRelationSelection = new EditRelationSelection();
    142         lstPrimitives.getSelectionModel().addListSelectionListener(actEditRelationSelection);
    143 
    144142        actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction();
    145         lstPrimitives.getSelectionModel().addListSelectionListener(actDownloadSelectedIncompleteMembers);
    146143
    147144        lstPrimitives.addMouseListener(new SelectionPopupMenuLauncher());
    148145        lstPrimitives.addMouseListener(new DblClickHandler());
     146       
     147        popupMenu = new SelectionPopup(lstPrimitives);
    149148    }
    150149
     
    190189     */
    191190    class SelectionPopupMenuLauncher extends PopupMenuLauncher {
    192         private SelectionPopup popup = new SelectionPopup();
    193191
    194192        @Override
     
    199197                model.setSelected(Collections.singleton((OsmPrimitive)model.getElementAt(idx)));
    200198            }
    201             popup.show(lstPrimitives, evt.getX(), evt.getY());
     199            popupMenu.show(lstPrimitives, evt.getX(), evt.getY());
    202200        }
    203201    }
     
    206204     * The popup menu for the selection list
    207205     */
    208     class SelectionPopup extends JPopupMenu {
    209         public SelectionPopup() {
     206    class SelectionPopup extends ListPopupMenu {
     207        public SelectionPopup(JList list) {
     208            super(list);
    210209            add(actZoomToJOSMSelection);
    211210            add(actZoomToListSelection);
     
    216215            add(actDownloadSelectedIncompleteMembers);
    217216        }
     217    }
     218
     219    public void addPopupMenuSeparator() {
     220        popupMenu.addSeparator();
     221    }
     222
     223    public JMenuItem addPopupMenuAction(Action a) {
     224        return popupMenu.add(a);
    218225    }
    219226
Note: See TracChangeset for help on using the changeset viewer.