Ticket #6953: SidetoolbarLayerChange2.patch

File SidetoolbarLayerChange2.patch, 3.9 KB (added by akks, 14 years ago)
  • src/org/openstreetmap/josm/gui/IconToggleButton.java

     
    2424
    2525    public boolean groupbutton;
    2626    private ShowHideButtonListener listener;
     27    private boolean hideIfDisabled=false;
    2728
    2829    /**
    2930     * Construct the toggle button with the given action.
     
    6566        }
    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);
    8395    }
    8496   
     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);
     104    }
     105   
    85106    @Override
    86107    public void showButton() {
    87108        setButtonHidden(false);
  • src/org/openstreetmap/josm/gui/MapFrame.java

     
    3232import javax.swing.JSplitPane;
    3333import javax.swing.JToolBar;
    3434import javax.swing.KeyStroke;
     35import javax.swing.SwingUtilities;
    3536import javax.swing.border.Border;
    3637import javax.swing.plaf.basic.BasicSplitPaneDivider;
    3738import javax.swing.plaf.basic.BasicSplitPaneUI;
     
    407408            }
    408409        }));
    409410    }
    410    
     411
    411412        class ListAllButtonsAction extends AbstractAction {
    412413
    413414        private JButton button;
     
    453454        }
    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
    463464     * map frame
     
    534535        }
    535536        // invalidate repaint cache
    536537        Main.map.mapView.preferenceChanged(null);
     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        });
    537546    }
     547   
    538548
    539549    private MapMode getLastMapMode(Layer newLayer) {
    540550        MapMode mode = lastMapMode.get(newLayer);