root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / FLayoutDraw.java @ 21299
History | View | Annotate | Download (29.2 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.project.documents.layout; |
46 |
|
47 |
import java.awt.Color; |
48 |
import java.awt.Component; |
49 |
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 |
import java.awt.print.PageFormat; |
55 |
import java.awt.print.PrinterException; |
56 |
import java.io.BufferedOutputStream; |
57 |
import java.io.File; |
58 |
import java.io.FileOutputStream; |
59 |
import java.io.IOException; |
60 |
import java.io.OutputStream; |
61 |
|
62 |
import javax.print.Doc; |
63 |
import javax.print.DocFlavor; |
64 |
import javax.print.DocPrintJob; |
65 |
import javax.print.PrintException; |
66 |
import javax.print.SimpleDoc; |
67 |
import javax.print.StreamPrintService; |
68 |
import javax.print.StreamPrintServiceFactory; |
69 |
import javax.print.attribute.PrintRequestAttributeSet; |
70 |
import javax.swing.JOptionPane; |
71 |
|
72 |
import org.gvsig.data.ReadException; |
73 |
|
74 |
import com.iver.andami.PluginServices; |
75 |
import com.iver.cit.gvsig.Print; |
76 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
77 |
import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
78 |
import com.lowagie.text.Document; |
79 |
import com.lowagie.text.DocumentException; |
80 |
import com.lowagie.text.pdf.PdfContentByte; |
81 |
import com.lowagie.text.pdf.PdfWriter; |
82 |
|
83 |
|
84 |
/**
|
85 |
* Clase que implementa los m?todos del Layout que dibujan sobre el Graphics.
|
86 |
*
|
87 |
* @author Vicente Caballero Navarro
|
88 |
*/
|
89 |
public class FLayoutDraw { |
90 |
private Layout layout;
|
91 |
|
92 |
/**
|
93 |
* Crea un nuevo FLayoutDraw.
|
94 |
*
|
95 |
* @param l Referencia al Layout.
|
96 |
*/
|
97 |
public FLayoutDraw(Layout l) {
|
98 |
layout = l; |
99 |
} |
100 |
|
101 |
/**
|
102 |
* M?todo para dibujar el Layout y modificar la matriz de transformaci?n a
|
103 |
* partir del tama?o en pixels que tenga rect y el formato de papel
|
104 |
* seleccionado.
|
105 |
*
|
106 |
* @param g2
|
107 |
* @param imgBase Si es null, est?s imprimiendo. Si no, la usas para el
|
108 |
* c?digo de optimizaci?n.
|
109 |
*
|
110 |
* @throws ReadDriverException
|
111 |
*/
|
112 |
public void drawLayout(Graphics2D g2, BufferedImage imgBase) |
113 |
throws ReadException {
|
114 |
layout.getLayoutControl().setCancelDrawing(false);
|
115 |
double scale = 0; |
116 |
scale = layout.getLayoutControl().getRect().height / layout.getLayoutContext().getAtributes().m_sizePaper.getAlto() * 1;
|
117 |
AffineTransform escalado = new AffineTransform(); |
118 |
AffineTransform translacion = new AffineTransform(); |
119 |
translacion.setToTranslation(layout.getLayoutControl().getRect().getMinX(), |
120 |
layout.getLayoutControl().getRect().getMinY()); |
121 |
escalado.setToScale(scale, scale); |
122 |
layout.getLayoutControl().getAT().setToIdentity(); |
123 |
layout.getLayoutControl().getAT().concatenate(translacion); |
124 |
layout.getLayoutControl().getAT().concatenate(escalado); |
125 |
layout.getLayoutContext().getAtributes().setDistanceUnitX(layout.getLayoutControl().getRect()); |
126 |
layout.getLayoutContext().getAtributes().setDistanceUnitY(layout.getLayoutControl().getRect()); |
127 |
IFFrame[] fframes=layout.getLayoutContext().getFFrames();
|
128 |
for (int i = 0; i < fframes.length; i++) { |
129 |
IFFrame f = fframes[i]; |
130 |
//original, lento (NO MAC)
|
131 |
f.draw(g2, layout.getLayoutControl().getAT(), layout.getLayoutControl().getVisibleRect(),imgBase); |
132 |
// ESTILO MAC
|
133 |
/* if (f instanceof FFrameView)
|
134 |
{
|
135 |
FFrameView fframe = (FFrameView) f;
|
136 |
BufferedImage img = new BufferedImage((int) layout.getLayoutControl().getWidth(),
|
137 |
(int) layout.getLayoutControl().getHeight(), BufferedImage.TYPE_INT_ARGB);
|
138 |
|
139 |
|
140 |
fframe.draw(img.createGraphics(), layout.getLayoutControl().getAT(), layout.getLayoutControl().getVisibleRect(), imgBase);
|
141 |
g2.drawImage(img, 0, 0, layout.getLayoutControl());
|
142 |
fframe.setBufferedImage(img);
|
143 |
}
|
144 |
else
|
145 |
{
|
146 |
f.draw(g2, layout.getLayoutControl().getAT(), layout.getLayoutControl().getVisibleRect(),imgBase);
|
147 |
} */
|
148 |
|
149 |
// Dibuja el s?mbolo de que contiene un tag.
|
150 |
if ((f.getTag() != null) && (layout.isShowIconTag())) { |
151 |
f.drawSymbolTag(g2); |
152 |
} |
153 |
} |
154 |
|
155 |
if (!(fframes.length==0)) { |
156 |
layout.getLayoutControl().setStatus(LayoutControl.ACTUALIZADO); |
157 |
} else {
|
158 |
layout.getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO); |
159 |
} |
160 |
} |
161 |
|
162 |
/**
|
163 |
* Dibuja sobre un Graphics2D el rect?ngulo que representa al folio.
|
164 |
*
|
165 |
* @param g Graphics2D
|
166 |
*/
|
167 |
public void drawRectangle(Graphics2D g) { |
168 |
double unidadesX = layout.getLayoutContext().getAtributes().getNumUnitsX();
|
169 |
double unidadesY = layout.getLayoutContext().getAtributes().getNumUnitsY();
|
170 |
|
171 |
if ((unidadesX == 0) && (unidadesY == 0)) { |
172 |
return;
|
173 |
} |
174 |
|
175 |
g.setColor(Color.darkGray);
|
176 |
|
177 |
Rectangle2D.Double rectBig = new Rectangle2D.Double(layout.getLayoutControl().getRect().x, |
178 |
layout.getLayoutControl().getRect().y, layout.getLayoutControl().getRect().width, |
179 |
layout.getLayoutControl().getRect().height); |
180 |
|
181 |
g.fill3DRect((int) rectBig.x + 7, (int) rectBig.y + 7, |
182 |
(int) rectBig.width, (int) rectBig.height, true); |
183 |
|
184 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
185 |
|
186 |
if (layout.getLayoutContext().getAtributes().isMargin()) {
|
187 |
r = new Rectangle2D.Double((layout.getLayoutControl().getRect().x + |
188 |
FLayoutUtilities.fromSheetDistance( |
189 |
layout.getLayoutContext().getAtributes().m_area[2], layout.getLayoutControl().getAT())),
|
190 |
(layout.getLayoutControl().getRect().y + |
191 |
FLayoutUtilities.fromSheetDistance( |
192 |
layout.getLayoutContext().getAtributes().m_area[0], layout.getLayoutControl().getAT())),
|
193 |
(layout.getLayoutControl().getRect().width - |
194 |
FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[2] +
|
195 |
layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT())),
|
196 |
(layout.getLayoutControl().getRect().height - |
197 |
FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[0] +
|
198 |
layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT())));
|
199 |
} else {
|
200 |
r.setRect(layout.getLayoutControl().getRect()); |
201 |
} |
202 |
|
203 |
g.setColor(Color.white);
|
204 |
g.fill(layout.getLayoutControl().getRect()); |
205 |
|
206 |
g.setColor(Color.darkGray);
|
207 |
g.drawRect((int) layout.getLayoutControl().getRect().getMinX(),
|
208 |
(int) layout.getLayoutControl().getRect().getMinY(),
|
209 |
(int) layout.getLayoutControl().getRect().getWidth(),
|
210 |
(int) layout.getLayoutControl().getRect().getHeight());
|
211 |
|
212 |
if (layout.getLayoutContext().getAtributes().isMargin()) {
|
213 |
g.setColor(Color.black);
|
214 |
|
215 |
g.drawRect((int) r.x, (int) r.y, (int) r.width, (int) r.height); |
216 |
} |
217 |
} |
218 |
|
219 |
/**
|
220 |
* DOCUMENT ME!
|
221 |
*
|
222 |
* @param g DOCUMENT ME!
|
223 |
*/
|
224 |
public void drawGrid(Graphics2D g) { |
225 |
int unidadesMin = 6; |
226 |
double unidadesX = layout.getLayoutContext().getAtributes().getUnitInPixelsX();
|
227 |
double unidadesY = layout.getLayoutContext().getAtributes().getUnitInPixelsY();
|
228 |
|
229 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
230 |
|
231 |
if (layout.getLayoutContext().getAtributes().isMargin()) {
|
232 |
r = new Rectangle2D.Double((layout.getLayoutControl().getRect().x + |
233 |
FLayoutUtilities.fromSheetDistance( |
234 |
layout.getLayoutContext().getAtributes().m_area[2], layout.getLayoutControl().getAT())),
|
235 |
(layout.getLayoutControl().getRect().y + |
236 |
FLayoutUtilities.fromSheetDistance( |
237 |
layout.getLayoutContext().getAtributes().m_area[0], layout.getLayoutControl().getAT())),
|
238 |
(layout.getLayoutControl().getRect().width - |
239 |
FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[2] +
|
240 |
layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT())),
|
241 |
(layout.getLayoutControl().getRect().height - |
242 |
FLayoutUtilities.fromSheetDistance(layout.getLayoutContext().getAtributes().m_area[0] +
|
243 |
layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT())));
|
244 |
} else {
|
245 |
r.setRect(layout.getLayoutControl().getRect()); |
246 |
} |
247 |
if ((unidadesX == 0) && (unidadesY == 0)) { |
248 |
return;
|
249 |
} |
250 |
g.setColor(Color.darkGray);
|
251 |
|
252 |
if (((unidadesX > unidadesMin) || (unidadesY > unidadesMin)) &&
|
253 |
layout.getLayoutContext().isGridVisible()) { |
254 |
double ax = r.getMinX();
|
255 |
double ay;
|
256 |
|
257 |
while (ax < (r.getMaxX())) {
|
258 |
ay = (r.getMinY()); |
259 |
|
260 |
while (ay < (r.getMaxY())) {
|
261 |
g.drawLine((int) ax, (int) ay, (int) ax, (int) ay); |
262 |
ay = ay + unidadesY; |
263 |
} |
264 |
|
265 |
ax = ax + unidadesX; |
266 |
} |
267 |
} |
268 |
} |
269 |
|
270 |
/**
|
271 |
* Dibuja sobre el graphics2d las reglas.
|
272 |
*
|
273 |
* @param g graphics2d sobre el que se dibuja.
|
274 |
* @param color Color de la regla.
|
275 |
*/
|
276 |
public void drawRuler(Graphics2D g, Color color) { |
277 |
if (layout.getLayoutContext().getRuler()) {
|
278 |
int ini = 10; |
279 |
int w = 30; |
280 |
int wi = 16; |
281 |
|
282 |
g.setColor(new Color(250, 255, 250, 180)); |
283 |
g.fillRect(ini, w, wi, layout.getLayoutControl().getHeight() - w); |
284 |
g.fillRect(w, ini, layout.getLayoutControl().getWidth() - w, wi); |
285 |
|
286 |
g.setColor(new Color(100, 155, 150, 180)); |
287 |
g.fillRect(w, ini, (int) layout.getLayoutControl().getRect().x - w, wi);
|
288 |
g.fillRect((int) layout.getLayoutControl().getRect().getMaxX(), ini,
|
289 |
layout.getLayoutControl().getWidth() - (int) layout.getLayoutControl().getRect().getMaxX(), wi);
|
290 |
|
291 |
g.fillRect(ini, w, wi, (int) layout.getLayoutControl().getRect().y - w);
|
292 |
g.fillRect(ini, (int) layout.getLayoutControl().getRect().getMaxY(), wi,
|
293 |
layout.getLayoutControl().getHeight() - (int) layout.getLayoutControl().getRect().getMaxY());
|
294 |
|
295 |
if (layout.getLayoutContext().getAtributes().isMargin()) {
|
296 |
g.setColor(new Color(50, 55, 50, 180)); |
297 |
g.fillRect((int) layout.getLayoutControl().getRect().x, ini,
|
298 |
(int) FLayoutUtilities.fromSheetDistance(
|
299 |
layout.getLayoutContext().getAtributes().m_area[2], layout.getLayoutControl().getAT()), wi);
|
300 |
g.fillRect((int) layout.getLayoutControl().getRect().getMaxX() -
|
301 |
(int) FLayoutUtilities.fromSheetDistance(
|
302 |
layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT()), ini,
|
303 |
(int) FLayoutUtilities.fromSheetDistance(
|
304 |
layout.getLayoutContext().getAtributes().m_area[3], layout.getLayoutControl().getAT()), wi);
|
305 |
|
306 |
g.fillRect(ini, (int) layout.getLayoutControl().getRect().y, wi,
|
307 |
(int) FLayoutUtilities.fromSheetDistance(
|
308 |
layout.getLayoutContext().getAtributes().m_area[0], layout.getLayoutControl().getAT()));
|
309 |
g.fillRect(ini, |
310 |
(int) layout.getLayoutControl().getRect().getMaxY() -
|
311 |
(int) FLayoutUtilities.fromSheetDistance(
|
312 |
layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT()), wi,
|
313 |
(int) FLayoutUtilities.fromSheetDistance(
|
314 |
layout.getLayoutContext().getAtributes().m_area[1], layout.getLayoutControl().getAT()));
|
315 |
} |
316 |
|
317 |
g.setColor(color); |
318 |
g.drawLine(w, wi + ini, layout.getLayoutControl().getWidth(), wi + ini); |
319 |
g.drawLine(w, ini, layout.getLayoutControl().getWidth(), ini); |
320 |
g.drawLine(ini, w, ini, layout.getLayoutControl().getHeight()); |
321 |
g.drawLine(wi + ini, w, wi + ini, layout.getLayoutControl().getHeight()); |
322 |
|
323 |
drawLineY(g, 5, 12, 22, layout.getLayoutControl().getRect().y, 0); |
324 |
drawLineX(g, 5, 12, 22, layout.getLayoutControl().getRect().x, 0); |
325 |
|
326 |
if (FLayoutUtilities.fromSheetDistance(1, layout.getLayoutControl().getAT()) > 15) { |
327 |
drawLineY(g, 1, 12, 22, layout.getLayoutControl().getRect().y, 0); |
328 |
drawLineX(g, 1, 12, 22, layout.getLayoutControl().getRect().x, 0); |
329 |
|
330 |
if (FLayoutUtilities.fromSheetDistance(1, layout.getLayoutControl().getAT()) > 25) { |
331 |
drawLineY(g, 1, 18, 22, layout.getLayoutControl().getRect().y, 0.5); |
332 |
drawLineY(g, 0.1, 21, 22, layout.getLayoutControl().getRect().y, 0); |
333 |
drawLineX(g, 1, 18, 22, layout.getLayoutControl().getRect().x, 0.5); |
334 |
drawLineX(g, 0.1, 21, 22, layout.getLayoutControl().getRect().x, 0); |
335 |
} |
336 |
} |
337 |
} |
338 |
} |
339 |
|
340 |
/**
|
341 |
* Dibuja sobre el graphics2d las l?neas verticales que representan a las
|
342 |
* unidades de medida.
|
343 |
*
|
344 |
* @param g Graphics2d sobre el que se dibuja.
|
345 |
* @param dist distancia en cent?metros de una l?nea a otra.
|
346 |
* @param init inicio de la l?nea.
|
347 |
* @param end fin de la l?nea.
|
348 |
* @param y rect?ngulo, dentro del cual se dibujan las l?neas.
|
349 |
* @param desp Desplazamiento.
|
350 |
*/
|
351 |
private void drawLineY(Graphics2D g, double dist, int init, int end, |
352 |
double y, double desp) { |
353 |
double distY = FLayoutUtilities.fromSheetDistance(dist, layout.getLayoutControl().getAT());
|
354 |
double rota = Math.toRadians(90); |
355 |
|
356 |
if (distY > 4) { |
357 |
double despY = FLayoutUtilities.fromSheetDistance(desp,
|
358 |
layout.getLayoutControl().getAT()); |
359 |
|
360 |
double posUnitY = y + despY;
|
361 |
double posUnitYNeg = posUnitY;
|
362 |
int num = 0; |
363 |
double iniY = 40; |
364 |
Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
365 |
layout.getLayoutControl().getWidth(), layout.getLayoutControl().getHeight()), layout.getLayoutControl().getAT()); |
366 |
|
367 |
while (posUnitY < (pfin.y - 5)) { |
368 |
posUnitYNeg -= distY; |
369 |
|
370 |
if (distY > 16) { |
371 |
if (init == 12) { |
372 |
if (posUnitY > iniY) {
|
373 |
g.rotate(-rota, 20, posUnitY - 12); |
374 |
g.drawString(String.valueOf(num), 10, |
375 |
(int) posUnitY - 12); |
376 |
g.rotate(rota, 20, posUnitY - 12); |
377 |
} |
378 |
|
379 |
if (dist == 5) { |
380 |
num = num + 5;
|
381 |
} else {
|
382 |
num++; |
383 |
} |
384 |
|
385 |
if (posUnitYNeg > iniY) {
|
386 |
g.rotate(-rota, 20, posUnitYNeg - 12); |
387 |
g.drawString(String.valueOf(-num), 10, |
388 |
(int) posUnitYNeg - 12); |
389 |
g.rotate(rota, 20, posUnitYNeg - 12); |
390 |
} |
391 |
} |
392 |
} |
393 |
|
394 |
if (posUnitY > iniY) {
|
395 |
g.drawLine( 2 + init, (int) posUnitY, 2 + end, |
396 |
(int) posUnitY);
|
397 |
} |
398 |
|
399 |
if (posUnitYNeg > iniY) {
|
400 |
g.drawLine(2 + init, (int) posUnitYNeg, |
401 |
2 + end, (int) posUnitYNeg); |
402 |
} |
403 |
|
404 |
posUnitY += distY; |
405 |
} |
406 |
} |
407 |
} |
408 |
|
409 |
/**
|
410 |
* Dibuja sobre el graphics2d las l?neas horizontales que representan a las
|
411 |
* unidades de medida.
|
412 |
*
|
413 |
* @param g Graphics2d sobre el que se dibuja.
|
414 |
* @param dist distancia en cent?metros de una l?nea a otra.
|
415 |
* @param init inicio de la l?nea.
|
416 |
* @param end fin de la l?nea.
|
417 |
* @param x rect?ngulo, dentro del cual se dibujan las l?neas.
|
418 |
* @param desp Desplazamiento.
|
419 |
*/
|
420 |
private void drawLineX(Graphics2D g, double dist, int init, int end, |
421 |
double x, double desp) { |
422 |
double distX = FLayoutUtilities.fromSheetDistance(dist, layout.getLayoutControl().getAT());
|
423 |
|
424 |
if (distX > 4) { |
425 |
double despX = FLayoutUtilities.fromSheetDistance(desp,
|
426 |
layout.getLayoutControl().getAT()); |
427 |
double posUnitX = x + despX;
|
428 |
double posUnitXNeg = posUnitX;
|
429 |
int num = 0; |
430 |
double iniX = 40; |
431 |
Point2D.Double pfin = FLayoutUtilities.fromSheetPoint(new Point2D.Double( |
432 |
layout.getLayoutControl().getWidth(), layout.getLayoutControl().getHeight()), layout.getLayoutControl().getAT()); |
433 |
|
434 |
while (posUnitX < (pfin.x - 5)) { |
435 |
posUnitXNeg -= distX; |
436 |
|
437 |
if (init == 12) { |
438 |
if (distX > 16) { |
439 |
if (posUnitX > iniX) {
|
440 |
g.drawString(String.valueOf(num),
|
441 |
(int) posUnitX + 3, 20); |
442 |
} |
443 |
|
444 |
if (dist == 5) { |
445 |
num = num + 5;
|
446 |
} else {
|
447 |
num++; |
448 |
} |
449 |
|
450 |
if (posUnitXNeg > iniX) {
|
451 |
g.drawString(String.valueOf(-num),
|
452 |
(int) posUnitXNeg + 3, 20); |
453 |
} |
454 |
} |
455 |
} |
456 |
|
457 |
if (posUnitX > iniX) {
|
458 |
g.drawLine((int) posUnitX, 2 + init, (int) posUnitX, |
459 |
2 + end);
|
460 |
} |
461 |
|
462 |
if (posUnitXNeg > iniX) {
|
463 |
g.drawLine((int) posUnitXNeg, 2 + init, |
464 |
(int) posUnitXNeg, 2 + end); |
465 |
} |
466 |
|
467 |
posUnitX += distX; |
468 |
} |
469 |
} |
470 |
} |
471 |
|
472 |
/**
|
473 |
* Dibuja los handlers sobre los fframes que esten seleccionados.
|
474 |
*
|
475 |
* @param g Graphics sobre el que se dibuja.
|
476 |
* @param color Color de los Handlers.
|
477 |
*/
|
478 |
public void drawHandlers(Graphics2D g, Color color) { |
479 |
g.setColor(color); |
480 |
IFFrame[] fframes=layout.getLayoutContext().getFFrames();
|
481 |
for (int i = 0; i < fframes.length; i++) { |
482 |
IFFrame fframe = fframes[i]; |
483 |
|
484 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
485 |
fframe.drawHandlers(g); |
486 |
} |
487 |
} |
488 |
} |
489 |
|
490 |
/**
|
491 |
* A partir de un fichero que se pasa como par?metro se crea un pdf con el
|
492 |
* contenido del Layout.
|
493 |
*
|
494 |
* @param pdf
|
495 |
*/
|
496 |
/* public void toPS(File ps) {
|
497 |
|
498 |
try {
|
499 |
// Open the image file
|
500 |
// InputStream is = new BufferedInputStream(
|
501 |
// new FileInputStream("filename.gif"));
|
502 |
|
503 |
// Prepare the output file to receive the postscript
|
504 |
OutputStream fos = new BufferedOutputStream(
|
505 |
new FileOutputStream("filename.ps"));
|
506 |
|
507 |
// Find a factory that can do the conversion
|
508 |
//DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
|
509 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
|
510 |
StreamPrintServiceFactory[] factories =
|
511 |
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
|
512 |
flavor,
|
513 |
DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
|
514 |
|
515 |
if (factories.length > 0) {
|
516 |
StreamPrintService service = factories[0].getPrintService(fos);
|
517 |
|
518 |
// Create the print job
|
519 |
DocPrintJob job = service.createPrintJob();
|
520 |
Print print= (Print)PluginServices.getExtension(
|
521 |
com.iver.cit.gvsig.Print.class);
|
522 |
print.setLayout(layout);
|
523 |
Doc doc = new SimpleDoc((Printable)print, flavor, null);
|
524 |
//Doc doc = new SimpleDoc(is, flavor, null);
|
525 |
// Monitor print job events; for the implementation of PrintJobWatcher,
|
526 |
// see e702 Determining When a Print Job Has Finished
|
527 |
//PrintJobWatcher pjDone = new PrintJobWatcher(job);
|
528 |
// Actualizar attributes
|
529 |
PrintRequestAttributeSet att = layout.getAtributes()
|
530 |
.toPrintAttributes();
|
531 |
// Print it
|
532 |
job.print(doc, att);
|
533 |
|
534 |
// Wait for the print job to be done
|
535 |
//pjDone.waitForDone();
|
536 |
// It is now safe to close the streams
|
537 |
}
|
538 |
|
539 |
// is.close();
|
540 |
fos.close();
|
541 |
} catch (PrintException e) {
|
542 |
} catch (IOException e) {
|
543 |
}
|
544 |
}
|
545 |
*/
|
546 |
|
547 |
/*
|
548 |
public void printLayout(Layout layout) {
|
549 |
l = layout;
|
550 |
|
551 |
try {
|
552 |
printerJob.setPrintable((Printable) PluginServices.getExtension(
|
553 |
com.iver.cit.gvsig.Print.class));
|
554 |
|
555 |
//Actualizar attributes
|
556 |
PrintRequestAttributeSet att = layout.getAtributes()
|
557 |
.toPrintAttributes();
|
558 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
|
559 |
|
560 |
if (m_cachePrintServices == null) {
|
561 |
m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
|
562 |
null);
|
563 |
}
|
564 |
|
565 |
PrintService defaultService = null;
|
566 |
|
567 |
if (m_cachePrintService == null) {
|
568 |
defaultService = PrintServiceLookup.lookupDefaultPrintService();
|
569 |
}
|
570 |
|
571 |
if (m_cachePrintService == null) {
|
572 |
m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
|
573 |
m_cachePrintServices, defaultService, flavor, att);
|
574 |
}
|
575 |
|
576 |
if (m_cachePrintService != null) {
|
577 |
DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
|
578 |
PrintJobListener pjlistener = new PrintJobAdapter() {
|
579 |
public void printDataTransferCompleted(PrintJobEvent e) {
|
580 |
System.out.println("Fin de impresi?n");
|
581 |
}
|
582 |
};
|
583 |
|
584 |
jobNuevo.addPrintJobListener(pjlistener);
|
585 |
|
586 |
Doc doc = new SimpleDoc((Printable) PluginServices.getExtension(
|
587 |
com.iver.cit.gvsig.Print.class), flavor, null);
|
588 |
jobNuevo.print(doc, att);
|
589 |
}
|
590 |
} catch (PrintException pe) {
|
591 |
pe.printStackTrace();
|
592 |
}
|
593 |
}
|
594 |
|
595 |
document.close();
|
596 |
|
597 |
layout.fullRect();
|
598 |
}
|
599 |
*/
|
600 |
|
601 |
|
602 |
|
603 |
/**
|
604 |
* A partir de un fichero que se pasa como par?metro se crea un ps con el
|
605 |
* contenido del Layout.
|
606 |
*
|
607 |
* @param ps
|
608 |
*/
|
609 |
public void toPS(File ps) { |
610 |
try {
|
611 |
// Prepare the output file to receive the postscript
|
612 |
OutputStream fos = new BufferedOutputStream( |
613 |
new FileOutputStream(ps)); |
614 |
|
615 |
// Find a factory that can do the conversion
|
616 |
//DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
|
617 |
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; |
618 |
StreamPrintServiceFactory [] factories = |
619 |
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
|
620 |
"application/postscript");
|
621 |
|
622 |
if (factories.length > 0) { |
623 |
StreamPrintService service = factories[0].getPrintService(fos); |
624 |
|
625 |
// Create the print job
|
626 |
DocPrintJob job = service.createPrintJob();
|
627 |
Print print= new Print();//(Print)PluginServices.getExtension( |
628 |
// com.iver.cit.gvsig.Print.class);
|
629 |
print.setLayout(layout); |
630 |
Doc doc = new SimpleDoc(print, flavor, null); |
631 |
//Doc doc = new SimpleDoc(is, flavor, null);
|
632 |
// Monitor print job events; for the implementation of PrintJobWatcher,
|
633 |
// see e702 Determining When a Print Job Has Finished
|
634 |
//PrintJobWatcher pjDone = new PrintJobWatcher(job);
|
635 |
// Actualizar attributes
|
636 |
PrintRequestAttributeSet att = layout.getLayoutContext().getAtributes()
|
637 |
.toPrintAttributes(); |
638 |
// Print it
|
639 |
job.print(doc, att); |
640 |
|
641 |
// Wait for the print job to be done
|
642 |
//pjDone.waitForDone();
|
643 |
// It is now safe to close the streams
|
644 |
} |
645 |
|
646 |
// is.close();
|
647 |
fos.close(); |
648 |
} catch (PrintException e) { |
649 |
} catch (IOException e) { |
650 |
} |
651 |
/* PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
|
652 |
DocPrintJob printerJob = defaultPrintService.createPrintJob();
|
653 |
|
654 |
try {
|
655 |
DocFlavor flavor=DocFlavor.URL.POSTSCRIPT;
|
656 |
if (!defaultPrintService.isDocFlavorSupported(flavor)) {
|
657 |
System.err.println("The printer does not support the appropriate DocFlavor");
|
658 |
}else {
|
659 |
|
660 |
SimpleDoc simpleDoc;
|
661 |
simpleDoc = new SimpleDoc(ps.toURL(),flavor, null);
|
662 |
printerJob.print(simpleDoc, null);
|
663 |
}
|
664 |
} catch (MalformedURLException e) {
|
665 |
// TODO Auto-generated catch block
|
666 |
e.printStackTrace();
|
667 |
} catch (PrintException e) {
|
668 |
// TODO Auto-generated catch block
|
669 |
e.printStackTrace();
|
670 |
}
|
671 |
*/
|
672 |
layout.getLayoutControl().fullRect(); |
673 |
} |
674 |
|
675 |
|
676 |
/**
|
677 |
* A partir de un fichero que se pasa como par?metro se crea un pdf con el
|
678 |
* contenido del Layout.
|
679 |
*
|
680 |
* @param pdf
|
681 |
*/
|
682 |
public void toPDF(File pdf) { |
683 |
double w = 0; |
684 |
double h = 0; |
685 |
Document document = new Document(); |
686 |
|
687 |
if (layout.getLayoutContext().getAtributes().isLandSpace()) {
|
688 |
w = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAlto() * Attributes.DPISCREEN) / Attributes.PULGADA); |
689 |
h = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAncho() * Attributes.DPISCREEN) / Attributes.PULGADA); |
690 |
} else {
|
691 |
w = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAncho() * Attributes.DPISCREEN) / Attributes.PULGADA); |
692 |
h = ((layout.getLayoutContext().getAtributes().m_sizePaper.getAlto() * Attributes.DPISCREEN) / Attributes.PULGADA); |
693 |
} |
694 |
|
695 |
document.setPageSize(new com.lowagie.text.Rectangle((float) w, (float) h)); |
696 |
|
697 |
try {
|
698 |
FileOutputStream fos=new FileOutputStream(pdf); |
699 |
PdfWriter writer = PdfWriter.getInstance(document,fos); |
700 |
document.open(); |
701 |
|
702 |
Print print = new Print();
|
703 |
print.setLayout(layout); |
704 |
|
705 |
PdfContentByte cb = writer.getDirectContent(); |
706 |
Graphics2D g2 = cb.createGraphicsShapes((float) w, (float) h); |
707 |
|
708 |
try {
|
709 |
if (layout.getLayoutContext().getAtributes().isLandSpace()) {
|
710 |
g2.rotate(Math.toRadians(-90), 0 + (w / (h / w)), |
711 |
0 + (h / 2)); |
712 |
print.print(g2, new PageFormat(), 0); |
713 |
g2.rotate(Math.toRadians(90), 0 + (w / (h / w)), 0 + |
714 |
(h / 2));
|
715 |
} else {
|
716 |
print.print(g2, new PageFormat(), 0); |
717 |
} |
718 |
} catch (PrinterException e) { |
719 |
e.printStackTrace(); |
720 |
} |
721 |
|
722 |
g2.dispose(); |
723 |
|
724 |
} catch (DocumentException de) {
|
725 |
System.err.println(de.getMessage());
|
726 |
} catch (IOException ioe) { |
727 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
728 |
ioe.getMessage()); |
729 |
} |
730 |
|
731 |
document.close(); |
732 |
|
733 |
layout.getLayoutControl().fullRect(); |
734 |
} |
735 |
} |