Revision 37415 branches/v2_0_0_prep/extensions/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/FLayoutDraw.java
FLayoutDraw.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import java.awt.Color; |
25 | 25 |
import java.awt.Component; |
26 |
import java.awt.Graphics; |
|
26 | 27 |
import java.awt.Graphics2D; |
27 | 28 |
import java.awt.geom.AffineTransform; |
28 | 29 |
import java.awt.geom.Point2D; |
29 | 30 |
import java.awt.geom.Rectangle2D; |
30 | 31 |
import java.awt.image.BufferedImage; |
31 | 32 |
import java.awt.print.PageFormat; |
33 |
import java.awt.print.Printable; |
|
32 | 34 |
import java.awt.print.PrinterException; |
33 | 35 |
import java.io.BufferedOutputStream; |
34 | 36 |
import java.io.File; |
... | ... | |
52 | 54 |
import com.lowagie.text.pdf.PdfWriter; |
53 | 55 |
|
54 | 56 |
import org.gvsig.andami.PluginServices; |
55 |
import org.gvsig.app.extension.Print; |
|
56 | 57 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
57 | 58 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
58 | 59 |
import org.gvsig.fmap.dal.exception.ReadException; |
... | ... | |
65 | 66 |
* |
66 | 67 |
* @author Vicente Caballero Navarro |
67 | 68 |
*/ |
68 |
public class FLayoutDraw implements Observable{ |
|
69 |
public class FLayoutDraw implements Observable, Printable{
|
|
69 | 70 |
|
70 |
private LayoutPanel layout; |
|
71 |
private LayoutPanel layoutPanel;
|
|
71 | 72 |
private ObservableHelper observers; |
72 | 73 |
|
73 | 74 |
/** |
... | ... | |
77 | 78 |
* Referencia al Layout. |
78 | 79 |
*/ |
79 | 80 |
public FLayoutDraw(LayoutPanel layoutPanel) { |
80 |
layout = layoutPanel;
|
|
81 |
this.layoutPanel = layoutPanel;
|
|
81 | 82 |
observers = new ObservableHelper(); |
82 | 83 |
observers.addObserver(layoutPanel.getLayoutControl()); |
83 | 84 |
} |
... | ... | |
96 | 97 |
*/ |
97 | 98 |
public void drawLayout(Graphics2D g2, BufferedImage imgBase) |
98 | 99 |
throws ReadException { |
99 |
LayoutControl layoutControl = layout.getLayoutControl(); |
|
100 |
LayoutContext layoutContext = layout.getLayoutContext(); |
|
100 |
LayoutControl layoutControl = layoutPanel.getLayoutControl();
|
|
101 |
LayoutContext layoutContext = layoutPanel.getLayoutContext();
|
|
101 | 102 |
Attributes attributes = layoutContext.getAttributes(); |
102 | 103 |
Rectangle2D rLayout = layoutControl.getRect(); |
103 | 104 |
AffineTransform at = layoutContext.getAT(); |
... | ... | |
121 | 122 |
imgBase); |
122 | 123 |
|
123 | 124 |
// Dibuja el s?mbolo de que contiene un tag. |
124 |
if ((f.getTag() != null) && (layout.isShowIconTag())) { |
|
125 |
if ((f.getTag() != null) && (layoutPanel.isShowIconTag())) {
|
|
125 | 126 |
f.drawSymbolTag(g2); |
126 | 127 |
} |
127 | 128 |
} |
... | ... | |
142 | 143 |
* Graphics2D |
143 | 144 |
*/ |
144 | 145 |
public void drawRectangle(Graphics2D g) { |
145 |
Attributes attributes = layout.getLayoutContext().getAttributes(); |
|
146 |
Rectangle2D rLayout = layout.getLayoutControl().getRect(); |
|
147 |
AffineTransform at = layout.getLayoutContext().getAT(); |
|
146 |
Attributes attributes = layoutPanel.getLayoutContext().getAttributes();
|
|
147 |
Rectangle2D rLayout = layoutPanel.getLayoutControl().getRect();
|
|
148 |
AffineTransform at = layoutPanel.getLayoutContext().getAT();
|
|
148 | 149 |
|
149 | 150 |
double unidadesX = attributes.getNumUnitsX(); |
150 | 151 |
double unidadesY = attributes.getNumUnitsY(); |
... | ... | |
202 | 203 |
*/ |
203 | 204 |
public void drawGrid(Graphics2D g) { |
204 | 205 |
int unidadesMin = 6; |
205 |
LayoutContext layoutContext = layout.getLayoutContext(); |
|
206 |
LayoutContext layoutContext = layoutPanel.getLayoutContext();
|
|
206 | 207 |
Attributes attributes = layoutContext.getAttributes(); |
207 |
Rectangle2D rLayout = layout.getLayoutControl().getRect(); |
|
208 |
Rectangle2D rLayout = layoutPanel.getLayoutControl().getRect();
|
|
208 | 209 |
AffineTransform at = layoutContext.getAT(); |
209 | 210 |
|
210 | 211 |
double unidadesX = attributes.getUnitInPixelsX(); |
... | ... | |
258 | 259 |
* Color de la regla. |
259 | 260 |
*/ |
260 | 261 |
public void drawRuler(Graphics2D g, Color color) { |
261 |
LayoutControl layoutControl = layout.getLayoutControl(); |
|
262 |
LayoutContext layoutContext = layout.getLayoutContext(); |
|
262 |
LayoutControl layoutControl = layoutPanel.getLayoutControl();
|
|
263 |
LayoutContext layoutContext = layoutPanel.getLayoutContext();
|
|
263 | 264 |
Attributes attributes = layoutContext.getAttributes(); |
264 | 265 |
Rectangle2D rLayout = layoutControl.getRect(); |
265 | 266 |
AffineTransform at = layoutContext.getAT(); |
... | ... | |
347 | 348 |
*/ |
348 | 349 |
private void drawLineY(Graphics2D g, double dist, int init, int end, |
349 | 350 |
double y, double desp) { |
350 |
AffineTransform at = layout.getLayoutContext().getAT(); |
|
351 |
LayoutControl layoutControl = layout.getLayoutControl(); |
|
351 |
AffineTransform at = layoutPanel.getLayoutContext().getAT();
|
|
352 |
LayoutControl layoutControl = layoutPanel.getLayoutControl();
|
|
352 | 353 |
|
353 | 354 |
double distY = FLayoutUtilities.fromSheetDistance(dist, at); |
354 | 355 |
double rota = Math.toRadians(90); |
... | ... | |
425 | 426 |
*/ |
426 | 427 |
private void drawLineX(Graphics2D g, double dist, int init, int end, |
427 | 428 |
double x, double desp) { |
428 |
AffineTransform at = layout.getLayoutContext().getAT(); |
|
429 |
LayoutControl layoutControl = layout.getLayoutControl(); |
|
429 |
AffineTransform at = layoutPanel.getLayoutContext().getAT();
|
|
430 |
LayoutControl layoutControl = layoutPanel.getLayoutControl();
|
|
430 | 431 |
|
431 | 432 |
double distX = FLayoutUtilities.fromSheetDistance(dist, at); |
432 | 433 |
|
... | ... | |
487 | 488 |
* Color de los Handlers. |
488 | 489 |
*/ |
489 | 490 |
public void drawHandlers(Graphics2D g, Color color) { |
490 |
LayoutContext layoutContext = layout.getLayoutContext(); |
|
491 |
LayoutContext layoutContext = layoutPanel.getLayoutContext();
|
|
491 | 492 |
|
492 | 493 |
g.setColor(color); |
493 | 494 |
IFFrame[] fframes = layoutContext.getFFrames(); |
... | ... | |
507 | 508 |
* @param ps |
508 | 509 |
*/ |
509 | 510 |
public void toPS(File ps) { |
510 |
Attributes attributes = layout.getLayoutContext().getAttributes(); |
|
511 |
LayoutControl layoutControl = layout.getLayoutControl(); |
|
511 |
Attributes attributes = layoutPanel.getLayoutContext().getAttributes();
|
|
512 |
LayoutControl layoutControl = layoutPanel.getLayoutControl();
|
|
512 | 513 |
|
513 | 514 |
try { |
514 | 515 |
// Prepare the output file to receive the postscript |
... | ... | |
527 | 528 |
|
528 | 529 |
// Create the print job |
529 | 530 |
DocPrintJob job = service.createPrintJob(); |
530 |
Print print = new Print();// (Print)PluginServices.getExtension( |
|
531 |
// com.iver.cit.gvsig.Print.class); |
|
532 |
print.setLayout(layout); |
|
533 |
Doc doc = new SimpleDoc(print, flavor, null); |
|
531 |
|
|
532 |
Doc doc = new SimpleDoc(this, flavor, null); |
|
534 | 533 |
// Doc doc = new SimpleDoc(is, flavor, null); |
535 | 534 |
// Monitor print job events; for the implementation of |
536 | 535 |
// PrintJobWatcher, |
... | ... | |
586 | 585 |
* @param pdf |
587 | 586 |
*/ |
588 | 587 |
public void toPDF(File pdf) { |
589 |
Attributes attributes = layout.getLayoutContext().getAttributes(); |
|
590 |
LayoutControl layoutControl = layout.getLayoutControl(); |
|
588 |
Attributes attributes = layoutPanel.getLayoutContext().getAttributes();
|
|
589 |
LayoutControl layoutControl = layoutPanel.getLayoutControl();
|
|
591 | 590 |
|
592 | 591 |
double w = 0; |
593 | 592 |
double h = 0; |
... | ... | |
612 | 611 |
FileOutputStream fos = new FileOutputStream(pdf); |
613 | 612 |
PdfWriter writer = PdfWriter.getInstance(document, fos); |
614 | 613 |
document.open(); |
615 |
|
|
616 |
Print print = new Print(); |
|
617 |
print.setLayout(layout); |
|
618 |
|
|
614 |
|
|
619 | 615 |
PdfContentByte cb = writer.getDirectContent(); |
620 | 616 |
Graphics2D g2 = cb.createGraphicsShapes((float) w, (float) h); |
621 | 617 |
|
... | ... | |
623 | 619 |
if (attributes.isLandSpace()) { |
624 | 620 |
g2.rotate(Math.toRadians(-90), 0 + (w / (h / w)), |
625 | 621 |
0 + (h / 2)); |
626 |
print.print(g2, new PageFormat(), 0);
|
|
622 |
print(g2, new PageFormat(), 0); |
|
627 | 623 |
g2.rotate(Math.toRadians(90), 0 + (w / (h / w)), |
628 | 624 |
0 + (h / 2)); |
629 | 625 |
} else { |
630 |
print.print(g2, new PageFormat(), 0);
|
|
626 |
print(g2, new PageFormat(), 0); |
|
631 | 627 |
} |
632 | 628 |
} catch (PrinterException e) { |
633 | 629 |
e.printStackTrace(); |
... | ... | |
646 | 642 |
|
647 | 643 |
layoutControl.fullRect(); |
648 | 644 |
} |
645 |
|
|
646 |
public int print(Graphics g, PageFormat format, int pi) |
|
647 |
throws PrinterException { |
|
648 |
if (pi >= 1) { |
|
649 |
return Printable.NO_SUCH_PAGE; |
|
650 |
} |
|
649 | 651 |
|
652 |
Graphics2D g2d = (Graphics2D) g; |
|
653 |
|
|
654 |
AffineTransform at = g2d.getTransform(); |
|
655 |
g2d.translate(0, 0); |
|
656 |
layoutPanel.obtainRect(true); |
|
657 |
|
|
658 |
g2d.scale((double) 72 / (double) (Attributes.DPI), (double) 72 |
|
659 |
/ (double) (Attributes.DPI)); |
|
660 |
System.err.println("Clip 2 =" + g2d.getClip()); |
|
661 |
|
|
662 |
if (layoutPanel.getLayoutContext().getAttributes().isMargin()) { |
|
663 |
g2d.setClip( |
|
664 |
(int) (layoutPanel.getLayoutControl().getRect().getMinX() + FLayoutUtilities |
|
665 |
.fromSheetDistance( |
|
666 |
layoutPanel.getLayoutContext().getAttributes().m_area[2], layoutPanel |
|
667 |
.getLayoutControl().getAT())), |
|
668 |
(int) (layoutPanel.getLayoutControl().getRect().getMinY() + FLayoutUtilities |
|
669 |
.fromSheetDistance( |
|
670 |
layoutPanel.getLayoutContext().getAttributes().m_area[0], layoutPanel |
|
671 |
.getLayoutControl().getAT())), |
|
672 |
(int) (layoutPanel.getLayoutControl().getRect().getWidth() - FLayoutUtilities |
|
673 |
.fromSheetDistance( |
|
674 |
layoutPanel.getLayoutContext().getAttributes().m_area[2] |
|
675 |
+ layoutPanel.getLayoutContext().getAttributes().m_area[3], layoutPanel |
|
676 |
.getLayoutControl().getAT())), |
|
677 |
(int) (layoutPanel.getLayoutControl().getRect().getHeight() - FLayoutUtilities |
|
678 |
.fromSheetDistance( |
|
679 |
layoutPanel.getLayoutContext().getAttributes().m_area[0] |
|
680 |
+ layoutPanel.getLayoutContext().getAttributes().m_area[1], layoutPanel |
|
681 |
.getLayoutControl().getAT()))); |
|
682 |
} |
|
683 |
|
|
684 |
|
|
685 |
drawShapes(g2d); |
|
686 |
g2d.setTransform(at); |
|
687 |
|
|
688 |
return Printable.PAGE_EXISTS; |
|
689 |
} |
|
690 |
|
|
691 |
/** |
|
692 |
* Se dibuja sobre el graphics el Layout. |
|
693 |
* |
|
694 |
* @param g2 |
|
695 |
* graphics sobre el que se dibuja. |
|
696 |
*/ |
|
697 |
public void drawShapes(Graphics2D g2) { |
|
698 |
layoutPanel.drawLayoutPrint(g2); |
|
699 |
} |
|
700 |
|
|
650 | 701 |
public void addObserver(Observer o) { |
651 | 702 |
observers.addObserver(o); |
652 | 703 |
} |
Also available in: Unified diff