Changeset 2224 in josm
- Timestamp:
- 2009-10-02T22:06:36+02:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r2185 r2224 220 220 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction()); 221 221 mapFrame.setVisible(true); 222 mapFrame. setVisibleDialogs();222 mapFrame.initializeDialogsPane(); 223 223 // bootstrapping problem: make sure the layer list dialog is going to 224 224 // listen to change events of the very first layer … … 243 243 /** 244 244 * Replies the current edit layer 245 * 245 * 246 246 * @return the current edit layer. null, if no current edit layer exists 247 247 */ … … 549 549 newGeometry = width + "x" + height + "+" + x + "+" + y; 550 550 } 551 551 552 552 if (map != null) { 553 553 newToggleDlgWidth = Integer.toString(map.getToggleDlgWidth()); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r2053 r2224 442 442 public final void resetToDefault(){ 443 443 properties.clear(); 444 put("layerlist.visible", true);445 put("propertiesdialog.visible", true);446 put("selectionlist.visible", true);447 put("commandstack.visible", true);448 444 if (System.getProperty("os.name").toUpperCase().indexOf("WINDOWS") == -1) { 449 445 put("laf", "javax.swing.plaf.metal.MetalLookAndFeel"); -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r2162 r2224 8 8 import java.awt.Dimension; 9 9 import java.util.ArrayList; 10 import java.util.List; 10 11 11 12 import javax.swing.AbstractButton; … … 29 30 import org.openstreetmap.josm.gui.dialogs.CommandStackDialog; 30 31 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 32 import org.openstreetmap.josm.gui.dialogs.DialogsPanel; 31 33 import org.openstreetmap.josm.gui.dialogs.FilterDialog; 32 34 import org.openstreetmap.josm.gui.dialogs.HistoryDialog; … … 75 77 * instead of adding directly to this list. 76 78 */ 77 private JPanel toggleDialogs = new JPanel();78 private ArrayList<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>();79 private List<ToggleDialog> allDialogs = new ArrayList<ToggleDialog>(); 80 private DialogsPanel dialogsPanel = new DialogsPanel(); 79 81 80 82 public final ButtonGroup toolGroup = new ButtonGroup(); 81 83 82 84 /** 83 85 * Default width of the toggle dialog area. … … 107 109 108 110 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, 109 mapView, toggleDialogs);111 mapView, dialogsPanel); 110 112 111 113 /** … … 113 115 */ 114 116 splitPane.setResizeWeight(1.0); 115 117 116 118 /** 117 119 * Some beautifications. … … 127 129 } 128 130 }); 129 131 130 132 add(splitPane, BorderLayout.CENTER); 131 133 132 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));133 toggleDialogs.setPreferredSize(new Dimension(Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH), 0));134 135 toggleDialogs.setMinimumSize(new Dimension(24, 0));134 dialogsPanel.setLayout(new BoxLayout(dialogsPanel, BoxLayout.Y_AXIS)); 135 dialogsPanel.setPreferredSize(new Dimension(Main.pref.getInteger("toggleDialogs.width",DEF_TOGGLE_DLG_WIDTH), 0)); 136 137 dialogsPanel.setMinimumSize(new Dimension(24, 0)); 136 138 mapView.setMinimumSize(new Dimension(10,0)); 137 139 … … 173 175 */ 174 176 public void destroy() { 175 for (ToggleDialog t : allDialogs) { 176 t.closeDetachedDialog(); 177 } 177 dialogsPanel.destroy(); 178 178 for (int i = 0; i < toolBarActions.getComponentCount(); ++i) 179 179 if (toolBarActions.getComponent(i) instanceof Destroyable) { … … 203 203 * Open all ToggleDialogs that have their preferences property set. Close all others. 204 204 */ 205 public void setVisibleDialogs() { 206 toggleDialogs.removeAll(); 207 for (ToggleDialog dialog: allDialogs) { 208 dialog.setVisible(false); 209 toggleDialogs.add(dialog); 210 dialog.setParent(toggleDialogs); 211 if (Main.pref.getBoolean(dialog.getPreferencePrefix()+".visible")) { 212 dialog.showDialog(); 213 } else { 214 dialog.hideDialog(); 215 } 216 } 205 public void initializeDialogsPane() { 206 dialogsPanel.initialize(allDialogs); 217 207 } 218 208 … … 243 233 } 244 234 } 245 246 247 235 248 236 /** … … 299 287 */ 300 288 public <T> T getToggleDialog(Class<T> type) { 301 for (ToggleDialog td : allDialogs) { 302 if (type.isInstance(td)) 303 return type.cast(td); 304 } 305 return null; 289 return dialogsPanel.getToggleDialog(type); 306 290 } 307 291 … … 310 294 */ 311 295 public int getToggleDlgWidth() { 312 return toggleDialogs.getWidth();296 return dialogsPanel.getWidth(); 313 297 } 314 298 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r2005 r2224 29 29 public CommandStackDialog(final MapFrame mapFrame) { 30 30 super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."), 31 Shortcut.registerShortcut("subwindow:commandstack", tr("Toggle: {0}", tr("Command Stack")), KeyEvent.VK_O, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 100 );31 Shortcut.registerShortcut("subwindow:commandstack", tr("Toggle: {0}", tr("Command Stack")), KeyEvent.VK_O, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 100, true); 32 32 Main.main.undoRedo.listenerCommands.add(this); 33 33 -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r2181 r2224 56 56 * change the ordering of the layers, to hide/show layers, to activate layers, 57 57 * and to delete layers. 58 * 58 * 59 59 */ 60 60 public class LayerListDialog extends ToggleDialog { … … 66 66 /** 67 67 * Creates the instance of the dialog. It's connected to the map frame <code>mapFrame</code> 68 * 68 * 69 69 * @param mapFrame the map frame 70 70 */ … … 75 75 /** 76 76 * Replies the instance of the dialog 77 * 77 * 78 78 * @return the instance of the dialog 79 79 * @throws IllegalStateException thrown, if the dialog is not created yet … … 144 144 protected LayerListDialog(MapFrame mapFrame) { 145 145 super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."), 146 Shortcut.registerShortcut("subwindow:layers", tr("Toggle: {0}", tr("Layers")), KeyEvent.VK_L, Shortcut.GROUP_LAYER), 100 );146 Shortcut.registerShortcut("subwindow:layers", tr("Toggle: {0}", tr("Layers")), KeyEvent.VK_L, Shortcut.GROUP_LAYER), 100, true); 147 147 148 148 // create the models … … 194 194 * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()} 195 195 * on every {@see ListSelectionEvent}. 196 * 196 * 197 197 * @param listener the listener 198 198 * @param listSelectionModel the source emitting {@see ListSelectionEvent}s … … 212 212 * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()} 213 213 * on every {@see ListDataEvent}. 214 * 214 * 215 215 * @param listener the listener 216 216 * @param listSelectionModel the source emitting {@see ListDataEvent}s … … 237 237 * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()} 238 238 * on every {@see LayerChangeListener}-event emitted by {@see MapView}. 239 * 239 * 240 240 * @param listener the listener 241 241 */ … … 272 272 /** 273 273 * Creates a {@see DeleteLayerAction} for a specific layer. 274 * 274 * 275 275 * @param layer the layer. Must not be null. 276 276 * @exception IllegalArgumentException thrown, if layer is null … … 288 288 * Creates a {@see DeleteLayerAction} which will delete the currently 289 289 * selected layers in the layer dialog. 290 * 290 * 291 291 */ 292 292 public DeleteLayerAction() { … … 353 353 * Creates a {@see ShowHideLayerAction} which toggle the visibility of 354 354 * a specific layer. 355 * 355 * 356 356 * @param layer the layer. Must not be null. 357 357 * @exception IllegalArgumentException thrown, if layer is null … … 369 369 * Creates a {@see ShowHideLayerAction} which will toggle the visibility of 370 370 * the currently selected layers 371 * 371 * 372 372 */ 373 373 public ShowHideLayerAction() { … … 620 620 * The layer list model. The model manages a list of layers and provides methods for 621 621 * moving layers up and down, for toggling their visibility, and for activating a layer. 622 * 622 * 623 623 * The model is a {@see ListModel} and it provides a {@see ListSelectionModel}. It expectes 624 624 * to be configured with a {@see DefaultListSelectionModel}. The selection model is used 625 625 * to update the selection state of views depending on messages sent to the model. 626 * 626 * 627 627 * The model manages a list of {@see LayerListModelListener} which are mainly notified if 628 628 * the model requires views to make a specific list entry visible. 629 * 629 * 630 630 * It also listens to {@see PropertyChangeEvent}s of every {@see Layer} it manages, in particular to 631 631 * the properties {@see Layer#VISIBLE_PROP} and {@see Layer#NAME_PROP}. … … 639 639 /** 640 640 * constructor 641 * 641 * 642 642 * @param selectionModel the list selection model 643 643 */ … … 649 649 /** 650 650 * Adds a listener to this model 651 * 651 * 652 652 * @param listener the listener 653 653 */ … … 663 663 * removes a listener from this model 664 664 * @param listener the listener 665 * 665 * 666 666 */ 667 667 public void removeLayerListModelListener(LayerListModelListener listener) { … … 675 675 /** 676 676 * Fires a make visible event to listeners 677 * 677 * 678 678 * @param index the index of the row to make visible 679 679 * @param layer the layer at this index … … 688 688 /** 689 689 * Fires a refresh event to listeners of this model 690 * 690 * 691 691 * @see LayerListModelListener#refresh() 692 692 */ … … 700 700 * Populates the model with the current layers managed by 701 701 * {@see MapView}. 702 * 702 * 703 703 */ 704 704 public void populate() { … … 715 715 * Marks <code>layer</code> as selected layer. Ignored, if 716 716 * layer is null. 717 * 717 * 718 718 * @param layer the layer. 719 719 */ … … 732 732 * Replies the list of currently selected layers. Never null, but may 733 733 * be empty. 734 * 734 * 735 735 * @return the list of currently selected layers. Never null, but may 736 736 * be empty. … … 749 749 * Replies a the list of indices of the selected rows. Never null, 750 750 * but may be empty. 751 * 751 * 752 752 * @return the list of indices of the selected rows. Never null, 753 753 * but may be empty. … … 765 765 /** 766 766 * Invoked if a layer managed by {@see MapView} is removed 767 * 767 * 768 768 * @param layer the layer which is removed 769 769 */ … … 783 783 /** 784 784 * Invoked when a layer managed by {@see MapView} is added 785 * 785 * 786 786 * @param layer the layer 787 787 */ … … 797 797 /** 798 798 * Replies the first layer. Null if no layers are present 799 * 799 * 800 800 * @return the first layer. Null if no layers are present 801 801 */ … … 807 807 /** 808 808 * Replies the layer at position <code>index</code> 809 * 809 * 810 810 * @param index the index 811 811 * @return the layer at position <code>index</code>. Null, … … 821 821 * Replies true if the the currently selected layers can move up 822 822 * by one position 823 * 823 * 824 824 * @return true if the the currently selected layers can move up 825 825 * by one position … … 832 832 /** 833 833 * Move up the currently selected layers by one position 834 * 834 * 835 835 */ 836 836 public void moveUp() { … … 854 854 * Replies true if the currently selected layers can move down 855 855 * by one position 856 * 856 * 857 857 * @return true if the currently selected layers can move down 858 858 * by one position … … 865 865 /** 866 866 * Move down the currently selected layers by one position 867 * 867 * 868 868 */ 869 869 public void moveDown() { … … 888 888 * Make sure the first of the selected layers is visible in the 889 889 * views of this model. 890 * 890 * 891 891 */ 892 892 protected void ensureSelectedIsVisible() { … … 901 901 * Replies a list of layers which are possible merge targets 902 902 * for <code>source</code> 903 * 903 * 904 904 * @param source the source layer 905 905 * @return a list of layers which are possible merge targets … … 924 924 * Replies the list of layers currently managed by {@see MapView}. 925 925 * Never null, but can be empty. 926 * 926 * 927 927 * @return the list of layers currently managed by {@see MapView}. 928 928 * Never null, but can be empty. … … 936 936 /** 937 937 * Ensures that at least one layer is selected in the layer dialog 938 * 938 * 939 939 */ 940 940 protected void ensureActiveSelected() { … … 956 956 /** 957 957 * Replies the active layer. null, if no active layer is available 958 * 958 * 959 959 * @return the active layer. null, if no active layer is available 960 960 */ … … 1043 1043 * Creates a {@see ShowHideLayerAction} for <code>layer</code> in the 1044 1044 * context of this {@see LayerListDialog}. 1045 * 1045 * 1046 1046 * @param layer the layer 1047 1047 * @return the action … … 1054 1054 * Creates a {@see DeleteLayerAction} for <code>layer</code> in the 1055 1055 * context of this {@see LayerListDialog}. 1056 * 1056 * 1057 1057 * @param layer the layer 1058 1058 * @return the action … … 1065 1065 * Creates a {@see ActivateLayerAction} for <code>layer</code> in the 1066 1066 * context of this {@see LayerListDialog}. 1067 * 1067 * 1068 1068 * @param layer the layer 1069 1069 * @return the action … … 1076 1076 * Creates a {@see MergeLayerAction} for <code>layer</code> in the 1077 1077 * context of this {@see LayerListDialog}. 1078 * 1078 * 1079 1079 * @param layer the layer 1080 1080 * @return the action -
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r2218 r2224 453 453 super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), 454 454 Shortcut.registerShortcut("subwindow:properties", tr("Toggle: {0}", tr("Properties/Memberships")), KeyEvent.VK_P, 455 Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150 );455 Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150, true); 456 456 457 457 // setting up the properties table -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r2005 r2224 85 85 public SelectionListDialog() { 86 86 super(tr("Current Selection"), "selectionlist", tr("Open a selection list window."), 87 Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150 );87 Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150, true); 88 88 89 89 selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r2185 r2224 34 34 import org.openstreetmap.josm.actions.JosmAction; 35 35 import org.openstreetmap.josm.actions.HelpAction.Helpful; 36 import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action; 36 37 import org.openstreetmap.josm.tools.GBC; 37 38 import org.openstreetmap.josm.tools.ImageProvider; … … 40 41 /** 41 42 * This class is a toggle dialog that can be turned on and off. 42 * 43 * 43 44 * 44 45 */ 45 46 public class ToggleDialog extends JPanel implements Helpful { 46 // private static final Logger logger = Logger.getLogger(ToggleDialog.class.getName()); 47 48 /** 49 * The action to toggle the visibility state of this toggle dialog. 50 * 51 * Emits {@see PropertyChangeEvent}s for the property <tt>selected</tt>: 52 * <ul> 53 * <li>true, if the dialog is currently visible</li> 54 * <li>false, if the dialog is currently invisible</li> 55 * </ul> 56 * 57 */ 58 public final class ToggleDialogAction extends JosmAction { 59 private ToggleDialogAction(String name, String iconName, String tooltip, Shortcut shortcut, String prefname) { 60 super(name, iconName, tooltip, shortcut, false); 61 } 62 63 public void actionPerformed(ActionEvent e) { 64 toggleVisibility(); 65 } 66 67 public void toggleVisibility() { 68 if (isShowing) { 69 hideDialog(); 70 } else { 71 showDialog(); 72 } 73 } 74 } 75 76 /** 77 * The action to toggle this dialog. 78 */ 47 /** The action to toggle this dialog */ 79 48 private ToggleDialogAction toggleAction; 80 49 private String preferencePrefix; 81 50 82 private JPanel parent; 51 /** DialogsPanel that manages all ToggleDialogs */ 52 private DialogsPanel dialogsPanel; 53 83 54 private TitleBar titleBar; 84 55 private String title; 85 56 86 /** 57 /** 87 58 * Indicates whether the dialog is showing or not. 88 59 */ 89 60 private boolean isShowing; 90 /** 61 /** 91 62 * If isShowing is true, indicates whether the dialog is docked or not, e. g. 92 63 * shown as part of the main window or as a seperate dialog window. 93 64 */ 94 65 private boolean isDocked; 95 /** 96 * If isShowing and isDocked are true, indicates whether the dialog is 66 /** 67 * If isShowing and isDocked are true, indicates whether the dialog is 97 68 * currently minimized or not. 98 69 */ … … 101 72 /** the preferred height if the toggle dialog is expanded */ 102 73 private int preferredHeight; 74 103 75 /** the label in the title bar which shows whether the toggle dialog is expanded or collapsed */ 104 76 private JLabel lblMinimized; 77 105 78 /** the JDialog displaying the toggle dialog as undocked dialog */ 106 79 private JDialog detachedDialog; … … 108 81 /** 109 82 * Constructor 110 * 83 * (see below) 84 */ 85 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight) { 86 this(name, iconName, tooltip, shortcut, preferredHeight, false); 87 } 88 /** 89 * Constructor 90 * 111 91 * @param name the name of the dialog 112 92 * @param iconName the name of the icon to be displayed … … 114 94 * @param shortcut the shortcut 115 95 * @param preferredHeight the preferred height for the dialog 116 */ 117 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight) { 96 * @param defShow if the dialog should be shown by default, if there is no preference 97 */ 98 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow) { 118 99 super(new BorderLayout()); 119 100 this.preferencePrefix = iconName; 120 init(name, iconName, tooltip, shortcut, preferredHeight); 121 } 122 123 /** 124 * Initializes the toggle dialog 125 * 126 * @param name 127 * @param iconName 128 * @param tooltip 129 * @param shortcut 130 * @param preferredHeight 131 */ 132 private void init(String name, String iconName, String tooltip, Shortcut shortcut, final int preferredHeight) { 101 133 102 /** Use the full width of the parent element */ 134 103 setPreferredSize(new Dimension(0, preferredHeight)); … … 147 116 add(titleBar, BorderLayout.NORTH); 148 117 149 setVisible(false);150 118 setBorder(BorderFactory.createEtchedBorder()); 151 119 120 isShowing = Main.pref.getBoolean(preferencePrefix+".visible", defShow); 152 121 isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true); 153 122 isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false); … … 155 124 156 125 /** 126 * The action to toggle the visibility state of this toggle dialog. 127 * 128 * Emits {@see PropertyChangeEvent}s for the property <tt>selected</tt>: 129 * <ul> 130 * <li>true, if the dialog is currently visible</li> 131 * <li>false, if the dialog is currently invisible</li> 132 * </ul> 133 * 134 */ 135 public final class ToggleDialogAction extends JosmAction { 136 private ToggleDialogAction(String name, String iconName, String tooltip, Shortcut shortcut, String prefname) { 137 super(name, iconName, tooltip, shortcut, false); 138 } 139 140 public void actionPerformed(ActionEvent e) { 141 if (isShowing) { 142 hideDialog(); 143 dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null); 144 } else { 145 showDialog(); 146 expand(); 147 dialogsPanel.reconstruct(Action.INVISIBLE_TO_DEFAULT, ToggleDialog.this); 148 } 149 } 150 } 151 152 /** 153 * Shows the dialog 154 */ 155 public void showDialog() { 156 setIsShowing(true); 157 if (!isDocked) { 158 detach(); 159 } else { 160 dock(); 161 this.setVisible(true); 162 } 163 // toggling the selected value in order to enforce PropertyChangeEvents 164 setIsShowing(true); 165 toggleAction.putValue("selected", false); 166 toggleAction.putValue("selected", true); 167 } 168 169 /** 170 * Hides the dialog 171 */ 172 public void hideDialog() { 173 closeDetachedDialog(); 174 this.setVisible(false); 175 setIsShowing(false); 176 toggleAction.putValue("selected", false); 177 } 178 179 /** 180 * Displays the toggle dialog in the toggle dialog view on the right 181 * of the main map window. 182 * 183 */ 184 protected void dock() { 185 detachedDialog = null; 186 titleBar.setVisible(true); 187 setIsDocked(true); 188 } 189 190 /** 191 * Display the dialog in a detached window. 192 * 193 */ 194 protected void detach() { 195 setContentVisible(true); 196 this.setVisible(true); 197 titleBar.setVisible(false); 198 detachedDialog = new DetachedDialog(); 199 detachedDialog.setVisible(true); 200 setIsDocked(false); 201 } 202 203 /** 204 * Collapses the toggle dialog to the title bar only 205 * 206 */ 207 public void collapse() { 208 setContentVisible(false); 209 setIsCollapsed(true); 210 setPreferredSize(new Dimension(0,20)); 211 setMaximumSize(new Dimension(Integer.MAX_VALUE,20)); 212 setMinimumSize(new Dimension(Integer.MAX_VALUE,20)); 213 lblMinimized.setIcon(ImageProvider.get("misc", "minimized")); 214 } 215 216 /** 217 * Expands the toggle dialog 218 */ 219 protected void expand() { 220 setContentVisible(true); 221 setIsCollapsed(false); 222 setPreferredSize(new Dimension(0,preferredHeight)); 223 setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 224 lblMinimized.setIcon(ImageProvider.get("misc", "normal")); 225 } 226 227 /** 157 228 * Sets the visibility of all components in this toggle dialog, except the title bar 158 * 229 * 159 230 * @param visible true, if the components should be visible; false otherwise 160 231 */ … … 169 240 170 241 /** 171 * Toggles between collapsed and expanded state172 *173 */174 protected void toggleExpandedState() {175 if (isCollapsed) {176 expand();177 } else {178 collapse();179 }180 }181 182 /**183 * Collapses the toggle dialog to the title bar only184 *185 */186 protected void collapse() {187 setContentVisible(false);188 isCollapsed = true;189 Main.pref.put(preferencePrefix+".minimized", true);190 setPreferredSize(new Dimension(0,20));191 setMaximumSize(new Dimension(Integer.MAX_VALUE,20));192 lblMinimized.setIcon(ImageProvider.get("misc", "minimized"));193 refreshToggleDialogsView();194 }195 196 /**197 * Expands the toggle dialog198 */199 protected void expand() {200 setContentVisible(true);201 isCollapsed = false;202 Main.pref.put(preferencePrefix+".minimized", false);203 setPreferredSize(new Dimension(0,preferredHeight));204 setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));205 lblMinimized.setIcon(ImageProvider.get("misc", "normal"));206 refreshToggleDialogsView();207 }208 209 /**210 * Replies the index of this toggle dialog in the view of211 * toggle dialog.212 *213 * @return214 */215 protected int getDialogPosition() {216 if (parent == null) return -1;217 for (int i=0; i< parent.getComponentCount(); i++) {218 String name = parent.getComponent(i).getName();219 if (name != null && name.equals(this.getName()))220 return i;221 }222 return -1;223 }224 225 /**226 * Displays the toggle dialog in the toggle dialog view on the right227 * of the main map window.228 *229 */230 protected void dock() {231 detachedDialog = null;232 if (parent == null) return;233 234 // check whether the toggle dialog view contains a placeholder235 // for this toggle dialog. If so, replace it with this dialog.236 //237 int idx = getDialogPosition();238 if (idx > -1) {239 parent.remove(idx);240 if (idx >= parent.getComponentCount()) {241 parent.add(ToggleDialog.this);242 } else {243 parent.add(ToggleDialog.this,idx);244 }245 } else {246 parent.add(ToggleDialog.this);247 }248 parent.validate();249 250 if(Main.pref.getBoolean(preferencePrefix+".visible")) {251 setVisible(true);252 } else {253 setVisible(false);254 }255 titleBar.setVisible(true);256 isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false);257 if (isCollapsed) {258 collapse();259 } else {260 expand();261 }262 isDocked = true;263 Main.pref.put(preferencePrefix+".docked", isDocked);264 }265 266 /**267 * Display the dialog in a detached window.268 *269 */270 protected void detach() {271 setContentVisible(true);272 setVisible(true);273 // replace the toggle dialog by an invisible place holder. Makes sure274 // we can place the toggle dialog where it was when it becomes docked275 // again.276 //277 if (parent != null) {278 int idx = getDialogPosition();279 if (idx > -1) {280 JPanel placeHolder = new JPanel();281 placeHolder.setName(this.getName());282 placeHolder.setVisible(false);283 parent.add(placeHolder,idx);284 }285 parent.remove(ToggleDialog.this);286 }287 288 289 titleBar.setVisible(false);290 detachedDialog = new DetachedDialog();291 detachedDialog.setVisible(true);292 refreshToggleDialogsView();293 isDocked = false;294 Main.pref.put(preferencePrefix+".docked", isDocked);295 }296 297 /**298 * Hides the dialog299 */300 public void hideDialog() {301 closeDetachedDialog();302 setVisible(false);303 isShowing = false;304 Main.pref.put(preferencePrefix+".visible", false);305 refreshToggleDialogsView();306 toggleAction.putValue("selected", false);307 }308 309 /**310 * Replies true if this dialog is showing either as docked or as detached dialog311 */312 public boolean isDialogShowing() {313 return this.isShowing;314 }315 316 /**317 * Shows the dialog318 */319 public void showDialog() {320 if (!isDocked) {321 detach();322 } else {323 dock();324 if (!isCollapsed) {325 expand();326 setVisible(true);327 refreshToggleDialogsView();328 } else {329 setVisible(true);330 refreshToggleDialogsView();331 }332 }333 isShowing = true;334 // toggling the selected value in order to enforce PropertyChangeEvents335 toggleAction.putValue("selected", false);336 toggleAction.putValue("selected", true);337 Main.pref.put(preferencePrefix+".visible", true);338 }339 340 /**341 * Refreshes the layout of the parent toggle dialog view342 *343 */344 protected void refreshToggleDialogsView() {345 if(parent != null){346 parent.validate();347 }348 }349 350 /**351 242 * Closes the the detached dialog if this toggle dialog is currently displayed 352 243 * in a detached dialog. 353 * 244 * 354 245 */ 355 246 public void closeDetachedDialog() { … … 361 252 } 362 253 363 public String helpTopic() {364 String help = getClass().getName();365 help = help.substring(help.lastIndexOf('.')+1, help.length()-6);366 return "Dialog/"+help;367 }368 369 /**370 * Replies the action to toggle the visible state of this toggle dialog371 *372 * @return the action to toggle the visible state of this toggle dialog373 */374 public AbstractAction getToggleAction() {375 return toggleAction;376 }377 378 /**379 * Replies the prefix for the preference settings of this dialog.380 *381 * @return the prefix for the preference settings of this dialog.382 */383 public String getPreferencePrefix() {384 return preferencePrefix;385 }386 387 /**388 * Sets the parent displaying all toggle dialogs389 *390 * @param parent the parent391 */392 public void setParent(JPanel parent) {393 this.parent = parent;394 }395 396 /**397 * Replies the name of this toggle dialog398 *399 */400 @Override401 public String getName() {402 return "toggleDialog." + preferencePrefix;403 }404 405 /**406 * Sets the title407 *408 * @param title the title409 */410 public void setTitle(String title) {411 titleBar.setTitle(title);412 }413 254 414 255 /** 415 256 * The title bar displayed in docked mode 416 * 257 * 417 258 */ 418 259 private class TitleBar extends JPanel { … … 429 270 lblTitle = new JLabel("",smallIcon, JLabel.TRAILING); 430 271 lblTitle.setIconTextGap(8); 431 272 432 273 JPanel conceal = new JPanel(); 433 274 conceal.add(lblTitle); 434 275 conceal.setVisible(false); 435 276 add(conceal, GBC.std()); 436 277 437 278 // Cannot add the label directly since it would displace other elements on resize 438 279 JComponent lblTitle_weak = new JComponent() { … … 450 291 @Override 451 292 public void mouseClicked(MouseEvent e) { 452 toggleExpandedState(); 293 // toggleExpandedState(); 294 if (isCollapsed) { 295 expand(); 296 dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, ToggleDialog.this); 297 } else { 298 collapse(); 299 dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null); 300 } 453 301 } 454 302 } … … 463 311 public void actionPerformed(ActionEvent e) { 464 312 detach(); 313 dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null); 465 314 } 466 315 } … … 476 325 public void actionPerformed(ActionEvent e) { 477 326 hideDialog(); 327 dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null); 478 328 } 479 329 } … … 495 345 /** 496 346 * The dialog class used to display toggle dialogs in a detached window. 497 * 347 * 498 348 */ 499 349 private class DetachedDialog extends JDialog { … … 507 357 dispose(); 508 358 dock(); 359 expand(); 360 dialogsPanel.reconstruct(Action.INVISIBLE_TO_DEFAULT, ToggleDialog.this); 509 361 } 510 362 }); … … 534 386 return last; 535 387 } 536 388 537 389 /** 538 390 * Default size of the detached dialog. … … 542 394 return new Dimension(Main.map.DEF_TOGGLE_DLG_WIDTH, preferredHeight); 543 395 } 396 397 /** 398 * Replies the action to toggle the visible state of this toggle dialog 399 * 400 * @return the action to toggle the visible state of this toggle dialog 401 */ 402 public AbstractAction getToggleAction() { 403 return toggleAction; 404 } 405 406 /** 407 * Replies the prefix for the preference settings of this dialog. 408 * 409 * @return the prefix for the preference settings of this dialog. 410 */ 411 public String getPreferencePrefix() { 412 return preferencePrefix; 413 } 414 415 /** 416 * Sets the dialogsPanel managing all toggle dialogs 417 */ 418 public void setDialogsPanel(DialogsPanel dialogsPanel) { 419 this.dialogsPanel = dialogsPanel; 420 } 421 422 /** 423 * Replies the name of this toggle dialog 424 */ 425 @Override 426 public String getName() { 427 return "toggleDialog." + preferencePrefix; 428 } 429 430 /** 431 * Sets the title 432 */ 433 public void setTitle(String title) { 434 titleBar.setTitle(title); 435 } 436 437 private void setIsShowing(boolean val) { 438 isShowing = val; 439 Main.pref.put(preferencePrefix+".visible", val); 440 } 441 442 private void setIsDocked(boolean val) { 443 isDocked = val; 444 Main.pref.put(preferencePrefix+".docked", val); 445 } 446 447 private void setIsCollapsed(boolean val) { 448 isCollapsed = val; 449 Main.pref.put(preferencePrefix+".minimized", val); 450 } 451 452 public int getPreferredHeight() { 453 return preferredHeight; 454 } 455 456 /** 457 * Replies true if this dialog is showing either as docked or as detached dialog 458 */ 459 public boolean isDialogShowing() { 460 return isShowing; 461 } 462 463 /** 464 * Replies true if this dialog is docked and expanded 465 */ 466 public boolean isDialogInDefaultView() { 467 return isShowing && isDocked && (! isCollapsed); 468 } 469 470 /** 471 * Replies true if this dialog is docked and collapsed 472 */ 473 public boolean isDialogInCollapsedView() { 474 return isShowing && isDocked && isCollapsed; 475 } 476 477 public String helpTopic() { 478 String help = getClass().getName(); 479 help = help.substring(help.lastIndexOf('.')+1, help.length()-6); 480 return "Dialog/"+help; 481 } 544 482 }
Note:
See TracChangeset
for help on using the changeset viewer.