svn-gvsig-desktop / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / gvsig / gui / styling / SymbolEditor.java @ 8458
History | View | Annotate | Download (11.8 KB)
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: SymbolEditor.java 8458 2006-10-31 16:18:03Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.5 2006-10-31 16:16:34 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.4 2006/10/30 19:30:35 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.3 2006/10/29 23:53:49 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.2 2006/10/27 12:41:09 jaume
|
56 |
* GUI
|
57 |
*
|
58 |
* Revision 1.1 2006/10/26 16:31:21 jaume
|
59 |
* GUI
|
60 |
*
|
61 |
*
|
62 |
*/
|
63 |
package com.iver.cit.gvsig.gvsig.gui.styling; |
64 |
|
65 |
import java.awt.BorderLayout; |
66 |
import java.awt.Dimension; |
67 |
import java.awt.FlowLayout; |
68 |
import java.awt.event.ActionEvent; |
69 |
import java.awt.event.ActionListener; |
70 |
import java.util.ArrayList; |
71 |
import java.util.Comparator; |
72 |
import java.util.TreeSet; |
73 |
|
74 |
import javax.swing.BorderFactory; |
75 |
import javax.swing.JComboBox; |
76 |
import javax.swing.JLabel; |
77 |
import javax.swing.JPanel; |
78 |
import javax.swing.JTabbedPane; |
79 |
|
80 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
81 |
|
82 |
import com.iver.andami.PluginServices; |
83 |
import com.iver.andami.ui.mdiManager.IWindow; |
84 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
85 |
import com.iver.cit.gvsig.fmap.core.FShape; |
86 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
87 |
import com.iver.utiles.XMLEntity; |
88 |
|
89 |
/**
|
90 |
*
|
91 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
92 |
*
|
93 |
*/
|
94 |
public class SymbolEditor extends JPanel implements IWindow { |
95 |
|
96 |
private WindowInfo wi;
|
97 |
private JPanel pnlWest = null; |
98 |
private JPanel pnlCenter = null; |
99 |
private JPanel pnlPreview = null; |
100 |
private JPanel pnlLayers = null; |
101 |
private AcceptCancelPanel okCancelPanel;
|
102 |
private ISymbol symbol;
|
103 |
private SymbolPreview symbolPreview = null; |
104 |
private SymbolPreview layerViewer = null; |
105 |
private JPanel pnlTypeAndUnits = null; |
106 |
private JComboBox cmbType; |
107 |
private JComboBox cmbUnits; |
108 |
private JTabbedPane tabbedPane = null; |
109 |
private int shapeType; |
110 |
private XMLEntity oldSymbolProperties;
|
111 |
private ArrayList layers; |
112 |
private ActionListener cmbTypeActionListener; |
113 |
|
114 |
private AbstractTypeSymbolEditorPanel[] tabs; |
115 |
private AbstractTypeSymbolEditorPanel[] pointOptions; |
116 |
|
117 |
|
118 |
public SymbolEditor(ISymbol symbol, int shapeType) { |
119 |
this.symbol = symbol;
|
120 |
this.oldSymbolProperties = symbol.getXMLEntity();
|
121 |
this.shapeType = shapeType;
|
122 |
initialize(); |
123 |
} |
124 |
|
125 |
|
126 |
/**
|
127 |
* This method initializes this
|
128 |
*
|
129 |
*/
|
130 |
private void initialize() { |
131 |
|
132 |
cmbTypeActionListener = new ActionListener() { |
133 |
int prevIndex = -2; |
134 |
public void actionPerformed(ActionEvent e) { |
135 |
int index = getCmbType().getSelectedIndex();
|
136 |
if (prevIndex != index) {
|
137 |
// needs to refresh
|
138 |
prevIndex = index; |
139 |
|
140 |
if (tabbedPane != null) |
141 |
getPnlCenter().remove(tabbedPane); |
142 |
AbstractTypeSymbolEditorPanel options = |
143 |
(AbstractTypeSymbolEditorPanel) getCmbType().getSelectedItem(); |
144 |
options.refreshControls(getSelectedLayerIndex()); |
145 |
JPanel[] tabs = options.getTabs(); |
146 |
tabbedPane = new JTabbedPane(); |
147 |
tabbedPane.setPreferredSize(new Dimension(300, 300)); |
148 |
for (int i = 0; i < tabs.length; i++) { |
149 |
tabbedPane.addTab(tabs[i].getName(), tabs[i]); |
150 |
} |
151 |
getPnlCenter().add(tabbedPane, BorderLayout.CENTER);
|
152 |
getPnlCenter().doLayout(); |
153 |
} |
154 |
} |
155 |
}; |
156 |
|
157 |
Comparator tabComparator = new Comparator() { |
158 |
public int compare(Object o1, Object o2) { |
159 |
if (! (o1 instanceof AbstractTypeSymbolEditorPanel |
160 |
|| o1 instanceof AbstractTypeSymbolEditorPanel))
|
161 |
throw new IllegalArgumentException(PluginServices.getText(this, "trying_to_add_a_non_TypeSymbolEditor_panel")); |
162 |
AbstractTypeSymbolEditorPanel pnl1 = (AbstractTypeSymbolEditorPanel) o1, |
163 |
pnl2 = (AbstractTypeSymbolEditorPanel) o2; |
164 |
int result = pnl1.getName().compareTo(pnl2.getName());
|
165 |
if (result == 0) |
166 |
throw new IllegalArgumentException(PluginServices.getText(this, "two_panels_with_the_same_name")); |
167 |
return result;
|
168 |
} |
169 |
}; |
170 |
TreeSet set = new TreeSet(tabComparator); |
171 |
|
172 |
if (shapeType == FShape.POLYGON)
|
173 |
{ |
174 |
// Polygon options
|
175 |
|
176 |
// add here your options for polygon symbols
|
177 |
set.add(new SimpleFill(SymbolEditor.this));
|
178 |
set.add(new MarkerFill(SymbolEditor.this));
|
179 |
} |
180 |
else if (shapeType == FShape.POINT) |
181 |
{ |
182 |
// Point options
|
183 |
|
184 |
// add here your options for point symbol
|
185 |
set.add(new CharacterMarker(SymbolEditor.this));
|
186 |
} |
187 |
tabs = (AbstractTypeSymbolEditorPanel[]) set.toArray(new AbstractTypeSymbolEditorPanel[0]); |
188 |
|
189 |
this.setLayout(new BorderLayout()); |
190 |
this.add(getPnlWest(), BorderLayout.WEST); |
191 |
this.add(getPnlCenter(), BorderLayout.CENTER); |
192 |
this.add(getOkCancelPanel(), BorderLayout.SOUTH); |
193 |
|
194 |
|
195 |
cmbTypeActionListener.actionPerformed(null);
|
196 |
refresh(); |
197 |
} |
198 |
|
199 |
private AcceptCancelPanel getOkCancelPanel() {
|
200 |
if (okCancelPanel == null) { |
201 |
ActionListener action = new ActionListener() { |
202 |
public void actionPerformed(ActionEvent e) { |
203 |
if ("CANCEL".equals(e.getActionCommand())) { |
204 |
symbol = null;
|
205 |
} |
206 |
PluginServices.getMDIManager().closeWindow(SymbolEditor.this); |
207 |
} |
208 |
}; |
209 |
okCancelPanel = new AcceptCancelPanel(action, action);
|
210 |
} |
211 |
return okCancelPanel;
|
212 |
} |
213 |
|
214 |
|
215 |
public WindowInfo getWindowInfo() {
|
216 |
if (wi == null) { |
217 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
218 |
wi.setWidth(600);
|
219 |
wi.setHeight(400);
|
220 |
wi.setTitle(PluginServices.getText(this, "symbol_property_editor")); |
221 |
} |
222 |
return wi;
|
223 |
} |
224 |
|
225 |
public ISymbol getSymbol() {
|
226 |
return symbol;
|
227 |
} |
228 |
/**
|
229 |
* This method initializes pnlWest
|
230 |
*
|
231 |
* @return javax.swing.JPanel
|
232 |
*/
|
233 |
private JPanel getPnlWest() { |
234 |
if (pnlWest == null) { |
235 |
pnlWest = new JPanel(); |
236 |
pnlWest.setLayout(new BorderLayout()); |
237 |
pnlWest.add(getPnlPreview(), java.awt.BorderLayout.NORTH); |
238 |
pnlWest.add(getPnlLayers(), java.awt.BorderLayout.SOUTH); |
239 |
} |
240 |
return pnlWest;
|
241 |
} |
242 |
/**
|
243 |
* This method initializes pnlCenter
|
244 |
*
|
245 |
* @return javax.swing.JPanel
|
246 |
*/
|
247 |
private JPanel getPnlCenter() { |
248 |
if (pnlCenter == null) { |
249 |
pnlCenter = new JPanel(new BorderLayout()); |
250 |
pnlCenter.setBorder(BorderFactory.
|
251 |
createTitledBorder(null,
|
252 |
PluginServices.getText(this, "properties"))); |
253 |
pnlCenter.add(getPnlTypeAndUnits(), java.awt.BorderLayout.NORTH); |
254 |
|
255 |
// pnlCenter.add(getTabbedPane(), java.awt.BorderLayout.CENTER);
|
256 |
} |
257 |
return pnlCenter;
|
258 |
} |
259 |
/**
|
260 |
* This method initializes pnlPreview
|
261 |
*
|
262 |
* @return javax.swing.JPanel
|
263 |
*/
|
264 |
private JPanel getPnlPreview() { |
265 |
if (pnlPreview == null) { |
266 |
pnlPreview = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
267 |
pnlPreview.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "preview"))); |
268 |
pnlPreview.add(getSymbolPreview()); |
269 |
} |
270 |
return pnlPreview;
|
271 |
} |
272 |
/**
|
273 |
* This method initializes pnlLayers
|
274 |
*
|
275 |
* @return javax.swing.JPanel
|
276 |
*/
|
277 |
private JPanel getPnlLayers() { |
278 |
if (pnlLayers == null) { |
279 |
pnlLayers = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
280 |
pnlLayers.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "layers"))); |
281 |
pnlLayers.add(getLayerViewer(), null);
|
282 |
} |
283 |
return pnlLayers;
|
284 |
} |
285 |
|
286 |
|
287 |
/**
|
288 |
* This method initializes symbolPreview
|
289 |
*
|
290 |
* @return com.iver.cit.gvsig.gvsig.gui.styling.SymbolPreview
|
291 |
*/
|
292 |
private SymbolPreview getSymbolPreview() {
|
293 |
if (symbolPreview == null) { |
294 |
symbolPreview = new SymbolPreview();
|
295 |
symbolPreview.setPreferredSize(new Dimension(100, 100)); |
296 |
|
297 |
} |
298 |
return symbolPreview;
|
299 |
} |
300 |
|
301 |
|
302 |
/**
|
303 |
* This method initializes symbolPreview1
|
304 |
*
|
305 |
* @return com.iver.cit.gvsig.gvsig.gui.styling.SymbolPreview
|
306 |
*/
|
307 |
private SymbolPreview getLayerViewer() {
|
308 |
if (layerViewer == null) { |
309 |
layerViewer = new SymbolPreview();
|
310 |
layerViewer.setPreferredSize(new Dimension(100, 100)); |
311 |
} |
312 |
return layerViewer;
|
313 |
} |
314 |
|
315 |
|
316 |
/**
|
317 |
* This method initializes pnlTypeAndUnits
|
318 |
*
|
319 |
* @return javax.swing.JPanel
|
320 |
*/
|
321 |
private JPanel getPnlTypeAndUnits() { |
322 |
if (pnlTypeAndUnits == null) { |
323 |
pnlTypeAndUnits = new JPanel(); |
324 |
pnlTypeAndUnits.setLayout(new BorderLayout()); |
325 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
326 |
aux.add(new JLabel(PluginServices.getText(this, "type"))); |
327 |
aux.add(getCmbType()); |
328 |
pnlTypeAndUnits.add(aux, BorderLayout.WEST);
|
329 |
|
330 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
331 |
aux.add(new JLabel(PluginServices.getText(this, "units"))); |
332 |
aux.add(getCmbUnits()); |
333 |
pnlTypeAndUnits.add(aux, BorderLayout.EAST);
|
334 |
} |
335 |
return pnlTypeAndUnits;
|
336 |
} |
337 |
|
338 |
private JComboBox getCmbUnits() { |
339 |
if (cmbUnits == null) { |
340 |
cmbUnits = new JComboBox(new String[] {"unidad1", "unidad2"}); |
341 |
} |
342 |
return cmbUnits;
|
343 |
} |
344 |
|
345 |
private JComboBox getCmbType() { |
346 |
if (cmbType == null) { |
347 |
cmbType = new JComboBox(tabs); |
348 |
cmbType.addActionListener(cmbTypeActionListener); |
349 |
} |
350 |
return cmbType;
|
351 |
} |
352 |
|
353 |
/**
|
354 |
* seguramente esto no me va a valer, deber?a traemere el xmlentity i aplicarlo al simbolo actual
|
355 |
* @param symbol
|
356 |
*/
|
357 |
protected void changeSymbolProperties(XMLEntity newXMLEntity) { |
358 |
XMLEntity symXML = symbol.getXMLEntity(); |
359 |
for (int i = 0; i < newXMLEntity.getPropertyCount(); i++) { |
360 |
String pName = newXMLEntity.getPropertyName(i);
|
361 |
symXML.putProperty(pName, newXMLEntity.getStringProperty(pName)); |
362 |
} |
363 |
refresh(); |
364 |
} |
365 |
|
366 |
protected void setLayerToSymbol(int layerIndex, XMLEntity layerXML) { |
367 |
XMLEntity symXML = symbol.getXMLEntity(); |
368 |
ArrayList layers = new ArrayList(); |
369 |
for (int i = 0; i < symXML.getChildrenCount(); i++) { |
370 |
layers.add(symXML.getChild(i)); |
371 |
} |
372 |
layers.add(layerIndex, layerXML); |
373 |
symXML.removeAllChildren(); |
374 |
for (int i = 0; i < layers.size(); i++) { |
375 |
symXML.addChild((XMLEntity) layers.get(i)); |
376 |
} |
377 |
symbol.setXMLEntity(symXML); |
378 |
refresh(); |
379 |
} |
380 |
|
381 |
protected void removeAllLayersFromSymbol() { |
382 |
symbol.getXMLEntity().removeAllChildren(); |
383 |
refresh(); |
384 |
} |
385 |
|
386 |
public void refresh() { |
387 |
getSymbolPreview().setSymbol(symbol); |
388 |
} |
389 |
|
390 |
|
391 |
public int getSelectedLayerIndex() { |
392 |
// TODO de moment zero, per? en un futur s'espera que hi haja m?s d'una capa
|
393 |
return 0; |
394 |
} |
395 |
|
396 |
} // @jve:decl-index=0:visual-constraint="10,10"
|