root / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / line / impl / SimpleLineSymbol.java @ 32880
History | View | Annotate | Download (5.17 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl; |
23 |
|
24 |
import java.awt.Graphics2D; |
25 |
import java.awt.Rectangle; |
26 |
import java.awt.geom.AffineTransform; |
27 |
|
28 |
import org.gvsig.compat.print.PrintAttributes; |
29 |
import org.gvsig.fmap.dal.feature.Feature; |
30 |
import org.gvsig.fmap.geom.Geometry; |
31 |
import org.gvsig.fmap.geom.GeometryLocator; |
32 |
import org.gvsig.fmap.geom.GeometryManager; |
33 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
35 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
36 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
37 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.ArrowDecoratorStyle; |
38 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.Line2DOffset; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dynobject.DynStruct; |
41 |
import org.gvsig.tools.persistence.PersistenceManager; |
42 |
import org.gvsig.tools.task.Cancellable; |
43 |
import org.slf4j.Logger; |
44 |
import org.slf4j.LoggerFactory; |
45 |
|
46 |
|
47 |
/**
|
48 |
* SimpleLineSymbol is the most basic symbol for the representation of line objects.
|
49 |
* Allows to define the width of the line, the color and the drawn pattern.
|
50 |
*
|
51 |
* @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
|
52 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
53 |
*/
|
54 |
public class SimpleLineSymbol extends AbstractLineSymbol { |
55 |
|
56 |
public static final String SIMPLE_LINE_SYMBOL_DYNCLASS_NAME = "SimpleLineSymbol"; |
57 |
|
58 |
SimpleLineSymbol symbolForSelection; |
59 |
// private double width;
|
60 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
61 |
private static final Logger logger = LoggerFactory.getLogger(SimpleLineSymbol.class); |
62 |
|
63 |
public SimpleLineSymbol() {
|
64 |
setLineWidth(1d);
|
65 |
} |
66 |
|
67 |
public ISymbol getSymbolForSelection() {
|
68 |
if (symbolForSelection == null) { |
69 |
symbolForSelection = (SimpleLineSymbol) cloneForSelection(); |
70 |
} |
71 |
return symbolForSelection;
|
72 |
} |
73 |
|
74 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
75 |
Geometry geom, Feature feature, Cancellable cancel) { |
76 |
|
77 |
Geometry geomToDraw = geom; |
78 |
g.setStroke(getLineStyle().getStroke()); |
79 |
|
80 |
if (getLineStyle().getOffset() != 0) { |
81 |
double offset = getLineStyle().getOffset();
|
82 |
try {
|
83 |
geomToDraw = |
84 |
geomManager.createSurface(Line2DOffset.offsetLine( |
85 |
geomToDraw, offset), SUBTYPES.GEOM2D); |
86 |
} catch (CreateGeometryException e) {
|
87 |
logger.error("Creating a Surface", e);
|
88 |
e.printStackTrace(); |
89 |
} |
90 |
} |
91 |
g.setColor(getColor()); |
92 |
g.draw(geomToDraw); |
93 |
|
94 |
ArrowDecoratorStyle arrowDecorator = getLineStyle().getArrowDecorator(); |
95 |
|
96 |
if (arrowDecorator != null) { |
97 |
try {
|
98 |
arrowDecorator.draw(g, affineTransform, geomToDraw, feature); |
99 |
} catch (CreateGeometryException e) {
|
100 |
logger.error("Error creating a geometry");
|
101 |
} |
102 |
} |
103 |
} |
104 |
|
105 |
public int getOnePointRgb() { |
106 |
return getColor().getRGB();
|
107 |
} |
108 |
|
109 |
public void drawInsideRectangle(Graphics2D g, |
110 |
AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException { |
111 |
g.setColor(getColor()); |
112 |
g.setStroke(getLineStyle().getStroke()); |
113 |
super.drawInsideRectangle(g, scaleInstance, r, properties);
|
114 |
} |
115 |
|
116 |
public String getClassName() { |
117 |
return getClass().getName();
|
118 |
} |
119 |
|
120 |
public void setLineWidth(double width) { |
121 |
// this.width = width;
|
122 |
getLineStyle().setLineWidth((float) width);
|
123 |
} |
124 |
|
125 |
public double getLineWidth() { |
126 |
// return width;
|
127 |
return getLineStyle().getLineWidth();
|
128 |
} |
129 |
|
130 |
public Object clone() throws CloneNotSupportedException { |
131 |
SimpleLineSymbol copy = (SimpleLineSymbol) super.clone();
|
132 |
|
133 |
// clone selection
|
134 |
if (symbolForSelection != null) { |
135 |
copy.symbolForSelection = (SimpleLineSymbol) symbolForSelection |
136 |
.clone(); |
137 |
} |
138 |
|
139 |
return copy;
|
140 |
} |
141 |
|
142 |
public static void registerPersistence() { |
143 |
// Add the SimpleLineSymbol DynClass definition.
|
144 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
145 |
DynStruct definition = manager.addDefinition( |
146 |
SimpleLineSymbol.class, |
147 |
SIMPLE_LINE_SYMBOL_DYNCLASS_NAME, |
148 |
SIMPLE_LINE_SYMBOL_DYNCLASS_NAME+" Persistence definition",
|
149 |
null,
|
150 |
null
|
151 |
); |
152 |
// Extend the LineSymbol base definition
|
153 |
definition.extend(LINE_SYMBOL_DYNCLASS_NAME); |
154 |
} |
155 |
|
156 |
} |