Revision 30
trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/gui/LayoutPanel.java | ||
---|---|---|
138 | 138 |
public abstract void showPrintDialog(PrinterJob job); |
139 | 139 |
|
140 | 140 |
public abstract void setLayoutManager(LayoutManager layoutManager); |
141 |
|
|
142 |
public abstract void drawLayoutPrint(Graphics2D g2); |
|
141 | 143 |
|
142 | 144 |
} |
trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/gui/DefaultLayoutPanel.java | ||
---|---|---|
22 | 22 |
package org.gvsig.app.project.documents.layout.gui; |
23 | 23 |
|
24 | 24 |
import java.awt.Component; |
25 |
import java.awt.Graphics2D; |
|
25 | 26 |
import java.awt.GridLayout; |
27 |
import java.awt.geom.AffineTransform; |
|
26 | 28 |
import java.awt.print.PageFormat; |
27 | 29 |
import java.awt.print.Printable; |
28 | 30 |
import java.awt.print.PrinterException; |
... | ... | |
252 | 254 |
}; |
253 | 255 |
|
254 | 256 |
jobNuevo.addPrintJobListener(pjlistener); |
257 |
|
|
258 |
/* |
|
259 |
Class repClass = null; |
|
260 |
try { |
|
261 |
repClass = Class.forName(flavor.getRepresentationClassName()); |
|
262 |
} catch (Throwable e) { |
|
263 |
throw new IllegalArgumentException("unknown representation class"); |
|
264 |
} |
|
265 |
|
|
266 |
if (!repClass.isInstance(printData)) { |
|
267 |
throw new IllegalArgumentException("data is not of declared type"); |
|
268 |
} */ |
|
255 | 269 |
|
256 |
doc = |
|
257 |
new SimpleDoc( |
|
258 |
PluginServices |
|
259 |
.getExtension(org.gvsig.app.extension.Print.class), |
|
260 |
flavor, null); |
|
270 |
Printable pb = null; |
|
271 |
Class repClass = null; |
|
272 |
try { |
|
273 |
repClass = Class.forName(flavor.getRepresentationClassName()); |
|
274 |
} catch (Throwable e) { |
|
275 |
throw new IllegalArgumentException("unknown representation class"); |
|
276 |
} |
|
261 | 277 |
|
278 |
Object printData = PluginServices.getExtension(org.gvsig.app.extension.Print.class); |
|
279 |
|
|
280 |
doc = new SimpleDoc(printData, flavor, null); |
|
281 |
|
|
262 | 282 |
try { |
263 | 283 |
jobNuevo.print(doc, att); |
264 | 284 |
|
... | ... | |
490 | 510 |
public void setLayoutManager(LayoutManager layoutManager) { |
491 | 511 |
this.layoutManager = layoutManager; |
492 | 512 |
} |
513 |
|
|
514 |
|
|
515 |
/** |
|
516 |
* Method to print the Layout without modify the Affinetransform. |
|
517 |
* |
|
518 |
* @param g2 Geaphics2D |
|
519 |
*/ |
|
520 |
public void drawLayoutPrint(Graphics2D g2) { |
|
521 |
layoutControl.setCancelDrawing(false); |
|
493 | 522 |
|
523 |
// setCursor(Cursor.getDefaultCursor()); |
|
524 |
|
|
525 |
double scale = 0; |
|
526 |
scale = layoutControl.getRect().height / layoutContext.getAttributes().m_sizePaper.getAlto() * 1; |
|
527 |
AffineTransform escalado = new AffineTransform(); |
|
528 |
AffineTransform translacion = new AffineTransform(); |
|
529 |
translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY()); |
|
530 |
escalado.setToScale(scale, scale); |
|
531 |
layoutControl.getAT().setToIdentity(); |
|
532 |
layoutControl.getAT().concatenate(translacion); |
|
533 |
layoutControl.getAT().concatenate(escalado); |
|
534 |
layoutContext.getAttributes().setDistanceUnitX(layoutControl.getRect()); |
|
535 |
layoutContext.getAttributes().setDistanceUnitY(layoutControl.getRect()); |
|
536 |
IFFrame[] fframes=layoutContext.getFFrames(); |
|
537 |
|
|
538 |
for (int i = 0; i < fframes.length; i++) { |
|
539 |
// fframes[i].setPrintingProperties(this.att); |
|
540 |
fframes[i].print( |
|
541 |
g2, |
|
542 |
layoutControl.getAT(), |
|
543 |
null, |
|
544 |
layoutContext.getAttributes().toPrintAttributes()); |
|
545 |
// fframes[i].setPrintingProperties(null); |
|
546 |
} |
|
547 |
|
|
548 |
// TODO Esto es para ver el rect�ngulo que representa el folio en la |
|
549 |
// impresi�n. |
|
550 |
// g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight()); |
|
551 |
} |
|
552 |
|
|
494 | 553 |
} |
trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/extension/Print.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.app.extension; |
23 | 23 |
|
24 |
import java.awt.Graphics; |
|
25 |
import java.awt.Graphics2D; |
|
26 |
import java.awt.geom.AffineTransform; |
|
24 | 27 |
import java.awt.geom.Rectangle2D; |
28 |
import java.awt.print.PageFormat; |
|
25 | 29 |
import java.awt.print.Printable; |
30 |
import java.awt.print.PrinterException; |
|
26 | 31 |
import java.awt.print.PrinterJob; |
27 | 32 |
|
28 | 33 |
import javax.print.Doc; |
... | ... | |
43 | 48 |
import org.gvsig.andami.plugins.Extension; |
44 | 49 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
45 | 50 |
import org.gvsig.app.project.documents.layout.Attributes; |
51 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
|
46 | 52 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
47 | 53 |
|
48 | 54 |
/** |
... | ... | |
50 | 56 |
* |
51 | 57 |
* @author Vicente Caballero Navarro |
52 | 58 |
*/ |
53 |
public class Print extends Extension { |
|
59 |
public class Print extends Extension implements Printable {
|
|
54 | 60 |
|
55 | 61 |
public static PrinterJob printerJob = PrinterJob.getPrinterJob(); |
56 | 62 |
|
... | ... | |
58 | 64 |
Rectangle2D.Double aux = null; |
59 | 65 |
private PrintService[] m_cachePrintServices = null; |
60 | 66 |
private PrintService m_cachePrintService = null; |
67 |
|
|
68 |
private static LayoutPanel theLayoutPanel = null; |
|
61 | 69 |
|
62 | 70 |
public void execute(String s) { |
63 | 71 |
if (s.compareTo("application-print-layout") == 0) { |
... | ... | |
66 | 74 |
} |
67 | 75 |
|
68 | 76 |
public void doPrint(final LayoutPanel layoutPanel) { |
77 |
|
|
78 |
theLayoutPanel = layoutPanel; |
|
79 |
|
|
69 | 80 |
try { |
70 | 81 |
PluginServices.backgroundExecution(new Runnable() { |
71 | 82 |
|
... | ... | |
122 | 133 |
*/ |
123 | 134 |
public void openDialogToPrint(LayoutPanel layoutPanel) { |
124 | 135 |
|
136 |
theLayoutPanel = layoutPanel; |
|
137 |
|
|
125 | 138 |
try { |
126 | 139 |
if (layoutPanel.getLayoutContext().getAttributes().getType() == Attributes.CUSTOM) { |
127 | 140 |
layoutPanel.showPrintDialog(printerJob); |
... | ... | |
143 | 156 |
*/ |
144 | 157 |
public void printLayout(LayoutPanel layoutPanel) { |
145 | 158 |
|
159 |
theLayoutPanel = layoutPanel; |
|
160 |
|
|
146 | 161 |
try { |
147 | 162 |
printerJob.setPrintable((Printable) PluginServices |
148 | 163 |
.getExtension(org.gvsig.app.extension.Print.class)); |
... | ... | |
192 | 207 |
pe.printStackTrace(); |
193 | 208 |
} |
194 | 209 |
} |
210 |
|
|
211 |
/** |
|
212 |
* Se dibuja sobre el graphics el Layout. |
|
213 |
* |
|
214 |
* @param g2 graphics sobre el que se dibuja. |
|
215 |
*/ |
|
216 |
public void drawShapes(Graphics2D g2) { |
|
217 |
theLayoutPanel.drawLayoutPrint(g2); |
|
218 |
} |
|
219 |
|
|
220 |
|
|
221 |
public int print(Graphics g, PageFormat format, int pi) |
|
222 |
throws PrinterException { |
|
223 |
|
|
224 |
if (pi >= 1) { |
|
225 |
return Printable.NO_SUCH_PAGE; |
|
226 |
} |
|
227 |
|
|
228 |
// System.err.println("Clip 0 = " + g.getClip()); |
|
229 |
|
|
230 |
Graphics2D g2d = (Graphics2D) g; |
|
231 |
|
|
232 |
/* |
|
233 |
double x = format.getImageableX(); |
|
234 |
double y = format.getImageableY(); |
|
235 |
double w = format.getImageableWidth(); |
|
236 |
double h = format.getImageableHeight(); |
|
237 |
*/ |
|
238 |
|
|
239 |
// System.err.println("Orientaci?n en Print: " + format.getOrientation()); |
|
240 |
// System.out.println("print:(" + x + "," + y + "," + w + "," + h + ")"); |
|
241 |
// System.err.println("Clip 1 = " + g2d.getClip()); |
|
242 |
|
|
243 |
AffineTransform at = g2d.getTransform(); |
|
244 |
g2d.translate(0, 0); |
|
245 |
theLayoutPanel.obtainRect(true); |
|
246 |
|
|
247 |
//LWSAffineTransform at = g2d.getTransform(); |
|
248 |
g2d.scale((double) 72 / (double) (Attributes.DPI), |
|
249 |
(double) 72 / (double) (Attributes.DPI)); |
|
250 |
// System.err.println("Clip 2 =" + g2d.getClip()); |
|
251 |
|
|
252 |
if (theLayoutPanel.getLayoutContext().getAttributes().isMargin()) { |
|
253 |
g2d.setClip((int) (theLayoutPanel.getLayoutControl().getRect().getMinX() + |
|
254 |
FLayoutUtilities.fromSheetDistance(theLayoutPanel.getLayoutContext().getAttributes().m_area[2], |
|
255 |
theLayoutPanel.getLayoutControl().getAT())), |
|
256 |
(int) (theLayoutPanel.getLayoutControl().getRect().getMinY() + |
|
257 |
FLayoutUtilities.fromSheetDistance(theLayoutPanel.getLayoutContext().getAttributes().m_area[0], |
|
258 |
theLayoutPanel.getLayoutControl().getAT())), |
|
259 |
(int) (theLayoutPanel.getLayoutControl().getRect().getWidth() - |
|
260 |
FLayoutUtilities.fromSheetDistance(theLayoutPanel.getLayoutContext().getAttributes().m_area[2] + |
|
261 |
theLayoutPanel.getLayoutContext().getAttributes().m_area[3], theLayoutPanel.getLayoutControl().getAT())), |
|
262 |
(int) (theLayoutPanel.getLayoutControl().getRect().getHeight() - |
|
263 |
FLayoutUtilities.fromSheetDistance(theLayoutPanel.getLayoutContext().getAttributes().m_area[0] + |
|
264 |
theLayoutPanel.getLayoutContext().getAttributes().m_area[1], theLayoutPanel.getLayoutControl().getAT()))); |
|
265 |
} |
|
266 |
|
|
267 |
drawShapes(g2d); |
|
268 |
g2d.setTransform(at); |
|
269 |
|
|
270 |
return Printable.PAGE_EXISTS; |
|
271 |
} |
|
195 | 272 |
} |
Also available in: Unified diff