Changeset 2138 in josm for trunk


Ignore:
Timestamp:
2009-09-14T23:02:59+02:00 (15 years ago)
Author:
xeen
Message:

Add remember window geometry feature to extended dialog (see #3478)

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DownloadAction.java

    r2132 r2138  
    4646
    4747        final String prefName = dialog.getClass().getName()+ ".geometry";
    48         ExtendedDialog dialog = new ExtendedDialog(Main.parent, tr("Download"), new String[] {tr("OK"), tr("Cancel")}) {
    49             @Override
    50             public void setVisible(boolean visible) {
    51                 if (visible) {
    52                     new WindowGeometry(
    53                             prefName,
    54                             WindowGeometry.centerInWindow(Main.parent, new Dimension(1000,600))
    55                     ).apply(this);
    56                 } else {
    57                     new WindowGeometry(this).remember(prefName);
    58                 }
    59                 super.setVisible(visible);
    60             }
    61         };
     48        final WindowGeometry wg = WindowGeometry.centerInWindow(Main.parent,
     49                new Dimension(1000,600));
     50
     51        ExtendedDialog dialog = new ExtendedDialog(Main.parent,
     52                tr("Download"),
     53                new String[] {tr("OK"), tr("Cancel")});
    6254        dialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */);
    6355        dialog.setButtonIcons(new String[] {"ok", "cancel"});
     56        dialog.setRememberWindowGeometry(prefName, wg);
    6457        return dialog;
    6558    }
  • trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java

    r2135 r2138  
    2525import org.openstreetmap.josm.tools.GBC;
    2626import org.openstreetmap.josm.tools.ImageProvider;
     27import org.openstreetmap.josm.tools.WindowGeometry;
    2728
    2829
     
    3233    public static final int DialogClosedOtherwise = 0;
    3334    private boolean toggleable = false;
     35    private String rememberSizePref = "";
     36    private WindowGeometry defaultWindowGeometry = null;
    3437    private String togglePref = "";
    3538    private String toggleCheckboxText = tr("Do not show again");
     
    5962     *   <li><code>toggleDisable</code></li>
    6063     *   <li><code>setToggleCheckboxText</code></li>
     64     *   <li><code>setRememberWindowGeometry</code></li>
    6165     * </ul>
    6266     *
     
    286290    @Override
    287291    public void setVisible(boolean visible) {
    288         super.setVisible(visible);
    289292        if (visible) {
    290293            repaint();
    291294        }
     295
     296        // Ensure all required variables are available
     297        if(!rememberSizePref.isEmpty() && defaultWindowGeometry != null) {
     298            if(visible) {
     299                new WindowGeometry(rememberSizePref,
     300                        defaultWindowGeometry).apply(this);
     301            } else {
     302                new WindowGeometry(this).remember(rememberSizePref);
     303            }
     304        }
     305        super.setVisible(visible);
     306    }
     307
     308    /**
     309     * Call this if you want the dialog to remember the size set by the user.
     310     * Set the pref to <code>null</code> or to an empty string to disable again.
     311     * By default, it's disabled.
     312     *
     313     * Note: If you want to set the width of this dialog directly use the usual
     314     * setSize, setPreferredSize, setMaxSize, setMinSize
     315     *
     316     * @param pref  The preference to save the dimension to
     317     * @param wg    The default window geometry that should be used if no
     318     *              existing preference is found (only takes effect if
     319     *              <code>pref</code> is not null or empty
     320     *
     321     */
     322    public void setRememberWindowGeometry(String pref, WindowGeometry wg) {
     323        rememberSizePref = pref == null ? "" : pref;
     324        defaultWindowGeometry = wg;
    292325    }
    293326
Note: See TracChangeset for help on using the changeset viewer.