1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.io;
|
---|
3 |
|
---|
4 | import java.awt.GraphicsConfiguration;
|
---|
5 | import java.awt.HeadlessException;
|
---|
6 | import java.awt.Window;
|
---|
7 |
|
---|
8 | import javax.swing.JComponent;
|
---|
9 | import javax.swing.JDialog;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * This is an abstract base class for dialogs used for entering generic upload options.
|
---|
13 | * @since 7358
|
---|
14 | */
|
---|
15 | public abstract class AbstractUploadDialog extends JDialog {
|
---|
16 |
|
---|
17 | private boolean canceled = false;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Creates a dialog with an empty title and the specified modality and
|
---|
21 | * {@code Window} as its owner.
|
---|
22 | * <p>
|
---|
23 | * This constructor sets the component's locale property to the value
|
---|
24 | * returned by {@code JComponent.getDefaultLocale}.
|
---|
25 | *
|
---|
26 | * @param owner the {@code Window} from which the dialog is displayed or
|
---|
27 | * {@code null} if this dialog has no owner
|
---|
28 | * @param modalityType specifies whether dialog blocks input to other
|
---|
29 | * windows when shown. {@code null} value and unsupported modality
|
---|
30 | * types are equivalent to {@code MODELESS}
|
---|
31 | *
|
---|
32 | * @throws IllegalArgumentException
|
---|
33 | * if the {@code owner} is not an instance of {@link java.awt.Dialog Dialog}
|
---|
34 | * or {@link java.awt.Frame Frame}
|
---|
35 | * @throws IllegalArgumentException
|
---|
36 | * if the {@code owner}'s {@code GraphicsConfiguration} is not from a screen device
|
---|
37 | * @throws HeadlessException
|
---|
38 | * when {@code GraphicsEnvironment.isHeadless()} returns {@code true}
|
---|
39 | * @throws SecurityException
|
---|
40 | * if the calling thread does not have permission to create modal dialogs
|
---|
41 | * with the given {@code modalityType}
|
---|
42 | *
|
---|
43 | * @see java.awt.Dialog.ModalityType
|
---|
44 | * @see java.awt.Dialog#setModal
|
---|
45 | * @see java.awt.Dialog#setModalityType
|
---|
46 | * @see java.awt.GraphicsEnvironment#isHeadless
|
---|
47 | * @see JComponent#getDefaultLocale
|
---|
48 | */
|
---|
49 | public AbstractUploadDialog(Window owner, ModalityType modalityType) {
|
---|
50 | super(owner, modalityType);
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Creates a dialog with the specified title, owner {@code Window},
|
---|
55 | * modality and {@code GraphicsConfiguration}.
|
---|
56 | * <p>
|
---|
57 | * NOTE: Any popup components ({@code JComboBox},
|
---|
58 | * {@code JPopupMenu}, {@code JMenuBar})
|
---|
59 | * created within a modal dialog will be forced to be lightweight.
|
---|
60 | * <p>
|
---|
61 | * This constructor sets the component's locale property to the value
|
---|
62 | * returned by {@code JComponent.getDefaultLocale}.
|
---|
63 | *
|
---|
64 | * @param owner the {@code Window} from which the dialog is displayed or
|
---|
65 | * {@code null} if this dialog has no owner
|
---|
66 | * @param title the {@code String} to display in the dialog's
|
---|
67 | * title bar or {@code null} if the dialog has no title
|
---|
68 | * @param modalityType specifies whether dialog blocks input to other
|
---|
69 | * windows when shown. {@code null} value and unsupported modality
|
---|
70 | * types are equivalent to {@code MODELESS}
|
---|
71 | * @param gc the {@code GraphicsConfiguration} of the target screen device;
|
---|
72 | * if {@code null}, the default system {@code GraphicsConfiguration}
|
---|
73 | * is assumed
|
---|
74 | * @throws IllegalArgumentException
|
---|
75 | * if the {@code owner} is not an instance of {@link java.awt.Dialog Dialog}
|
---|
76 | * or {@link java.awt.Frame Frame}
|
---|
77 | * @throws IllegalArgumentException
|
---|
78 | * if the {@code owner}'s {@code GraphicsConfiguration} is not from a screen device
|
---|
79 | * @throws HeadlessException
|
---|
80 | * when {@code GraphicsEnvironment.isHeadless()} returns {@code true}
|
---|
81 | * @throws SecurityException
|
---|
82 | * if the calling thread does not have permission to create modal dialogs
|
---|
83 | * with the given {@code modalityType}
|
---|
84 | *
|
---|
85 | * @see java.awt.Dialog.ModalityType
|
---|
86 | * @see java.awt.Dialog#setModal
|
---|
87 | * @see java.awt.Dialog#setModalityType
|
---|
88 | * @see java.awt.GraphicsEnvironment#isHeadless
|
---|
89 | * @see JComponent#getDefaultLocale
|
---|
90 | */
|
---|
91 | public AbstractUploadDialog(Window owner, String title, ModalityType modalityType, GraphicsConfiguration gc) {
|
---|
92 | super(owner, title, modalityType, gc);
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Creates a dialog with the specified title, owner {@code Window} and
|
---|
97 | * modality.
|
---|
98 | * <p>
|
---|
99 | * 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 | }
|
---|