Revision 30 trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/extension/Print.java

View differences:

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