Ticket #6953: toolbarMapModeShowHide.patch
File toolbarMapModeShowHide.patch, 5.7 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/gui/IconToggleButton.java
6 6 import java.beans.PropertyChangeEvent; 7 7 import java.beans.PropertyChangeListener; 8 8 9 import javax.swing.AbstractAction; 9 10 import javax.swing.Action; 10 11 import javax.swing.JToggleButton; 11 12 13 import org.openstreetmap.josm.Main; 12 14 import org.openstreetmap.josm.tools.Destroyable; 13 15 14 16 /** … … 58 60 } 59 61 action.removePropertyChangeListener(this); 60 62 } 63 64 public void checkButtonHiddenPreferences() { 65 String actionName = (String) getAction().getValue(AbstractAction.NAME); 66 boolean hiddenFlag = 67 Main.pref.getBoolean(actionName + ".itbutton_hidden", false); 68 setVisible(!hiddenFlag); 69 } 70 71 public void setButtonHidden(boolean b) { 72 String actionName = (String) getAction().getValue(AbstractAction.NAME); 73 setVisible(!b); 74 Main.pref.put(actionName + ".itbutton_hidden", b); 75 } 61 76 } -
src/org/openstreetmap/josm/gui/MapFrame.java
13 13 import java.awt.event.MouseWheelEvent; 14 14 import java.awt.event.MouseWheelListener; 15 15 import java.util.ArrayList; 16 import java.util.Enumeration; 16 17 import java.util.HashMap; 17 18 import java.util.List; 18 19 import java.util.Map; … … 108 109 public final ButtonGroup toolGroup = new ButtonGroup(); 109 110 110 111 public final JButton otherButton = new JButton(new OtherButtonsAction()); 112 public final JButton listAllMapModesButton = new JButton(new ListAllMapModesAction()); 111 113 112 114 /** 113 115 * Default width of the toggle dialog area. … … 304 306 mapModes.add((MapMode) b.getAction()); 305 307 } else 306 308 throw new IllegalArgumentException("MapMode action must be subclass of MapMode"); 309 final IconToggleButton bb = b; // ee do not want to change signature of the method 310 //context menu 311 b.addMouseListener(new PopupMenuLauncher(new JPopupMenu() { 312 { 313 add(new AbstractAction() { 314 { 315 putValue(NAME, tr("Hide this button")); 316 putValue(SHORT_DESCRIPTION, tr("Click the arrow at the bottom to show it again.")); 317 } 318 @Override 319 public void actionPerformed(ActionEvent e) { 320 bb.setButtonHidden(true); 321 validateToolBarVisibility(); 322 } 323 }); 324 } 325 })); 326 b.checkButtonHiddenPreferences(); 307 327 } 308 328 309 329 /** … … 362 382 jb.setFloatable(false); 363 383 toolBarActions.setAlignmentX(0.5f); 364 384 jb.add(toolBarActions); 365 385 listAllMapModesButton.setAlignmentX(0.5f); 386 listAllMapModesButton.setBorder(null); 387 listAllMapModesButton.setFont(otherButton.getFont().deriveFont(Font.PLAIN)); 388 jb.add(listAllMapModesButton); 389 366 390 if(Main.pref.getBoolean("sidetoolbar.togglevisible", true)) { 367 391 jb.addSeparator(new Dimension(0,18)); 368 392 toolBarToggle.setAlignmentX(0.5f); … … 425 449 menu.show(otherButton, bounds.x+bounds.width, 0); 426 450 } 427 451 } 452 453 class ListAllMapModesAction extends AbstractAction { 428 454 455 public ListAllMapModesAction() { 456 putValue(NAME, ">>"); 457 } 458 459 @Override 460 public void actionPerformed(ActionEvent e) { 461 JPopupMenu menu = new JPopupMenu(); 462 AbstractButton b; 463 Enumeration<AbstractButton> elements = toolGroup.getElements(); 464 while (elements.hasMoreElements()) { 465 b = elements.nextElement(); 466 if (!(b instanceof IconToggleButton)) continue; 467 final IconToggleButton t = (IconToggleButton) b; 468 menu.add(new JCheckBoxMenuItem(new AbstractAction() { 469 470 { 471 putValue(NAME, t.getAction().getValue(NAME)); 472 putValue(SMALL_ICON, t.getAction().getValue(SMALL_ICON)); 473 putValue(SELECTED_KEY, t.isVisible()); 474 putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button")); 475 } 476 477 @Override 478 public void actionPerformed(ActionEvent e) { 479 if ((Boolean) getValue(SELECTED_KEY)) { 480 t.setButtonHidden(false); 481 } else { 482 t.setButtonHidden(true); 483 } 484 validateToolBarVisibility(); 485 } 486 })); 487 } 488 Rectangle bounds = listAllMapModesButton.getBounds(); 489 menu.show(listAllMapModesButton, bounds.x + bounds.width, 0); 490 } 491 } 492 493 public void validateToolBarVisibility() { 494 AbstractButton b; 495 Enumeration<AbstractButton> elements = toolGroup.getElements(); 496 while (elements.hasMoreElements()) { 497 b = elements.nextElement(); 498 if (!(b instanceof IconToggleButton)) continue; 499 ((IconToggleButton) b).checkButtonHiddenPreferences(); 500 } 501 toolBarActions.repaint(); 502 } 503 504 429 505 /** 430 506 * Replies the instance of a toggle dialog of type <code>type</code> managed by this 431 507 * map frame