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 / DummySymbol.java @ 40559
History | View | Annotate | Download (4.58 KB)
1 |
/**
|
---|---|
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 |
package org.gvsig.fmap.mapcontext.rendering.symbol; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.Rectangle; |
29 |
import java.awt.geom.AffineTransform; |
30 |
import java.awt.geom.PathIterator; |
31 |
import java.util.ArrayList; |
32 |
|
33 |
import org.gvsig.compat.print.PrintAttributes; |
34 |
import org.gvsig.fmap.dal.feature.Feature; |
35 |
import org.gvsig.fmap.geom.Geometry; |
36 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
37 |
import org.gvsig.fmap.geom.primitive.Point; |
38 |
import org.gvsig.fmap.mapcontext.ViewPort; |
39 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
40 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
41 |
import org.gvsig.tools.persistence.PersistentState; |
42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
43 |
import org.gvsig.tools.task.Cancellable; |
44 |
|
45 |
public class DummySymbol implements ISymbol { |
46 |
|
47 |
private Color color = Color.GREEN; |
48 |
private int type = TYPES.SOLID; |
49 |
|
50 |
public DummySymbol(Color c, int geomtype) { |
51 |
color = c; |
52 |
type = geomtype; |
53 |
} |
54 |
|
55 |
public Object clone() { |
56 |
return null; |
57 |
} |
58 |
|
59 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
60 |
Geometry geom, Feature f, Cancellable cancel) { |
61 |
|
62 |
g.setColor(color); |
63 |
|
64 |
if (geom instanceof Point) { |
65 |
Point p = (Point) geom; |
66 |
p.transform(affineTransform); |
67 |
g.drawRect((int) p.getX(), (int) p.getY(), 3, 3); |
68 |
} else {
|
69 |
PathIterator piter = geom.getPathIterator(affineTransform);
|
70 |
drawPathIterator(g, piter); |
71 |
} |
72 |
} |
73 |
|
74 |
public void drawInsideRectangle(Graphics2D g, |
75 |
AffineTransform scaleInstance, Rectangle r, |
76 |
PrintAttributes properties) throws SymbolDrawingException {
|
77 |
// TODO Auto-generated method stub
|
78 |
|
79 |
} |
80 |
|
81 |
public Color getColor() { |
82 |
return color;
|
83 |
} |
84 |
|
85 |
public String getDescription() { |
86 |
return "a dummy symbol"; |
87 |
} |
88 |
|
89 |
public int getOnePointRgb() { |
90 |
return color.getRGB();
|
91 |
} |
92 |
|
93 |
public void getPixExtentPlus(Geometry geom, float[] distances, |
94 |
ViewPort viewPort, int dpi) {
|
95 |
// TODO Auto-generated method stub
|
96 |
|
97 |
} |
98 |
|
99 |
public ISymbol getSymbolForSelection() {
|
100 |
return new DummySymbol(Color.YELLOW, type); |
101 |
} |
102 |
|
103 |
public int getSymbolType() { |
104 |
return type;
|
105 |
} |
106 |
|
107 |
public boolean isOneDotOrPixel(Geometry geom, |
108 |
double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) { |
109 |
// TODO Auto-generated method stub
|
110 |
return false; |
111 |
} |
112 |
|
113 |
public boolean isShapeVisible() { |
114 |
return true; |
115 |
} |
116 |
|
117 |
public boolean isSuitableFor(Geometry geom) { |
118 |
return type == geom.getType();
|
119 |
} |
120 |
|
121 |
public void setColor(Color c) { |
122 |
color = c; |
123 |
} |
124 |
|
125 |
public void setDescription(String desc) { |
126 |
} |
127 |
|
128 |
public void loadFromState(PersistentState state) |
129 |
throws PersistenceException {
|
130 |
} |
131 |
|
132 |
public void saveToState(PersistentState state) throws PersistenceException { |
133 |
} |
134 |
|
135 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
136 |
PrintAttributes properties) { |
137 |
} |
138 |
|
139 |
|
140 |
|
141 |
/**
|
142 |
* Draws the general path on the graphics object with the given affine transformation
|
143 |
* @param g the graphics object
|
144 |
* @param gp the general path
|
145 |
*/
|
146 |
public static void drawPathIterator(Graphics2D g, PathIterator pit) { |
147 |
|
148 |
ArrayList x = new ArrayList(); |
149 |
ArrayList y = new ArrayList(); |
150 |
double[] current = new double[6]; |
151 |
|
152 |
while (!pit.isDone()) {
|
153 |
pit.currentSegment(current); |
154 |
x.add(new Integer((int) current[0])); |
155 |
y.add(new Integer((int) current[1])); |
156 |
pit.next(); |
157 |
} |
158 |
|
159 |
int[] gx = integerArrayListToIntArray(x); |
160 |
int[] gy = integerArrayListToIntArray(y); |
161 |
|
162 |
g.drawPolyline(gx, gy, gx.length); |
163 |
} |
164 |
|
165 |
|
166 |
/**
|
167 |
* Converts array list of Integer objects into array of int
|
168 |
* @param l
|
169 |
* @return array of int
|
170 |
*/
|
171 |
public static int[] integerArrayListToIntArray(ArrayList l) { |
172 |
|
173 |
int size = l.size();
|
174 |
int[] resp = new int[size]; |
175 |
for (int i=0; i<size; i++) { |
176 |
resp[i] = ((Integer) l.get(i)).intValue();
|
177 |
} |
178 |
return resp;
|
179 |
} |
180 |
|
181 |
} |