root / branches / gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutDraw.java @ 1822
History | View | Annotate | Download (15.1 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-sep-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.DriverException; |
48 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
49 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
50 |
|
51 |
import java.awt.Color; |
52 |
import java.awt.Graphics2D; |
53 |
import java.awt.geom.AffineTransform; |
54 |
import java.awt.geom.Point2D; |
55 |
import java.awt.geom.Rectangle2D; |
56 |
import java.awt.image.BufferedImage; |
57 |
|
58 |
|
59 |
/**
|
60 |
* Clase que implementa los m?todos del Layout que dibujan sobre el Graphics.
|
61 |
*
|
62 |
* @author Vicente Caballero Navarro
|
63 |
*/
|
64 |
public class FLayoutDraw { |
65 |
private Layout layout;
|
66 |
|
67 |
/**
|
68 |
* Crea un nuevo FLayoutDraw.
|
69 |
*
|
70 |
* @param l Referencia al Layout.
|
71 |
*/
|
72 |
public FLayoutDraw(Layout l) {
|
73 |
layout = l; |
74 |
} |
75 |
|
76 |
/**
|
77 |
* M?todo para dibujar el Layout y modificar la matriz de transformaci?n a
|
78 |
* partir del tama?o en pixels que tenga rect y el formato de papel
|
79 |
* seleccionado.
|
80 |
*
|
81 |
* @param g2
|
82 |
* @param imgBase Si es null, est?s imprimiendo. Si no, la usas para el
|
83 |
* c?digo de optimizaci?n.
|
84 |
*
|
85 |
* @throws DriverException
|
86 |
*/
|
87 |
public void drawLayout(Graphics2D g2, BufferedImage imgBase) |
88 |
throws DriverException {
|
89 |
/* PluginServices.getMainFrame().getStatusBar().setMessage("1",
|
90 |
layout.getAtributes().getNameUnit());
|
91 |
*/
|
92 |
layout.setCancelDrawing(false);
|
93 |
|
94 |
double scale = 0; |
95 |
|
96 |
scale = layout.getRect().height / layout.getAtributes().m_sizePaper.getAlto() * 1;
|
97 |
|
98 |
AffineTransform escalado = new AffineTransform(); |
99 |
AffineTransform translacion = new AffineTransform(); |
100 |
translacion.setToTranslation(layout.getRect().getMinX(), |
101 |
layout.getRect().getMinY()); |
102 |
escalado.setToScale(scale, scale); |
103 |
layout.getAT().setToIdentity(); |
104 |
layout.getAT().concatenate(translacion); |
105 |
layout.getAT().concatenate(escalado); |
106 |
layout.getAtributes().setDistanceUnitX(layout.getRect()); |
107 |
layout.getAtributes().setDistanceUnitY(layout.getRect()); |
108 |
|
109 |
IFFrame[] frames = layout.getFFrames1();
|
110 |
|
111 |
for (int i = 0; i < frames.length; i++) { |
112 |
if (frames[i] instanceof FFrameView) { |
113 |
FFrameView fframe = (FFrameView) frames[i]; //layout.getFFrames().get(i);
|
114 |
Rectangle2D rec = fframe.getBoundingBox(layout.getAT());
|
115 |
rec = rec.createIntersection(layout.getVisibleRect()); |
116 |
|
117 |
BufferedImage img = new BufferedImage((int) layout.getWidth(), |
118 |
(int) layout.getHeight(), BufferedImage.TYPE_INT_ARGB); |
119 |
((Graphics2D) img.getGraphics()).clipRect((int) rec.getMinX(), |
120 |
(int) rec.getMinY(), (int) rec.getWidth(), |
121 |
(int) rec.getHeight());
|
122 |
fframe.draw((Graphics2D) img.getGraphics(), layout.getAT(),
|
123 |
layout.getVisibleRect(), imgBase); |
124 |
|
125 |
if (fframe.getFMap() != null) { |
126 |
fframe.setAt((AffineTransform) fframe.getFMap().getViewPort()
|
127 |
.getAffineTransform() |
128 |
.clone()); |
129 |
} |
130 |
|
131 |
fframe.setBufferedImage(img); |
132 |
} |
133 |
} |
134 |
|
135 |
for (int i = 0; i < frames.length; i++) { |
136 |
if (frames[i] instanceof FFrameView) { |
137 |
g2.drawImage(((FFrameView) frames[i]).getBufferedImage(), 0, 0, |
138 |
layout); |
139 |
} else {
|
140 |
frames[i].draw(g2, layout.getAT(), layout.getVisibleRect(), |
141 |
imgBase); |
142 |
} |
143 |
|
144 |
// Dibuja el s?mbolo de que contiene un tag.
|
145 |
if (frames[i].getTag() != null) { |
146 |
frames[i].drawSymbolTag(g2); |
147 |
} |
148 |
} |
149 |
|
150 |
///layout.getFFrameGraphics().draw(g2, layout.getAT(),
|
151 |
/// layout.getVisibleRect(), imgBase);
|
152 |
if (!layout.getAllFFrames().isEmpty()) {
|
153 |
layout.setStatus(Layout.ACTUALIZADO); |
154 |
} else {
|
155 |
layout.setStatus(Layout.DESACTUALIZADO); |
156 |
} |
157 |
} |
158 |
|
159 |
/**
|
160 |
* Dibuja sobre un Graphics2D el rect?ngulo que representa al folio.
|
161 |
*
|
162 |
* @param g Graphics2D
|
163 |
*/
|
164 |
public void drawRectangle(Graphics2D g) { |
165 |
double unidadesX = layout.getAtributes().getUnitInPixelsX();
|
166 |
double unidadesY = layout.getAtributes().getUnitInPixelsY();
|
167 |
|
168 |
if ((unidadesX == 0) && (unidadesY == 0)) { |
169 |
return;
|
170 |
} |
171 |
|
172 |
g.setColor(Color.red);
|
173 |
|
174 |
Rectangle2D.Double rectBig = new Rectangle2D.Double(layout.getRect().x, |
175 |
layout.getRect().y, layout.getRect().width, |
176 |
layout.getRect().height); |
177 |
|
178 |
g.fill3DRect((int) rectBig.x + 10, (int) rectBig.y + 10, |
179 |
(int) rectBig.width, (int) rectBig.height, true); |
180 |
|
181 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
182 |
|
183 |
if (layout.getAtributes().isMargin()) {
|
184 |
r = new Rectangle2D.Double((layout.getRect().x + |
185 |
FLayoutUtilities.fromSheetDistance( |
186 |
layout.getAtributes().m_area[2], layout.getAT())),
|
187 |
(layout.getRect().y + |
188 |
FLayoutUtilities.fromSheetDistance( |
189 |
layout.getAtributes().m_area[0], layout.getAT())),
|
190 |
(layout.getRect().width - |
191 |
FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[2] +
|
192 |
layout.getAtributes().m_area[3], layout.getAT())),
|
193 |
(layout.getRect().height - |
194 |
FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[0] +
|
195 |
layout.getAtributes().m_area[1], layout.getAT())));
|
196 |
} else {
|
197 |
r.setRect(layout.getRect()); |
198 |
} |
199 |
|
200 |
g.setColor(Color.white);
|
201 |
g.fill(layout.getRect()); |
202 |
|
203 |
g.setColor(Color.blue);
|
204 |
g.drawRect((int) layout.getRect().getMinX(),
|
205 |
(int) layout.getRect().getMinY(),
|
206 |
(int) layout.getRect().getWidth(),
|
207 |
(int) layout.getRect().getHeight());
|
208 |
|
209 |
if (layout.getAtributes().isMargin()) {
|
210 |
g.setColor(Color.black);
|
211 |
|
212 |
g.drawRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
213 |
} |
214 |
} |
215 |
|
216 |
/* public void drawGrid(Graphics2D g)
|
217 |
{
|
218 |
int unidadesMin = 6;
|
219 |
double unidadesX = layout.getAtributes().getUnitInPixelsX();
|
220 |
double unidadesY = layout.getAtributes().getUnitInPixelsY();
|
221 |
if ((unidadesX == 0) && (unidadesY == 0)) {
|
222 |
return;
|
223 |
}
|
224 |
Rectangle2D.Double rectBig = new Rectangle2D.Double(layout.getRect().x,
|
225 |
layout.getRect().y, layout.getRect().width,
|
226 |
layout.getRect().height);
|
227 |
Rectangle2D.Double r = new Rectangle2D.Double();
|
228 |
if (layout.getAtributes().isMargin()) {
|
229 |
r = new Rectangle2D.Double((layout.getRect().x +
|
230 |
FLayoutUtilities.fromSheetDistance(
|
231 |
layout.getAtributes().m_area[2], layout.getAT())),
|
232 |
(layout.getRect().y +
|
233 |
FLayoutUtilities.fromSheetDistance(
|
234 |
layout.getAtributes().m_area[0], layout.getAT())),
|
235 |
(layout.getRect().width -
|
236 |
FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[2] +
|
237 |
layout.getAtributes().m_area[3], layout.getAT())),
|
238 |
(layout.getRect().height -
|
239 |
FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[0] +
|
240 |
layout.getAtributes().m_area[1], layout.getAT())));
|
241 |
} else {
|
242 |
r.setRect(layout.getRect());
|
243 |
}
|
244 |
g.setColor(Color.BLUE);
|
245 |
if (((unidadesX > unidadesMin) || (unidadesY > unidadesMin)) &&
|
246 |
layout.getIsDrawGrid()) {
|
247 |
double ax = r.getMinX();
|
248 |
double ay;
|
249 |
while (ax < (r.getMaxX())) {
|
250 |
ay = (r.getMinY());
|
251 |
while (ay < (r.getMaxY())) {
|
252 |
g.drawLine((int) ax, (int) ay, (int) ax, (int) ay);
|
253 |
ay = ay + unidadesY;
|
254 |
}
|
255 |
ax = ax + unidadesX;
|
256 |
}
|
257 |
}
|
258 |
}
|
259 |
*/
|
260 |
|
261 |
/**
|
262 |
* Dibuja sobre el graphics2d las reglas.
|
263 |
*
|
264 |
* @param g graphics2d sobre el que se dibuja.
|
265 |
* @param color Color de la regla.
|
266 |
*/
|
267 |
public void drawRuler(Graphics2D g, Color color) { |
268 |
if (layout.getRuler()) {
|
269 |
int ini = 10; |
270 |
int w = 30; |
271 |
int wi = 16; |
272 |
|
273 |
g.setColor(new Color(250, 255, 250, 180)); |
274 |
g.fillRect(ini, w, wi, layout.getHeight() - w); |
275 |
g.fillRect(w, ini, layout.getWidth() - w, wi); |
276 |
|
277 |
g.setColor(new Color(100, 155, 150, 180)); |
278 |
g.fillRect(w, ini, (int) layout.getRect().x - w, wi);
|
279 |
g.fillRect((int) layout.getRect().getMaxX(), ini,
|
280 |
(int) layout.getWidth() - (int) layout.getRect().getMaxX(), wi); |
281 |
|
282 |
g.fillRect(ini, w, wi, (int) layout.getRect().y - w);
|
283 |
g.fillRect(ini, (int) layout.getRect().getMaxY(), wi,
|
284 |
(int) layout.getHeight() - (int) layout.getRect().getMaxY()); |
285 |
|
286 |
if (layout.getAtributes().isMargin()) {
|
287 |
g.setColor(new Color(50, 55, 50, 180)); |
288 |
g.fillRect((int) layout.getRect().x, ini,
|
289 |
(int) FLayoutUtilities.fromSheetDistance(
|
290 |
layout.getAtributes().m_area[2], layout.getAT()), wi);
|
291 |
g.fillRect((int) layout.getRect().getMaxX() -
|
292 |
(int) FLayoutUtilities.fromSheetDistance(
|
293 |
layout.getAtributes().m_area[3], layout.getAT()), ini,
|
294 |
(int) FLayoutUtilities.fromSheetDistance(
|
295 |
layout.getAtributes().m_area[3], layout.getAT()), wi);
|
296 |
|
297 |
g.fillRect(ini, (int) layout.getRect().y, wi,
|
298 |
(int) FLayoutUtilities.fromSheetDistance(
|
299 |
layout.getAtributes().m_area[0], layout.getAT()));
|
300 |
g.fillRect(ini, |
301 |
(int) layout.getRect().getMaxY() -
|
302 |
(int) FLayoutUtilities.fromSheetDistance(
|
303 |
layout.getAtributes().m_area[1], layout.getAT()), wi,
|
304 |
(int) FLayoutUtilities.fromSheetDistance(
|
305 |
layout.getAtributes().m_area[1], layout.getAT()));
|
306 |
} |
307 |
|
308 |
g.setColor(color); |
309 |
g.drawLine(w, wi + ini, layout.getWidth(), wi + ini); |
310 |
g.drawLine(w, ini, layout.getWidth(), ini); |
311 |
g.drawLine(ini, w, ini, layout.getHeight()); |
312 |
g.drawLine(wi + ini, w, wi + ini, layout.getHeight()); |
313 |
|
314 |
drawLineY(g, 5, 12, 22, layout.getRect().y, 0); |
315 |
drawLineX(g, 5, 12, 22, layout.getRect().x, 0); |
316 |
|
317 |
if (FLayoutUtilities.fromSheetDistance(1, layout.getAT()) > 15) { |
318 |
drawLineY(g, 1, 12, 22, layout.getRect().y, 0); |
319 |
drawLineX(g, 1, 12, 22, layout.getRect().x, 0); |
320 |
|
321 |
if (FLayoutUtilities.fromSheetDistance(1, layout.getAT()) > 25) { |
322 |
drawLineY(g, 1, 18, 22, layout.getRect().y, 0.5); |
323 |
drawLineY(g, 0.1, 21, 22, layout.getRect().y, 0); |
324 |
drawLineX(g, 1, 18, 22, layout.getRect().x, 0.5); |
325 |
drawLineX(g, 0.1, 21, 22, layout.getRect().x, 0); |
326 |
} |
327 |
} |
328 |
} |
329 |
} |
330 |
|
331 |
/**
|
332 |
* Dibuja sobre el graphics2d las l?neas verticales 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 y rect?ngulo, dentro del cual se dibujan las l?neas.
|
340 |
* @param desp Desplazamiento.
|
341 |
*/
|
342 |
private void drawLineY(Graphics2D g, double dist, int init, int end, |
343 |
double y, double desp) { |
344 |
double distY = FLayoutUtilities.fromSheetDistance(dist, layout.getAT());
|
345 |
double rota = Math.toRadians(90); |
346 |
|
347 |
if (distY > 4) { |
348 |
double despY = FLayoutUtilities.fromSheetDistance(desp,
|
349 |
layout.getAT()); |
350 |
|
351 |
double posUnitY = y + despY;
|
352 |
double posUnitYNeg = posUnitY;
|
353 |
int num = 0; |
354 |
double iniY = 40; |
355 |
Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
356 |
layout.getWidth(), layout.getHeight()), layout.getAT()); |
357 |
|
358 |
while (posUnitY < (pfin.y - 5)) { |
359 |
posUnitYNeg -= distY; |
360 |
|
361 |
if (distY > 16) { |
362 |
if (init == 12) { |
363 |
if (posUnitY > iniY) {
|
364 |
g.rotate(-rota, 20, posUnitY - 12); |
365 |
g.drawString(String.valueOf(num), (int) 10, |
366 |
(int) posUnitY - 12); |
367 |
g.rotate(rota, 20, posUnitY - 12); |
368 |
} |
369 |
|
370 |
if (dist == 5) { |
371 |
num = num + 5;
|
372 |
} else {
|
373 |
num++; |
374 |
} |
375 |
|
376 |
if (posUnitYNeg > iniY) {
|
377 |
g.rotate(-rota, 20, posUnitYNeg - 12); |
378 |
g.drawString(String.valueOf(-num), (int) 10, |
379 |
(int) posUnitYNeg - 12); |
380 |
g.rotate(rota, 20, posUnitYNeg - 12); |
381 |
} |
382 |
} |
383 |
} |
384 |
|
385 |
if (posUnitY > iniY) {
|
386 |
g.drawLine((int) 2 + init, (int) posUnitY, (int) 2 + end, |
387 |
(int) posUnitY);
|
388 |
} |
389 |
|
390 |
if (posUnitYNeg > iniY) {
|
391 |
g.drawLine((int) 2 + init, (int) posUnitYNeg, |
392 |
(int) 2 + end, (int) posUnitYNeg); |
393 |
} |
394 |
|
395 |
posUnitY += distY; |
396 |
} |
397 |
} |
398 |
} |
399 |
|
400 |
/**
|
401 |
* Dibuja sobre el graphics2d las l?neas horizontales que representan a las
|
402 |
* unidades de medida.
|
403 |
*
|
404 |
* @param g Graphics2d sobre el que se dibuja.
|
405 |
* @param dist distancia en cent?metros de una l?nea a otra.
|
406 |
* @param init inicio de la l?nea.
|
407 |
* @param end fin de la l?nea.
|
408 |
* @param x rect?ngulo, dentro del cual se dibujan las l?neas.
|
409 |
* @param desp Desplazamiento.
|
410 |
*/
|
411 |
private void drawLineX(Graphics2D g, double dist, int init, int end, |
412 |
double x, double desp) { |
413 |
double distX = FLayoutUtilities.fromSheetDistance(dist, layout.getAT());
|
414 |
|
415 |
if (distX > 4) { |
416 |
double despX = FLayoutUtilities.fromSheetDistance(desp,
|
417 |
layout.getAT()); |
418 |
double posUnitX = x + despX;
|
419 |
double posUnitXNeg = posUnitX;
|
420 |
int num = 0; |
421 |
double iniX = 40; |
422 |
Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
423 |
layout.getWidth(), layout.getHeight()), layout.getAT()); |
424 |
|
425 |
while (posUnitX < (pfin.x - 5)) { |
426 |
posUnitXNeg -= distX; |
427 |
|
428 |
if (init == 12) { |
429 |
if (distX > 16) { |
430 |
if (posUnitX > iniX) {
|
431 |
g.drawString(String.valueOf(num),
|
432 |
(int) posUnitX + 3, (int) 20); |
433 |
} |
434 |
|
435 |
if (dist == 5) { |
436 |
num = num + 5;
|
437 |
} else {
|
438 |
num++; |
439 |
} |
440 |
|
441 |
if (posUnitXNeg > iniX) {
|
442 |
g.drawString(String.valueOf(-num),
|
443 |
(int) posUnitXNeg + 3, (int) 20); |
444 |
} |
445 |
} |
446 |
} |
447 |
|
448 |
if (posUnitX > iniX) {
|
449 |
g.drawLine((int) posUnitX, (int) 2 + init, (int) posUnitX, |
450 |
(int) 2 + end); |
451 |
} |
452 |
|
453 |
if (posUnitXNeg > iniX) {
|
454 |
g.drawLine((int) posUnitXNeg, (int) 2 + init, |
455 |
(int) posUnitXNeg, (int) 2 + end); |
456 |
} |
457 |
|
458 |
posUnitX += distX; |
459 |
} |
460 |
} |
461 |
} |
462 |
|
463 |
/**
|
464 |
* Dibuja los handlers sobre los fframes que esten seleccionados.
|
465 |
*
|
466 |
* @param g Graphics sobre el que se dibuja.
|
467 |
* @param color Color de los Handlers.
|
468 |
*/
|
469 |
public void drawHandlers(Graphics2D g, Color color) { |
470 |
g.setColor(color); |
471 |
|
472 |
IFFrame[] frames = layout.getFFrames1();
|
473 |
|
474 |
for (int i = 0; i < frames.length; i++) { |
475 |
IFFrame fframe = frames[i]; //(IFFrame) layout.getFFrames().get(i);
|
476 |
|
477 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
478 |
fframe.drawHandlers((Graphics2D) g);
|
479 |
} |
480 |
} |
481 |
} |
482 |
} |