Java Code Examples for java.awt.print.PageFormat#LANDSCAPE

The following examples show how to use java.awt.print.PageFormat#LANDSCAPE . 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: PrintLayout.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * This describes a <code>PageFormat</code> as a String. This is provided as
 * a debugging tool, because <code>PageFormat.toString()</code> doesn't
 * support this itself.
 */
public static String toString(PageFormat f) {
	if (f == null)
		return "null";
	String orientation;
	if (f.getOrientation() == PageFormat.LANDSCAPE) {
		orientation = "LANDSCAPE";
	} else if (f.getOrientation() == PageFormat.PORTRAIT) {
		orientation = "PORTRAIT";
	} else if (f.getOrientation() == PageFormat.REVERSE_LANDSCAPE) {
		orientation = "REVERSE_LANDSCAPE";
	} else {
		orientation = "UNKNOWN";
	}
	return ("PageFormat[ " + f.getWidth() + "x" + f.getHeight()
			+ " imageable=(" + f.getImageableX() + ", " + f.getImageableY()
			+ ", " + f.getImageableWidth() + ", " + f.getImageableHeight()
			+ ") orientation=" + orientation + "]");
}
 
Example 2
Source File: PrintLayout.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Sets the orientation for this page. This also validates the imageable
 * bounds of the paper.
 * 
 * @param orientation
 *            must be PageFormat.LANDSCAPE or PageFormat.PORTRAIT
 */
public boolean setOrientation(int orientation) {
	if (!(orientation == PageFormat.LANDSCAPE || orientation == PageFormat.PORTRAIT))
		throw new IllegalArgumentException(
				"orientation must be PageFormat.LANDSCAPE or PageFormat.PORTRAIT");
	if (orientation == pageFormat.getOrientation())
		return false;
	int oldOrientation = pageFormat.getOrientation();
	pageFormat.setOrientation(orientation);
	firePropertyChange(PROPERTY_ORIENTATION, new Integer(oldOrientation),
			new Integer(orientation));

	validateImageableBounds();

	return true;
}
 
Example 3
Source File: Options.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public static void setPageFormat(String name, PageFormat pageFormat) {
    Properties properties = getProperties(name);
    switch (pageFormat.getOrientation()) {
        case PageFormat.LANDSCAPE:
            properties.setProperty(ORIENTATION, LANDSCAPE);
            break;
        case PageFormat.PORTRAIT:
            properties.setProperty(ORIENTATION, PORTRAIT);
            break;
        case PageFormat.REVERSE_LANDSCAPE:
            properties.setProperty(ORIENTATION, REVERSE_LANDSCAPE);
            break;
        default:
            properties.setProperty(ORIENTATION, "EMPTY");
    }
    ;
    final Paper paper = pageFormat.getPaper();
    properties.setProperty(PAPER_IMAGEABLE_HEIGHT, Double.toString(paper
            .getImageableHeight()));
    properties.setProperty(PAPER_IMAGEABLE_WIDTH, Double.toString(paper
            .getImageableWidth()));
    properties.setProperty(PAPER_IMAGEABLE_X, Double.toString(paper
            .getImageableX()));
    properties.setProperty(PAPER_IMAGEABLE_Y, Double.toString(paper
            .getImageableY()));
    properties
            .setProperty(PAPER_HEIGHT, Double.toString(paper.getHeight()));
    properties.setProperty(PAPER_WIDTH, Double.toString(paper.getWidth()));
}
 
Example 4
Source File: PrintPreviewPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public void setPageFormat(PageFormat pageFormat) {
	this.pageFormat = pageFormat;
	remove(landscapePanel);
	remove(portraitPanel);
	add(landscapePanel, Orientation.LANDSCAPE.toString());
	add(portraitPanel, Orientation.PORTRAIT.toString());
	if (pageFormat.getOrientation() == PageFormat.LANDSCAPE) {
		cardLayout.show(this, Orientation.LANDSCAPE.toString());
	} else {
		cardLayout.show(this, Orientation.PORTRAIT.toString());
	}
	repaint();
}
 
Example 5
Source File: Java14PrintUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static OrientationRequested mapOrientation( final int orientation ) {
  switch ( orientation ) {
    case PageFormat.LANDSCAPE:
      return OrientationRequested.LANDSCAPE;
    case PageFormat.REVERSE_LANDSCAPE:
      return OrientationRequested.REVERSE_LANDSCAPE;
    case PageFormat.PORTRAIT:
      return OrientationRequested.PORTRAIT;
    default:
      throw new IllegalArgumentException( "The given value is no valid PageFormat orientation." );
  }
}
 
Example 6
Source File: PageDefinitionReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Handles the page format.
 *
 * @param atts
 *          the attributes.
 * @throws SAXException
 *           if a parser error occurs or the validation failed.
 * @noinspection SuspiciousNameCombination
 */
private PageFormat configurePageSizeAndMargins( final Attributes atts, PageFormat format ) throws SAXException {
  // (1) Grab the existing default ...
  float defTopMargin = (float) format.getImageableY();
  float defBottomMargin = (float) ( format.getHeight() - format.getImageableHeight() - format.getImageableY() );
  float defLeftMargin = (float) format.getImageableX();
  float defRightMargin = (float) ( format.getWidth() - format.getImageableWidth() - format.getImageableX() );

  // (2) Now configure the new paper-size
  format = configurePageSize( format, atts );

  // (3) Reconfigure margins as requested
  defTopMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-top" ), defTopMargin );
  defBottomMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-bottom" ), defBottomMargin );
  defLeftMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-left" ), defLeftMargin );
  defRightMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-right" ), defRightMargin );

  final Paper p = format.getPaper();
  switch ( format.getOrientation() ) {
    case PageFormat.PORTRAIT:
      PageFormatFactory.getInstance().setBorders( p, defTopMargin, defLeftMargin, defBottomMargin, defRightMargin );
      break;
    case PageFormat.REVERSE_LANDSCAPE:
      PageFormatFactory.getInstance().setBorders( p, defLeftMargin, defBottomMargin, defRightMargin, defTopMargin );
      break;
    case PageFormat.LANDSCAPE:
      PageFormatFactory.getInstance().setBorders( p, defRightMargin, defTopMargin, defLeftMargin, defBottomMargin );
      break;
    default:
      // will not happen..
      throw new IllegalArgumentException( "Unexpected paper orientation." );
  }

  format.setPaper( p );
  return format;
}
 
Example 7
Source File: PageReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Handles the page format.
 *
 * @param atts
 *          the attributes.
 * @throws SAXException
 *           if a parser error occurs or the validation failed.
 * @noinspection SuspiciousNameCombination
 */
private void handlePageFormat( final Attributes atts ) throws SAXException {
  final MasterReport report =
      (MasterReport) getRootHandler().getHelperObject( ReportParserUtil.HELPER_OBJ_REPORT_NAME );

  // grab the default page definition ...
  PageFormat format = report.getPageDefinition().getPageFormat( 0 );
  float defTopMargin = (float) format.getImageableY();
  float defBottomMargin = (float) ( format.getHeight() - format.getImageableHeight() - format.getImageableY() );
  float defLeftMargin = (float) format.getImageableX();
  float defRightMargin = (float) ( format.getWidth() - format.getImageableWidth() - format.getImageableX() );

  format = createPageFormat( format, atts );

  defTopMargin = ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.TOPMARGIN_ATT ), defTopMargin );
  defBottomMargin =
      ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.BOTTOMMARGIN_ATT ), defBottomMargin );
  defLeftMargin = ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.LEFTMARGIN_ATT ), defLeftMargin );
  defRightMargin = ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.RIGHTMARGIN_ATT ), defRightMargin );

  final Paper p = format.getPaper();
  switch ( format.getOrientation() ) {
    case PageFormat.PORTRAIT:
      PageFormatFactory.getInstance().setBorders( p, defTopMargin, defLeftMargin, defBottomMargin, defRightMargin );
      break;
    case PageFormat.LANDSCAPE:
      // right, top, left, bottom
      PageFormatFactory.getInstance().setBorders( p, defRightMargin, defTopMargin, defLeftMargin, defBottomMargin );
      break;
    case PageFormat.REVERSE_LANDSCAPE:
      PageFormatFactory.getInstance().setBorders( p, defLeftMargin, defBottomMargin, defRightMargin, defTopMargin );
      break;
    default:
      // will not happen..
      throw new IllegalArgumentException( "Unexpected paper orientation." );
  }

  format.setPaper( p );
  pageFormat = format;
}
 
Example 8
Source File: Impressor.java    From brModelo with GNU General Public License v3.0 4 votes vote down vote up
public boolean isLandscape() {
    return (Impressora.getPage().getOrientation() == PageFormat.LANDSCAPE);
}
 
Example 9
Source File: SizeReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public CSSValue createValue( StyleKey name, LexicalUnit value ) {
  if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) {
    String ident = value.getStringValue();
    if ( ident.equalsIgnoreCase( "auto" ) ) {
      return CSSAutoValue.getInstance();
    }
    final PageSize ps = PageSizeFactory.getInstance().getPageSizeByName( ident );
    if ( ps == null ) {
      return null;
    }

    value = value.getNextLexicalUnit();
    int pageOrientation = PageFormat.PORTRAIT;
    if ( value != null ) {
      if ( value.getLexicalUnitType() != LexicalUnit.SAC_IDENT ) {
        return null;
      }

      if ( value.getStringValue().equalsIgnoreCase( "landscape" ) ) {
        pageOrientation = PageFormat.LANDSCAPE;
      } else if ( value.getStringValue().equalsIgnoreCase( "reverse-landscape" ) ) {
        pageOrientation = PageFormat.REVERSE_LANDSCAPE;
      } else if ( value.getStringValue().equalsIgnoreCase( "portrait" ) ) {
        pageOrientation = PageFormat.PORTRAIT;
      } else {
        return null;
      }
    }

    if ( pageOrientation == PageFormat.LANDSCAPE ||
      pageOrientation == PageFormat.REVERSE_LANDSCAPE ) {
      return new CSSValuePair( CSSNumericValue.createPtValue( ps.getHeight() ),
        CSSNumericValue.createPtValue( ps.getWidth() ) );
    } else {
      return new CSSValuePair( CSSNumericValue.createPtValue( ps.getWidth() ),
        CSSNumericValue.createPtValue( ps.getHeight() ) );
    }
  } else {
    final CSSNumericValue horizontalWidth = (CSSNumericValue) parseWidth( value );
    if ( horizontalWidth == null ) {
      return null;
    }

    value = value.getNextLexicalUnit();

    final CSSNumericValue verticalWidth;
    if ( value == null ) {
      verticalWidth = horizontalWidth;
    } else {
      verticalWidth = (CSSNumericValue) parseWidth( value );
      if ( verticalWidth == null ) {
        return null;
      }
    }

    return new CSSValuePair( horizontalWidth, verticalWidth );
  }
}
 
Example 10
Source File: ReportConfigWriter.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.
 *
 * @return The properties.
 */
private AttributeList buildPageFormatProperties( final PageFormat fmt ) {
  final AttributeList retval = new AttributeList();
  final int[] borders = getBorders( fmt.getPaper() );

  if ( fmt.getOrientation() == PageFormat.LANDSCAPE ) {
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.ORIENTATION_ATT,
        ReportConfigWriter.ORIENTATION_LANDSCAPE_VAL );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.TOPMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.RIGHT_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.LEFTMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.TOP_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.BOTTOMMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.LEFT_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.RIGHTMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.BOTTOM_BORDER] ) );
  } else if ( fmt.getOrientation() == PageFormat.PORTRAIT ) {
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.ORIENTATION_ATT,
        ReportConfigWriter.ORIENTATION_PORTRAIT_VAL );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.TOPMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.TOP_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.LEFTMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.LEFT_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.BOTTOMMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.BOTTOM_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.RIGHTMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.RIGHT_BORDER] ) );
  } else {
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.ORIENTATION_ATT,
        ReportConfigWriter.ORIENTATION_REVERSE_LANDSCAPE_VAL );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.TOPMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.LEFT_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.LEFTMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.BOTTOM_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.BOTTOMMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.RIGHT_BORDER] ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.RIGHTMARGIN_ATT, String
        .valueOf( borders[ReportConfigWriter.TOP_BORDER] ) );
  }

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

  final String pageDefinition = PageFormatFactory.getInstance().getPageFormatName( w, h );
  if ( pageDefinition != null ) {
    retval.setAttribute( ExtParserModule.NAMESPACE, ReportConfigWriter.PAGEFORMAT_ATT, pageDefinition );
  } else {
    retval.setAttribute( ExtParserModule.NAMESPACE, AbstractXMLDefinitionWriter.WIDTH_ATT, String.valueOf( w ) );
    retval.setAttribute( ExtParserModule.NAMESPACE, AbstractXMLDefinitionWriter.HEIGHT_ATT, String.valueOf( h ) );
  }
  return retval;
}
 
Example 11
Source File: PhysicalPageDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * @param pageDrawable
 * @param page
 * @noinspection SuspiciousNameCombination
 */
public PhysicalPageDrawable( final LogicalPageDrawable pageDrawable, final PhysicalPageBox page ) {
  if ( pageDrawable == null ) {
    throw new NullPointerException();
  }
  if ( page == null ) {
    throw new NullPointerException();
  }

  this.pageDrawable = pageDrawable;

  this.globalX = page.getGlobalX();
  this.globalY = page.getGlobalY();

  final Paper p = new Paper();

  final float marginLeft = (float) StrictGeomUtility.toExternalValue( page.getImageableX() );
  final float marginRight =
      (float) StrictGeomUtility.toExternalValue( page.getWidth() - page.getImageableWidth() - page.getImageableX() );
  final float marginTop = (float) StrictGeomUtility.toExternalValue( page.getImageableY() );
  final float marginBottom =
      (float) StrictGeomUtility.toExternalValue( page.getHeight() - page.getImageableHeight() - page.getImageableY() );
  switch ( page.getOrientation() ) {
    case PageFormat.PORTRAIT:
      p.setSize( StrictGeomUtility.toExternalValue( page.getWidth() ), StrictGeomUtility.toExternalValue( page
          .getHeight() ) );
      PageFormatFactory.getInstance().setBorders( p, marginTop, marginLeft, marginBottom, marginRight );
      break;
    case PageFormat.LANDSCAPE:
      // right, top, left, bottom
      p.setSize( StrictGeomUtility.toExternalValue( page.getHeight() ), StrictGeomUtility.toExternalValue( page
          .getWidth() ) );
      PageFormatFactory.getInstance().setBorders( p, marginRight, marginTop, marginLeft, marginBottom );
      break;
    case PageFormat.REVERSE_LANDSCAPE:
      p.setSize( StrictGeomUtility.toExternalValue( page.getHeight() ), StrictGeomUtility.toExternalValue( page
          .getWidth() ) );
      PageFormatFactory.getInstance().setBorders( p, marginLeft, marginBottom, marginRight, marginTop );
      break;
    default:
      // will not happen..
      throw new IllegalArgumentException( "Unexpected page-orientation encountered." );
  }

  this.pageFormat = new PageFormat();
  this.pageFormat.setPaper( p );
  this.pageFormat.setOrientation( page.getOrientation() );
}