root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiLayerSymbol.java @ 9669
History | View | Annotate | Download (5.6 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: MultiLayerSymbol.java 9669 2007-01-11 12:17:34Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3 2007-01-11 12:17:34 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
50 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
51 |
*
|
52 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package com.iver.cit.gvsig.fmap.core.symbols; |
58 |
|
59 |
import java.awt.Graphics2D; |
60 |
import java.awt.Rectangle; |
61 |
import java.awt.Shape; |
62 |
import java.awt.geom.AffineTransform; |
63 |
|
64 |
import javax.print.attribute.PrintRequestAttributeSet; |
65 |
|
66 |
import com.iver.cit.gvsig.fmap.core.FShape; |
67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
68 |
import com.iver.cit.gvsig.fmap.core.SymbolFactory; |
69 |
import com.iver.utiles.XMLEntity; |
70 |
|
71 |
/**
|
72 |
* <p>Symbol that allows to combine many symbols into one and treat it
|
73 |
* as a single one. Within MultiLayerSymbol, each symbol is defined as a
|
74 |
* layer inside the MultiLayerSymbol.<br></p>
|
75 |
*
|
76 |
* <p>This symbol does not perform anything by itself. Rather than that it
|
77 |
* keeps a list of symbols and iterates over each element performing the
|
78 |
* operation over each one.<br></p>
|
79 |
*
|
80 |
* <p>The elements of the list can be any symbol, even other MultiLayerSymbol
|
81 |
* so, it is also possible to define symbols as a tree of symbols</p>
|
82 |
*
|
83 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
84 |
*
|
85 |
*/
|
86 |
public class MultiLayerSymbol extends AbstractSymbol { |
87 |
private ISymbol[] layers; |
88 |
private MultiLayerSymbol selectionSymbol;
|
89 |
|
90 |
/**
|
91 |
* Gets the symbol in the layerIndex position of the symbol list.
|
92 |
* @param int layerIndex
|
93 |
* @return
|
94 |
*/
|
95 |
public ISymbol getLayer(int layerIndex) { |
96 |
try{
|
97 |
return layers[layerIndex];
|
98 |
} catch (Exception e) { |
99 |
return null; |
100 |
} |
101 |
} |
102 |
|
103 |
public int getLayerCount() { |
104 |
if (layers == null) |
105 |
return -1; |
106 |
return layers.length;
|
107 |
} |
108 |
|
109 |
public ISymbol getSymbolForSelection() {
|
110 |
if (selectionSymbol == null) { |
111 |
selectionSymbol = new MultiLayerSymbol();
|
112 |
selectionSymbol.setDescription(getDescription()); |
113 |
for (int i = 0; i < layers.length; i++) { |
114 |
selectionSymbol.addLayer(layers[i].getSymbolForSelection()); |
115 |
} |
116 |
} |
117 |
return selectionSymbol;
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Stacks a new symbol to the symbol list. The symbol is appended to the
|
122 |
* list and, in terms of use, it will be the last symbol to be processed.
|
123 |
* @param ISymbol newLayer
|
124 |
*/
|
125 |
public void addLayer(ISymbol newLayer) { |
126 |
selectionSymbol = null; /* forces the selection symbol to be re-created |
127 |
* next time it is required
|
128 |
*/
|
129 |
ISymbol[] newLayers = new ISymbol[layers.length+1]; |
130 |
for (int i = 0; i < newLayers.length-1; i++) { |
131 |
newLayers[i] = layers[i]; |
132 |
} |
133 |
layers[layers.length] = newLayer; |
134 |
} |
135 |
|
136 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
137 |
for (int i = 0; i < layers.length; i++) { |
138 |
layers[i].draw(g, affineTransform, shp); |
139 |
} |
140 |
} |
141 |
|
142 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
143 |
// TODO Auto-generated method stub
|
144 |
throw new Error("Not yet implemented!"); |
145 |
|
146 |
} |
147 |
|
148 |
public int getOnePointRgb() { |
149 |
// will paint only the last layer pixel
|
150 |
return layers[layers.length-1].getOnePointRgb(); |
151 |
} |
152 |
|
153 |
public XMLEntity getXMLEntity() {
|
154 |
XMLEntity xml = new XMLEntity();
|
155 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
156 |
xml.putProperty("desc", getDescription());
|
157 |
for (int i = 0; i < layers.length; i++) { |
158 |
xml.addChild(layers[i].getXMLEntity()); |
159 |
} |
160 |
return xml;
|
161 |
} |
162 |
|
163 |
public int getSymbolType() { |
164 |
// TODO Auto-generated method stub
|
165 |
throw new Error("Not yet implemented!"); |
166 |
|
167 |
} |
168 |
|
169 |
public boolean isSuitableFor(IGeometry geom) { |
170 |
return true; |
171 |
} |
172 |
|
173 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
174 |
for (int i = 0; i < layers.length; i++) { |
175 |
layers[i].drawInsideRectangle(g, scaleInstance, r); |
176 |
} |
177 |
} |
178 |
|
179 |
public String getClassName() { |
180 |
return getClass().getName();
|
181 |
} |
182 |
|
183 |
public void setXMLEntity(XMLEntity xml) { |
184 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
185 |
setDescription(xml.getStringProperty("desc"));
|
186 |
layers = new ISymbol[xml.getChildrenCount()];
|
187 |
for (int i = 0; i < layers.length; i++) { |
188 |
layers[i] = SymbolFactory.createFromXML(xml.getChild(i), "layer" + i);
|
189 |
} |
190 |
} |
191 |
|
192 |
public void setPrintingProperties(PrintRequestAttributeSet properties) { |
193 |
for (int i = 0; i < layers.length; i++) { |
194 |
layers[i].setPrintingProperties(properties); |
195 |
} |
196 |
} |
197 |
|
198 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws com.iver.cit.gvsig.fmap.DriverException { |
199 |
// TODO Implement it
|
200 |
throw new Error("Not yet implemented!"); |
201 |
|
202 |
} |
203 |
|
204 |
|
205 |
} |