svn-gvsig-desktop / tags / PilotoRedes_Build_1 / extensions / extGraph_predes / src / com / iver / cit / gvsig / gvsig / gui / styling / SymbolSelector.java @ 11097
History | View | Annotate | Download (19.2 KB)
1 |
/*
|
---|---|
2 |
* Created on 26-abr-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.gvsig.gui.styling; |
45 |
|
46 |
import java.awt.BorderLayout; |
47 |
import java.awt.Color; |
48 |
import java.awt.Component; |
49 |
import java.awt.Dimension; |
50 |
import java.awt.FlowLayout; |
51 |
import java.awt.Font; |
52 |
import java.awt.GridLayout; |
53 |
import java.awt.event.ActionEvent; |
54 |
import java.awt.event.ActionListener; |
55 |
import java.io.File; |
56 |
import java.io.FileFilter; |
57 |
import java.io.FileWriter; |
58 |
|
59 |
import javax.swing.BorderFactory; |
60 |
import javax.swing.BoxLayout; |
61 |
import javax.swing.JComponent; |
62 |
import javax.swing.JFileChooser; |
63 |
import javax.swing.JLabel; |
64 |
import javax.swing.JList; |
65 |
import javax.swing.JOptionPane; |
66 |
import javax.swing.JPanel; |
67 |
import javax.swing.JScrollPane; |
68 |
import javax.swing.JSplitPane; |
69 |
import javax.swing.JTree; |
70 |
import javax.swing.ListCellRenderer; |
71 |
import javax.swing.event.ListSelectionEvent; |
72 |
import javax.swing.event.ListSelectionListener; |
73 |
import javax.swing.event.TreeModelListener; |
74 |
import javax.swing.tree.TreeModel; |
75 |
import javax.swing.tree.TreePath; |
76 |
|
77 |
import org.exolab.castor.xml.Marshaller; |
78 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
79 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
80 |
import org.gvsig.gui.beans.swing.JButton; |
81 |
|
82 |
import com.iver.andami.PluginServices; |
83 |
import com.iver.andami.messages.NotificationManager; |
84 |
import com.iver.andami.ui.mdiManager.IWindow; |
85 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
86 |
import com.iver.cit.gvsig.fmap.core.FShape; |
87 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
88 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
89 |
import com.iver.utiles.StringUtilities; |
90 |
import com.iver.utiles.XMLEntity; |
91 |
|
92 |
import de.ios.framework.swing.JDecimalField; |
93 |
import de.ios.framework.swing.JNumberField; |
94 |
|
95 |
/**
|
96 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
97 |
*/
|
98 |
public class SymbolSelector extends JPanel implements IWindow{ |
99 |
|
100 |
private JTree treeFamilies = null; |
101 |
private JList jListSymbols = null; |
102 |
private JPanel jPanel = null; |
103 |
private JScrollPane jScrollPane = null; |
104 |
private JScrollPane jScrollPane1 = null; |
105 |
private SymbolPreview jPanelPreview = null; |
106 |
private GridBagLayoutPanel jPanelOptions = null; |
107 |
private WindowInfo wi;
|
108 |
private JSplitPane jSplitPane = null; |
109 |
private File symbolDir; |
110 |
private AcceptCancelPanel okCancelPanel;
|
111 |
private ISymbol selectedSymbol = null; |
112 |
private JPanel northPanel; |
113 |
private ColorChooserPanel jcc1;
|
114 |
private ColorChooserPanel jcc2;
|
115 |
private JNumberField txtSize;
|
116 |
private JDecimalField txtAngle;
|
117 |
private JPanel jPanelButtons; |
118 |
private JButton btnProperties; |
119 |
private int shapeType; |
120 |
private JButton btnSaveSymbol; |
121 |
private JButton btnResetSymbol; |
122 |
private ActionListener buttonListener = new MyButtonListener(); |
123 |
/**
|
124 |
* This method initializes
|
125 |
*
|
126 |
*/
|
127 |
public SymbolSelector(ISymbol symbol, int shapeType) { |
128 |
super();
|
129 |
this.selectedSymbol = symbol;
|
130 |
this.shapeType = shapeType;
|
131 |
this.symbolDir = new File(getClass(). |
132 |
getClassLoader(). |
133 |
getResource("symbols").
|
134 |
getFile()); |
135 |
initialize(); |
136 |
} |
137 |
|
138 |
/**
|
139 |
* This method initializes
|
140 |
*
|
141 |
*/
|
142 |
public SymbolSelector(ISymbol symbol, int shapeType, File symbolDir) { |
143 |
super();
|
144 |
this.selectedSymbol = symbol;
|
145 |
this.shapeType = shapeType;
|
146 |
this.symbolDir = symbolDir;
|
147 |
initialize(); |
148 |
} |
149 |
/**
|
150 |
* This method initializes this
|
151 |
*
|
152 |
*/
|
153 |
private void initialize() { |
154 |
|
155 |
this.setLayout(new BorderLayout()); |
156 |
this.setSize(400, 221); |
157 |
|
158 |
this.add(getJNorthPanel(), BorderLayout.NORTH); |
159 |
this.add(getJSplitPane(), BorderLayout.CENTER); |
160 |
this.add(getJEastPanel(), BorderLayout.EAST); |
161 |
ActionListener okAction = new ActionListener() { |
162 |
public void actionPerformed(ActionEvent e) { |
163 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
164 |
} |
165 |
}, cancelAction = new ActionListener() { |
166 |
public void actionPerformed(ActionEvent e) { |
167 |
setSymbol(null);
|
168 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
169 |
} |
170 |
}; |
171 |
|
172 |
okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
|
173 |
|
174 |
|
175 |
this.add(okCancelPanel, BorderLayout.SOUTH); |
176 |
} |
177 |
|
178 |
private JPanel getJNorthPanel() throws IllegalArgumentException { |
179 |
if (northPanel == null) { |
180 |
String text = ""; |
181 |
switch (shapeType) {
|
182 |
case FShape.POINT:
|
183 |
text = PluginServices.getText(this, "point_symbols"); |
184 |
break;
|
185 |
case FShape.LINE:
|
186 |
text = PluginServices.getText(this, "line_symbols"); |
187 |
break;
|
188 |
case FShape.POLYGON:
|
189 |
text = PluginServices.getText(this, "polygon_symbols"); |
190 |
break;
|
191 |
default:
|
192 |
throw new IllegalArgumentException(PluginServices.getText(this, "shape_type_not_yet_supported")); |
193 |
} |
194 |
northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
195 |
JLabel lbl = new JLabel(text); |
196 |
lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
|
197 |
northPanel.add(lbl); |
198 |
} |
199 |
return northPanel;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* This method initializes jList
|
204 |
*
|
205 |
* @return javax.swing.JList
|
206 |
*/
|
207 |
private JTree getJListFav() { |
208 |
if (treeFamilies == null) { |
209 |
treeFamilies = new JTree(); |
210 |
treeFamilies.setPreferredSize(new java.awt.Dimension(70,100)); |
211 |
try {
|
212 |
treeFamilies.setModel(new TreeModel() { |
213 |
final class MyFile extends File { |
214 |
public MyFile(String pathname) { |
215 |
super(pathname);
|
216 |
} |
217 |
|
218 |
public String toString() { |
219 |
if (this.equals(root)) |
220 |
return PluginServices.getText(this, "symbol_library"); |
221 |
String path = getAbsolutePath();
|
222 |
String prefixToRemove = symbolDir.getAbsolutePath();
|
223 |
path = path.substring(prefixToRemove.length()+1, path.length());
|
224 |
return path;
|
225 |
} |
226 |
}; |
227 |
MyFile root = new MyFile(symbolDir.getAbsolutePath());
|
228 |
|
229 |
private FileFilter ff = new FileFilter() { |
230 |
public boolean accept(File pathname) { |
231 |
return pathname.isDirectory();
|
232 |
} |
233 |
}; |
234 |
|
235 |
public Object getRoot() { |
236 |
return root;
|
237 |
} |
238 |
|
239 |
public int getChildCount(Object parent) { |
240 |
return ((File) parent).listFiles(ff).length; |
241 |
} |
242 |
|
243 |
public boolean isLeaf(Object node) { |
244 |
return getChildCount(node)==0; |
245 |
} |
246 |
|
247 |
public void addTreeModelListener(TreeModelListener l) { |
248 |
// TODO Necessite?
|
249 |
|
250 |
} |
251 |
|
252 |
public void removeTreeModelListener(TreeModelListener l) { |
253 |
// TODO Auto-generated method stub
|
254 |
|
255 |
} |
256 |
|
257 |
public Object getChild(Object parent, int index) { |
258 |
return new MyFile(((File) parent).listFiles(ff)[index].getAbsolutePath()); |
259 |
} |
260 |
|
261 |
public int getIndexOfChild(Object parent, Object child) { |
262 |
if (parent == null) |
263 |
return -1; |
264 |
File[] files = ((File) parent).listFiles(ff); |
265 |
for (int i = 0; i < files.length; i++) { |
266 |
if (files[i].equals((File) child)) |
267 |
return i;
|
268 |
} |
269 |
return -1; |
270 |
} |
271 |
|
272 |
public void valueForPathChanged(TreePath path, Object newValue) { |
273 |
// TODO Auto-generated method stub
|
274 |
} |
275 |
|
276 |
}); |
277 |
treeFamilies.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
|
278 |
public void valueChanged(javax.swing.event.TreeSelectionEvent e) { |
279 |
File node = (File) |
280 |
treeFamilies.getLastSelectedPathComponent(); |
281 |
|
282 |
if (node == null) return; |
283 |
jListSymbols.setModel( |
284 |
new SymbolSelectorListModel(node));
|
285 |
} |
286 |
}); |
287 |
} catch ( ExceptionInInitializerError ex ) { |
288 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "could_not_find_symbol_directory")); |
289 |
} |
290 |
} |
291 |
return treeFamilies;
|
292 |
} |
293 |
|
294 |
/**
|
295 |
* This method initializes jList
|
296 |
*
|
297 |
* @return javax.swing.JList
|
298 |
*/
|
299 |
private JList getJListSymbols() { |
300 |
if (jListSymbols == null) { |
301 |
jListSymbols = new JList(); |
302 |
jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
303 |
jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
304 |
jListSymbols.setVisibleRowCount(-1);
|
305 |
jListSymbols.addListSelectionListener(new ListSelectionListener() { |
306 |
public void valueChanged(ListSelectionEvent e) { |
307 |
setSymbol((ISymbol) jListSymbols.getSelectedValue()); |
308 |
updateOptionsPanel(); |
309 |
} |
310 |
}); |
311 |
ListCellRenderer renderer = new ListCellRenderer() { |
312 |
private Color mySelectedBGColor = new Color(255,145,100,255); |
313 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
314 |
ISymbol sym = (ISymbol) value; |
315 |
JPanel pnl = new JPanel(); |
316 |
BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS); |
317 |
pnl.setLayout(layout); |
318 |
Color bgColor = (isSelected) ? mySelectedBGColor
|
319 |
: getJListSymbols().getBackground(); |
320 |
|
321 |
pnl.setBackground(bgColor); |
322 |
SymbolPreview sp = new SymbolPreview();
|
323 |
sp.setAlignmentX(Component.CENTER_ALIGNMENT);
|
324 |
sp.setPreferredSize(new Dimension(50, 50)); |
325 |
sp.setSymbol(sym); |
326 |
sp.setBackground(bgColor); |
327 |
pnl.add(sp); |
328 |
JLabel lbl = new JLabel(sym.getDescription()); |
329 |
lbl.setBackground(bgColor); |
330 |
lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
331 |
pnl.add(lbl); |
332 |
|
333 |
return pnl;
|
334 |
} |
335 |
|
336 |
}; |
337 |
jListSymbols.setCellRenderer(renderer); |
338 |
} |
339 |
return jListSymbols;
|
340 |
} |
341 |
|
342 |
protected void updateOptionsPanel() { |
343 |
ISymbol sym = ((ISymbol) jListSymbols.getSelectedValue()); |
344 |
if (sym == null) |
345 |
return;
|
346 |
|
347 |
XMLEntity xml = sym.getXMLEntity(); |
348 |
|
349 |
Color c = null; |
350 |
if (xml.contains("color")) { |
351 |
c = StringUtilities.string2Color(xml.getStringProperty("color"));
|
352 |
} |
353 |
jcc1.setColor(c); |
354 |
|
355 |
if (jcc2 == null) |
356 |
return;
|
357 |
if (xml.contains("outline")) { |
358 |
c = StringUtilities.string2Color(xml.getStringProperty("outline"));
|
359 |
jcc2.setEnabled(true);
|
360 |
jcc2.setColor(c); |
361 |
} else {
|
362 |
jcc2.setEnabled(false);
|
363 |
} |
364 |
|
365 |
|
366 |
} |
367 |
|
368 |
/**
|
369 |
* This method initializes jPanel
|
370 |
*
|
371 |
* @return javax.swing.JPanel
|
372 |
*/
|
373 |
private JPanel getJEastPanel() { |
374 |
if (jPanel == null) { |
375 |
jPanel = new JPanel(); |
376 |
jPanel.setLayout(new BorderLayout()); |
377 |
jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
|
378 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
379 |
aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "preview"))); |
380 |
aux.add(getJPanelPreview()); |
381 |
jPanel.add(aux, BorderLayout.NORTH);
|
382 |
|
383 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
384 |
aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options"))); |
385 |
aux.add(getJPanelOptions()); |
386 |
jPanel.add(aux, BorderLayout.CENTER);
|
387 |
aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5)); |
388 |
aux.add(getJPanelButtons()); |
389 |
jPanel.add(aux, BorderLayout.SOUTH);
|
390 |
} |
391 |
return jPanel;
|
392 |
} |
393 |
|
394 |
private JPanel getJPanelButtons() { |
395 |
if (jPanelButtons == null) { |
396 |
jPanelButtons = new JPanel(); |
397 |
GridLayout layout = new GridLayout(); |
398 |
layout.setColumns(1);
|
399 |
layout.setVgap(5);
|
400 |
jPanelButtons.add(getBtnSaveSymbol()); |
401 |
jPanelButtons.add(getBtnResetSymbol()); |
402 |
jPanelButtons.add(getBtnProperties()); |
403 |
|
404 |
// do not add components bellow this line!
|
405 |
layout.setRows(jPanelButtons.getComponentCount()); |
406 |
jPanelButtons.setLayout(layout); |
407 |
} |
408 |
return jPanelButtons;
|
409 |
} |
410 |
|
411 |
private JButton getBtnResetSymbol() { |
412 |
if (btnResetSymbol == null) { |
413 |
btnResetSymbol = new JButton(); |
414 |
btnResetSymbol.setName("btnResetSymbol");
|
415 |
btnResetSymbol.setText(PluginServices.getText(this, "reset")); |
416 |
btnResetSymbol.addActionListener(buttonListener); |
417 |
} |
418 |
return btnResetSymbol;
|
419 |
} |
420 |
|
421 |
private JButton getBtnSaveSymbol() { |
422 |
if (btnSaveSymbol == null) { |
423 |
btnSaveSymbol = new JButton(); |
424 |
btnSaveSymbol.setName("btnSaveSymbol");
|
425 |
btnSaveSymbol.setText(PluginServices.getText(this, "save")); |
426 |
btnSaveSymbol.addActionListener(buttonListener); |
427 |
} |
428 |
return btnSaveSymbol;
|
429 |
} |
430 |
|
431 |
private JButton getBtnProperties() { |
432 |
if (btnProperties == null) { |
433 |
btnProperties = new JButton(); |
434 |
btnProperties.setName("btnProperties");
|
435 |
btnProperties.setText(PluginServices.getText(this, "properties")); |
436 |
btnProperties.addActionListener(buttonListener); |
437 |
} |
438 |
return btnProperties;
|
439 |
} |
440 |
|
441 |
/**
|
442 |
* This method initializes jScrollPane
|
443 |
*
|
444 |
* @return javax.swing.JScrollPane
|
445 |
*/
|
446 |
private JScrollPane getJScrollPane() { |
447 |
if (jScrollPane == null) { |
448 |
jScrollPane = new JScrollPane(); |
449 |
jScrollPane.setPreferredSize(new java.awt.Dimension(80,130)); |
450 |
jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
451 |
jScrollPane.setViewportView(getJListFav()); |
452 |
} |
453 |
return jScrollPane;
|
454 |
} |
455 |
|
456 |
/**
|
457 |
* This method initializes jScrollPane1
|
458 |
*
|
459 |
* @return javax.swing.JScrollPane
|
460 |
*/
|
461 |
private JScrollPane getJScrollPane1() { |
462 |
if (jScrollPane1 == null) { |
463 |
jScrollPane1 = new JScrollPane(); |
464 |
jScrollPane1.setViewportView(getJListSymbols()); |
465 |
} |
466 |
return jScrollPane1;
|
467 |
} |
468 |
|
469 |
/**
|
470 |
* This method initializes jPanel1
|
471 |
*
|
472 |
* @return javax.swing.JPanel
|
473 |
*/
|
474 |
private SymbolPreview getJPanelPreview() {
|
475 |
if (jPanelPreview == null) { |
476 |
jPanelPreview = new SymbolPreview();
|
477 |
jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100)); |
478 |
jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
479 |
} |
480 |
return jPanelPreview;
|
481 |
} |
482 |
|
483 |
/**
|
484 |
* This method initializes jPanel1
|
485 |
*
|
486 |
* @return javax.swing.JPanel
|
487 |
*/
|
488 |
private JPanel getJPanelOptions() { |
489 |
if (jPanelOptions == null) { |
490 |
jPanelOptions = new GridBagLayoutPanel();
|
491 |
|
492 |
jcc1 = new ColorChooserPanel();
|
493 |
jcc2 = new ColorChooserPanel();
|
494 |
jcc1.setAlpha(255);
|
495 |
jcc2.setAlpha(255);
|
496 |
jcc1.addActionListener(buttonListener); |
497 |
jcc2.addActionListener(buttonListener); |
498 |
if (shapeType == FShape.POINT) {
|
499 |
jPanelOptions.addComponent( |
500 |
PluginServices.getText(this, "color")+":", jcc1); |
501 |
jPanelOptions.addComponent( |
502 |
PluginServices.getText(this, "size")+":", |
503 |
txtSize = new JNumberField());
|
504 |
jPanelOptions.addComponent( |
505 |
PluginServices.getText(this, "angle")+":", |
506 |
txtAngle = new JDecimalField());
|
507 |
} else if (shapeType == FShape.LINE) { |
508 |
jPanelOptions.addComponent( |
509 |
PluginServices.getText(this, "color")+":", jcc1); |
510 |
jPanelOptions.addComponent( |
511 |
PluginServices.getText(this, "width")+":", |
512 |
txtSize = new JNumberField());
|
513 |
jPanelOptions.addComponent(new JLabel("AQUI VA EL COMBO DE PATTERN DE LINEA")); |
514 |
} else if (shapeType == FShape.POLYGON) { |
515 |
jPanelOptions.addComponent( |
516 |
PluginServices.getText(this, "fill_color")+":", jcc1); |
517 |
jPanelOptions.addComponent( |
518 |
PluginServices.getText(this, "outline_color")+":", jcc2); |
519 |
jPanelOptions.addComponent( |
520 |
new JLabel("AQUI VA EL ANCHO DEL CONTORNO")); |
521 |
} |
522 |
} |
523 |
return jPanelOptions;
|
524 |
} |
525 |
|
526 |
public WindowInfo getWindowInfo() {
|
527 |
if (wi == null) { |
528 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
529 |
wi.setWidth(706);
|
530 |
wi.setHeight(500);
|
531 |
wi.setTitle(PluginServices.getText(this, "symbol_selector")); |
532 |
} |
533 |
return wi;
|
534 |
} |
535 |
|
536 |
/**
|
537 |
* This method initializes jSplitPane
|
538 |
*
|
539 |
* @return javax.swing.JSplitPane
|
540 |
*/
|
541 |
private JSplitPane getJSplitPane() { |
542 |
if (jSplitPane == null) { |
543 |
jSplitPane = new JSplitPane(); |
544 |
jSplitPane.setDividerLocation(200);
|
545 |
jSplitPane.setResizeWeight(0.4);
|
546 |
jSplitPane.setLeftComponent(getJScrollPane()); |
547 |
jSplitPane.setRightComponent(getJScrollPane1()); |
548 |
} |
549 |
return jSplitPane;
|
550 |
} |
551 |
|
552 |
/**
|
553 |
* Returns the symbol selected by the user or null if none
|
554 |
* @return
|
555 |
*/
|
556 |
public ISymbol getSymbol() {
|
557 |
return selectedSymbol;
|
558 |
} |
559 |
|
560 |
private void setSymbol(ISymbol symbol) { |
561 |
selectedSymbol = symbol; |
562 |
jPanelPreview.setSymbol(symbol); |
563 |
} |
564 |
|
565 |
|
566 |
private class MyButtonListener implements ActionListener { |
567 |
public void actionPerformed(ActionEvent e) { |
568 |
if (selectedSymbol ==null) |
569 |
return;
|
570 |
|
571 |
JComponent comp = (JComponent) e.getSource(); |
572 |
XMLEntity xml = selectedSymbol.getXMLEntity(); |
573 |
|
574 |
if ( comp.equals(getBtnProperties()) ) {
|
575 |
// properties pressed
|
576 |
SymbolEditor se = new SymbolEditor(selectedSymbol, shapeType);
|
577 |
PluginServices.getMDIManager().addWindow(se); |
578 |
setSymbol(se.getSymbol()); |
579 |
} else if ( comp.equals(getBtnResetSymbol()) ) { |
580 |
// reset pressed
|
581 |
setSymbol(null);
|
582 |
} else if ( comp.equals(getBtnSaveSymbol()) ) { |
583 |
// save pressed
|
584 |
JFileChooser jfc = new JFileChooser(SymbolSelectorListModel.SYMBOL_DIRECTORY); |
585 |
javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
|
586 |
public boolean accept(File f) { |
587 |
return f.getAbsolutePath().
|
588 |
toLowerCase(). |
589 |
endsWith(SymbolSelectorListModel. |
590 |
SYMBOL_FILE_EXTENSION); |
591 |
} |
592 |
|
593 |
public String getDescription() { |
594 |
return PluginServices.getText(
|
595 |
this, "gvSIG_symbol_definition_file")+ " (*.sym)"; |
596 |
} |
597 |
}; |
598 |
jfc.setFileFilter(ff); |
599 |
if (jfc.showSaveDialog(SymbolSelector.this) == JFileChooser.APPROVE_OPTION) { |
600 |
File targetFile = jfc.getSelectedFile();
|
601 |
String fExtension = SymbolSelectorListModel.SYMBOL_FILE_EXTENSION;
|
602 |
if (!targetFile.
|
603 |
getAbsolutePath(). |
604 |
toLowerCase(). |
605 |
endsWith(fExtension)) |
606 |
targetFile = new File(targetFile.getAbsolutePath() + fExtension); |
607 |
FileWriter writer;
|
608 |
try {
|
609 |
writer = new FileWriter(targetFile.getAbsolutePath()); |
610 |
Marshaller m = new Marshaller(writer);
|
611 |
m.setEncoding("ISO-8859-1");
|
612 |
m.marshal(xml.getXmlTag()); |
613 |
|
614 |
} catch (Exception ex) { |
615 |
NotificationManager.addError( |
616 |
PluginServices.getText(this, "save_error"), ex); |
617 |
} |
618 |
} |
619 |
} else if (comp.equals(jcc1) && xml != null) { |
620 |
xml.putProperty("color", StringUtilities.color2String(jcc1.getColor()));
|
621 |
selectedSymbol.setXMLEntity(xml); |
622 |
setSymbol(selectedSymbol); |
623 |
} else if (comp.equals(jcc2) && xml != null) { |
624 |
xml.putProperty("outline", StringUtilities.color2String(jcc2.getColor()));
|
625 |
selectedSymbol.setXMLEntity(xml); |
626 |
setSymbol(selectedSymbol); |
627 |
} |
628 |
|
629 |
SymbolSelector.this.repaint(); |
630 |
} |
631 |
} |
632 |
} // @jve:decl-index=0:visual-constraint="10,10"
|