svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutDraw.java @ 5222
History | View | Annotate | Download (15.2 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 27-sep-2004
|
||
3 | *
|
||
4 | */
|
||
5 | 1103 | fjp | /* 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 | 312 | fernando | package com.iver.cit.gvsig.gui.layout; |
46 | |||
47 | import java.awt.Color; |
||
48 | 2342 | vcaballero | import java.awt.Component; |
49 | 312 | fernando | import java.awt.Graphics2D; |
50 | import java.awt.geom.AffineTransform; |
||
51 | import java.awt.geom.Point2D; |
||
52 | import java.awt.geom.Rectangle2D; |
||
53 | import java.awt.image.BufferedImage; |
||
54 | 2342 | vcaballero | import java.awt.print.PageFormat; |
55 | import java.awt.print.PrinterException; |
||
56 | import java.io.File; |
||
57 | import java.io.FileOutputStream; |
||
58 | import java.io.IOException; |
||
59 | 312 | fernando | |
60 | 2342 | vcaballero | import javax.swing.JOptionPane; |
61 | 312 | fernando | |
62 | 3106 | caballero | import com.iver.andami.PluginServices; |
63 | import com.iver.cit.gvsig.Print; |
||
64 | import com.iver.cit.gvsig.fmap.DriverException; |
||
65 | import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
||
66 | import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
||
67 | import com.lowagie.text.Document; |
||
68 | import com.lowagie.text.DocumentException; |
||
69 | import com.lowagie.text.pdf.PdfContentByte; |
||
70 | import com.lowagie.text.pdf.PdfWriter; |
||
71 | 2342 | vcaballero | |
72 | 3106 | caballero | |
73 | 312 | fernando | /**
|
74 | * Clase que implementa los m?todos del Layout que dibujan sobre el Graphics.
|
||
75 | *
|
||
76 | * @author Vicente Caballero Navarro
|
||
77 | */
|
||
78 | public class FLayoutDraw { |
||
79 | 1074 | vcaballero | private Layout layout;
|
80 | /**
|
||
81 | * Crea un nuevo FLayoutDraw.
|
||
82 | *
|
||
83 | * @param l Referencia al Layout.
|
||
84 | */
|
||
85 | public FLayoutDraw(Layout l) {
|
||
86 | layout = l; |
||
87 | } |
||
88 | 312 | fernando | |
89 | 4209 | jaume | /**
|
90 | * M?todo para dibujar el Layout y modificar la matriz de transformaci?n a
|
||
91 | * partir del tama?o en pixels que tenga rect y el formato de papel
|
||
92 | * seleccionado.
|
||
93 | *
|
||
94 | * @param g2
|
||
95 | * @param imgBase Si es null, est?s imprimiendo. Si no, la usas para el
|
||
96 | * c?digo de optimizaci?n.
|
||
97 | *
|
||
98 | * @throws DriverException
|
||
99 | */
|
||
100 | public void drawLayout(Graphics2D g2, BufferedImage imgBase) |
||
101 | throws DriverException {
|
||
102 | layout.setCancelDrawing(false);
|
||
103 | double scale = 0; |
||
104 | scale = layout.getRect().height / layout.getAtributes().m_sizePaper.getAlto() * 1;
|
||
105 | AffineTransform escalado = new AffineTransform(); |
||
106 | AffineTransform translacion = new AffineTransform(); |
||
107 | translacion.setToTranslation(layout.getRect().getMinX(), |
||
108 | layout.getRect().getMinY()); |
||
109 | escalado.setToScale(scale, scale); |
||
110 | layout.getAT().setToIdentity(); |
||
111 | layout.getAT().concatenate(translacion); |
||
112 | layout.getAT().concatenate(escalado); |
||
113 | layout.getAtributes().setDistanceUnitX(layout.getRect()); |
||
114 | layout.getAtributes().setDistanceUnitY(layout.getRect()); |
||
115 | for (int i = 0; i < layout.getFFrames().size(); i++) { |
||
116 | IFFrame f = (IFFrame) layout.getFFrames().get(i); |
||
117 | f.draw(g2, layout.getAT(), layout.getVisibleRect(), |
||
118 | imgBase); |
||
119 | // Dibuja el s?mbolo de que contiene un tag.
|
||
120 | if ((f.getTag() != null) && (layout.isModeDebug())) { |
||
121 | f.drawSymbolTag(g2); |
||
122 | } |
||
123 | } |
||
124 | 312 | fernando | |
125 | 4209 | jaume | if (!(layout.getFFrames().size()==0)) { |
126 | layout.setStatus(Layout.ACTUALIZADO); |
||
127 | } else {
|
||
128 | layout.setStatus(Layout.DESACTUALIZADO); |
||
129 | } |
||
130 | } |
||
131 | 312 | fernando | |
132 | 1074 | vcaballero | /**
|
133 | * Dibuja sobre un Graphics2D el rect?ngulo que representa al folio.
|
||
134 | *
|
||
135 | * @param g Graphics2D
|
||
136 | */
|
||
137 | public void drawRectangle(Graphics2D g) { |
||
138 | double unidadesX = layout.getAtributes().getUnitInPixelsX();
|
||
139 | double unidadesY = layout.getAtributes().getUnitInPixelsY();
|
||
140 | 312 | fernando | |
141 | 1074 | vcaballero | if ((unidadesX == 0) && (unidadesY == 0)) { |
142 | return;
|
||
143 | } |
||
144 | 312 | fernando | |
145 | 1074 | vcaballero | g.setColor(Color.red);
|
146 | 312 | fernando | |
147 | 1074 | vcaballero | Rectangle2D.Double rectBig = new Rectangle2D.Double(layout.getRect().x, |
148 | layout.getRect().y, layout.getRect().width, |
||
149 | layout.getRect().height); |
||
150 | 312 | fernando | |
151 | 1074 | vcaballero | g.fill3DRect((int) rectBig.x + 10, (int) rectBig.y + 10, |
152 | (int) rectBig.width, (int) rectBig.height, true); |
||
153 | 312 | fernando | |
154 | 1074 | vcaballero | Rectangle2D.Double r = new Rectangle2D.Double(); |
155 | 312 | fernando | |
156 | 1074 | vcaballero | if (layout.getAtributes().isMargin()) {
|
157 | r = new Rectangle2D.Double((layout.getRect().x + |
||
158 | FLayoutUtilities.fromSheetDistance( |
||
159 | layout.getAtributes().m_area[2], layout.getAT())),
|
||
160 | (layout.getRect().y + |
||
161 | FLayoutUtilities.fromSheetDistance( |
||
162 | layout.getAtributes().m_area[0], layout.getAT())),
|
||
163 | (layout.getRect().width - |
||
164 | FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[2] +
|
||
165 | layout.getAtributes().m_area[3], layout.getAT())),
|
||
166 | (layout.getRect().height - |
||
167 | FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[0] +
|
||
168 | layout.getAtributes().m_area[1], layout.getAT())));
|
||
169 | } else {
|
||
170 | r.setRect(layout.getRect()); |
||
171 | } |
||
172 | 312 | fernando | |
173 | 1074 | vcaballero | g.setColor(Color.white);
|
174 | g.fill(layout.getRect()); |
||
175 | 312 | fernando | |
176 | 1074 | vcaballero | g.setColor(Color.blue);
|
177 | g.drawRect((int) layout.getRect().getMinX(),
|
||
178 | (int) layout.getRect().getMinY(),
|
||
179 | (int) layout.getRect().getWidth(),
|
||
180 | (int) layout.getRect().getHeight());
|
||
181 | 312 | fernando | |
182 | 1281 | fjp | if (layout.getAtributes().isMargin()) {
|
183 | g.setColor(Color.black);
|
||
184 | |||
185 | g.drawRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
||
186 | } |
||
187 | } |
||
188 | |||
189 | public void drawGrid(Graphics2D g) |
||
190 | { |
||
191 | 1074 | vcaballero | int unidadesMin = 6; |
192 | 1281 | fjp | double unidadesX = layout.getAtributes().getUnitInPixelsX();
|
193 | double unidadesY = layout.getAtributes().getUnitInPixelsY();
|
||
194 | 312 | fernando | |
195 | 1281 | fjp | if ((unidadesX == 0) && (unidadesY == 0)) { |
196 | return;
|
||
197 | } |
||
198 | Rectangle2D.Double r = new Rectangle2D.Double(); |
||
199 | |||
200 | if (layout.getAtributes().isMargin()) {
|
||
201 | r = new Rectangle2D.Double((layout.getRect().x + |
||
202 | FLayoutUtilities.fromSheetDistance( |
||
203 | layout.getAtributes().m_area[2], layout.getAT())),
|
||
204 | (layout.getRect().y + |
||
205 | FLayoutUtilities.fromSheetDistance( |
||
206 | layout.getAtributes().m_area[0], layout.getAT())),
|
||
207 | (layout.getRect().width - |
||
208 | FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[2] +
|
||
209 | layout.getAtributes().m_area[3], layout.getAT())),
|
||
210 | (layout.getRect().height - |
||
211 | FLayoutUtilities.fromSheetDistance(layout.getAtributes().m_area[0] +
|
||
212 | layout.getAtributes().m_area[1], layout.getAT())));
|
||
213 | } else {
|
||
214 | r.setRect(layout.getRect()); |
||
215 | } |
||
216 | |||
217 | g.setColor(Color.BLUE);
|
||
218 | 1074 | vcaballero | if (((unidadesX > unidadesMin) || (unidadesY > unidadesMin)) &&
|
219 | layout.getIsDrawGrid()) { |
||
220 | double ax = r.getMinX();
|
||
221 | double ay;
|
||
222 | 312 | fernando | |
223 | 1074 | vcaballero | while (ax < (r.getMaxX())) {
|
224 | ay = (r.getMinY()); |
||
225 | 312 | fernando | |
226 | 1074 | vcaballero | while (ay < (r.getMaxY())) {
|
227 | g.drawLine((int) ax, (int) ay, (int) ax, (int) ay); |
||
228 | ay = ay + unidadesY; |
||
229 | } |
||
230 | 312 | fernando | |
231 | 1074 | vcaballero | ax = ax + unidadesX; |
232 | } |
||
233 | } |
||
234 | 312 | fernando | |
235 | 1074 | vcaballero | } |
236 | /**
|
||
237 | * Dibuja sobre el graphics2d las reglas.
|
||
238 | *
|
||
239 | * @param g graphics2d sobre el que se dibuja.
|
||
240 | * @param color Color de la regla.
|
||
241 | */
|
||
242 | public void drawRuler(Graphics2D g, Color color) { |
||
243 | if (layout.getRuler()) {
|
||
244 | int ini = 10; |
||
245 | int w = 30; |
||
246 | int wi = 16; |
||
247 | 312 | fernando | |
248 | 1074 | vcaballero | g.setColor(new Color(250, 255, 250, 180)); |
249 | g.fillRect(ini, w, wi, layout.getHeight() - w); |
||
250 | g.fillRect(w, ini, layout.getWidth() - w, wi); |
||
251 | 312 | fernando | |
252 | 1074 | vcaballero | g.setColor(new Color(100, 155, 150, 180)); |
253 | g.fillRect(w, ini, (int) layout.getRect().x - w, wi);
|
||
254 | g.fillRect((int) layout.getRect().getMaxX(), ini,
|
||
255 | (int) layout.getWidth() - (int) layout.getRect().getMaxX(), wi); |
||
256 | 312 | fernando | |
257 | 1074 | vcaballero | g.fillRect(ini, w, wi, (int) layout.getRect().y - w);
|
258 | g.fillRect(ini, (int) layout.getRect().getMaxY(), wi,
|
||
259 | (int) layout.getHeight() - (int) layout.getRect().getMaxY()); |
||
260 | 312 | fernando | |
261 | 1074 | vcaballero | if (layout.getAtributes().isMargin()) {
|
262 | g.setColor(new Color(50, 55, 50, 180)); |
||
263 | g.fillRect((int) layout.getRect().x, ini,
|
||
264 | (int) FLayoutUtilities.fromSheetDistance(
|
||
265 | layout.getAtributes().m_area[2], layout.getAT()), wi);
|
||
266 | g.fillRect((int) layout.getRect().getMaxX() -
|
||
267 | (int) FLayoutUtilities.fromSheetDistance(
|
||
268 | layout.getAtributes().m_area[3], layout.getAT()), ini,
|
||
269 | (int) FLayoutUtilities.fromSheetDistance(
|
||
270 | layout.getAtributes().m_area[3], layout.getAT()), wi);
|
||
271 | 312 | fernando | |
272 | 1074 | vcaballero | g.fillRect(ini, (int) layout.getRect().y, wi,
|
273 | (int) FLayoutUtilities.fromSheetDistance(
|
||
274 | layout.getAtributes().m_area[0], layout.getAT()));
|
||
275 | g.fillRect(ini, |
||
276 | (int) layout.getRect().getMaxY() -
|
||
277 | (int) FLayoutUtilities.fromSheetDistance(
|
||
278 | layout.getAtributes().m_area[1], layout.getAT()), wi,
|
||
279 | (int) FLayoutUtilities.fromSheetDistance(
|
||
280 | layout.getAtributes().m_area[1], layout.getAT()));
|
||
281 | } |
||
282 | 312 | fernando | |
283 | 1074 | vcaballero | g.setColor(color); |
284 | g.drawLine(w, wi + ini, layout.getWidth(), wi + ini); |
||
285 | g.drawLine(w, ini, layout.getWidth(), ini); |
||
286 | g.drawLine(ini, w, ini, layout.getHeight()); |
||
287 | g.drawLine(wi + ini, w, wi + ini, layout.getHeight()); |
||
288 | 312 | fernando | |
289 | 1074 | vcaballero | drawLineY(g, 5, 12, 22, layout.getRect().y, 0); |
290 | drawLineX(g, 5, 12, 22, layout.getRect().x, 0); |
||
291 | 312 | fernando | |
292 | 1074 | vcaballero | if (FLayoutUtilities.fromSheetDistance(1, layout.getAT()) > 15) { |
293 | drawLineY(g, 1, 12, 22, layout.getRect().y, 0); |
||
294 | drawLineX(g, 1, 12, 22, layout.getRect().x, 0); |
||
295 | 312 | fernando | |
296 | 1074 | vcaballero | if (FLayoutUtilities.fromSheetDistance(1, layout.getAT()) > 25) { |
297 | drawLineY(g, 1, 18, 22, layout.getRect().y, 0.5); |
||
298 | drawLineY(g, 0.1, 21, 22, layout.getRect().y, 0); |
||
299 | drawLineX(g, 1, 18, 22, layout.getRect().x, 0.5); |
||
300 | drawLineX(g, 0.1, 21, 22, layout.getRect().x, 0); |
||
301 | } |
||
302 | } |
||
303 | } |
||
304 | } |
||
305 | 312 | fernando | |
306 | 1074 | vcaballero | /**
|
307 | * Dibuja sobre el graphics2d las l?neas verticales que representan a las
|
||
308 | * unidades de medida.
|
||
309 | *
|
||
310 | * @param g Graphics2d sobre el que se dibuja.
|
||
311 | * @param dist distancia en cent?metros de una l?nea a otra.
|
||
312 | * @param init inicio de la l?nea.
|
||
313 | * @param end fin de la l?nea.
|
||
314 | * @param y rect?ngulo, dentro del cual se dibujan las l?neas.
|
||
315 | * @param desp Desplazamiento.
|
||
316 | */
|
||
317 | private void drawLineY(Graphics2D g, double dist, int init, int end, |
||
318 | double y, double desp) { |
||
319 | double distY = FLayoutUtilities.fromSheetDistance(dist, layout.getAT());
|
||
320 | double rota = Math.toRadians(90); |
||
321 | 312 | fernando | |
322 | 1074 | vcaballero | if (distY > 4) { |
323 | double despY = FLayoutUtilities.fromSheetDistance(desp,
|
||
324 | layout.getAT()); |
||
325 | 312 | fernando | |
326 | 1074 | vcaballero | double posUnitY = y + despY;
|
327 | double posUnitYNeg = posUnitY;
|
||
328 | int num = 0; |
||
329 | double iniY = 40; |
||
330 | Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
||
331 | layout.getWidth(), layout.getHeight()), layout.getAT()); |
||
332 | 312 | fernando | |
333 | 1074 | vcaballero | while (posUnitY < (pfin.y - 5)) { |
334 | posUnitYNeg -= distY; |
||
335 | 312 | fernando | |
336 | 1074 | vcaballero | if (distY > 16) { |
337 | if (init == 12) { |
||
338 | if (posUnitY > iniY) {
|
||
339 | g.rotate(-rota, 20, posUnitY - 12); |
||
340 | g.drawString(String.valueOf(num), (int) 10, |
||
341 | (int) posUnitY - 12); |
||
342 | g.rotate(rota, 20, posUnitY - 12); |
||
343 | } |
||
344 | 312 | fernando | |
345 | 1074 | vcaballero | if (dist == 5) { |
346 | num = num + 5;
|
||
347 | } else {
|
||
348 | num++; |
||
349 | } |
||
350 | 312 | fernando | |
351 | 1074 | vcaballero | if (posUnitYNeg > iniY) {
|
352 | g.rotate(-rota, 20, posUnitYNeg - 12); |
||
353 | g.drawString(String.valueOf(-num), (int) 10, |
||
354 | (int) posUnitYNeg - 12); |
||
355 | g.rotate(rota, 20, posUnitYNeg - 12); |
||
356 | } |
||
357 | } |
||
358 | } |
||
359 | 312 | fernando | |
360 | 1074 | vcaballero | if (posUnitY > iniY) {
|
361 | g.drawLine((int) 2 + init, (int) posUnitY, (int) 2 + end, |
||
362 | (int) posUnitY);
|
||
363 | } |
||
364 | 312 | fernando | |
365 | 1074 | vcaballero | if (posUnitYNeg > iniY) {
|
366 | g.drawLine((int) 2 + init, (int) posUnitYNeg, |
||
367 | (int) 2 + end, (int) posUnitYNeg); |
||
368 | } |
||
369 | 312 | fernando | |
370 | 1074 | vcaballero | posUnitY += distY; |
371 | } |
||
372 | } |
||
373 | } |
||
374 | 312 | fernando | |
375 | 1074 | vcaballero | /**
|
376 | * Dibuja sobre el graphics2d las l?neas horizontales que representan a las
|
||
377 | * unidades de medida.
|
||
378 | *
|
||
379 | * @param g Graphics2d sobre el que se dibuja.
|
||
380 | * @param dist distancia en cent?metros de una l?nea a otra.
|
||
381 | * @param init inicio de la l?nea.
|
||
382 | * @param end fin de la l?nea.
|
||
383 | * @param x rect?ngulo, dentro del cual se dibujan las l?neas.
|
||
384 | * @param desp Desplazamiento.
|
||
385 | */
|
||
386 | private void drawLineX(Graphics2D g, double dist, int init, int end, |
||
387 | double x, double desp) { |
||
388 | double distX = FLayoutUtilities.fromSheetDistance(dist, layout.getAT());
|
||
389 | |||
390 | if (distX > 4) { |
||
391 | double despX = FLayoutUtilities.fromSheetDistance(desp,
|
||
392 | layout.getAT()); |
||
393 | double posUnitX = x + despX;
|
||
394 | double posUnitXNeg = posUnitX;
|
||
395 | int num = 0; |
||
396 | double iniX = 40; |
||
397 | Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
||
398 | layout.getWidth(), layout.getHeight()), layout.getAT()); |
||
399 | |||
400 | while (posUnitX < (pfin.x - 5)) { |
||
401 | posUnitXNeg -= distX; |
||
402 | |||
403 | if (init == 12) { |
||
404 | if (distX > 16) { |
||
405 | if (posUnitX > iniX) {
|
||
406 | g.drawString(String.valueOf(num),
|
||
407 | (int) posUnitX + 3, (int) 20); |
||
408 | } |
||
409 | |||
410 | if (dist == 5) { |
||
411 | num = num + 5;
|
||
412 | } else {
|
||
413 | num++; |
||
414 | } |
||
415 | |||
416 | if (posUnitXNeg > iniX) {
|
||
417 | g.drawString(String.valueOf(-num),
|
||
418 | (int) posUnitXNeg + 3, (int) 20); |
||
419 | } |
||
420 | } |
||
421 | } |
||
422 | |||
423 | if (posUnitX > iniX) {
|
||
424 | g.drawLine((int) posUnitX, (int) 2 + init, (int) posUnitX, |
||
425 | (int) 2 + end); |
||
426 | } |
||
427 | |||
428 | if (posUnitXNeg > iniX) {
|
||
429 | g.drawLine((int) posUnitXNeg, (int) 2 + init, |
||
430 | (int) posUnitXNeg, (int) 2 + end); |
||
431 | } |
||
432 | |||
433 | posUnitX += distX; |
||
434 | } |
||
435 | } |
||
436 | } |
||
437 | |||
438 | /**
|
||
439 | * Dibuja los handlers sobre los fframes que esten seleccionados.
|
||
440 | *
|
||
441 | * @param g Graphics sobre el que se dibuja.
|
||
442 | * @param color Color de los Handlers.
|
||
443 | */
|
||
444 | public void drawHandlers(Graphics2D g, Color color) { |
||
445 | g.setColor(color); |
||
446 | |||
447 | for (int i = 0; i < layout.getFFrames().size(); i++) { |
||
448 | IFFrame fframe = (IFFrame) layout.getFFrames().get(i); |
||
449 | |||
450 | 2263 | vcaballero | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
451 | 1074 | vcaballero | fframe.drawHandlers((Graphics2D) g);
|
452 | } |
||
453 | } |
||
454 | } |
||
455 | 2342 | vcaballero | /**
|
456 | * A partir de un fichero que se pasa como par?metro se crea un pdf con el
|
||
457 | * contenido del Layout.
|
||
458 | *
|
||
459 | * @param pdf
|
||
460 | */
|
||
461 | public void toPDF(File pdf) { |
||
462 | 2761 | caballero | double w = 0; |
463 | double h = 0; |
||
464 | 2342 | vcaballero | Document document = new Document(); |
465 | |||
466 | if (layout.getAtributes().isLandSpace()) {
|
||
467 | 2761 | caballero | w = ((layout.getAtributes().m_sizePaper.getAlto() * Attributes.DPISCREEN) / Attributes.PULGADA); |
468 | h = ((layout.getAtributes().m_sizePaper.getAncho() * Attributes.DPISCREEN) / Attributes.PULGADA); |
||
469 | 2342 | vcaballero | } else {
|
470 | 2761 | caballero | w = ((layout.getAtributes().m_sizePaper.getAncho() * Attributes.DPISCREEN) / Attributes.PULGADA); |
471 | h = ((layout.getAtributes().m_sizePaper.getAlto() * Attributes.DPISCREEN) / Attributes.PULGADA); |
||
472 | 2342 | vcaballero | } |
473 | |||
474 | 2761 | caballero | document.setPageSize(new com.lowagie.text.Rectangle((float)w, (float)h)); |
475 | 2342 | vcaballero | |
476 | try {
|
||
477 | PdfWriter writer = PdfWriter.getInstance(document, |
||
478 | new FileOutputStream(pdf)); |
||
479 | document.open(); |
||
480 | |||
481 | Print print = new Print();
|
||
482 | print.setLayout(layout); |
||
483 | |||
484 | PdfContentByte cb = writer.getDirectContent(); |
||
485 | 2761 | caballero | Graphics2D g2 = cb.createGraphicsShapes((float)w, (float)h); |
486 | 2342 | vcaballero | |
487 | try {
|
||
488 | if (layout.getAtributes().isLandSpace()) {
|
||
489 | g2.rotate(Math.toRadians(-90), |
||
490 | 2761 | caballero | 0 + (w / (h /w)), 0 + (h / 2)); |
491 | 2342 | vcaballero | print.print(g2, new PageFormat(), 0); |
492 | g2.rotate(Math.toRadians(90), |
||
493 | 2761 | caballero | 0 + (w / (h / w)), 0 + (h / 2)); |
494 | 2342 | vcaballero | } else {
|
495 | print.print(g2, new PageFormat(), 0); |
||
496 | } |
||
497 | } catch (PrinterException e) { |
||
498 | e.printStackTrace(); |
||
499 | } |
||
500 | |||
501 | g2.dispose(); |
||
502 | } catch (DocumentException de) {
|
||
503 | System.err.println(de.getMessage());
|
||
504 | } catch (IOException ioe) { |
||
505 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),ioe.getMessage()); |
||
506 | } |
||
507 | |||
508 | document.close(); |
||
509 | layout.fullRect(); |
||
510 | } |
||
511 | 312 | fernando | } |