Revision 10995

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/SelectorListModel.java
1
/* 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
*
44
* $Id$
45
* $Log$
46
* Revision 1.2  2007-03-28 16:44:08  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.1  2007/03/09 11:25:00  jaume
50
* Advanced symbology (start committing)
51
*
52
* Revision 1.4.2.4  2007/02/21 07:35:14  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.4.2.3  2007/02/09 11:00:03  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.4.2.2  2007/02/08 15:43:05  jaume
59
* some bug fixes in the editor and removed unnecessary imports
60
*
61
* Revision 1.4.2.1  2007/01/26 13:49:03  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.4  2007/01/16 11:52:11  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.7  2007/01/10 17:05:05  jaume
68
* moved to FMap and gvSIG
69
*
70
* Revision 1.6  2006/11/06 16:06:52  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.5  2006/11/06 07:33:54  jaume
74
* javadoc, source style
75
*
76
* Revision 1.4  2006/11/02 17:19:28  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.3  2006/10/30 19:30:35  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.2  2006/10/26 16:31:21  jaume
83
* GUI
84
*
85
* Revision 1.1  2006/10/25 10:50:41  jaume
86
* movement of classes and gui stuff
87
*
88
* Revision 1.2  2006/10/24 22:26:18  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.1  2006/10/24 16:31:12  jaume
92
* *** empty log message ***
93
*
94
*
95
*/
96
package com.iver.cit.gvsig.gui.styling;
97

  
98
import java.io.File;
99
import java.io.FileFilter;
100
import java.io.FileNotFoundException;
101
import java.io.FileReader;
102
import java.util.ArrayList;
103
import java.util.Comparator;
104
import java.util.TreeSet;
105
import java.util.Vector;
106

  
107
import javax.swing.event.ListDataListener;
108

  
109
import org.exolab.castor.xml.MarshalException;
110
import org.exolab.castor.xml.ValidationException;
111

  
112
import com.iver.andami.messages.NotificationManager;
113
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
114
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
115
import com.iver.utiles.XMLEntity;
116
import com.iver.utiles.listManager.ListModel;
117
import com.iver.utiles.xmlEntity.generate.XmlTag;
118

  
119
public class SelectorListModel implements ListModel {
120

  
121
	private String fileExtension;
122
	public static final String SYMBOL_FILE_EXTENSION = ".sym";
123
	public static final String STYLE_FILE_EXTENSION = ".style";
124

  
125
	private FileFilter ffilter = new FileFilter() {
126
		public boolean accept(File pathname) {
127
			return pathname.getAbsolutePath().toLowerCase().endsWith(SelectorListModel.this.fileExtension);
128
		}
129
	};
130
	private SelectorFilter sfilter;
131
	private Vector elements;
132
	private ArrayList listeners;
133
	private Object currentElement;
134
	private File dir;
135

  
136
	public SelectorListModel(File dir, Object currentElemet, SelectorFilter filter, String fileExtension) {
137
		this.fileExtension = fileExtension;
138
		this.dir = dir;
139
		this.currentElement = currentElemet;
140
		this.sfilter = filter;
141
	}
142

  
143
	public Object remove(int i) throws ArrayIndexOutOfBoundsException {
144
		return elements.remove(i);
145
	}
146

  
147
	public void insertAt(int i, Object o) {
148
		getObjects().insertElementAt(o, i);
149
	}
150

  
151
	public void add(Object o) {
152
		TreeSet map = new TreeSet(new Comparator() {
153

  
154
			public int compare(Object o1, Object o2) {
155
				// first will always be the current symbol
156
				if (o1.equals(currentElement)) return -1;
157
				if (o2.equals(currentElement)) return 1;
158

  
159
				ISymbol sym1 = (ISymbol) o1;
160
				ISymbol sym2 = (ISymbol) o2;
161
				if (sym1.getDescription() == null && sym2.getDescription() != null) return -1;
162
				if (sym1.getDescription() != null && sym2.getDescription() == null) return 1;
163
				if (sym1.getDescription() == null && sym2.getDescription() == null) return 1;
164

  
165
				int result = sym1.getDescription().compareTo(sym2.getDescription());
166
				return (result!=0) ? result: 1; /* this will allow adding symbols with
167
												   the same value for description than
168
												   a previous one. */
169
			}
170

  
171
		});
172

  
173
		map.addAll(elements);
174
		map.add(o);
175
		elements = new Vector(map);
176

  
177
	}
178

  
179
	public Vector getObjects() {
180
		if (elements == null) {
181
			elements = new Vector();
182

  
183
			if (currentElement!= null)
184
				elements.add(currentElement);
185

  
186
			File[] ff = dir.listFiles(ffilter);
187
			for (int i = 0; i < ff.length; i++) {
188

  
189
				XMLEntity xml;
190
				try {
191
					xml = new XMLEntity((XmlTag) XmlTag.unmarshal(new FileReader(ff[i])));
192
					ISymbol sym = SymbologyFactory.createSymbolFromXML(xml, ff[i].getName());
193
					if (sfilter.accepts(sym))
194
						add(sym);
195
				} catch (MarshalException e) {
196
					NotificationManager.
197
						addWarning("Error in file ["+ff[i].getAbsolutePath()+"]. " +
198
								"File corrupted! Skiping it...", e);
199
				} catch (ValidationException e) {
200
					NotificationManager.
201
						addWarning("Error validating symbol file ["+ff[i].getAbsolutePath()+"].", e);
202
				} catch (FileNotFoundException e) {
203
					// unreachable code, but anyway...
204
					NotificationManager.
205
						addWarning("File not found: "+ ff[i].getAbsolutePath(), e);
206
				}
207

  
208
			}
209
		}
210
		return elements;
211
	}
212

  
213
	public int getSize() {
214
		return getObjects().size();
215
	}
216

  
217
	public Object getElementAt(int index) {
218
		return getObjects().get(index);
219
	}
220

  
221
	public void addListDataListener(ListDataListener l) {
222
		if (listeners == null)
223
			listeners = new ArrayList();
224
		listeners.add(l);
225
	}
226

  
227
	public void removeListDataListener(ListDataListener l) {
228
		if (listeners!=null)
229
			listeners.remove(l);
230
	}
231

  
232
}
233

  
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/SymbolSelectorListModel.java
1
/* 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
*
44
* $Id$
45
* $Log$
46
* Revision 1.6  2007-04-02 00:08:05  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.2  2007/03/28 16:44:08  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1  2007/03/09 11:25:00  jaume
53
* Advanced symbology (start committing)
54
*
55
* Revision 1.4.2.4  2007/02/21 07:35:14  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.4.2.3  2007/02/09 11:00:03  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.4.2.2  2007/02/08 15:43:05  jaume
62
* some bug fixes in the editor and removed unnecessary imports
63
*
64
* Revision 1.4.2.1  2007/01/26 13:49:03  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.4  2007/01/16 11:52:11  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.7  2007/01/10 17:05:05  jaume
71
* moved to FMap and gvSIG
72
*
73
* Revision 1.6  2006/11/06 16:06:52  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.5  2006/11/06 07:33:54  jaume
77
* javadoc, source style
78
*
79
* Revision 1.4  2006/11/02 17:19:28  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.3  2006/10/30 19:30:35  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.2  2006/10/26 16:31:21  jaume
86
* GUI
87
*
88
* Revision 1.1  2006/10/25 10:50:41  jaume
89
* movement of classes and gui stuff
90
*
91
* Revision 1.2  2006/10/24 22:26:18  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.1  2006/10/24 16:31:12  jaume
95
* *** empty log message ***
96
*
97
*
98
*/
99
package com.iver.cit.gvsig.gui.styling;
100

  
101
import java.io.File;
102
import java.io.FileFilter;
103
import java.io.FileNotFoundException;
104
import java.io.FileReader;
105
import java.util.ArrayList;
106
import java.util.Comparator;
107
import java.util.TreeSet;
108
import java.util.Vector;
109

  
110
import javax.swing.event.ListDataListener;
111

  
112
import org.exolab.castor.xml.MarshalException;
113
import org.exolab.castor.xml.ValidationException;
114

  
115
import com.iver.andami.messages.NotificationManager;
116
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
117
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
118
import com.iver.utiles.XMLEntity;
119
import com.iver.utiles.listManager.ListModel;
120
import com.iver.utiles.xmlEntity.generate.XmlTag;
121

  
122
public class SymbolSelectorListModel implements ListModel {
123

  
124
	private String fileExtension;
125
	public static final String SYMBOL_FILE_EXTENSION = ".sym";
126
	protected FileFilter ffilter = new FileFilter() {
127
		public boolean accept(File pathname) {
128
			return pathname.getAbsolutePath().toLowerCase().endsWith(SymbolSelectorListModel.this.fileExtension);
129
		}
130
	};
131
	protected SelectorFilter sfilter;
132
	protected Vector elements;
133
	private ArrayList listeners;
134
	protected Object currentElement;
135
	protected File dir;
136

  
137
	public SymbolSelectorListModel(File dir, Object currentElemet, SelectorFilter filter, String fileExtension) {
138
		this.fileExtension = fileExtension;
139
		this.dir = dir;
140
		this.currentElement = currentElemet;
141
		this.sfilter = filter;
142
	}
143

  
144
	public Object remove(int i) throws ArrayIndexOutOfBoundsException {
145
		return elements.remove(i);
146
	}
147

  
148
	public void insertAt(int i, Object o) {
149
		getObjects().insertElementAt(o, i);
150
	}
151

  
152
	public void add(Object o) {
153
		TreeSet map = new TreeSet(new Comparator() {
154

  
155
			public int compare(Object o1, Object o2) {
156
				// first will always be the current symbol
157
				if (o1.equals(currentElement)) return -1;
158
				if (o2.equals(currentElement)) return 1;
159

  
160
				ISymbol sym1 = (ISymbol) o1;
161
				ISymbol sym2 = (ISymbol) o2;
162
				if (sym1.getDescription() == null && sym2.getDescription() != null) return -1;
163
				if (sym1.getDescription() != null && sym2.getDescription() == null) return 1;
164
				if (sym1.getDescription() == null && sym2.getDescription() == null) return 1;
165

  
166
				int result = sym1.getDescription().compareTo(sym2.getDescription());
167
				return (result!=0) ? result: 1; /* this will allow adding symbols with
168
												   the same value for description than
169
												   a previous one. */
170
			}
171

  
172
		});
173

  
174
		map.addAll(elements);
175
		map.add(o);
176
		elements = new Vector(map);
177

  
178
	}
179

  
180
	public Vector getObjects() {
181
		if (elements == null) {
182
			elements = new Vector();
183

  
184
			if (currentElement!= null)
185
				elements.add(currentElement);
186

  
187
			File[] ff = dir.listFiles(ffilter);
188
			for (int i = 0; i < ff.length; i++) {
189

  
190
				XMLEntity xml;
191
				try {
192
					xml = new XMLEntity((XmlTag) XmlTag.unmarshal(new FileReader(ff[i])));
193
					ISymbol sym = SymbologyFactory.createSymbolFromXML(xml, ff[i].getName());
194
					if (sfilter.accepts(sym))
195
						add(sym);
196
				} catch (MarshalException e) {
197
					NotificationManager.
198
						addWarning("Error in file ["+ff[i].getAbsolutePath()+"]. " +
199
								"File corrupted! Skiping it...", e);
200
				} catch (ValidationException e) {
201
					NotificationManager.
202
						addWarning("Error validating symbol file ["+ff[i].getAbsolutePath()+"].", e);
203
				} catch (FileNotFoundException e) {
204
					// unreachable code, but anyway...
205
					NotificationManager.
206
						addWarning("File not found: "+ ff[i].getAbsolutePath(), e);
207
				}
208

  
209
			}
210
		}
211
		return elements;
212
	}
213

  
214
	public int getSize() {
215
		return getObjects().size();
216
	}
217

  
218
	public Object getElementAt(int index) {
219
		return getObjects().get(index);
220
	}
221

  
222
	public void addListDataListener(ListDataListener l) {
223
		if (listeners == null)
224
			listeners = new ArrayList();
225
		listeners.add(l);
226
	}
227

  
228
	public void removeListDataListener(ListDataListener l) {
229
		if (listeners!=null)
230
			listeners.remove(l);
231
	}
232

  
233
}
234

  
0 235

  
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/StyleSelector.java
4 4
import java.awt.Component;
5 5
import java.awt.Dimension;
6 6
import java.io.File;
7
import java.io.FileFilter;
7 8
import java.util.prefs.Preferences;
8 9

  
9 10
import javax.swing.BoxLayout;
......
13 14
import javax.swing.ListCellRenderer;
14 15
import javax.swing.event.ListSelectionEvent;
15 16
import javax.swing.event.ListSelectionListener;
17
import javax.swing.event.TreeModelListener;
18
import javax.swing.tree.TreeModel;
19
import javax.swing.tree.TreePath;
16 20

  
17 21
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
18 22

  
......
44 48
			rootDir.mkdir();
45 49
		lblTitle.setText(PluginServices.getText(this, "label_styles"));
46 50
		treeRootName = PluginServices.getText(this, "style_library");
51
		treeModel = new TreeModel() {
52
    		final class MyFile extends File {
53
    			public MyFile(String pathname) {
54
    				super(pathname);
55
    			}
47 56

  
57
    			public String toString() {
58
    				if (this.equals(root))
59
    					return treeRootName;
60
    				String path = getAbsolutePath();
61
    				String prefixToRemove = rootDir.getAbsolutePath();
62
    				path = path.substring(prefixToRemove.length()+1, path.length());
63
    				return path;
64
    			}
65
    		};
66
    		MyFile root = new MyFile(rootDir.getAbsolutePath());
67

  
68
    		private FileFilter ff = new FileFilter() {
69
    			public boolean accept(File pathname) {
70
    				return pathname.isDirectory();
71
    			}
72
    		};
73

  
74
    		public Object getRoot() {
75
    			return root;
76
    		}
77

  
78
    		public int getChildCount(Object parent) {
79
    			return ((File) parent).listFiles(ff).length;
80
    		}
81

  
82
    		public boolean isLeaf(Object node) {
83
    			return getChildCount(node)==0;
84
    		}
85

  
86
    		public void addTreeModelListener(TreeModelListener l) {
87
    			// TODO Necessite?
88

  
89
    		}
90

  
91
    		public void removeTreeModelListener(TreeModelListener l) {
92
    			// TODO Necessite?
93
    		}
94

  
95
    		public Object getChild(Object parent, int index) {
96
    			return new MyFile(((File) parent).listFiles(ff)[index].getAbsolutePath());
97
    		}
98

  
99
    		public int getIndexOfChild(Object parent, Object child) {
100
    			if (parent == null)
101
    				return -1;
102
    			File[] files = ((File) parent).listFiles(ff);
103
    			for (int i = 0; i < files.length; i++) {
104
    				if (files[i].equals((File) child))
105
    					return i;
106
    			}
107
    			return -1;
108
    		}
109

  
110
    		public void valueForPathChanged(TreePath path, Object newValue) {
111
    			// TODO Auto-generated method stub
112
    		}
113

  
114
    	};
115
		getTreeFav().setModel(treeModel);
48 116
	}
49 117

  
50
	protected SelectorListModel newListModel() {
51
		SelectorListModel listModel = new SelectorListModel(
118
	protected SymbolSelectorListModel newListModel() {
119
		StyleSelectorListModel listModel = new StyleSelectorListModel(
52 120
				dir,
53 121
				selectedElement,
54 122
				sFilter,
55
				SelectorListModel.STYLE_FILE_EXTENSION);
123
				StyleSelectorListModel.STYLE_FILE_EXTENSION);
56 124
		return listModel;
57 125

  
58 126
	}
......
86 154
            ListCellRenderer renderer = new ListCellRenderer() {
87 155
        		private Color mySelectedBGColor = new Color(255,145,100,255);
88 156
    			public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
89
    				IStyle sym = (IStyle) value;
157
    				IStyle sty = (IStyle) value;
90 158
    				JPanel pnl = new JPanel();
91 159
    				BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
92 160
    				pnl.setLayout(layout);
......
97 165
    				StylePreviewer sp = new StylePreviewer();
98 166
    				sp.setAlignmentX(Component.CENTER_ALIGNMENT);
99 167
    				sp.setPreferredSize(new Dimension(50, 50));
100
    				sp.setStyle(sym);
168
    				sp.setStyle(sty);
101 169
    				sp.setBackground(bgColor);
102 170
    				pnl.add(sp);
103
    				JLabel lbl = new JLabel(sym.getDescription());
171
    				JLabel lbl = new JLabel(sty.getDescription());
104 172
    				lbl.setBackground(bgColor);
105 173
    				lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
106 174
    				pnl.add(lbl);
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/SymbolSelector.java
143 143
    protected GridBagLayoutPanel jPanelOptions = null;
144 144
    protected JList jListSymbols = null;
145 145
    protected String treeRootName;
146
    protected TreeModel treeModel;
146 147
    private JDecimalField txtWidth;
147 148

  
148 149
	protected SelectorFilter sFilter = new SelectorFilter() {
......
203 204
     *
204 205
     */
205 206
    private void initialize() {
207
    	treeModel = new TreeModel() {
208
    		final class MyFile extends File {
209
    			public MyFile(String pathname) {
210
    				super(pathname);
211
    			}
206 212

  
207
        this.setLayout(new BorderLayout());
208
        this.setSize(400, 221);
213
    			public String toString() {
214
    				if (this.equals(root))
215
    					return treeRootName;
216
    				String path = getAbsolutePath();
217
    				String prefixToRemove = rootDir.getAbsolutePath();
218
    				path = path.substring(prefixToRemove.length()+1, path.length());
219
    				return path;
220
    			}
221
    		};
222
    		MyFile root = new MyFile(rootDir.getAbsolutePath());
209 223

  
210
        this.add(getJNorthPanel(), BorderLayout.NORTH);
211
        this.add(getJSplitPane(), BorderLayout.CENTER);
212
        this.add(getJEastPanel(), BorderLayout.EAST);
213
        ActionListener okAction = new ActionListener() {
224
    		private FileFilter ff = new FileFilter() {
225
    			public boolean accept(File pathname) {
226
    				return pathname.isDirectory();
227
    			}
228
    		};
229

  
230
    		public Object getRoot() {
231
    			return root;
232
    		}
233

  
234
    		public int getChildCount(Object parent) {
235
    			return ((File) parent).listFiles(ff).length;
236
    		}
237

  
238
    		public boolean isLeaf(Object node) {
239
    			return getChildCount(node)==0;
240
    		}
241

  
242
    		public void addTreeModelListener(TreeModelListener l) {
243
    			// TODO Necessite?
244

  
245
    		}
246

  
247
    		public void removeTreeModelListener(TreeModelListener l) {
248
    			// TODO Necessite?
249
    		}
250

  
251
    		public Object getChild(Object parent, int index) {
252
    			return new MyFile(((File) parent).listFiles(ff)[index].getAbsolutePath());
253
    		}
254

  
255
    		public int getIndexOfChild(Object parent, Object child) {
256
    			if (parent == null)
257
    				return -1;
258
    			File[] files = ((File) parent).listFiles(ff);
259
    			for (int i = 0; i < files.length; i++) {
260
    				if (files[i].equals((File) child))
261
    					return i;
262
    			}
263
    			return -1;
264
    		}
265

  
266
    		public void valueForPathChanged(TreePath path, Object newValue) {
267
    			// TODO Auto-generated method stub
268
    		}
269

  
270
    	};
271

  
272
    	this.setLayout(new BorderLayout());
273
    	this.setSize(400, 221);
274

  
275
    	this.add(getJNorthPanel(), BorderLayout.NORTH);
276
    	this.add(getJSplitPane(), BorderLayout.CENTER);
277
    	this.add(getJEastPanel(), BorderLayout.EAST);
278
    	ActionListener okAction = new ActionListener() {
214 279
    		public void actionPerformed(ActionEvent e) {
215 280
    			PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
216 281
    		}
......
221 286
    		}
222 287
    	};
223 288

  
224
        okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
289
    	okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
225 290

  
226 291

  
227
        this.add(okCancelPanel, BorderLayout.SOUTH);
292
    	this.add(okCancelPanel, BorderLayout.SOUTH);
228 293
    }
229 294

  
230
    protected SelectorListModel newListModel() {
231
    	SelectorListModel listModel = new SelectorListModel(
295
    protected SymbolSelectorListModel newListModel() {
296
    	SymbolSelectorListModel listModel = new SymbolSelectorListModel(
232 297
    			dir,
233 298
    			(ISymbol) selectedElement,
234 299
    			sFilter,
235
    			SelectorListModel.SYMBOL_FILE_EXTENSION);
300
    			SymbolSelectorListModel.SYMBOL_FILE_EXTENSION);
236 301
    	return listModel;
237 302
    }
238 303

  
......
263 328
		return northPanel;
264 329
	}
265 330

  
266
	/**
267
     * This method initializes jList
268
     *
269
     * @return javax.swing.JList
270
     */
271
    private JTree getJListFav() {
331

  
332
    protected JTree getTreeFav() {
272 333
    	if (treeFamilies == null) {
273 334
    		treeFamilies = new JTree();
274 335
    		treeFamilies.setPreferredSize(new java.awt.Dimension(70,100));
275 336
    		try {
276
    			treeFamilies.setModel(new TreeModel() {
277
    				final class MyFile extends File {
278
    					public MyFile(String pathname) {
279
    						super(pathname);
280
    					}
281

  
282
    					public String toString() {
283
    						if (this.equals(root))
284
    							return treeRootName;
285
    						String path = getAbsolutePath();
286
    						String prefixToRemove = rootDir.getAbsolutePath();
287
    						path = path.substring(prefixToRemove.length()+1, path.length());
288
    						return path;
289
    					}
290
    				};
291
    				MyFile root = new MyFile(rootDir.getAbsolutePath());
292

  
293
    				private FileFilter ff = new FileFilter() {
294
    					public boolean accept(File pathname) {
295
    						return pathname.isDirectory();
296
    					}
297
    				};
298

  
299
    				public Object getRoot() {
300
    					return root;
301
    				}
302

  
303
    				public int getChildCount(Object parent) {
304
    					return ((File) parent).listFiles(ff).length;
305
    				}
306

  
307
    				public boolean isLeaf(Object node) {
308
    					return getChildCount(node)==0;
309
    				}
310

  
311
    				public void addTreeModelListener(TreeModelListener l) {
312
    					// TODO Necessite?
313

  
314
    				}
315

  
316
    				public void removeTreeModelListener(TreeModelListener l) {
317
    					// TODO Necessite?
318
    				}
319

  
320
    				public Object getChild(Object parent, int index) {
321
    					return new MyFile(((File) parent).listFiles(ff)[index].getAbsolutePath());
322
    				}
323

  
324
    				public int getIndexOfChild(Object parent, Object child) {
325
    					if (parent == null)
326
    						return -1;
327
    					File[] files = ((File) parent).listFiles(ff);
328
    					for (int i = 0; i < files.length; i++) {
329
    						if (files[i].equals((File) child))
330
    							return i;
331
    					}
332
    					return -1;
333
    				}
334

  
335
    				public void valueForPathChanged(TreePath path, Object newValue) {
336
    					// TODO Auto-generated method stub
337
    				}
338

  
339
    			});
337
    			treeFamilies.setModel(treeModel);
340 338
    			treeFamilies.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
341 339
					public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
342 340
						dir = (File)
......
519 517
    		jScrollPane = new JScrollPane();
520 518
    		jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
521 519
    		jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
522
    		jScrollPane.setViewportView(getJListFav());
520
    		jScrollPane.setViewportView(getTreeFav());
523 521
    	}
524 522
    	return jScrollPane;
525 523
    }
......
724 722
			public boolean accept(File f) {
725 723
				return f.getAbsolutePath().
726 724
				toLowerCase().
727
				endsWith(SelectorListModel.SYMBOL_FILE_EXTENSION);
725
				endsWith(SymbolSelectorListModel.SYMBOL_FILE_EXTENSION);
728 726
			}
729 727

  
730 728
			public String getDescription() {
......
741 739
		if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
742 740
			File targetFile = jfc.getSelectedFile();
743 741

  
744
			String fExtension = SelectorListModel.SYMBOL_FILE_EXTENSION;
742
			String fExtension = SymbolSelectorListModel.SYMBOL_FILE_EXTENSION;
745 743

  
746 744
			// apply description
747 745
			String desc;
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/StyleSelectorListModel.java
1
package com.iver.cit.gvsig.gui.styling;
2

  
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.io.FileReader;
6
import java.util.Comparator;
7
import java.util.TreeSet;
8
import java.util.Vector;
9

  
10
import org.exolab.castor.xml.MarshalException;
11
import org.exolab.castor.xml.ValidationException;
12

  
13
import com.iver.andami.messages.NotificationManager;
14
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
15
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
16
import com.iver.utiles.XMLEntity;
17
import com.iver.utiles.xmlEntity.generate.XmlTag;
18

  
19
public class StyleSelectorListModel extends SymbolSelectorListModel {
20

  
21
	public static final String STYLE_FILE_EXTENSION = ".style";
22

  
23
	public StyleSelectorListModel(File dir, Object currentElemet, SelectorFilter filter, String fileExtension) {
24
		super(dir, currentElemet, filter, fileExtension);
25
		// TODO Auto-generated constructor stub
26
	}
27

  
28
	public Vector getObjects() {
29
		if (elements == null) {
30
			elements = new Vector();
31

  
32
			if (currentElement!= null)
33
				elements.add(currentElement);
34

  
35
			File[] ff = dir.listFiles(ffilter);
36
			for (int i = 0; i < ff.length; i++) {
37

  
38
				XMLEntity xml;
39
				try {
40
					xml = new XMLEntity((XmlTag) XmlTag.unmarshal(new FileReader(ff[i])));
41
					IStyle sty = SymbologyFactory.createStyleFromXML(xml, ff[i].getName());
42
					if (sfilter.accepts(sty))
43
						add(sty);
44
				} catch (MarshalException e) {
45
					NotificationManager.
46
						addWarning("Error in file ["+ff[i].getAbsolutePath()+"]. " +
47
								"File corrupted! Skiping it...", e);
48
				} catch (ValidationException e) {
49
					NotificationManager.
50
						addWarning("Error validating style file ["+ff[i].getAbsolutePath()+"].", e);
51
				} catch (FileNotFoundException e) {
52
					// unreachable code, but anyway...
53
					NotificationManager.
54
						addWarning("File not found: "+ ff[i].getAbsolutePath(), e);
55
				}
56

  
57
			}
58
		}
59
		return elements;
60
	}
61
	
62

  
63
	public void add(Object o) {
64
		TreeSet map = new TreeSet(new Comparator() {
65

  
66
			public int compare(Object o1, Object o2) {
67
				// first will always be the current symbol
68
				if (o1.equals(currentElement)) return -1;
69
				if (o2.equals(currentElement)) return 1;
70

  
71
				IStyle sym1 = (IStyle) o1;
72
				IStyle sym2 = (IStyle) o2;
73
				if (sym1.getDescription() == null && sym2.getDescription() != null) return -1;
74
				if (sym1.getDescription() != null && sym2.getDescription() == null) return 1;
75
				if (sym1.getDescription() == null && sym2.getDescription() == null) return 1;
76

  
77
				int result = sym1.getDescription().compareTo(sym2.getDescription());
78
				return (result!=0) ? result: 1; /* this will allow adding symbols with
79
												   the same value for description than
80
												   a previous one. */
81
			}
82

  
83
		});
84

  
85
		map.addAll(elements);
86
		map.add(o);
87
		elements = new Vector(map);
88

  
89
	}
90
}
0 91

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/SVGStyle.java
1
package com.iver.cit.gvsig.fmap.core.styles;
2
import java.awt.Graphics2D;
3
import java.awt.Rectangle;
4
import java.awt.RenderingHints;
5
import java.io.File;
6
import java.io.IOException;
7

  
8
import org.apache.batik.bridge.BridgeContext;
9
import org.apache.batik.bridge.DocumentLoader;
10
import org.apache.batik.bridge.GVTBuilder;
11
import org.apache.batik.bridge.UserAgentAdapter;
12
import org.apache.batik.bridge.ViewBox;
13
import org.apache.batik.gvt.GraphicsNode;
14
import org.apache.batik.gvt.renderer.StaticRenderer;
15
import org.w3c.dom.Document;
16
import org.w3c.dom.Element;
17
import org.w3c.dom.svg.SVGDocument;
18

  
19
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
20
import com.iver.utiles.XMLEntity;
21

  
22
public class SVGStyle extends AbstractStyle {
23

  
24
	private GVTBuilder gvtBuilder = new GVTBuilder();
25
    private UserAgentAdapter userAgent;
26
	private DocumentLoader loader;
27
	private StaticRenderer renderer = new StaticRenderer();
28
	private GraphicsNode gvtRoot;
29
	private BridgeContext ctx;
30
	private Element elt;
31
	private String sourceFile;
32
	protected static RenderingHints defaultRenderingHints;
33
    static {
34
        defaultRenderingHints = new RenderingHints(null);
35
        defaultRenderingHints.put(RenderingHints.KEY_ANTIALIASING,
36
                                  RenderingHints.VALUE_ANTIALIAS_ON);
37

  
38
        defaultRenderingHints.put(RenderingHints.KEY_INTERPOLATION,
39
                                  RenderingHints.VALUE_INTERPOLATION_BILINEAR);
40
    }
41

  
42
	public SVGStyle(){
43
		userAgent = new UserAgentAdapter();
44
		loader    = new DocumentLoader(userAgent);
45
		ctx       = new BridgeContext(userAgent, loader);
46
		renderer.setDoubleBuffered(true);
47
	}
48
	
49
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
50
		Graphics2D g2 = (Graphics2D) g;
51
		RenderingHints renderingHints = new RenderingHints(defaultRenderingHints);
52
		g2.setRenderingHints(renderingHints);
53
		gvtRoot.setTransform((ViewBox.getViewTransform(null, elt, (float) r.getWidth()-1, (float) r.getHeight()-1)));
54
		gvtRoot.paint(g2);
55
	}
56

  
57
	public boolean isSuitableFor(ISymbol symbol) {
58
		return true;
59
	}
60

  
61
	public String getClassName() {
62
		return getClass().getName();
63
	}
64

  
65
	public XMLEntity getXMLEntity() {
66
		XMLEntity xml = new XMLEntity();
67
		xml.putProperty("className", getClassName());
68
		xml.putProperty("source", sourceFile);
69
		xml.putProperty("desc", getDescription());
70
		return xml;
71
	}
72

  
73
	public void setXMLEntity(XMLEntity xml) {
74
		try {
75
			setSource(new File(xml.getStringProperty("source")));
76
			setDescription(xml.getStringProperty("desc"));
77
		} catch (IOException e) {
78
			// TODO Auto-generated catch block
79
			e.printStackTrace();
80
		}
81
	}
82

  
83
	public void setSource(File f) throws IOException {
84
		sourceFile = f.getAbsolutePath();
85
		Document svgDoc = loader.loadDocument(f.toURI().toString());
86
        gvtRoot = gvtBuilder.build(ctx, svgDoc);
87
        renderer.setTree(gvtRoot);
88
        elt = ((SVGDocument)svgDoc).getRootElement();
89
	}
90
}
0 91

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/styles/SimpleLabelStyle.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.3  2007-03-29 16:02:01  jaume
46
* Revision 1.4  2007-04-02 00:10:04  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.3  2007/03/29 16:02:01  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.2  2007/03/09 11:20:56  jaume
50 53
* Advanced symbology (start committing)
51 54
*
......
73 76
/**
74 77
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
75 78
 */
76
public class SimpleLabelStyle extends AbstractStyle implements ILabelStyle{
77
	private PictureMarkerSymbol backGround;
79
public class SimpleLabelStyle extends SVGStyle implements ILabelStyle{
78 80
	private String text;
79 81

  
80 82
	public int getFieldCount() {
......
98 100
	public Point2D[] getTextPositions(AffineTransform at) {
99 101
		// TODO Implement it
100 102
		throw new Error("Not yet implemented!");
101

  
102 103
	}
103 104

  
104

  
105 105
	public boolean isSuitableFor(ISymbol symbol) {
106 106
		return true;
107
	}
107
	}	
108 108

  
109
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
110
		// TODO Implement it
111
		throw new Error("Not yet implemented!");
112

  
113
	}
114

  
115 109
	public String getClassName() {
116
		// TODO Implement it
117
		throw new Error("Not yet implemented!");
118

  
110
		return getClass().getName();
119 111
	}
120 112

  
121 113
	public XMLEntity getXMLEntity() {
122
		// TODO Implement it
123
		throw new Error("Not yet implemented!");
124

  
114
		XMLEntity xml = super.getXMLEntity();
115
		xml.putProperty("className", getClassName());
116
		xml.putProperty("desc", getDescription());
117
		xml.putProperty("text", text);
118
		return xml;
125 119
	}
126 120

  
127 121
	public void setXMLEntity(XMLEntity xml) {
128
		// TODO Implement it
129
		throw new Error("Not yet implemented!");
130

  
122
		super.setXMLEntity(xml);
123
		setDescription(xml.getStringProperty("desc"));
124
		text = xml.getStringProperty("text");
131 125
	}
132 126

  
133 127
	public void drawBackground(Graphics2D g, Shape shp) {
134
		// no background
128
//		drawInsideRectangle(g, )
135 129
	}
136 130
}

Also available in: Unified diff