PageRenderTime 320ms CodeModel.GetById 313ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/print/BufferPrinter1_3.java

#
Java | 116 lines | 70 code | 15 blank | 31 comment | 5 complexity | 4ed41ab20d9c58c39a3483ec73b36dab MD5 | raw file
  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 javax.swing.SwingUtilities;
 28import java.awt.print.*;
 29import java.awt.*;
 30import org.gjt.sp.jedit.*;
 31import org.gjt.sp.util.Log;
 32import org.gjt.sp.jedit.io.VFSManager;
 33//}}}
 34
 35public class BufferPrinter1_3
 36{
 37	//{{{ getPrintJob() method
 38	private static PrinterJob getPrintJob()
 39	{
 40		job = PrinterJob.getPrinterJob();
 41
 42		int orientation = jEdit.getIntegerProperty("print.orientation",PageFormat.PORTRAIT);
 43		double width = jEdit.getDoubleProperty("print.width",0);
 44		double height = jEdit.getDoubleProperty("print.height",0);
 45		double x = jEdit.getDoubleProperty("print.x",0);
 46		double y = jEdit.getDoubleProperty("print.y",0);
 47		double pagewidth = jEdit.getDoubleProperty("print.pagewidth",0);
 48		double pageheight = jEdit.getDoubleProperty("print.pageheight",0);
 49
 50		format = job.defaultPage();
 51		//format.setOrientation(PageFormat.PORTRAIT);
 52		if(width!=0 && height!=0 )
 53		{
 54			Paper pap = format.getPaper();
 55			pap.setImageableArea(x,y,width,height);
 56			pap.setSize(pagewidth,pageheight);
 57			format.setPaper(pap);
 58		}
 59		format.setOrientation(orientation);
 60		return job;
 61
 62	}//}}}
 63
 64	//{{{ pageSetup() method
 65	public static void pageSetup(View view)
 66	{
 67		job = getPrintJob();
 68
 69		PageFormat newFormat = job.pageDialog(format);
 70		if(newFormat != null)
 71		{
 72			format = newFormat;
 73			jEdit.setIntegerProperty("print.orientation",format.getOrientation());
 74			Paper paper=format.getPaper();
 75
 76			jEdit.setDoubleProperty("print.width",paper.getImageableWidth());
 77			jEdit.setDoubleProperty("print.height",paper.getImageableHeight());
 78			jEdit.setDoubleProperty("print.x",paper.getImageableX());
 79			jEdit.setDoubleProperty("print.y",paper.getImageableY());
 80			jEdit.setDoubleProperty("print.pagewidth",paper.getWidth());
 81			jEdit.setDoubleProperty("print.pageheight",paper.getHeight());
 82		}
 83	} //}}}
 84
 85	//{{{ print() method
 86	public static void print(final View view, final Buffer buffer, boolean selection)
 87	{
 88		job = getPrintJob();
 89		job.setJobName(buffer.getPath());
 90		boolean header = jEdit.getBooleanProperty("print.header");
 91		boolean footer = jEdit.getBooleanProperty("print.footer");
 92		boolean lineNumbers = jEdit.getBooleanProperty("print.lineNumbers");
 93		boolean color = jEdit.getBooleanProperty("print.color");
 94		Font font = jEdit.getFontProperty("print.font");
 95
 96		BufferPrintable printable = new BufferPrintable(job,null,view,
 97			buffer,font,header,footer,lineNumbers,color);
 98		job.setPrintable(printable,format);
 99
100		if(!job.printDialog())
101			return;
102
103		VFSManager.runInWorkThread(printable);
104	} //}}}
105
106	//{{{ getPageFormat() method
107	public static PageFormat getPageFormat()
108	{
109		return format;
110	} //}}}
111
112	//{{{ Private members
113	private static PageFormat format;
114	private static PrinterJob job;
115	//}}}
116}