Changeset 6727 in josm


Ignore:
Timestamp:
2014-01-18T15:10:13+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #7633 - Make dynamic buttons features disabled by default

File:
1 edited

Legend:

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

    r6643 r6727  
    7373public class ToggleDialog extends JPanel implements ShowHideButtonListener, Helpful, AWTEventListener, Destroyable {
    7474
    75     public enum ButtonHiddingType {
    76         ALWAYS_SHOWN, ALWAYS_HIDDEN, DYNAMIC
    77     }
    78 
    79     private final ParametrizedEnumProperty<ButtonHiddingType> PROP_BUTTON_HIDING = new ParametrizedEnumProperty<ToggleDialog.ButtonHiddingType>(ButtonHiddingType.class, ButtonHiddingType.DYNAMIC) {
     75    /**
     76     * The button-hiding strategy in toggler dialogs.
     77     */
     78    public enum ButtonHidingType {
     79        /** Buttons are always shown (default) **/
     80        ALWAYS_SHOWN,
     81        /** Buttons are always hidden **/
     82        ALWAYS_HIDDEN,
     83        /** Buttons are dynamically hidden, i.e. only shown when mouse cursor is in dialog */
     84        DYNAMIC
     85    }
     86
     87    private final ParametrizedEnumProperty<ButtonHidingType> PROP_BUTTON_HIDING = new ParametrizedEnumProperty<ToggleDialog.ButtonHidingType>(
     88            ButtonHidingType.class, ButtonHidingType.ALWAYS_SHOWN) {
    8089        @Override
    8190        protected String getKey(String... params) {
     
    8392        }
    8493        @Override
    85         protected ButtonHiddingType parse(String s) {
     94        protected ButtonHidingType parse(String s) {
    8695            try {
    8796                return super.parse(s);
    8897            } catch (IllegalArgumentException e) {
    8998                // Legacy settings
    90                 return Boolean.parseBoolean(s)?ButtonHiddingType.DYNAMIC:ButtonHiddingType.ALWAYS_SHOWN;
     99                return Boolean.parseBoolean(s)?ButtonHidingType.DYNAMIC:ButtonHidingType.ALWAYS_SHOWN;
    91100            }
    92101        }
     
    107116     */
    108117    protected boolean isShowing;
     118
    109119    /**
    110120     * If isShowing is true, indicates whether the dialog is docked or not, e. g.
     
    112122     */
    113123    protected boolean isDocked;
     124
    114125    /**
    115126     * If isShowing and isDocked are true, indicates whether the dialog is
     
    117128     */
    118129    protected boolean isCollapsed;
     130
    119131    /**
    120132     * Indicates whether dynamic button hiding is active or not.
    121133     */
    122     protected ButtonHiddingType buttonHiding;
     134    protected ButtonHidingType buttonHiding;
    123135
    124136    /** the preferred height if the toggle dialog is expanded */
     
    385397        Component[] comps = getComponents();
    386398        for (Component comp : comps) {
    387             if (comp != titleBar && (!visible || comp != buttonsPanel || buttonHiding != ButtonHiddingType.ALWAYS_HIDDEN)) {
     399            if (comp != titleBar && (!visible || comp != buttonsPanel || buttonHiding != ButtonHidingType.ALWAYS_HIDDEN)) {
    388400                comp.setVisible(visible);
    389401            }
     
    475487
    476488            if(Main.pref.getBoolean("dialog.dynamic.buttons", true)) {
    477                 buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHiddingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow"));
     489                buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow"));
    478490                buttonsHide.setToolTipText(tr("Toggle dynamic buttons"));
    479491                buttonsHide.setBorder(BorderFactory.createEmptyBorder());
     
    482494                            @Override
    483495                            public void actionPerformed(ActionEvent e) {
    484                                 setIsButtonHiding(buttonHiding == ButtonHiddingType.ALWAYS_SHOWN?ButtonHiddingType.DYNAMIC:ButtonHiddingType.ALWAYS_SHOWN);
     496                                setIsButtonHiding(buttonHiding == ButtonHidingType.ALWAYS_SHOWN?ButtonHidingType.DYNAMIC:ButtonHidingType.ALWAYS_SHOWN);
    485497                            }
    486498                        }
     
    559571            public final JRadioButtonMenuItem alwaysShown = new JRadioButtonMenuItem(new AbstractAction(tr("Always shown")) {
    560572                @Override public void actionPerformed(ActionEvent e) {
    561                     setIsButtonHiding(ButtonHiddingType.ALWAYS_SHOWN);
     573                    setIsButtonHiding(ButtonHidingType.ALWAYS_SHOWN);
    562574                }
    563575            });
    564576            public final JRadioButtonMenuItem dynamic = new JRadioButtonMenuItem(new AbstractAction(tr("Dynamic")) {
    565577                @Override public void actionPerformed(ActionEvent e) {
    566                     setIsButtonHiding(ButtonHiddingType.DYNAMIC);
     578                    setIsButtonHiding(ButtonHidingType.DYNAMIC);
    567579                }
    568580            });
    569581            public final JRadioButtonMenuItem alwaysHidden = new JRadioButtonMenuItem(new AbstractAction(tr("Always hidden")) {
    570582                @Override public void actionPerformed(ActionEvent e) {
    571                     setIsButtonHiding(ButtonHiddingType.ALWAYS_HIDDEN);
     583                    setIsButtonHiding(ButtonHidingType.ALWAYS_HIDDEN);
    572584                }
    573585            });
    574586            public DialogPopupMenu() {
    575                 alwaysShown.setSelected(buttonHiding == ButtonHiddingType.ALWAYS_SHOWN);
    576                 dynamic.setSelected(buttonHiding == ButtonHiddingType.DYNAMIC);
    577                 alwaysHidden.setSelected(buttonHiding == ButtonHiddingType.ALWAYS_HIDDEN);
     587                alwaysShown.setSelected(buttonHiding == ButtonHidingType.ALWAYS_SHOWN);
     588                dynamic.setSelected(buttonHiding == ButtonHidingType.DYNAMIC);
     589                alwaysHidden.setSelected(buttonHiding == ButtonHidingType.ALWAYS_HIDDEN);
    578590                buttonHidingMenu.add(alwaysShown);
    579591                buttonHidingMenu.add(dynamic);
     
    711723    protected void setIsDocked(boolean val) {
    712724        if(buttonsPanel != null && buttonsHide != null) {
    713             buttonsPanel.setVisible(val ? buttonHiding == ButtonHiddingType.ALWAYS_SHOWN : true);
     725            buttonsPanel.setVisible(val ? buttonHiding == ButtonHidingType.ALWAYS_SHOWN : true);
    714726        }
    715727        isDocked = val;
     
    724736    }
    725737
    726     protected void setIsButtonHiding(ButtonHiddingType val) {
     738    protected void setIsButtonHiding(ButtonHidingType val) {
    727739        buttonHiding = val;
    728740        PROP_BUTTON_HIDING.put(val);
    729741        if (buttonsHide != null) {
    730             buttonsHide.setIcon(ImageProvider.get("misc", val != ButtonHiddingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow"));
     742            buttonsHide.setIcon(ImageProvider.get("misc", val != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow"));
    731743        }
    732744        if (buttonsPanel != null) {
    733             buttonsPanel.setVisible(val != ButtonHiddingType.ALWAYS_HIDDEN);
     745            buttonsPanel.setVisible(val != ButtonHidingType.ALWAYS_HIDDEN);
    734746        }
    735747        stateChanged();
     
    854866            if (Main.pref.getBoolean("dialog.dynamic.buttons", true)) {
    855867                Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK);
    856                 buttonsPanel.setVisible(buttonHiding == ButtonHiddingType.ALWAYS_SHOWN || !isDocked);
    857             } else if (buttonHiding == ButtonHiddingType.ALWAYS_HIDDEN) {
     868                buttonsPanel.setVisible(buttonHiding == ButtonHidingType.ALWAYS_SHOWN || !isDocked);
     869            } else if (buttonHiding == ButtonHidingType.ALWAYS_HIDDEN) {
    858870                buttonsPanel.setVisible(false);
    859871            }
     
    870882    @Override
    871883    public void eventDispatched(AWTEvent event) {
    872         if(isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHiddingType.DYNAMIC) {
     884        if(isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHidingType.DYNAMIC) {
    873885            Rectangle b = this.getBounds();
    874886            b.setLocation(getLocationOnScreen());
Note: See TracChangeset for help on using the changeset viewer.