Revision 30144 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/view/legend/gui/LegendManager.java
LegendManager.java | ||
---|---|---|
49 | 49 |
import java.awt.Dimension; |
50 | 50 |
import java.awt.FlowLayout; |
51 | 51 |
import java.awt.event.ActionListener; |
52 |
import java.io.File; |
|
53 | 52 |
import java.util.ArrayList; |
54 | 53 |
import java.util.Enumeration; |
55 | 54 |
import java.util.Hashtable; |
56 | 55 |
import java.util.prefs.Preferences; |
57 | 56 |
|
58 | 57 |
import javax.swing.ImageIcon; |
59 |
import javax.swing.JComponent; |
|
60 |
import javax.swing.JFileChooser; |
|
61 | 58 |
import javax.swing.JLabel; |
62 | 59 |
import javax.swing.JOptionPane; |
63 | 60 |
import javax.swing.JPanel; |
... | ... | |
95 | 92 |
public class LegendManager extends AbstractThemeManagerPage { |
96 | 93 |
private static final long serialVersionUID = 7989057553773181019L; |
97 | 94 |
private static ArrayList<Class<? extends ILegendPanel>> legendPool = new ArrayList<Class<? extends ILegendPanel>>(); |
98 |
private static ArrayList<Class<? extends IFMapLegendDriver>> legendDriverPool = new ArrayList<Class<? extends IFMapLegendDriver>>(); |
|
95 |
// private static ArrayList<Class<? extends IFMapLegendDriver>> legendDriverPool = new ArrayList<Class<? extends IFMapLegendDriver>>();
|
|
99 | 96 |
|
100 | 97 |
private FLayer layer; |
101 | 98 |
private ILegend legend; // Le asignaremos la leyenda del primer tema activo. |
... | ... | |
128 | 125 |
} |
129 | 126 |
private ActionListener loadSaveLegendAction = new ActionListener() { |
130 | 127 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
131 |
JComponent c = (JComponent) e.getSource(); |
|
132 |
if (c.equals(getBtnSaveLegend())) { |
|
133 |
|
|
134 |
JLegendFileChooser jfc = new JLegendFileChooser(getLegendDrivers(),true); |
|
135 |
jfc.setAcceptAllFileFilterUsed(false); |
|
136 |
|
|
137 |
|
|
138 |
File basedir = null; |
|
139 |
jfc.setCurrentDirectory(basedir); |
|
140 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
141 |
|
|
142 |
File file = jfc.getSelectedFile(); |
|
143 |
String version = jfc.getDriverVersion(); |
|
144 |
IFMapLegendDriver driver = jfc.getSuitableDriver(); |
|
145 |
|
|
146 |
if(!(driver instanceof FMapGVLDriver)){ |
|
147 |
Object[] options = {PluginServices.getText(this, "yes"), |
|
148 |
PluginServices.getText(this, "no")}; |
|
149 |
|
|
150 |
int answer = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
|
151 |
PluginServices.getText(this, "not_GVL_save_question")+"\n"+ |
|
152 |
PluginServices.getText(this, "desea_continuar"), |
|
153 |
PluginServices.getText(this, "confirmation_dialog"), |
|
154 |
JOptionPane.YES_NO_OPTION, |
|
155 |
JOptionPane.QUESTION_MESSAGE, |
|
156 |
null, |
|
157 |
options, options[1]); |
|
158 |
if (answer!=JOptionPane.OK_OPTION) { |
|
159 |
// 'Cancel' pressed or window closed: don't save anythig, exit save dialog |
|
160 |
return; |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
if (file.exists()) { |
|
165 |
Object[] options = {PluginServices.getText(this, "yes"), |
|
166 |
PluginServices.getText(this, "no"), |
|
167 |
PluginServices.getText(this, "Cancel")}; |
|
168 |
|
|
169 |
int answer = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
|
170 |
PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo"), |
|
171 |
PluginServices.getText(this, "confirmation_dialog"), |
|
172 |
JOptionPane.YES_NO_CANCEL_OPTION, |
|
173 |
JOptionPane.QUESTION_MESSAGE, |
|
174 |
null, |
|
175 |
options, options[1]); |
|
176 |
if (answer!=JOptionPane.OK_OPTION) { |
|
177 |
// 'Cancel' pressed or window closed: don't save anythig, exit save dialog |
|
178 |
return; |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
|
|
183 |
try { |
|
184 |
driver.write(layer.getMapContext().getLayers(),layer, activePanel.getLegend(), file, version); |
|
185 |
|
|
186 |
} catch (LegendDriverException e1) { |
|
187 |
int type = e1.getType(); |
|
188 |
String message=PluginServices.getText(this, "could_not_save_legend")+":\n"; |
|
189 |
|
|
190 |
if ((type & LegendDriverException.SAVE_LEGEND_ERROR) != 0){ |
|
191 |
type = type & ~LegendDriverException.SAVE_LEGEND_ERROR; |
|
192 |
message += PluginServices.getText(this, "error_writing_file")+".\n"; |
|
193 |
} |
|
194 |
if ((type & LegendDriverException.UNSUPPORTED_LEGEND_CREATION) != 0){ |
|
195 |
type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_CREATION; |
|
196 |
message += "-"+ PluginServices.getText(this, "legend_format_not_yet_supported")+"\n"; |
|
197 |
} |
|
198 |
if (type != 0) { |
|
199 |
message = "-"+PluginServices.getText(this, "unknown_error")+"\n"; |
|
200 |
} |
|
201 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), message); |
|
202 |
} |
|
203 |
} |
|
204 |
} else if (c.equals(getBtnLoadLegend())) { |
|
205 |
|
|
206 |
JLegendFileChooser jfc = new JLegendFileChooser(getLegendDrivers()); |
|
207 |
jfc.setAcceptAllFileFilterUsed(false); |
|
208 |
|
|
209 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
210 |
File file=jfc.getSelectedFile(); |
|
211 |
IFMapLegendDriver driver = jfc.getSuitableDriver(); |
|
212 |
String path = file.getAbsolutePath(); |
|
213 |
defaultLegendFolderPath = path.substring(0, path.lastIndexOf(File.separator)); |
|
214 |
|
|
215 |
try { |
|
216 |
table = driver.read(layer.getMapContext().getLayers(),layer, file); |
|
217 |
|
|
218 |
if(table.containsKey(layer)) |
|
219 |
applyLegend((ILegend) table.get(layer)); |
|
220 |
|
|
221 |
|
|
222 |
} catch (LegendDriverException e1) { |
|
223 |
int type = e1.getType(); |
|
224 |
String message = PluginServices.getText(this, "the_legend_will_not_be_applied")+":\n"; |
|
225 |
boolean hasReason = false; |
|
226 |
|
|
227 |
if ((type & LegendDriverException.CLASSIFICATION_FIELDS_NOT_FOUND) != 0){ |
|
228 |
type = type & ~LegendDriverException.CLASSIFICATION_FIELDS_NOT_FOUND; |
|
229 |
message +="-"+ PluginServices.getText(this, "classification_field_does_not_exists")+"\n"; |
|
230 |
hasReason = true; |
|
231 |
} |
|
232 |
if ((type & LegendDriverException.LEGEND_TYPE_NOT_YET_SUPPORTED) != 0){ |
|
233 |
type = type & ~LegendDriverException.LEGEND_TYPE_NOT_YET_SUPPORTED; |
|
234 |
message += "-"+ PluginServices.getText(this, "legend_type_not_yet_supported")+"\n"; |
|
235 |
hasReason = true; |
|
236 |
} |
|
237 |
if ((type & LegendDriverException.SYMBOL_TYPE_NOT_YET_SUPPORTED) != 0){ |
|
238 |
type = type & ~LegendDriverException.SYMBOL_TYPE_NOT_YET_SUPPORTED; |
|
239 |
message += "-"+ PluginServices.getText(this, "unsupported_symbol_type")+"\n"; |
|
240 |
hasReason = true; |
|
241 |
} |
|
242 |
if ((type & LegendDriverException.LAYER_SHAPETYPE_MISMATCH) != 0){ |
|
243 |
type = type & ~LegendDriverException.LAYER_SHAPETYPE_MISMATCH; |
|
244 |
message += "-"+ PluginServices.getText(this, "layer_geometry_and_legend_types_are_incompatible")+"\n"; |
|
245 |
hasReason = true; |
|
246 |
} |
|
247 |
if ((type & LegendDriverException.PARSE_LEGEND_FILE_ERROR) != 0){ |
|
248 |
type = type & ~LegendDriverException.PARSE_LEGEND_FILE_ERROR; |
|
249 |
message += "-"+ PluginServices.getText(this, "failed_reading_file")+"\n"; |
|
250 |
hasReason = true; |
|
251 |
} |
|
252 |
if ((type & LegendDriverException.UNSUPPORTED_LEGEND_FILE_VERSION) != 0){ |
|
253 |
type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_FILE_VERSION; |
|
254 |
message += "-"+ PluginServices.getText(this, "unsupported_legend_file_version")+"\n"; |
|
255 |
hasReason = true; |
|
256 |
} |
|
257 |
if ((type & LegendDriverException.UNSUPPORTED_LEGEND_READING) != 0){ |
|
258 |
type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_READING; |
|
259 |
message +="-"+ PluginServices.getText(this, "unsupported_legend_file_format")+"\n"; |
|
260 |
hasReason = true; |
|
261 |
} |
|
262 |
if ((type & LegendDriverException.LAYER_NAME_NOT_FOUND) != 0){ |
|
263 |
type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_READING; |
|
264 |
message +="-"+ PluginServices.getText(this, "could_not_find_layer")+"\n"; |
|
265 |
hasReason = true; |
|
266 |
} |
|
267 |
if (!hasReason) { |
|
268 |
message = "-"+ PluginServices.getText(this, "unknown_error")+"\n"; |
|
269 |
} |
|
270 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), message); |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
128 |
// JComponent c = (JComponent) e.getSource();
|
|
129 |
// if (c.equals(getBtnSaveLegend())) {
|
|
130 |
// |
|
131 |
// JLegendFileChooser jfc = new JLegendFileChooser(getLegendDrivers(),true);
|
|
132 |
// jfc.setAcceptAllFileFilterUsed(false);
|
|
133 |
// |
|
134 |
// |
|
135 |
// File basedir = null;
|
|
136 |
// jfc.setCurrentDirectory(basedir);
|
|
137 |
// if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
|
138 |
// |
|
139 |
// File file = jfc.getSelectedFile();
|
|
140 |
// String version = jfc.getDriverVersion();
|
|
141 |
// IFMapLegendDriver driver = jfc.getSuitableDriver();
|
|
142 |
// |
|
143 |
// if(!(driver instanceof FMapGVLDriver)){
|
|
144 |
// Object[] options = {PluginServices.getText(this, "yes"),
|
|
145 |
// PluginServices.getText(this, "no")};
|
|
146 |
// |
|
147 |
// int answer = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
|
|
148 |
// PluginServices.getText(this, "not_GVL_save_question")+"\n"+
|
|
149 |
// PluginServices.getText(this, "desea_continuar"),
|
|
150 |
// PluginServices.getText(this, "confirmation_dialog"),
|
|
151 |
// JOptionPane.YES_NO_OPTION,
|
|
152 |
// JOptionPane.QUESTION_MESSAGE,
|
|
153 |
// null,
|
|
154 |
// options, options[1]);
|
|
155 |
// if (answer!=JOptionPane.OK_OPTION) {
|
|
156 |
// // 'Cancel' pressed or window closed: don't save anythig, exit save dialog
|
|
157 |
// return;
|
|
158 |
// }
|
|
159 |
// }
|
|
160 |
// |
|
161 |
// if (file.exists()) {
|
|
162 |
// Object[] options = {PluginServices.getText(this, "yes"),
|
|
163 |
// PluginServices.getText(this, "no"),
|
|
164 |
// PluginServices.getText(this, "Cancel")};
|
|
165 |
// |
|
166 |
// int answer = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
|
|
167 |
// PluginServices.getText(this, "fichero_ya_existe_seguro_desea_guardarlo"),
|
|
168 |
// PluginServices.getText(this, "confirmation_dialog"),
|
|
169 |
// JOptionPane.YES_NO_CANCEL_OPTION,
|
|
170 |
// JOptionPane.QUESTION_MESSAGE,
|
|
171 |
// null,
|
|
172 |
// options, options[1]);
|
|
173 |
// if (answer!=JOptionPane.OK_OPTION) {
|
|
174 |
// // 'Cancel' pressed or window closed: don't save anythig, exit save dialog
|
|
175 |
// return;
|
|
176 |
// }
|
|
177 |
// }
|
|
178 |
// |
|
179 |
// |
|
180 |
// try {
|
|
181 |
// driver.write(layer.getMapContext().getLayers(),layer, activePanel.getLegend(), file, version);
|
|
182 |
// |
|
183 |
// } catch (LegendDriverException e1) {
|
|
184 |
// int type = e1.getType();
|
|
185 |
// String message=PluginServices.getText(this, "could_not_save_legend")+":\n";
|
|
186 |
// |
|
187 |
// if ((type & LegendDriverException.SAVE_LEGEND_ERROR) != 0){
|
|
188 |
// type = type & ~LegendDriverException.SAVE_LEGEND_ERROR;
|
|
189 |
// message += PluginServices.getText(this, "error_writing_file")+".\n";
|
|
190 |
// }
|
|
191 |
// if ((type & LegendDriverException.UNSUPPORTED_LEGEND_CREATION) != 0){
|
|
192 |
// type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_CREATION;
|
|
193 |
// message += "-"+ PluginServices.getText(this, "legend_format_not_yet_supported")+"\n";
|
|
194 |
// }
|
|
195 |
// if (type != 0) {
|
|
196 |
// message = "-"+PluginServices.getText(this, "unknown_error")+"\n";
|
|
197 |
// }
|
|
198 |
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), message);
|
|
199 |
// }
|
|
200 |
// }
|
|
201 |
// } else if (c.equals(getBtnLoadLegend())) {
|
|
202 |
// |
|
203 |
// JLegendFileChooser jfc = new JLegendFileChooser(getLegendDrivers());
|
|
204 |
// jfc.setAcceptAllFileFilterUsed(false);
|
|
205 |
// |
|
206 |
// if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
|
207 |
// File file=jfc.getSelectedFile();
|
|
208 |
// IFMapLegendDriver driver = jfc.getSuitableDriver();
|
|
209 |
// String path = file.getAbsolutePath();
|
|
210 |
// defaultLegendFolderPath = path.substring(0, path.lastIndexOf(File.separator));
|
|
211 |
// |
|
212 |
// try {
|
|
213 |
// table = driver.read(layer.getMapContext().getLayers(),layer, file);
|
|
214 |
// |
|
215 |
// if(table.containsKey(layer))
|
|
216 |
// applyLegend((ILegend) table.get(layer));
|
|
217 |
// |
|
218 |
// |
|
219 |
// } catch (LegendDriverException e1) {
|
|
220 |
// int type = e1.getType();
|
|
221 |
// String message = PluginServices.getText(this, "the_legend_will_not_be_applied")+":\n";
|
|
222 |
// boolean hasReason = false;
|
|
223 |
// |
|
224 |
// if ((type & LegendDriverException.CLASSIFICATION_FIELDS_NOT_FOUND) != 0){
|
|
225 |
// type = type & ~LegendDriverException.CLASSIFICATION_FIELDS_NOT_FOUND;
|
|
226 |
// message +="-"+ PluginServices.getText(this, "classification_field_does_not_exists")+"\n";
|
|
227 |
// hasReason = true;
|
|
228 |
// }
|
|
229 |
// if ((type & LegendDriverException.LEGEND_TYPE_NOT_YET_SUPPORTED) != 0){
|
|
230 |
// type = type & ~LegendDriverException.LEGEND_TYPE_NOT_YET_SUPPORTED;
|
|
231 |
// message += "-"+ PluginServices.getText(this, "legend_type_not_yet_supported")+"\n";
|
|
232 |
// hasReason = true;
|
|
233 |
// }
|
|
234 |
// if ((type & LegendDriverException.SYMBOL_TYPE_NOT_YET_SUPPORTED) != 0){
|
|
235 |
// type = type & ~LegendDriverException.SYMBOL_TYPE_NOT_YET_SUPPORTED;
|
|
236 |
// message += "-"+ PluginServices.getText(this, "unsupported_symbol_type")+"\n";
|
|
237 |
// hasReason = true;
|
|
238 |
// }
|
|
239 |
// if ((type & LegendDriverException.LAYER_SHAPETYPE_MISMATCH) != 0){
|
|
240 |
// type = type & ~LegendDriverException.LAYER_SHAPETYPE_MISMATCH;
|
|
241 |
// message += "-"+ PluginServices.getText(this, "layer_geometry_and_legend_types_are_incompatible")+"\n";
|
|
242 |
// hasReason = true;
|
|
243 |
// }
|
|
244 |
// if ((type & LegendDriverException.PARSE_LEGEND_FILE_ERROR) != 0){
|
|
245 |
// type = type & ~LegendDriverException.PARSE_LEGEND_FILE_ERROR;
|
|
246 |
// message += "-"+ PluginServices.getText(this, "failed_reading_file")+"\n";
|
|
247 |
// hasReason = true;
|
|
248 |
// }
|
|
249 |
// if ((type & LegendDriverException.UNSUPPORTED_LEGEND_FILE_VERSION) != 0){
|
|
250 |
// type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_FILE_VERSION;
|
|
251 |
// message += "-"+ PluginServices.getText(this, "unsupported_legend_file_version")+"\n";
|
|
252 |
// hasReason = true;
|
|
253 |
// }
|
|
254 |
// if ((type & LegendDriverException.UNSUPPORTED_LEGEND_READING) != 0){
|
|
255 |
// type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_READING;
|
|
256 |
// message +="-"+ PluginServices.getText(this, "unsupported_legend_file_format")+"\n";
|
|
257 |
// hasReason = true;
|
|
258 |
// }
|
|
259 |
// if ((type & LegendDriverException.LAYER_NAME_NOT_FOUND) != 0){
|
|
260 |
// type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_READING;
|
|
261 |
// message +="-"+ PluginServices.getText(this, "could_not_find_layer")+"\n";
|
|
262 |
// hasReason = true;
|
|
263 |
// }
|
|
264 |
// if (!hasReason) {
|
|
265 |
// message = "-"+ PluginServices.getText(this, "unknown_error")+"\n";
|
|
266 |
// }
|
|
267 |
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), message);
|
|
268 |
// }
|
|
269 |
// }
|
|
270 |
// }
|
|
274 | 271 |
} |
275 | 272 |
|
276 | 273 |
|
277 |
private IFMapLegendDriver[] getLegendDrivers() { |
|
278 |
Class<?>[] legendDriverClasses = legendDriverPool.toArray(new Class[0]); |
|
279 |
ArrayList<IFMapLegendDriver> drivers = new ArrayList<IFMapLegendDriver>(); |
|
280 |
for (int i = 0; i < legendDriverClasses.length; i++) { |
|
281 |
String message = PluginServices.getText(this, "adding_legend_file_format_support")+": "; |
|
282 |
try { |
|
283 |
Class<?> c = legendDriverClasses[i]; |
|
284 |
drivers.add((IFMapLegendDriver) c.newInstance()); |
|
285 |
} catch (Exception e) { |
|
286 |
NotificationManager.addError(message+PluginServices.getText(this, "failed"), e); |
|
287 |
} |
|
288 |
NotificationManager.addInfo(message+PluginServices.getText(this, "OK")); |
|
289 |
|
|
290 |
} |
|
291 |
return (IFMapLegendDriver[]) drivers.toArray(new IFMapLegendDriver[0]); |
|
292 |
}; |
|
274 |
// private IFMapLegendDriver[] getLegendDrivers() {
|
|
275 |
// Class<?>[] legendDriverClasses = legendDriverPool.toArray(new Class[0]);
|
|
276 |
// ArrayList<IFMapLegendDriver> drivers = new ArrayList<IFMapLegendDriver>();
|
|
277 |
// for (int i = 0; i < legendDriverClasses.length; i++) {
|
|
278 |
// String message = PluginServices.getText(this, "adding_legend_file_format_support")+": ";
|
|
279 |
// try {
|
|
280 |
// Class<?> c = legendDriverClasses[i];
|
|
281 |
// drivers.add((IFMapLegendDriver) c.newInstance());
|
|
282 |
// } catch (Exception e) {
|
|
283 |
// NotificationManager.addError(message+PluginServices.getText(this, "failed"), e);
|
|
284 |
// }
|
|
285 |
// NotificationManager.addInfo(message+PluginServices.getText(this, "OK"));
|
|
286 |
// |
|
287 |
// }
|
|
288 |
// return (IFMapLegendDriver[]) drivers.toArray(new IFMapLegendDriver[0]);
|
|
289 |
// };
|
|
293 | 290 |
}; |
294 | 291 |
|
295 | 292 |
|
... | ... | |
812 | 809 |
"loaded_legend_the_legend_wont_be_applied")); |
813 | 810 |
} |
814 | 811 |
|
815 |
public static void addLegendDriver(Class<? extends IFMapLegendDriver> legendDriverClass) { |
|
816 |
if (!legendDriverPool.contains(legendDriverClass)) { |
|
817 |
legendDriverPool.add(legendDriverClass); |
|
818 |
} |
|
819 |
} |
|
812 |
// public static void addLegendDriver(Class<? extends IFMapLegendDriver> legendDriverClass) {
|
|
813 |
// if (!legendDriverPool.contains(legendDriverClass)) {
|
|
814 |
// legendDriverPool.add(legendDriverClass);
|
|
815 |
// }
|
|
816 |
// }
|
|
820 | 817 |
} |
Also available in: Unified diff