svn-gvsig-desktop / tags / v2_0_0_Build_2056 / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SymbolLayerManager.java @ 39043
History | View | Annotate | Download (14.4 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: SymbolLayerManager.java 31067 2009-10-01 16:11:25Z cordinyana $
|
45 |
* $Log$
|
46 |
* Revision 1.8 2007-09-17 09:21:45 jaume
|
47 |
* refactored SymboSelector (added support for multishapedsymbol)
|
48 |
*
|
49 |
* Revision 1.7 2007/08/09 10:39:04 jaume
|
50 |
* first round of found bugs fixed
|
51 |
*
|
52 |
* Revision 1.6 2007/06/29 13:07:33 jaume
|
53 |
* +PictureLineSymbol
|
54 |
*
|
55 |
* Revision 1.5 2007/05/31 09:36:22 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.4 2007/04/20 07:54:38 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.3 2007/03/09 11:25:00 jaume
|
62 |
* Advanced symbology (start committing)
|
63 |
*
|
64 |
* Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1.2.3 2007/02/08 15:45:37 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.1.2.2 2007/02/08 15:43:04 jaume
|
71 |
* some bug fixes in the editor and removed unnecessary imports
|
72 |
*
|
73 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.1 2007/01/16 11:52:11 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.7 2007/01/10 17:05:05 jaume
|
80 |
* moved to FMap and gvSIG
|
81 |
*
|
82 |
* Revision 1.6 2006/11/08 10:56:47 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.5 2006/11/07 08:52:30 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.4 2006/11/06 17:08:45 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.3 2006/11/06 16:06:52 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.2 2006/11/06 07:33:54 jaume
|
95 |
* javadoc, source style
|
96 |
*
|
97 |
* Revision 1.1 2006/11/02 17:19:28 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
*
|
101 |
*/
|
102 |
package org.gvsig.app.gui.styling; |
103 |
|
104 |
import java.awt.BorderLayout; |
105 |
import java.awt.Color; |
106 |
import java.awt.Component; |
107 |
import java.awt.Dimension; |
108 |
import java.awt.FlowLayout; |
109 |
import java.awt.LayoutManager; |
110 |
import java.awt.event.ActionEvent; |
111 |
import java.awt.event.ActionListener; |
112 |
import java.awt.event.MouseAdapter; |
113 |
import java.awt.event.MouseEvent; |
114 |
import java.util.ArrayList; |
115 |
|
116 |
import javax.swing.AbstractListModel; |
117 |
import javax.swing.BorderFactory; |
118 |
import javax.swing.DefaultListCellRenderer; |
119 |
import javax.swing.ImageIcon; |
120 |
import javax.swing.JCheckBox; |
121 |
import javax.swing.JList; |
122 |
import javax.swing.JPanel; |
123 |
import javax.swing.JScrollPane; |
124 |
import javax.swing.event.ListDataListener; |
125 |
import javax.swing.event.ListSelectionEvent; |
126 |
import javax.swing.event.ListSelectionListener; |
127 |
|
128 |
import org.gvsig.andami.IconThemeHelper; |
129 |
import org.gvsig.andami.PluginServices; |
130 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
131 |
import org.gvsig.fmap.geom.Geometry; |
132 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
133 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
134 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
135 |
import org.gvsig.gui.beans.swing.JButton; |
136 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
137 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
138 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
139 |
|
140 |
|
141 |
/**
|
142 |
* A component linked to a SymbolEditor that shows the layers
|
143 |
*
|
144 |
* @author jaume
|
145 |
*
|
146 |
*/
|
147 |
public class SymbolLayerManager extends JPanel implements ActionListener{ |
148 |
private static final long serialVersionUID = -1939951243066481691L; |
149 |
private static final Dimension LIST_CELL_SIZE = new Dimension(150,37); |
150 |
private SymbolEditor owner;
|
151 |
private JList jListLayers; |
152 |
private ISymbol activeLayer;
|
153 |
private IMultiLayerSymbol symbol;
|
154 |
private JButton btnAddLayer = null; |
155 |
private JPanel pnlButtons = null; |
156 |
private JButton btnRemoveLayer = null; |
157 |
private JButton btnMoveUpLayer = null; |
158 |
private JButton btnMoveDownLayer = null; |
159 |
private final Dimension btnDimension = new Dimension(24, 24); |
160 |
private JScrollPane scroll; |
161 |
private Color cellSelectedBGColor = Color.BLUE; |
162 |
|
163 |
|
164 |
public SymbolLayerManager(SymbolEditor owner) {
|
165 |
this.owner = owner;
|
166 |
this.symbol = (IMultiLayerSymbol) owner.getSymbol();
|
167 |
if (symbol.getLayerCount()==0) { |
168 |
int shapeType = -1; |
169 |
if (symbol instanceof IMarkerSymbol) { |
170 |
shapeType = Geometry.TYPES.POINT; |
171 |
} else if (symbol instanceof ILineSymbol) { |
172 |
shapeType = Geometry.TYPES.CURVE; |
173 |
} else if (symbol instanceof IFillSymbol) { |
174 |
shapeType = Geometry.TYPES.SURFACE; |
175 |
} |
176 |
|
177 |
if (shapeType != -1) |
178 |
symbol.addLayer(MapContextLocator.getSymbolManager() |
179 |
.createSymbol(shapeType)); |
180 |
} |
181 |
initialize(); |
182 |
|
183 |
} |
184 |
|
185 |
private void initialize() { |
186 |
this.setLayout(new BorderLayout()); |
187 |
this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
|
188 |
this.add(getPnlButtons(), java.awt.BorderLayout.SOUTH);
|
189 |
getJListLayers().setSelectedIndex(0);
|
190 |
} |
191 |
|
192 |
private JScrollPane getJScrollPane() { |
193 |
if (scroll == null) { |
194 |
scroll = new JScrollPane(); |
195 |
scroll.setPreferredSize(new Dimension(150, 160)); |
196 |
scroll.setViewportView(getJListLayers()); |
197 |
} |
198 |
return scroll;
|
199 |
} |
200 |
|
201 |
private JList getJListLayers() { |
202 |
if (jListLayers == null) { |
203 |
jListLayers = new JList(); |
204 |
jListLayers.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
205 |
jListLayers.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
206 |
|
207 |
jListLayers.setVisibleRowCount(-1);
|
208 |
jListLayers.addListSelectionListener(new ListSelectionListener() { |
209 |
public void valueChanged(ListSelectionEvent e) { |
210 |
setLayer((ISymbol) jListLayers.getSelectedValue()); |
211 |
} |
212 |
}); |
213 |
jListLayers.setModel(new SymbolLayerListModel());
|
214 |
jListLayers.setCellRenderer(new DefaultListCellRenderer() { |
215 |
private static final long serialVersionUID = -2551357351239544039L; |
216 |
|
217 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
218 |
return new SymbolLayerComponent((ISymbol) value, index, isSelected); |
219 |
} |
220 |
}); |
221 |
jListLayers.addMouseListener(new MouseAdapter() { |
222 |
public void mouseClicked(MouseEvent e) { |
223 |
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { |
224 |
ISymbolSelector symSel = SymbolSelector.createSymbolSelector(activeLayer, owner.getShapeType()); |
225 |
PluginServices.getMDIManager().addWindow(symSel); |
226 |
updateSymbol((ISymbol) symSel.getSelectedObject()); |
227 |
setLayer((ISymbol) symSel.getSelectedObject()); |
228 |
} |
229 |
|
230 |
} |
231 |
}); |
232 |
} |
233 |
return jListLayers;
|
234 |
} |
235 |
|
236 |
private void updateSymbol(ISymbol layer) { |
237 |
if (layer != null) { |
238 |
int index = getJListLayers().getSelectedIndex();
|
239 |
symbol.setLayer(index, layer); |
240 |
owner.refresh(); |
241 |
validate(); |
242 |
} |
243 |
} |
244 |
|
245 |
private void setLayer(ISymbol symbol) { |
246 |
if (symbol!=null) { |
247 |
activeLayer = symbol; |
248 |
owner.setOptionsPageFor(symbol); |
249 |
} |
250 |
} |
251 |
|
252 |
private JButton getBtnAddLayer() { |
253 |
if (btnAddLayer == null) { |
254 |
btnAddLayer = new JButton(PluginServices.getIconTheme().get("symbol-layer-add")); |
255 |
btnAddLayer.setActionCommand("ADD");
|
256 |
btnAddLayer.setSize(btnDimension); |
257 |
btnAddLayer.setPreferredSize(btnDimension); |
258 |
btnAddLayer.addActionListener(this);
|
259 |
} |
260 |
return btnAddLayer;
|
261 |
} |
262 |
|
263 |
private JPanel getPnlButtons() { |
264 |
if (pnlButtons == null) { |
265 |
pnlButtons = new JPanel(); |
266 |
pnlButtons.add(getBtnAddLayer(), null);
|
267 |
pnlButtons.add(getBtnRemoveLayer(), null);
|
268 |
pnlButtons.add(getBtnMoveUpLayer(), null);
|
269 |
pnlButtons.add(getBtnMoveDown(), null);
|
270 |
} |
271 |
return pnlButtons;
|
272 |
} |
273 |
|
274 |
private JButton getBtnRemoveLayer() { |
275 |
if (btnRemoveLayer == null) { |
276 |
btnRemoveLayer = new JButton(PluginServices.getIconTheme().get("symbol-layer-remove")); |
277 |
btnRemoveLayer.setActionCommand("REMOVE");
|
278 |
btnRemoveLayer.setSize(btnDimension); |
279 |
btnRemoveLayer.setPreferredSize(btnDimension); |
280 |
btnRemoveLayer.addActionListener(this);
|
281 |
} |
282 |
return btnRemoveLayer;
|
283 |
} |
284 |
|
285 |
private JButton getBtnMoveUpLayer() { |
286 |
if (btnMoveUpLayer == null) { |
287 |
btnMoveUpLayer = new JButton(PluginServices.getIconTheme().get("symbol-layer-move-up")); |
288 |
btnMoveUpLayer.setActionCommand("MOVE_UP");
|
289 |
btnMoveUpLayer.setSize(btnDimension); |
290 |
btnMoveUpLayer.setPreferredSize(btnDimension); |
291 |
btnMoveUpLayer.addActionListener(this);
|
292 |
} |
293 |
return btnMoveUpLayer;
|
294 |
} |
295 |
|
296 |
private JButton getBtnMoveDown() { |
297 |
if (btnMoveDownLayer == null) { |
298 |
btnMoveDownLayer = new JButton(PluginServices.getIconTheme().get("symbol-layer-move-down")); |
299 |
btnMoveDownLayer.setActionCommand("MOVE_DOWN");
|
300 |
btnMoveDownLayer.setSize(btnDimension); |
301 |
btnMoveDownLayer.setPreferredSize(btnDimension); |
302 |
btnMoveDownLayer.addActionListener(this);
|
303 |
} |
304 |
return btnMoveDownLayer;
|
305 |
} |
306 |
|
307 |
public void actionPerformed(ActionEvent e) { |
308 |
String command = e.getActionCommand();
|
309 |
|
310 |
int jlistIndex = getJListLayers().getSelectedIndex();
|
311 |
int index = symbol.getLayerCount() - 1 - jlistIndex; |
312 |
|
313 |
if (command.equals("ADD")) { |
314 |
symbol.addLayer(owner.getNewLayer()); |
315 |
index = symbol.getLayerCount(); |
316 |
} else if (command.equals("REMOVE")) { |
317 |
int layerCount = symbol.getLayerCount();
|
318 |
if (layerCount >1 && index < layerCount) |
319 |
symbol.removeLayer(symbol.getLayer(index)); |
320 |
} else if (command.equals("MOVE_UP")) { |
321 |
if (index < symbol.getLayerCount()-1) { |
322 |
symbol.swapLayers(index, index+1);
|
323 |
jlistIndex--; |
324 |
} |
325 |
} else if (command.equals("MOVE_DOWN")) { |
326 |
if (index > 0) { |
327 |
symbol.swapLayers(index, index-1);
|
328 |
jlistIndex++; |
329 |
} |
330 |
} else if (command.equals("LOCK")) { |
331 |
try {
|
332 |
//XMLENTITY-UPDATED
|
333 |
// XMLEntity layerXML = symbol.getLayer(index).getXMLEntity();
|
334 |
// boolean locked = !layerXML.contains("locked") || !layerXML.getBooleanProperty("locked");
|
335 |
// layerXML.putProperty("locked", locked);
|
336 |
} catch (Exception ex) { |
337 |
// Index out of bounds or so, we don't care
|
338 |
} |
339 |
} |
340 |
owner.refresh(); |
341 |
validate(); |
342 |
getJListLayers().setSelectedIndex(jlistIndex); |
343 |
|
344 |
} |
345 |
|
346 |
private class SymbolLayerListModel extends AbstractListModel { |
347 |
private static final long serialVersionUID = 4197818146836802855L; |
348 |
private ArrayList listeners = new ArrayList(); |
349 |
|
350 |
public int getSize() { |
351 |
return symbol.getLayerCount();
|
352 |
} |
353 |
|
354 |
public Object getElementAt(int index) { |
355 |
return symbol.getLayer(symbol.getLayerCount()-1-index); |
356 |
} |
357 |
|
358 |
public void addListDataListener(ListDataListener l) { |
359 |
listeners.add(l); |
360 |
} |
361 |
|
362 |
public void removeListDataListener(ListDataListener l) { |
363 |
listeners.remove(l); |
364 |
} |
365 |
|
366 |
} |
367 |
|
368 |
public ISymbol getSelectedLayer() {
|
369 |
return (ISymbol) getJListLayers().getSelectedValue();
|
370 |
} |
371 |
|
372 |
public int getSelectedLayerIndex() { |
373 |
return getJListLayers().getSelectedIndex();
|
374 |
} |
375 |
|
376 |
public void validate() { // patched to force the list to be painted when it starts empty |
377 |
jListLayers = null;
|
378 |
getJScrollPane().setViewportView(getJListLayers()); |
379 |
super.validate();
|
380 |
} |
381 |
|
382 |
private class SymbolLayerComponent extends JPanel { |
383 |
private static final long serialVersionUID = -3706313315505454031L; |
384 |
|
385 |
public SymbolLayerComponent(ISymbol sym, int index, boolean isSelected) { |
386 |
LayoutManager layout = new FlowLayout(FlowLayout.LEFT, 3, 3); |
387 |
setLayout(layout); |
388 |
Color bgColor = (isSelected) ? cellSelectedBGColor
|
389 |
: Color.WHITE;
|
390 |
setBackground(bgColor); |
391 |
JCheckBox chkVisible = new JCheckBox("", symbol.getLayer(index).isShapeVisible()); |
392 |
chkVisible.setBackground(bgColor); |
393 |
add(chkVisible); |
394 |
SymbolPreviewer sp = new SymbolPreviewer();
|
395 |
sp.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
396 |
sp.setAlignmentX(Component.LEFT_ALIGNMENT);
|
397 |
sp.setPreferredSize(new Dimension(80, 30)); |
398 |
sp.setSize(new Dimension(80, 30)); |
399 |
sp.setSymbol(sym); |
400 |
sp.setBackground(Color.WHITE);
|
401 |
add(sp); |
402 |
|
403 |
// TODO: which is the meaning of a "locked" symbol, and where is defined??
|
404 |
// XMLEntity xml=null;
|
405 |
////XMLENTITY-UPDATED
|
406 |
//// try {
|
407 |
//// xml = sym.getXMLEntity();
|
408 |
//// } catch (XMLException e) {
|
409 |
//// NotificationManager.addWarning("Symbol layer", e);
|
410 |
//// }
|
411 |
// String source;
|
412 |
// if (xml.contains("locked"))
|
413 |
// source = xml.getBooleanProperty("locked") ?
|
414 |
// "images/locked.png" :
|
415 |
// "images/unlocked.png";
|
416 |
// else
|
417 |
// source = "images/unlocked.png";
|
418 |
|
419 |
|
420 |
JButton btnLock = new JButton(IconThemeHelper.getImageIcon("symbol-layer-unlock")); |
421 |
btnLock.setSize(btnDimension); |
422 |
btnLock.setPreferredSize(btnDimension); |
423 |
btnLock.setActionCommand("LOCK");
|
424 |
btnLock.setBackground(bgColor); |
425 |
btnLock.setAlignmentX(Component.CENTER_ALIGNMENT);
|
426 |
add(btnLock); |
427 |
setPreferredSize(LIST_CELL_SIZE); |
428 |
|
429 |
} |
430 |
} |
431 |
} |
432 |
|
433 |
|