svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / StyleSelector.java @ 27576
History | View | Annotate | Download (15.5 KB)
1 | 11055 | jaume | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | 22951 | vcaballero | *
|
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | * Revision 1.11 2007-08-21 09:32:53 jvidal
|
||
47 | * javadoc
|
||
48 | *
|
||
49 | * Revision 1.10 2007/05/31 09:36:22 jaume
|
||
50 | * *** empty log message ***
|
||
51 | *
|
||
52 | * Revision 1.9 2007/05/10 09:47:50 jaume
|
||
53 | * *** empty log message ***
|
||
54 | *
|
||
55 | * Revision 1.8 2007/05/08 15:44:07 jaume
|
||
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | * Revision 1.7 2007/04/27 12:10:17 jaume
|
||
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | * Revision 1.6 2007/04/11 16:02:43 jaume
|
||
62 | * file filter
|
||
63 | *
|
||
64 | * Revision 1.5 2007/04/05 16:08:34 jaume
|
||
65 | * Styled labeling stuff
|
||
66 | *
|
||
67 | * Revision 1.4 2007/04/04 16:01:14 jaume
|
||
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | * Revision 1.2 2007/03/09 11:25:00 jaume
|
||
71 | * Advanced symbology (start committing)
|
||
72 | *
|
||
73 | * Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
||
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | * Revision 1.1.2.3 2007/02/08 15:43:04 jaume
|
||
77 | * some bug fixes in the editor and removed unnecessary imports
|
||
78 | *
|
||
79 | * Revision 1.1.2.2 2007/01/30 18:10:10 jaume
|
||
80 | * start commiting labeling stuff
|
||
81 | *
|
||
82 | * Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
||
83 | * *** empty log message ***
|
||
84 | *
|
||
85 | *
|
||
86 | */
|
||
87 | 10959 | jaume | package com.iver.cit.gvsig.gui.styling; |
88 | |||
89 | 18623 | jdominguez | import java.awt.BorderLayout; |
90 | 10959 | jaume | import java.awt.Color; |
91 | import java.awt.Component; |
||
92 | import java.awt.Dimension; |
||
93 | 11073 | jaume | import java.awt.FlowLayout; |
94 | 11503 | jaume | import java.awt.event.ActionEvent; |
95 | import java.awt.event.ActionListener; |
||
96 | 10959 | jaume | import java.io.File; |
97 | 11073 | jaume | import java.io.FileWriter; |
98 | 10959 | jaume | import java.util.prefs.Preferences; |
99 | |||
100 | 11404 | jaume | import javax.swing.BorderFactory; |
101 | 10959 | jaume | import javax.swing.BoxLayout; |
102 | 11055 | jaume | import javax.swing.JComponent; |
103 | 11073 | jaume | import javax.swing.JFileChooser; |
104 | 10959 | jaume | import javax.swing.JLabel; |
105 | import javax.swing.JList; |
||
106 | 27576 | vcaballero | import javax.swing.JOptionPane; |
107 | 10959 | jaume | import javax.swing.JPanel; |
108 | 11073 | jaume | import javax.swing.JTextField; |
109 | 10959 | jaume | import javax.swing.ListCellRenderer; |
110 | import javax.swing.event.ListSelectionEvent; |
||
111 | import javax.swing.event.ListSelectionListener; |
||
112 | |||
113 | 11073 | jaume | import org.exolab.castor.xml.Marshaller; |
114 | 18623 | jdominguez | import org.gvsig.gui.beans.AcceptCancelPanel; |
115 | import org.gvsig.gui.beans.controls.dnd.JDnDList; |
||
116 | 10959 | jaume | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
117 | |||
118 | import com.iver.andami.PluginServices; |
||
119 | 11073 | jaume | import com.iver.andami.messages.NotificationManager; |
120 | 18623 | jdominguez | import com.iver.cit.gvsig.fmap.core.CartographicSupport; |
121 | 27507 | vcaballero | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
122 | 11503 | jaume | import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
123 | 10959 | jaume | import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
124 | 18623 | jdominguez | import com.iver.cit.gvsig.gui.JComboBoxUnits; |
125 | 11559 | jaume | import com.iver.cit.gvsig.gui.panels.ImageSizePanel; |
126 | 11073 | jaume | import com.iver.utiles.XMLEntity; |
127 | 10959 | jaume | |
128 | /**
|
||
129 | 13189 | jvidal | * Creates a panel where the user can select a style for an object that allows
|
130 | * to manage this property.This panel will be similar to the symbol selector panel
|
||
131 | * and, on it, the user will have a previsualization of the style of objects
|
||
132 | * stored and posibilities to modify an existing one, to create a new one
|
||
133 | * and so on.
|
||
134 | 10959 | jaume | *
|
135 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
136 | *
|
||
137 | */
|
||
138 | 24102 | vcaballero | public class StyleSelector extends SymbolSelector{ |
139 | 18623 | jdominguez | private static final long serialVersionUID = -7476555713446755512L; |
140 | 11404 | jaume | private ImageSizePanel isp;
|
141 | 22951 | vcaballero | private IStyle styleType;
|
142 | 27507 | vcaballero | private IStyle previousStyle;
|
143 | 27278 | vcaballero | private boolean showPanelOptions = true; |
144 | 22837 | vcaballero | |
145 | 10959 | jaume | public StyleSelector(IStyle style, int shapeType) { |
146 | 22951 | vcaballero | this(style, shapeType, new StyleSelectorFilter() { |
147 | |||
148 | 10959 | jaume | public boolean accepts(Object obj) { |
149 | return obj instanceof IStyle; |
||
150 | } |
||
151 | 22951 | vcaballero | |
152 | public IStyle getAllowedObject() {
|
||
153 | return null; |
||
154 | } |
||
155 | 10959 | jaume | }); |
156 | } |
||
157 | 13189 | jvidal | /**
|
158 | * Constructor method
|
||
159 | *
|
||
160 | * @param style
|
||
161 | * @param shapeType
|
||
162 | * @param filter
|
||
163 | */
|
||
164 | 22951 | vcaballero | public StyleSelector(IStyle style, int shapeType, StyleSelectorFilter filter) { |
165 | 27278 | vcaballero | this(style, shapeType, filter, true); |
166 | } |
||
167 | |||
168 | |||
169 | public StyleSelector(IStyle style, int shapeType, StyleSelectorFilter filter, boolean showPanelOptions) { |
||
170 | 18623 | jdominguez | super(null, shapeType, filter, false); |
171 | 11503 | jaume | |
172 | 27507 | vcaballero | this.previousStyle = (IStyle)style;
|
173 | IStyle clonedStyle = null;
|
||
174 | if (style != null){ |
||
175 | clonedStyle = SymbologyFactory.createStyleFromXML( |
||
176 | ((IStyle)style).getXMLEntity(), "");
|
||
177 | } |
||
178 | |||
179 | |||
180 | 27278 | vcaballero | this.showPanelOptions = showPanelOptions;
|
181 | |||
182 | 24028 | vcaballero | styleType = ((StyleSelectorFilter)filter).getAllowedObject(); |
183 | 22951 | vcaballero | Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
184 | 10959 | jaume | rootDir = new File(prefs.get("SymbolStylesFolder", System.getProperty("user.home")+"/gvSIG/Styles")); |
185 | if (!rootDir.exists())
|
||
186 | rootDir.mkdir(); |
||
187 | 22837 | vcaballero | |
188 | 18623 | jdominguez | try {
|
189 | 27507 | vcaballero | initialize(clonedStyle); |
190 | 18623 | jdominguez | } catch (ClassNotFoundException e) { |
191 | throw new Error(e); |
||
192 | } |
||
193 | 10959 | jaume | lblTitle.setText(PluginServices.getText(this, "label_styles")); |
194 | treeRootName = PluginServices.getText(this, "style_library"); |
||
195 | 22837 | vcaballero | |
196 | 18623 | jdominguez | } |
197 | 10959 | jaume | |
198 | 27278 | vcaballero | |
199 | |||
200 | 18623 | jdominguez | @Override
|
201 | protected void initialize(Object currentElement) throws ClassNotFoundException { |
||
202 | 22951 | vcaballero | library = new StyleLibrary(rootDir);
|
203 | 10995 | jaume | |
204 | 22951 | vcaballero | this.setLayout(new BorderLayout()); |
205 | this.setSize(400, 221); |
||
206 | 10995 | jaume | |
207 | 22951 | vcaballero | this.add(getJNorthPanel(), BorderLayout.NORTH); |
208 | this.add(getJSplitPane(), BorderLayout.CENTER); |
||
209 | this.add(getJEastPanel(), BorderLayout.EAST); |
||
210 | ActionListener okAction = new ActionListener() { |
||
211 | public void actionPerformed(ActionEvent e) { |
||
212 | accepted = true;
|
||
213 | PluginServices.getMDIManager().closeWindow(StyleSelector.this); |
||
214 | } |
||
215 | }, cancelAction = new ActionListener() { |
||
216 | public void actionPerformed(ActionEvent e) { |
||
217 | 24102 | vcaballero | accepted = false;
|
218 | 22951 | vcaballero | PluginServices.getMDIManager().closeWindow(StyleSelector.this); |
219 | } |
||
220 | }; |
||
221 | 18623 | jdominguez | |
222 | 22951 | vcaballero | okCancelPanel = new AcceptCancelPanel();
|
223 | okCancelPanel.setOkButtonActionListener(okAction); |
||
224 | okCancelPanel.setCancelButtonActionListener(cancelAction); |
||
225 | 11503 | jaume | |
226 | 22951 | vcaballero | this.add(okCancelPanel, BorderLayout.SOUTH); |
227 | libraryBrowser.setSelectionRow(0);
|
||
228 | 22837 | vcaballero | |
229 | 22951 | vcaballero | SillyDragNDropAction dndAction = new SillyDragNDropAction();
|
230 | libraryBrowser.addMouseListener(dndAction); |
||
231 | libraryBrowser.addMouseMotionListener(dndAction); |
||
232 | getJListSymbols().addMouseListener(dndAction); |
||
233 | getJListSymbols().addMouseMotionListener(dndAction); |
||
234 | 27507 | vcaballero | |
235 | 22951 | vcaballero | setSymbol(currentElement); |
236 | } |
||
237 | 22837 | vcaballero | |
238 | 18623 | jdominguez | @Override
|
239 | public void setSymbol(Object style) { |
||
240 | ((StylePreviewer) jPanelPreview).setStyle((IStyle) style); |
||
241 | updateOptionsPanel(); |
||
242 | 10959 | jaume | } |
243 | 22837 | vcaballero | |
244 | 18623 | jdominguez | @Override
|
245 | public Object getSelectedObject() { |
||
246 | 24698 | vcaballero | // if (!accepted) return null;
|
247 | 18623 | jdominguez | Object mySelectedElement = ((StylePreviewer) jPanelPreview).getStyle();
|
248 | 22837 | vcaballero | |
249 | 24698 | vcaballero | if(mySelectedElement == null) |
250 | return null; |
||
251 | |||
252 | 18623 | jdominguez | if (mySelectedElement instanceof CartographicSupport) { |
253 | CartographicSupport csSym = (CartographicSupport) mySelectedElement; |
||
254 | csSym.setUnit(cmbUnits.getSelectedUnitIndex()); |
||
255 | csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex()); |
||
256 | } |
||
257 | 22837 | vcaballero | |
258 | 18623 | jdominguez | return mySelectedElement;
|
259 | } |
||
260 | 22837 | vcaballero | |
261 | 10995 | jaume | protected SymbolSelectorListModel newListModel() {
|
262 | StyleSelectorListModel listModel = new StyleSelectorListModel(
|
||
263 | 10959 | jaume | dir, |
264 | sFilter, |
||
265 | 10995 | jaume | StyleSelectorListModel.STYLE_FILE_EXTENSION); |
266 | 10959 | jaume | return listModel;
|
267 | |||
268 | } |
||
269 | |||
270 | protected JPanel getJPanelOptions() { |
||
271 | if (jPanelOptions == null) { |
||
272 | jPanelOptions = new GridBagLayoutPanel();
|
||
273 | 27278 | vcaballero | if(showPanelOptions){
|
274 | jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options"))); |
||
275 | jPanelOptions.addComponent(getImageSizePanel()); |
||
276 | jPanelOptions.addComponent(PluginServices.getText(this, "units"), |
||
277 | cmbUnits = new JComboBoxUnits(true)); |
||
278 | jPanelOptions.addComponent("",
|
||
279 | cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
||
280 | } |
||
281 | 10959 | jaume | } |
282 | 22951 | vcaballero | return jPanelOptions;
|
283 | } |
||
284 | 22837 | vcaballero | |
285 | 18623 | jdominguez | /**
|
286 | 22837 | vcaballero | *
|
287 | 22951 | vcaballero | * This method initializes ImageSizePanel
|
288 | *
|
||
289 | * @return isp ImageSizePanel
|
||
290 | */
|
||
291 | private ImageSizePanel getImageSizePanel() {
|
||
292 | if (isp == null) { |
||
293 | 11503 | jaume | isp = new ImageSizePanel();
|
294 | isp.addActionListener(new ActionListener() { |
||
295 | public void actionPerformed(ActionEvent e) { |
||
296 | 18623 | jdominguez | ILabelStyle st = (ILabelStyle) getSelectedObject(); |
297 | if (st != null) { |
||
298 | double[] sz = isp.getImageDimension(); |
||
299 | st.setSize(sz[0], sz[1]); |
||
300 | } |
||
301 | 11503 | jaume | } |
302 | }); |
||
303 | } |
||
304 | |||
305 | return isp;
|
||
306 | } |
||
307 | |||
308 | protected void updateOptionsPanel() { |
||
309 | 27278 | vcaballero | if(showPanelOptions){
|
310 | IStyle s = ((StylePreviewer) jPanelPreview).getStyle(); |
||
311 | 27507 | vcaballero | if (s == null){ |
312 | Dimension sz = new Dimension(0,0); |
||
313 | getImageSizePanel().setImageSize(sz); |
||
314 | } |
||
315 | 27278 | vcaballero | if (s instanceof ILabelStyle) { |
316 | ILabelStyle lab = (ILabelStyle) s; |
||
317 | Dimension sz = lab.getSize();
|
||
318 | getImageSizePanel().setImageSize(sz); |
||
319 | } |
||
320 | 11503 | jaume | } |
321 | 22951 | vcaballero | } |
322 | 11503 | jaume | |
323 | |||
324 | 22951 | vcaballero | /**
|
325 | * This method initializes jList
|
||
326 | *
|
||
327 | * @return javax.swing.JList
|
||
328 | */
|
||
329 | protected JList getJListSymbols() { |
||
330 | if (jListSymbols == null) { |
||
331 | jListSymbols = new JDnDList();
|
||
332 | jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
||
333 | jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
||
334 | jListSymbols.setVisibleRowCount(-1);
|
||
335 | jListSymbols.addListSelectionListener(new ListSelectionListener() { |
||
336 | public void valueChanged(ListSelectionEvent e) { |
||
337 | 27507 | vcaballero | if (jListSymbols.getSelectedValue()!=null) { |
338 | IStyle selStyle = SymbologyFactory.createStyleFromXML( |
||
339 | ((IStyle) jListSymbols.getSelectedValue()).getXMLEntity(), null);
|
||
340 | setStyle(selStyle); |
||
341 | updateOptionsPanel(); |
||
342 | } |
||
343 | 22951 | vcaballero | } |
344 | 27507 | vcaballero | |
345 | 22951 | vcaballero | }); |
346 | ListCellRenderer renderer = new ListCellRenderer() { |
||
347 | private Color mySelectedBGColor = new Color(255,145,100,255); |
||
348 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||
349 | IStyle sty = (IStyle) value; |
||
350 | JPanel pnl = new JPanel(); |
||
351 | BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS); |
||
352 | pnl.setLayout(layout); |
||
353 | Color bgColor = (isSelected) ? mySelectedBGColor
|
||
354 | : getJListSymbols().getBackground(); |
||
355 | 10959 | jaume | |
356 | 22951 | vcaballero | pnl.setBackground(bgColor); |
357 | StylePreviewer sp = new StylePreviewer();
|
||
358 | sp.setShowOutline(false);
|
||
359 | sp.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||
360 | sp.setPreferredSize(new Dimension(50, 50)); |
||
361 | sp.setStyle(sty); |
||
362 | sp.setBackground(bgColor); |
||
363 | pnl.add(sp); |
||
364 | JLabel lbl = new JLabel(sty.getDescription()); |
||
365 | lbl.setBackground(bgColor); |
||
366 | lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||
367 | pnl.add(lbl); |
||
368 | 10959 | jaume | |
369 | 22951 | vcaballero | return pnl;
|
370 | } |
||
371 | 10959 | jaume | |
372 | 22951 | vcaballero | }; |
373 | jListSymbols.setCellRenderer(renderer); |
||
374 | } |
||
375 | return jListSymbols;
|
||
376 | } |
||
377 | /**
|
||
378 | * Modify the previsualization showed in the panel with the style of the
|
||
379 | * new object selected.
|
||
380 | *
|
||
381 | * @param selectedValue
|
||
382 | */
|
||
383 | protected void setStyle(Object selectedValue) { |
||
384 | 18623 | jdominguez | //selectedElement = selectedValue;
|
385 | 11503 | jaume | ((StylePreviewer) jPanelPreview).setStyle((IStyle) selectedValue); |
386 | doLayout(); |
||
387 | 27507 | vcaballero | updateOptionsPanel(); |
388 | 11503 | jaume | repaint(); |
389 | 10959 | jaume | } |
390 | |||
391 | 22837 | vcaballero | protected void newPressed() { |
392 | 22951 | vcaballero | |
393 | StyleEditor se = new StyleEditor(styleType);
|
||
394 | 22837 | vcaballero | PluginServices.getMDIManager().addWindow(se); |
395 | setStyle(se.getStyle()); |
||
396 | 22951 | vcaballero | |
397 | 22837 | vcaballero | } |
398 | |||
399 | 11055 | jaume | protected void propertiesPressed() { |
400 | 24698 | vcaballero | // boolean state = accepted;
|
401 | // accepted = true;
|
||
402 | 18623 | jdominguez | StyleEditor se = new StyleEditor((IStyle) getSelectedObject());
|
403 | 22951 | vcaballero | if(se != null){ |
404 | PluginServices.getMDIManager().addWindow(se); |
||
405 | setStyle(se.getStyle()); |
||
406 | } |
||
407 | 24698 | vcaballero | // accepted = state;
|
408 | 11055 | jaume | } |
409 | |||
410 | 11073 | jaume | protected void savePressed() { |
411 | 24698 | vcaballero | if (getSelectedObject() == null) |
412 | 11073 | jaume | return;
|
413 | |||
414 | JFileChooser jfc = new JFileChooser(rootDir); |
||
415 | javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
|
||
416 | public boolean accept(File f) { |
||
417 | return f.getAbsolutePath().
|
||
418 | toLowerCase(). |
||
419 | endsWith(StyleSelectorListModel.STYLE_FILE_EXTENSION); |
||
420 | } |
||
421 | |||
422 | public String getDescription() { |
||
423 | return PluginServices.getText(
|
||
424 | 11141 | jaume | this, "gvSIG_style_definition_file")+ " ("+StyleSelectorListModel.STYLE_FILE_EXTENSION+")"; |
425 | 11073 | jaume | } |
426 | }; |
||
427 | jfc.setFileFilter(ff); |
||
428 | JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
||
429 | accessory.add(new JLabel(PluginServices.getText(this, "enter_description"))); |
||
430 | JTextField txtDesc = new JTextField(25); |
||
431 | 22462 | vcaballero | txtDesc.setText(((IStyle) getSelectedObject()).getDescription()); |
432 | 11073 | jaume | accessory.add(txtDesc); |
433 | jfc.setAccessory(accessory); |
||
434 | if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { |
||
435 | File targetFile = jfc.getSelectedFile();
|
||
436 | |||
437 | String fExtension = StyleSelectorListModel.STYLE_FILE_EXTENSION;
|
||
438 | |||
439 | // apply description
|
||
440 | String desc;
|
||
441 | if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) { |
||
442 | // default to file name
|
||
443 | String s = targetFile.getAbsolutePath();
|
||
444 | desc = s.substring(s.lastIndexOf(File.separator)+1).replaceAll(fExtension, ""); |
||
445 | } else {
|
||
446 | desc = txtDesc.getText().trim(); |
||
447 | } |
||
448 | IStyle s = (IStyle) getSelectedObject(); |
||
449 | s.setDescription(desc); |
||
450 | |||
451 | // save it
|
||
452 | XMLEntity xml = s.getXMLEntity(); |
||
453 | if (!targetFile.
|
||
454 | getAbsolutePath(). |
||
455 | toLowerCase(). |
||
456 | endsWith(fExtension)) |
||
457 | targetFile = new File(targetFile.getAbsolutePath() + fExtension); |
||
458 | 27576 | vcaballero | if(targetFile.exists()){
|
459 | int resp = JOptionPane.showConfirmDialog( |
||
460 | (Component) PluginServices.getMainFrame(),
|
||
461 | PluginServices.getText(this,
|
||
462 | "fichero_ya_existe_seguro_desea_guardarlo"),
|
||
463 | PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION); |
||
464 | if (resp != JOptionPane.YES_OPTION) { |
||
465 | return;
|
||
466 | } |
||
467 | } |
||
468 | 11073 | jaume | FileWriter writer;
|
469 | try {
|
||
470 | writer = new FileWriter(targetFile.getAbsolutePath()); |
||
471 | Marshaller m = new Marshaller(writer);
|
||
472 | m.setEncoding("ISO-8859-1");
|
||
473 | m.marshal(xml.getXmlTag()); |
||
474 | |||
475 | } catch (Exception ex) { |
||
476 | NotificationManager.addError( |
||
477 | PluginServices.getText(this, "save_error"), ex); |
||
478 | } |
||
479 | getJListSymbols().setModel(newListModel()); |
||
480 | } |
||
481 | } |
||
482 | |||
483 | 22951 | vcaballero | /**
|
484 | * This method initializes jPanelPreview
|
||
485 | *
|
||
486 | * @return javax.swing.JComponent
|
||
487 | */
|
||
488 | protected JComponent getJPanelPreview() { |
||
489 | if (jPanelPreview == null) { |
||
490 | jPanelPreview = new StylePreviewer();
|
||
491 | jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100)); |
||
492 | jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
||
493 | ((StylePreviewer) jPanelPreview).setShowOutline(true);
|
||
494 | } |
||
495 | return jPanelPreview;
|
||
496 | } |
||
497 | 18623 | jdominguez | |
498 | 22951 | vcaballero | @Override
|
499 | public void actionPerformed(ActionEvent e) { |
||
500 | if (!act) return; |
||
501 | 18623 | jdominguez | Object selectedElement = ((StylePreviewer) jPanelPreview).getStyle();//getSelectedObject(); |
502 | 25933 | vcaballero | performActionOn(selectedElement, (JComponent) e.getSource());
|
503 | 18623 | jdominguez | StyleSelector.this.repaint(); |
504 | 22951 | vcaballero | } |
505 | 22837 | vcaballero | |
506 | 22951 | vcaballero | public int getUnit() { |
507 | return cmbUnits.getSelectedUnitIndex();
|
||
508 | } |
||
509 | 22837 | vcaballero | |
510 | 22951 | vcaballero | public int getReferenceSystem() { |
511 | return cmbReferenceSystem.getSelectedIndex();
|
||
512 | } |
||
513 | 22837 | vcaballero | |
514 | 18623 | jdominguez | public void setUnit(int unit) { |
515 | cmbUnits.setSelectedUnitIndex(unit); |
||
516 | } |
||
517 | 22837 | vcaballero | |
518 | 18623 | jdominguez | public void setReferenceSystem(int referenceSystem) { |
519 | cmbReferenceSystem.setSelectedIndex(referenceSystem); |
||
520 | } |
||
521 | 24102 | vcaballero | |
522 | 24698 | vcaballero | public void windowClosed() { |
523 | if (!accepted) {
|
||
524 | 27507 | vcaballero | IStyle clonedStyle = null;
|
525 | if (previousStyle != null){ |
||
526 | clonedStyle = SymbologyFactory.createStyleFromXML( |
||
527 | ((IStyle)previousStyle).getXMLEntity(), "");
|
||
528 | } |
||
529 | ((StylePreviewer) jPanelPreview).setStyle(clonedStyle); |
||
530 | 24698 | vcaballero | } |
531 | } |
||
532 | |||
533 | 27507 | vcaballero | /**
|
534 | * Invoked when the RESET button is pressed
|
||
535 | */
|
||
536 | protected void resetPressed() { |
||
537 | IStyle clonedStyle = null;
|
||
538 | if (previousStyle != null){ |
||
539 | clonedStyle = SymbologyFactory.createStyleFromXML( |
||
540 | ((IStyle)previousStyle).getXMLEntity(), "");
|
||
541 | } |
||
542 | setStyle(clonedStyle); |
||
543 | } |
||
544 | |||
545 | |||
546 | 10959 | jaume | } |