Changeset 6752 in josm for trunk/src/org
- Timestamp:
- 2014-01-24T01:30:06+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r6727 r6752 32 32 import javax.swing.AbstractAction; 33 33 import javax.swing.BorderFactory; 34 import javax.swing.ButtonGroup; 34 35 import javax.swing.JButton; 35 36 import javax.swing.JCheckBoxMenuItem; … … 48 49 import org.openstreetmap.josm.Main; 49 50 import org.openstreetmap.josm.actions.JosmAction; 51 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 52 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 53 import org.openstreetmap.josm.data.preferences.BooleanProperty; 50 54 import org.openstreetmap.josm.data.preferences.ParametrizedEnumProperty; 51 55 import org.openstreetmap.josm.gui.MainMenu; … … 71 75 * 72 76 */ 73 public class ToggleDialog extends JPanel implements ShowHideButtonListener, Helpful, AWTEventListener, Destroyable {77 public class ToggleDialog extends JPanel implements ShowHideButtonListener, Helpful, AWTEventListener, Destroyable, PreferenceChangedListener { 74 78 75 79 /** … … 84 88 DYNAMIC 85 89 } 90 91 /** 92 * Property to enable dyanmic buttons globally. 93 * @since 6752 94 */ 95 public static final BooleanProperty PROP_DYNAMIC_BUTTONS = new BooleanProperty("dialog.dynamic.buttons", false); 86 96 87 97 private final ParametrizedEnumProperty<ButtonHidingType> PROP_BUTTON_HIDING = new ParametrizedEnumProperty<ToggleDialog.ButtonHidingType>( 88 ButtonHidingType.class, ButtonHidingType. ALWAYS_SHOWN) {98 ButtonHidingType.class, ButtonHidingType.DYNAMIC) { 89 99 @Override 90 100 protected String getKey(String... params) { … … 137 147 private int preferredHeight; 138 148 139 /** the label in the title bar which shows whether the toggle dialog is expanded or collapsed */140 private JLabel lblMinimized;141 142 /** the label in the title bar which shows whether buttons are dynamic or not */143 private JButton buttonsHide = null;144 145 149 /** the JDialog displaying the toggle dialog as undocked dialog */ 146 150 protected JDialog detachedDialog; … … 172 176 this(name, iconName, tooltip, shortcut, preferredHeight, false); 173 177 } 178 174 179 /** 175 180 * Constructor … … 185 190 this(name, iconName, tooltip, shortcut, preferredHeight, defShow, null); 186 191 } 192 187 193 /** 188 194 * Constructor … … 223 229 224 230 Main.redirectToMainContentPane(this); 231 Main.pref.addPreferenceChangeListener(this); 225 232 226 233 windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu, … … 370 377 setMaximumSize(new Dimension(Integer.MAX_VALUE,20)); 371 378 setMinimumSize(new Dimension(Integer.MAX_VALUE,20)); 372 lblMinimized.setIcon(ImageProvider.get("misc", "minimized"));379 titleBar.lblMinimized.setIcon(ImageProvider.get("misc", "minimized")); 373 380 } 374 381 else throw new IllegalStateException(); … … 384 391 setPreferredSize(new Dimension(0,preferredHeight)); 385 392 setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 386 lblMinimized.setIcon(ImageProvider.get("misc", "normal"));393 titleBar.lblMinimized.setIcon(ImageProvider.get("misc", "normal")); 387 394 } 388 395 else throw new IllegalStateException(); … … 409 416 Main.main.menu.windowMenu.remove(windowMenuItem); 410 417 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 418 Main.pref.removePreferenceChangeListener(this); 411 419 destroyComponents(this, false); 412 420 } … … 457 465 */ 458 466 protected class TitleBar extends JPanel { 459 final private JLabel lblTitle; 460 final private JComponent lblTitle_weak; 467 /** the label which shows whether the toggle dialog is expanded or collapsed */ 468 private final JLabel lblMinimized; 469 /** the label which displays the dialog's title **/ 470 private final JLabel lblTitle; 471 private final JComponent lblTitle_weak; 472 private final DialogPopupMenu popupMenu = new DialogPopupMenu(); 473 /** the button which shows whether buttons are dynamic or not */ 474 private final JButton buttonsHide; 461 475 462 476 public TitleBar(String toggleDialogName, String iconName) { … … 486 500 add(lblTitle_weak, GBC.std().fill(GBC.HORIZONTAL)); 487 501 488 if(Main.pref.getBoolean("dialog.dynamic.buttons", true)) {489 buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow"));490 buttonsHide.setToolTipText(tr("Toggle dynamic buttons"));491 buttonsHide.setBorder(BorderFactory.createEmptyBorder());492 buttonsHide.addActionListener(493 new ActionListener(){494 @Override495 public void actionPerformed(ActionEvent e) {496 setIsButtonHiding(buttonHiding == ButtonHidingType.ALWAYS_SHOWN?ButtonHidingType.DYNAMIC:ButtonHidingType.ALWAYS_SHOWN);497 }502 buttonsHide = new JButton(ImageProvider.get("misc", buttonHiding != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow")); 503 buttonsHide.setToolTipText(tr("Toggle dynamic buttons")); 504 buttonsHide.setBorder(BorderFactory.createEmptyBorder()); 505 buttonsHide.addActionListener( 506 new ActionListener() { 507 @Override 508 public void actionPerformed(ActionEvent e) { 509 JRadioButtonMenuItem item = (buttonHiding == ButtonHidingType.DYNAMIC) ? popupMenu.alwaysShown : popupMenu.dynamic; 510 item.setSelected(true); 511 item.getAction().actionPerformed(null); 498 512 } 499 );500 add(buttonsHide);501 }513 } 514 ); 515 add(buttonsHide); 502 516 503 517 // show the pref button if applicable … … 568 582 569 583 public class DialogPopupMenu extends JPopupMenu { 570 public final JMenu buttonHidingMenu = new JMenu(tr("Side buttons")); 571 public final JRadioButtonMenuItem alwaysShown = new JRadioButtonMenuItem(new AbstractAction(tr("Always shown")) { 584 private final ButtonGroup buttonHidingGroup = new ButtonGroup(); 585 private final JMenu buttonHidingMenu = new JMenu(tr("Side buttons")); 586 587 public final JRadioButtonMenuItem alwaysShown = new JRadioButtonMenuItem(new AbstractAction(tr("Always shown")) { 572 588 @Override public void actionPerformed(ActionEvent e) { 573 589 setIsButtonHiding(ButtonHidingType.ALWAYS_SHOWN); 574 590 } 575 591 }); 576 public final JRadioButtonMenuItem dynamic = new JRadioButtonMenuItem(new AbstractAction(tr("Dynamic")) { 592 593 public final JRadioButtonMenuItem dynamic = new JRadioButtonMenuItem(new AbstractAction(tr("Dynamic")) { 577 594 @Override public void actionPerformed(ActionEvent e) { 578 595 setIsButtonHiding(ButtonHidingType.DYNAMIC); 579 596 } 580 597 }); 598 581 599 public final JRadioButtonMenuItem alwaysHidden = new JRadioButtonMenuItem(new AbstractAction(tr("Always hidden")) { 582 600 @Override public void actionPerformed(ActionEvent e) { … … 584 602 } 585 603 }); 604 586 605 public DialogPopupMenu() { 587 606 alwaysShown.setSelected(buttonHiding == ButtonHidingType.ALWAYS_SHOWN); 588 607 dynamic.setSelected(buttonHiding == ButtonHidingType.DYNAMIC); 589 608 alwaysHidden.setSelected(buttonHiding == ButtonHidingType.ALWAYS_HIDDEN); 590 buttonHidingMenu.add(alwaysShown); 591 buttonHidingMenu.add(dynamic); 592 buttonHidingMenu.add(alwaysHidden); 609 for (JRadioButtonMenuItem rb : new JRadioButtonMenuItem[]{alwaysShown, dynamic, alwaysHidden}) { 610 buttonHidingGroup.add(rb); 611 buttonHidingMenu.add(rb); 612 } 593 613 add(buttonHidingMenu); 594 614 for (javax.swing.Action action: buttonActions) { … … 598 618 } 599 619 600 public void registerMouseListener() {620 public final void registerMouseListener() { 601 621 addMouseListener(new MouseEventHandler()); 602 622 } … … 604 624 class MouseEventHandler extends PopupMenuLauncher { 605 625 public MouseEventHandler() { 606 super( new DialogPopupMenu());626 super(popupMenu); 607 627 } 608 628 @Override public void mouseClicked(MouseEvent e) { … … 624 644 * 625 645 */ 626 private class DetachedDialog extends JDialog {646 private class DetachedDialog extends JDialog { 627 647 public DetachedDialog() { 628 648 super(JOptionPane.getFrameForComponent(Main.parent)); … … 706 726 707 727 /** 708 * Sets the title 728 * Sets the title. 729 * @param title The dialog's title 709 730 */ 710 731 public void setTitle(String title) { … … 722 743 723 744 protected void setIsDocked(boolean val) { 724 if (buttonsPanel != null && buttonsHide!= null) {725 buttonsPanel.setVisible(val ? buttonHiding == ButtonHidingType.ALWAYS_SHOWN : true);745 if (buttonsPanel != null) { 746 buttonsPanel.setVisible(val ? buttonHiding != ButtonHidingType.ALWAYS_HIDDEN : true); 726 747 } 727 748 isDocked = val; … … 739 760 buttonHiding = val; 740 761 PROP_BUTTON_HIDING.put(val); 741 if (buttonsHide != null) { 742 buttonsHide.setIcon(ImageProvider.get("misc", val != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow")); 743 } 744 if (buttonsPanel != null) { 745 buttonsPanel.setVisible(val != ButtonHidingType.ALWAYS_HIDDEN); 746 } 747 stateChanged(); 748 } 749 762 refreshHidingButtons(); 763 } 764 750 765 public int getPreferredHeight() { 751 766 return preferredHeight; … … 864 879 } 865 880 add(buttonsPanel, BorderLayout.SOUTH); 866 if (Main.pref.getBoolean("dialog.dynamic.buttons", true)) { 867 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK); 868 buttonsPanel.setVisible(buttonHiding == ButtonHidingType.ALWAYS_SHOWN || !isDocked); 869 } else if (buttonHiding == ButtonHidingType.ALWAYS_HIDDEN) { 870 buttonsPanel.setVisible(false); 871 } 872 } else if (buttonsHide != null) { 873 buttonsHide.setVisible(false); 881 dynamicButtonsPropertyChanged(); 882 } else { 883 titleBar.buttonsHide.setVisible(false); 874 884 } 875 885 … … 894 904 } 895 905 } 906 907 @Override 908 public void preferenceChanged(PreferenceChangeEvent e) { 909 if (e.getKey().equals(PROP_DYNAMIC_BUTTONS.getKey())) { 910 dynamicButtonsPropertyChanged(); 911 } 912 } 913 914 private void dynamicButtonsPropertyChanged() { 915 boolean propEnabled = PROP_DYNAMIC_BUTTONS.get(); 916 if (propEnabled) { 917 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_MOTION_EVENT_MASK); 918 } else { 919 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 920 } 921 titleBar.buttonsHide.setVisible(propEnabled); 922 refreshHidingButtons(); 923 } 924 925 private void refreshHidingButtons() { 926 titleBar.buttonsHide.setIcon(ImageProvider.get("misc", buttonHiding != ButtonHidingType.ALWAYS_SHOWN ? "buttonhide" : "buttonshow")); 927 titleBar.buttonsHide.setEnabled(buttonHiding != ButtonHidingType.ALWAYS_HIDDEN); 928 if (buttonsPanel != null) { 929 buttonsPanel.setVisible(buttonHiding != ButtonHidingType.ALWAYS_HIDDEN || !isDocked); 930 } 931 stateChanged(); 932 } 896 933 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r6746 r6752 53 53 import org.openstreetmap.josm.actions.relation.DownloadMembersAction; 54 54 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction; 55 import org.openstreetmap.josm.actions.relation.EditRelationAction;56 55 import org.openstreetmap.josm.actions.relation.SelectInRelationListAction; 57 56 import org.openstreetmap.josm.actions.relation.SelectMembersAction; … … 63 62 import org.openstreetmap.josm.command.Command; 64 63 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 65 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;66 64 import org.openstreetmap.josm.data.SelectionChangedListener; 67 65 import org.openstreetmap.josm.data.osm.IRelation; … … 118 116 * @author imi 119 117 */ 120 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener , PreferenceChangedListener{118 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener { 121 119 122 120 /** … … 1253 1251 @Override 1254 1252 public void preferenceChanged(PreferenceChangeEvent e) { 1253 super.preferenceChanged(e); 1255 1254 if ("display.discardable-keys".equals(e.getKey()) && Main.main.getCurrentDataSet() != null) { 1256 1255 // Re-load data when display preference change -
trunk/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java
r6529 r6752 21 21 import org.openstreetmap.josm.Main; 22 22 import org.openstreetmap.josm.actions.ExpertToggleAction; 23 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 23 24 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 24 25 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; … … 110 111 111 112 dynamicButtons.setToolTipText(tr("Display buttons in right side menus only when mouse is inside the element")); 112 dynamicButtons.setSelected( Main.pref.getBoolean("dialog.dynamic.buttons", true));113 dynamicButtons.setSelected(ToggleDialog.PROP_DYNAMIC_BUTTONS.get()); 113 114 panel.add(dynamicButtons, GBC.eop().insets(20, 0, 0, 0)); 114 115 … … 131 132 Main.pref.put("osm-primitives.localize-name", showLocalizedName.isSelected()); 132 133 Main.pref.put("modeless", modeless.isSelected()); 133 Main.pref.put( "dialog.dynamic.buttons", dynamicButtons.isSelected());134 Main.pref.put(ToggleDialog.PROP_DYNAMIC_BUTTONS.getKey(), dynamicButtons.isSelected()); 134 135 mod |= Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName()); 135 136 return mod;
Note:
See TracChangeset
for help on using the changeset viewer.