| | 309 | |
| | 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 | String actionName = (String) b.getAction().getValue(AbstractAction.NAME); |
| | 321 | Main.pref.put(actionName+".mbutton_hidden",false); |
| | 322 | validateToolBarVisibility(); |
| | 323 | } |
| | 324 | }); |
| | 325 | } |
| | 326 | })); |
| | 418 | class OtherMapModesAction extends AbstractAction { |
| | 419 | |
| | 420 | public OtherMapModesAction() { |
| | 421 | putValue(NAME, ">>"); |
| | 422 | } |
| | 423 | |
| | 424 | @Override |
| | 425 | public void actionPerformed(ActionEvent e) { |
| | 426 | JPopupMenu menu = new JPopupMenu(); |
| | 427 | AbstractButton b; |
| | 428 | Enumeration<AbstractButton> elements = toolGroup.getElements(); |
| | 429 | while (elements.hasMoreElements()) { |
| | 430 | b = elements.nextElement(); |
| | 431 | if (!(b instanceof IconToggleButton)) continue; |
| | 432 | final IconToggleButton t = (IconToggleButton) b; |
| | 433 | menu.add(new JCheckBoxMenuItem(new AbstractAction() { |
| | 434 | |
| | 435 | { |
| | 436 | putValue(NAME, t.getAction().getValue(NAME)); |
| | 437 | putValue(SMALL_ICON, t.getAction().getValue(SMALL_ICON)); |
| | 438 | putValue(SELECTED_KEY, t.isVisible()); |
| | 439 | putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button")); |
| | 440 | } |
| | 441 | |
| | 442 | @Override |
| | 443 | public void actionPerformed(ActionEvent e) { |
| | 444 | if ((Boolean) getValue(SELECTED_KEY)) { |
| | 445 | Main.pref.put(getValue(NAME) + ".mbutton_hidden", true); |
| | 446 | } else { |
| | 447 | Main.pref.put(getValue(NAME) + ".mbutton_hidden", false); |
| | 448 | } |
| | 449 | validateToolBarVisibility(); |
| | 450 | } |
| | 451 | })); |
| | 452 | } |
| | 453 | Rectangle bounds = otherMapModeButton.getBounds(); |
| | 454 | menu.show(otherMapModeButton, bounds.x + bounds.width, 0); |
| | 455 | } |
| | 456 | } |
| | 457 | |
| | 458 | public void validateToolBarVisibility() { |
| | 459 | AbstractButton b; |
| | 460 | Enumeration<AbstractButton> elements = toolGroup.getElements(); |
| | 461 | while (elements.hasMoreElements()) { |
| | 462 | b = elements.nextElement(); |
| | 463 | if (!(b instanceof IconToggleButton)) continue; |
| | 464 | final IconToggleButton t = (IconToggleButton) b; |
| | 465 | String actionName = (String) t.getAction().getValue(AbstractAction.NAME); |
| | 466 | boolean visibilityFlag = |
| | 467 | Main.pref.getBoolean(actionName + ".mbutton_hidden", true); |
| | 468 | t.setVisible(visibilityFlag); |
| | 469 | } |
| | 470 | toolBarActions.repaint(); |
| | 471 | } |
| | 472 | |