Revision 44386 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/java/org/gvsig/export/swing/impl/DefaultJExportProcessPanel.java
DefaultJExportProcessPanel.java | ||
---|---|---|
27 | 27 |
import java.awt.Dimension; |
28 | 28 |
import java.awt.event.ActionEvent; |
29 | 29 |
import java.awt.event.ActionListener; |
30 |
import java.util.Date; |
|
30 | 31 |
import java.util.HashSet; |
31 | 32 |
import java.util.Set; |
33 |
import java.util.logging.Level; |
|
32 | 34 |
import javax.swing.JButton; |
33 | 35 |
|
34 | 36 |
import javax.swing.JComponent; |
... | ... | |
38 | 40 |
import jwizardcomponent.DefaultJWizardComponents; |
39 | 41 |
|
40 | 42 |
import org.gvsig.export.ExportException; |
43 |
import org.gvsig.export.ExportLocator; |
|
41 | 44 |
import org.slf4j.Logger; |
42 | 45 |
import org.slf4j.LoggerFactory; |
43 | 46 |
|
44 | 47 |
import org.gvsig.fmap.dal.feature.Feature; |
45 | 48 |
import org.gvsig.gui.beans.wizard.WizardPanel; |
46 | 49 |
import org.gvsig.gui.beans.wizard.WizardPanelActionListener; |
47 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
|
48 | 50 |
import org.gvsig.tools.ToolsLocator; |
49 | 51 |
import org.gvsig.tools.i18n.I18nManager; |
50 | 52 |
import org.gvsig.export.ExportParameters; |
51 | 53 |
import org.gvsig.export.ExportProcess; |
52 | 54 |
import org.gvsig.export.Filter; |
53 | 55 |
import org.gvsig.export.spi.ExportServiceFactory; |
56 |
import org.gvsig.export.spi.ExportServiceManager; |
|
54 | 57 |
import org.gvsig.export.swing.ExportSwingLocator; |
55 | 58 |
import org.gvsig.export.swing.JExportProcessPanel; |
56 | 59 |
import org.gvsig.export.swing.impl.panels.ExportProgressPanel; |
... | ... | |
61 | 64 |
import org.gvsig.export.swing.spi.ExportPanelsManager; |
62 | 65 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
63 | 66 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
67 |
import org.gvsig.tools.bookmarksandhistory.History; |
|
64 | 68 |
|
65 | 69 |
/** |
66 | 70 |
* Default implementation for the {@link JExportProcessPanel}. |
... | ... | |
68 | 72 |
* @author gvSIG Team |
69 | 73 |
* @version $Id$ |
70 | 74 |
*/ |
71 |
public class DefaultJExportProcessPanel
|
|
75 |
public class DefaultJExportProcessPanel |
|
72 | 76 |
extends JPanel |
73 |
implements JExportProcessPanel, WizardPanel |
|
74 |
{ |
|
77 |
implements JExportProcessPanel, WizardPanel { |
|
75 | 78 |
|
76 | 79 |
private static final Logger LOG = LoggerFactory.getLogger(DefaultJExportProcessPanel.class); |
77 | 80 |
|
... | ... | |
81 | 84 |
private WizardPanelWithLogo wizardPanel; |
82 | 85 |
private WizardPanelActionListener wizardListener; |
83 | 86 |
private int lastAction; |
84 |
|
|
85 |
|
|
87 |
|
|
86 | 88 |
public DefaultJExportProcessPanel( |
87 |
ExportProcess process,
|
|
89 |
ExportProcess process, |
|
88 | 90 |
Filter<ExportServiceFactory> serviceFilter |
89 |
) {
|
|
91 |
) { |
|
90 | 92 |
this.process = process; |
91 | 93 |
this.serviceFilter = serviceFilter; |
92 | 94 |
this.finishListeners = new HashSet<>(); |
93 | 95 |
this.initComponents(); |
94 | 96 |
} |
95 |
|
|
97 |
|
|
96 | 98 |
private void initComponents() { |
97 | 99 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
98 |
|
|
100 |
|
|
99 | 101 |
this.wizardPanel = new WizardPanelWithLogo(); |
100 | 102 |
this.addPanel( |
101 |
new SelectFormatPanel( |
|
102 |
this, |
|
103 |
this.process.getParameters(),
|
|
104 |
this.serviceFilter,
|
|
105 |
new ActionListener() { |
|
103 |
new SelectFormatPanel(
|
|
104 |
this,
|
|
105 |
this.process.getParameters(),
|
|
106 |
this.serviceFilter,
|
|
107 |
new ActionListener() {
|
|
106 | 108 |
@Override |
107 | 109 |
public void actionPerformed(ActionEvent e) { |
108 |
doAddPanels(((SelectFormatPanel)(e.getSource())).getSelectedService()); |
|
110 |
doAddPanels(((SelectFormatPanel) (e.getSource())).getSelectedService());
|
|
109 | 111 |
} |
110 | 112 |
} |
111 |
) |
|
112 |
);
|
|
113 |
)
|
|
114 |
); |
|
113 | 115 |
this.setLayout(new BorderLayout()); |
114 | 116 |
this.add(this.wizardPanel, BorderLayout.CENTER); |
115 | 117 |
this.wizardPanel.setFinishButtonText(i18n.getTranslation("export")); |
... | ... | |
120 | 122 |
this.wizardPanel.setFinishButtonEnabled(false); |
121 | 123 |
this.setPreferredSize(new Dimension(600, 350)); |
122 | 124 |
} |
123 |
|
|
125 |
|
|
124 | 126 |
private void addPanel(ExportPanel panel) { |
125 | 127 |
OptionPanel optionPanel = new WizardOptionPanelAdapter(this, panel); |
126 | 128 |
this.wizardPanel.addOptionPanel(optionPanel); |
127 | 129 |
} |
128 |
|
|
130 |
|
|
129 | 131 |
private void doAddPanels(ExportServiceFactory serviceFactory) { |
130 |
|
|
132 |
|
|
131 | 133 |
try { |
132 | 134 |
removePreviousPanels(); |
135 |
if (this.process.getParameters() != null) { |
|
136 |
if (this.process.getParameters().getServiceName() != serviceFactory.getName()) { |
|
137 |
this.process.setParameters(null); |
|
138 |
} |
|
139 |
} |
|
133 | 140 |
|
134 |
this.process.setOutputFormat(serviceFactory.getName()); |
|
141 |
if (this.process.getParameters()==null) { |
|
142 |
this.process.setOutputFormat(serviceFactory.getName()); |
|
143 |
} |
|
144 |
|
|
145 |
|
|
135 | 146 |
ExportParameters parameters = this.process.getParameters(); |
136 |
|
|
147 |
|
|
137 | 148 |
ExportPanelsManager panelsManager = ExportSwingLocator.getExportPanelsManager(); |
138 | 149 |
ExportPanelsFactory panelsFactory = panelsManager.getPanelsFactory(serviceFactory.getName()); |
139 | 150 |
ExportPanels panels = panelsFactory.createPanels(this, parameters); |
140 | 151 |
for (ExportPanel panel : panels) { |
141 | 152 |
this.addPanel(panel); |
142 | 153 |
} |
143 |
if( parameters.needsSelectTargetProjection() ) {
|
|
144 |
if( ! panels.contains(ExportPanelsManager.PANEL_SELECT_TARGET_PROJECTION) ) {
|
|
145 |
this.addPanel( panelsManager.createStandardPanel(
|
|
154 |
if (parameters.needsSelectTargetProjection()) {
|
|
155 |
if (!panels.contains(ExportPanelsManager.PANEL_SELECT_TARGET_PROJECTION)) {
|
|
156 |
this.addPanel(panelsManager.createStandardPanel( |
|
146 | 157 |
ExportPanelsManager.PANEL_SELECT_TARGET_PROJECTION, |
147 | 158 |
this, |
148 | 159 |
parameters |
149 |
)
|
|
160 |
) |
|
150 | 161 |
); |
151 | 162 |
} |
152 | 163 |
} |
153 |
if( ! panels.contains(ExportPanelsManager.PANEL_SELECT_FILTER) ) {
|
|
154 |
this.addPanel( panelsManager.createStandardPanel(
|
|
164 |
if (!panels.contains(ExportPanelsManager.PANEL_SELECT_FILTER)) {
|
|
165 |
this.addPanel(panelsManager.createStandardPanel( |
|
155 | 166 |
ExportPanelsManager.PANEL_SELECT_FILTER, |
156 | 167 |
this, |
157 | 168 |
parameters |
158 |
)
|
|
169 |
) |
|
159 | 170 |
); |
160 | 171 |
} |
161 | 172 |
this.addPanel(new ExportProgressPanel(this, parameters)); |
162 | 173 |
|
163 | 174 |
} catch (ExportException ex) { |
164 |
LOG.warn("Can't add panels to wizard.",ex); |
|
175 |
LOG.warn("Can't add panels to wizard.", ex);
|
|
165 | 176 |
showError(ex); |
166 | 177 |
} |
167 | 178 |
} |
168 |
|
|
179 |
|
|
169 | 180 |
@Override |
170 | 181 |
public ExportProcess getProcess() { |
171 | 182 |
return this.process; |
... | ... | |
175 | 186 |
public ExportParameters getParameters() { |
176 | 187 |
return this.process.getParameters(); |
177 | 188 |
} |
178 |
|
|
189 |
|
|
179 | 190 |
@Override |
180 | 191 |
public void setWizardPanelActionListener( |
181 | 192 |
WizardPanelActionListener wizardListener |
182 |
) {
|
|
193 |
) { |
|
183 | 194 |
this.wizardListener = wizardListener; |
184 | 195 |
} |
185 | 196 |
|
... | ... | |
205 | 216 |
DefaultJWizardComponents wizardComponents = wizardPanel.getWizardComponents(); |
206 | 217 |
for (int i = wizardComponents.getWizardPanelList().size() - 1; i >= 1; i--) { |
207 | 218 |
wizardComponents.removeWizardPanel(i); |
208 |
}
|
|
219 |
} |
|
209 | 220 |
} |
210 |
|
|
221 |
|
|
211 | 222 |
private void lastWizard() { |
212 | 223 |
this.wizardPanel.getWizardComponents().getNextButton() |
213 |
.getActionListeners()[0].actionPerformed(null); |
|
214 |
}
|
|
224 |
.getActionListeners()[0].actionPerformed(null);
|
|
225 |
} |
|
215 | 226 |
|
216 | 227 |
private void showError(Exception e) { |
217 | 228 |
Feature f = null; |
218 |
if( e instanceof ExportException ) {
|
|
219 |
f = ((ExportException)e).getFeature(); |
|
229 |
if (e instanceof ExportException) {
|
|
230 |
f = ((ExportException) e).getFeature();
|
|
220 | 231 |
} |
221 | 232 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
222 | 233 |
MessagePanel.showMessage( |
... | ... | |
226 | 237 |
f |
227 | 238 |
); |
228 | 239 |
} |
229 |
|
|
240 |
|
|
230 | 241 |
@Override |
231 | 242 |
public void addFinishListener(ExportFinishListener finishListener) { |
232 | 243 |
this.finishListeners.add(finishListener); |
233 | 244 |
} |
234 | 245 |
|
235 | 246 |
private void fireCancelled() { |
236 |
if( ! SwingUtilities.isEventDispatchThread() ) {
|
|
247 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
237 | 248 |
SwingUtilities.invokeLater(new Runnable() { |
238 | 249 |
@Override |
239 | 250 |
public void run() { |
... | ... | |
244 | 255 |
for (ExportFinishListener listener : this.finishListeners) { |
245 | 256 |
try { |
246 | 257 |
listener.cancelled(this); |
247 |
} catch(Exception ex) { |
|
248 |
|
|
258 |
} catch (Exception ex) {
|
|
259 |
|
|
249 | 260 |
} |
250 | 261 |
} |
251 | 262 |
} |
252 |
|
|
263 |
|
|
253 | 264 |
private void fireFinished() { |
254 |
if( ! SwingUtilities.isEventDispatchThread() ) {
|
|
265 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
255 | 266 |
SwingUtilities.invokeLater(new Runnable() { |
256 | 267 |
@Override |
257 | 268 |
public void run() { |
... | ... | |
263 | 274 |
for (ExportFinishListener listener : this.finishListeners) { |
264 | 275 |
try { |
265 | 276 |
listener.finished(this); |
266 |
} catch(Exception ex) { |
|
267 |
|
|
277 |
} catch (Exception ex) {
|
|
278 |
|
|
268 | 279 |
} |
269 | 280 |
} |
270 | 281 |
} |
271 |
|
|
282 |
|
|
272 | 283 |
private void doCancel() { |
273 | 284 |
this.setVisible(false); |
274 | 285 |
this.fireCancelled(); |
275 | 286 |
} |
276 |
|
|
287 |
|
|
277 | 288 |
private void doExport() { |
278 | 289 |
lastWizard(); |
290 |
ExportParameters params = this.process.getParameters(); |
|
291 |
ExportServiceManager ems = ExportLocator.getServiceManager(); |
|
292 |
|
|
293 |
ExportParameters copyParams = null; |
|
294 |
try { |
|
295 |
copyParams = (ExportParameters) params.clone(); |
|
296 |
History<ExportParameters> h = ems.getHistory(); |
|
297 |
h.add(copyParams); |
|
298 |
} catch (CloneNotSupportedException ex) { |
|
299 |
LOG.error("Not able to create a clone object for export parameters", ex); |
|
300 |
} |
|
301 |
|
|
279 | 302 |
Thread th = new Thread( |
280 |
new Runnable() { |
|
281 |
@Override |
|
282 |
public void run() { |
|
283 |
try { |
|
284 |
process.run(); |
|
285 |
doProcessFinished(); |
|
286 |
} catch(Exception ex) { |
|
287 |
LOG.warn("Can't export",ex); |
|
288 |
showError(ex); |
|
289 |
} |
|
303 |
new Runnable() { |
|
304 |
@Override |
|
305 |
public void run() { |
|
306 |
try { |
|
307 |
process.run(); |
|
308 |
doProcessFinished(); |
|
309 |
} catch (Exception ex) { |
|
310 |
LOG.warn("Can't export", ex); |
|
311 |
showError(ex); |
|
290 | 312 |
} |
291 |
}, |
|
292 |
"exportProcess" |
|
313 |
} |
|
314 |
}, |
|
315 |
"exportProcess" |
|
293 | 316 |
); |
294 | 317 |
th.start(); |
295 | 318 |
} |
296 |
|
|
297 |
private void doProcessFinished() {
|
|
319 |
|
|
320 |
private void doProcessFinished() { |
|
298 | 321 |
fireFinished(); |
299 | 322 |
} |
300 | 323 |
|
... | ... | |
304 | 327 |
} |
305 | 328 |
|
306 | 329 |
private JButton getButton(int button) { |
307 |
switch(button) { |
|
330 |
switch (button) {
|
|
308 | 331 |
case BUTTON_BACK: |
309 | 332 |
return this.wizardPanel.getWizardComponents().getBackButton(); |
310 | 333 |
case BUTTON_NEXT: |
... | ... | |
314 | 337 |
case BUTTON_CANCEL: |
315 | 338 |
return this.wizardPanel.getWizardComponents().getCancelButton(); |
316 | 339 |
} |
317 |
throw new IllegalArgumentException("Illegal button value ("+button+").");
|
|
340 |
throw new IllegalArgumentException("Illegal button value (" + button + ").");
|
|
318 | 341 |
} |
319 |
|
|
342 |
|
|
320 | 343 |
@Override |
321 | 344 |
public void setButtonEnabled(int button, boolean enabled) { |
322 | 345 |
this.getButton(button).setEnabled(enabled); |
... | ... | |
340 | 363 |
public void setLastAcction(int action) { |
341 | 364 |
this.lastAction = action; |
342 | 365 |
} |
343 |
|
|
366 |
|
|
344 | 367 |
public int getLastAction() { |
345 | 368 |
return this.lastAction; |
346 | 369 |
} |
... | ... | |
354 | 377 |
public void previousPanel() { |
355 | 378 |
this.wizardPanel.doAction(WizardPanelWithLogo.ACTION_PREVIOUS); |
356 | 379 |
} |
357 |
|
|
380 |
|
|
358 | 381 |
} |
Also available in: Unified diff