Changeset 4609 in josm
- Timestamp:
- 2011-11-26T16:52:05+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java
r3451 r4609 7 7 import java.beans.PropertyChangeListener; 8 8 9 import javax.swing.AbstractAction; 9 10 import javax.swing.Action; 11 import javax.swing.Icon; 10 12 import javax.swing.JToggleButton; 11 13 14 import org.openstreetmap.josm.Main; 12 15 import org.openstreetmap.josm.tools.Destroyable; 13 16 … … 15 18 * Just a toggle button, with smaller border and icon only to display in 16 19 * MapFrame toolbars. 17 * 18 * @author imi 20 * Also provides methods for storing hidden state in preferences 21 * @author imi, akks 19 22 */ 20 public class IconToggleButton extends JToggleButton implements PropertyChangeListener, Destroyable {23 public class IconToggleButton extends JToggleButton implements HideableButton, PropertyChangeListener, Destroyable { 21 24 22 25 public boolean groupbutton; 26 private ShowHideButtonListener listener; 23 27 24 28 /** … … 59 63 action.removePropertyChangeListener(this); 60 64 } 65 66 @Override 67 public void applyButtonHiddenPreferences() { 68 String actionName = (String) getAction().getValue(AbstractAction.NAME); 69 boolean hiddenFlag = 70 Main.pref.getBoolean(actionName + ".itbutton_hidden", false); 71 setVisible(!hiddenFlag); 72 } 73 74 @Override 75 public void setButtonHidden(boolean b) { 76 String actionName = (String) getAction().getValue(AbstractAction.NAME); 77 setVisible(!b); 78 if (listener!=null) { // if someone wants to know about changes of visibility 79 if (!b) listener.buttonShown(); else listener.buttonHidden(); 80 } 81 Main.pref.put(actionName + ".itbutton_hidden", b); 82 83 } 84 @Override 85 public void showButton() { 86 setButtonHidden(false); 87 } 88 @Override 89 public void hideButton() { 90 setButtonHidden(true); 91 } 92 93 @Override 94 public String getActionName() { 95 return (String) getAction().getValue(Action.NAME); 96 } 97 98 @Override 99 public Icon getIcon() { 100 return (Icon) getAction().getValue(Action.SMALL_ICON); 101 } 102 103 @Override 104 public boolean isButtonVisible() { 105 return isVisible(); 106 } 107 108 @Override 109 public void setShowHideButtonListener(ShowHideButtonListener l) { 110 listener = l; 111 } 112 113 61 114 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r4590 r4609 14 14 import java.awt.event.MouseWheelListener; 15 15 import java.util.ArrayList; 16 import java.util.Collection; 16 17 import java.util.HashMap; 17 18 import java.util.List; … … 107 108 108 109 public final ButtonGroup toolGroup = new ButtonGroup(); 109 110 public final JButton otherButton = new JButton(new OtherButtonsAction()); 110 111 private List<IconToggleButton> allDialogButtons = new ArrayList<IconToggleButton>(); 112 private List<IconToggleButton> allMapModeButtons = new ArrayList<IconToggleButton>(); 113 114 private final ListAllButtonsAction listAllDialogsAction = new ListAllButtonsAction(allDialogButtons); 115 private final ListAllButtonsAction listAllMapModesAction = new ListAllButtonsAction(allMapModeButtons); 116 private final JButton listAllToggleDialogsButton = new JButton(listAllDialogsAction); 117 private final JButton listAllMapModesButton = new JButton(listAllMapModesAction); 118 { 119 listAllDialogsAction.setButton(listAllToggleDialogsButton); 120 listAllMapModesAction.setButton(listAllMapModesButton); 121 } 111 122 112 123 /** … … 262 273 public IconToggleButton addToggleDialog(final ToggleDialog dlg) { 263 274 final IconToggleButton button = new IconToggleButton(dlg.getToggleAction()); 264 button.addMouseListener(new PopupMenuLauncher(new JPopupMenu() { 265 { 266 add(new AbstractAction() { 267 { 268 putValue(NAME, tr("Hide this button")); 269 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again.")); 270 } 271 272 @Override 273 public void actionPerformed(ActionEvent e) { 274 dlg.hideButton(); 275 validateToolBarToggle(); 276 } 277 }); 278 } 279 })); 275 button.setShowHideButtonListener(dlg); 276 addHideContextMenu(button); 280 277 dlg.setButton(button); 281 if (button.isVisible()) { 282 toolBarToggle.add(button); 283 } 278 toolBarToggle.add(button); 284 279 allDialogs.add(dlg); 280 allDialogButtons.add(button); 281 button.applyButtonHiddenPreferences(); 285 282 if (dialogsPanel.initialized) { 286 283 dialogsPanel.add(dlg); … … 289 286 } 290 287 291 public void validateToolBarToggle() { 292 toolBarToggle.removeAll(); 293 for (ToggleDialog dlg : allDialogs) { 294 if (dlg.getButton().isVisible()) { 295 toolBarToggle.add(dlg.getButton()); 296 } 297 } 298 } 288 299 289 300 290 public void addMapMode(IconToggleButton b) { 301 291 toolBarActions.add(b); 302 292 toolGroup.add(b); 293 allMapModeButtons.add(b); 303 294 if (b.getAction() instanceof MapMode) { 304 295 mapModes.add((MapMode) b.getAction()); 305 296 } else 306 297 throw new IllegalArgumentException("MapMode action must be subclass of MapMode"); 298 addHideContextMenu(b); 299 b.applyButtonHiddenPreferences(); 307 300 } 308 301 … … 363 356 toolBarActions.setAlignmentX(0.5f); 364 357 jb.add(toolBarActions); 365 358 listAllMapModesButton.setAlignmentX(0.5f); 359 listAllMapModesButton.setBorder(null); 360 listAllMapModesButton.setFont(listAllMapModesButton.getFont().deriveFont(Font.PLAIN)); 361 jb.add(listAllMapModesButton); 362 366 363 if(Main.pref.getBoolean("sidetoolbar.togglevisible", true)) { 367 364 jb.addSeparator(new Dimension(0,18)); 368 365 toolBarToggle.setAlignmentX(0.5f); 369 366 jb.add(toolBarToggle); 370 otherButton.setAlignmentX(0.5f);371 otherButton.setBorder(null);372 otherButton.setFont(otherButton.getFont().deriveFont(Font.PLAIN));373 jb.add( otherButton);367 listAllToggleDialogsButton.setAlignmentX(0.5f); 368 listAllToggleDialogsButton.setBorder(null); 369 listAllToggleDialogsButton.setFont(listAllToggleDialogsButton.getFont().deriveFont(Font.PLAIN)); 370 jb.add(listAllToggleDialogsButton); 374 371 } 375 372 … … 393 390 } 394 391 395 class OtherButtonsAction extends AbstractAction { 396 397 public OtherButtonsAction() { 392 private void addHideContextMenu(final IconToggleButton b) { 393 //context menu 394 b.addMouseListener(new PopupMenuLauncher(new JPopupMenu() { 395 { 396 add(new AbstractAction() { 397 { 398 putValue(NAME, tr("Hide this button")); 399 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again.")); 400 } 401 @Override 402 public void actionPerformed(ActionEvent e) { 403 b.setButtonHidden(true); 404 validateToolBarsVisibility(); 405 } 406 }); 407 } 408 })); 409 } 410 411 class ListAllButtonsAction extends AbstractAction { 412 413 private JButton button; 414 private Collection<? extends HideableButton> buttons; 415 416 417 public ListAllButtonsAction(Collection<? extends HideableButton> buttons) { 418 this.buttons = buttons; 398 419 putValue(NAME, ">>"); 420 } 421 422 public void setButton(JButton button) { 423 this.button = button; 399 424 } 400 425 … … 402 427 public void actionPerformed(ActionEvent e) { 403 428 JPopupMenu menu = new JPopupMenu(); 404 for (final ToggleDialog t : allDialogs) { 429 for (HideableButton b : buttons) { 430 final HideableButton t = b; 405 431 menu.add(new JCheckBoxMenuItem(new AbstractAction() { 406 432 { 407 putValue(NAME, t.get ToggleAction().getValue(NAME));408 putValue(SMALL_ICON, t.get ToggleAction().getValue(SMALL_ICON));409 putValue(SELECTED_KEY, !t.isButtonHidden());433 putValue(NAME, t.getActionName()); 434 putValue(SMALL_ICON, t.getIcon()); 435 putValue(SELECTED_KEY, t.isButtonVisible()); 410 436 putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button")); 411 437 } 412 438 @Override 413 439 public void actionPerformed(ActionEvent e) { 414 if ((Boolean) getValue(SELECTED_KEY)) { 415 t.showButton(); 416 validateToolBarToggle(); 417 } else { 418 t.hideButton(); 419 validateToolBarToggle(); 420 } 440 if ((Boolean) getValue(SELECTED_KEY)) t.showButton(); else t.hideButton(); 441 validateToolBarsVisibility(); 421 442 } 422 443 })); 423 444 } 424 Rectangle bounds = otherButton.getBounds(); 425 menu.show(otherButton, bounds.x+bounds.width, 0); 426 } 445 Rectangle bounds = button.getBounds(); 446 menu.show(button, bounds.x + bounds.width, 0); 447 } 448 } 449 450 public void validateToolBarsVisibility() { 451 for (IconToggleButton b : allDialogButtons) { 452 b.applyButtonHiddenPreferences(); 453 } 454 toolBarToggle.repaint(); 455 for (IconToggleButton b : allMapModeButtons) { 456 b.applyButtonHiddenPreferences(); 457 } 458 toolBarActions.repaint(); 427 459 } 428 460 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r4590 r4609 13 13 import java.awt.GridLayout; 14 14 import java.awt.Image; 15 import java.awt.Point;16 15 import java.awt.Rectangle; 17 16 import java.awt.Toolkit; … … 47 46 import org.openstreetmap.josm.gui.help.HelpUtil; 48 47 import org.openstreetmap.josm.gui.help.Helpful; 48 import org.openstreetmap.josm.gui.ShowHideButtonListener; 49 49 import org.openstreetmap.josm.gui.util.RedirectInputMap; 50 50 import org.openstreetmap.josm.gui.SideButton; … … 57 57 * 58 58 */ 59 public class ToggleDialog extends JPanel implements Helpful, AWTEventListener {59 public class ToggleDialog extends JPanel implements ShowHideButtonListener, Helpful, AWTEventListener { 60 60 61 61 /** The action to toggle this dialog */ … … 94 94 95 95 protected JToggleButton button; 96 protected boolean buttonHidden;97 96 private JPanel buttonsPanel; 98 97 … … 143 142 isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true); 144 143 isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); 145 146 buttonHidden = Main.pref.getBoolean(preferencePrefix+".button_hidden", false);147 144 148 145 RedirectInputMap.redirectToMainContentPane(this); … … 225 222 dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, this); 226 223 } else if (!isDialogShowing()) { 227 if (isButtonHidden()) {228 showButtonImpl();229 }224 // if (isButtonHidden()) { 225 // showButtonImpl(); 226 // } 230 227 showDialog(); 231 228 if (isDocked && isCollapsed) { … … 239 236 } 240 237 241 public void hideButton() { 242 if (!button.isVisible()) 243 throw new AssertionError(); 238 @Override 239 public void buttonHidden() { 244 240 if ((Boolean) toggleAction.getValue("selected")) { 245 241 toggleAction.actionPerformed(null); 246 242 } 247 button.setVisible(false); 248 setButtonHidden(true); 249 } 250 251 public void showButton() { 252 showButtonImpl(); 243 } 244 245 public void buttonShown() { 253 246 unfurlDialog(); 254 247 } 255 248 256 protected void showButtonImpl() {257 if (button.isVisible())258 throw new AssertionError();259 button.setVisible(true);260 setButtonHidden(false);261 }262 249 263 250 /** … … 623 610 } 624 611 625 public boolean isButtonHidden() {626 return buttonHidden;627 }628 629 protected void setButtonHidden(boolean buttonHidden) {630 this.buttonHidden = buttonHidden;631 Main.pref.put(preferencePrefix+".button_hidden", buttonHidden);632 }633 634 635 612 public void setButton(JToggleButton button) { 636 613 this.button = button; 637 button.setVisible(!buttonHidden);638 614 } 639 615 … … 641 617 return button; 642 618 } 643 619 644 620 /*** 645 621 * The following methods are intended to be overridden, in order to customize
Note:
See TracChangeset
for help on using the changeset viewer.