28 |
28 |
import java.awt.Component;
|
29 |
29 |
import java.awt.Dimension;
|
30 |
30 |
import java.awt.FlowLayout;
|
|
31 |
import java.awt.Point;
|
|
32 |
import java.awt.event.ActionEvent;
|
31 |
33 |
import java.awt.event.ActionListener;
|
32 |
|
import java.io.File;
|
33 |
|
import java.io.FileInputStream;
|
34 |
|
import java.io.FileNotFoundException;
|
35 |
|
import java.io.FileOutputStream;
|
36 |
|
import java.io.InputStream;
|
37 |
|
import java.io.OutputStream;
|
38 |
|
import java.util.ArrayList;
|
|
34 |
import java.util.Collection;
|
39 |
35 |
import java.util.Enumeration;
|
|
36 |
import java.util.HashMap;
|
40 |
37 |
import java.util.Hashtable;
|
41 |
38 |
import java.util.Iterator;
|
42 |
|
import java.util.List;
|
|
39 |
import java.util.Map;
|
43 |
40 |
import java.util.prefs.Preferences;
|
|
41 |
import javax.swing.Action;
|
44 |
42 |
|
45 |
43 |
import javax.swing.ImageIcon;
|
46 |
44 |
import javax.swing.JButton;
|
47 |
|
import javax.swing.JComponent;
|
48 |
|
import javax.swing.JFileChooser;
|
49 |
45 |
import javax.swing.JLabel;
|
|
46 |
import javax.swing.JMenuItem;
|
50 |
47 |
import javax.swing.JOptionPane;
|
51 |
48 |
import javax.swing.JPanel;
|
|
49 |
import javax.swing.JPopupMenu;
|
52 |
50 |
import javax.swing.JScrollPane;
|
53 |
51 |
import javax.swing.JSplitPane;
|
54 |
52 |
import javax.swing.JTextArea;
|
55 |
53 |
import javax.swing.JTree;
|
56 |
|
import javax.swing.filechooser.FileFilter;
|
57 |
54 |
import javax.swing.tree.DefaultMutableTreeNode;
|
58 |
55 |
import javax.swing.tree.DefaultTreeCellRenderer;
|
59 |
56 |
import javax.swing.tree.DefaultTreeModel;
|
... | ... | |
66 |
63 |
|
67 |
64 |
import org.gvsig.andami.PluginServices;
|
68 |
65 |
import org.gvsig.andami.messages.NotificationManager;
|
69 |
|
import org.gvsig.app.ApplicationLocator;
|
70 |
|
import org.gvsig.fmap.geom.Geometry;
|
71 |
|
import org.gvsig.fmap.mapcontext.MapContextLocator;
|
72 |
|
import org.gvsig.fmap.mapcontext.MapContextManager;
|
73 |
66 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
|
74 |
|
import org.gvsig.fmap.mapcontext.exceptions.WriteLegendException;
|
75 |
67 |
import org.gvsig.fmap.mapcontext.layers.FLayer;
|
76 |
68 |
import org.gvsig.fmap.mapcontext.layers.FLayers;
|
77 |
69 |
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable;
|
... | ... | |
80 |
72 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
|
81 |
73 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
|
82 |
74 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
|
83 |
|
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader;
|
84 |
|
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter;
|
85 |
|
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
|
86 |
|
import org.gvsig.i18n.Messages;
|
|
75 |
import org.gvsig.symbology.SymbologyLocator;
|
87 |
76 |
import org.gvsig.symbology.swing.SymbologySwingLocator;
|
88 |
77 |
import org.gvsig.symbology.swing.SymbologySwingManager;
|
89 |
|
import org.gvsig.tools.ToolsLocator;
|
90 |
|
import org.gvsig.tools.persistence.PersistenceManager;
|
91 |
78 |
|
92 |
79 |
/**
|
93 |
80 |
* Implements the panel which allows the user to control all the information
|
... | ... | |
98 |
85 |
*
|
99 |
86 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
100 |
87 |
*/
|
101 |
|
public class LegendManager extends AbstractThemeManagerPage {
|
|
88 |
public class LegendManager extends AbstractThemeManagerPage implements LegendsPanel {
|
102 |
89 |
|
103 |
90 |
private static final Logger logger =
|
104 |
91 |
LoggerFactory.getLogger(LegendManager.class);
|
105 |
92 |
|
106 |
93 |
private static final long serialVersionUID = 7989057553773181019L;
|
107 |
|
// private static ArrayList<Class<? extends ILegendPanel>> legendPool =
|
108 |
|
// new ArrayList<Class<? extends ILegendPanel>>();
|
109 |
|
// private static ArrayList<Class<? extends IFMapLegendDriver>>
|
110 |
|
// legendDriverPool = new ArrayList<Class<? extends IFMapLegendDriver>>();
|
111 |
94 |
|
|
95 |
public static class Pages implements Iterable<ILegendPanel> {
|
|
96 |
|
|
97 |
private Map<Class<? extends ILegendPanel>, ILegendPanel> pages;
|
|
98 |
|
|
99 |
public Pages() {
|
|
100 |
this.pages = new HashMap<>();
|
|
101 |
}
|
|
102 |
|
|
103 |
public void add(ILegendPanel page) {
|
|
104 |
this.pages.put(page.getClass(), page);
|
|
105 |
}
|
|
106 |
|
|
107 |
public Iterator<ILegendPanel> iterator() {
|
|
108 |
return this.pages.values().iterator();
|
|
109 |
}
|
|
110 |
|
|
111 |
public boolean contains(Class<? extends ILegendPanel> pageClass) {
|
|
112 |
return this.pages.containsKey(pageClass);
|
|
113 |
}
|
|
114 |
|
|
115 |
public ILegendPanel get(Class<? extends ILegendPanel> pageClass) {
|
|
116 |
return this.pages.get(pageClass);
|
|
117 |
}
|
|
118 |
|
|
119 |
public Collection<ILegendPanel> asCollection() {
|
|
120 |
return this.pages.values();
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
112 |
124 |
private FLayer layer;
|
113 |
|
private ILegend legend; // Le asignaremos la leyenda del primer tema activo.
|
114 |
|
private Hashtable<Class<? extends ILegendPanel>, ILegendPanel> pages =
|
115 |
|
new Hashtable<Class<? extends ILegendPanel>, ILegendPanel>();
|
|
125 |
private ILegend legend;
|
|
126 |
private Pages pages = new Pages();
|
|
127 |
|
116 |
128 |
private JPanel topPanel = null;
|
117 |
129 |
private JTextArea titleArea = null;
|
118 |
130 |
private JPanel preview = null;
|
... | ... | |
120 |
132 |
private JTree jTreeLegends;
|
121 |
133 |
private ILegendPanel activePanel;
|
122 |
134 |
private JScrollPane legendTreeScrollPane;
|
123 |
|
private boolean dirtyTree_;
|
124 |
|
private DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
|
135 |
// private boolean dirtyTree_;
|
|
136 |
private final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
125 |
137 |
private DefaultTreeModel treeModel;
|
126 |
138 |
private JScrollPane jPanelContainer;
|
127 |
139 |
private JPanel jCentralPanel;
|
128 |
140 |
private JSplitPane jSplitPane;
|
129 |
141 |
private boolean isTreeListenerDisabled;
|
130 |
|
private JButton btnSaveLegend;
|
131 |
|
private JButton btnLoadLegend;
|
|
142 |
private JButton btnOptionalActions;
|
|
143 |
private JPopupMenu menuOptionalActions;
|
132 |
144 |
private Hashtable<FLayer, ILegend> table = null;
|
133 |
145 |
private boolean empty = true;
|
134 |
146 |
private JLabel iconLabel;
|
135 |
147 |
|
136 |
148 |
public static String defaultLegendFolderPath;
|
137 |
149 |
{
|
138 |
|
|
139 |
150 |
Preferences prefs = Preferences.userRoot().node("gvsig.foldering");
|
140 |
151 |
defaultLegendFolderPath = prefs.get("LegendsFolder", "");
|
141 |
152 |
}
|
142 |
153 |
|
143 |
|
private ActionListener loadSaveLegendAction = new ActionListener() {
|
144 |
154 |
|
145 |
|
public void actionPerformed(java.awt.event.ActionEvent e) {
|
146 |
|
JComponent c = (JComponent) e.getSource();
|
147 |
|
if (c.equals(getBtnSaveLegend())) {
|
148 |
|
|
149 |
|
try {
|
150 |
|
saveLegend();
|
151 |
|
} catch (Exception exc) {
|
152 |
|
JOptionPane.showMessageDialog(
|
153 |
|
ApplicationLocator.getManager().getRootComponent(),
|
154 |
|
Messages.getText("_Unable_to_save_legend")
|
155 |
|
+ "\n\n" + exc.getMessage(),
|
156 |
|
Messages.getText("legend"),
|
157 |
|
JOptionPane.WARNING_MESSAGE);
|
158 |
|
return;
|
159 |
|
}
|
160 |
|
|
161 |
|
} else
|
162 |
|
if (c.equals(getBtnLoadLegend())) {
|
163 |
|
try {
|
164 |
|
loadLegend();
|
165 |
|
} catch (Exception e1) {
|
166 |
|
JOptionPane.showMessageDialog(
|
167 |
|
ApplicationLocator.getManager().getRootComponent(),
|
168 |
|
Messages.getText("_Unable_to_read_legend")
|
169 |
|
+ "\n\n" + e1.getMessage(),
|
170 |
|
Messages.getText("legend"),
|
171 |
|
JOptionPane.WARNING_MESSAGE);
|
172 |
|
return;
|
173 |
|
}
|
174 |
|
}
|
175 |
|
}
|
176 |
|
|
177 |
|
private void saveLegend() throws Exception {
|
178 |
|
|
179 |
|
List<LegendFileFilter> filters = getLegendFileFilters(true);
|
180 |
|
if (filters.size() == 0) {
|
181 |
|
JOptionPane.showMessageDialog(
|
182 |
|
ApplicationLocator.getManager().getRootComponent(),
|
183 |
|
Messages.getText("_No_output_format_available"),
|
184 |
|
Messages.getText("legend"),
|
185 |
|
JOptionPane.WARNING_MESSAGE);
|
186 |
|
return;
|
187 |
|
}
|
188 |
|
|
189 |
|
ILegend legend = activePanel.getLegend();
|
190 |
|
MapContextManager mcoman = MapContextLocator.getMapContextManager();
|
191 |
|
|
192 |
|
JFileChooser fileChooser = new JFileChooser();
|
193 |
|
fileChooser.setAcceptAllFileFilterUsed(false);
|
194 |
|
|
195 |
|
for (int i=0; i<filters.size(); i++) {
|
196 |
|
fileChooser.addChoosableFileFilter(filters.get(i));
|
197 |
|
}
|
198 |
|
|
199 |
|
if (fileChooser.showSaveDialog(
|
200 |
|
ApplicationLocator.getManager().getRootComponent())
|
201 |
|
== JFileChooser.APPROVE_OPTION) {
|
202 |
|
|
203 |
|
LegendFileFilter lff = (LegendFileFilter) fileChooser.getFileFilter();
|
204 |
|
|
205 |
|
File selfile = fileChooser.getSelectedFile();
|
206 |
|
if (!selfile.getAbsolutePath().toLowerCase().endsWith(
|
207 |
|
"." + lff.getFileExtension().toLowerCase())) {
|
208 |
|
|
209 |
|
selfile = new File(selfile.getAbsolutePath() +
|
210 |
|
"." + lff.getFileExtension().toLowerCase());
|
211 |
|
}
|
212 |
|
|
213 |
|
ILegendWriter lw = null;
|
214 |
|
lw = mcoman.createLegendWriter(legend.getClass(), lff.getFileExtension());
|
215 |
|
|
216 |
|
if (lw == null) {
|
217 |
|
throw new WriteLegendException(legend,
|
218 |
|
new Exception("Unable to create legend writer."));
|
219 |
|
} else {
|
220 |
|
lw.write(legend, selfile, lff.getFileExtension());
|
221 |
|
}
|
222 |
|
}
|
223 |
|
}
|
224 |
|
|
225 |
|
/**
|
226 |
|
*
|
227 |
|
* @param writing true for writing; false for reading
|
228 |
|
* @return
|
229 |
|
*/
|
230 |
|
private List<LegendFileFilter> getLegendFileFilters(boolean writing) {
|
231 |
|
|
232 |
|
List<LegendFileFilter> resp = new ArrayList<LegendFileFilter>();
|
233 |
|
MapContextManager mcoman = MapContextLocator.getMapContextManager();
|
234 |
|
List wformats = null;
|
235 |
|
|
236 |
|
if (writing) {
|
237 |
|
wformats = mcoman.getLegendWritingFormats();
|
238 |
|
} else {
|
239 |
|
wformats = mcoman.getLegendReadingFormats();
|
240 |
|
}
|
241 |
|
|
242 |
|
String fmt = null;
|
243 |
|
for (int i=0; i<wformats.size(); i++) {
|
244 |
|
fmt = (String) wformats.get(i);
|
245 |
|
fmt = getFileExtension(fmt);
|
246 |
|
if (fmt != null) {
|
247 |
|
resp.add(new LegendFileFilter(fmt));
|
248 |
|
}
|
249 |
|
}
|
250 |
|
return resp;
|
251 |
|
}
|
252 |
|
|
253 |
|
|
254 |
|
/**
|
255 |
|
* Returns null if mime format is not parsed properly
|
256 |
|
*
|
257 |
|
* @param fmt MIME format
|
258 |
|
*
|
259 |
|
* @return
|
260 |
|
*/
|
261 |
|
private String getFileExtension(String fmt) {
|
262 |
|
// Example: "text/xml; subtype=gml/2.1.2" => "gml"
|
263 |
|
if (fmt == null) {
|
264 |
|
return null;
|
265 |
|
}
|
266 |
|
String[] parts = fmt.split(";");
|
267 |
|
String aux = "";
|
268 |
|
if (parts.length > 1) {
|
269 |
|
aux = parts[1].trim();
|
270 |
|
} else {
|
271 |
|
aux = parts[0].trim();
|
272 |
|
}
|
273 |
|
parts = aux.split("=");
|
274 |
|
if (parts.length > 1) {
|
275 |
|
aux = parts[1].trim();
|
276 |
|
// Example: aux = "gml/2.1.2"
|
277 |
|
parts = aux.split("/");
|
278 |
|
return parts[0].length() == 0 ? null : parts[0].toLowerCase();
|
279 |
|
} else {
|
280 |
|
aux = parts[0].trim();
|
281 |
|
// Example: "text/xml"
|
282 |
|
parts = aux.split("/");
|
283 |
|
if (parts.length > 1) {
|
284 |
|
return parts[1].length() == 0 ? null : parts[1].toLowerCase();
|
285 |
|
} else {
|
286 |
|
return aux.length() == 0 ? null : aux.toLowerCase();
|
287 |
|
}
|
288 |
|
}
|
289 |
|
}
|
290 |
|
|
291 |
|
private void loadLegend() throws Exception {
|
292 |
|
|
293 |
|
List<LegendFileFilter> filters = getLegendFileFilters(false);
|
294 |
|
if (filters.size() == 0) {
|
295 |
|
JOptionPane.showMessageDialog(
|
296 |
|
ApplicationLocator.getManager().getRootComponent(),
|
297 |
|
Messages.getText("_No_input_format_available"),
|
298 |
|
Messages.getText("legend"),
|
299 |
|
JOptionPane.WARNING_MESSAGE);
|
300 |
|
return;
|
301 |
|
}
|
302 |
|
|
303 |
|
JFileChooser fileChooser = new JFileChooser();
|
304 |
|
fileChooser.setAcceptAllFileFilterUsed(false);
|
305 |
|
|
306 |
|
for (int i=0; i<filters.size(); i++) {
|
307 |
|
fileChooser.addChoosableFileFilter(filters.get(i));
|
308 |
|
}
|
309 |
|
|
310 |
|
// open a file
|
311 |
|
if (fileChooser.showOpenDialog((Component) PluginServices
|
312 |
|
.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
|
313 |
|
|
314 |
|
File file = fileChooser.getSelectedFile();
|
315 |
|
LegendFileFilter lff = (LegendFileFilter) fileChooser.getFileFilter();
|
316 |
|
MapContextManager mcoman = MapContextLocator.getMapContextManager();
|
317 |
|
ILegendReader lr = mcoman.createLegendReader(lff.getFileExtension());
|
318 |
|
|
319 |
|
ILegend leg = lr.read(file, Geometry.TYPES.GEOMETRY);
|
320 |
|
applyLegend(leg);
|
321 |
|
}
|
322 |
|
}
|
323 |
|
};
|
324 |
|
|
325 |
|
//
|
326 |
|
// JLegendFileChooser jfc = new
|
327 |
|
// JLegendFileChooser(getLegendDrivers(),true);
|
328 |
|
// jfc.setAcceptAllFileFilterUsed(false);
|
329 |
|
//
|
330 |
|
//
|
331 |
|
// File basedir = null;
|
332 |
|
// jfc.setCurrentDirectory(basedir);
|
333 |
|
// if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
|
334 |
|
// == JFileChooser.APPROVE_OPTION) {
|
335 |
|
//
|
336 |
|
// File file = jfc.getSelectedFile();
|
337 |
|
// String version = jfc.getDriverVersion();
|
338 |
|
// IFMapLegendDriver driver = jfc.getSuitableDriver();
|
339 |
|
//
|
340 |
|
// if(!(driver instanceof FMapGVLDriver)){
|
341 |
|
// Object[] options = {PluginServices.getText(this, "yes"),
|
342 |
|
// PluginServices.getText(this, "no")};
|
343 |
|
//
|
344 |
|
// int answer =
|
345 |
|
// JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
|
346 |
|
// PluginServices.getText(this, "not_GVSLEG_save_question")+"\n"+ //GVL
|
347 |
|
// changed to GVSLEG, be aware
|
348 |
|
// PluginServices.getText(this, "desea_continuar"),
|
349 |
|
// PluginServices.getText(this, "confirmation_dialog"),
|
350 |
|
// JOptionPane.YES_NO_OPTION,
|
351 |
|
// JOptionPane.QUESTION_MESSAGE,
|
352 |
|
// null,
|
353 |
|
// options, options[1]);
|
354 |
|
// if (answer!=JOptionPane.OK_OPTION) {
|
355 |
|
// // 'Cancel' pressed or window closed: don't save anythig, exit
|
356 |
|
// save dialog
|
357 |
|
// return;
|
358 |
|
// }
|
359 |
|
// }
|
360 |
|
//
|
361 |
|
// if (file.exists()) {
|
362 |
|
// Object[] options = {PluginServices.getText(this, "yes"),
|
363 |
|
// PluginServices.getText(this, "no"),
|
364 |
|
// PluginServices.getText(this, "Cancel")};
|
365 |
|
//
|
366 |
|
// int answer =
|
367 |
|
// JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(),
|
368 |
|
// PluginServices.getText(this,
|
369 |
|
// "fichero_ya_existe_seguro_desea_guardarlo"),
|
370 |
|
// PluginServices.getText(this, "confirmation_dialog"),
|
371 |
|
// JOptionPane.YES_NO_CANCEL_OPTION,
|
372 |
|
// JOptionPane.QUESTION_MESSAGE,
|
373 |
|
// null,
|
374 |
|
// options, options[1]);
|
375 |
|
// if (answer!=JOptionPane.OK_OPTION) {
|
376 |
|
// // 'Cancel' pressed or window closed: don't save anythig, exit
|
377 |
|
// save dialog
|
378 |
|
// return;
|
379 |
|
// }
|
380 |
|
// }
|
381 |
|
//
|
382 |
|
//
|
383 |
|
// try {
|
384 |
|
// driver.write(layer.getMapContext().getLayers(),layer,
|
385 |
|
// activePanel.getLegend(), file, version);
|
386 |
|
//
|
387 |
|
// } catch (LegendDriverException e1) {
|
388 |
|
// int type = e1.getType();
|
389 |
|
// String message=PluginServices.getText(this,
|
390 |
|
// "could_not_save_legend")+":\n";
|
391 |
|
//
|
392 |
|
// if ((type & LegendDriverException.SAVE_LEGEND_ERROR) != 0){
|
393 |
|
// type = type & ~LegendDriverException.SAVE_LEGEND_ERROR;
|
394 |
|
// message += PluginServices.getText(this,
|
395 |
|
// "error_writing_file")+".\n";
|
396 |
|
// }
|
397 |
|
// if ((type & LegendDriverException.UNSUPPORTED_LEGEND_CREATION) !=
|
398 |
|
// 0){
|
399 |
|
// type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_CREATION;
|
400 |
|
// message += "-"+ PluginServices.getText(this,
|
401 |
|
// "legend_format_not_yet_supported")+"\n";
|
402 |
|
// }
|
403 |
|
// if (type != 0) {
|
404 |
|
// message = "-"+PluginServices.getText(this, "unknown_error")+"\n";
|
405 |
|
// }
|
406 |
|
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
|
407 |
|
// message);
|
408 |
|
// }
|
409 |
|
// }
|
410 |
|
// } else if (c.equals(getBtnLoadLegend())) {
|
411 |
|
//
|
412 |
|
// JLegendFileChooser jfc = new
|
413 |
|
// JLegendFileChooser(getLegendDrivers());
|
414 |
|
// jfc.setAcceptAllFileFilterUsed(false);
|
415 |
|
//
|
416 |
|
// if (jfc.showOpenDialog((Component) PluginServices.getMainFrame())
|
417 |
|
// == JFileChooser.APPROVE_OPTION) {
|
418 |
|
// File file=jfc.getSelectedFile();
|
419 |
|
// IFMapLegendDriver driver = jfc.getSuitableDriver();
|
420 |
|
// String path = file.getAbsolutePath();
|
421 |
|
// defaultLegendFolderPath = path.substring(0,
|
422 |
|
// path.lastIndexOf(File.separator));
|
423 |
|
//
|
424 |
|
// try {
|
425 |
|
// table = driver.read(layer.getMapContext().getLayers(),layer,
|
426 |
|
// file);
|
427 |
|
//
|
428 |
|
// if(table.containsKey(layer))
|
429 |
|
// applyLegend((ILegend) table.get(layer));
|
430 |
|
//
|
431 |
|
//
|
432 |
|
// } catch (LegendDriverException e1) {
|
433 |
|
// int type = e1.getType();
|
434 |
|
// String message = PluginServices.getText(this,
|
435 |
|
// "the_legend_will_not_be_applied")+":\n";
|
436 |
|
// boolean hasReason = false;
|
437 |
|
//
|
438 |
|
// if ((type &
|
439 |
|
// LegendDriverException.CLASSIFICATION_FIELDS_NOT_FOUND) != 0){
|
440 |
|
// type = type &
|
441 |
|
// ~LegendDriverException.CLASSIFICATION_FIELDS_NOT_FOUND;
|
442 |
|
// message +="-"+ PluginServices.getText(this,
|
443 |
|
// "classification_field_does_not_exists")+"\n";
|
444 |
|
// hasReason = true;
|
445 |
|
// }
|
446 |
|
// if ((type & LegendDriverException.LEGEND_TYPE_NOT_YET_SUPPORTED)
|
447 |
|
// != 0){
|
448 |
|
// type = type &
|
449 |
|
// ~LegendDriverException.LEGEND_TYPE_NOT_YET_SUPPORTED;
|
450 |
|
// message += "-"+ PluginServices.getText(this,
|
451 |
|
// "legend_type_not_yet_supported")+"\n";
|
452 |
|
// hasReason = true;
|
453 |
|
// }
|
454 |
|
// if ((type & LegendDriverException.SYMBOL_TYPE_NOT_YET_SUPPORTED)
|
455 |
|
// != 0){
|
456 |
|
// type = type &
|
457 |
|
// ~LegendDriverException.SYMBOL_TYPE_NOT_YET_SUPPORTED;
|
458 |
|
// message += "-"+ PluginServices.getText(this,
|
459 |
|
// "unsupported_symbol_type")+"\n";
|
460 |
|
// hasReason = true;
|
461 |
|
// }
|
462 |
|
// if ((type & LegendDriverException.LAYER_SHAPETYPE_MISMATCH) !=
|
463 |
|
// 0){
|
464 |
|
// type = type & ~LegendDriverException.LAYER_SHAPETYPE_MISMATCH;
|
465 |
|
// message += "-"+ PluginServices.getText(this,
|
466 |
|
// "layer_geometry_and_legend_types_are_incompatible")+"\n";
|
467 |
|
// hasReason = true;
|
468 |
|
// }
|
469 |
|
// if ((type & LegendDriverException.PARSE_LEGEND_FILE_ERROR) != 0){
|
470 |
|
// type = type & ~LegendDriverException.PARSE_LEGEND_FILE_ERROR;
|
471 |
|
// message += "-"+ PluginServices.getText(this,
|
472 |
|
// "failed_reading_file")+"\n";
|
473 |
|
// hasReason = true;
|
474 |
|
// }
|
475 |
|
// if ((type &
|
476 |
|
// LegendDriverException.UNSUPPORTED_LEGEND_FILE_VERSION) != 0){
|
477 |
|
// type = type &
|
478 |
|
// ~LegendDriverException.UNSUPPORTED_LEGEND_FILE_VERSION;
|
479 |
|
// message += "-"+ PluginServices.getText(this,
|
480 |
|
// "unsupported_legend_file_version")+"\n";
|
481 |
|
// hasReason = true;
|
482 |
|
// }
|
483 |
|
// if ((type & LegendDriverException.UNSUPPORTED_LEGEND_READING) !=
|
484 |
|
// 0){
|
485 |
|
// type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_READING;
|
486 |
|
// message +="-"+ PluginServices.getText(this,
|
487 |
|
// "unsupported_legend_file_format")+"\n";
|
488 |
|
// hasReason = true;
|
489 |
|
// }
|
490 |
|
// if ((type & LegendDriverException.LAYER_NAME_NOT_FOUND) != 0){
|
491 |
|
// type = type & ~LegendDriverException.UNSUPPORTED_LEGEND_READING;
|
492 |
|
// message +="-"+ PluginServices.getText(this,
|
493 |
|
// "could_not_find_layer")+"\n";
|
494 |
|
// hasReason = true;
|
495 |
|
// }
|
496 |
|
// if (!hasReason) {
|
497 |
|
// message = "-"+ PluginServices.getText(this,
|
498 |
|
// "unknown_error")+"\n";
|
499 |
|
// }
|
500 |
|
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
|
501 |
|
// message);
|
502 |
|
// }
|
503 |
|
// }
|
504 |
|
// }
|
505 |
|
|
506 |
|
// private IFMapLegendDriver[] getLegendDrivers() {
|
507 |
|
// Class<?>[] legendDriverClasses = legendDriverPool.toArray(new Class[0]);
|
508 |
|
// ArrayList<IFMapLegendDriver> drivers = new
|
509 |
|
// ArrayList<IFMapLegendDriver>();
|
510 |
|
// for (int i = 0; i < legendDriverClasses.length; i++) {
|
511 |
|
// String message = PluginServices.getText(this,
|
512 |
|
// "adding_legend_file_format_support")+": ";
|
513 |
|
// try {
|
514 |
|
// Class<?> c = legendDriverClasses[i];
|
515 |
|
// drivers.add((IFMapLegendDriver) c.newInstance());
|
516 |
|
// } catch (Exception e) {
|
517 |
|
// NotificationManager.addError(message+PluginServices.getText(this,
|
518 |
|
// "failed"), e);
|
519 |
|
// }
|
520 |
|
// NotificationManager.addInfo(message+PluginServices.getText(this, "OK"));
|
521 |
|
//
|
522 |
|
// }
|
523 |
|
// return (IFMapLegendDriver[]) drivers.toArray(new IFMapLegendDriver[0]);
|
524 |
|
// };
|
525 |
|
|
526 |
|
private String getExtension(File f) {
|
527 |
|
String ext = null;
|
528 |
|
String s = f.getName();
|
529 |
|
int i = s.lastIndexOf('.');
|
530 |
|
|
531 |
|
if (i > 0 && i < s.length() - 1) {
|
532 |
|
// ext = s.substring(i + 1).toLowerCase();
|
533 |
|
ext = s.substring(i).toLowerCase();
|
534 |
|
}
|
535 |
|
return ext;
|
536 |
|
}
|
537 |
|
|
538 |
155 |
public LegendManager() {
|
539 |
156 |
initialize();
|
540 |
157 |
}
|
... | ... | |
589 |
206 |
null, "",
|
590 |
207 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
|
591 |
208 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
|
592 |
|
topPanel.add(getBtnSaveLegend(), null);
|
593 |
|
topPanel.add(getBtnLoadLegend(), null);
|
|
209 |
topPanel.add(getBtnOptionalActions(), null);
|
594 |
210 |
}
|
595 |
211 |
return topPanel;
|
596 |
212 |
}
|
597 |
213 |
|
598 |
|
private JButton getBtnSaveLegend() {
|
599 |
|
if (btnSaveLegend == null) {
|
600 |
|
btnSaveLegend =
|
601 |
|
new JButton(PluginServices.getText(this, "Guardar_leyenda")
|
|
214 |
private JButton getBtnOptionalActions() {
|
|
215 |
if (btnOptionalActions == null) {
|
|
216 |
btnOptionalActions =
|
|
217 |
new JButton(PluginServices.getText(this, "_Mas_opciones")
|
602 |
218 |
+ "...");
|
603 |
|
btnSaveLegend.addActionListener(loadSaveLegendAction);
|
|
219 |
btnOptionalActions.addActionListener(new ActionListener() {
|
|
220 |
@Override
|
|
221 |
public void actionPerformed(ActionEvent e) {
|
|
222 |
Point p = btnOptionalActions.getLocationOnScreen();
|
|
223 |
menuOptionalActions.show(asJComponent(),0,0);
|
|
224 |
menuOptionalActions.setLocation(p.x,p.y+btnOptionalActions.getHeight());
|
|
225 |
}
|
|
226 |
});
|
604 |
227 |
}
|
605 |
|
return btnSaveLegend;
|
|
228 |
return btnOptionalActions;
|
606 |
229 |
}
|
607 |
230 |
|
608 |
|
private JButton getBtnLoadLegend() {
|
609 |
|
if (btnLoadLegend == null) {
|
610 |
|
btnLoadLegend =
|
611 |
|
new JButton(PluginServices.getText(this, "Recuperar_leyenda")
|
612 |
|
+ "...");
|
613 |
|
btnLoadLegend.addActionListener(loadSaveLegendAction);
|
614 |
|
}
|
615 |
|
return btnLoadLegend;
|
616 |
|
}
|
617 |
|
|
618 |
231 |
/**
|
619 |
232 |
* This method initializes jTextArea
|
620 |
233 |
*
|
... | ... | |
687 |
300 |
* bug, sorry. Just avoid this case or try to fix it (lol).<br>
|
688 |
301 |
* </p>
|
689 |
302 |
*
|
690 |
|
* @param page
|
691 |
|
* , Class of type ILegendPanel
|
692 |
303 |
* @deprecated use SymbologySwingManager.registerLegendEditor
|
693 |
304 |
*/
|
694 |
305 |
public static void addLegendPage(Class<? extends ILegendPanel> iLegendPanelClass) {
|
... | ... | |
707 |
318 |
Iterator<ILegendPanel> it = manager.getLegendEditors(layer).iterator();
|
708 |
319 |
while( it.hasNext() ) {
|
709 |
320 |
ILegendPanel page = it.next();
|
710 |
|
pages.put(page.getClass(), page);
|
|
321 |
pages.add(page);
|
711 |
322 |
}
|
712 |
|
|
713 |
|
Enumeration<ILegendPanel> enume = pages.elements();
|
714 |
|
while (enume.hasMoreElements()) {
|
715 |
|
ILegendPanel page = enume.nextElement();
|
|
323 |
addOptionalActions();
|
|
324 |
for(ILegendPanel page : this.pages ) {
|
716 |
325 |
doInsertNode(treeModel, page);
|
717 |
326 |
}
|
718 |
327 |
getJTreeLegends().setModel(treeModel);
|
... | ... | |
721 |
330 |
}
|
722 |
331 |
}
|
723 |
332 |
|
|
333 |
private void addOptionalActions() {
|
|
334 |
this.menuOptionalActions = new JPopupMenu();
|
|
335 |
Iterable<Action> actions = SymbologySwingLocator.getSwingManager().getOptionalActionOfLegendsPanel();
|
|
336 |
for( Action action : actions ) {
|
|
337 |
JMenuItemForOptionalAction item = new JMenuItemForOptionalAction(action);
|
|
338 |
this.menuOptionalActions.add(item);
|
|
339 |
}
|
|
340 |
}
|
|
341 |
|
|
342 |
private class JMenuItemForOptionalAction extends JMenuItem implements ActionListener {
|
|
343 |
|
|
344 |
private static final long serialVersionUID = 1656264978338543368L;
|
|
345 |
Action action;
|
|
346 |
|
|
347 |
JMenuItemForOptionalAction(Action action) {
|
|
348 |
this.action = action;
|
|
349 |
this.configurePropertiesFromAction(action);
|
|
350 |
this.addActionListener(this);
|
|
351 |
}
|
|
352 |
|
|
353 |
@Override
|
|
354 |
public void actionPerformed(ActionEvent e) {
|
|
355 |
e.setSource(LegendManager.this);
|
|
356 |
this.action.actionPerformed(e);
|
|
357 |
}
|
|
358 |
}
|
|
359 |
|
724 |
360 |
@SuppressWarnings("unchecked")
|
725 |
361 |
private DefaultMutableTreeNode findNode(Class searchID) {
|
726 |
362 |
String title;
|
... | ... | |
812 |
448 |
Class parent_class = page.getParentClass();
|
813 |
449 |
|
814 |
450 |
if (parent_class != null) {
|
815 |
|
if (pages.containsKey(parent_class)) {
|
|
451 |
// if (pages.containsKey(parent_class)) {
|
|
452 |
if (pages.contains(parent_class)) {
|
816 |
453 |
ILegendPanel parent = (ILegendPanel) pages.get(parent_class);
|
817 |
454 |
|
818 |
455 |
aux = doInsertNode(tm, parent);
|
... | ... | |
880 |
517 |
return jTreeLegends;
|
881 |
518 |
}
|
882 |
519 |
|
883 |
|
private void setActivePage(ILegendPanel page) {
|
|
520 |
@Override
|
|
521 |
public void setActivePage(ILegendPanel page) {
|
884 |
522 |
if (page.getPanel() == null) {
|
885 |
523 |
// this is what happens when the user clicked in a parent node
|
886 |
524 |
// which only acts as a folder, and does not manage any legend
|
... | ... | |
904 |
542 |
}
|
905 |
543 |
}
|
906 |
544 |
|
|
545 |
@Override
|
|
546 |
public ILegendPanel getActivePage() {
|
|
547 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
548 |
}
|
|
549 |
|
907 |
550 |
private void setIcon(ImageIcon icon) {
|
908 |
551 |
getIconLabel().setIcon(icon);
|
909 |
552 |
}
|
... | ... | |
1079 |
722 |
private void applyLegend(ILegend aLegend) {
|
1080 |
723 |
this.legend = aLegend;
|
1081 |
724 |
fillDialog();
|
1082 |
|
Enumeration<Class<? extends ILegendPanel>> en = pages.keys();
|
1083 |
|
while (en.hasMoreElements()) {
|
1084 |
|
ILegendPanel page = (ILegendPanel) pages.get(en.nextElement());
|
|
725 |
for(ILegendPanel page : this.pages ) {
|
|
726 |
// Enumeration<Class<? extends ILegendPanel>> en = pages.keys();
|
|
727 |
// while (en.hasMoreElements()) {
|
|
728 |
// ILegendPanel page = (ILegendPanel) pages.get(en.nextElement());
|
1085 |
729 |
if (legend.getClass().equals(page.getLegendClass())) {
|
1086 |
730 |
setActivePage(page);
|
1087 |
731 |
expandAndSelect(page);
|
... | ... | |
1098 |
742 |
return 800;
|
1099 |
743 |
}
|
1100 |
744 |
|
1101 |
|
// public static void addLegendDriver(Class<? extends IFMapLegendDriver>
|
1102 |
|
// legendDriverClass) {
|
1103 |
|
// if (!legendDriverPool.contains(legendDriverClass)) {
|
1104 |
|
// legendDriverPool.add(legendDriverClass);
|
1105 |
|
// }
|
1106 |
|
// }
|
|
745 |
@Override
|
|
746 |
public ILegend getLegend() {
|
|
747 |
return this.legend;
|
|
748 |
}
|
|
749 |
|
|
750 |
@Override
|
|
751 |
public void setLegend(ILegend legend) {
|
|
752 |
applyLegend(legend);
|
|
753 |
}
|
|
754 |
|
|
755 |
@Override
|
|
756 |
public FLayer getLayer() {
|
|
757 |
return this.layer;
|
|
758 |
}
|
|
759 |
|
|
760 |
@Override
|
|
761 |
public void setLayer(FLayer layer) {
|
|
762 |
this.layer = layer;
|
|
763 |
applyLegend(((Classifiable) layer).getLegend());
|
|
764 |
}
|
|
765 |
|
|
766 |
@Override
|
|
767 |
public ILegendPanel getPage(Class<? extends ILegendPanel> pageClass) {
|
|
768 |
return this.pages.get(pageClass);
|
|
769 |
}
|
|
770 |
|
|
771 |
@Override
|
|
772 |
public Collection<ILegendPanel> getPages() {
|
|
773 |
return this.pages.asCollection();
|
|
774 |
}
|
|
775 |
|
1107 |
776 |
}
|