Revision 11073 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/StyleSelector.java

View differences:

StyleSelector.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.4  2007-04-04 16:01:14  jaume
46
* Revision 1.5  2007-04-05 16:08:34  jaume
47
* Styled labeling stuff
48
*
49
* Revision 1.4  2007/04/04 16:01:14  jaume
47 50
* *** empty log message ***
48 51
*
49 52
* Revision 1.2  2007/03/09 11:25:00  jaume
......
68 71
import java.awt.Color;
69 72
import java.awt.Component;
70 73
import java.awt.Dimension;
74
import java.awt.FlowLayout;
71 75
import java.io.File;
72 76
import java.io.FileFilter;
77
import java.io.FileWriter;
73 78
import java.util.prefs.Preferences;
74 79

  
75 80
import javax.swing.BoxLayout;
76 81
import javax.swing.JComponent;
82
import javax.swing.JFileChooser;
77 83
import javax.swing.JLabel;
78 84
import javax.swing.JList;
79 85
import javax.swing.JPanel;
86
import javax.swing.JTextField;
80 87
import javax.swing.ListCellRenderer;
81 88
import javax.swing.event.ListSelectionEvent;
82 89
import javax.swing.event.ListSelectionListener;
......
84 91
import javax.swing.tree.TreeModel;
85 92
import javax.swing.tree.TreePath;
86 93

  
94
import org.exolab.castor.xml.Marshaller;
87 95
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
88 96

  
89 97
import com.iver.andami.PluginServices;
98
import com.iver.andami.messages.NotificationManager;
90 99
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
91
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
100
import com.iver.utiles.XMLEntity;
92 101

  
93 102
/**
94 103
 *
......
258 267
	protected void propertiesPressed() {
259 268
		StyleEditor se = new StyleEditor((IStyle) selectedElement);
260 269
		PluginServices.getMDIManager().addWindow(se);
270
		setStyle(se.getStyle());
261 271
	}
262 272

  
273
	protected void savePressed() {
274
		if (getSelectedObject() ==null)
275
			return;
276

  
277

  
278
		JFileChooser jfc = new JFileChooser(rootDir);
279
		javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
280
			public boolean accept(File f) {
281
				return f.getAbsolutePath().
282
				toLowerCase().
283
				endsWith(StyleSelectorListModel.STYLE_FILE_EXTENSION);
284
			}
285

  
286
			public String getDescription() {
287
				return PluginServices.getText(
288
						this, "gvSIG_symbol_definition_file")+ " (*.sym)";
289
			}
290
		};
291
		jfc.setFileFilter(ff);
292
		JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
293
		accessory.add(new JLabel(PluginServices.getText(this, "enter_description")));
294
		JTextField txtDesc = new JTextField(25);
295
		accessory.add(txtDesc);
296
		jfc.setAccessory(accessory);
297
		if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
298
			File targetFile = jfc.getSelectedFile();
299

  
300
			String fExtension = StyleSelectorListModel.STYLE_FILE_EXTENSION;
301

  
302
			// apply description
303
			String desc;
304
			if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) {
305
				// default to file name
306
				String s = targetFile.getAbsolutePath();
307
				desc = s.substring(s.lastIndexOf(File.separator)+1).replaceAll(fExtension, "");
308
			} else {
309
				desc = txtDesc.getText().trim();
310
			}
311
			IStyle s = (IStyle) getSelectedObject();
312
			s.setDescription(desc);
313

  
314
			// save it
315
			XMLEntity xml = s.getXMLEntity();
316
			if (!targetFile.
317
					getAbsolutePath().
318
					toLowerCase().
319
					endsWith(fExtension))
320
				targetFile = new File(targetFile.getAbsolutePath() + fExtension);
321
			FileWriter writer;
322
			try {
323
				writer = new FileWriter(targetFile.getAbsolutePath());
324
				Marshaller m = new Marshaller(writer);
325
				m.setEncoding("ISO-8859-1");
326
				m.marshal(xml.getXmlTag());
327

  
328
			} catch (Exception ex) {
329
				NotificationManager.addError(
330
						PluginServices.getText(this, "save_error"), ex);
331
			}
332
			getJListSymbols().setModel(newListModel());
333
		}
334
	}
335

  
263 336
    /**
264 337
     * This method initializes jPanel1
265 338
     *

Also available in: Unified diff