001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.io;
003
004import java.awt.GraphicsConfiguration;
005import java.awt.HeadlessException;
006import java.awt.Window;
007
008import javax.swing.JComponent;
009import javax.swing.JDialog;
010
011/**
012 * This is an abstract base class for dialogs used for entering generic upload options.
013 * @since 7358
014 */
015public abstract class AbstractUploadDialog extends JDialog {
016
017    private boolean canceled;
018
019    /**
020     * Creates a dialog with an empty title and the specified modality and
021     * {@code Window} as its owner.
022     * <p>
023     * This constructor sets the component's locale property to the value
024     * returned by {@code JComponent.getDefaultLocale}.
025     *
026     * @param owner the {@code Window} from which the dialog is displayed or
027     *     {@code null} if this dialog has no owner
028     * @param modalityType specifies whether dialog blocks input to other
029     *     windows when shown. {@code null} value and unsupported modality
030     *     types are equivalent to {@code MODELESS}
031     *
032     * @throws IllegalArgumentException
033     *     if the {@code owner} is not an instance of {@link java.awt.Dialog Dialog}
034     *     or {@link java.awt.Frame Frame}
035     * @throws IllegalArgumentException
036     *     if the {@code owner}'s {@code GraphicsConfiguration} is not from a screen device
037     * @throws HeadlessException
038     *     when {@code GraphicsEnvironment.isHeadless()} returns {@code true}
039     * @throws SecurityException
040     *     if the calling thread does not have permission to create modal dialogs
041     *     with the given {@code modalityType}
042     *
043     * @see java.awt.Dialog.ModalityType
044     * @see java.awt.Dialog#setModal
045     * @see java.awt.Dialog#setModalityType
046     * @see java.awt.GraphicsEnvironment#isHeadless
047     * @see JComponent#getDefaultLocale
048     */
049    public AbstractUploadDialog(Window owner, ModalityType modalityType) {
050        super(owner, modalityType);
051    }
052
053    /**
054     * Creates a dialog with the specified title, owner {@code Window},
055     * modality and {@code GraphicsConfiguration}.
056     * <p>
057     * NOTE: Any popup components ({@code JComboBox},
058     * {@code JPopupMenu}, {@code JMenuBar})
059     * created within a modal dialog will be forced to be lightweight.
060     * <p>
061     * This constructor sets the component's locale property to the value
062     * returned by {@code JComponent.getDefaultLocale}.
063     *
064     * @param owner the {@code Window} from which the dialog is displayed or
065     *     {@code null} if this dialog has no owner
066     * @param title the {@code String} to display in the dialog's
067     *     title bar or {@code null} if the dialog has no title
068     * @param modalityType specifies whether dialog blocks input to other
069     *     windows when shown. {@code null} value and unsupported modality
070     *     types are equivalent to {@code MODELESS}
071     * @param gc the {@code GraphicsConfiguration} of the target screen device;
072     *     if {@code null}, the default system {@code GraphicsConfiguration}
073     *     is assumed
074     * @throws IllegalArgumentException
075     *     if the {@code owner} is not an instance of {@link java.awt.Dialog Dialog}
076     *     or {@link java.awt.Frame Frame}
077     * @throws IllegalArgumentException
078     *     if the {@code owner}'s {@code GraphicsConfiguration} is not from a screen device
079     * @throws HeadlessException
080     *     when {@code GraphicsEnvironment.isHeadless()} returns {@code true}
081     * @throws SecurityException
082     *     if the calling thread does not have permission to create modal dialogs
083     *     with the given {@code modalityType}
084     *
085     * @see java.awt.Dialog.ModalityType
086     * @see java.awt.Dialog#setModal
087     * @see java.awt.Dialog#setModalityType
088     * @see java.awt.GraphicsEnvironment#isHeadless
089     * @see JComponent#getDefaultLocale
090     */
091    public AbstractUploadDialog(Window owner, String title, ModalityType modalityType, GraphicsConfiguration gc) {
092        super(owner, title, modalityType, gc);
093    }
094
095    /**
096     * Creates a dialog with the specified title, owner {@code Window} and
097     * modality.
098     * <p>
099     * This constructor sets the component's locale property to the value
100     * returned by {@code JComponent.getDefaultLocale}.
101     *
102     * @param owner the {@code Window} from which the dialog is displayed or
103     *     {@code null} if this dialog has no owner
104     * @param title the {@code String} to display in the dialog's
105     *     title bar or {@code null} if the dialog has no title
106     * @param modalityType specifies whether dialog blocks input to other
107     *     windows when shown. {@code null} value and unsupported modality
108     *     types are equivalent to {@code MODELESS}
109     *
110     * @throws IllegalArgumentException
111     *     if the {@code owner} is not an instance of {@link java.awt.Dialog Dialog}
112     *     or {@link java.awt.Frame Frame}
113     * @throws IllegalArgumentException
114     *     if the {@code owner}'s {@code GraphicsConfiguration} is not from a screen device
115     * @throws HeadlessException
116     *     when {@code GraphicsEnvironment.isHeadless()} returns {@code true}
117     * @throws SecurityException
118     *     if the calling thread does not have permission to create modal dialogs
119     *     with the given {@code modalityType}
120     *
121     * @see java.awt.Dialog.ModalityType
122     * @see java.awt.Dialog#setModal
123     * @see java.awt.Dialog#setModalityType
124     * @see java.awt.GraphicsEnvironment#isHeadless
125     * @see JComponent#getDefaultLocale
126     */
127    public AbstractUploadDialog(Window owner, String title, ModalityType modalityType) {
128        super(owner, title, modalityType);
129    }
130
131    /**
132     * Creates a modeless dialog with the specified title and owner
133     * {@code Window}.
134     * <p>
135     * This constructor sets the component's locale property to the value
136     * returned by {@code JComponent.getDefaultLocale}.
137     *
138     * @param owner the {@code Window} from which the dialog is displayed or
139     *     {@code null} if this dialog has no owner
140     * @param title the {@code String} to display in the dialog's
141     *     title bar or {@code null} if the dialog has no title
142     *
143     * @throws IllegalArgumentException
144     *     if the {@code owner} is not an instance of {@link java.awt.Dialog Dialog}
145     *     or {@link java.awt.Frame Frame}
146     * @throws IllegalArgumentException
147     *     if the {@code owner}'s {@code GraphicsConfiguration} is not from a screen device
148     * @throws HeadlessException
149     *     when {@code GraphicsEnvironment.isHeadless()} returns {@code true}
150     *
151     * @see java.awt.GraphicsEnvironment#isHeadless
152     * @see JComponent#getDefaultLocale
153     */
154    public AbstractUploadDialog(Window owner, String title) {
155        super(owner, title);
156    }
157
158    /**
159     * Creates a modeless dialog with the specified {@code Window}
160     * as its owner and an empty title.
161     * <p>
162     * This constructor sets the component's locale property to the value
163     * returned by {@code JComponent.getDefaultLocale}.
164     *
165     * @param owner the {@code Window} from which the dialog is displayed or
166     *     {@code null} if this dialog has no owner
167     *
168     * @throws IllegalArgumentException
169     *     if the {@code owner} is not an instance of {@link java.awt.Dialog Dialog}
170     *     or {@link java.awt.Frame Frame}
171     * @throws IllegalArgumentException
172     *     if the {@code owner}'s {@code GraphicsConfiguration} is not from a screen device
173     * @throws HeadlessException
174     *     when {@code GraphicsEnvironment.isHeadless()} returns {@code true}
175     *
176     * @see java.awt.GraphicsEnvironment#isHeadless
177     * @see JComponent#getDefaultLocale
178     */
179    public AbstractUploadDialog(Window owner) {
180        super(owner);
181    }
182
183    /**
184     * Returns true if the dialog was canceled
185     *
186     * @return true if the dialog was canceled
187     */
188    public final boolean isCanceled() {
189        return canceled;
190    }
191
192    /**
193     * Sets whether the dialog was canceled
194     *
195     * @param canceled true if the dialog is canceled
196     */
197    protected void setCanceled(boolean canceled) {
198        this.canceled = canceled;
199    }
200
201    /**
202     * Remembers the user input in the preference settings
203     */
204    public void rememberUserInput() {
205        // Override if needed
206    }
207}