Changeset 6727 in josm
- Timestamp:
- 2014-01-18T15:10:13+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r6643 r6727 73 73 public class ToggleDialog extends JPanel implements ShowHideButtonListener, Helpful, AWTEventListener, Destroyable { 74 74 75 public enum ButtonHiddingType { 76 ALWAYS_SHOWN, ALWAYS_HIDDEN, DYNAMIC 77 } 78 79 private final ParametrizedEnumProperty<ButtonHiddingType> PROP_BUTTON_HIDING = new ParametrizedEnumProperty<ToggleDialog.ButtonHiddingType>(ButtonHiddingType.class, ButtonHiddingType.DYNAMIC) { 75 /** 76 * The button-hiding strategy in toggler dialogs. 77 */ 78 public enum ButtonHidingType { 79 /** Buttons are always shown (default) **/ 80 ALWAYS_SHOWN, 81 /** Buttons are always hidden **/ 82 ALWAYS_HIDDEN, 83 /** Buttons are dynamically hidden, i.e. only shown when mouse cursor is in dialog */ 84 DYNAMIC 85 } 86 87 private final ParametrizedEnumProperty<ButtonHidingType> PROP_BUTTON_HIDING = new ParametrizedEnumProperty<ToggleDialog.ButtonHidingType>( 88 ButtonHidingType.class, ButtonHidingType.ALWAYS_SHOWN) { 80 89 @Override 81 90 protected String getKey(String... params) { … … 83 92 } 84 93 @Override 85 protected ButtonHid dingType parse(String s) {94 protected ButtonHidingType parse(String s) { 86 95 try { 87 96 return super.parse(s); 88 97 } catch (IllegalArgumentException e) { 89 98 // Legacy settings 90 return Boolean.parseBoolean(s)?ButtonHid dingType.DYNAMIC:ButtonHiddingType.ALWAYS_SHOWN;99 return Boolean.parseBoolean(s)?ButtonHidingType.DYNAMIC:ButtonHidingType.ALWAYS_SHOWN; 91 100 } 92 101 } … … 107 116 */ 108 117 protected boolean isShowing; 118 109 119 /** 110 120 * If isShowing is true, indicates whether the dialog is docked or not, e. g. … … 112 122 */ 113 123 protected boolean isDocked; 124 114 125 /** 115 126 * If isShowing and isDocked are true, indicates whether the dialog is … … 117 128 */ 118 129 protected boolean isCollapsed; 130 119 131 /** 120 132 * Indicates whether dynamic button hiding is active or not. 121 133 */ 122 protected ButtonHid dingType buttonHiding;134 protected ButtonHidingType buttonHiding; 123 135 124 136 /** the preferred height if the toggle dialog is expanded */ … … 385 397 Component[] comps = getComponents(); 386 398 for (Component comp : comps) { 387 if (comp != titleBar && (!visible || comp != buttonsPanel || buttonHiding != ButtonHid dingType.ALWAYS_HIDDEN)) {399 if (comp != titleBar && (!visible || comp != buttonsPanel || buttonHiding != ButtonHidingType.ALWAYS_HIDDEN)) { 388 400 comp.setVisible(visible); 389 401 } … … 475 487 476 488 if(Main.pref.getBoolean("dialog.dynamic.buttons", true)) { 477 buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHid dingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow"));489 buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow")); 478 490 buttonsHide.setToolTipText(tr("Toggle dynamic buttons")); 479 491 buttonsHide.setBorder(BorderFactory.createEmptyBorder()); … … 482 494 @Override 483 495 public void actionPerformed(ActionEvent e) { 484 setIsButtonHiding(buttonHiding == ButtonHid dingType.ALWAYS_SHOWN?ButtonHiddingType.DYNAMIC:ButtonHiddingType.ALWAYS_SHOWN);496 setIsButtonHiding(buttonHiding == ButtonHidingType.ALWAYS_SHOWN?ButtonHidingType.DYNAMIC:ButtonHidingType.ALWAYS_SHOWN); 485 497 } 486 498 } … … 559 571 public final JRadioButtonMenuItem alwaysShown = new JRadioButtonMenuItem(new AbstractAction(tr("Always shown")) { 560 572 @Override public void actionPerformed(ActionEvent e) { 561 setIsButtonHiding(ButtonHid dingType.ALWAYS_SHOWN);573 setIsButtonHiding(ButtonHidingType.ALWAYS_SHOWN); 562 574 } 563 575 }); 564 576 public final JRadioButtonMenuItem dynamic = new JRadioButtonMenuItem(new AbstractAction(tr("Dynamic")) { 565 577 @Override public void actionPerformed(ActionEvent e) { 566 setIsButtonHiding(ButtonHid dingType.DYNAMIC);578 setIsButtonHiding(ButtonHidingType.DYNAMIC); 567 579 } 568 580 }); 569 581 public final JRadioButtonMenuItem alwaysHidden = new JRadioButtonMenuItem(new AbstractAction(tr("Always hidden")) { 570 582 @Override public void actionPerformed(ActionEvent e) { 571 setIsButtonHiding(ButtonHid dingType.ALWAYS_HIDDEN);583 setIsButtonHiding(ButtonHidingType.ALWAYS_HIDDEN); 572 584 } 573 585 }); 574 586 public DialogPopupMenu() { 575 alwaysShown.setSelected(buttonHiding == ButtonHid dingType.ALWAYS_SHOWN);576 dynamic.setSelected(buttonHiding == ButtonHid dingType.DYNAMIC);577 alwaysHidden.setSelected(buttonHiding == ButtonHid dingType.ALWAYS_HIDDEN);587 alwaysShown.setSelected(buttonHiding == ButtonHidingType.ALWAYS_SHOWN); 588 dynamic.setSelected(buttonHiding == ButtonHidingType.DYNAMIC); 589 alwaysHidden.setSelected(buttonHiding == ButtonHidingType.ALWAYS_HIDDEN); 578 590 buttonHidingMenu.add(alwaysShown); 579 591 buttonHidingMenu.add(dynamic); … … 711 723 protected void setIsDocked(boolean val) { 712 724 if(buttonsPanel != null && buttonsHide != null) { 713 buttonsPanel.setVisible(val ? buttonHiding == ButtonHid dingType.ALWAYS_SHOWN : true);725 buttonsPanel.setVisible(val ? buttonHiding == ButtonHidingType.ALWAYS_SHOWN : true); 714 726 } 715 727 isDocked = val; … … 724 736 } 725 737 726 protected void setIsButtonHiding(ButtonHid dingType val) {738 protected void setIsButtonHiding(ButtonHidingType val) { 727 739 buttonHiding = val; 728 740 PROP_BUTTON_HIDING.put(val); 729 741 if (buttonsHide != null) { 730 buttonsHide.setIcon(ImageProvider.get("misc", val != ButtonHid dingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow"));742 buttonsHide.setIcon(ImageProvider.get("misc", val != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow")); 731 743 } 732 744 if (buttonsPanel != null) { 733 buttonsPanel.setVisible(val != ButtonHid dingType.ALWAYS_HIDDEN);745 buttonsPanel.setVisible(val != ButtonHidingType.ALWAYS_HIDDEN); 734 746 } 735 747 stateChanged(); … … 854 866 if (Main.pref.getBoolean("dialog.dynamic.buttons", true)) { 855 867 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK); 856 buttonsPanel.setVisible(buttonHiding == ButtonHid dingType.ALWAYS_SHOWN || !isDocked);857 } else if (buttonHiding == ButtonHid dingType.ALWAYS_HIDDEN) {868 buttonsPanel.setVisible(buttonHiding == ButtonHidingType.ALWAYS_SHOWN || !isDocked); 869 } else if (buttonHiding == ButtonHidingType.ALWAYS_HIDDEN) { 858 870 buttonsPanel.setVisible(false); 859 871 } … … 870 882 @Override 871 883 public void eventDispatched(AWTEvent event) { 872 if(isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHid dingType.DYNAMIC) {884 if(isShowing() && !isCollapsed && isDocked && buttonHiding == ButtonHidingType.DYNAMIC) { 873 885 Rectangle b = this.getBounds(); 874 886 b.setLocation(getLocationOnScreen());
Note:
See TracChangeset
for help on using the changeset viewer.