svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Print.java @ 312
History | View | Annotate | Download (5.48 KB)
1 |
/*
|
---|---|
2 |
* Created on 17-feb-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
package com.iver.cit.gvsig; |
8 |
|
9 |
import com.iver.cit.gvsig.gui.layout.Attributes; |
10 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
11 |
import com.iver.cit.gvsig.gui.layout.Layout; |
12 |
|
13 |
import com.iver.mdiApp.App; |
14 |
import com.iver.mdiApp.AppStatus; |
15 |
import com.iver.mdiApp.plugins.AbstractExtension; |
16 |
import com.iver.mdiApp.ui.MDIManager.View; |
17 |
|
18 |
import java.awt.Cursor; |
19 |
import java.awt.Graphics; |
20 |
import java.awt.Graphics2D; |
21 |
import java.awt.geom.AffineTransform; |
22 |
import java.awt.geom.Rectangle2D; |
23 |
import java.awt.print.PageFormat; |
24 |
import java.awt.print.Paper; |
25 |
import java.awt.print.Printable; |
26 |
import java.awt.print.PrinterException; |
27 |
import java.awt.print.PrinterJob; |
28 |
|
29 |
|
30 |
/**
|
31 |
* Extensi?n desde la que se imprime.
|
32 |
*
|
33 |
* @author Vicente Caballero Navarro
|
34 |
*/
|
35 |
public class Print extends AbstractExtension implements Printable { |
36 |
/** DOCUMENT ME! */
|
37 |
public static PrinterJob printerJob = PrinterJob.getPrinterJob(); |
38 |
private Layout l;
|
39 |
private Paper paper; |
40 |
Rectangle2D.Double aux = null; |
41 |
private int veces = 0; |
42 |
|
43 |
/**
|
44 |
* DOCUMENT ME!
|
45 |
*
|
46 |
* @param status DOCUMENT ME!
|
47 |
* @param s DOCUMENT ME!
|
48 |
*/
|
49 |
public void updateUI(AppStatus status, String s) { |
50 |
l = (Layout) status.getActiveView(); |
51 |
|
52 |
PageFormat format = printerJob.defaultPage(); //new PageFormat(); |
53 |
paper = format.getPaper(); |
54 |
|
55 |
//double margin = 72.0 / 25.4 * 5.0;
|
56 |
try {
|
57 |
if (l.getAtributes().getType() == Attributes.CUSTOM) { |
58 |
l.showPrintDialog(printerJob); |
59 |
} else {
|
60 |
l.showPrintDialog(null);
|
61 |
} |
62 |
|
63 |
//Thread.sleep(10000);
|
64 |
} catch (Exception e) { |
65 |
System.out.println("Excepci?n al abrir el di?logo de impresi?n: " + |
66 |
e); |
67 |
} |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Se dibuja sobre el graphics el Layout.
|
72 |
*
|
73 |
* @param g2 graphics sobre el que se dibuja.
|
74 |
*/
|
75 |
public void drawShapes(Graphics2D g2) { |
76 |
double w = paper.getWidth();
|
77 |
|
78 |
//System.out.println("w " + w);
|
79 |
double h = paper.getHeight();
|
80 |
|
81 |
//System.out.println("h " + h);
|
82 |
//g2.translate(-l.getRect().x, -l.getRect().y);
|
83 |
l.drawLayoutPrint(g2); |
84 |
|
85 |
// System.out.println("drawShapes = "+g2.getTransform().getScaleX());
|
86 |
//g2.translate(l.getRect().x, l.getRect().y);
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* DOCUMENT ME!
|
91 |
*
|
92 |
* @return DOCUMENT ME!
|
93 |
*/
|
94 |
public boolean isVisible() { |
95 |
View f = App.instance.getMDIContext().getActiveView();
|
96 |
|
97 |
if (f == null) { |
98 |
return false; |
99 |
} |
100 |
|
101 |
return (f.getClass() == Layout.class);
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* @see com.iver.mdiApp.plugins.Extension#isEnabled()
|
106 |
*/
|
107 |
public boolean isEnabled() { |
108 |
Layout f = (Layout) App.instance.getMDIContext().getActiveView(); |
109 |
|
110 |
if (f == null) { |
111 |
return false; |
112 |
} |
113 |
|
114 |
return true; |
115 |
} |
116 |
|
117 |
/* (non-Javadoc)
|
118 |
* @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
|
119 |
*/
|
120 |
public int print(Graphics g, PageFormat format, int pi) |
121 |
throws PrinterException { |
122 |
if (pi >= 1) { |
123 |
return Printable.NO_SUCH_PAGE; |
124 |
} |
125 |
|
126 |
System.err.println("Clip 0 = " + g.getClip()); |
127 |
|
128 |
Graphics2D g2d = (Graphics2D) g; |
129 |
|
130 |
double x = format.getImageableX();
|
131 |
double y = format.getImageableY();
|
132 |
double w = format.getImageableWidth();
|
133 |
double h = format.getImageableHeight();
|
134 |
|
135 |
//System.err.println("Orientaci?n en Print: " + format.getOrientation());
|
136 |
System.out.println("print:(" + x + "," + y + "," + w + "," + h + ")"); |
137 |
System.err.println("Clip 1 = " + g2d.getClip()); |
138 |
|
139 |
AffineTransform at = g2d.getTransform();
|
140 |
g2d.translate(0, 0); |
141 |
l.obtainRect(true);
|
142 |
|
143 |
//LWSAffineTransform at = g2d.getTransform();
|
144 |
g2d.scale((double) 72 / (double) (Attributes.DPI), |
145 |
(double) 72 / (double) (Attributes.DPI)); |
146 |
System.err.println("Clip 2 =" + g2d.getClip()); |
147 |
|
148 |
if (l.getAtributes().isMargin()) {
|
149 |
g2d.setClip((int) (l.getRect().getMinX() +
|
150 |
FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[2],
|
151 |
l.getAT())), |
152 |
(int) (l.getRect().getMinY() +
|
153 |
FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[0],
|
154 |
l.getAT())), |
155 |
(int) (l.getRect().getWidth() -
|
156 |
FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[2] +
|
157 |
l.getAtributes().m_area[3], l.getAT())),
|
158 |
(int) (l.getRect().getHeight() -
|
159 |
FLayoutUtilities.fromSheetDistance(l.getAtributes().m_area[0] +
|
160 |
l.getAtributes().m_area[1], l.getAT())));
|
161 |
} else {
|
162 |
/*
|
163 |
Rectangle rec=(Rectangle)g2d.getClipBounds();
|
164 |
Rectangle2D.Double rec2d=new Rectangle2D.Double();
|
165 |
rec2d.setRect(rec.x,rec.y,l.getRect().width,rec.getHeight());
|
166 |
g2d.setClip((int)rec2d.x,(int)rec2d.y,(int)rec2d.width,(int)rec2d.height);
|
167 |
*/
|
168 |
/* g2d.setClip((int) l.getRect().getMinX(),
|
169 |
(int) l.getRect().getMinY(), (int) l.getRect().getWidth(),
|
170 |
(int) l.getRect().getHeight()); */
|
171 |
} |
172 |
|
173 |
veces++; |
174 |
System.out.println("veces = " + veces); |
175 |
|
176 |
drawShapes(g2d); |
177 |
g2d.setTransform(at); |
178 |
|
179 |
return Printable.PAGE_EXISTS; |
180 |
} |
181 |
} |