root / branches / v2_0_0_prep / libraries / org.gvsig.annotation / org.gvsig.annotation.swing / org.gvsig.annotation.swing.impl / src / main / java / org / gvsig / annotation / swing / impl / DefaultJAnnotationCreationServicePanel.java @ 36679
History | View | Annotate | Download (7.35 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.annotation.swing.impl; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.net.URL; |
26 |
|
27 |
import javax.swing.ImageIcon; |
28 |
import javax.swing.JOptionPane; |
29 |
|
30 |
import org.slf4j.Logger; |
31 |
import org.slf4j.LoggerFactory; |
32 |
|
33 |
import org.gvsig.annotation.AnnotationCreationException; |
34 |
import org.gvsig.annotation.AnnotationCreationService; |
35 |
import org.gvsig.annotation.AnnotationCreationServiceException; |
36 |
import org.gvsig.annotation.swing.AnnotationSwingManager; |
37 |
import org.gvsig.annotation.swing.JAnnotationCreationServicePanel; |
38 |
import org.gvsig.annotation.swing.impl.wizard.AnnotationProgressWizard; |
39 |
import org.gvsig.annotation.swing.impl.wizard.MainOptionsWizard; |
40 |
import org.gvsig.annotation.swing.impl.wizard.OptionalOptionsWizard; |
41 |
import org.gvsig.annotation.swing.impl.wizard.SelectOutputFileWizard; |
42 |
import org.gvsig.fmap.dal.exception.DataException; |
43 |
import org.gvsig.gui.beans.wizard.WizardPanel; |
44 |
import org.gvsig.gui.beans.wizard.WizardPanelActionListener; |
45 |
import org.gvsig.gui.beans.wizard.WizardPanelWithLogo; |
46 |
import org.gvsig.i18n.Messages; |
47 |
import org.gvsig.tools.service.ServiceException; |
48 |
import org.gvsig.tools.task.TaskStatus; |
49 |
|
50 |
/**
|
51 |
* Default implementation for the {@link JAnnotationCreationServicePanel}.
|
52 |
*
|
53 |
* @author gvSIG Team
|
54 |
* @version $Id$
|
55 |
*/
|
56 |
public class DefaultJAnnotationCreationServicePanel extends JAnnotationCreationServicePanel implements WizardPanel{ |
57 |
|
58 |
private static final Logger LOG = |
59 |
LoggerFactory.getLogger(DefaultJAnnotationCreationServicePanel.class); |
60 |
|
61 |
private static final long serialVersionUID = 2965442763236823977L; |
62 |
|
63 |
private AnnotationCreationService annotationCreationService;
|
64 |
private AnnotationSwingManager annotationSwingManager;
|
65 |
|
66 |
private WizardPanelWithLogo wizardPanelWithLogo = null; |
67 |
|
68 |
private MainOptionsWizard mainOptionsWizard = null; |
69 |
private OptionalOptionsWizard optionalOptionsWizard = null; |
70 |
private SelectOutputFileWizard selectOutputFileWizard = null; |
71 |
private AnnotationProgressWizard annotationProgressWizard = null; |
72 |
|
73 |
private WizardListenerAdapter wizardListenerAdapter = null; |
74 |
|
75 |
public DefaultJAnnotationCreationServicePanel(
|
76 |
DefaultAnnotationSwingManager annotationSwingManager, AnnotationCreationService annotationCreationService) throws ServiceException {
|
77 |
|
78 |
super();
|
79 |
|
80 |
URL iconURL = getClass().getClassLoader().getResource("org/gvsig/annotation/swing/impl/images/wizard-icon.png"); |
81 |
ImageIcon icon = new ImageIcon(iconURL); |
82 |
wizardPanelWithLogo = new WizardPanelWithLogo(icon);
|
83 |
|
84 |
this.annotationCreationService = annotationCreationService;
|
85 |
this.annotationSwingManager = annotationSwingManager;
|
86 |
|
87 |
try {
|
88 |
mainOptionsWizard = new MainOptionsWizard(this); |
89 |
optionalOptionsWizard = new OptionalOptionsWizard(this); |
90 |
selectOutputFileWizard = new SelectOutputFileWizard(this); |
91 |
annotationProgressWizard = new AnnotationProgressWizard(this); |
92 |
} catch (DataException e) {
|
93 |
new AnnotationCreationServiceException("Exception creating the wizard forms", e); |
94 |
} |
95 |
|
96 |
|
97 |
addWizards(); |
98 |
|
99 |
//Adding the listener
|
100 |
wizardPanelWithLogo.setWizardListener(this);
|
101 |
|
102 |
setFinishButtonEnabled(false);
|
103 |
|
104 |
wizardPanelWithLogo.getWizardComponents().getFinishButton().setText(Messages.getText("Comenzar"));
|
105 |
|
106 |
this.setLayout(new BorderLayout()); |
107 |
this.add(wizardPanelWithLogo, BorderLayout.CENTER); |
108 |
} |
109 |
|
110 |
private void addWizards(){ |
111 |
wizardPanelWithLogo.addOptionPanel(mainOptionsWizard); |
112 |
wizardPanelWithLogo.addOptionPanel(optionalOptionsWizard); |
113 |
wizardPanelWithLogo.addOptionPanel(selectOutputFileWizard); |
114 |
wizardPanelWithLogo.addOptionPanel(annotationProgressWizard); |
115 |
} |
116 |
|
117 |
|
118 |
@Override
|
119 |
public AnnotationCreationService getAnnotationCreationService() {
|
120 |
return annotationCreationService;
|
121 |
} |
122 |
|
123 |
public void setFinishButtonEnabled(boolean isEnabled){ |
124 |
wizardPanelWithLogo.setFinishButtonEnabled(isEnabled); |
125 |
} |
126 |
|
127 |
public void setCancellButtonEnabled(boolean isEnabled){ |
128 |
wizardPanelWithLogo.setCancelButtonEnabled(isEnabled); |
129 |
} |
130 |
|
131 |
public String getTextValueAttribute(){ |
132 |
return mainOptionsWizard.getTextValueAttribute();
|
133 |
} |
134 |
|
135 |
public WizardPanelActionListener getWizardPanelActionListener() {
|
136 |
if ((wizardListenerAdapter == null && (getAnnotationServicePanelActionListener() != null))){ |
137 |
return new WizardListenerAdapter(this); |
138 |
} |
139 |
return wizardListenerAdapter;
|
140 |
} |
141 |
|
142 |
public void setWizardPanelActionListener( |
143 |
WizardPanelActionListener wizardActionListener) { |
144 |
// TODO Auto-generated method stub
|
145 |
} |
146 |
|
147 |
public String getDestinationShapeFile() { |
148 |
return selectOutputFileWizard.getSelectedFileName();
|
149 |
} |
150 |
|
151 |
public void setNextButtonEnabled(boolean isEnabled){ |
152 |
wizardPanelWithLogo.setNextButtonEnabled(isEnabled); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* @return the annotationSwingManager
|
157 |
*/
|
158 |
public AnnotationSwingManager getAnnotationSwingManager() {
|
159 |
return annotationSwingManager;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* @param translation
|
164 |
*/
|
165 |
public void setCancelButtonText(String translation) { |
166 |
wizardPanelWithLogo.getWizardComponents().getCancelButton().setText(translation); |
167 |
} |
168 |
|
169 |
public void createAnnotation() { |
170 |
this.lastWizard();
|
171 |
|
172 |
Annotation annotation = new Annotation(getDestinationShapeFile(), getTextValueAttribute()); |
173 |
annotation.start(); |
174 |
} |
175 |
|
176 |
public void lastWizard() { |
177 |
this.wizardPanelWithLogo.getWizardComponents().getNextButton().getActionListeners()[0].actionPerformed(null); |
178 |
} |
179 |
|
180 |
private class Annotation extends Thread{ |
181 |
private String file; |
182 |
private String textValueAttributeName; |
183 |
|
184 |
public Annotation(String file, String textValueAttributeName) { |
185 |
super();
|
186 |
this.file = file;
|
187 |
this.textValueAttributeName = textValueAttributeName;
|
188 |
} |
189 |
|
190 |
public synchronized void run() { |
191 |
AnnotationCreationService annotationCreationService = getAnnotationCreationService(); |
192 |
annotationProgressWizard.bind(annotationCreationService.getTaskStatus()); |
193 |
try {
|
194 |
annotationCreationService.createAnnotationStore(file, textValueAttributeName); |
195 |
} catch (AnnotationCreationException e) {
|
196 |
LOG.error("Error creating the annotation", e);
|
197 |
showError(e, annotationCreationService.getTaskStatus()); |
198 |
} |
199 |
} |
200 |
} |
201 |
|
202 |
private void showError(AnnotationCreationException e, TaskStatus taskStatus){ |
203 |
String message = e.getMessage();
|
204 |
if (e.getCause() != null){ |
205 |
message = e.getCause().getMessage(); |
206 |
} |
207 |
JOptionPane.showMessageDialog(annotationProgressWizard, message);
|
208 |
} |
209 |
} |