Ignore:
Timestamp:
2009-10-02T22:06:36+02:00 (15 years ago)
Author:
stoecker
Message:

see #3550 - patch by bastiK - allow resizing right handside dialogs, updated i18n

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r2162 r2224  
    88import java.awt.Dimension;
    99import java.util.ArrayList;
     10import java.util.List;
    1011
    1112import javax.swing.AbstractButton;
     
    2930import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
    3031import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
     32import org.openstreetmap.josm.gui.dialogs.DialogsPanel;
    3133import org.openstreetmap.josm.gui.dialogs.FilterDialog;
    3234import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
     
    7577     * instead of adding directly to this list.
    7678     */
    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();
    7981
    8082    public final ButtonGroup toolGroup = new ButtonGroup();
    81    
     83
    8284    /**
    8385     * Default width of the toggle dialog area.
     
    107109
    108110        JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
    109                              mapView, toggleDialogs);
     111                             mapView, dialogsPanel);
    110112
    111113        /**
     
    113115         */
    114116        splitPane.setResizeWeight(1.0);
    115        
     117
    116118        /**
    117119         * Some beautifications.
     
    127129            }
    128130        });
    129        
     131
    130132        add(splitPane, BorderLayout.CENTER);
    131133
    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));
    136138        mapView.setMinimumSize(new Dimension(10,0));
    137139
     
    173175     */
    174176    public void destroy() {
    175         for (ToggleDialog t : allDialogs) {
    176             t.closeDetachedDialog();
    177         }
     177        dialogsPanel.destroy();
    178178        for (int i = 0; i < toolBarActions.getComponentCount(); ++i)
    179179            if (toolBarActions.getComponent(i) instanceof Destroyable) {
     
    203203     * Open all ToggleDialogs that have their preferences property set. Close all others.
    204204     */
    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);
    217207    }
    218208
     
    243233        }
    244234    }
    245 
    246 
    247235
    248236    /**
     
    299287     */
    300288    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);
    306290    }
    307291
     
    310294     */
    311295    public int getToggleDlgWidth() {
    312         return toggleDialogs.getWidth();
     296        return dialogsPanel.getWidth();
    313297    }
    314298}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r2005 r2224  
    2929    public CommandStackDialog(final MapFrame mapFrame) {
    3030        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);
    3232        Main.main.undoRedo.listenerCommands.add(this);
    3333
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r2181 r2224  
    5656 * change the ordering of the layers, to hide/show layers, to activate layers,
    5757 * and to delete layers.
    58  * 
     58 *
    5959 */
    6060public class LayerListDialog extends ToggleDialog {
     
    6666    /**
    6767     * Creates the instance of the dialog. It's connected to the map frame <code>mapFrame</code>
    68      * 
     68     *
    6969     * @param mapFrame the map frame
    7070     */
     
    7575    /**
    7676     * Replies the instance of the dialog
    77      * 
     77     *
    7878     * @return the instance of the dialog
    7979     * @throws IllegalStateException thrown, if the dialog is not created yet
     
    144144    protected LayerListDialog(MapFrame mapFrame) {
    145145        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);
    147147
    148148        // create the models
     
    194194     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
    195195     * on every {@see ListSelectionEvent}.
    196      * 
     196     *
    197197     * @param listener  the listener
    198198     * @param listSelectionModel  the source emitting {@see ListSelectionEvent}s
     
    212212     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
    213213     * on every {@see ListDataEvent}.
    214      * 
     214     *
    215215     * @param listener  the listener
    216216     * @param listSelectionModel  the source emitting {@see ListDataEvent}s
     
    237237     * <code>listener</code> receives a {@see IEnabledStateUpdating#updateEnabledState()}
    238238     * on every {@see LayerChangeListener}-event emitted by {@see MapView}.
    239      * 
     239     *
    240240     * @param listener  the listener
    241241     */
     
    272272        /**
    273273         * Creates a {@see DeleteLayerAction} for a specific layer.
    274          * 
     274         *
    275275         * @param layer the layer. Must not be null.
    276276         * @exception IllegalArgumentException thrown, if layer is null
     
    288288         * Creates a {@see DeleteLayerAction} which will delete the currently
    289289         * selected layers in the layer dialog.
    290          * 
     290         *
    291291         */
    292292        public DeleteLayerAction() {
     
    353353         * Creates a {@see ShowHideLayerAction} which toggle the visibility of
    354354         * a specific layer.
    355          * 
     355         *
    356356         * @param layer  the layer. Must not be null.
    357357         * @exception IllegalArgumentException thrown, if layer is null
     
    369369         * Creates a {@see ShowHideLayerAction} which will toggle the visibility of
    370370         * the currently selected layers
    371          * 
     371         *
    372372         */
    373373        public ShowHideLayerAction() {
     
    620620     * The layer list model. The model manages a list of layers and provides methods for
    621621     * moving layers up and down, for toggling their visibility, and for activating a layer.
    622      * 
     622     *
    623623     * The model is a {@see ListModel} and it provides a {@see ListSelectionModel}. It expectes
    624624     * to be configured with a {@see DefaultListSelectionModel}. The selection model is used
    625625     * to update the selection state of views depending on messages sent to the model.
    626      * 
     626     *
    627627     * The model manages a list of {@see LayerListModelListener} which are mainly notified if
    628628     * the model requires views to make a specific list entry visible.
    629      * 
     629     *
    630630     * It also listens to {@see PropertyChangeEvent}s of every {@see Layer} it manages, in particular to
    631631     * the properties {@see Layer#VISIBLE_PROP} and {@see Layer#NAME_PROP}.
     
    639639        /**
    640640         * constructor
    641          * 
     641         *
    642642         * @param selectionModel the list selection model
    643643         */
     
    649649        /**
    650650         * Adds a listener to this model
    651          * 
     651         *
    652652         * @param listener the listener
    653653         */
     
    663663         * removes a listener from  this model
    664664         * @param listener the listener
    665          * 
     665         *
    666666         */
    667667        public void removeLayerListModelListener(LayerListModelListener listener) {
     
    675675        /**
    676676         * Fires a make visible event to listeners
    677          * 
     677         *
    678678         * @param index the index of the row to make visible
    679679         * @param layer the layer at this index
     
    688688        /**
    689689         * Fires a refresh event to listeners of this model
    690          * 
     690         *
    691691         * @see LayerListModelListener#refresh()
    692692         */
     
    700700         * Populates the model with the current layers managed by
    701701         * {@see MapView}.
    702          * 
     702         *
    703703         */
    704704        public void populate() {
     
    715715         * Marks <code>layer</code> as selected layer. Ignored, if
    716716         * layer is null.
    717          * 
     717         *
    718718         * @param layer the layer.
    719719         */
     
    732732         * Replies the list of currently selected layers. Never null, but may
    733733         * be empty.
    734          * 
     734         *
    735735         * @return the list of currently selected layers. Never null, but may
    736736         * be empty.
     
    749749         * Replies a the list of indices of the selected rows. Never null,
    750750         * but may be empty.
    751          * 
     751         *
    752752         * @return  the list of indices of the selected rows. Never null,
    753753         * but may be empty.
     
    765765        /**
    766766         * Invoked if a layer managed by {@see MapView} is removed
    767          * 
     767         *
    768768         * @param layer the layer which is removed
    769769         */
     
    783783        /**
    784784         * Invoked when a layer managed by {@see MapView} is added
    785          * 
     785         *
    786786         * @param layer the layer
    787787         */
     
    797797        /**
    798798         * Replies the first layer. Null if no layers are present
    799          * 
     799         *
    800800         * @return the first layer. Null if no layers are present
    801801         */
     
    807807        /**
    808808         * Replies the layer at position <code>index</code>
    809          * 
     809         *
    810810         * @param index the index
    811811         * @return the layer at position <code>index</code>. Null,
     
    821821         * Replies true if the the currently selected layers can move up
    822822         * by one position
    823          * 
     823         *
    824824         * @return true if the the currently selected layers can move up
    825825         * by one position
     
    832832        /**
    833833         * Move up the currently selected layers by one position
    834          * 
     834         *
    835835         */
    836836        public void moveUp() {
     
    854854         * Replies true if the currently selected layers can move down
    855855         * by one position
    856          * 
     856         *
    857857         * @return true if the currently selected layers can move down
    858858         * by one position
     
    865865        /**
    866866         * Move down the currently selected layers by one position
    867          * 
     867         *
    868868         */
    869869        public void moveDown() {
     
    888888         * Make sure the first of the selected layers is visible in the
    889889         * views of this model.
    890          * 
     890         *
    891891         */
    892892        protected void ensureSelectedIsVisible() {
     
    901901         * Replies a list of layers which are possible merge targets
    902902         * for <code>source</code>
    903          * 
     903         *
    904904         * @param source the source layer
    905905         * @return a list of layers which are possible merge targets
     
    924924         * Replies the list of layers currently managed by {@see MapView}.
    925925         * Never null, but can be empty.
    926          * 
     926         *
    927927         * @return the list of layers currently managed by {@see MapView}.
    928928         * Never null, but can be empty.
     
    936936        /**
    937937         * Ensures that at least one layer is selected in the layer dialog
    938          * 
     938         *
    939939         */
    940940        protected void ensureActiveSelected() {
     
    956956        /**
    957957         * Replies the active layer. null, if no active layer is available
    958          * 
     958         *
    959959         * @return the active layer. null, if no active layer is available
    960960         */
     
    10431043     * Creates a {@see ShowHideLayerAction} for <code>layer</code> in the
    10441044     * context of this {@see LayerListDialog}.
    1045      * 
     1045     *
    10461046     * @param layer the layer
    10471047     * @return the action
     
    10541054     * Creates a {@see DeleteLayerAction} for <code>layer</code> in the
    10551055     * context of this {@see LayerListDialog}.
    1056      * 
     1056     *
    10571057     * @param layer the layer
    10581058     * @return the action
     
    10651065     * Creates a {@see ActivateLayerAction} for <code>layer</code> in the
    10661066     * context of this {@see LayerListDialog}.
    1067      * 
     1067     *
    10681068     * @param layer the layer
    10691069     * @return the action
     
    10761076     * Creates a {@see MergeLayerAction} for <code>layer</code> in the
    10771077     * context of this {@see LayerListDialog}.
    1078      * 
     1078     *
    10791079     * @param layer the layer
    10801080     * @return the action
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r2218 r2224  
    453453        super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."),
    454454                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);
    456456
    457457        // setting up the properties table
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r2005 r2224  
    8585    public SelectionListDialog() {
    8686        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);
    8888
    8989        selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r2185 r2224  
    3434import org.openstreetmap.josm.actions.JosmAction;
    3535import org.openstreetmap.josm.actions.HelpAction.Helpful;
     36import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
    3637import org.openstreetmap.josm.tools.GBC;
    3738import org.openstreetmap.josm.tools.ImageProvider;
     
    4041/**
    4142 * This class is a toggle dialog that can be turned on and off.
    42  * 
     43 *
    4344 *
    4445 */
    4546public 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 */
    7948    private ToggleDialogAction toggleAction;
    8049    private String preferencePrefix;
    8150
    82     private JPanel parent;
     51    /** DialogsPanel that manages all ToggleDialogs */
     52    private DialogsPanel dialogsPanel;
     53
    8354    private  TitleBar titleBar;
    8455    private String title;
    8556
    86     /** 
     57    /**
    8758     * Indicates whether the dialog is showing or not.
    8859     */
    8960    private boolean isShowing;
    90     /** 
     61    /**
    9162     * If isShowing is true, indicates whether the dialog is docked or not, e. g.
    9263     * shown as part of the main window or as a seperate dialog window.
    9364     */
    9465    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
    9768     * currently minimized or not.
    9869     */
     
    10172    /** the preferred height if the toggle dialog is expanded */
    10273    private int preferredHeight;
     74
    10375    /** the label in the title bar which shows whether the toggle dialog is expanded or collapsed */
    10476    private JLabel lblMinimized;
     77
    10578    /** the JDialog displaying the toggle dialog as undocked dialog */
    10679    private JDialog detachedDialog;
     
    10881    /**
    10982     * 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     *
    11191     * @param name  the name of the dialog
    11292     * @param iconName the name of the icon to be displayed
     
    11494     * @param shortcut  the shortcut
    11595     * @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) {
    11899        super(new BorderLayout());
    119100        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
    133102        /** Use the full width of the parent element */
    134103        setPreferredSize(new Dimension(0, preferredHeight));
     
    147116        add(titleBar, BorderLayout.NORTH);
    148117
    149         setVisible(false);
    150118        setBorder(BorderFactory.createEtchedBorder());
    151119
     120        isShowing = Main.pref.getBoolean(preferencePrefix+".visible", defShow);
    152121        isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true);
    153122        isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false);
     
    155124
    156125    /**
     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    /**
    157228     * Sets the visibility of all components in this toggle dialog, except the title bar
    158      * 
     229     *
    159230     * @param visible true, if the components should be visible; false otherwise
    160231     */
     
    169240
    170241    /**
    171      * Toggles between collapsed and expanded state
    172      *
    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 only
    184      *
    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 dialog
    198      */
    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 of
    211      * toggle dialog.
    212      *
    213      * @return
    214      */
    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 right
    227      * 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 placeholder
    235         // 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 sure
    274         // we can place the toggle dialog where it was when it becomes docked
    275         // 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 dialog
    299      */
    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 dialog
    311      */
    312     public boolean isDialogShowing() {
    313         return this.isShowing;
    314     }
    315 
    316     /**
    317      * Shows the dialog
    318      */
    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 PropertyChangeEvents
    335         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 view
    342      *
    343      */
    344     protected void refreshToggleDialogsView() {
    345         if(parent != null){
    346             parent.validate();
    347         }
    348     }
    349 
    350     /**
    351242     * Closes the the detached dialog if this toggle dialog is currently displayed
    352243     * in a detached dialog.
    353      * 
     244     *
    354245     */
    355246    public void closeDetachedDialog() {
     
    361252    }
    362253
    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 dialog
    371      *
    372      * @return the action to toggle the visible state of this toggle dialog
    373      */
    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 dialogs
    389      *
    390      * @param parent the parent
    391      */
    392     public void setParent(JPanel parent) {
    393         this.parent = parent;
    394     }
    395 
    396     /**
    397      * Replies the name of this toggle dialog
    398      *
    399      */
    400     @Override
    401     public String getName() {
    402         return "toggleDialog." + preferencePrefix;
    403     }
    404 
    405     /**
    406      * Sets the title
    407      *
    408      * @param title the title
    409      */
    410     public void setTitle(String title) {
    411         titleBar.setTitle(title);
    412     }
    413254
    414255    /**
    415256     * The title bar displayed in docked mode
    416      * 
     257     *
    417258     */
    418259    private class TitleBar extends JPanel {
     
    429270            lblTitle = new JLabel("",smallIcon, JLabel.TRAILING);
    430271            lblTitle.setIconTextGap(8);
    431            
     272
    432273            JPanel conceal = new JPanel();
    433274            conceal.add(lblTitle);
    434275            conceal.setVisible(false);
    435276            add(conceal, GBC.std());
    436            
     277
    437278            // Cannot add the label directly since it would displace other elements on resize
    438279            JComponent lblTitle_weak = new JComponent() {
     
    450291                        @Override
    451292                        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                            }
    453301                        }
    454302                    }
     
    463311                        public void actionPerformed(ActionEvent e) {
    464312                            detach();
     313                            dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null);
    465314                        }
    466315                    }
     
    476325                        public void actionPerformed(ActionEvent e) {
    477326                            hideDialog();
     327                            dialogsPanel.reconstruct(Action.ELEMENT_SHRINKS, null);
    478328                        }
    479329                    }
     
    495345    /**
    496346     * The dialog class used to display toggle dialogs in a detached window.
    497      * 
     347     *
    498348     */
    499349    private class DetachedDialog extends JDialog {
     
    507357                    dispose();
    508358                    dock();
     359                    expand();
     360                    dialogsPanel.reconstruct(Action.INVISIBLE_TO_DEFAULT, ToggleDialog.this);
    509361                }
    510362            });
     
    534386        return last;
    535387    }
    536    
     388
    537389    /**
    538390     * Default size of the detached dialog.
     
    542394        return new Dimension(Main.map.DEF_TOGGLE_DLG_WIDTH, preferredHeight);
    543395    }
     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    }
    544482}
Note: See TracChangeset for help on using the changeset viewer.