Java Code Examples for java.awt.print.Paper#getWidth()

The following examples show how to use java.awt.print.Paper#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PageFormatSerializer.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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.
 */
private 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 };
}
 
Example 2
Source File: PSPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 3
Source File: RasterPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 4
Source File: StyleFileWriter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Compiles a collection of page format properties.
 *
 * @param fmt
 *          the pageformat
 * @param retval
 *          the attribute list
 * @return The properties.
 */
private static AttributeList buildPageFormatProperties( final PageFormat fmt, final AttributeList retval ) {
  if ( fmt == null ) {
    throw new NullPointerException();
  }
  if ( retval == null ) {
    throw new NullPointerException();
  }

  final Paper paper = fmt.getPaper();
  final int w = (int) paper.getWidth();
  final int h = (int) paper.getHeight();

  final String pageDefinition = PageFormatFactory.getInstance().getPageFormatName( w, h );
  if ( pageDefinition != null ) {
    retval.setAttribute( BundleNamespaces.STYLE, "pageformat", pageDefinition );
  } else {
    retval.setAttribute( BundleNamespaces.STYLE, "width", String.valueOf( w ) );
    retval.setAttribute( BundleNamespaces.STYLE, "height", String.valueOf( h ) );
  }

  final Insets borders = getBorders( paper );

  if ( fmt.getOrientation() == PageFormat.REVERSE_LANDSCAPE ) {
    retval.setAttribute( BundleNamespaces.STYLE, "orientation", "reverse-landscape" );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-top", String.valueOf( borders.right ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-left", String.valueOf( borders.top ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-bottom", String.valueOf( borders.left ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-right", String.valueOf( borders.bottom ) );
  } else if ( fmt.getOrientation() == PageFormat.PORTRAIT ) {
    retval.setAttribute( BundleNamespaces.STYLE, "orientation", "portrait" );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-top", String.valueOf( borders.top ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-left", String.valueOf( borders.left ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-bottom", String.valueOf( borders.bottom ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-right", String.valueOf( borders.right ) );
  } else {
    retval.setAttribute( BundleNamespaces.STYLE, "orientation", "landscape" );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-top", String.valueOf( borders.left ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-left", String.valueOf( borders.bottom ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-bottom", String.valueOf( borders.right ) );
    retval.setAttribute( BundleNamespaces.STYLE, "margin-right", String.valueOf( borders.top ) );
  }

  return retval;
}
 
Example 5
Source File: RasterPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 6
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 7
Source File: PSPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 8
Source File: RasterPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 9
Source File: PSPrinterJob.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 10
Source File: RasterPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 11
Source File: PSPrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 12
Source File: RasterPrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 13
Source File: PSPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 14
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 15
Source File: PSPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 16
Source File: RasterPrinterJob.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
Example 17
Source File: PSPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 18
Source File: PSPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 19
Source File: PSPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected double getPhysicalPageWidth(Paper p) {
    return p.getWidth();
}
 
Example 20
Source File: PageFormatFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are
 * given in points.
 *
 * @param paper
 *          the paper that should be modified
 * @param top
 *          the bordersize of the top-border
 * @param left
 *          the border in points in the left
 * @param bottom
 *          the border in points in the bottom
 * @param right
 *          the border in points in the right
 */
public void setBorders( final Paper paper, final double top, final double left, final double bottom,
    final double right ) {
  final double w = paper.getWidth() - ( right + left );
  final double h = paper.getHeight() - ( bottom + top );
  paper.setImageableArea( left, top, w, h );
}