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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.