Ticket #6953: SidetoolbarLayerChange2.patch
File SidetoolbarLayerChange2.patch, 3.9 KB (added by , 14 years ago) |
---|
-
src/org/openstreetmap/josm/gui/IconToggleButton.java
24 24 25 25 public boolean groupbutton; 26 26 private ShowHideButtonListener listener; 27 private boolean hideIfDisabled=false; 27 28 28 29 /** 29 30 * Construct the toggle button with the given action. … … 65 66 } 66 67 } 67 68 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 68 78 @Override 69 79 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 73 86 } 74 87 75 88 @Override 76 89 public void setButtonHidden(boolean b) { 77 String actionName = (String) getSafeActionValue(AbstractAction.NAME);78 90 setVisible(!b); 79 91 if (listener!=null) { // if someone wants to know about changes of visibility 80 92 if (!b) listener.buttonShown(); else listener.buttonHidden(); 81 93 } 82 Main.pref.put( actionName + ".itbutton_hidden", b);94 Main.pref.put(getPreferenceKey(), b); 83 95 } 84 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); 104 } 105 85 106 @Override 86 107 public void showButton() { 87 108 setButtonHidden(false); -
src/org/openstreetmap/josm/gui/MapFrame.java
32 32 import javax.swing.JSplitPane; 33 33 import javax.swing.JToolBar; 34 34 import javax.swing.KeyStroke; 35 import javax.swing.SwingUtilities; 35 36 import javax.swing.border.Border; 36 37 import javax.swing.plaf.basic.BasicSplitPaneDivider; 37 38 import javax.swing.plaf.basic.BasicSplitPaneUI; … … 407 408 } 408 409 })); 409 410 } 410 411 411 412 class ListAllButtonsAction extends AbstractAction { 412 413 413 414 private JButton button; … … 453 454 } 454 455 toolBarToggle.repaint(); 455 456 for (IconToggleButton b : allMapModeButtons) { 456 b.applyButtonHiddenPreferences();457 b.applyButtonHiddenPreferences(); 457 458 } 458 459 toolBarActions.repaint(); 459 460 } 460 461 461 462 /** 462 463 * Replies the instance of a toggle dialog of type <code>type</code> managed by this 463 464 * map frame … … 534 535 } 535 536 // invalidate repaint cache 536 537 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 }); 537 546 } 547 538 548 539 549 private MapMode getLastMapMode(Layer newLayer) { 540 550 MapMode mode = lastMapMode.get(newLayer);