Java Code Examples for java.awt.print.PageFormat#getOrientation()

The following examples show how to use java.awt.print.PageFormat#getOrientation() . 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: PageSetupDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void copyPageFormatToFields( final PageFormat pageFormat ) {
  final Paper paper = pageFormat.getPaper();
  final PageFormatFactory pageFormatFactory = PageFormatFactory.getInstance();
  final String formatName = pageFormatFactory.getPageFormatName( paper.getWidth(), paper.getHeight() );
  pageFormatBox.setSelectedItem( formatName );
  pageWidthField.setText( String.valueOf( paper.getWidth() ) );
  pageHeightField.setText( String.valueOf( paper.getHeight() ) );
  userDefinedPageSizeBox.setSelected( formatName == null );
  preDefinedPageSizeBox.setSelected( formatName != null );

  final boolean portraitMode = pageFormat.getOrientation() == PageFormat.PORTRAIT;
  portraitModeBox.setSelected( portraitMode );
  landscapeModeBox.setSelected( portraitMode == false );

  if ( portraitMode ) {
    marginLeftField.setText( String.valueOf( pageFormatFactory.getLeftBorder( paper ) ) );
    marginTopField.setText( String.valueOf( pageFormatFactory.getTopBorder( paper ) ) );
    marginRightField.setText( String.valueOf( pageFormatFactory.getRightBorder( paper ) ) );
    marginBottomField.setText( String.valueOf( pageFormatFactory.getBottomBorder( paper ) ) );
  } else {
    marginTopField.setText( String.valueOf( pageFormatFactory.getLeftBorder( paper ) ) );
    marginLeftField.setText( String.valueOf( pageFormatFactory.getBottomBorder( paper ) ) );
    marginBottomField.setText( String.valueOf( pageFormatFactory.getRightBorder( paper ) ) );
    marginRightField.setText( String.valueOf( pageFormatFactory.getTopBorder( paper ) ) );
  }
}
 
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: 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 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: PageFormatFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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.
 */
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;
}
 
Example 9
Source File: PhysicalPageBox.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public PhysicalPageBox( final PageFormat pageFormat, final long globalX, final long globalY ) {
  this.width = StrictGeomUtility.toInternalValue( pageFormat.getWidth() );
  this.height = StrictGeomUtility.toInternalValue( pageFormat.getHeight() );
  this.imageableX = StrictGeomUtility.toInternalValue( pageFormat.getImageableX() );
  this.imageableY = StrictGeomUtility.toInternalValue( pageFormat.getImageableY() );
  this.imageableWidth = StrictGeomUtility.toInternalValue( pageFormat.getImageableWidth() );
  this.imageableHeight = StrictGeomUtility.toInternalValue( pageFormat.getImageableHeight() );
  this.globalX = globalX;
  this.globalY = globalY;
  this.orientation = pageFormat.getOrientation();
}
 
Example 10
Source File: PrintPreviewComponent.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
private void setSize() {
     int pageCount = printable.getPageCount();
     rowCount = (pageCount - 1) / columnCount + 1;
     pageWidth = 0;
     pageHeight = 0;
     pages = new Page[pageCount];
     PageFormat pageFormat = printable.getPageFormat();
     for (int i = 0; i < pageCount; i++) {
         pageFormat = printable.getPageFormat(pageFormat, i);
         double w = pageFormat.getWidth() + 1;
         double h = pageFormat.getHeight() + 1;
         double iW = pageFormat.getImageableWidth();
         double iH = pageFormat.getImageableHeight();
         double x = pageFormat.getImageableX();
         double y = pageFormat.getImageableY();

         reverce = (pageFormat.getOrientation() == PageFormat.REVERSE_LANDSCAPE);

/*
          * if (pageFormat.getOrientation() == PageFormat.LANDSCAPE) { double
 * t;
 * 
 * t = w; w = h; h = t;
 * 
 * t = iW; iW = iH; iH = t;
 * 
 * t = x; x = y; y = t; }
 */

         Page page = new Page(w, h, x, y, iW, iH);

         if (pageWidth < w)
             pageWidth = w;
         if (pageHeight < h)
             pageHeight = h;
         pages[i] = page;
     }
     width = (columnCount - 1) * (pageWidth + W_SPACE / zoom) + pageWidth;
     height = rowCount * (pageHeight + W_SPACE / zoom);
     Dimension size = new Dimension((int) (width * getZoom()),
             (int) (height * getZoom()));
     this.setSize(size);
     this.setPreferredSize(size);
 }
 
Example 11
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 12
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;
}