Example usage for java.awt.print Paper getImageableWidth

List of usage examples for java.awt.print Paper getImageableWidth

Introduction

In this page you can find the example usage for java.awt.print Paper getImageableWidth.

Prototype

public double getImageableWidth() 

Source Link

Document

Returns the width of this Paper object's imageable area.

Usage

From source file:PageFormatFactory.java

/**
 * Logs the paper size./*from w w  w.java 2 s  .  com*/
 *
 * @param pf the paper size.
 */
public static void logPaper(final Paper pf) {
    System.out.println("Paper: Width: " + pf.getWidth() + " Height: " + pf.getHeight());
    System.out.println("Paper: Image: X " + pf.getImageableX() + " Y " + pf.getImageableY() + " H: "
            + pf.getImageableHeight() + " W: " + pf.getImageableWidth());
}

From source file:PageFormatFactory.java

/**
 * Tests, whether the given two page format objects are equal.
 *
 * @param pf1 the first page format that should be compared.
 * @param pf2 the second page format that should be compared.
 * @return true, if both page formats are equal, false otherwise.
 *///w  ww  .  jav a2  s  .co  m
public static boolean isEqual(final PageFormat pf1, final PageFormat pf2) {
    if (pf1 == pf2) {
        return true;
    }
    if (pf1 == null || pf2 == null) {
        return false;
    }

    if (pf1.getOrientation() != pf2.getOrientation()) {
        return false;
    }
    final Paper p1 = pf1.getPaper();
    final Paper p2 = pf2.getPaper();

    if (p1.getWidth() != p2.getWidth()) {
        return false;
    }
    if (p1.getHeight() != p2.getHeight()) {
        return false;
    }
    if (p1.getImageableX() != p2.getImageableX()) {
        return false;
    }
    if (p1.getImageableY() != p2.getImageableY()) {
        return false;
    }
    if (p1.getImageableWidth() != p2.getImageableWidth()) {
        return false;
    }
    if (p1.getImageableHeight() != p2.getImageableHeight()) {
        return false;
    }
    return true;
}

From source file:PageFormatFactory.java

/**
 * Returns the right border of the given paper.
 *
 * @param p the paper that defines the borders.
 * @return the right border./*from   w  w  w  . j  ava2 s  . c  o m*/
 */
public double getRightBorder(final Paper p) {
    return p.getWidth() - (p.getImageableX() + p.getImageableWidth());
}

From source file:PageFormatFactory.java

/**
 * Resolves a page format, so that the result can be serialized.
 *
 * @param format the page format that should be prepared for serialisation.
 * @return the prepared page format data.
 * @deprecated This functionality is part of JCommon-Serializer
 *//*from w  w w  .  j  a  v  a  2  s.c om*/
public Object[] resolvePageFormat(final PageFormat format) {
    final Integer orientation = new Integer(format.getOrientation());
    final Paper p = format.getPaper();
    final float[] fdim = new float[] { (float) p.getWidth(), (float) p.getHeight() };
    final float[] rect = new float[] { (float) p.getImageableX(), (float) p.getImageableY(),
            (float) p.getImageableWidth(), (float) p.getImageableHeight() };
    return new Object[] { orientation, fdim, rect };
}

From source file:lu.fisch.unimozer.Diagram.java

@Override
public int print(Graphics g, PageFormat pageFormat, int page) throws PrinterException {
    /*/*from  w w w. ja va2s.c om*/
        // clone paper
        Paper originalPaper = pageFormat.getPaper();
        Paper paper = new Paper();
        // resize it
        paper.setSize(originalPaper.getWidth(), originalPaper.getHeight());
        paper.setImageableArea(
                originalPaper.getImageableX(),
                originalPaper.getImageableY()+30,
                originalPaper.getImageableWidth(),
                originalPaper.getImageableHeight()-60);
        // apply it
        pageFormat.setPaper(paper);
    */
    /*                Paper paper = new Paper();
        paper.setSize(pageFormat.getWidth(),pageFormat.getHeight());
                
        double paddingLeftRight = pageFormat.getImageableX();
        double paddingTopBottom = pageFormat.getImageableY()+30;
        if (pageFormat.getOrientation()==PageFormat.LANDSCAPE)
        {
            paddingLeftRight = 60;
            paddingTopBottom = 60;
        }
        paper.setImageableArea(paddingLeftRight,
                               paddingTopBottom,
                               pageFormat.getWidth()-2*paddingLeftRight,
                               pageFormat.getHeight()-2*paddingTopBottom);
        pageFormat.setPaper(paper);*/

    if (page == 0) {
        pageList.clear();
        if (printOptions.printCode() == true) {
            /*Set<String> set = classes.keySet();
            Iterator<String> itr = set.iterator();
            while (itr.hasNext())
            {
              String str = itr.next();*/

            /* let's try this one ... */
            for (Entry<String, MyClass> entry : classes.entrySet()) {
                // get the actual class ...
                String str = entry.getKey();

                MyClass thisClass = classes.get(str);
                CodeEditor edit = new CodeEditor();
                edit.setFont(new Font(edit.getFont().getName(), Font.PLAIN, printOptions.getFontSize()));

                String code = "";
                // get code, depending on JavaDoc filter
                if (printOptions.printJavaDoc())
                    code = thisClass.getContent().getText();
                else
                    code = thisClass.getJavaCodeCommentless();

                // filter double lines
                if (printOptions.filterDoubleLines()) {
                    StringList sl = StringList.explode(code, "\n");
                    sl.removeDoubleEmptyLines();
                    code = sl.getText();
                }

                //edit.setDiagram(diagram);
                edit.setCode(code);

                // resize the picture
                PageFormat pf = (PageFormat) pageFormat.clone();
                Paper pa = pf.getPaper();
                pa.setImageableArea(pa.getImageableX(), pa.getImageableY() + 20, pa.getImageableWidth(),
                        pa.getImageableHeight() - 40);
                pf.setPaper(pa);

                //sheets = new Vector<BufferedImage>();
                int p = 0;
                int result = 0;
                do {
                    /*BufferedImage img = new BufferedImage((int) pageFormat.getImageableWidth(),(int) pageFormat.getImageableHeight(),BufferedImage.TYPE_INT_RGB );
                    img.getGraphics().setColor(Color.WHITE);
                    img.getGraphics().fillRect(0,0,(int) pageFormat.getImageableWidth(),(int) pageFormat.getImageableHeight());*/

                    BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
                    result = edit.print(img.createGraphics(), pf, p);
                    if (result == PAGE_EXISTS) {
                        //sheets.add(img);
                        pageList.add(str);
                        p++;
                    }
                } while (result == PAGE_EXISTS);

                //edit.print(g, pf, p);
                edit = null;
                System.gc();
            }
        }
    }

    if (page == 0 && printOptions.printDiagram() == true) {
        Graphics2D g2d = (Graphics2D) g;

        int yOffset = (int) pageFormat.getImageableY();

        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

        double sX = (pageFormat.getImageableWidth() - 1) / getDiagramWidth();
        double sY = (pageFormat.getImageableHeight() - 1 - 40) / getDiagramHeight();
        double sca = Math.min(sX, sY);
        if (sca > 1) {
            sca = 1;
        }
        g2d.translate(0, 20);
        g2d.scale(sca, sca);

        paint(g2d);

        g2d.scale(1 / sca, 1 / sca);
        g2d.translate(0, -(20));
        g2d.translate(-pageFormat.getImageableX(), -pageFormat.getImageableY());

        printHeaderFooter(g2d, pageFormat, page, new String());

        PageFormat pf = (PageFormat) pageFormat.clone();
        Paper pa = pf.getPaper();
        pa.setImageableArea(pa.getImageableX(), pa.getImageableY() + 20, pa.getImageableWidth(),
                pa.getImageableHeight() - 40);
        pf.setPaper(pa);

        // reset the paper
        //pageFormat.setPaper(originalPaper);
        return (PAGE_EXISTS);
    } else {
        int origPage = page;

        if (printOptions.printDiagram() == true)
            page--;

        if (page >= pageList.size() || printOptions.printCode() == false)
            return (NO_SUCH_PAGE);
        else {
            String mc = pageList.get(page);
            page--;
            int p = 0;
            while (page >= 0) {
                if (pageList.get(page).equals(mc))
                    p++;
                page--;
            }
            MyClass thisClass = classes.get(mc);

            CodeEditor edit = new CodeEditor();
            edit.setFont(new Font(edit.getFont().getName(), Font.PLAIN, printOptions.getFontSize()));

            String code = "";
            // get code, depending on JavaDoc filter
            if (printOptions.printJavaDoc())
                code = thisClass.getContent().getText();
            else
                code = thisClass.getJavaCodeCommentless();

            // filter double lines
            if (printOptions.filterDoubleLines()) {
                StringList sl = StringList.explode(code, "\n");
                sl.removeDoubleEmptyLines();
                code = sl.getText();
            }

            edit.setCode(code);

            printHeaderFooter(g, pageFormat, origPage, thisClass.getShortName());

            PageFormat pf = (PageFormat) pageFormat.clone();
            Paper pa = pf.getPaper();
            pa.setImageableArea(pa.getImageableX(), pa.getImageableY() + 20, pa.getImageableWidth(),
                    pa.getImageableHeight() - 40);
            pf.setPaper(pa);

            edit.print(g, pf, p);
            edit = null;
            System.gc();

            // reset the paper
            //pageFormat.setPaper(originalPaper);
            return (PAGE_EXISTS);
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.util.PageFormatFactory.java

private static String printPaper(final Paper paper) {
    StringBuffer b = new StringBuffer();
    b.append("Paper={width=");
    b.append(paper.getWidth());//from  w ww.j av  a  2 s . c  o  m
    b.append(", height=");
    b.append(paper.getHeight());
    b.append(", imageableX=");
    b.append(paper.getImageableX());
    b.append(", imageableY=");
    b.append(paper.getImageableY());
    b.append(", imageableWidth=");
    b.append(paper.getImageableWidth());
    b.append(", imageableHeight=");
    b.append(paper.getImageableHeight());
    b.append("}");
    return b.toString();
}

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

/**
 * This method replaces the media definition from the given attribute set with the one found in the report itself.
 * <p/>/*from   www  . j  av  a 2  s  . c  om*/
 * If no JobName is set, a default jobname will be assigned.
 *
 * @param attributes
 * @param report
 * @return
 */
public static PrintRequestAttributeSet copyConfiguration(PrintRequestAttributeSet attributes,
        final MasterReport report) {
    if (attributes == null) {
        attributes = new HashPrintRequestAttributeSet();
    }

    // for now, be lazy, assume that the first page is the reference
    final PageDefinition pdef = report.getPageDefinition();
    final PageFormat format = pdef.getPageFormat(0);
    final Paper paper = format.getPaper();

    final Media media = MediaSize.findMedia((float) (paper.getWidth() / POINTS_PER_INCH),
            (float) (paper.getHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);
    attributes.add(media);

    final MediaPrintableArea printableArea = new MediaPrintableArea(
            (float) (paper.getImageableX() / POINTS_PER_INCH),
            (float) (paper.getImageableY() / POINTS_PER_INCH),
            (float) (paper.getImageableWidth() / POINTS_PER_INCH),
            (float) (paper.getImageableHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);

    attributes.add(printableArea);
    attributes.add(mapOrientation(format.getOrientation()));

    return attributes;
}