Ignore:
Timestamp:
2010-10-10T23:37:19+02:00 (14 years ago)
Author:
bastiK
Message:

add option to hide toggle buttons on the left

File:
1 edited

Legend:

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

    r3455 r3598  
    11// License: GPL. See LICENSE file for details.
    2 
    32package org.openstreetmap.josm.gui;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    45
    56import java.awt.BorderLayout;
    67import java.awt.Container;
    78import java.awt.Dimension;
     9import java.awt.Font;
     10import java.awt.Rectangle;
     11import java.awt.event.ActionEvent;
    812import java.awt.event.KeyEvent;
    913import java.awt.event.MouseWheelEvent;
     
    1519import java.util.concurrent.CopyOnWriteArrayList;
    1620
     21import javax.swing.AbstractAction;
    1722import javax.swing.AbstractButton;
    1823import javax.swing.Action;
    1924import javax.swing.BoxLayout;
    2025import javax.swing.ButtonGroup;
     26import javax.swing.JButton;
     27import javax.swing.JCheckBoxMenuItem;
    2128import javax.swing.JComponent;
    2229import javax.swing.JPanel;
     30import javax.swing.JPopupMenu;
    2331import javax.swing.JSplitPane;
    2432import javax.swing.JToolBar;
     
    4957import org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog;
    5058import org.openstreetmap.josm.gui.layer.Layer;
     59import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    5160import org.openstreetmap.josm.tools.Destroyable;
    5261
     
    92101
    93102    public final ButtonGroup toolGroup = new ButtonGroup();
     103
     104    public final JButton otherButton = new JButton(new OtherButtonsAction());
    94105
    95106    /**
     
    201212        MapView.removeLayerChangeListener(this);
    202213        dialogsPanel.destroy();
    203         for (int i = 0; i < toolBarActions.getComponentCount(); ++i)
     214        for (int i = 0; i < toolBarActions.getComponentCount(); ++i) {
    204215            if (toolBarActions.getComponent(i) instanceof Destroyable) {
    205216                ((Destroyable)toolBarActions.getComponent(i)).destroy();
    206217            }
    207         for (int i = 0; i < toolBarToggle.getComponentCount(); ++i)
     218        }
     219        for (int i = 0; i < toolBarToggle.getComponentCount(); ++i) {
    208220            if (toolBarToggle.getComponent(i) instanceof Destroyable) {
    209221                ((Destroyable)toolBarToggle.getComponent(i)).destroy();
    210222            }
     223        }
    211224
    212225        // remove menu entries
     
    240253     * @param dlg The toggle dialog. It must not be in the list already.
    241254     */
    242     public IconToggleButton addToggleDialog(ToggleDialog dlg) {
    243         IconToggleButton button = new IconToggleButton(dlg.getToggleAction());
     255    public IconToggleButton addToggleDialog(final ToggleDialog dlg) {
     256        final IconToggleButton button = new IconToggleButton(dlg.getToggleAction());
    244257        toolBarToggle.add(button);
     258        button.addMouseListener(new PopupMenuLauncher(new JPopupMenu() {
     259            {
     260                add(new AbstractAction() {
     261                    {
     262                        putValue(NAME, tr("Hide this button"));
     263                        putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again."));
     264                    }
     265
     266                    @Override
     267                    public void actionPerformed(ActionEvent e) {
     268                        dlg.hideButton();
     269                    }
     270                });
     271            }
     272        }));
     273        dlg.setButton(button);
    245274        allDialogs.add(dlg);
    246275        if (dialogsPanel.initialized) {
     
    298327        JToolBar jb = new JToolBar(JToolBar.VERTICAL);
    299328        jb.setFloatable(false);
     329        toolBarActions.setAlignmentX(0.5f);
    300330        jb.add(toolBarActions);
     331
    301332        jb.addSeparator(new Dimension(0,10));
     333        toolBarToggle.setAlignmentX(0.5f);
    302334        jb.add(toolBarToggle);
     335        otherButton.setAlignmentX(0.5f);
     336        otherButton.setBorder(null);
     337        otherButton.setFont(otherButton.getFont().deriveFont(Font.PLAIN));
     338        jb.add(otherButton);
     339
    303340        if(Main.pref.getBoolean("sidetoolbar.visible", true))
    304341        {
     
    317354        if (statusLine != null && Main.pref.getBoolean("statusline.visible", true)) {
    318355            panel.add(statusLine, BorderLayout.SOUTH);
     356        }
     357    }
     358
     359    class OtherButtonsAction extends AbstractAction {
     360
     361        public OtherButtonsAction() {
     362            putValue(NAME, ">>");
     363        }
     364
     365        @Override
     366        public void actionPerformed(ActionEvent e) {
     367            JPopupMenu menu = new JPopupMenu();
     368            for (final ToggleDialog t : allDialogs) {
     369                menu.add(new JCheckBoxMenuItem(new AbstractAction() {
     370                    {
     371                        putValue(NAME, t.getToggleAction().getValue(NAME));
     372                        putValue(SMALL_ICON, t.getToggleAction().getValue(SMALL_ICON));
     373                        putValue(SELECTED_KEY, !t.isButtonHidden());
     374                        putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button"));
     375                    }
     376                    @Override
     377                    public void actionPerformed(ActionEvent e) {
     378                        if ((Boolean) getValue(SELECTED_KEY)) {
     379                            t.showButton();
     380                        } else {
     381                            t.hideButton();
     382                        }
     383                    }
     384                }));
     385            }
     386            Rectangle bounds = otherButton.getBounds();
     387            menu.show(otherButton, bounds.x+bounds.width, 0);
    319388        }
    320389    }
Note: See TracChangeset for help on using the changeset viewer.