Java Code Examples for org.pentaho.reporting.engine.classic.core.MasterReport#getPageHeader()

The following examples show how to use org.pentaho.reporting.engine.classic.core.MasterReport#getPageHeader() . 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: PlainTextOutputIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private MasterReport createStandardReport( final String longTextLabel ) {
  final MasterReport report = new MasterReport();
  report
      .setPageDefinition( new SimplePageDefinition( PageSize.A4, PageFormat.LANDSCAPE, new Insets( 72, 72, 72, 72 ) ) );
  report.setCompatibilityLevel( null );
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  final Band pageHeader = report.getPageHeader();
  final LabelElementFactory labelFactory = new LabelElementFactory();
  labelFactory.setName( "LabelElement" );
  labelFactory.setText( longTextLabel );
  labelFactory.setFontName( "Serif" );
  labelFactory.setFontSize( new Integer( 10 ) );
  labelFactory.setBold( Boolean.FALSE );
  labelFactory.setHeight( 26.0F );
  labelFactory.setWidth( 568.0F );
  labelFactory.setWrap( TextWrap.WRAP );
  labelFactory.setAbsolutePosition( new Point2D.Double( 2.0, 4.0 ) );
  labelFactory.setHorizontalAlignment( ElementAlignment.LEFT );
  labelFactory.setVerticalAlignment( ElementAlignment.TOP );
  final Element labelElement = labelFactory.createElement();
  pageHeader.addElement( labelElement );
  return report;
}
 
Example 2
Source File: Prd3154IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testReport() throws Exception {
  final URL url = getClass().getResource( "Prd-3154.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport report = (MasterReport) directly.getResource();

  // having images in the header does not add any information, but slows down the report processing.
  PageHeader pageHeader = report.getPageHeader();
  pageHeader.removeElement( pageHeader.getElement( 5 ) );
  pageHeader.removeElement( pageHeader.getElement( 0 ) );

  List<LogicalPageBox> logicalPageBoxes = DebugReportRunner.layoutPages( report, 0, 1 );
  for ( LogicalPageBox box : logicalPageBoxes ) {
    RenderNode[] elementsByElementType = MatchFactory.findElementsByElementType( box, PageHeaderType.INSTANCE );
    Assert.assertEquals( 1, elementsByElementType.length );
    Assert.assertTrue( elementsByElementType[0] instanceof RenderBox );
    RenderBox ph = (RenderBox) elementsByElementType[0];
    Assert.assertEquals( 4, ph.getChildCount() );
  }
}
 
Example 3
Source File: AlignmentLeftIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private MasterReport createReport( final boolean wrap ) {
  final MasterReport report = new MasterReport();
  final PageFormatFactory pff = PageFormatFactory.getInstance();
  final Paper paper = pff.createPaper( PageSize.A4 );
  pff.setBorders( paper, 36.0f, 36.0f, 36.0f, 36.0f );
  final PageFormat format = pff.createPageFormat( paper, PageFormat.PORTRAIT );
  report.setPageDefinition( new SimplePageDefinition( format ) );

  final Band pageHeader = report.getPageHeader();
  pageHeader.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 10.0f );

  // the main heading is just a fixed label centered on the page...
  final LabelElementFactory labelFactory = new LabelElementFactory();
  labelFactory.setText( "Free/OpenSourceSoftwareSurvey" );
  labelFactory.setFontName( "SansSerif" );
  labelFactory.setFontSize( new Integer( 10 ) );
  labelFactory.setBold( Boolean.TRUE );
  labelFactory.setAbsolutePosition( new Point2D.Double( 15, 10.0 ) );
  labelFactory.setMinimumSize( new FloatDimension( 40, 10.0f ) );
  labelFactory.setHorizontalAlignment( ElementAlignment.LEFT );
  Element element = labelFactory.createElement();
  element.getStyle().setStyleProperty( TextStyleKeys.WORDBREAK, wrap );
  pageHeader.addElement( element );
  return report;
}
 
Example 4
Source File: LayerUpActionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLayerUp() {
  final MasterReport report = new MasterReport();
  final PageHeader pageHeader = report.getPageHeader();
  final Element first = new Element();
  final Element second = new Element();
  final Element third = new Element();

  pageHeader.addElement( first );
  pageHeader.addElement( second );
  pageHeader.addElement( third );

  final Element[] selectedElements = new Element[] { first, second };
  final ArrayList list = new ArrayList();
  assertTrue( new TestLayerUpAction().collectChange( selectedElements, report, list ) );
  assertEquals( 2, list.size() );

  assertEquals( pageHeader.getElement( 1 ).getObjectID(), selectedElements[ 0 ].getObjectID() );
  assertEquals( pageHeader.getElement( 2 ).getObjectID(), selectedElements[ 1 ].getObjectID() );
}
 
Example 5
Source File: LayerDownActionTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testLayerDown() {
  final MasterReport report = new MasterReport();
  final PageHeader pageHeader = report.getPageHeader();
  final Element first = new Element();
  final Element second = new Element();
  final Element third = new Element();

  pageHeader.addElement( first );
  pageHeader.addElement( second );
  pageHeader.addElement( third );

  final Element[] selectedElements = new Element[] { second, third };
  final ArrayList list = new ArrayList();
  assertTrue( new TestLayerDownAction().collectChange( selectedElements, report, list ) );
  assertEquals( 2, list.size() );

  assertEquals( pageHeader.getElement( 0 ).getObjectID(), selectedElements[ 0 ].getObjectID() );
  assertEquals( pageHeader.getElement( 1 ).getObjectID(), selectedElements[ 1 ].getObjectID() );
}
 
Example 6
Source File: WordWrapLayoutIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static MasterReport createReport( String word, boolean allowWordBreak, float labelMaxWidth,
    ElementAlignment alignment ) {
  MasterReport report = new MasterReport();
  // force not to use complex text processing
  report.getReportConfiguration().setConfigProperty( COMPLEX_TEXT_CONFIG_OVERRIDE_KEY, "false" );

  PageFormatFactory pff = PageFormatFactory.getInstance();
  Paper paper = pff.createPaper( PageSize.A4 );
  pff.setBorders( paper, 36.0, 36.0, 36.0, 36.0 );
  PageFormat format = pff.createPageFormat( paper, PageFormat.PORTRAIT );
  report.setPageDefinition( new SimplePageDefinition( format ) );

  Band pageHeader = report.getPageHeader();
  pageHeader.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 10.0f );

  // the main heading is just a fixed label
  LabelElementFactory labelFactory = new LabelElementFactory();
  labelFactory.setText( word );
  labelFactory.setFontName( "SansSerif" );
  labelFactory.setFontSize( 10 );
  labelFactory.setDynamicHeight( true );
  // will be useful when printing the page on a real monitor as it highlights paragraph's area
  labelFactory.setBackgroundColor( Color.YELLOW );
  labelFactory.setAbsolutePosition( new Point2D.Double( 15, 10 ) );
  labelFactory.setMinimumSize( new FloatDimension( 40, 10 ) );
  labelFactory.setMaximumWidth( labelMaxWidth );
  labelFactory.setHorizontalAlignment( alignment );

  Element element = labelFactory.createElement();
  element.setName( PARAGRAPH_NAME );
  element.getStyle().setStyleProperty( TextStyleKeys.WORDBREAK, allowWordBreak );
  pageHeader.addElement( element );

  return report;
}
 
Example 7
Source File: AlignmentRightApiIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testAlignmentRight() throws Exception {
  final MasterReport report = new MasterReport();
  final PageFormatFactory pff = PageFormatFactory.getInstance();
  final Paper paper = pff.createPaper( PageSize.A4 );
  pff.setBorders( paper, 36.0f, 36.0f, 36.0f, 36.0f );
  final PageFormat format = pff.createPageFormat( paper, PageFormat.PORTRAIT );
  report.setPageDefinition( new SimplePageDefinition( format ) );

  final Band pageHeader = report.getPageHeader();
  pageHeader.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 10.0f );

  // the main heading is just a fixed label centered on the page...
  final LabelElementFactory labelFactory = new LabelElementFactory();
  labelFactory.setText( "Free / Open Source Software Survey" );
  labelFactory.setFontName( "SansSerif" );
  labelFactory.setFontSize( new Integer( 18 ) );
  labelFactory.setBold( Boolean.TRUE );
  labelFactory.setAbsolutePosition( new Point2D.Double( 15, 10.0 ) );
  labelFactory.setMinimumSize( new FloatDimension( 565, 28.0f ) );
  labelFactory.setHorizontalAlignment( ElementAlignment.RIGHT );
  pageHeader.addElement( labelFactory.createElement() );

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( report, report.getPageHeader(), false, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485000 or 400000
  // and that only two lines exist for each
  new ValidateRunner().startValidation( logicalPageBox );
}
 
Example 8
Source File: AlignmentCenterApiIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testAlignmentCenter() throws Exception {
  final MasterReport report = new MasterReport();
  final PageFormatFactory pff = PageFormatFactory.getInstance();
  final Paper paper = pff.createPaper( PageSize.A4 );
  pff.setBorders( paper, 36.0f, 36.0f, 36.0f, 36.0f );
  final PageFormat format = pff.createPageFormat( paper, PageFormat.PORTRAIT );
  report.setPageDefinition( new SimplePageDefinition( format ) );

  final Band pageHeader = report.getPageHeader();
  pageHeader.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 10.0f );

  // the main heading is just a fixed label centered on the page...
  final LabelElementFactory labelFactory = new LabelElementFactory();
  labelFactory.setText( "Free / Open Source Software Survey" );
  labelFactory.setFontName( "SansSerif" );
  labelFactory.setFontSize( new Integer( 18 ) );
  labelFactory.setBold( Boolean.TRUE );
  labelFactory.setAbsolutePosition( new Point2D.Double( 15, 10.0 ) );
  labelFactory.setMinimumSize( new FloatDimension( 565, 28.0f ) );
  labelFactory.setHorizontalAlignment( ElementAlignment.CENTER );
  pageHeader.addElement( labelFactory.createElement() );

  final LogicalPageBox logicalPageBox =
      DebugReportRunner.layoutSingleBand( report, report.getPageHeader(), false, false );
  // simple test, we assert that all paragraph-poolboxes are on either 485000 or 400000
  // and that only two lines exist for each
  new ValidateRunner().startValidation( logicalPageBox );
}
 
Example 9
Source File: SurveyScaleAPIDemoHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void setupPageHeader(final MasterReport report)
{
  // define the page header...
  final Band pageHeader = report.getPageHeader();
  pageHeader.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(20));

  // the main heading is just a fixed label centered on the page...
  final LabelElementFactory labelFactory = new LabelElementFactory();
  labelFactory.setText("Free / Open Source Software Survey");
  labelFactory.setFontName("SansSerif");
  labelFactory.setFontSize(new Integer(18));
  labelFactory.setBold(Boolean.TRUE);
  labelFactory.setAbsolutePosition(new Point2D.Double(X1, 10.0));
  labelFactory.setMinimumSize(new FloatDimension(C1_WIDTH + C2_WIDTH + C3_WIDTH + C4_WIDTH, 28.0f));
  labelFactory.setHorizontalAlignment(ElementAlignment.CENTER);
  pageHeader.addElement(labelFactory.createElement());

  // the following expression is used to format the manager name into a message string
  // that says 'Respondent:  <name>'.  The whole string can be centered on the page that way.
  // This expression expects to find a marked report property called 'MANAGER_NAME', look
  // in the attemptPreview() method to see how this is set up.

  // here is the element that displays the string calculated in the expression above.
  final MessageFieldElementFactory tfef = new MessageFieldElementFactory();
  tfef.setFormatString("Respondent: $(RESPONDENT_NAME)");
  tfef.setFontName("SansSerif");
  tfef.setFontSize(new Integer(12));
  tfef.setBold(Boolean.TRUE);
  tfef.setAbsolutePosition(new Point2D.Double(0.0, 38.0));
  tfef.setMinimumSize(new FloatDimension(PRINT_WIDTH, 14.0f));
  tfef.setHorizontalAlignment(ElementAlignment.CENTER);
  pageHeader.addElement(tfef.createElement());

  labelFactory.setAbsolutePosition(new Point2D.Double(X1, 58.0));
  labelFactory.setText(
      "Please note that the questions AND responses presented below were INVENTED for the the purpose of this demo report.  They are NOT real.");
  labelFactory.setFontName("Serif");
  labelFactory.setFontSize(new Integer(11));
  labelFactory.setBold(Boolean.FALSE);
  labelFactory.setItalic(Boolean.TRUE);
  pageHeader.addElement(labelFactory.createElement());

  // labels
  labelFactory.setFontName("SansSerif");
  labelFactory.setFontSize(new Integer(7));
  labelFactory.setItalic(Boolean.FALSE);
  labelFactory.setBold(Boolean.FALSE);
  labelFactory.setVerticalAlignment(ElementAlignment.BOTTOM);

  final float delta = C2_WIDTH / 5.0f;
  labelFactory.setText("Not Important");
  labelFactory.setAbsolutePosition(new Point2D.Double(X2, 70.0));
  labelFactory.setMinimumSize(new FloatDimension(delta, 30.0f));
  pageHeader.addElement(labelFactory.createElement());

  labelFactory.setText("Very Important");
  labelFactory.setAbsolutePosition(new Point2D.Double(X2 + 4 * delta, 70.0));
  labelFactory.setMinimumSize(new FloatDimension(delta, 30.0f));
  pageHeader.addElement(labelFactory.createElement());

  addBoxedLabelToBand(pageHeader, null, X1, BOX_TOP, C1_WIDTH, COLUMN_HEADER_BOX_HEIGHT,
      "SansSerif", 10, true, Color.black, new Color(220, 255, 220));
  addBoxedLabelToBand(pageHeader, null, X2, BOX_TOP, C2_WIDTH, COLUMN_HEADER_BOX_HEIGHT,
      "SansSerif", 10, true, Color.black, new Color(220, 255, 220));

  final SurveyScale scaleHeader = new SurveyScale(1, 5, null);
  scaleHeader.setDrawScaleValues(true);
  scaleHeader.setDrawTickMarks(false);
  scaleHeader.setScaleValueFont(new Font("SansSerif", Font.PLAIN, 9));
  report.getParameterValues().put("SCALE_HEADER", scaleHeader);

  final ContentFieldElementFactory dfef = new ContentFieldElementFactory();
  dfef.setName("ScaleHeaderElement");
  dfef.setAbsolutePosition(new Point2D.Double(X2, BOX_TOP));
  dfef.setFieldname("SCALE_HEADER");
  dfef.setMinimumSize(new FloatDimension(C2_WIDTH, COLUMN_HEADER_BOX_HEIGHT));
  pageHeader.addElement(dfef.createElement());

  addBoxedLabelToBand(pageHeader, "Your Response", X3, BOX_TOP, C3_WIDTH, COLUMN_HEADER_BOX_HEIGHT,
      "SansSerif", 8, false, Color.black, new Color(220, 255, 220));

  addBoxedLabelToBand(pageHeader, "Average Response", X3 + C3_WIDTH, BOX_TOP, C3_WIDTH, COLUMN_HEADER_BOX_HEIGHT,
      "SansSerif", 8, false, Color.black, new Color(220, 255, 220));
}
 
Example 10
Source File: AlignmentRightApiIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void setupPageHeader( final MasterReport report ) {
  // define the page header...
  final Band pageHeader = report.getPageHeader();
  pageHeader.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, new Float( 20 ) );

  // the main heading is just a fixed label centered on the page...
  final LabelElementFactory labelFactory = new LabelElementFactory();
  labelFactory.setText( "Free / Open Source Software Survey" );
  labelFactory.setFontName( "SansSerif" );
  labelFactory.setFontSize( new Integer( 18 ) );
  labelFactory.setBold( Boolean.TRUE );
  labelFactory.setAbsolutePosition( new Point2D.Double( X1, 10.0 ) );
  labelFactory.setMinimumSize( new FloatDimension( C1_WIDTH + C2_WIDTH + C3_WIDTH + C4_WIDTH, 28.0f ) );
  labelFactory.setHorizontalAlignment( ElementAlignment.CENTER );
  pageHeader.addElement( labelFactory.createElement() );

  // the following expression is used to format the manager name into a message string
  // that says 'Respondent: <name>'. The whole string can be centered on the page that way.
  // This expression expects to find a marked report property called 'MANAGER_NAME', look
  // in the attemptPreview() method to see how this is set up.

  // here is the element that displays the string calculated in the expression above.
  final MessageFieldElementFactory tfef = new MessageFieldElementFactory();
  tfef.setFormatString( "Respondent: $(RESPONDENT_NAME)" );
  tfef.setFontName( "SansSerif" );
  tfef.setFontSize( new Integer( 12 ) );
  tfef.setBold( Boolean.TRUE );
  tfef.setAbsolutePosition( new Point2D.Double( 0.0, 38.0 ) );
  tfef.setMinimumSize( new FloatDimension( PRINT_WIDTH, 14.0f ) );
  tfef.setHorizontalAlignment( ElementAlignment.CENTER );
  pageHeader.addElement( tfef.createElement() );

  labelFactory.setAbsolutePosition( new Point2D.Double( X1, 58.0 ) );
  labelFactory
      .setText( "Please note that the questions AND responses presented below were INVENTED for the the purpose of this demo "
          + "report.  They are NOT real." );
  labelFactory.setFontName( "Serif" );
  labelFactory.setFontSize( new Integer( 11 ) );
  labelFactory.setBold( Boolean.FALSE );
  labelFactory.setItalic( Boolean.TRUE );
  pageHeader.addElement( labelFactory.createElement() );

  // labels
  labelFactory.setFontName( "SansSerif" );
  labelFactory.setFontSize( new Integer( 7 ) );
  labelFactory.setItalic( Boolean.FALSE );
  labelFactory.setBold( Boolean.FALSE );
  labelFactory.setVerticalAlignment( ElementAlignment.BOTTOM );

  final float delta = C2_WIDTH / 5.0f;
  labelFactory.setText( "Not Important" );
  labelFactory.setAbsolutePosition( new Point2D.Double( X2, 70.0 ) );
  labelFactory.setMinimumSize( new FloatDimension( delta, 30.0f ) );
  pageHeader.addElement( labelFactory.createElement() );

  labelFactory.setText( "Very Important" );
  labelFactory.setAbsolutePosition( new Point2D.Double( X2 + 4 * delta, 70.0 ) );
  labelFactory.setMinimumSize( new FloatDimension( delta, 30.0f ) );
  pageHeader.addElement( labelFactory.createElement() );

  addBoxedLabelToBand( pageHeader, null, X1, BOX_TOP, C1_WIDTH, COLUMN_HEADER_BOX_HEIGHT, "SansSerif", 10, true,
      Color.black, new Color( 220, 255, 220 ) );
  addBoxedLabelToBand( pageHeader, null, X2, BOX_TOP, C2_WIDTH, COLUMN_HEADER_BOX_HEIGHT, "SansSerif", 10, true,
      Color.black, new Color( 220, 255, 220 ) );

  final SurveyScale scaleHeader = new SurveyScale( 1, 5, null );
  scaleHeader.setDrawScaleValues( true );
  scaleHeader.setDrawTickMarks( false );
  scaleHeader.setScaleValueFont( new Font( "SansSerif", Font.PLAIN, 9 ) );
  report.getParameterValues().put( "SCALE_HEADER", scaleHeader );

  final ContentFieldElementFactory dfef = new ContentFieldElementFactory();
  dfef.setName( "ScaleHeaderElement" );
  dfef.setAbsolutePosition( new Point2D.Double( X2, BOX_TOP ) );
  dfef.setFieldname( "SCALE_HEADER" );
  dfef.setMinimumSize( new FloatDimension( C2_WIDTH, COLUMN_HEADER_BOX_HEIGHT ) );
  pageHeader.addElement( dfef.createElement() );

  addBoxedLabelToBand( pageHeader, "Your Response", X3, BOX_TOP, C3_WIDTH, COLUMN_HEADER_BOX_HEIGHT, "SansSerif",
      8, false, Color.black, new Color( 220, 255, 220 ) );

  addBoxedLabelToBand( pageHeader, "Average Response", X3 + C3_WIDTH, BOX_TOP, C3_WIDTH, COLUMN_HEADER_BOX_HEIGHT,
      "SansSerif", 8, false, Color.black, new Color( 220, 255, 220 ) );
}
 
Example 11
Source File: ResourceLoaderListenerTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 3 votes vote down vote up
public void testEmbedDocument() {
  final MasterReport report = new MasterReport();
  final ResourceLoaderListener listener = new ResourceLoaderListener( report, report );

  final PageHeader pageHeader = report.getPageHeader();
  final Element element = new Element();
  pageHeader.addElement( element );


}