Java 类java.awt.PrintGraphics 实例源码

项目:LGoodDatePicker    文件:RenderingUtils.java   
private static boolean isPrinting(Graphics g) {
    return g instanceof PrintGraphics || g instanceof PrinterGraphics;
}
项目:JCheckboxTree    文件:RenderingUtils.java   
private static boolean isPrinting(Graphics g) {
    return g instanceof PrintGraphics || g instanceof PrinterGraphics;
}
项目:confluence.keygen    文件:RenderingUtils.java   
private static boolean isPrinting(Graphics g)
/* 113:    */   {
/* 114:190 */     return ((g instanceof PrintGraphics)) || ((g instanceof PrinterGraphics));
/* 115:    */   }
项目:jif    文件:Utils.java   
private void printLongString(PrintJob pjob, Graphics pg, String s) {

        // Replacing the TABS with spaces
        s = Utils.replace(s, "\t", "    ");

        int margin = 50;
        int pageNum = 1;
        int linesForThisPage = 0;
        int linesForThisJob = 0;
        // Note: String is immutable so won't change while printing.
        if (!(pg instanceof PrintGraphics)) {
            throw new IllegalArgumentException("Graphics context not PrintGraphics");
        }
        StringReader sr = new StringReader(s);
        LineNumberReader lnr = new LineNumberReader(sr);
        String nextLine;
        int pageHeight = pjob.getPageDimension().height - margin;
        Font helv = new Font("Monospaced", Font.PLAIN, 8);
        //have to set the font to get any output
        pg.setFont(helv);
        FontMetrics fm = pg.getFontMetrics(helv);
        int fontHeight = fm.getHeight();
        int fontDescent = fm.getDescent();
        int curHeight = margin;
        try {
            do {
                nextLine = lnr.readLine();
                if (nextLine != null) {
                    if ((curHeight + fontHeight) > pageHeight) {
                        // New Page
                        //System.out.println ("" + linesForThisPage + " lines printed for page " + pageNum);
                        if (linesForThisPage == 0) {
                            //System.out.println ("Font is too big for pages of this size; aborting...");
                            break;
                        }
                        pageNum++;
                        linesForThisPage = 0;
                        pg.dispose();
                        pg = pjob.getGraphics();
                        if (pg != null) {
                            pg.setFont(helv);
                        }
                        curHeight = 0;
                    }
                    curHeight += fontHeight;
                    if (pg != null) {
                        pg.drawString(nextLine, margin, curHeight - fontDescent);
                        linesForThisPage++;

                        linesForThisJob++;
                    } else {
                        //System.out.println ("pg null");
                    }
                }
            } while (nextLine != null);
        } catch (EOFException eof) {
            // Fine, ignore
        } catch (Throwable t) { // Anything else
            t.printStackTrace();
        }
        //System.out.println ("" + linesForThisPage + " lines printed for page " + pageNum);
        //System.out.println ("pages printed: " + pageNum);
        //System.out.println ("total lines printed: " + linesForThisJob);
    }
项目:IBMDataMovementTool    文件:RenderingUtils.java   
private static boolean isPrinting(Graphics g)
{
  return ((g instanceof PrintGraphics)) || ((g instanceof PrinterGraphics));
}