Changeset 2577 in josm for trunk/src/org/openstreetmap/josm


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.
Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 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}
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r2566 r2577  
    322322                    return;
    323323                }
    324                 JFileChooser fc = new JFileChooser(Main.pref.get("tagimages.lastdirectory"));
     324                JFileChooser fc = new JFileChooser(Main.pref.get("tagimages.lastdirectory", Main.pref.get("lastDirectory")));
    325325                fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    326326                fc.setMultiSelectionEnabled(true);
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r2566 r2577  
    2121import org.openstreetmap.josm.Main;
    2222import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
     23import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
    2324import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.ImageEntry;
    2425import org.openstreetmap.josm.tools.ImageProvider;
     
    4546        return INSTANCE;
    4647    }
    47    
     48
    4849    private JButton btnNext;
    4950    private JButton btnPrevious;
     
    5253        super(tr("Geotagged Images"), "geoimage", tr("Display geotagged images"), Shortcut.registerShortcut("tools:geotagged", tr("Tool: {0}", tr("Display geotagged images")), KeyEvent.VK_Y, Shortcut.GROUP_EDIT), 200);
    5354
     55        /* Don't show a detached dialog right from the start. */
     56        if (isShowing && !isDocked) {
     57            setIsShowing(false);
     58        }
     59
    5460        if (INSTANCE != null) {
    5561            throw new IllegalStateException("Image viewer dialog should not be instanciated twice !");
     
    5763
    5864        INSTANCE = this;
    59        
     65
    6066        JPanel content = new JPanel();
    6167        content.setLayout(new BorderLayout());
     
    188194            imgDisplay.setOsdText("");
    189195        }
    190     }
    191    
     196        if (! isDialogShowing()) {
     197            setIsDocked(false);     // always open a detached window when an image is clicked and dialog is closed
     198            showDialog();
     199        } else {
     200            if (isDocked && isCollapsed) {
     201                expand();
     202                dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, this);
     203            }
     204        }
     205
     206    }
     207
     208    /**
     209     * When pressing the Toggle button always show the docked dialog.
     210     */
     211    @Override
     212    protected void toggleButtonHook() {
     213        if (! isShowing) {
     214            setIsDocked(true);
     215            setIsCollapsed(false);
     216        }
     217    }
     218
     219    /**
     220     * When an image is closed, really close it and do not pop
     221     * up the side dialog.
     222     */
     223    @Override
     224    protected boolean dockWhenClosingDetachedDlg() {
     225        return false;
     226    }
     227
    192228    /**
    193229     * Returns whether an image is currently displayed
Note: See TracChangeset for help on using the changeset viewer.