root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src-test / org / gvsig / fmap / mapcontext / rendering / symbol / DummyVectorLegend.java @ 32880
History | View | Annotate | Download (4.92 KB)
1 |
package org.gvsig.fmap.mapcontext.rendering.symbol; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.image.BufferedImage; |
6 |
import java.util.Iterator; |
7 |
import java.util.Map; |
8 |
|
9 |
import org.cresques.cts.ICoordTrans; |
10 |
import org.gvsig.compat.print.PrintAttributes; |
11 |
import org.gvsig.fmap.dal.exception.DataException; |
12 |
import org.gvsig.fmap.dal.feature.Feature; |
13 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
16 |
import org.gvsig.fmap.mapcontext.ViewPort; |
17 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
18 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
19 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
20 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
21 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
22 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
23 |
import org.gvsig.tools.ToolsLocator; |
24 |
import org.gvsig.tools.dynobject.DynStruct; |
25 |
import org.gvsig.tools.observer.Observer; |
26 |
import org.gvsig.tools.persistence.PersistenceManager; |
27 |
import org.gvsig.tools.persistence.PersistentState; |
28 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
29 |
import org.gvsig.tools.task.Cancellable; |
30 |
|
31 |
public class DummyVectorLegend implements IVectorLegend { |
32 |
|
33 |
private long shpType = -1; |
34 |
|
35 |
private ISymbol sym = new DummySymbol(Color.RED, TYPES.SOLID); |
36 |
|
37 |
public DummyVectorLegend() {
|
38 |
shpType = System.currentTimeMillis() % 1000000; |
39 |
} |
40 |
|
41 |
public DummyVectorLegend(int type) { |
42 |
shpType = type; // System.currentTimeMillis() % 1000000;
|
43 |
} |
44 |
|
45 |
public void draw(BufferedImage image, Graphics2D graphics2D, |
46 |
ViewPort viewPort, Cancellable cancel, double scale,
|
47 |
Map queryParameters, ICoordTrans coordTrans,
|
48 |
FeatureStore featureStore) throws LegendException {
|
49 |
|
50 |
try {
|
51 |
FeatureSet fs = featureStore.getFeatureSet(); |
52 |
Iterator iter = fs.iterator();
|
53 |
Feature feat = null;
|
54 |
ISymbol symb = null;
|
55 |
while (iter.hasNext()) {
|
56 |
feat = (Feature) iter.next(); |
57 |
symb = this.getSymbolByFeature(feat);
|
58 |
symb.draw(graphics2D, viewPort.getAffineTransform(), feat.getDefaultGeometry(), feat, null);
|
59 |
} |
60 |
} catch (DataException e) {
|
61 |
// TODO Auto-generated catch block
|
62 |
e.printStackTrace(); |
63 |
} |
64 |
// TODO Auto-generated method stub
|
65 |
|
66 |
} |
67 |
|
68 |
public int getShapeType() { |
69 |
// TODO Auto-generated method stub
|
70 |
return (int) shpType; |
71 |
} |
72 |
|
73 |
public ISymbol getSymbolByFeature(Feature feat) {
|
74 |
return sym;
|
75 |
} |
76 |
|
77 |
public boolean isSuitableForShapeType(int shapeType) { |
78 |
return sym.getSymbolType() == shapeType;
|
79 |
} |
80 |
|
81 |
public boolean isUseDefaultSymbol() { |
82 |
return true; |
83 |
} |
84 |
|
85 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
86 |
double scale, Object object, ICoordTrans coordTrans, |
87 |
FeatureStore featureStore, PrintAttributes properties) |
88 |
throws LegendException {
|
89 |
// TODO Auto-generated method stub
|
90 |
|
91 |
} |
92 |
|
93 |
public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException { |
94 |
sym = s; |
95 |
} |
96 |
|
97 |
public void setShapeType(int shapeType) { |
98 |
shpType = shapeType; |
99 |
} |
100 |
|
101 |
public void useDefaultSymbol(boolean b) { |
102 |
} |
103 |
|
104 |
public void addLegendListener(LegendContentsChangedListener listener) { |
105 |
// TODO Auto-generated method stub
|
106 |
|
107 |
} |
108 |
|
109 |
public ILegend cloneLegend() {
|
110 |
// TODO Auto-generated method stub
|
111 |
return null; |
112 |
} |
113 |
|
114 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
115 |
// TODO Auto-generated method stub
|
116 |
|
117 |
} |
118 |
|
119 |
public ISymbol getDefaultSymbol() {
|
120 |
return sym;
|
121 |
} |
122 |
|
123 |
public LegendContentsChangedListener[] getListeners() { |
124 |
// TODO Auto-generated method stub
|
125 |
return null; |
126 |
} |
127 |
|
128 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
129 |
// TODO Auto-generated method stub
|
130 |
|
131 |
} |
132 |
|
133 |
public String getClassName() { |
134 |
return this.getClass().getName(); |
135 |
} |
136 |
|
137 |
|
138 |
|
139 |
|
140 |
public void addDrawingObserver(Observer observer) { |
141 |
// TODO Auto-generated method stub
|
142 |
|
143 |
} |
144 |
|
145 |
public void deleteDrawingObserver(Observer observer) { |
146 |
// TODO Auto-generated method stub
|
147 |
|
148 |
} |
149 |
|
150 |
public void deleteDrawingObservers() { |
151 |
// TODO Auto-generated method stub
|
152 |
|
153 |
} |
154 |
|
155 |
public void loadFromState(PersistentState state) throws PersistenceException { |
156 |
shpType = state.getLong("shpType");
|
157 |
} |
158 |
|
159 |
|
160 |
public void saveToState(PersistentState state) throws PersistenceException { |
161 |
state.set("shpType", shpType);
|
162 |
} |
163 |
|
164 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
165 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
166 |
FeatureStore featureStore, PrintAttributes properties) |
167 |
throws LegendException {
|
168 |
// TODO Auto-generated method stub
|
169 |
|
170 |
} |
171 |
|
172 |
public static void registerPersistent() { |
173 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
174 |
DynStruct definition = manager.addDefinition( |
175 |
DummyVectorLegend.class, |
176 |
"DummyVectorLegend",
|
177 |
"DummyVectorLegend Persistence definition",
|
178 |
null,
|
179 |
null
|
180 |
); |
181 |
definition.addDynFieldLong("shpType")
|
182 |
.setMandatory(true);
|
183 |
} |
184 |
|
185 |
|
186 |
public Object clone() throws CloneNotSupportedException { |
187 |
return super.clone(); |
188 |
} |
189 |
|
190 |
|
191 |
} |