svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrameSymbol.java @ 772
History | View | Annotate | Download (6.06 KB)
1 | 5 | jldominguez | /* 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.app.project.documents.layout.fframes; |
||
23 | |||
24 | import java.awt.Graphics2D; |
||
25 | import java.awt.Rectangle; |
||
26 | import java.awt.geom.AffineTransform; |
||
27 | import java.awt.geom.Rectangle2D; |
||
28 | import java.awt.image.BufferedImage; |
||
29 | |||
30 | import org.gvsig.andami.PluginServices; |
||
31 | import org.gvsig.app.project.documents.layout.geometryadapters.GeometryAdapter; |
||
32 | import org.gvsig.compat.print.PrintAttributes; |
||
33 | import org.gvsig.fmap.geom.Geometry; |
||
34 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
35 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
36 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
||
37 | import org.gvsig.tools.ToolsLocator; |
||
38 | import org.gvsig.tools.dynobject.DynStruct; |
||
39 | import org.gvsig.tools.persistence.PersistenceManager; |
||
40 | import org.gvsig.tools.persistence.PersistentState; |
||
41 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
42 | |||
43 | /**
|
||
44 | * FFrame para introducir una S?mbolo en el Layout.
|
||
45 | *
|
||
46 | * @author Vicente Caballero Navarro
|
||
47 | */
|
||
48 | public class FFrameSymbol extends FFrameGraphics { |
||
49 | |||
50 | public static final String PERSISTENCE_DEFINITION_NAME = "FFrameSymbol"; |
||
51 | |||
52 | private PrintAttributes properties;
|
||
53 | |||
54 | private MapContextManager mapContextManager = MapContextLocator
|
||
55 | .getMapContextManager(); |
||
56 | |||
57 | /**
|
||
58 | * Crea un nuevo FFrameSymbol.
|
||
59 | */
|
||
60 | public FFrameSymbol() {
|
||
61 | super();
|
||
62 | } |
||
63 | |||
64 | /**
|
||
65 | * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
||
66 | * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
||
67 | * de dibujar.
|
||
68 | *
|
||
69 | * @param g
|
||
70 | * Graphics
|
||
71 | * @param at
|
||
72 | * Transformada afin.
|
||
73 | * @param rv
|
||
74 | * rect?ngulo sobre el que hacer un clip.
|
||
75 | * @param imgBase
|
||
76 | * Imagen para acelerar el dibujado.
|
||
77 | */
|
||
78 | public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
||
79 | BufferedImage imgBase) {
|
||
80 | Rectangle2D.Double re = getBoundingBox(at);
|
||
81 | g.rotate(Math.toRadians(getRotation()), re.x + (re.width / 2), re.y |
||
82 | + (re.height / 2));
|
||
83 | |||
84 | if (intersects(rv, re)) {
|
||
85 | AffineTransform mT2 = new AffineTransform(); |
||
86 | mT2.setToIdentity(); |
||
87 | |||
88 | Rectangle rec =
|
||
89 | new Rectangle((int) re.x, (int) re.y, (int) (re.width), |
||
90 | (int) (re.height));
|
||
91 | |||
92 | try {
|
||
93 | getFSymbol().drawInsideRectangle(g, mT2, rec, properties); |
||
94 | } catch (SymbolDrawingException e) {
|
||
95 | if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
|
||
96 | try {
|
||
97 | mapContextManager |
||
98 | .getSymbolManager() |
||
99 | .getWarningSymbol( |
||
100 | SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, |
||
101 | getFSymbol().getDescription(), |
||
102 | SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) |
||
103 | .drawInsideRectangle(g, null, rec, null); |
||
104 | } catch (SymbolDrawingException e1) {
|
||
105 | // IMPOSSIBLE TO REACH THIS
|
||
106 | } |
||
107 | } else {
|
||
108 | // should be unreachable code
|
||
109 | throw new Error(PluginServices.getText(this, |
||
110 | "symbol_shapetype_mismatch"));
|
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
115 | g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2), re.y |
||
116 | + (re.height / 2));
|
||
117 | } |
||
118 | |||
119 | /**
|
||
120 | * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#getNameFFrame()
|
||
121 | */
|
||
122 | public String getNameFFrame() { |
||
123 | return PluginServices.getText(this, "simbolo") + num; |
||
124 | } |
||
125 | |||
126 | public String getName() { |
||
127 | return PERSISTENCE_DEFINITION_NAME;
|
||
128 | } |
||
129 | |||
130 | /**
|
||
131 | * @see org.gvsig.app.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
||
132 | * java.awt.geom.AffineTransform)
|
||
133 | */
|
||
134 | public void print(Graphics2D g, AffineTransform at, Geometry geom, |
||
135 | PrintAttributes printingProperties) { |
||
136 | this.properties = printingProperties;
|
||
137 | draw(g, at, null, null); |
||
138 | this.properties = null; |
||
139 | } |
||
140 | |||
141 | public void initialize() { |
||
142 | |||
143 | } |
||
144 | |||
145 | public void setBoundBox(Rectangle2D r) { |
||
146 | m_BoundBox.setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); |
||
147 | } |
||
148 | |||
149 | public void setShapeType(int shapeType) { |
||
150 | setType(shapeType); |
||
151 | } |
||
152 | |||
153 | public static void registerPersistent() { |
||
154 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
155 | if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
||
156 | DynStruct definition = |
||
157 | manager.addDefinition(FFrameSymbol.class, |
||
158 | PERSISTENCE_DEFINITION_NAME, |
||
159 | "FFrameSymbol persistence definition", null, null); |
||
160 | |||
161 | definition.extend(manager |
||
162 | .getDefinition(FFrameGraphics.PERSISTENCE_DEFINITION_NAME)); |
||
163 | } |
||
164 | |||
165 | GeometryAdapter.registerPersistent(); |
||
166 | } |
||
167 | |||
168 | @Override
|
||
169 | public void loadFromState(PersistentState state) |
||
170 | throws PersistenceException {
|
||
171 | super.loadFromState(state);
|
||
172 | } |
||
173 | |||
174 | @Override
|
||
175 | public void saveToState(PersistentState state) throws PersistenceException { |
||
176 | super.saveToState(state);
|
||
177 | } |
||
178 | |||
179 | } |