Changeset 4669 in josm for trunk/src


Ignore:
Timestamp:
2011-12-20T21:33:34+01:00 (13 years ago)
Author:
stoecker
Message:

fix #6963 - patch by akks - fixes for left hand buttons

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

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

    r4666 r4669  
    2525    public boolean groupbutton;
    2626    private ShowHideButtonListener listener;
     27    private boolean hideIfDisabled=false;
    2728
    2829    /**
     
    6667    }
    6768   
     69    String getPreferenceKey() {
     70        String s = (String) getSafeActionValue("toolbar");
     71        if (s==null) {
     72            if (getAction()!=null) s=getAction().getClass().getName();
     73        }
     74        return "sidetoolbar.hidden."+s;
     75       
     76    }
     77   
    6878    @Override
    6979    public void applyButtonHiddenPreferences() {
    70         String actionName = (String) getSafeActionValue(AbstractAction.NAME);
    71         boolean hiddenFlag = Main.pref.getBoolean(actionName + ".itbutton_hidden", false);
    72         setVisible(!hiddenFlag);   
     80        boolean alwaysHideDisabled = Main.pref.getBoolean("sidetoolbar.hideDisabledButtons", false);
     81        boolean hiddenFlag = Main.pref.getBoolean(getPreferenceKey(), false);
     82        if (!isEnabled() && (hideIfDisabled || alwaysHideDisabled))
     83                setVisible(false);  // hide because of disabled button
     84            else
     85                setVisible( !hiddenFlag ); // show or hide, do what preferences say 
    7386    }
    7487
    7588    @Override
    7689    public void setButtonHidden(boolean b) {
    77         String actionName = (String) getSafeActionValue(AbstractAction.NAME);
    7890        setVisible(!b);
    7991        if (listener!=null) { // if someone wants to know about changes of visibility
    8092            if (!b) listener.buttonShown(); else listener.buttonHidden();
    8193        }
    82         Main.pref.put(actionName + ".itbutton_hidden", b);
     94        Main.pref.put(getPreferenceKey(), b);
     95    }
     96   
     97    /*
     98     * This fuction should be called for plugins that want to enable auto-hiding
     99     * custom buttons when they are disabled (because of incorrect layer, for example)
     100     */
     101    public void setAutoHideDisabledButton(boolean b) {
     102        hideIfDisabled=b;
     103        if (b && !isEnabled()) setVisible(false);
    83104    }
    84105   
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r4609 r4669  
    3333import javax.swing.JToolBar;
    3434import javax.swing.KeyStroke;
     35import javax.swing.SwingUtilities;
    3536import javax.swing.border.Border;
    3637import javax.swing.plaf.basic.BasicSplitPaneDivider;
     
    408409        }));
    409410    }
    410    
     411
    411412        class ListAllButtonsAction extends AbstractAction {
    412413
     
    454455        toolBarToggle.repaint();
    455456        for (IconToggleButton b : allMapModeButtons) {
    456             b.applyButtonHiddenPreferences();
     457             b.applyButtonHiddenPreferences();
    457458        }
    458459        toolBarActions.repaint();
    459460    }
    460 
     461   
    461462    /**
    462463     * Replies the instance of a toggle dialog of type <code>type</code> managed by this
     
    535536        // invalidate repaint cache
    536537        Main.map.mapView.preferenceChanged(null);
    537     }
     538       
     539        // After all listeners notice new layer, some buttons will be disabled/enabled
     540        // and possibly need to be hidden/shown.
     541        SwingUtilities.invokeLater(new Runnable() {
     542            public void run() {
     543                validateToolBarsVisibility();
     544            }
     545        });
     546    }
     547   
    538548
    539549    private MapMode getLastMapMode(Layer newLayer) {
Note: See TracChangeset for help on using the changeset viewer.