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


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

add option to hide toggle buttons on the left

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 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    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r3502 r3598  
    3131import javax.swing.JOptionPane;
    3232import javax.swing.JPanel;
     33import javax.swing.JToggleButton;
    3334
    3435import org.openstreetmap.josm.Main;
     
    8283    protected JDialog detachedDialog;
    8384
     85    protected JToggleButton button;
     86    protected boolean buttonHidden;
     87
    8488    /**
    8589     * Constructor
     
    125129        isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true);
    126130        isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false);
     131
     132        buttonHidden = Main.pref.getBoolean(preferencePrefix+".button_hidden", false);
    127133
    128134        RedirectInputMap.redirectToMainContentPane(this);
     
    187193
    188194    /**
    189      * Changes the state of the dialog such that the user can see the content
    190      * and takes care of the panel reconstruction.
    191      */
    192     public void unfurlDialog()
    193     {
     195     * Changes the state of the dialog such that the user can see the content.
     196     * (takes care of the panel reconstruction)
     197     */
     198    public void unfurlDialog() {
    194199        if (isDialogInDefaultView())
    195200            return;
     
    198203            dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, this);
    199204        } else if (!isDialogShowing()) {
     205            if (isButtonHidden()) {
     206                showButtonImpl();
     207            }
    200208            showDialog();
    201209            if (isDocked && isCollapsed) {
     
    207215            showNotify();
    208216        }
     217    }
     218
     219    public void hideButton() {
     220        if (!button.isVisible())
     221            throw new AssertionError();
     222        if ((Boolean) toggleAction.getValue("selected")) {
     223            toggleAction.actionPerformed(null);
     224        }
     225        button.setVisible(false);
     226        setButtonHidden(true);
     227    }
     228
     229    public void showButton() {
     230        showButtonImpl();
     231        unfurlDialog();
     232    }
     233
     234    protected void showButtonImpl() {
     235        if (button.isVisible())
     236            throw new AssertionError();
     237        button.setVisible(true);
     238        setButtonHidden(false);
    209239    }
    210240
     
    569599    }
    570600
     601    public boolean isButtonHidden() {
     602        return buttonHidden;
     603    }
     604
     605    protected void setButtonHidden(boolean buttonHidden) {
     606        this.buttonHidden = buttonHidden;
     607        Main.pref.put(preferencePrefix+".button_hidden", buttonHidden);
     608    }
     609
     610
     611    public void setButton(JToggleButton button) {
     612        this.button = button;
     613        button.setVisible(!buttonHidden);
     614    }
     615
     616    public JToggleButton getButton() {
     617        return button;
     618    }
     619
    571620    /***
    572621     * The following methods are intended to be overridden, in order to customize
Note: See TracChangeset for help on using the changeset viewer.