/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/print/BufferPrinter1_3.java
Java | 113 lines | 67 code | 15 blank | 31 comment | 5 complexity | 0acc45e943564843ffb50ad67c82b1d4 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
1/*
2 * BufferPrinter1_3.java - Main class that controls printing
3 * :tabSize=8:indentSize=8:noTabs=false:
4 * :folding=explicit:collapseFolds=1:
5 *
6 * Copyright (C) 2001 Slava Pestov
7 * Portions copyright (C) 2002 Thomas Dilts
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 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
24package org.gjt.sp.jedit.print;
25
26//{{{ Imports
27import java.awt.print.*;
28import java.awt.*;
29import org.gjt.sp.jedit.*;
30//}}}
31
32public class BufferPrinter1_3
33{
34 //{{{ getPrintJob() method
35 private static PrinterJob getPrintJob()
36 {
37 job = PrinterJob.getPrinterJob();
38
39 int orientation = jEdit.getIntegerProperty("print.orientation",PageFormat.PORTRAIT);
40 double width = jEdit.getDoubleProperty("print.width",0);
41 double height = jEdit.getDoubleProperty("print.height",0);
42 double x = jEdit.getDoubleProperty("print.x",0);
43 double y = jEdit.getDoubleProperty("print.y",0);
44 double pagewidth = jEdit.getDoubleProperty("print.pagewidth",0);
45 double pageheight = jEdit.getDoubleProperty("print.pageheight",0);
46
47 format = job.defaultPage();
48 //format.setOrientation(PageFormat.PORTRAIT);
49 if(width!=0 && height!=0 )
50 {
51 Paper pap = format.getPaper();
52 pap.setImageableArea(x,y,width,height);
53 pap.setSize(pagewidth,pageheight);
54 format.setPaper(pap);
55 }
56 format.setOrientation(orientation);
57 return job;
58
59 }//}}}
60
61 //{{{ pageSetup() method
62 public static void pageSetup(View view)
63 {
64 job = getPrintJob();
65
66 PageFormat newFormat = job.pageDialog(format);
67 if(newFormat != null)
68 {
69 format = newFormat;
70 jEdit.setIntegerProperty("print.orientation",format.getOrientation());
71 Paper paper=format.getPaper();
72
73 jEdit.setDoubleProperty("print.width",paper.getImageableWidth());
74 jEdit.setDoubleProperty("print.height",paper.getImageableHeight());
75 jEdit.setDoubleProperty("print.x",paper.getImageableX());
76 jEdit.setDoubleProperty("print.y",paper.getImageableY());
77 jEdit.setDoubleProperty("print.pagewidth",paper.getWidth());
78 jEdit.setDoubleProperty("print.pageheight",paper.getHeight());
79 }
80 } //}}}
81
82 //{{{ print() method
83 public static void print(final View view, final Buffer buffer, boolean selection)
84 {
85 job = getPrintJob();
86 job.setJobName(buffer.getPath());
87 boolean header = jEdit.getBooleanProperty("print.header");
88 boolean footer = jEdit.getBooleanProperty("print.footer");
89 boolean lineNumbers = jEdit.getBooleanProperty("print.lineNumbers");
90 boolean color = jEdit.getBooleanProperty("print.color");
91 Font font = jEdit.getFontProperty("print.font");
92
93 BufferPrintable printable = new BufferPrintable(job,null,view,
94 buffer,font,header,footer,lineNumbers,color);
95 job.setPrintable(printable,format);
96
97 if(!job.printDialog())
98 return;
99
100 printable.print();
101 } //}}}
102
103 //{{{ getPageFormat() method
104 public static PageFormat getPageFormat()
105 {
106 return format;
107 } //}}}
108
109 //{{{ Private members
110 private static PageFormat format;
111 private static PrinterJob job;
112 //}}}
113}