Java Code Examples for org.pentaho.reporting.engine.classic.core.Element#setName()

The following examples show how to use org.pentaho.reporting.engine.classic.core.Element#setName() . 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: SerializationGoldTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void testResourceLabelAfterSerialization() throws Exception {
  final File url = GoldTestBase.locateGoldenSampleReport( "Prd-3514.prpt" );
  assertNotNull( url );
  final ResourceManager resourceManager = new ResourceManager();
  resourceManager.registerDefaults();
  final Resource directly = resourceManager.createDirectly( url, MasterReport.class );
  final MasterReport org = (MasterReport) directly.getResource();

  final MasterReport report = postProcess( org );

  RelationalGroup relationalGroup = report.getRelationalGroup( 0 );
  GroupHeader header = relationalGroup.getHeader();
  Band band = (Band) header.getElement( 0 );
  Element element = band.getElement( 1 );
  assertTrue( element.getElementType() instanceof ResourceMessageType );
  element.setName( "DateTitleField" );
  //    LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 1);
  LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, header, false, false );
  RenderNode dateTitleField = MatchFactory.findElementByName( logicalPageBox, "DateTitleField" );
  assertNotNull( dateTitleField );
  //    ModelPrinter.INSTANCE.print(logicalPageBox);
}
 
Example 2
Source File: OrphanIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Element createDataItem( final String text, final float width, final float height ) {
  final Element label = new Element();
  label.setElementType( LabelType.INSTANCE );
  label.setName( text );
  label.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, width );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, height );
  return label;
}
 
Example 3
Source File: HtmlRichTextConverter.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Element createLiNumElement( final String _liNum ) {
  final Element linum = new Element();
  linum.setName( "point" );
  linum.setElementType( LabelType.INSTANCE );
  linum.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, _liNum );
  return linum;
}
 
Example 4
Source File: Prd3514IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLineBreaksOnStart() throws ReportProcessingException, ContentProcessingException {
  Element textField = new Element();
  textField.setName( "textField" );
  textField.getStyle().setStyleProperty( TextStyleKeys.FONT, "Arial" );
  textField.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 14 );
  textField.getStyle().setStyleProperty( TextStyleKeys.TEXT_WRAP, TextWrap.NONE );
  textField.getStyle().setStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT, false );
  textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 97f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 20f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );
  textField.setElementType( LabelType.INSTANCE );
  textField.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "\nClassic Cars" );

  final MasterReport report = new MasterReport();
  report.getReportHeader().addElement( textField );
  report.setCompatibilityLevel( null );
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader(), false, false );
  ModelPrinter.INSTANCE.print( logicalPageBox );

  RenderNode textFieldBox = MatchFactory.findElementByName( logicalPageBox, "textField" );
  assertNotNull( textFieldBox );

  assertEquals( 0, textFieldBox.getY() );

  // box only contains one line, and min-size is set to 8, max size = 20, so the line-height of 14.024 is used.
  assertEquals( StrictGeomUtility.toInternalValue( 28 ), textFieldBox.getHeight() );
}
 
Example 5
Source File: Prd3514IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLineBreaksOnEnd() throws ReportProcessingException, ContentProcessingException {
  Element textField = new Element();
  textField.setName( "textField" );
  textField.getStyle().setStyleProperty( TextStyleKeys.FONT, "Arial" );
  textField.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 14 );
  textField.getStyle().setStyleProperty( TextStyleKeys.TEXT_WRAP, TextWrap.NONE );
  textField.getStyle().setStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT, false );
  textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 97f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 20f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );
  textField.setElementType( LabelType.INSTANCE );
  textField.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Classic Cars\n" );

  final MasterReport report = new MasterReport();
  report.getReportHeader().addElement( textField );
  report.setCompatibilityLevel( null );
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader(), false, false );
  ModelPrinter.INSTANCE.print( logicalPageBox );

  RenderNode textFieldBox = MatchFactory.findElementByName( logicalPageBox, "textField" );
  assertNotNull( textFieldBox );

  assertEquals( 0, textFieldBox.getY() );

  // box only contains one line, and min-size is set to 8, max size = 20, so the line-height of 14.024 is used.
  assertEquals( StrictGeomUtility.toInternalValue( 20 ), textFieldBox.getHeight() );
}
 
Example 6
Source File: Prd3514IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testMultipleLineBreaks() throws ReportProcessingException, ContentProcessingException {
  Element textField = new Element();
  textField.setName( "textField" );
  textField.getStyle().setStyleProperty( TextStyleKeys.FONT, "Arial" );
  textField.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 14 );
  textField.getStyle().setStyleProperty( TextStyleKeys.TEXT_WRAP, TextWrap.NONE );
  textField.getStyle().setStyleProperty( TextStyleKeys.TRIM_TEXT_CONTENT, false );
  textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 97f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 20f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
  textField.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );
  textField.setElementType( LabelType.INSTANCE );
  textField.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "\r\n\r\nClassic Cars" );

  final MasterReport report = new MasterReport();
  report.getReportHeader().addElement( textField );
  report.setCompatibilityLevel( null );
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader(), false, false );
  ModelPrinter.INSTANCE.print( logicalPageBox );

  RenderNode textFieldBox = MatchFactory.findElementByName( logicalPageBox, "textField" );
  assertNotNull( textFieldBox );

  assertEquals( 0, textFieldBox.getY() );

  // box only contains one line, and min-size is set to 8, max size = 20, so the line-height of 14.024 is used.
  assertEquals( StrictGeomUtility.toInternalValue( 42 ), textFieldBox.getHeight() );
}
 
Example 7
Source File: KeepTogetherIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Element createDataItem( final String text, final float width, final float height ) {
  final Element label = new Element();
  label.setElementType( LabelType.INSTANCE );
  label.setName( text );
  label.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, width );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, height );
  return label;
}
 
Example 8
Source File: RichTextRenderingIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Element createDataItem( final String text, final float width, final float height ) {
  final Element label = new Element();
  label.setName( "Label" );
  label.setElementType( LabelType.INSTANCE );
  label.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, width );
  label.getStyle().setStyleProperty( ElementStyleKeys.MAX_WIDTH, width );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, height );
  label.getStyle().setStyleProperty( ElementStyleKeys.MAX_HEIGHT, height );
  return label;
}
 
Example 9
Source File: Prd5321IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * In 5.0 and later, elements are dynamic by default - if they only define a minimum height, and no max-height then
 * that element can grow as if dynamic=true has been set. To limit the element growth, use the max-height property.
 * <p/>
 * This test validates that growth happens unless explicitly restricted, and if restricted, that the first line is
 * printed.
 *
 * @throws Exception
 */
@Test
public void testTextLimitedInHeight() throws Exception {
  Element l = new Element();
  l.setElementType( LabelType.INSTANCE );
  l.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 10f );
  l.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 100f );
  l.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 50 );
  l.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Label" );
  l.setName( "Label" );

  Element l2 = new Element();
  l2.setElementType( LabelType.INSTANCE );
  l2.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 100f );
  l.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 100f );
  l2.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 10f );
  l2.getStyle().setStyleProperty( ElementStyleKeys.MAX_HEIGHT, 10f );
  l2.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 50 );
  l2.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Label" );
  l2.setName( "Label2" );

  MasterReport r = new MasterReport();
  r.getReportHeader().addElement( l );
  r.getReportFooter().addElement( l2 );

  LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage( r, 0 );
  ModelPrinter.INSTANCE.print( logicalPageBox );
  RenderNode label = MatchFactory.findElementByName( logicalPageBox, "Label" );
  // PRD-2736 note: the label is split into two parts now, since it does not fit the line width anymore:
  // Lab
  // el_
  Assert.assertEquals( StrictGeomUtility.toInternalValue( 100 ), label.getCachedHeight() );
  RenderNode label2 = MatchFactory.findElementByName( logicalPageBox, "Label2" );
  Assert.assertEquals( StrictGeomUtility.toInternalValue( 10 ), label2.getCachedHeight() );
}
 
Example 10
Source File: Prd3479IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testRowInCanvas() throws ReportProcessingException, ContentProcessingException {
  final Element label = new Element();
  label.setName( "Label" );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, -100f );
  label.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, -33f );
  label.getStyle().setStyleProperty( ElementStyleKeys.DYNAMIC_HEIGHT, true );
  label.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Label" );
  label.setElementType( LabelType.INSTANCE );

  final Band rowBand = new Band();
  rowBand.setName( "RowBand" );
  rowBand.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, "row" );
  rowBand.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 20f );
  rowBand.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, -100f );
  rowBand.getStyle().setStyleProperty( ElementStyleKeys.VALIGNMENT, ElementAlignment.MIDDLE );
  rowBand.getStyle().setStyleProperty( ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT );
  rowBand.addElement( label );

  final MasterReport report = new MasterReport();
  final ReportHeader band = report.getReportHeader();
  band.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 2f );
  band.addElement( rowBand );

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, band );
  // ModelPrinter.INSTANCE.print(logicalPageBox);

  final RenderNode labelRenderBox = MatchFactory.findElementByName( logicalPageBox, "Label" );
  final RenderNode rowRenderBox = MatchFactory.findElementByName( logicalPageBox, "RowBand" );
  assertEquals( StrictGeomUtility.toInternalValue( 468 ), rowRenderBox.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 154.44 ), labelRenderBox.getWidth() );
}
 
Example 11
Source File: StyleInheritanceIT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Element createLabel( final String text ) {
  final Element element = new Element();
  element.setName( text );
  element.setElementType( LabelType.INSTANCE );
  element.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, new Float( 20 ) );
  element.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float( 200 ) );
  element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text );
  return element;
}
 
Example 12
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 13
Source File: Prd3688IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testPrd3688Strict() throws Exception {
  final MasterReport report = new MasterReport();
  report.setCompatibilityLevel( ClassicEngineBoot.computeVersionId( 3, 8, 0 ) );

  final Element e1 = createDataItem( "Header" );
  e1.setName( "E1" );
  e1.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, -37f );
  e1.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 11f );
  e1.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 500f );
  e1.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );

  final Element e2 = createDataItem( "Header" );
  e2.setName( "E2" );
  e2.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, -50f );
  e2.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 11f );
  e2.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
  e2.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );

  final Element e3 = createDataItem( "Header" );
  e3.setName( "E3" );
  e3.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 1464f );
  e3.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 3.5f );
  e3.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
  e3.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 12.5f );

  report.getReportHeader().setName( "RH" );
  report.getReportHeader().addElement( e1 );
  report.getReportHeader().addElement( e2 );
  report.getReportHeader().addElement( e3 );

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader() );
  // ModelPrinter.INSTANCE.print(logicalPageBox);

  final RenderNode e1Box = MatchFactory.findElementByName( logicalPageBox, "E1" );
  final RenderNode e2Box = MatchFactory.findElementByName( logicalPageBox, "E2" );
  final RenderNode e3Box = MatchFactory.findElementByName( logicalPageBox, "E3" );
  final RenderNode rhBox = MatchFactory.findElementByName( logicalPageBox, "RH" );

  assertEquals( StrictGeomUtility.toInternalValue( 500 ), e1Box.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e1Box.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 173.16f ), e1Box.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 11 ), e1Box.getHeight() );

  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e2Box.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e2Box.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 234 ), e2Box.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 11 ), e2Box.getHeight() );

  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e3Box.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 12.5 ), e3Box.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 1464f ), e3Box.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 3.5f ), e3Box.getHeight() );

  assertEquals( StrictGeomUtility.toInternalValue( 0 ), rhBox.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), rhBox.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 468f ), rhBox.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 16 ), rhBox.getHeight() );

}
 
Example 14
Source File: Prd4956InlineTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Element create( String name ) {
  Element dataItemSR = TableTestUtil.createDataItem( name, 100, 20 );
  dataItemSR.setName( name );
  return dataItemSR;
}
 
Example 15
Source File: Prd4956BandedTest.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Element create( String name ) {
  Element dataItemSR = TableTestUtil.createDataItem( name, 100, 20 );
  dataItemSR.setName( name );
  return dataItemSR;
}
 
Example 16
Source File: Prd3688IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testPrd3688() throws Exception {
  final MasterReport report = new MasterReport();
  report.setCompatibilityLevel( null );
  report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
      "false" );

  final Element e1 = createDataItem( "Header" );
  e1.setName( "E1" );
  e1.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, -37f );
  e1.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 11f );
  e1.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 500f );
  e1.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );

  final Element e2 = createDataItem( "Header" );
  e2.setName( "E2" );
  e2.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, -50f );
  e2.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 11f );
  e2.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
  e2.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );

  final Element e3 = createDataItem( "Header" );
  e3.setName( "E3" );
  e3.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 1464f );
  e3.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 3.5f );
  e3.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
  e3.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 12.5f );

  report.getReportHeader().setName( "RH" );
  report.getReportHeader().addElement( e1 );
  report.getReportHeader().addElement( e2 );
  report.getReportHeader().addElement( e3 );

  final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader() );
  // ModelPrinter.INSTANCE.print(logicalPageBox);

  final RenderNode e1Box = MatchFactory.findElementByName( logicalPageBox, "E1" );
  final RenderNode e2Box = MatchFactory.findElementByName( logicalPageBox, "E2" );
  final RenderNode e3Box = MatchFactory.findElementByName( logicalPageBox, "E3" );
  final RenderNode rhBox = MatchFactory.findElementByName( logicalPageBox, "RH" );

  assertEquals( StrictGeomUtility.toInternalValue( 500 ), e1Box.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e1Box.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 173.16f ), e1Box.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 11 ), e1Box.getHeight() );

  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e2Box.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e2Box.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 234 ), e2Box.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 11 ), e2Box.getHeight() );

  assertEquals( StrictGeomUtility.toInternalValue( 0 ), e3Box.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 12.5 ), e3Box.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 1464f ), e3Box.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 8 ), e3Box.getHeight() );

  // in non-legacy mode, a parent box expands to enclose all childs, unless prohibited by max-size or preferred-size.
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), rhBox.getX() );
  assertEquals( StrictGeomUtility.toInternalValue( 0 ), rhBox.getY() );
  assertEquals( StrictGeomUtility.toInternalValue( 1464f ), rhBox.getWidth() );
  assertEquals( StrictGeomUtility.toInternalValue( 20.5 ), rhBox.getHeight() );
}
 
Example 17
Source File: Prd3514IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testWeirdTocLayoutComplex() throws ReportProcessingException, ContentProcessingException {

    if ( !DebugReportRunner.isSafeToTestComplexText() ) {
      return;
    }

    Element textField = new Element();
    textField.setName( "textField" );
    textField.getStyle().setStyleProperty( TextStyleKeys.FONT, "Arial" );
    textField.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 14 );
    textField.getStyle().setStyleProperty( TextStyleKeys.TEXT_WRAP, TextWrap.NONE );
    textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 97f );
    textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 20f );
    textField.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
    textField.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );
    textField.setElementType( LabelType.INSTANCE );
    textField.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Classic Cars" );

    Element dotField = new Element();
    dotField.setName( "dotField" );
    dotField.getStyle().setStyleProperty( TextStyleKeys.FONT, "Arial" );
    dotField.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 14 );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.ALIGNMENT, ElementAlignment.RIGHT );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.VALIGNMENT, ElementAlignment.TOP );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 97f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 628.463f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 20f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.WIDTH, 100f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.MAX_WIDTH, 100f );
    dotField.setElementType( LabelType.INSTANCE );
    dotField
        .setAttribute(
            AttributeNames.Core.NAMESPACE,
            AttributeNames.Core.VALUE,
            " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
                + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
                + ". . . . . . . . . . . . . . . . . ." );

    Band band = new Band();
    band.setName( "outer-box" );
    band.setLayout( "inline" );
    band.getStyle().setStyleProperty( ElementStyleKeys.BOX_SIZING, BoxSizing.CONTENT_BOX );
    band.getStyle().setStyleProperty( ElementStyleKeys.OVERFLOW_X, false );
    band.getStyle().setStyleProperty( ElementStyleKeys.OVERFLOW_Y, false );
    band.getStyle().setStyleProperty( TextStyleKeys.LINEHEIGHT, 1f );
    band.getStyle().setStyleProperty( TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE_BREAKS );
    band.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 708f );
    band.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 12f );
    band.getStyle().setStyleProperty( ElementStyleKeys.MAX_HEIGHT, 20f );
    band.addElement( textField );
    band.addElement( dotField );

    final MasterReport report = new MasterReport();
    report.getReportHeader().addElement( band );
    report.setCompatibilityLevel( null );
    report.getReportConfiguration()
        .setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY, "true" );
    report.getStyle().setStyleProperty( TextStyleKeys.WORDBREAK, true );

    LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader(), false, false );
    // ModelPrinter.INSTANCE.print(logicalPageBox);

    RenderBox outerBox = (RenderBox) MatchFactory.findElementByName( logicalPageBox, "outer-box" );
    assertNotNull( outerBox );

    assertEquals( 0, outerBox.getY() );

    // box only contains one line, and min-size is set to 8, max size = 20, so the line-height of 14.024 is used.
    assertTrue( outerBox.getHeight() >= StrictGeomUtility.toInternalValue( 16 ) );
    assertSame( outerBox.getFirstChild(), outerBox.getLastChild() );
    // no valid test.
    // assertEquals(outerBox.getHeight(), outerBox.getFirstChild().getHeight());
  }
 
Example 18
Source File: Prd3514IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testWeirdTocLayout() throws ReportProcessingException, ContentProcessingException {

    Element textField = new Element();
    textField.setName( "textField" );
    textField.getStyle().setStyleProperty( TextStyleKeys.FONT, "Arial" );
    textField.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 14 );
    textField.getStyle().setStyleProperty( TextStyleKeys.TEXT_WRAP, TextWrap.NONE );
    textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 97f );
    textField.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 20f );
    textField.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 0f );
    textField.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );
    textField.setElementType( LabelType.INSTANCE );
    textField.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Classic Cars" );

    Element dotField = new Element();
    dotField.setName( "dotField" );
    dotField.getStyle().setStyleProperty( TextStyleKeys.FONT, "Arial" );
    dotField.getStyle().setStyleProperty( TextStyleKeys.FONTSIZE, 14 );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.ALIGNMENT, ElementAlignment.RIGHT );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.VALIGNMENT, ElementAlignment.TOP );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.POS_X, 97f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.POS_Y, 0f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 628.463f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 20f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.WIDTH, 100f );
    dotField.getStyle().setStyleProperty( ElementStyleKeys.MAX_WIDTH, 100f );
    dotField.setElementType( LabelType.INSTANCE );
    dotField
        .setAttribute(
            AttributeNames.Core.NAMESPACE,
            AttributeNames.Core.VALUE,
            " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
                + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "
                + ". . . . . . . . . . . . . . . . . ." );

    Band band = new Band();
    band.setName( "outer-box" );
    band.setLayout( "inline" );
    band.getStyle().setStyleProperty( ElementStyleKeys.BOX_SIZING, BoxSizing.CONTENT_BOX );
    band.getStyle().setStyleProperty( ElementStyleKeys.OVERFLOW_X, false );
    band.getStyle().setStyleProperty( ElementStyleKeys.OVERFLOW_Y, false );
    band.getStyle().setStyleProperty( TextStyleKeys.LINEHEIGHT, 1f );
    band.getStyle().setStyleProperty( TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE_BREAKS );
    band.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 708f );
    band.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 12f );
    band.getStyle().setStyleProperty( ElementStyleKeys.MAX_HEIGHT, 20f );
    band.addElement( textField );
    band.addElement( dotField );

    final MasterReport report = new MasterReport();
    report.getReportHeader().addElement( band );
    report.setCompatibilityLevel( null );
    report.getReportConfiguration().setConfigProperty( ClassicEngineCoreModule.COMPLEX_TEXT_CONFIG_OVERRIDE_KEY,
        "false" );

    LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand( report, report.getReportHeader(), false, false );
    ModelPrinter.INSTANCE.print( logicalPageBox );

    RenderNode textFieldBox = MatchFactory.findElementByName( logicalPageBox, "textField" );
    assertNotNull( textFieldBox );

    assertEquals( 0, textFieldBox.getY() );

    // box only contains one line, and min-size is set to 8, max size = 20, so the line-height of 14.024 is used.
    assertEquals( StrictGeomUtility.toInternalValue( 14 ), textFieldBox.getHeight() );
  }
 
Example 19
Source File: WizardProcessor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void setupField( final Band detailsHeader,
                           final Band detailsFooter,
                           final Band itemBand,
                           final DetailFieldDefinition field,
                           final float width,
                           final int fieldIdx ) throws ReportProcessingException {
  if ( StringUtils.isEmpty( field.getField() ) ) {
    return;
  }

  final Element detailElement =
    AutoGeneratorUtility.generateDetailsElement( field.getField(), computeElementType( field ) );
  setupDefaultGrid( itemBand, detailElement );

  final String id = "wizard::details-" + field.getField();
  detailElement.setName( id );
  detailElement.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float( width ) );
  if ( Boolean.TRUE.equals
    ( detailElement
      .getAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ALLOW_METADATA_STYLING ) ) ) {
    detailElement
      .setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.CACHED_WIZARD_FORMAT_DATA, field );
  }
  if ( Boolean.TRUE.equals
    ( detailElement
      .getAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ALLOW_METADATA_ATTRIBUTES ) ) ) {
    detailElement
      .setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.CACHED_WIZARD_FIELD_DATA, field );
  }
  itemBand.addElement( detailElement );

  if ( Boolean.TRUE.equals( field.getOnlyShowChangingValues() ) ) {
    detailElement.setAttribute
      ( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ONLY_SHOW_CHANGING_VALUES, Boolean.TRUE );
  }

  if ( detailsHeader != null ) {
    final Element headerElement = AutoGeneratorUtility.generateHeaderElement( field.getField() );
    setupDefaultGrid( detailsHeader, headerElement );
    headerElement.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float( width ) );
    if ( Boolean.TRUE.equals
      ( headerElement
        .getAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ALLOW_METADATA_STYLING ) ) ) {
      headerElement
        .setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.CACHED_WIZARD_FORMAT_DATA, field );
    }
    if ( Boolean.TRUE.equals
      ( headerElement
        .getAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ALLOW_METADATA_ATTRIBUTES ) ) ) {
      headerElement
        .setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.CACHED_WIZARD_FIELD_DATA, field );
    }
    headerElement.setAttribute( AttributeNames.Wizard.NAMESPACE,
      MetaAttributeNames.Style.HORIZONTAL_ALIGNMENT, field.getHorizontalAlignment() );

    detailsHeader.addElement( headerElement );
  }

  if ( detailsFooter != null ) {
    final Class aggFunctionClass = field.getAggregationFunction();
    final Element footerElement = AutoGeneratorUtility.generateFooterElement
      ( aggFunctionClass, computeElementType( field ), null, field.getField() );

    setupDefaultGrid( detailsFooter, footerElement );

    footerElement.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float( width ) );
    if ( Boolean.TRUE.equals
      ( footerElement
        .getAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ALLOW_METADATA_STYLING ) ) ) {
      footerElement
        .setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.CACHED_WIZARD_FORMAT_DATA, field );
    }
    if ( Boolean.TRUE.equals
      ( footerElement
        .getAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ALLOW_METADATA_ATTRIBUTES ) ) ) {
      footerElement
        .setAttribute( AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.CACHED_WIZARD_FIELD_DATA, field );
    }

    detailsFooter.addElement( footerElement );
  }
}
 
Example 20
Source File: ElementFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Applies the defined name to the created element.
 *
 * @param e
 *          the element which was created.
 */
protected void applyElementName( final Element e ) {
  if ( getName() != null ) {
    e.setName( getName() );
  }
}