Ignore:
Timestamp:
2009-12-05T17:54:49+01:00 (14 years ago)
Author:
bastiK
Message:

Adjusted toggle dialog behavior for geoimage:

  • When click on a thumbnail, show the detached dialog unless the side dialog is already open.
  • When closing the detached dialog do not open it in the side dialog again, just close.
  • When the toggle button is clicked, always open the side dialog.
File:
1 edited

Legend:

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

    r2566 r2577  
    4646public class ToggleDialog extends JPanel implements Helpful {
    4747    /** The action to toggle this dialog */
    48     private ToggleDialogAction toggleAction;
    49     private String preferencePrefix;
     48    protected ToggleDialogAction toggleAction;
     49    protected String preferencePrefix;
    5050
    5151    /** DialogsPanel that manages all ToggleDialogs */
    52     private DialogsPanel dialogsPanel;
    53 
    54     private TitleBar titleBar;
     52    protected DialogsPanel dialogsPanel;
     53
     54    protected TitleBar titleBar;
    5555
    5656    /**
    5757     * Indicates whether the dialog is showing or not.
    5858     */
    59     private boolean isShowing;
     59    protected boolean isShowing;
    6060    /**
    6161     * If isShowing is true, indicates whether the dialog is docked or not, e. g.
    6262     * shown as part of the main window or as a seperate dialog window.
    6363     */
    64     private boolean isDocked;
     64    protected boolean isDocked;
    6565    /**
    6666     * If isShowing and isDocked are true, indicates whether the dialog is
    6767     * currently minimized or not.
    6868     */
    69     boolean isCollapsed;
     69    protected boolean isCollapsed;
    7070
    7171    /** the preferred height if the toggle dialog is expanded */
     
    139139
    140140        public void actionPerformed(ActionEvent e) {
     141            toggleButtonHook();
    141142            if (isShowing) {
    142143                hideDialog();
     
    204205        detachedDialog = new DetachedDialog();
    205206        detachedDialog.setVisible(true);
     207        setIsShowing(true);
    206208        setIsDocked(false);
    207209    }
     
    213215    public void collapse() {
    214216//        if (isShowing && isDocked && !isCollapsed) {
     217        if (isDialogInDefaultView()) {
    215218            setContentVisible(false);
    216219            setIsCollapsed(true);
     
    220223            lblMinimized.setIcon(ImageProvider.get("misc", "minimized"));
    221224            hideNotify();
    222 //        }
    223 //        else throw ...
     225        }
     226        else throw new IllegalStateException();
    224227    }
    225228
     
    229232    protected void expand() {
    230233//        if (isShowing && isDocked && isCollapsed) {
     234        if (isDialogInCollapsedView()) {
    231235            setContentVisible(true);
    232236            setIsCollapsed(false);
     
    235239            lblMinimized.setIcon(ImageProvider.get("misc", "normal"));
    236240            showNotify();
    237 //        }
    238 //        else throw ...
     241        }
     242        else throw new IllegalStateException();
    239243    }
    240244
     
    392396                    getContentPane().removeAll();
    393397                    dispose();
    394                     dock();
    395                     expand();
    396                     dialogsPanel.reconstruct(Action.INVISIBLE_TO_DEFAULT, ToggleDialog.this);
     398                    if (dockWhenClosingDetachedDlg()) {
     399                        dock();
     400                        if (isDialogInCollapsedView()) {
     401                            expand();
     402                        }
     403                        dialogsPanel.reconstruct(Action.INVISIBLE_TO_DEFAULT, ToggleDialog.this);
     404                    } else {
     405                        hideDialog();
     406                    }
    397407                }
    398408            });
     
    426436
    427437    /**
    428      * Change the Geometry of the detached dialog to better fit the content.
    429      * Overrride this to make it useful.
    430      */
    431     protected Rectangle getDetachedGeometry(Rectangle last) {
    432         return last;
    433     }
    434 
    435     /**
    436      * Default size of the detached dialog.
    437      * Override this method to customize the initial dialog size.
    438      */
    439     protected Dimension getDefaultDetachedSize() {
    440         return new Dimension(Main.map.DEF_TOGGLE_DLG_WIDTH, preferredHeight);
    441     }
    442 
    443     /**
    444438     * Replies the action to toggle the visible state of this toggle dialog
    445439     *
     
    481475    }
    482476
    483     private void setIsShowing(boolean val) {
     477    protected void setIsShowing(boolean val) {
    484478        isShowing = val;
    485479        Main.pref.put(preferencePrefix+".visible", val);
    486480    }
    487481
    488     private void setIsDocked(boolean val) {
     482    protected void setIsDocked(boolean val) {
    489483        isDocked = val;
    490484        Main.pref.put(preferencePrefix+".docked", val);
    491485    }
    492486
    493     private void setIsCollapsed(boolean val) {
     487    protected void setIsCollapsed(boolean val) {
    494488        isCollapsed = val;
    495489        Main.pref.put(preferencePrefix+".minimized", val);
     
    498492    public int getPreferredHeight() {
    499493        return preferredHeight;
    500     }
    501 
    502     /**
    503      * Replies true if this dialog is showing either as docked or as detached dialog
    504      */
    505     public boolean isDialogShowing() {
    506         return isShowing;
    507     }
    508 
    509     /**
    510      * Replies true if this dialog is docked and expanded
    511      */
    512     public boolean isDialogInDefaultView() {
    513         return isShowing && isDocked && (! isCollapsed);
    514     }
    515 
    516     /**
    517      * Replies true if this dialog is docked and collapsed
    518      */
    519     public boolean isDialogInCollapsedView() {
    520         return isShowing && isDocked && isCollapsed;
    521494    }
    522495
     
    526499        return "Dialog/"+help;
    527500    }
     501    /**
     502     * Replies true if this dialog is showing either as docked or as detached dialog
     503     */
     504    public boolean isDialogShowing() {
     505        return isShowing;
     506    }
     507
     508    /**
     509     * Replies true if this dialog is docked and expanded
     510     */
     511    public boolean isDialogInDefaultView() {
     512        return isShowing && isDocked && (! isCollapsed);
     513    }
     514
     515    /**
     516     * Replies true if this dialog is docked and collapsed
     517     */
     518    public boolean isDialogInCollapsedView() {
     519        return isShowing && isDocked && isCollapsed;
     520    }
     521
     522    /***
     523     * The following methods are intended to be overridden, in order to customize
     524     * the toggle dialog behavior.
     525     **/
     526
     527    /**
     528    * Change the Geometry of the detached dialog to better fit the content.
     529    */
     530    protected Rectangle getDetachedGeometry(Rectangle last) {
     531        return last;
     532    }
     533
     534    /**
     535     * Default size of the detached dialog.
     536     * Override this method to customize the initial dialog size.
     537     */
     538    protected Dimension getDefaultDetachedSize() {
     539        return new Dimension(dialogsPanel.getWidth(), preferredHeight);
     540    }
     541
     542    /**
     543     * Do something when the toggleButton is pressed.
     544     */
     545    protected void toggleButtonHook() {
     546    }
     547
     548    protected boolean dockWhenClosingDetachedDlg() {
     549        return true;
     550    }
     551
     552    /***
     553     * End of override hooks
     554     **/
    528555}
Note: See TracChangeset for help on using the changeset viewer.