1 23 24 package org.gjt.sp.jedit.print; 25 26 import java.awt.print.*; 28 import java.awt.*; 29 import org.gjt.sp.jedit.*; 30 32 public class BufferPrinter1_3 33 { 34 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 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 } 61 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 } 82 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 } 103 public static PageFormat getPageFormat() 105 { 106 return format; 107 } 109 private static PageFormat format; 111 private static PrinterJob job; 112 } 114 | Popular Tags |