001: /*
002: * BufferPrinter1_3.java - Main class that controls printing
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2001 Slava Pestov
007: * Portions copyright (C) 2002 Thomas Dilts
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: */
023:
024: package org.gjt.sp.jedit.print;
025:
026: //{{{ Imports
027: import java.awt.print.*;
028: import java.awt.*;
029: import org.gjt.sp.jedit.*;
030:
031: //}}}
032:
033: public class BufferPrinter1_3 {
034: //{{{ getPrintJob() method
035: private static PrinterJob getPrintJob() {
036: job = PrinterJob.getPrinterJob();
037:
038: int orientation = jEdit.getIntegerProperty("print.orientation",
039: PageFormat.PORTRAIT);
040: double width = jEdit.getDoubleProperty("print.width", 0);
041: double height = jEdit.getDoubleProperty("print.height", 0);
042: double x = jEdit.getDoubleProperty("print.x", 0);
043: double y = jEdit.getDoubleProperty("print.y", 0);
044: double pagewidth = jEdit
045: .getDoubleProperty("print.pagewidth", 0);
046: double pageheight = jEdit.getDoubleProperty("print.pageheight",
047: 0);
048:
049: format = job.defaultPage();
050: //format.setOrientation(PageFormat.PORTRAIT);
051: if (width != 0 && height != 0) {
052: Paper pap = format.getPaper();
053: pap.setImageableArea(x, y, width, height);
054: pap.setSize(pagewidth, pageheight);
055: format.setPaper(pap);
056: }
057: format.setOrientation(orientation);
058: return job;
059:
060: }//}}}
061:
062: //{{{ pageSetup() method
063: public static void pageSetup(View view) {
064: job = getPrintJob();
065:
066: PageFormat newFormat = job.pageDialog(format);
067: if (newFormat != null) {
068: format = newFormat;
069: jEdit.setIntegerProperty("print.orientation", format
070: .getOrientation());
071: Paper paper = format.getPaper();
072:
073: jEdit.setDoubleProperty("print.width", paper
074: .getImageableWidth());
075: jEdit.setDoubleProperty("print.height", paper
076: .getImageableHeight());
077: jEdit.setDoubleProperty("print.x", paper.getImageableX());
078: jEdit.setDoubleProperty("print.y", paper.getImageableY());
079: jEdit
080: .setDoubleProperty("print.pagewidth", paper
081: .getWidth());
082: jEdit.setDoubleProperty("print.pageheight", paper
083: .getHeight());
084: }
085: } //}}}
086:
087: //{{{ print() method
088: public static void print(final View view, final Buffer buffer,
089: boolean selection) {
090: job = getPrintJob();
091: job.setJobName(buffer.getPath());
092: boolean header = jEdit.getBooleanProperty("print.header");
093: boolean footer = jEdit.getBooleanProperty("print.footer");
094: boolean lineNumbers = jEdit
095: .getBooleanProperty("print.lineNumbers");
096: boolean color = jEdit.getBooleanProperty("print.color");
097: Font font = jEdit.getFontProperty("print.font");
098:
099: BufferPrintable printable = new BufferPrintable(job, null,
100: view, buffer, font, header, footer, lineNumbers, color);
101: job.setPrintable(printable, format);
102:
103: if (!job.printDialog())
104: return;
105:
106: printable.print();
107: } //}}}
108:
109: //{{{ getPageFormat() method
110: public static PageFormat getPageFormat() {
111: return format;
112: } //}}}
113:
114: //{{{ Private members
115: private static PageFormat format;
116: private static PrinterJob job;
117: //}}}
118: }
|