svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / test / java / org / gvsig / fmap / mapcontext / rendering / symbol / DummyVectorLegend.java @ 40559
History | View | Annotate | Download (7.08 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.fmap.mapcontext.rendering.symbol; |
25 | |||
26 | import java.awt.Color; |
||
27 | import java.awt.Graphics2D; |
||
28 | import java.awt.image.BufferedImage; |
||
29 | import java.util.Iterator; |
||
30 | import java.util.Map; |
||
31 | |||
32 | import org.cresques.cts.ICoordTrans; |
||
33 | |||
34 | import org.gvsig.compat.print.PrintAttributes; |
||
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.feature.Feature; |
||
37 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
38 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
39 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
40 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
41 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
42 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
43 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
44 | import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
||
45 | import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
||
46 | import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
||
47 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
48 | import org.gvsig.tools.ToolsLocator; |
||
49 | import org.gvsig.tools.dynobject.DynStruct; |
||
50 | import org.gvsig.tools.evaluator.Evaluator; |
||
51 | import org.gvsig.tools.observer.Observer; |
||
52 | import org.gvsig.tools.persistence.PersistenceManager; |
||
53 | import org.gvsig.tools.persistence.PersistentState; |
||
54 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
55 | import org.gvsig.tools.task.Cancellable; |
||
56 | |||
57 | public class DummyVectorLegend implements IVectorLegend { |
||
58 | |||
59 | private long shpType = -1; |
||
60 | |||
61 | private ISymbol sym = new DummySymbol(Color.RED, TYPES.SOLID); |
||
62 | |||
63 | public DummyVectorLegend() {
|
||
64 | shpType = System.currentTimeMillis() % 1000000; |
||
65 | } |
||
66 | |||
67 | public DummyVectorLegend(int type) { |
||
68 | shpType = type; // System.currentTimeMillis() % 1000000;
|
||
69 | } |
||
70 | |||
71 | public void draw(BufferedImage image, Graphics2D graphics2D, |
||
72 | ViewPort viewPort, Cancellable cancel, double scale,
|
||
73 | Map queryParameters, ICoordTrans coordTrans,
|
||
74 | FeatureStore featureStore, FeatureQuery featureQuery) throws LegendException {
|
||
75 | |||
76 | } |
||
77 | public void draw(BufferedImage image, Graphics2D graphics2D, |
||
78 | ViewPort viewPort, Cancellable cancel, double scale,
|
||
79 | Map queryParameters, ICoordTrans coordTrans,
|
||
80 | FeatureStore featureStore) throws LegendException {
|
||
81 | |||
82 | try {
|
||
83 | FeatureSet fs = featureStore.getFeatureSet(); |
||
84 | Iterator iter = fs.iterator();
|
||
85 | Feature feat = null;
|
||
86 | ISymbol symb = null;
|
||
87 | while (iter.hasNext()) {
|
||
88 | feat = (Feature) iter.next(); |
||
89 | symb = this.getSymbolByFeature(feat);
|
||
90 | symb.draw(graphics2D, viewPort.getAffineTransform(), feat.getDefaultGeometry(), feat, null);
|
||
91 | } |
||
92 | } catch (DataException e) {
|
||
93 | // TODO Auto-generated catch block
|
||
94 | e.printStackTrace(); |
||
95 | } |
||
96 | // TODO Auto-generated method stub
|
||
97 | |||
98 | } |
||
99 | |||
100 | public int getShapeType() { |
||
101 | // TODO Auto-generated method stub
|
||
102 | return (int) shpType; |
||
103 | } |
||
104 | |||
105 | public ISymbol getSymbolByFeature(Feature feat) {
|
||
106 | return sym;
|
||
107 | } |
||
108 | |||
109 | public boolean isSuitableForShapeType(int shapeType) { |
||
110 | return sym.getSymbolType() == shapeType;
|
||
111 | } |
||
112 | |||
113 | public boolean isUseDefaultSymbol() { |
||
114 | return true; |
||
115 | } |
||
116 | |||
117 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
118 | double scale, Object object, ICoordTrans coordTrans, |
||
119 | FeatureStore featureStore, Evaluator evaluator, PrintAttributes properties) |
||
120 | throws LegendException {
|
||
121 | // TODO Auto-generated method stub
|
||
122 | |||
123 | } |
||
124 | |||
125 | public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException { |
||
126 | sym = s; |
||
127 | } |
||
128 | |||
129 | public void setShapeType(int shapeType) { |
||
130 | shpType = shapeType; |
||
131 | } |
||
132 | |||
133 | public void useDefaultSymbol(boolean b) { |
||
134 | } |
||
135 | |||
136 | public void addLegendListener(LegendContentsChangedListener listener) { |
||
137 | // TODO Auto-generated method stub
|
||
138 | |||
139 | } |
||
140 | |||
141 | public ILegend cloneLegend() {
|
||
142 | // TODO Auto-generated method stub
|
||
143 | return null; |
||
144 | } |
||
145 | |||
146 | public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
||
147 | // TODO Auto-generated method stub
|
||
148 | |||
149 | } |
||
150 | |||
151 | public ISymbol getDefaultSymbol() {
|
||
152 | return sym;
|
||
153 | } |
||
154 | |||
155 | public LegendContentsChangedListener[] getListeners() { |
||
156 | // TODO Auto-generated method stub
|
||
157 | return null; |
||
158 | } |
||
159 | |||
160 | public void removeLegendListener(LegendContentsChangedListener listener) { |
||
161 | // TODO Auto-generated method stub
|
||
162 | |||
163 | } |
||
164 | |||
165 | public String getClassName() { |
||
166 | return this.getClass().getName(); |
||
167 | } |
||
168 | |||
169 | |||
170 | |||
171 | |||
172 | public void addDrawingObserver(Observer observer) { |
||
173 | // TODO Auto-generated method stub
|
||
174 | |||
175 | } |
||
176 | |||
177 | public void deleteDrawingObserver(Observer observer) { |
||
178 | // TODO Auto-generated method stub
|
||
179 | |||
180 | } |
||
181 | |||
182 | public void deleteDrawingObservers() { |
||
183 | // TODO Auto-generated method stub
|
||
184 | |||
185 | } |
||
186 | |||
187 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
188 | shpType = state.getLong("shpType");
|
||
189 | } |
||
190 | |||
191 | |||
192 | public void saveToState(PersistentState state) throws PersistenceException { |
||
193 | state.set("shpType", shpType);
|
||
194 | } |
||
195 | |||
196 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
197 | double scale, Map queryParameters, ICoordTrans coordTrans, |
||
198 | FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties) |
||
199 | throws LegendException {
|
||
200 | // TODO Auto-generated method stub
|
||
201 | |||
202 | } |
||
203 | |||
204 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
205 | double scale, Map queryParameters, ICoordTrans coordTrans, |
||
206 | FeatureStore featureStore, PrintAttributes properties) |
||
207 | throws LegendException {
|
||
208 | // TODO Auto-generated method stub
|
||
209 | |||
210 | } |
||
211 | |||
212 | public static void registerPersistent() { |
||
213 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
214 | DynStruct definition = manager.addDefinition( |
||
215 | DummyVectorLegend.class, |
||
216 | "DummyVectorLegend",
|
||
217 | "DummyVectorLegend Persistence definition",
|
||
218 | null,
|
||
219 | null
|
||
220 | ); |
||
221 | definition.addDynFieldLong("shpType")
|
||
222 | .setMandatory(true);
|
||
223 | } |
||
224 | |||
225 | |||
226 | public Object clone() throws CloneNotSupportedException { |
||
227 | return super.clone(); |
||
228 | } |
||
229 | |||
230 | |||
231 | } |