Ignore:
Timestamp:
2012-01-21T23:04:50+01:00 (12 years ago)
Author:
bastiK
Message:

expert mode rework:

  • toggling of expert mode does not require restart
  • checkbox at a more prominent places (MainMenu > View and in the preference dialog at the bottom)
File:
1 edited

Legend:

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

    r4835 r4840  
    1313
    1414import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.actions.ExpertToggleAction;
     16import org.openstreetmap.josm.actions.ExpertToggleAction.ExpertModeChangeListener;
    1517import org.openstreetmap.josm.tools.Destroyable;
    1618
     
    2123 * @author imi, akks
    2224 */
    23 public class IconToggleButton extends JToggleButton implements HideableButton, PropertyChangeListener, Destroyable {
     25public class IconToggleButton extends JToggleButton implements HideableButton, PropertyChangeListener, Destroyable, ExpertModeChangeListener {
    2426
    2527    public boolean groupbutton;
    2628    private ShowHideButtonListener listener;
    27     private boolean hideIfDisabled=false;
    28     private boolean hiddenByDefault;
     29    private boolean hideIfDisabled = false;
     30    private boolean isExpert;
    2931
    3032    /**
     
    3840     * Construct the toggle button with the given action.
    3941     */
    40     public IconToggleButton(Action action, boolean hiddenByDefault) {
     42    public IconToggleButton(Action action, boolean isExpert) {
    4143        super(action);
    42         this.hiddenByDefault = hiddenByDefault;
     44        this.isExpert = isExpert;
    4345        setText(null);
    4446
     
    5557            }
    5658        });
     59
     60        ExpertToggleAction.addExpertModeChangeListener(this);
    5761    }
    5862
     
    7579        }
    7680    }
    77    
     81
    7882    String getPreferenceKey() {
    7983        String s = (String) getSafeActionValue("toolbar");
    80         if (s==null) {
    81             if (getAction()!=null) s=getAction().getClass().getName();
     84        if (s == null) {
     85            if (getAction()!=null) {
     86                s = getAction().getClass().getName();
     87            }
    8288        }
    8389        return "sidetoolbar.hidden."+s;
    84        
     90
    8591    }
    86    
     92
     93    @Override
     94    public void expertChanged(boolean isExpert) {
     95        applyButtonHiddenPreferences();
     96    }
     97
    8798    @Override
    8899    public void applyButtonHiddenPreferences() {
    89100        boolean alwaysHideDisabled = Main.pref.getBoolean("sidetoolbar.hideDisabledButtons", false);
    90         boolean hiddenFlag = Main.pref.getBoolean(getPreferenceKey(), hiddenByDefault);
    91         if (!isEnabled() && (hideIfDisabled || alwaysHideDisabled))
    92                 setVisible(false);  // hide because of disabled button
    93             else
    94                 setVisible( !hiddenFlag ); // show or hide, do what preferences say 
     101        if (!isEnabled() && (hideIfDisabled || alwaysHideDisabled)) {
     102            setVisible(false);  // hide because of disabled button
     103        } else {
     104            boolean hiddenFlag = false;
     105            String hiddenFlagStr = Main.pref.get(getPreferenceKey(), null);
     106            if (hiddenFlagStr == null) {
     107                if (isExpert && !Main.main.menu.expert.isSelected()) {
     108                    hiddenFlag = true;
     109                }
     110            } else {
     111                hiddenFlag = Boolean.parseBoolean(hiddenFlagStr);
     112            }
     113            setVisible( !hiddenFlag ); // show or hide, do what preferences say
     114        }
    95115    }
    96116
     
    101121            if (!b) listener.buttonShown(); else listener.buttonHidden();
    102122        }
    103         Main.pref.put(getPreferenceKey(), b);
     123        if ((b && isExpert && !Main.main.menu.expert.isSelected()) ||
     124            (!b && isExpert && Main.main.menu.expert.isSelected())) {
     125            Main.pref.put(getPreferenceKey(), null);
     126        } else {
     127            Main.pref.put(getPreferenceKey(), b);
     128        }
    104129    }
    105    
    106     /* 
     130
     131    /*
    107132     * This fuction should be called for plugins that want to enable auto-hiding
    108133     * custom buttons when they are disabled (because of incorrect layer, for example)
    109134     */
    110135    public void setAutoHideDisabledButton(boolean b) {
    111         hideIfDisabled=b;
    112         if (b && !isEnabled()) setVisible(false);
     136        hideIfDisabled = b;
     137        if (b && !isEnabled()) {
     138            setVisible(false);
     139        }
    113140    }
    114    
     141
    115142    @Override
    116143    public void showButton() {
    117144        setButtonHidden(false);
    118145    }
    119    
     146
    120147    @Override
    121148    public void hideButton() {
Note: See TracChangeset for help on using the changeset viewer.