Changeset 5965 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2013-05-17T20:45:17+02:00 (11 years ago)
Author:
akks
Message:

see #8652 (patch by cmuelle8, part 1, modified): add "toggle panels" action (soon will be on Tab)
rework all toolbar context menus (add "do not hide" item and remove PopupMenuLauncher usage)
fixing minor warnings (@Override, private final)

Location:
trunk/src/org/openstreetmap/josm
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r5886 r5965  
    2626import org.openstreetmap.josm.gui.widgets.JosmTextField;
    2727
    28 public class JumpToAction extends JosmAction implements MouseListener {
     28public class JumpToAction extends JosmAction {
    2929    /**
    3030     * Constructs a new {@code JumpToAction}.
     
    6767
    6868        class osmURLListener implements DocumentListener {
    69             public void changedUpdate(DocumentEvent e) { parseURL(); }
    70             public void insertUpdate(DocumentEvent e) { parseURL(); }
    71             public void removeUpdate(DocumentEvent e) { parseURL(); }
     69            @Override public void changedUpdate(DocumentEvent e) { parseURL(); }
     70            @Override public void insertUpdate(DocumentEvent e) { parseURL(); }
     71            @Override public void removeUpdate(DocumentEvent e) { parseURL(); }
    7272        }
    7373
    7474        class osmLonLatListener implements DocumentListener {
    75             public void changedUpdate(DocumentEvent e) { updateUrl(false); }
    76             public void insertUpdate(DocumentEvent e) { updateUrl(false); }
    77             public void removeUpdate(DocumentEvent e) { updateUrl(false); }
     75            @Override public void changedUpdate(DocumentEvent e) { updateUrl(false); }
     76            @Override public void insertUpdate(DocumentEvent e) { updateUrl(false); }
     77            @Override public void removeUpdate(DocumentEvent e) { updateUrl(false); }
    7878        }
    7979
     
    172172        showJumpToDialog();
    173173    }
    174 
    175     public void mousePressed(MouseEvent e) {}
    176 
    177     public void mouseReleased(MouseEvent e) {}
    178 
    179     public void mouseEntered(MouseEvent e) {}
    180 
    181     public void mouseExited(MouseEvent e) {}
    182 
    183     public void mouseClicked(MouseEvent e) {
    184         showJumpToDialog();
    185     }
    186174}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r5922 r5965  
    17241724                add(repeatedCb);
    17251725                add(helperCb);
    1726                 add(projectionCb);;
     1726                add(projectionCb);
    17271727                add(new AbstractAction(tr("Disable")) {
    17281728                    @Override public void actionPerformed(ActionEvent e) {
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r5958 r5965  
    3636import org.openstreetmap.josm.actions.CreateMultipolygonAction;
    3737import org.openstreetmap.josm.actions.DeleteAction;
     38import org.openstreetmap.josm.actions.DialogsToggleAction;
    3839import org.openstreetmap.josm.actions.DistributeAction;
    3940import org.openstreetmap.josm.actions.DownloadAction;
     
    6566import org.openstreetmap.josm.actions.OpenLocationAction;
    6667import org.openstreetmap.josm.actions.OrthogonalizeAction;
     68import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
    6769import org.openstreetmap.josm.actions.PasteAction;
    6870import org.openstreetmap.josm.actions.PasteTagsAction;
     71import org.openstreetmap.josm.actions.PreferenceToggleAction;
    6972import org.openstreetmap.josm.actions.PreferencesAction;
    7073import org.openstreetmap.josm.actions.PurgeAction;
     
    9396import org.openstreetmap.josm.actions.ZoomInAction;
    9497import org.openstreetmap.josm.actions.ZoomOutAction;
    95 import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
    96 import org.openstreetmap.josm.actions.PreferenceToggleAction;
    9798import org.openstreetmap.josm.actions.audio.AudioBackAction;
    9899import org.openstreetmap.josm.actions.audio.AudioFasterAction;
     
    233234
    234235    public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
     236    public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction();
    235237    public FullscreenToggleAction fullscreenToggleAction = null;
    236238
     
    519521            fullscreenToggleAction.addButtonModel(fullscreen.getModel());
    520522        }
     523
     524        // -- dialogs panel toggle action
     525        final JCheckBoxMenuItem dialogsToggle = new JCheckBoxMenuItem(dialogsToggleAction);
     526        dialogsToggle.setAccelerator(dialogsToggleAction.getShortcut().getKeyStroke());
     527        dialogsToggleAction.addButtonModel(dialogsToggle.getModel());
     528        viewMenu.add(dialogsToggle);
     529
    521530        viewMenu.addSeparator();
    522531        add(viewMenu, info);
     
    627636        }
    628637
     638        @Override
    629639        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    630640            refreshEnabled();
    631641        }
    632642
     643        @Override
    633644        public void layerAdded(Layer newLayer) {
    634645            refreshEnabled();
    635646        }
    636647
     648        @Override
    637649        public void layerRemoved(Layer oldLayer) {
    638650            refreshEnabled();
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r5909 r5965  
    1010import java.awt.Font;
    1111import java.awt.GridBagLayout;
     12import java.awt.KeyboardFocusManager;
    1213import java.awt.Rectangle;
    1314import java.awt.event.ActionEvent;
     
    1819import java.util.Collection;
    1920import java.util.HashMap;
     21import java.util.HashSet;
    2022import java.util.List;
    2123import java.util.Map;
     
    3739import javax.swing.SwingUtilities;
    3840import javax.swing.border.Border;
     41import javax.swing.event.PopupMenuEvent;
     42import javax.swing.event.PopupMenuListener;
    3943import javax.swing.plaf.basic.BasicSplitPaneDivider;
    4044import javax.swing.plaf.basic.BasicSplitPaneUI;
     
    7074import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
    7175import org.openstreetmap.josm.gui.layer.Layer;
    72 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    7376import org.openstreetmap.josm.tools.Destroyable;
    7477import org.openstreetmap.josm.tools.GBC;
     78
    7579
    7680/**
     
    8791    public MapMode mapMode;
    8892
     93    /**
     94     * The view control displayed.
     95     */
     96    public final MapView mapView;
     97
     98    /**
     99     * The toolbar with the action icons. To add new toggle dialog buttons,
     100     * use addToggleDialog, to add a new map mode button use addMapMode.
     101     */
     102    private JComponent sideToolBar = new JToolBar(JToolBar.VERTICAL);
     103    private final ButtonGroup toolBarActionsGroup = new ButtonGroup();
     104    private final JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
     105    private final JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL);
     106
     107    private final List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
    89108    private final List<MapMode> mapModes = new ArrayList<MapMode>();
    90     /**
    91      * The view control displayed.
    92      */
    93     public final MapView mapView;
    94     /**
    95      * The toolbar with the action icons. To add new toggle dialog actions, use addToggleDialog
    96      * instead of adding directly to this list. To add a new mode use addMapMode.
    97      */
    98     private JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL);
    99     private JToolBar toolBarToggle = new JToolBar(JToolBar.VERTICAL);
    100     /**
    101      * The status line below the map
    102      */
    103     public MapStatus statusLine;
     109    private final List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>();
     110    public final List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>();
     111
     112    private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons);
     113    private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons);
     114    private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction);
     115    private final JButton listAllMapModesButton = new JButton(listAllMapModesAction);
     116    {
     117        listAllDialogsAction.setButton(listAllToggleDialogsButton);
     118        listAllMapModesAction.setButton(listAllMapModesButton);
     119    }
    104120
    105121    // Toggle dialogs
     
    113129    // Map modes
    114130    public final SelectAction mapModeSelect;
     131    private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>();
    115132    private final MapMode mapModeDraw;
    116133    private final MapMode mapModeZoom;
    117134
    118135    /**
    119      * The panel list of all toggle dialog icons. To add new toggle dialog actions, use addToggleDialog
    120      * instead of adding directly to this list.
    121      */
    122     private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();
     136     * The status line below the map
     137     */
     138    public MapStatus statusLine;
     139
     140    /**
     141     * The split pane with the mapview (leftPanel) and toggle dialogs (dialogsPanel).
     142     */
     143    private final JSplitPane splitPane;
    123144    private final JPanel leftPanel;
    124145    private final DialogsPanel dialogsPanel;
    125146
    126     public final ButtonGroup toolGroup = new ButtonGroup();
    127 
    128     private List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>();
    129     private List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>();
    130 
    131     private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons);
    132     private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons);
    133     private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction);
    134     private final JButton listAllMapModesButton = new JButton(listAllMapModesAction);
    135     {
    136         listAllDialogsAction.setButton(listAllToggleDialogsButton);
    137         listAllMapModesAction.setButton(listAllMapModesButton);
    138     }
    139 
    140147    /**
    141148     * Default width of the toggle dialog area.
    142149     */
    143150    public static final int DEF_TOGGLE_DLG_WIDTH = 330;
    144 
    145     private final Map<Layer, MapMode> lastMapMode = new HashMap<Layer, MapMode>();
    146151
    147152    /**
     
    157162
    158163        mapView = new MapView(contentPane, viewportData);
    159 
    160164        new FileDrop(mapView);
     165
     166        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
    161167
    162168        leftPanel = new JPanel();
    163169        leftPanel.setLayout(new GridBagLayout());
    164 
    165170        leftPanel.add(mapView, GBC.std().fill());
    166 
    167         // toolbar
    168         toolBarActions.setFloatable(false);
    169         addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this)));
    170         addMapMode(new IconToggleButton(new LassoModeAction(), true));
    171         addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this)));
    172         addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this)));
    173         addMapMode(new IconToggleButton(new DeleteAction(this), true));
    174         addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
    175         addMapMode(new IconToggleButton(new ExtrudeAction(this), true));
    176         addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true));
    177 
    178         toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
    179 
    180         JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
     171        splitPane.setLeftComponent(leftPanel);
     172
    181173        dialogsPanel = new DialogsPanel(splitPane);
    182         splitPane.setLeftComponent(leftPanel);
    183174        splitPane.setRightComponent(dialogsPanel);
    184175
     
    212203        dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS));
    213204        dialogsPanel.setPreferredSize(new Dimension(Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH), 0));
    214 
    215205        dialogsPanel.setMinimumSize(new Dimension(24, 0));
    216206        mapView.setMinimumSize(new Dimension(10,0));
    217207
    218         toolBarToggle.setFloatable(false);
     208        // toolBarActions, map mode buttons
     209        addMapMode(new IconToggleButton(mapModeSelect = new SelectAction(this)));
     210        addMapMode(new IconToggleButton(new LassoModeAction(), true));
     211        addMapMode(new IconToggleButton(mapModeDraw = new DrawAction(this)));
     212        addMapMode(new IconToggleButton(mapModeZoom = new ZoomAction(this)));
     213        addMapMode(new IconToggleButton(new DeleteAction(this), true));
     214        addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
     215        addMapMode(new IconToggleButton(new ExtrudeAction(this), true));
     216        addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true));
     217        toolBarActionsGroup.setSelected(allMapModeButtons.get(0).getModel(), true);
     218        toolBarActions.setFloatable(false);
     219
     220        // toolBarToggles, toggle dialog buttons
    219221        LayerListDialog.createInstance(this);
    220222        addToggleDialog(LayerListDialog.getInstance());
     
    230232        addToggleDialog(new ChangesetDialog(this), true);
    231233        addToggleDialog(new MapPaintDialog());
     234        toolBarToggle.setFloatable(false);
    232235
    233236        // status line below the map
     
    261264     * Delegates the call to all Destroyables within this component (e.g. MapModes)
    262265     */
     266    @Override
    263267    public void destroy() {
    264268        MapView.removeLayerChangeListener(this);
     
    310314        final IconToggleButton button = new IconToggleButton(dlg.getToggleAction(), isExpert);
    311315        button.setShowHideButtonListener(dlg);
    312         addHideContextMenu(button);
     316        button.setInheritsPopupMenu(true);
    313317        dlg.setButton(button);
    314318        toolBarToggle.add(button);
     
    325329
    326330    public void addMapMode(IconToggleButton b) {
    327         toolBarActions.add(b);
    328         toolGroup.add(b);
    329         allMapModeButtons.add(b);
    330331        if (b.getAction() instanceof MapMode) {
    331332            mapModes.add((MapMode) b.getAction());
    332333        } else
    333334            throw new IllegalArgumentException("MapMode action must be subclass of MapMode");
    334         addHideContextMenu(b);
     335        allMapModeButtons.add(b);
     336        toolBarActionsGroup.add(b);
     337        toolBarActions.add(b);
    335338        b.applyButtonHiddenPreferences();
     339        b.setInheritsPopupMenu(true);
    336340    }
    337341
     
    392396    public void fillPanel(Container panel) {
    393397        panel.add(this, BorderLayout.CENTER);
    394         JToolBar jb = new JToolBar(JToolBar.VERTICAL);
    395         jb.setFloatable(false);
     398
     399        /**
     400         * sideToolBar: add map modes icons
     401         */
     402        if(Main.pref.getBoolean("sidetoolbar.mapmodes.visible", true)) {
    396403        toolBarActions.setAlignmentX(0.5f);
    397         jb.add(toolBarActions);
     404            toolBarActions.setInheritsPopupMenu(true);
     405            sideToolBar.add(toolBarActions);
    398406        listAllMapModesButton.setAlignmentX(0.5f);
    399407        listAllMapModesButton.setBorder(null);
    400408        listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN));
    401         jb.add(listAllMapModesButton);
    402 
    403         if(Main.pref.getBoolean("sidetoolbar.togglevisible", true)) {
    404             jb.addSeparator(new Dimension(0,18));
     409            listAllMapModesButton.setInheritsPopupMenu(true);
     410            sideToolBar.add(listAllMapModesButton);
     411        }
     412
     413        /**
     414         * sideToolBar: add toggle dialogs icons
     415         */
     416        if(Main.pref.getBoolean("sidetoolbar.toggledialogs.visible", true)) {
     417            ((JToolBar)sideToolBar).addSeparator(new Dimension(0,18));
    405418            toolBarToggle.setAlignmentX(0.5f);
    406             jb.add(toolBarToggle);
     419            toolBarToggle.setInheritsPopupMenu(true);
     420            sideToolBar.add(toolBarToggle);
    407421            listAllToggleDialogsButton.setAlignmentX(0.5f);
    408422            listAllToggleDialogsButton.setBorder(null);
    409423            listAllToggleDialogsButton.setFont(listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN));
    410             jb.add(listAllToggleDialogsButton);
    411         }
    412 
    413         final Component toToggle;
    414         if (Main.pref.getBoolean("sidetoolbar.scrollable", true)) {
    415             final ScrollViewport svp = new ScrollViewport(jb, ScrollViewport.VERTICAL_DIRECTION);
    416             toToggle = svp;
    417             panel.add(svp, BorderLayout.WEST);
    418             jb.addMouseWheelListener(new MouseWheelListener() {
    419 
    420                 public void mouseWheelMoved(MouseWheelEvent e) {
    421                     svp.scroll(0, e.getUnitsToScroll() * 5);
     424            listAllToggleDialogsButton.setInheritsPopupMenu(true);
     425            sideToolBar.add(listAllToggleDialogsButton);
     426        }
     427
     428        /**
     429         * sideToolBar: add dynamic popup menu
     430         */
     431        sideToolBar.setComponentPopupMenu(new JPopupMenu() {
     432            final int staticMenuEntryCount = 2;
     433            JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide toolbar")) {
     434                @Override
     435                public void actionPerformed(ActionEvent e) {
     436                    boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState();
     437                    Main.pref.put("sidetoolbar.always-visible", sel);
    422438                }
    423439            });
    424         } else {
    425             toToggle = jb;
    426             panel.add(jb, BorderLayout.WEST);
    427         }
    428         toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true));
    429 
    430         jb.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {
    431 
    432440            {
     441                addPopupMenuListener(new PopupMenuListener() {
     442                    @Override
     443                    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
     444                        final Object src = ((JPopupMenu)e.getSource()).getInvoker();
     445                        if (src instanceof IconToggleButton) {
     446                            insert(new Separator(), 0);
     447                            insert(new AbstractAction() {
     448                                {
     449                                    putValue(NAME, tr("Hide this button"));
     450                                    putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again."));
     451        }
     452                                @Override
     453                                public void actionPerformed(ActionEvent e) {
     454                                    ((IconToggleButton)src).setButtonHidden(true);
     455                                    validateToolBarsVisibility();
     456                                }
     457                            }, 0);
     458                        }
     459                        doNotHide.setSelected(Main.pref.getBoolean("sidetoolbar.always-visible", true));
     460                    }
     461                    @Override
     462                    public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
     463                        while (getComponentCount() > staticMenuEntryCount) {
     464                            remove(0);
     465                        }
     466                    }
     467                    @Override
     468                    public void popupMenuCanceled(PopupMenuEvent e) {}
     469                });
     470
    433471                add(new AbstractAction(tr("Hide edit toolbar")) {
    434 
    435472                    @Override
    436473                    public void actionPerformed(ActionEvent e) {
     
    438475                    }
    439476                });
    440             }
    441         }));
    442 
     477                add(doNotHide);
     478            }
     479        });
     480        ((JToolBar)sideToolBar).setFloatable(false);
     481
     482        /**
     483         * sideToolBar: decide scroll- and visibility
     484         */
     485        if(Main.pref.getBoolean("sidetoolbar.scrollable", true)) {
     486            final ScrollViewport svp = new ScrollViewport(sideToolBar, ScrollViewport.VERTICAL_DIRECTION);
     487            svp.addMouseWheelListener(new MouseWheelListener() {
     488                @Override
     489                public void mouseWheelMoved(MouseWheelEvent e) {
     490                    svp.scroll(0, e.getUnitsToScroll() * 5);
     491                }
     492            });
     493            sideToolBar = svp;
     494        }
     495        sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible", true));
    443496        sidetoolbarPreferencesChangedListener = new Preferences.PreferenceChangedListener() {
    444 
    445497            @Override
    446498            public void preferenceChanged(PreferenceChangeEvent e) {
    447499                if ("sidetoolbar.visible".equals(e.getKey())) {
    448                     toToggle.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));
     500                    sideToolBar.setVisible(Main.pref.getBoolean("sidetoolbar.visible"));
    449501                }
    450502            }
     
    452504        Main.pref.addPreferenceChangeListener(sidetoolbarPreferencesChangedListener);
    453505
     506        /**
     507         * sideToolBar: add it to the panel
     508         */
     509        panel.add(sideToolBar, BorderLayout.WEST);
     510
     511        /**
     512         * statusLine: add to panel
     513         */
    454514        if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) {
    455515            panel.add(statusLine, BorderLayout.SOUTH);
    456516        }
    457     }
    458 
    459     private void addHideContextMenu(final IconToggleButton b) {
    460         //context menu
    461         b.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {
    462             {
    463                 add(new AbstractAction() {
    464                     {
    465                         putValue(NAME, tr("Hide this button"));
    466                         putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again."));
    467                     }
    468                     @Override
    469                     public void actionPerformed(ActionEvent e) {
    470                         b.setButtonHidden(true);
    471                         validateToolBarsVisibility();
    472                     }
    473                 });
    474             }
    475         }));
    476517    }
    477518
     
    544585    }
    545586
     587    public void setDialogsPanelVisible(boolean visible) {
     588        rememberToggleDialogWidth();
     589        dialogsPanel.setVisible(visible);
     590        splitPane.setDividerLocation(visible?splitPane.getWidth()-Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH):0);
     591        splitPane.setDividerSize(visible?5:0);
     592    }
     593
    546594    /**
    547595     * Remember the current width of the (possibly resized) toggle dialog area
    548596     */
    549597    public void rememberToggleDialogWidth() {
    550         Main.pref.putInteger("toggleDialogs.width", dialogsPanel.getWidth());
     598        if (dialogsPanel.isVisible()) {
     599            Main.pref.putInteger("toggleDialogs.width", splitPane.getWidth()-splitPane.getDividerLocation());
     600    }
    551601    }
    552602
    553603    /*
    554      * Remove panel from top of MapView by class
    555      */
     604     * Remove panel from top of MapView by class     */
    556605    public void removeTopPanel(Class<?> type) {
    557606        int n = leftPanel.getComponentCount();
     
    653702        // and possibly need to be hidden/shown.
    654703        SwingUtilities.invokeLater(new Runnable() {
    655             public void run() {
     704            @Override public void run() {
    656705                validateToolBarsVisibility();
    657706            }
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r5909 r5965  
    66
    77import java.awt.AWTEvent;
    8 import java.awt.Color;
    98import java.awt.Component;
    109import java.awt.Cursor;
     
    1716import java.awt.Toolkit;
    1817import java.awt.event.AWTEventListener;
     18import java.awt.event.ActionEvent;
    1919import java.awt.event.InputEvent;
    2020import java.awt.event.KeyAdapter;
     
    2929import java.util.List;
    3030
     31import javax.swing.AbstractAction;
    3132import javax.swing.BorderFactory;
     33import javax.swing.JButton;
     34import javax.swing.JCheckBoxMenuItem;
    3235import javax.swing.JLabel;
     36import javax.swing.JMenuItem;
    3337import javax.swing.JPanel;
     38import javax.swing.JPopupMenu;
    3439import javax.swing.JProgressBar;
    3540import javax.swing.JScrollPane;
     
    3742import javax.swing.PopupFactory;
    3843import javax.swing.UIManager;
     44import javax.swing.event.PopupMenuEvent;
     45import javax.swing.event.PopupMenuListener;
    3946
    4047import org.openstreetmap.josm.Main;
     
    4754import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog;
    4855import org.openstreetmap.josm.gui.util.GuiHelper;
     56import org.openstreetmap.josm.gui.widgets.ImageLabel;
     57import org.openstreetmap.josm.gui.widgets.JosmTextField;
    4958import org.openstreetmap.josm.tools.GBC;
    5059import org.openstreetmap.josm.tools.ImageProvider;
    51 import org.openstreetmap.josm.gui.widgets.JosmTextField;
    5260
    5361/**
     
    7280    final Collector collector;
    7381
    74     /**
    75      * A small user interface component that consists of an image label and
    76      * a fixed text content to the right of the image.
    77      */
    78     static class ImageLabel extends JPanel {
    79         static Color backColor = Color.decode("#b8cfe5");
    80         static Color backColorActive = Color.decode("#aaff5e");
    81            
    82         private JLabel tf;
    83         private int chars;
    84         public ImageLabel(String img, String tooltip, int chars) {
    85             super();
    86             setLayout(new GridBagLayout());
    87             setBackground(backColor);
    88             add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));
    89             add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));
    90             setToolTipText(tooltip);
    91             this.chars = chars;
    92         }
    93         public void setText(String t) {
    94             tf.setText(t);
    95         }
    96         @Override public Dimension getPreferredSize() {
    97             return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);
    98         }
    99         @Override public Dimension getMinimumSize() {
    100             return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
    101         }
    102     }
    103 
    10482    public class BackgroundProgressMonitor implements ProgressMonitorDialog {
    10583
     
    11593        }
    11694
     95        @Override
    11796        public void setVisible(boolean visible) {
    11897            progressBar.setVisible(visible);
    11998        }
    12099
     100        @Override
    121101        public void updateProgress(int progress) {
    122102            progressBar.setValue(progress);
     
    125105        }
    126106
     107        @Override
    127108        public void setCustomText(String text) {
    128109            this.customText = text;
     
    130111        }
    131112
     113        @Override
    132114        public void setCurrentAction(String text) {
    133115            this.title = text;
     
    135117        }
    136118
     119        @Override
    137120        public void setIndeterminate(boolean newValue) {
    138121            UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100);
     
    218201         * Execution function for the Collector.
    219202         */
     203        @Override
    220204        public void run() {
    221205            registerListeners();
     
    281265                                    // Set the text label in the bottom status bar
    282266                                    // "if mouse moved only" was added to stop heap growing
    283                                     if (!mouseNotMoved) statusBarElementUpdate(ms);
     267                                    if (!mouseNotMoved) {
     268                                        statusBarElementUpdate(ms);
     269                                    }
    284270
    285271
     
    363349         * @return popup
    364350         */
    365         private final Popup popupCreatePopup(Component content, MouseState ms) {
     351        private Popup popupCreatePopup(Component content, MouseState ms) {
    366352            Point p = mv.getLocationOnScreen();
    367353            Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize();
     
    399385         * @param ms
    400386         */
    401         private final void statusBarElementUpdate(MouseState ms) {
     387        private void statusBarElementUpdate(MouseState ms) {
    402388            final OsmPrimitive osmNearest = mv.getNearestNodeOrWay(ms.mousePos, OsmPrimitive.isUsablePredicate, false);
    403389            if (osmNearest != null) {
     
    414400         * @param mods modifiers (i.e. control keys)
    415401         */
    416         private final void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
     402        private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
    417403            DataSet ds = Main.main.getCurrentDataSet();
    418404            // Find some items that are required for cycling through
     
    453439         * Tries to hide the given popup
    454440         */
    455         private final void popupHidePopup() {
     441        private void popupHidePopup() {
    456442            popupLabels = null;
    457443            if(popup == null)
     
    460446            popup = null;
    461447            EventQueue.invokeLater(new Runnable(){
    462                 public void run() { staticPopup.hide(); }});
     448               public void run() {
     449                    staticPopup.hide();
     450                }});
    463451        }
    464452
     
    469457         * @param lbls lables to show (see {@link #popupLabels})
    470458         */
    471         private final void popupShowPopup(Popup newPopup, List<JLabel> lbls) {
     459        private void popupShowPopup(Popup newPopup, List<JLabel> lbls) {
    472460            final Popup staticPopup = newPopup;
    473461            if(this.popup != null) {
     
    476464                final Popup staticOldPopup = this.popup;
    477465                EventQueue.invokeLater(new Runnable(){
    478                     public void run() {
     466                    @Override public void run() {
    479467                        staticPopup.show();
    480468                        staticOldPopup.hide();
     
    484472                // There is no old popup
    485473                EventQueue.invokeLater(new Runnable(){
    486                     public void run() { staticPopup.show(); }});
     474                     @Override public void run() { staticPopup.show(); }});
    487475            }
    488476            this.popupLabels = lbls;
     
    495483         * user clicks on the map instead of the popup.
    496484         */
    497         private final void popupUpdateLabels() {
     485        private void popupUpdateLabels() {
    498486            if(this.popup == null || this.popupLabels == null)
    499487                return;
     
    510498         * @param osm The primitive to derive the colors from
    511499         */
    512         private final void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
     500        private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
    513501            DataSet ds = Main.main.getCurrentDataSet();
    514502            if(ds.isSelected(osm)) {
     
    527515         * @return labels for info popup
    528516         */
    529         private final JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {
     517        private JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {
    530518            final StringBuilder text = new StringBuilder();
    531519            String name = osm.getDisplayName(DefaultNameFormatter.getInstance());
     
    587575            // can correct this defect.
    588576            l.addMouseMotionListener(new MouseMotionListener() {
    589                 public void mouseMoved(MouseEvent e) {
     577                 @Override public void mouseMoved(MouseEvent e) {
    590578                    l.setBackground(SystemColor.info);
    591579                    l.setForeground(SystemColor.infoText);
    592580                }
    593                 public void mouseDragged(MouseEvent e) {
     581                 @Override public void mouseDragged(MouseEvent e) {
    594582                    l.setBackground(SystemColor.info);
    595583                    l.setForeground(SystemColor.infoText);
     
    614602
    615603    private AWTEventListener awtListener = new AWTEventListener() {
    616         public void eventDispatched(AWTEvent event) {
     604         @Override
     605         public void eventDispatched(AWTEvent event) {
    617606            if (event instanceof InputEvent &&
    618607                    ((InputEvent)event).getComponent() == mv) {
     
    629618
    630619    private MouseMotionListener mouseMotionListener = new MouseMotionListener() {
     620        @Override
    631621        public void mouseMoved(MouseEvent e) {
    632622            synchronized (collector) {
     
    637627        }
    638628
     629        @Override
    639630        public void mouseDragged(MouseEvent e) {
    640631            mouseMoved(e);
     
    686677        this.collector = new Collector(mapFrame);
    687678
    688         lonText.addMouseListener(Main.main.menu.jumpToAct);
    689         latText.addMouseListener(Main.main.menu.jumpToAct);
    690        
     679        // Context menu of status bar
     680        setComponentPopupMenu(new JPopupMenu() {
     681            JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide status bar")) {
     682                @Override public void actionPerformed(ActionEvent e) {
     683                    boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState();
     684                    Main.pref.put("statusbar.always-visible", sel);
     685                }
     686            });
     687            JMenuItem jumpButton;
     688            {
     689                jumpButton = add(Main.main.menu.jumpToAct);
     690                addPopupMenuListener(new PopupMenuListener() {
     691                    @Override
     692                    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
     693                        Component invoker = ((JPopupMenu)e.getSource()).getInvoker();
     694                        jumpButton.setVisible(invoker == latText || invoker == lonText);
     695                        doNotHide.setSelected(Main.pref.getBoolean("statusbar.always-visible", true));
     696                    }
     697                    @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
     698                    @Override public void popupMenuCanceled(PopupMenuEvent e) {}
     699                });
     700                add(doNotHide);
     701            }
     702        });
     703
    691704        // Listen for mouse movements and set the position text field
    692705        mv.addMouseMotionListener(new MouseMotionListener(){
     706            @Override
    693707            public void mouseDragged(MouseEvent e) {
    694708                mouseMoved(e);
    695709            }
     710            @Override
    696711            public void mouseMoved(MouseEvent e) {
    697712                if (mv.center == null)
     
    709724        setLayout(new GridBagLayout());
    710725        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     726
     727        latText.setInheritsPopupMenu(true);
     728        lonText.setInheritsPopupMenu(true);
     729        headingText.setInheritsPopupMenu(true);
     730        //angleText.setInheritsPopupMenu(true);
     731        distText.setInheritsPopupMenu(true);
     732        nameText.setInheritsPopupMenu(true);
     733        //helpText.setInheritsPopupMenu(true);
     734        //progressBar.setInheritsPopupMenu(true);
    711735
    712736        add(latText, GBC.std());
     
    745769    }
    746770
     771    @Override
    747772    public String helpTopic() {
    748773        return ht("/Statusline");
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r5670 r5965  
    2323import java.util.Collections;
    2424import java.util.Comparator;
    25 import java.util.Enumeration;
    2625import java.util.LinkedList;
    2726import java.util.List;
     
    261260        //store the last mouse action
    262261        this.addMouseMotionListener(new MouseMotionListener() {
    263             public void mouseDragged(MouseEvent e) {
     262            @Override public void mouseDragged(MouseEvent e) {
    264263                mouseMoved(e);
    265264            }
    266             public void mouseMoved(MouseEvent e) {
     265            @Override public void mouseMoved(MouseEvent e) {
    267266                lastMEvent = e;
    268267            }
     
    483482                ret,
    484483                new Comparator<Layer>() {
    485                     public int compare(Layer l1, Layer l2) {
     484                    @Override public int compare(Layer l1, Layer l2) {
    486485                        if (l1 instanceof OsmDataLayer && l2 instanceof OsmDataLayer) {
    487486                            if (l1 == getActiveLayer()) return -1;
     
    780779         * that I switch layers and actions at the same time and it was annoying to mind the
    781780         * order. This way it works as visual clue for new users */
    782         for (Enumeration<AbstractButton> e = Main.map.toolGroup.getElements() ; e.hasMoreElements() ;) {
    783             AbstractButton button = e.nextElement();
    784             MapMode mode = (MapMode)button.getAction();
    785             boolean isLayerSupported = mode.layerIsSupported(layer);
    786             button.setEnabled(isLayerSupported);
    787             // Also update associated shortcut (fix #6876)
    788             if (isLayerSupported) {
    789                 Main.registerActionShortcut(mode, mode.getShortcut());
     781        for (AbstractButton b: Main.map.allMapModeButtons) {
     782            MapMode mode = (MapMode)b.getAction();
     783            if (mode.layerIsSupported(layer)) {
     784                Main.registerActionShortcut(mode, mode.getShortcut()); //fix #6876
     785                b.setEnabled(true);
    790786            } else {
    791787                Main.unregisterShortcut(mode.getShortcut());
     788                b.setEnabled(false);
    792789            }
    793790        }
     
    859856    }
    860857
     858    @Override
    861859    public void propertyChange(PropertyChangeEvent evt) {
    862860        if (evt.getPropertyName().equals(Layer.VISIBLE_PROP)) {
     
    894892
    895893    private SelectionChangedListener repaintSelectionChangedListener = new SelectionChangedListener(){
    896         public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     894        @Override public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    897895            repaint();
    898896        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r5954 r5965  
    3030import java.util.Map;
    3131
     32import javax.swing.AbstractAction;
    3233import javax.swing.Action;
    3334import javax.swing.DefaultListCellRenderer;
     
    3637import javax.swing.ImageIcon;
    3738import javax.swing.JButton;
     39import javax.swing.JCheckBoxMenuItem;
    3840import javax.swing.JComponent;
    3941import javax.swing.JLabel;
     
    5153import javax.swing.event.ListSelectionEvent;
    5254import javax.swing.event.ListSelectionListener;
     55import javax.swing.event.PopupMenuEvent;
     56import javax.swing.event.PopupMenuListener;
    5357import javax.swing.event.TreeSelectionEvent;
    5458import javax.swing.event.TreeSelectionListener;
     
    6670import org.openstreetmap.josm.actions.ParameterizedActionDecorator;
    6771import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    68 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    6972import org.openstreetmap.josm.tools.GBC;
    7073import org.openstreetmap.josm.tools.ImageProvider;
     
    7275
    7376public class ToolbarPreferences implements PreferenceSettingFactory {
    74 
    7577
    7678    private static final String EMPTY_TOOLBAR_MARKER = "<!-empty-!>";
     
    228230                    skip('=');
    229231                    String paramValue = readTillChar(',','}');
    230                     if ("icon".equals(paramName) && paramValue.length() > 0)
     232                    if ("icon".equals(paramName) && paramValue.length() > 0) {
    231233                        result.setIcon(paramValue);
    232                     else if("name".equals(paramName) && paramValue.length() > 0)
     234                    } else if("name".equals(paramName) && paramValue.length() > 0) {
    233235                        result.setName(paramValue);
     236                    }
    234237                    skip(',');
    235238                }
     
    294297                    first = false;
    295298                }
    296                 if(!first)
     299                if(!first) {
    297300                    result.append('}');
     301            }
    298302            }
    299303
     
    339343                        return null;
    340344                    }
    341                 } else
     345                } else {
    342346                    rowIndex -= 2;
     347            }
    343348            }
    344349            ActionParameter<Object> param = getParam(rowIndex);
     
    368373                     currentAction.setIcon((String)aValue);
    369374                     return;
    370                 } else
     375                } else {
    371376                    rowIndex -= 2;
     377            }
    372378            }
    373379            ActionParameter<Object> param = getParam(rowIndex);
     
    383389    }
    384390
    385     private static class ToolbarPopupMenu extends JPopupMenu {
    386         public ToolbarPopupMenu(final ActionDefinition action) {
    387 
    388             if(action != null) {
    389                 add(tr("Remove from toolbar",action.getDisplayName()))
    390                         .addActionListener(new ActionListener() {
    391                             @Override public void actionPerformed(ActionEvent e) {
     391    private class ToolbarPopupMenu extends JPopupMenu  {
     392        ActionDefinition act;
     393
     394        private void setActionAndAdapt(ActionDefinition action) {
     395            this.act = action;
     396            doNotHide.setSelected(Main.pref.getBoolean("toolbar.always-visible", true));
     397            remove.setVisible(act!=null);
     398            shortcutEdit.setVisible(act!=null);
     399        }
     400
     401        JMenuItem remove = new JMenuItem(new AbstractAction(tr("Remove from toolbar")) {
     402            @Override
     403            public void actionPerformed(ActionEvent e) {
    392404                                Collection<String> t = new LinkedList<String>(getToolString());
    393405                                ActionParser parser = new ActionParser(null);
    394406                                // get text definition of current action
    395                                 String res = parser.saveAction(action);
     407                String res = parser.saveAction(act);
    396408                                // remove the button from toolbar preferences
    397409                                t.remove( res );
     
    400412                            }
    401413                });
    402             }
    403414           
    404             add(tr("Configure toolbar")).addActionListener(new ActionListener() {
    405                 @Override public void actionPerformed(ActionEvent e) {
     415        JMenuItem configure = new JMenuItem(new AbstractAction(tr("Configure toolbar")) {
     416            @Override
     417            public void actionPerformed(ActionEvent e) {
    406418                    final PreferenceDialog p =new PreferenceDialog(Main.parent);
    407419                    p.selectPreferencesTabByName("toolbar");
     
    410422            });
    411423
    412             add(tr("Edit shortcut")).addActionListener(new ActionListener() {
    413                 @Override public void actionPerformed(ActionEvent e) {
     424        JMenuItem shortcutEdit = new JMenuItem(new AbstractAction(tr("Edit shortcut")) {
     425            @Override
     426            public void actionPerformed(ActionEvent e) {
    414427                    final PreferenceDialog p =new PreferenceDialog(Main.parent);
    415                     p.getTabbedPane().getShortcutPreference().setDefaultFilter(action.getDisplayName());
     428                p.getTabbedPane().getShortcutPreference().setDefaultFilter(act.getDisplayName());
    416429                    p.selectPreferencesTabByName("shortcuts");
    417430                    p.setVisible(true);
    418                     // refresh toolbar to accept changes of shortcuts without restart
     431                // refresh toolbar to try using changed shortcuts without restart
    419432                    Main.toolbar.refreshToolbarControl();
    420433                }
    421434            });
    422         }
    423     }
     435
     436        JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("getSt hide toolbar and menu")) {
     437            @Override
     438            public void actionPerformed(ActionEvent e) {
     439                boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState();
     440                Main.pref.put("toolbar.always-visible", sel);
     441                Main.pref.put("menu.always-visible", sel);
     442        }
     443        });
     444        {
     445            addPopupMenuListener(new PopupMenuListener() {
     446                @Override
     447                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
     448                    setActionAndAdapt(buttonActions.get(
     449                            ((JPopupMenu)e.getSource()).getInvoker()
     450                    ));
     451    }
     452                @Override
     453                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
     454
     455                @Override
     456                public void popupMenuCanceled(PopupMenuEvent e) {}
     457            });
     458            add(remove);
     459            add(configure);
     460            add(shortcutEdit);
     461            add(doNotHide);
     462        }
     463    }
     464
     465    private ToolbarPopupMenu popupMenu = new ToolbarPopupMenu();
    424466
    425467    /**
     
    433475
    434476    public JToolBar control = new JToolBar();
     477    private HashMap<Object, ActionDefinition> buttonActions = new HashMap<Object, ActionDefinition>(30);
    435478
    436479    @Override
     
    826869                } else {
    827870                    String res = parser.saveAction(action);
    828                     if(res != null)
     871                    if(res != null) {
    829872                        t.add(res);
    830873                }
     874            }
    831875            }
    832876            if (t.isEmpty()) {
     
    842886    public ToolbarPreferences() {
    843887        control.setFloatable(false);
    844         control.addMouseListener(new PopupMenuLauncher(new ToolbarPopupMenu(null)));
     888        control.setComponentPopupMenu(popupMenu);
    845889    }
    846890
     
    9791023    public void refreshToolbarControl() {
    9801024        control.removeAll();
     1025        buttonActions.clear();
    9811026
    9821027        for (ActionDefinition action : getDefinedActions()) {
     
    9851030            } else {
    9861031                final JButton b = addButtonAndShortcut(action);
     1032                buttonActions.put(b, action);
    9871033               
    9881034                Icon i = action.getDisplayIcon();
     
    10011047                    });
    10021048                }
    1003                 b.addMouseListener(new PopupMenuLauncher( new ToolbarPopupMenu(action)));
     1049                b.setInheritsPopupMenu(true);
    10041050            }
    10051051        }
     
    10141060        if (action.getAction() instanceof JosmAction) {
    10151061            sc = ((JosmAction) action.getAction()).getShortcut();
    1016             if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) sc = null;
     1062            if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) {
     1063                sc = null;
     1064        }
    10171065        }
    10181066
     
    10231071       
    10241072        String tt = action.getDisplayTooltip();
    1025         if (tt==null) tt="";
     1073        if (tt==null) {
     1074            tt="";
     1075        }
    10261076
    10271077        if (sc == null || paramCode != 0) {
    10281078            String name = (String) action.getAction().getValue("toolbar");
    1029             if (name==null) name=action.getDisplayName();
    1030             if (paramCode!=0) name = name+paramCode;
     1079            if (name==null) {
     1080                name=action.getDisplayName();
     1081            }
     1082            if (paramCode!=0) {
     1083                name = name+paramCode;
     1084            }
    10311085            String desc = action.getDisplayName() + ((paramCode==0)?"":action.parameters.toString());
    10321086            sc = Shortcut.registerShortcut("toolbar:"+name, tr("Toolbar: {0}", desc),
     
    10441098        }
    10451099       
    1046         if (!tt.isEmpty()) b.setToolTipText(tt);
     1100        if (!tt.isEmpty()) {
     1101            b.setToolTipText(tt);
     1102        }
    10471103        return b;
    10481104    }
Note: See TracChangeset for help on using the changeset viewer.