Revision 1593
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/threadsafedialogs/DefaultThreadSafeDialogsManager.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.tools.swing.impl.threadsafedialogs; |
25 | 25 |
|
26 |
import java.awt.BorderLayout; |
|
26 | 27 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
27 | 28 |
import java.awt.Component; |
28 | 29 |
import java.io.File; |
29 | 30 |
import java.lang.reflect.Constructor; |
31 |
import javax.swing.JCheckBox; |
|
30 | 32 |
|
31 | 33 |
import javax.swing.JFileChooser; |
34 |
import javax.swing.JLabel; |
|
32 | 35 |
import javax.swing.JOptionPane; |
36 |
import javax.swing.JPanel; |
|
33 | 37 |
import javax.swing.SwingUtilities; |
34 | 38 |
import javax.swing.filechooser.FileFilter; |
35 | 39 |
import org.gvsig.tools.ToolsLocator; |
36 | 40 |
import org.gvsig.tools.i18n.I18nManager; |
41 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
42 |
import org.gvsig.tools.swing.api.reminder.DialogReminder; |
|
37 | 43 |
|
38 | 44 |
import org.gvsig.tools.task.RunnableWithParameters; |
39 | 45 |
import org.slf4j.Logger; |
... | ... | |
41 | 47 |
|
42 | 48 |
/** |
43 | 49 |
* Thread safe functions for showing dialogs |
44 |
*
|
|
50 |
* |
|
45 | 51 |
* @author jjdelcerro |
46 |
*
|
|
52 |
* |
|
47 | 53 |
*/ |
48 | 54 |
public class DefaultThreadSafeDialogsManager implements ThreadSafeDialogsManager { |
49 | 55 |
|
50 |
private static Logger logger = LoggerFactory
|
|
51 |
.getLogger(DefaultThreadSafeDialogsManager.class);
|
|
52 |
private Component rootComponent;
|
|
56 |
private static Logger logger = LoggerFactory
|
|
57 |
.getLogger(DefaultThreadSafeDialogsManager.class);
|
|
58 |
private final Component rootComponent;
|
|
53 | 59 |
|
54 |
public DefaultThreadSafeDialogsManager() {
|
|
55 |
this.rootComponent = null;
|
|
56 |
}
|
|
60 |
public DefaultThreadSafeDialogsManager() { |
|
61 |
this.rootComponent = null;
|
|
62 |
}
|
|
57 | 63 |
|
58 |
public DefaultThreadSafeDialogsManager(Component rootComponent) {
|
|
59 |
this.rootComponent = rootComponent;
|
|
60 |
}
|
|
64 |
public DefaultThreadSafeDialogsManager(Component rootComponent) {
|
|
65 |
this.rootComponent = rootComponent;
|
|
66 |
}
|
|
61 | 67 |
|
62 |
protected Component getRootComponent() {
|
|
63 |
return this.rootComponent;
|
|
64 |
}
|
|
68 |
protected Component getRootComponent() {
|
|
69 |
return this.rootComponent;
|
|
70 |
}
|
|
65 | 71 |
|
66 |
private String translate(String message) {
|
|
67 |
I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
68 |
return i18nManager.getTranslation(message);
|
|
69 |
}
|
|
72 |
private String translate(String message) {
|
|
73 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
74 |
return i18nManager.getTranslation(message); |
|
75 |
}
|
|
70 | 76 |
|
71 |
private String translate(String message, String[] args) {
|
|
72 |
I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
73 |
return i18nManager.getTranslation(message, args);
|
|
74 |
}
|
|
77 |
private String translate(String message, String[] args) {
|
|
78 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
79 |
return i18nManager.getTranslation(message, args); |
|
80 |
}
|
|
75 | 81 |
|
76 |
public int confirmDialog(final String message, final String title, final int optionType, |
|
77 |
final int messageType) { |
|
78 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
79 |
public void run() { |
|
80 |
this.returnValue = JOptionPane.showConfirmDialog( |
|
81 |
getRootComponent(), message,title, optionType, messageType); |
|
82 |
} |
|
83 |
}; |
|
84 |
if (SwingUtilities.isEventDispatchThread()) { |
|
85 |
runnable.run(); |
|
86 |
} else { |
|
87 |
try { |
|
88 |
SwingUtilities.invokeAndWait(runnable); |
|
89 |
} catch (Exception e) { |
|
90 |
logger.info("Can't show input dialog '" + message + "'.", e); |
|
91 |
} |
|
92 |
} |
|
93 |
return (Integer) runnable.getReturnValue(); |
|
94 |
} |
|
82 |
@Override |
|
83 |
public int confirmDialog(final String message, final String title, final int optionType, |
|
84 |
final int messageType) { |
|
85 |
return this.confirmDialog(message, title, optionType, messageType, null); |
|
86 |
} |
|
95 | 87 |
|
96 |
public String inputDialog(final String message, final String title, final int messageType, |
|
97 |
final String initialValue) { |
|
98 |
// inputDialog dlg = new inputDialog(); |
|
99 |
// return dlg.show(translate(message), translate(title), messageType, |
|
100 |
// initialValue); |
|
101 |
// |
|
102 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
103 |
public void run() { |
|
104 |
this.returnValue = JOptionPane.showInputDialog( |
|
105 |
getRootComponent(), translate(message), |
|
106 |
translate(title), |
|
107 |
messageType, null, null, |
|
108 |
initialValue); |
|
109 |
} |
|
110 |
}; |
|
111 |
if (SwingUtilities.isEventDispatchThread()) { |
|
112 |
runnable.run(); |
|
113 |
} else { |
|
114 |
try { |
|
115 |
SwingUtilities.invokeAndWait(runnable); |
|
116 |
} catch (Exception e) { |
|
117 |
logger.info("Can't show input dialog '" + message + "'.", e); |
|
118 |
} |
|
119 |
} |
|
120 |
return (String) runnable.getReturnValue(); |
|
121 |
} |
|
88 |
private static class JMessageWithCheck extends JPanel { |
|
122 | 89 |
|
123 |
public String inputDialog(final String message, final String title) { |
|
124 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
125 |
public void run() { |
|
126 |
this.returnValue = JOptionPane.showInputDialog( |
|
127 |
getRootComponent(), (String) translate(message), |
|
128 |
translate(title), |
|
129 |
JOptionPane.QUESTION_MESSAGE, null, null, null); |
|
130 |
} |
|
131 |
}; |
|
132 |
if (SwingUtilities.isEventDispatchThread()) { |
|
133 |
runnable.run(); |
|
134 |
} else { |
|
135 |
try { |
|
136 |
SwingUtilities.invokeAndWait(runnable); |
|
137 |
} catch (Exception e) { |
|
138 |
logger.info("Can't show input dialog '" + message + "'.", e); |
|
139 |
} |
|
140 |
} |
|
141 |
return (String) runnable.getReturnValue(); |
|
142 |
} |
|
90 |
private static final long serialVersionUID = -1902712909850016361L; |
|
91 |
private final JLabel label; |
|
92 |
private final JCheckBox check; |
|
143 | 93 |
|
144 |
public void messageDialog(String message, String title, int messageType) { |
|
145 |
messageDialog(message, null, title, messageType); |
|
146 |
} |
|
94 |
public JMessageWithCheck(String msg, String msgchk) { |
|
95 |
if( !msg.toLowerCase().trim().startsWith("<html>") ) { |
|
96 |
msg = "<html>" + msg.replace("\n", "<br>\n") + "</html>"; |
|
97 |
} |
|
98 |
this.label = new JLabel(msg); |
|
99 |
this.check = new JCheckBox(msgchk); |
|
100 |
this.setLayout(new BorderLayout(10, 10)); |
|
101 |
this.add(this.label, BorderLayout.CENTER); |
|
102 |
this.add(this.check, BorderLayout.PAGE_END); |
|
103 |
} |
|
147 | 104 |
|
148 |
public void messageDialog(final String message, final String messageArgs[], |
|
149 |
final String title, final int messageType) { |
|
150 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
151 |
try { |
|
152 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
153 |
public void run() { |
|
154 |
messageDialog(message, messageArgs, title, messageType); |
|
155 |
} |
|
156 |
}); |
|
157 |
} catch (Exception e) { |
|
158 |
logger.info("Can't show message dialog '" + message, e); |
|
159 |
} |
|
160 |
return; |
|
161 |
} |
|
105 |
public boolean isCheckSelected() { |
|
106 |
return this.check.isSelected(); |
|
107 |
} |
|
108 |
} |
|
162 | 109 |
|
163 |
if (message == null) { |
|
164 |
logger.info("message if null, message dialog not show."); |
|
165 |
return; |
|
166 |
} |
|
167 |
JOptionPane.showMessageDialog(getRootComponent(), |
|
168 |
translate(message, messageArgs), translate(title), messageType); |
|
169 |
} |
|
110 |
@Override |
|
111 |
public int confirmDialog(final String message, final String title, final int optionType, |
|
112 |
final int messageType, final String msgid) { |
|
113 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
114 |
@Override |
|
115 |
public void run() { |
|
116 |
DialogReminder r = null; |
|
117 |
Object msg = message; |
|
118 |
if( msgid != null ) { |
|
119 |
r = ToolsSwingLocator.getDialogReminderManager().add(msgid); |
|
120 |
if( r.hasValue() ) { |
|
121 |
this.returnValue = r.getValue(); |
|
122 |
return; |
|
123 |
} |
|
124 |
msg = new JMessageWithCheck( |
|
125 |
message, |
|
126 |
ToolsLocator.getI18nManager().getTranslation("_Remember_answer_and_do_not_ask_again") |
|
127 |
); |
|
128 |
} |
|
129 |
this.returnValue = JOptionPane.showConfirmDialog( |
|
130 |
getRootComponent(), |
|
131 |
msg, |
|
132 |
title, |
|
133 |
optionType, |
|
134 |
messageType |
|
135 |
); |
|
136 |
if( r != null ) { |
|
137 |
if( ((JMessageWithCheck) msg).isCheckSelected() ) { |
|
138 |
r.setValue(this.returnValue); |
|
139 |
} else { |
|
140 |
r.reset(); |
|
141 |
} |
|
142 |
} |
|
143 |
} |
|
144 |
}; |
|
145 |
if( SwingUtilities.isEventDispatchThread() ) { |
|
146 |
runnable.run(); |
|
147 |
} else { |
|
148 |
try { |
|
149 |
SwingUtilities.invokeAndWait(runnable); |
|
150 |
} catch (Exception e) { |
|
151 |
logger.info("Can't show input dialog '" + message + "'.", e); |
|
152 |
} |
|
153 |
} |
|
154 |
return (Integer) runnable.getReturnValue(); |
|
155 |
} |
|
170 | 156 |
|
157 |
@Override |
|
158 |
public String inputDialog(final String message, final String title, final int messageType, |
|
159 |
final String initialValue) { |
|
160 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
161 |
@Override |
|
162 |
public void run() { |
|
163 |
this.returnValue = JOptionPane.showInputDialog( |
|
164 |
getRootComponent(), translate(message), |
|
165 |
translate(title), |
|
166 |
messageType, null, null, |
|
167 |
initialValue); |
|
168 |
} |
|
169 |
}; |
|
170 |
if( SwingUtilities.isEventDispatchThread() ) { |
|
171 |
runnable.run(); |
|
172 |
} else { |
|
173 |
try { |
|
174 |
SwingUtilities.invokeAndWait(runnable); |
|
175 |
} catch (Exception e) { |
|
176 |
logger.info("Can't show input dialog '" + message + "'.", e); |
|
177 |
} |
|
178 |
} |
|
179 |
return (String) runnable.getReturnValue(); |
|
180 |
} |
|
171 | 181 |
|
172 |
public Component createComponent(final Class<? extends Component> theClass, |
|
173 |
final Object... parameters) { |
|
174 |
return createComponentWithParams(theClass, parameters); |
|
175 |
} |
|
182 |
@Override |
|
183 |
public String inputDialog(final String message, final String title) { |
|
184 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
185 |
@Override |
|
186 |
public void run() { |
|
187 |
this.returnValue = JOptionPane.showInputDialog( |
|
188 |
getRootComponent(), (String) translate(message), |
|
189 |
translate(title), |
|
190 |
JOptionPane.QUESTION_MESSAGE, null, null, null); |
|
191 |
} |
|
192 |
}; |
|
193 |
if( SwingUtilities.isEventDispatchThread() ) { |
|
194 |
runnable.run(); |
|
195 |
} else { |
|
196 |
try { |
|
197 |
SwingUtilities.invokeAndWait(runnable); |
|
198 |
} catch (Exception e) { |
|
199 |
logger.info("Can't show input dialog '" + message + "'.", e); |
|
200 |
} |
|
201 |
} |
|
202 |
return (String) runnable.getReturnValue(); |
|
203 |
} |
|
176 | 204 |
|
177 |
public Component createComponentWithParams( |
|
178 |
final Class<? extends Component> theClass, final Object[] parameters) { |
|
179 |
final Class<?>[] parameterTypes = new Class<?>[parameters.length]; |
|
180 |
for (int i = 0; i < parameters.length; i++) { |
|
181 |
parameterTypes[i] = parameters[i].getClass(); |
|
182 |
} |
|
183 |
final Component component; |
|
184 |
final Constructor<?> constructor; |
|
185 |
try { |
|
186 |
constructor = theClass.getConstructor(parameterTypes); |
|
187 |
} catch (Exception e) { |
|
188 |
throw new IllegalArgumentException(e); |
|
189 |
} |
|
190 |
if (SwingUtilities.isEventDispatchThread()) { |
|
191 |
try { |
|
192 |
component = (Component) constructor.newInstance(parameters); |
|
193 |
} catch (Exception e) { |
|
194 |
throw new IllegalArgumentException(e); |
|
195 |
} |
|
196 |
} else { |
|
197 |
try { |
|
198 |
RunnableWithParameters runnable = new RunnableWithParameters(parameters) { |
|
199 |
public void run() { |
|
200 |
Constructor<?> cons = constructor; |
|
201 |
try { |
|
202 |
this.returnValue = cons.newInstance(parameters.toArray()); |
|
203 |
} catch (Exception e) { |
|
204 |
String msg ="Can't create instance of components, constructor="+cons.toString()+", parameters="+this.parameters.toString()+"."; |
|
205 |
logger.info(msg,e); |
|
206 |
throw new IllegalArgumentException(e); |
|
207 |
} |
|
208 |
} |
|
209 |
}; |
|
210 |
SwingUtilities.invokeAndWait(runnable); |
|
211 |
component = (Component) runnable.getReturnValue(); |
|
212 |
} catch (Exception e) { |
|
213 |
throw new IllegalArgumentException(e); |
|
214 |
} |
|
215 |
} |
|
216 |
return component; |
|
217 |
} |
|
205 |
@Override |
|
206 |
public void messageDialog(String message, String title, int messageType) { |
|
207 |
messageDialog(message, null, title, messageType); |
|
208 |
} |
|
218 | 209 |
|
219 |
public File[] showChooserDialog( |
|
220 |
final String title, |
|
221 |
final int type, // SAVE_DIALOG / OPEN_DIALOG |
|
222 |
final int selectionMode, // JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES |
|
223 |
final boolean multiselection, |
|
224 |
final File initialPath, |
|
225 |
final FileFilter filter, |
|
226 |
final boolean fileHidingEnabled |
|
227 |
) { |
|
228 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
229 |
public void run() { |
|
230 |
JFileChooser fc = new JFileChooser(); |
|
231 |
fc.setDialogTitle(title); |
|
232 |
fc.setDialogType(type); |
|
233 |
fc.setFileSelectionMode(selectionMode); |
|
234 |
fc.setMultiSelectionEnabled(multiselection); |
|
235 |
fc.setCurrentDirectory(initialPath); |
|
236 |
fc.setFileFilter(filter); |
|
237 |
fc.setFileHidingEnabled(fileHidingEnabled); |
|
238 |
int r = JFileChooser.CANCEL_OPTION; |
|
239 |
switch(type) { |
|
240 |
case JFileChooser.SAVE_DIALOG: |
|
241 |
r = fc.showSaveDialog(getRootComponent()); |
|
242 |
break; |
|
243 |
case JFileChooser.OPEN_DIALOG: |
|
244 |
default: |
|
245 |
r = fc.showOpenDialog(getRootComponent()); |
|
246 |
break; |
|
247 |
} |
|
248 |
if( r != JFileChooser.APPROVE_OPTION ) { |
|
249 |
this.returnValue = null; |
|
250 |
return; |
|
251 |
} |
|
252 |
if( fc.isMultiSelectionEnabled() ) { |
|
253 |
this.returnValue = fc.getSelectedFiles(); |
|
254 |
} else { |
|
255 |
this.returnValue = new File[] { fc.getSelectedFile() }; |
|
256 |
} |
|
257 |
} |
|
258 |
}; |
|
259 |
if (SwingUtilities.isEventDispatchThread()) { |
|
260 |
runnable.run(); |
|
261 |
} else { |
|
262 |
try { |
|
263 |
SwingUtilities.invokeAndWait(runnable); |
|
264 |
} catch (Exception e) { |
|
265 |
logger.info("Can't show chooser dialog '" + title + "'.", e); |
|
266 |
} |
|
267 |
} |
|
268 |
return (File[]) runnable.getReturnValue(); |
|
269 |
} |
|
270 |
|
|
271 |
public File[] showOpenDirectoryDialog(String title, File initialPath) { |
|
272 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false); |
|
273 |
} |
|
210 |
@Override |
|
211 |
public void messageDialog(final String message, final String messageArgs[], |
|
212 |
final String title, final int messageType) { |
|
213 |
messageDialog(message, messageArgs, title, messageType, null); |
|
214 |
} |
|
274 | 215 |
|
275 |
|
|
276 |
public File[] showOpenFileDialog(String title, File initialPath) { |
|
277 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
|
278 |
} |
|
216 |
@Override |
|
217 |
public void messageDialog(final String message, final String messageArgs[], |
|
218 |
final String title, final int messageType, final String msgid) { |
|
219 |
if( !SwingUtilities.isEventDispatchThread() ) { |
|
220 |
try { |
|
221 |
SwingUtilities.invokeAndWait(new Runnable() { |
|
222 |
@Override |
|
223 |
public void run() { |
|
224 |
messageDialog(message, messageArgs, title, messageType, msgid); |
|
225 |
} |
|
226 |
}); |
|
227 |
} catch (Exception e) { |
|
228 |
logger.warn("Can't show message dialog '" + message + "'.", e); |
|
229 |
} |
|
230 |
return; |
|
231 |
} |
|
279 | 232 |
|
280 |
|
|
281 |
public File[] showSaveFileDialog(String title, File initialPath) { |
|
282 |
return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
|
283 |
} |
|
233 |
if( message == null ) { |
|
234 |
logger.info("message if null, message dialog not show."); |
|
235 |
return; |
|
236 |
} |
|
237 |
DialogReminder r = null; |
|
238 |
Object msg = translate(message, messageArgs); |
|
239 |
if( msgid != null ) { |
|
240 |
r = ToolsSwingLocator.getDialogReminderManager().add(msgid); |
|
241 |
if( r.hasValue() && ((boolean) r.getValue()) ) { |
|
242 |
return; |
|
243 |
} |
|
244 |
msg = new JMessageWithCheck( |
|
245 |
translate(message, messageArgs), |
|
246 |
ToolsLocator.getI18nManager().getTranslation("_do_not_show_again") |
|
247 |
); |
|
248 |
} |
|
249 |
JOptionPane.showMessageDialog(getRootComponent(), |
|
250 |
msg, translate(title), messageType); |
|
284 | 251 |
|
252 |
if( r != null ) { |
|
253 |
if( ((JMessageWithCheck) msg).isCheckSelected() ) { |
|
254 |
r.setValue(true); |
|
255 |
} else { |
|
256 |
r.reset(); |
|
257 |
} |
|
258 |
} |
|
259 |
|
|
260 |
} |
|
261 |
|
|
262 |
@Override |
|
263 |
public Component createComponent(final Class<? extends Component> theClass, |
|
264 |
final Object... parameters) { |
|
265 |
return createComponentWithParams(theClass, parameters); |
|
266 |
} |
|
267 |
|
|
268 |
@Override |
|
269 |
public Component createComponentWithParams( |
|
270 |
final Class<? extends Component> theClass, final Object[] parameters) { |
|
271 |
final Class<?>[] parameterTypes = new Class<?>[parameters.length]; |
|
272 |
for( int i = 0; i < parameters.length; i++ ) { |
|
273 |
parameterTypes[i] = parameters[i].getClass(); |
|
274 |
} |
|
275 |
final Component component; |
|
276 |
final Constructor<?> constructor; |
|
277 |
try { |
|
278 |
constructor = theClass.getConstructor(parameterTypes); |
|
279 |
} catch (Exception e) { |
|
280 |
throw new IllegalArgumentException(e); |
|
281 |
} |
|
282 |
if( SwingUtilities.isEventDispatchThread() ) { |
|
283 |
try { |
|
284 |
component = (Component) constructor.newInstance(parameters); |
|
285 |
} catch (Exception e) { |
|
286 |
throw new IllegalArgumentException(e); |
|
287 |
} |
|
288 |
} else { |
|
289 |
try { |
|
290 |
RunnableWithParameters runnable = new RunnableWithParameters(parameters) { |
|
291 |
@Override |
|
292 |
public void run() { |
|
293 |
Constructor<?> cons = constructor; |
|
294 |
try { |
|
295 |
this.returnValue = cons.newInstance(parameters.toArray()); |
|
296 |
} catch (Exception e) { |
|
297 |
String msg = "Can't create instance of components, constructor=" + cons.toString() + ", parameters=" + this.parameters.toString() + "."; |
|
298 |
logger.info(msg, e); |
|
299 |
throw new IllegalArgumentException(e); |
|
300 |
} |
|
301 |
} |
|
302 |
}; |
|
303 |
SwingUtilities.invokeAndWait(runnable); |
|
304 |
component = (Component) runnable.getReturnValue(); |
|
305 |
} catch (Exception e) { |
|
306 |
throw new IllegalArgumentException(e); |
|
307 |
} |
|
308 |
} |
|
309 |
return component; |
|
310 |
} |
|
311 |
|
|
312 |
@Override |
|
313 |
public File[] showChooserDialog( |
|
314 |
final String title, |
|
315 |
final int type, // SAVE_DIALOG / OPEN_DIALOG |
|
316 |
final int selectionMode, // JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES |
|
317 |
final boolean multiselection, |
|
318 |
final File initialPath, |
|
319 |
final FileFilter filter, |
|
320 |
final boolean fileHidingEnabled |
|
321 |
) { |
|
322 |
RunnableWithParameters runnable = new RunnableWithParameters() { |
|
323 |
@Override |
|
324 |
public void run() { |
|
325 |
JFileChooser fc = new JFileChooser(); |
|
326 |
fc.setDialogTitle(title); |
|
327 |
fc.setDialogType(type); |
|
328 |
fc.setFileSelectionMode(selectionMode); |
|
329 |
fc.setMultiSelectionEnabled(multiselection); |
|
330 |
fc.setCurrentDirectory(initialPath); |
|
331 |
fc.setFileFilter(filter); |
|
332 |
fc.setFileHidingEnabled(fileHidingEnabled); |
|
333 |
int r; |
|
334 |
switch( type ) { |
|
335 |
case JFileChooser.SAVE_DIALOG: |
|
336 |
r = fc.showSaveDialog(getRootComponent()); |
|
337 |
break; |
|
338 |
case JFileChooser.OPEN_DIALOG: |
|
339 |
default: |
|
340 |
r = fc.showOpenDialog(getRootComponent()); |
|
341 |
break; |
|
342 |
} |
|
343 |
if( r != JFileChooser.APPROVE_OPTION ) { |
|
344 |
this.returnValue = null; |
|
345 |
return; |
|
346 |
} |
|
347 |
if( fc.isMultiSelectionEnabled() ) { |
|
348 |
this.returnValue = fc.getSelectedFiles(); |
|
349 |
} else { |
|
350 |
this.returnValue = new File[]{fc.getSelectedFile()}; |
|
351 |
} |
|
352 |
} |
|
353 |
}; |
|
354 |
if( SwingUtilities.isEventDispatchThread() ) { |
|
355 |
runnable.run(); |
|
356 |
} else { |
|
357 |
try { |
|
358 |
SwingUtilities.invokeAndWait(runnable); |
|
359 |
} catch (Exception e) { |
|
360 |
logger.info("Can't show chooser dialog '" + title + "'.", e); |
|
361 |
} |
|
362 |
} |
|
363 |
return (File[]) runnable.getReturnValue(); |
|
364 |
} |
|
365 |
|
|
366 |
@Override |
|
367 |
public File[] showOpenDirectoryDialog(String title, File initialPath) { |
|
368 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.DIRECTORIES_ONLY, false, initialPath, null, false); |
|
369 |
} |
|
370 |
|
|
371 |
@Override |
|
372 |
public File[] showOpenFileDialog(String title, File initialPath) { |
|
373 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
|
374 |
} |
|
375 |
|
|
376 |
@Override |
|
377 |
public File[] showSaveFileDialog(String title, File initialPath) { |
|
378 |
return showChooserDialog(title, JFileChooser.SAVE_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
|
379 |
} |
|
380 |
|
|
285 | 381 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/ToolsSwingDefaultImplLibrary.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package org.gvsig.tools.swing.impl; |
24 | 24 |
|
25 |
import org.gvsig.tools.dataTypes.DataTypes; |
|
26 | 25 |
import org.gvsig.tools.library.AbstractLibrary; |
27 | 26 |
import org.gvsig.tools.library.Library; |
28 | 27 |
import org.gvsig.tools.library.LibraryException; |
29 |
import org.gvsig.tools.service.spi.ServiceManager; |
|
30 | 28 |
import org.gvsig.tools.swing.api.ToolsSwingLibrary; |
31 | 29 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
32 | 30 |
import org.gvsig.tools.swing.impl.component.DefaultComponentSwingManager; |
31 |
import org.gvsig.tools.swing.impl.dialogreminder.DefaultDialogReminderManager; |
|
33 | 32 |
import org.gvsig.tools.swing.impl.icontheme.DefaultIconThemeManager; |
34 | 33 |
import org.gvsig.tools.swing.impl.task.DefaultTaskStatusSwingManager; |
35 | 34 |
import org.gvsig.tools.swing.impl.threadsafedialogs.DefaultThreadSafeDialogsManager; |
... | ... | |
51 | 50 |
|
52 | 51 |
@Override |
53 | 52 |
protected void doInitialize() throws LibraryException { |
54 |
ToolsSwingLocator |
|
55 |
.registerUsabilitySwingManager(DefaultUsabilitySwingManager.class); |
|
56 |
ToolsSwingLocator |
|
57 |
.registerTaskStatusSwingManager(DefaultTaskStatusSwingManager.class); |
|
58 |
ToolsSwingLocator |
|
59 |
.registerWindowManager(DefaultWindowManager.class); |
|
53 |
ToolsSwingLocator.registerUsabilitySwingManager(DefaultUsabilitySwingManager.class); |
|
54 |
ToolsSwingLocator.registerTaskStatusSwingManager(DefaultTaskStatusSwingManager.class); |
|
55 |
ToolsSwingLocator.registerWindowManager(DefaultWindowManager.class); |
|
60 | 56 |
ToolsSwingLocator.registerIconThemeManager(DefaultIconThemeManager.class); |
61 |
|
|
62 |
ToolsSwingLocator.registerComponentSwingManager( |
|
63 |
DefaultComponentSwingManager.class); |
|
64 |
|
|
57 |
ToolsSwingLocator.registerComponentSwingManager(DefaultComponentSwingManager.class); |
|
65 | 58 |
ToolsSwingLocator.registerThreadSafeDialogsManager(DefaultThreadSafeDialogsManager.class); |
66 |
|
|
67 | 59 |
ToolsSwingLocator.registerToolsSwingManager(DefaultToolsSwingManager.class); |
68 |
|
|
60 |
ToolsSwingLocator.registerDefaultDialogReminderManager(DefaultDialogReminderManager.class); |
|
69 | 61 |
} |
70 | 62 |
|
71 | 63 |
@Override |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/dialogreminder/DefaultDialogReminder.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.tools.swing.impl.dialogreminder; |
|
3 |
|
|
4 |
import org.gvsig.tools.swing.api.reminder.DialogReminder; |
|
5 |
|
|
6 |
|
|
7 |
public class DefaultDialogReminder implements DialogReminder { |
|
8 |
private final String id; |
|
9 |
private Object value; |
|
10 |
|
|
11 |
public DefaultDialogReminder(String id) { |
|
12 |
this.id = id; |
|
13 |
this.value = null; |
|
14 |
} |
|
15 |
@Override |
|
16 |
public String getId() { |
|
17 |
return id; |
|
18 |
} |
|
19 |
|
|
20 |
@Override |
|
21 |
public Object getValue() { |
|
22 |
return this.value; |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public void reset() { |
|
27 |
this.value = null; |
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public boolean hasValue() { |
|
32 |
return this.value!=null; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public void setValue(Object value) { |
|
37 |
this.value = value; |
|
38 |
} |
|
39 |
|
|
40 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/dialogreminder/DefaultDialogReminderManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.tools.swing.impl.dialogreminder; |
|
3 |
|
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Collections; |
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.Iterator; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
import org.gvsig.tools.swing.api.reminder.DialogReminder; |
|
11 |
import org.gvsig.tools.swing.api.reminder.DialogReminderManager; |
|
12 |
|
|
13 |
|
|
14 |
public class DefaultDialogReminderManager implements DialogReminderManager { |
|
15 |
|
|
16 |
private Map<String,DialogReminder> remembers; |
|
17 |
|
|
18 |
public DefaultDialogReminderManager() { |
|
19 |
this.remembers = new HashMap<>(); |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public boolean exists(String id) { |
|
24 |
return this.remembers.containsKey(id); |
|
25 |
} |
|
26 |
|
|
27 |
@Override |
|
28 |
public DialogReminder get(String id) { |
|
29 |
return this.remembers.get(id); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public DialogReminder add(String id) { |
|
34 |
DialogReminder r = this.get(id); |
|
35 |
if( r == null ) { |
|
36 |
r = new DefaultDialogReminder(id); |
|
37 |
this.remembers.put(id, r); |
|
38 |
} |
|
39 |
return r; |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
public DialogReminder add(String id, int value) { |
|
44 |
DialogReminder r = this.add(id); |
|
45 |
r.setValue(value); |
|
46 |
return r; |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
public Iterator<DialogReminder> iterator() { |
|
51 |
return this.remembers.values().iterator(); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public List<DialogReminder> reminders() { |
|
56 |
return Collections.unmodifiableList(new ArrayList<>(this.remembers.values())); |
|
57 |
} |
|
58 |
|
|
59 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/reminder/DialogReminder.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.tools.swing.api.reminder; |
|
3 |
|
|
4 |
|
|
5 |
public interface DialogReminder { |
|
6 |
|
|
7 |
public String getId(); |
|
8 |
|
|
9 |
public Object getValue(); |
|
10 |
|
|
11 |
public void setValue(Object value); |
|
12 |
|
|
13 |
public void reset(); |
|
14 |
|
|
15 |
public boolean hasValue(); |
|
16 |
|
|
17 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/reminder/DialogReminderManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.tools.swing.api.reminder; |
|
3 |
|
|
4 |
import java.util.Iterator; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
|
|
8 |
public interface DialogReminderManager extends Iterable<DialogReminder> { |
|
9 |
|
|
10 |
public boolean exists(String id); |
|
11 |
|
|
12 |
public DialogReminder get(String id); |
|
13 |
|
|
14 |
public DialogReminder add(String id); |
|
15 |
|
|
16 |
public DialogReminder add(String id, int value); |
|
17 |
|
|
18 |
@Override |
|
19 |
public Iterator<DialogReminder> iterator(); |
|
20 |
|
|
21 |
public List<DialogReminder> reminders(); |
|
22 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/threadsafedialogs/ThreadSafeDialogsManager.java | ||
---|---|---|
60 | 60 |
* @see javax.swing.JOptionPane#showMessageDialog(Component, Object, String, int) |
61 | 61 |
*/ |
62 | 62 |
public void messageDialog(String message, String messageArgs[], String title, int messageType); |
63 |
|
|
64 |
public void messageDialog(String message, String messageArgs[], String title, int messageType, String msgid); |
|
63 | 65 |
|
64 | 66 |
/** |
65 | 67 |
* Show a JOptionPane confirm dialog. |
... | ... | |
78 | 80 |
* |
79 | 81 |
*/ |
80 | 82 |
public int confirmDialog(String message, String title, int optionType, int messageType) ; |
83 |
|
|
84 |
public int confirmDialog(String message, String title, int optionType, int messageType, String msgid) ; |
|
81 | 85 |
|
82 | 86 |
/** |
83 | 87 |
* Show a JOptionPane input dialog. |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/ToolsSwingLocator.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import org.gvsig.tools.locator.BaseLocator; |
27 | 27 |
import org.gvsig.tools.locator.Locator; |
28 |
import org.gvsig.tools.locator.LocatorException; |
|
28 | 29 |
import org.gvsig.tools.swing.api.evaluator.ComponentSwingManager; |
30 |
import org.gvsig.tools.swing.api.reminder.DialogReminderManager; |
|
29 | 31 |
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager; |
30 | 32 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
31 | 33 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
... | ... | |
73 | 75 |
|
74 | 76 |
private static final String SWING_MANAGER_DESCRIPTION = "Tools Swing Manager"; |
75 | 77 |
|
78 |
public static final String PLUGINS_DIALOGREMINDER_MANAGER_NAME = "DialogReminderManager"; |
|
79 |
private static final String PLUGINS_DIALOGREMINDER_MANAGER_DESCRIPTION = "DialogReminderManager"; |
|
80 |
|
|
76 | 81 |
/** |
77 | 82 |
* Unique instance. |
78 | 83 |
*/ |
... | ... | |
259 | 264 |
getInstance().register(SWING_MANAGER_NAME, |
260 | 265 |
SWING_MANAGER_DESCRIPTION, clazz); |
261 | 266 |
} |
267 |
|
|
268 |
//Dialog reminder |
|
269 |
public static DialogReminderManager getDialogReminderManager() throws LocatorException { |
|
270 |
return (DialogReminderManager) getInstance().get(PLUGINS_DIALOGREMINDER_MANAGER_NAME); |
|
271 |
} |
|
262 | 272 |
|
273 |
public static void registerDialogReminderManager(Class clazz) { |
|
274 |
getInstance().register(PLUGINS_DIALOGREMINDER_MANAGER_NAME, PLUGINS_DIALOGREMINDER_MANAGER_DESCRIPTION, |
|
275 |
clazz); |
|
276 |
} |
|
277 |
|
|
278 |
public static void registerDefaultDialogReminderManager(Class clazz) { |
|
279 |
getInstance().registerDefault(PLUGINS_DIALOGREMINDER_MANAGER_NAME, PLUGINS_DIALOGREMINDER_MANAGER_DESCRIPTION, |
|
280 |
clazz); |
|
281 |
} |
|
263 | 282 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.impl/src/main/java/org/gvsig/tools/util/impl/ToolsUtilLibraryImpl.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package org.gvsig.tools.util.impl; |
24 | 24 |
|
25 |
import org.gvsig.dialogreminder.impl.DefaultDialogReminderManager; |
|
26 | 25 |
import org.gvsig.filedialogchooser.impl.DefaultFileDialogChooserManager; |
27 | 26 |
import org.gvsig.svgsupport.DumbSVGSupportManager; |
28 | 27 |
import org.gvsig.tools.library.AbstractLibrary; |
... | ... | |
47 | 46 |
@Override |
48 | 47 |
protected void doInitialize() throws LibraryException { |
49 | 48 |
ToolsUtilLocator.registerDefaultToolsUtilManager(DefaultToolsUtilManager.class); |
50 |
ToolsUtilLocator.registerDefaultDialogReminderManager(DefaultDialogReminderManager.class); |
|
51 | 49 |
ToolsUtilLocator.registerDefaultFileDialogChooserManager(DefaultFileDialogChooserManager.class); |
52 | 50 |
ToolsUtilLocator.registerDefaultSVGSupportManager(DumbSVGSupportManager.class); |
53 | 51 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.util/org.gvsig.tools.util.api/src/main/java/org/gvsig/tools/util/ToolsUtilLocator.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
|
27 | 27 |
import org.gvsig.filedialogchooser.FileDialogChooserManager; |
28 |
import org.gvsig.reminder.DialogReminderManager; |
|
29 | 28 |
import org.gvsig.svgsupport.SVGSupportManager; |
30 | 29 |
import org.gvsig.tools.locator.AbstractLocator; |
31 | 30 |
import org.gvsig.tools.locator.Locator; |
... | ... | |
46 | 45 |
public static final String FILE_DIALOG_CHOOSER_MANAGER_NAME = "org.gvsig.filedialogchooser.manager"; |
47 | 46 |
private static final String FILE_DIALOG_CHOOSER_MANAGER_DESCRIPTION = "File dialog chooser."; |
48 | 47 |
|
49 |
public static final String PLUGINS_DIALOGREMINDER_MANAGER_NAME = "DialogReminderManager"; |
|
50 |
private static final String PLUGINS_DIALOGREMINDER_MANAGER_DESCRIPTION = "DialogReminderManager"; |
|
51 |
|
|
52 | 48 |
public static final String PLUGINS_SVGSUPPORT_MANAGER_NAME = "SVGSupportManager"; |
53 | 49 |
private static final String PLUGINS_SVGSUPPORT_MANAGER_DESCRIPTION = "SVGSupportManager"; |
54 | 50 |
|
... | ... | |
116 | 112 |
FILE_DIALOG_CHOOSER_MANAGER_DESCRIPTION, clazz); |
117 | 113 |
} |
118 | 114 |
|
119 |
//Dialog reminder |
|
120 |
public static DialogReminderManager getDialogReminderManager() throws LocatorException { |
|
121 |
return (DialogReminderManager) getInstance().get(PLUGINS_DIALOGREMINDER_MANAGER_NAME); |
|
122 |
} |
|
123 |
|
|
124 |
public static void registerDialogReminderManager(Class clazz) { |
|
125 |
getInstance().register(PLUGINS_DIALOGREMINDER_MANAGER_NAME, PLUGINS_DIALOGREMINDER_MANAGER_DESCRIPTION, |
|
126 |
clazz); |
|
127 |
} |
|
128 |
|
|
129 |
public static void registerDefaultDialogReminderManager(Class clazz) { |
|
130 |
getInstance().registerDefault(PLUGINS_DIALOGREMINDER_MANAGER_NAME, PLUGINS_DIALOGREMINDER_MANAGER_DESCRIPTION, |
|
131 |
clazz); |
|
132 |
} |
|
133 |
|
|
134 | 115 |
//SVG support |
135 | 116 |
public static SVGSupportManager getSVGSupportManager() throws LocatorException { |
136 | 117 |
return (SVGSupportManager) getInstance().get(PLUGINS_SVGSUPPORT_MANAGER_NAME); |
Also available in: Unified diff