root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutDraw.java @ 1074
History | View | Annotate | Download (11.9 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-sep-2004
|
3 |
*
|
4 |
*/
|
5 |
package com.iver.cit.gvsig.gui.layout; |
6 |
|
7 |
import com.iver.cit.gvsig.fmap.DriverException; |
8 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrame; |
9 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
10 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
11 |
|
12 |
import java.awt.Color; |
13 |
import java.awt.Graphics2D; |
14 |
import java.awt.geom.AffineTransform; |
15 |
import java.awt.geom.Point2D; |
16 |
import java.awt.geom.Rectangle2D; |
17 |
import java.awt.image.BufferedImage; |
18 |
|
19 |
|
20 |
/**
|
21 |
* Clase que implementa los m?todos del Layout que dibujan sobre el Graphics.
|
22 |
*
|
23 |
* @author Vicente Caballero Navarro
|
24 |
*/
|
25 |
public class FLayoutDraw { |
26 |
private Layout layout;
|
27 |
|
28 |
/**
|
29 |
* Crea un nuevo FLayoutDraw.
|
30 |
*
|
31 |
* @param l Referencia al Layout.
|
32 |
*/
|
33 |
public FLayoutDraw(Layout l) {
|
34 |
layout = l; |
35 |
} |
36 |
|
37 |
/**
|
38 |
* M?todo para dibujar el Layout y modificar la matriz de transformaci?n a
|
39 |
* partir del tama?o en pixels que tenga rect y el formato de papel
|
40 |
* seleccionado.
|
41 |
*
|
42 |
* @param g2
|
43 |
* @param imgBase Si es null, est?s imprimiendo. Si no, la usas para el
|
44 |
* c?digo de optimizaci?n.
|
45 |
*
|
46 |
* @throws DriverException
|
47 |
*/
|
48 |
public void drawLayout(Graphics2D g2, BufferedImage imgBase) |
49 |
throws DriverException {
|
50 |
/* PluginServices.getMainFrame().getStatusBar().setMessage("1",
|
51 |
layout.getAtributes().getNameUnit());
|
52 |
*/
|
53 |
layout.setCancelDrawing(false);
|
54 |
|
55 |
double scale = 0; |
56 |
|
57 |
scale = layout.getRect().height / layout.getAtributes().m_sizePaper.getAlto() * 1;
|
58 |
|
59 |
AffineTransform escalado = new AffineTransform(); |
60 |
AffineTransform translacion = new AffineTransform(); |
61 |
translacion.setToTranslation(layout.getRect().getMinX(), |
62 |
layout.getRect().getMinY()); |
63 |
escalado.setToScale(scale, scale); |
64 |
layout.getAT().setToIdentity(); |
65 |
layout.getAT().concatenate(translacion); |
66 |
layout.getAT().concatenate(escalado); |
67 |
layout.getAtributes().setDistanceUnitX(layout.getRect()); |
68 |
layout.getAtributes().setDistanceUnitY(layout.getRect()); |
69 |
|
70 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
71 |
if (layout.getFFrames().get(i) instanceof FFrameView) { |
72 |
FFrameView fframe = (FFrameView) layout.getFFrames().get(i); |
73 |
Rectangle2D rec = fframe.getBoundingBox(layout.getAT());
|
74 |
rec = rec.createIntersection(layout.getVisibleRect()); |
75 |
|
76 |
BufferedImage img = new BufferedImage((int) layout.getWidth(), |
77 |
(int) layout.getHeight(), BufferedImage.TYPE_INT_ARGB); |
78 |
((Graphics2D) img.getGraphics()).clipRect((int) rec.getMinX(), |
79 |
(int) rec.getMinY(), (int) rec.getWidth(), |
80 |
(int) rec.getHeight());
|
81 |
fframe.draw((Graphics2D) img.getGraphics(), layout.getAT(),
|
82 |
layout.getVisibleRect(), imgBase); |
83 |
|
84 |
if (fframe.getFMap() != null) { |
85 |
fframe.setAt((AffineTransform) fframe.getFMap().getViewPort()
|
86 |
.getAffineTransform() |
87 |
.clone()); |
88 |
} |
89 |
|
90 |
fframe.setBufferedImage(img); |
91 |
} |
92 |
} |
93 |
|
94 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
95 |
if (layout.getFFrames().get(i) instanceof FFrameView) { |
96 |
g2.drawImage(((FFrameView) layout.getFFrames().get(i)).getBufferedImage(), |
97 |
0, 0, layout); |
98 |
} else {
|
99 |
((IFFrame) layout.getFFrames().get(i)).draw(g2, layout.getAT(), |
100 |
layout.getVisibleRect(), imgBase); |
101 |
} |
102 |
|
103 |
// Dibuja el s?mbolo de que contiene un tag.
|
104 |
if (((IFFrame) layout.getFFrames().get(i)).getTag() != null) { |
105 |
((IFFrame) layout.getFFrames().get(i)).drawSymbolTag(g2); |
106 |
} |
107 |
} |
108 |
|
109 |
if (!layout.getFFrames().isEmpty()) {
|
110 |
layout.setStatus(Layout.ACTUALIZADO); |
111 |
} else {
|
112 |
layout.setStatus(Layout.DESACTUALIZADO); |
113 |
} |
114 |
} |
115 |
|
116 |
/**
|
117 |
* Dibuja sobre un Graphics2D el rect?ngulo que representa al folio.
|
118 |
*
|
119 |
* @param g Graphics2D
|
120 |
*/
|
121 |
public void drawRectangle(Graphics2D g) { |
122 |
double unidadesX = layout.getAtributes().getUnitInPixelsX();
|
123 |
double unidadesY = layout.getAtributes().getUnitInPixelsY();
|
124 |
|
125 |
if ((unidadesX == 0) && (unidadesY == 0)) { |
126 |
return;
|
127 |
} |
128 |
|
129 |
g.setColor(Color.red);
|
130 |
|
131 |
Rectangle2D.Double rectBig = new Rectangle2D.Double(layout.getRect().x, |
132 |
layout.getRect().y, layout.getRect().width, |
133 |
layout.getRect().height); |
134 |
|
135 |
g.fill3DRect((int) rectBig.x + 10, (int) rectBig.y + 10, |
136 |
(int) rectBig.width, (int) rectBig.height, true); |
137 |
|
138 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
139 |
|
140 |
if (layout.getAtributes().isMargin()) {
|
141 |
r = new Rectangle2D.Double((layout.getRect().x + |
142 |
FLayoutUtilities.fromSheetDistance( |
143 |
layout.getAtributes().m_area[2], layout.getAT())),
|
144 |
(layout.getRect().y + |
145 |
FLayoutUtilities.fromSheetDistance( |
146 |
layout.getAtributes().m_area[0], layout.getAT())),
|
147 |
(layout.getRect().width - |
148 |
FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[2] +
|
149 |
layout.getAtributes().m_area[3], layout.getAT())),
|
150 |
(layout.getRect().height - |
151 |
FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[0] +
|
152 |
layout.getAtributes().m_area[1], layout.getAT())));
|
153 |
} else {
|
154 |
r.setRect(layout.getRect()); |
155 |
} |
156 |
|
157 |
g.setColor(Color.white);
|
158 |
g.fill(layout.getRect()); |
159 |
|
160 |
g.setColor(Color.blue);
|
161 |
g.drawRect((int) layout.getRect().getMinX(),
|
162 |
(int) layout.getRect().getMinY(),
|
163 |
(int) layout.getRect().getWidth(),
|
164 |
(int) layout.getRect().getHeight());
|
165 |
|
166 |
int unidadesMin = 6; |
167 |
|
168 |
if (((unidadesX > unidadesMin) || (unidadesY > unidadesMin)) &&
|
169 |
layout.getIsDrawGrid()) { |
170 |
double ax = r.getMinX();
|
171 |
double ay;
|
172 |
|
173 |
while (ax < (r.getMaxX())) {
|
174 |
ay = (r.getMinY()); |
175 |
|
176 |
while (ay < (r.getMaxY())) {
|
177 |
g.drawLine((int) ax, (int) ay, (int) ax, (int) ay); |
178 |
ay = ay + unidadesY; |
179 |
} |
180 |
|
181 |
ax = ax + unidadesX; |
182 |
} |
183 |
} |
184 |
|
185 |
if (layout.getAtributes().isMargin()) {
|
186 |
g.setColor(Color.black);
|
187 |
|
188 |
g.drawRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
189 |
} |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Dibuja sobre el graphics2d las reglas.
|
194 |
*
|
195 |
* @param g graphics2d sobre el que se dibuja.
|
196 |
* @param color Color de la regla.
|
197 |
*/
|
198 |
public void drawRuler(Graphics2D g, Color color) { |
199 |
if (layout.getRuler()) {
|
200 |
int ini = 10; |
201 |
int w = 30; |
202 |
int wi = 16; |
203 |
|
204 |
g.setColor(new Color(250, 255, 250, 180)); |
205 |
g.fillRect(ini, w, wi, layout.getHeight() - w); |
206 |
g.fillRect(w, ini, layout.getWidth() - w, wi); |
207 |
|
208 |
g.setColor(new Color(100, 155, 150, 180)); |
209 |
g.fillRect(w, ini, (int) layout.getRect().x - w, wi);
|
210 |
g.fillRect((int) layout.getRect().getMaxX(), ini,
|
211 |
(int) layout.getWidth() - (int) layout.getRect().getMaxX(), wi); |
212 |
|
213 |
g.fillRect(ini, w, wi, (int) layout.getRect().y - w);
|
214 |
g.fillRect(ini, (int) layout.getRect().getMaxY(), wi,
|
215 |
(int) layout.getHeight() - (int) layout.getRect().getMaxY()); |
216 |
|
217 |
if (layout.getAtributes().isMargin()) {
|
218 |
g.setColor(new Color(50, 55, 50, 180)); |
219 |
g.fillRect((int) layout.getRect().x, ini,
|
220 |
(int) FLayoutUtilities.fromSheetDistance(
|
221 |
layout.getAtributes().m_area[2], layout.getAT()), wi);
|
222 |
g.fillRect((int) layout.getRect().getMaxX() -
|
223 |
(int) FLayoutUtilities.fromSheetDistance(
|
224 |
layout.getAtributes().m_area[3], layout.getAT()), ini,
|
225 |
(int) FLayoutUtilities.fromSheetDistance(
|
226 |
layout.getAtributes().m_area[3], layout.getAT()), wi);
|
227 |
|
228 |
g.fillRect(ini, (int) layout.getRect().y, wi,
|
229 |
(int) FLayoutUtilities.fromSheetDistance(
|
230 |
layout.getAtributes().m_area[0], layout.getAT()));
|
231 |
g.fillRect(ini, |
232 |
(int) layout.getRect().getMaxY() -
|
233 |
(int) FLayoutUtilities.fromSheetDistance(
|
234 |
layout.getAtributes().m_area[1], layout.getAT()), wi,
|
235 |
(int) FLayoutUtilities.fromSheetDistance(
|
236 |
layout.getAtributes().m_area[1], layout.getAT()));
|
237 |
} |
238 |
|
239 |
g.setColor(color); |
240 |
g.drawLine(w, wi + ini, layout.getWidth(), wi + ini); |
241 |
g.drawLine(w, ini, layout.getWidth(), ini); |
242 |
g.drawLine(ini, w, ini, layout.getHeight()); |
243 |
g.drawLine(wi + ini, w, wi + ini, layout.getHeight()); |
244 |
|
245 |
drawLineY(g, 5, 12, 22, layout.getRect().y, 0); |
246 |
drawLineX(g, 5, 12, 22, layout.getRect().x, 0); |
247 |
|
248 |
if (FLayoutUtilities.fromSheetDistance(1, layout.getAT()) > 15) { |
249 |
drawLineY(g, 1, 12, 22, layout.getRect().y, 0); |
250 |
drawLineX(g, 1, 12, 22, layout.getRect().x, 0); |
251 |
|
252 |
if (FLayoutUtilities.fromSheetDistance(1, layout.getAT()) > 25) { |
253 |
drawLineY(g, 1, 18, 22, layout.getRect().y, 0.5); |
254 |
drawLineY(g, 0.1, 21, 22, layout.getRect().y, 0); |
255 |
drawLineX(g, 1, 18, 22, layout.getRect().x, 0.5); |
256 |
drawLineX(g, 0.1, 21, 22, layout.getRect().x, 0); |
257 |
} |
258 |
} |
259 |
} |
260 |
} |
261 |
|
262 |
/**
|
263 |
* Dibuja sobre el graphics2d las l?neas verticales que representan a las
|
264 |
* unidades de medida.
|
265 |
*
|
266 |
* @param g Graphics2d sobre el que se dibuja.
|
267 |
* @param dist distancia en cent?metros de una l?nea a otra.
|
268 |
* @param init inicio de la l?nea.
|
269 |
* @param end fin de la l?nea.
|
270 |
* @param y rect?ngulo, dentro del cual se dibujan las l?neas.
|
271 |
* @param desp Desplazamiento.
|
272 |
*/
|
273 |
private void drawLineY(Graphics2D g, double dist, int init, int end, |
274 |
double y, double desp) { |
275 |
double distY = FLayoutUtilities.fromSheetDistance(dist, layout.getAT());
|
276 |
double rota = Math.toRadians(90); |
277 |
|
278 |
if (distY > 4) { |
279 |
double despY = FLayoutUtilities.fromSheetDistance(desp,
|
280 |
layout.getAT()); |
281 |
|
282 |
double posUnitY = y + despY;
|
283 |
double posUnitYNeg = posUnitY;
|
284 |
int num = 0; |
285 |
double iniY = 40; |
286 |
Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
287 |
layout.getWidth(), layout.getHeight()), layout.getAT()); |
288 |
|
289 |
while (posUnitY < (pfin.y - 5)) { |
290 |
posUnitYNeg -= distY; |
291 |
|
292 |
if (distY > 16) { |
293 |
if (init == 12) { |
294 |
if (posUnitY > iniY) {
|
295 |
g.rotate(-rota, 20, posUnitY - 12); |
296 |
g.drawString(String.valueOf(num), (int) 10, |
297 |
(int) posUnitY - 12); |
298 |
g.rotate(rota, 20, posUnitY - 12); |
299 |
} |
300 |
|
301 |
if (dist == 5) { |
302 |
num = num + 5;
|
303 |
} else {
|
304 |
num++; |
305 |
} |
306 |
|
307 |
if (posUnitYNeg > iniY) {
|
308 |
g.rotate(-rota, 20, posUnitYNeg - 12); |
309 |
g.drawString(String.valueOf(-num), (int) 10, |
310 |
(int) posUnitYNeg - 12); |
311 |
g.rotate(rota, 20, posUnitYNeg - 12); |
312 |
} |
313 |
} |
314 |
} |
315 |
|
316 |
if (posUnitY > iniY) {
|
317 |
g.drawLine((int) 2 + init, (int) posUnitY, (int) 2 + end, |
318 |
(int) posUnitY);
|
319 |
} |
320 |
|
321 |
if (posUnitYNeg > iniY) {
|
322 |
g.drawLine((int) 2 + init, (int) posUnitYNeg, |
323 |
(int) 2 + end, (int) posUnitYNeg); |
324 |
} |
325 |
|
326 |
posUnitY += distY; |
327 |
} |
328 |
} |
329 |
} |
330 |
|
331 |
/**
|
332 |
* Dibuja sobre el graphics2d las l?neas horizontales que representan a las
|
333 |
* unidades de medida.
|
334 |
*
|
335 |
* @param g Graphics2d sobre el que se dibuja.
|
336 |
* @param dist distancia en cent?metros de una l?nea a otra.
|
337 |
* @param init inicio de la l?nea.
|
338 |
* @param end fin de la l?nea.
|
339 |
* @param x rect?ngulo, dentro del cual se dibujan las l?neas.
|
340 |
* @param desp Desplazamiento.
|
341 |
*/
|
342 |
private void drawLineX(Graphics2D g, double dist, int init, int end, |
343 |
double x, double desp) { |
344 |
double distX = FLayoutUtilities.fromSheetDistance(dist, layout.getAT());
|
345 |
|
346 |
if (distX > 4) { |
347 |
double despX = FLayoutUtilities.fromSheetDistance(desp,
|
348 |
layout.getAT()); |
349 |
double posUnitX = x + despX;
|
350 |
double posUnitXNeg = posUnitX;
|
351 |
int num = 0; |
352 |
double iniX = 40; |
353 |
Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
354 |
layout.getWidth(), layout.getHeight()), layout.getAT()); |
355 |
|
356 |
while (posUnitX < (pfin.x - 5)) { |
357 |
posUnitXNeg -= distX; |
358 |
|
359 |
if (init == 12) { |
360 |
if (distX > 16) { |
361 |
if (posUnitX > iniX) {
|
362 |
g.drawString(String.valueOf(num),
|
363 |
(int) posUnitX + 3, (int) 20); |
364 |
} |
365 |
|
366 |
if (dist == 5) { |
367 |
num = num + 5;
|
368 |
} else {
|
369 |
num++; |
370 |
} |
371 |
|
372 |
if (posUnitXNeg > iniX) {
|
373 |
g.drawString(String.valueOf(-num),
|
374 |
(int) posUnitXNeg + 3, (int) 20); |
375 |
} |
376 |
} |
377 |
} |
378 |
|
379 |
if (posUnitX > iniX) {
|
380 |
g.drawLine((int) posUnitX, (int) 2 + init, (int) posUnitX, |
381 |
(int) 2 + end); |
382 |
} |
383 |
|
384 |
if (posUnitXNeg > iniX) {
|
385 |
g.drawLine((int) posUnitXNeg, (int) 2 + init, |
386 |
(int) posUnitXNeg, (int) 2 + end); |
387 |
} |
388 |
|
389 |
posUnitX += distX; |
390 |
} |
391 |
} |
392 |
} |
393 |
|
394 |
/**
|
395 |
* Dibuja los handlers sobre los fframes que esten seleccionados.
|
396 |
*
|
397 |
* @param g Graphics sobre el que se dibuja.
|
398 |
* @param color Color de los Handlers.
|
399 |
*/
|
400 |
public void drawHandlers(Graphics2D g, Color color) { |
401 |
g.setColor(color); |
402 |
|
403 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
404 |
IFFrame fframe = (IFFrame) layout.getFFrames().get(i); |
405 |
|
406 |
if (fframe.getSelected() != FFrame.NOSELECT) {
|
407 |
fframe.drawHandlers((Graphics2D) g);
|
408 |
} |
409 |
} |
410 |
} |
411 |
} |