1 14 package org.compiere.apps; 15 16 import java.awt.*; 17 import java.awt.print.*; 18 import javax.swing.*; 19 import java.util.*; 20 21 import org.compiere.util.*; 22 import org.compiere.print.*; 23 24 30 public class PrintScreenPainter implements Pageable, Printable 31 { 32 36 public PrintScreenPainter (Window element) 37 { 38 m_element = element; 39 } 41 42 private Window m_element; 43 44 48 public int getNumberOfPages() 49 { 50 return 1; 51 } 53 59 public Printable getPrintable(int pageIndex) throws java.lang.IndexOutOfBoundsException 60 { 61 return this; 62 } 64 70 public PageFormat getPageFormat(int pageIndex) throws java.lang.IndexOutOfBoundsException 71 { 72 CPaper paper = new CPaper(false); 73 return paper.getPageFormat(); 74 } 76 84 public int print (Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException 85 { 86 if (pageIndex > 0) 88 return Printable.NO_SUCH_PAGE; 89 Graphics2D g2 = (Graphics2D) graphics; 91 92 g2.translate (pageFormat.getImageableX(), pageFormat.getImageableY()); 94 95 String header = Msg.getMsg(Env.getCtx(), "PrintScreen") + " - " 97 + DisplayType.getDateFormat(DisplayType.DateTime).format(new Date()); 98 int y = g2.getFontMetrics().getHeight(); g2.drawString(header, 0, y); 100 g2.translate (0, 2*y); 102 103 double xRatio = pageFormat.getImageableWidth() / m_element.getSize().width; 104 double yRatio = (pageFormat.getImageableHeight() - 2*y) / m_element.getSize().height; 105 double ratio = Math.min(Math.min(xRatio, yRatio), 1.0); 107 g2.scale (ratio, ratio); 108 m_element.printAll (g2); 110 111 return Printable.PAGE_EXISTS; 112 } 114 115 116 120 public static void printScreen (Window element) 121 { 122 PrintUtil.print(new PrintScreenPainter(element), null, "PrintScreen", 1, false); 123 } 125 } | Popular Tags |