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