public static Band createCell( final Element dataItem, final int rowSpan, final int colSpan ) { final Band tableCell = new Band(); tableCell.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE_CELL ); tableCell.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 150f ); tableCell.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 200f ); tableCell.setAttribute( AttributeNames.Table.NAMESPACE, AttributeNames.Table.ROWSPAN, rowSpan ); tableCell.setAttribute( AttributeNames.Table.NAMESPACE, AttributeNames.Table.COLSPAN, colSpan ); tableCell.addElement( dataItem ); return tableCell; }
/** * Clones this band and all elements contained in this band. After the cloning the band is no longer connected to a * report definition. * * @return the clone of this band. */ public AbstractRootLevelBand clone() { final AbstractRootLevelBand rootLevelBand = (AbstractRootLevelBand) super.clone(); if ( rootLevelBand.subReports != null ) { rootLevelBand.subReports = (ArrayList<SubReport>) rootLevelBand.subReports.clone(); rootLevelBand.subReports.clear(); for ( int i = 0; i < subReports.size(); i++ ) { final SubReport report = subReports.get( i ); final SubReport clone = (SubReport) report.clone(); clone.setParent( rootLevelBand ); rootLevelBand.subReports.add( clone ); } } return rootLevelBand; }
public void removeElement( int index ) { removeElement( getElement( index ) ); }
public ReportElement create() { final Band element = new Band(); element.setElementType( INSTANCE ); return element; }
/** * Adds a report element to the band. * * @param element * the element that should be added * @throws NullPointerException * if the given element is null * @throws IllegalArgumentException * if the position is invalid, either negative or greater than the number of elements in this band or if the * given element is a parent of this element. */ public void addElement( final Element element ) { addElement( getElementCount(), element ); }
public void testBandCreate() { Band b = new Band(); assertNotNull( b.getDataSource() ); assertNotNull( b.getStyle() ); assertNotNull( b.getName() ); assertTrue( b.isVisible() ); assertNull( b.getParent() ); assertNotNull( b.getElementArray() ); assertTrue( b.getElementCount() == 0 ); assertTrue( b.getElementType() instanceof BandType ); assertFalse( b.isPagebreakBeforePrint() ); assertFalse( b.isPagebreakAfterPrint() ); InstanceID id = new InstanceID(); b = new Band( id ); assertNotNull( b.getTreeLock() ); assertEquals( id, b.getTreeLock() ); assertTrue( b.getElementType() instanceof BandType ); assertFalse( b.isPagebreakBeforePrint() ); assertFalse( b.isPagebreakAfterPrint() ); b = new Band( true, true ); assertTrue( b.getElementType() instanceof BandType ); assertTrue( b.isPagebreakBeforePrint() ); assertTrue( b.isPagebreakAfterPrint() ); }
public void testGetElement() { Band band = new Band(); try { band.getElement( null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } Element elem = mock( Element.class ); doReturn( "test_name" ).when( elem ).getName(); band.addElement( elem ); assertEquals( 1, band.getElementCount() ); assertEquals( elem, band.getElement( "test_name" ) ); }
public void testElementClone() throws CloneNotSupportedException { final Band band = new Band(); final Element e = new Element(); band.addElement( e ); assertNotNull( e.getParent() ); assertNotNull( e.getDataSource() ); assertNotNull( e.getStyle() ); assertNotNull( e.getName() ); assertTrue( e.isVisible() ); final Element clone = (Element) e.clone(); assertNull( clone.getParent() ); assertNotNull( clone.getDataSource() ); assertNotNull( clone.getStyle() ); assertNotNull( clone.getName() ); assertTrue( clone.isVisible() ); final Band clonedBand = (Band) band.clone(); assertNull( clonedBand.getParent() ); assertNotNull( clonedBand.getDataSource() ); assertNotNull( clonedBand.getStyle() ); assertNotNull( clonedBand.getName() ); assertTrue( clonedBand.isVisible() ); final Element clientElement = clonedBand.getElement( 0 ); assertNotNull( clientElement.getParent() ); assertNotNull( clientElement.getDataSource() ); assertNotNull( clientElement.getStyle() ); assertNotNull( clientElement.getName() ); assertTrue( clientElement.isVisible() ); assertEquals( clonedBand, clientElement.getParent() ); }
public static Band createCell( final int rowNumber, final int colNumber, final float cellWidth, final float cellHeight, final Element... elements ) { final Band cell = new Band(); cell.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE_CELL ); cell.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, cellWidth ); cell.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, cellHeight ); cell.setName( "c-" + rowNumber + "-" + colNumber ); for ( int i = 0; i < elements.length; i++ ) { final Element element = elements[i]; cell.addElement( element ); } return cell; }
public void setElementAt( final int position, final Element element ) { if ( position < 0 ) { throw new IllegalArgumentException( "Position < 0" ); } if ( position >= getElementCount() ) { throw new IllegalArgumentException( "Position >= size" ); } if ( element == null ) { throw new NullPointerException( "Band.addElement(...): element is null." ); } validateLooping( element ); if ( unregisterParent( element ) ) { return; } if ( allElements == null ) { throw new IllegalStateException( "The throws above should have caught that state" ); } // add the element, update the childs Parent and the childs stylesheet. final Element o = allElements.set( position, element ); o.setParent( null ); allElementsCached = null; // then add the parents, or the band's parent will be unregistered .. registerAsChild( element ); notifyNodeChildRemoved( o ); notifyNodeChildAdded( element ); }
/** * Returns, whether the page layout manager should perform a pagebreak before this page is printed. This will have no * effect on empty pages or if the band is no root-level band. * * @return true, if to force a pagebreak before this band is printed, false otherwise */ public boolean isPagebreakBeforePrint() { return getStyle().getBooleanStyleProperty( BandStyleKeys.PAGEBREAK_BEFORE ); }
public void testAddElementTooBigPosition() { try { Band band = new Band(); band.addElement( 10, mock( Element.class ) ); fail( "should throw exception" ); } catch ( IllegalArgumentException e ) { // expected } }
public static Band createAutoBox( final Element... boxes ) { final Band tableRow = new Band(); tableRow.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_AUTO ); for ( int i = 0; i < boxes.length; i++ ) { tableRow.addElement( boxes[i] ); } return tableRow; }
private boolean isEmptyRootBand( final Band band ) { if ( band.getName().startsWith( Band.ANONYMOUS_BAND_PREFIX ) == false ) { return false; } if ( band.getName().startsWith( Element.ANONYMOUS_ELEMENT_PREFIX ) == false ) { return false; } if ( band.getElementCount() != 0 ) { return false; } if ( band instanceof RootLevelBand ) { final RootLevelBand rlb = (RootLevelBand) band; if ( rlb.getSubReportCount() > 0 ) { return false; } } final ElementStyleSheet styleSheet = band.getStyle(); if ( isStyleSheetEmpty( styleSheet ) ) { return true; } return false; }
public void testAddElements() { Band band = new Band(); try { band.addElements( null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } Element elem = mock( Element.class ); List<Element> elements = new ArrayList<Element>(); elements.add( elem ); band.addElements( elements ); assertEquals( 1, band.getElementCount() ); assertEquals( elem, band.getElement( 0 ) ); }
public static Band createTable( final TableLayout tableLayout ) { final Band b = new Band(); b.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE ); b.getStyle().setStyleProperty( ElementStyleKeys.INVISIBLE_CONSUMES_SPACE, true ); b.getStyle().setStyleProperty( BandStyleKeys.TABLE_LAYOUT, tableLayout ); final StyleResolver resolver = new SimpleStyleResolver(); final ResolverStyleSheet resolverTarget = new ResolverStyleSheet(); resolver.resolve( b, resolverTarget ); b.setComputedStyle( new SimpleStyleSheet( resolverTarget ) ); return b; }
public static Band createCell( final float width, final float height, final int rowSpan, final int colSpan ) { final Band tableCell = new Band(); tableCell.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE_CELL ); tableCell.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, width ); tableCell.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, height ); tableCell.setAttribute( AttributeNames.Table.NAMESPACE, AttributeNames.Table.ROWSPAN, rowSpan ); tableCell.setAttribute( AttributeNames.Table.NAMESPACE, AttributeNames.Table.COLSPAN, colSpan ); return tableCell; } }
public void testBandMethods() { final Band b = new Band(); assertTrue( b.isVisible() ); b.setVisible( false ); assertTrue( b.isVisible() == false ); b.setVisible( true ); assertTrue( b.isVisible() ); try { b.setDataSource( null ); fail(); } catch ( NullPointerException npe ) { // expected, ignored } b.toString(); }
public void testFindElement() { final Band noLate = new Band(); noLate.setName( "noLate" ); final Band landScape = new Band(); landScape.setName( "landscape" ); landScape.addElement( noLate ); final ItemBand band = new ItemBand(); band.addElement( landScape ); assertEquals( noLate, FunctionUtilities.findElement( band, "noLate" ) ); } }
public void testAddElement() { final Band b = new Band(); assertTrue( b.getElementCount() == 0 ); b.addElement( 0, new Element() ); assertTrue( b.getElementCount() == 1 ); b.addElement( new Element() ); assertTrue( b.getElementCount() == 2 ); b.addElement( 0, new Element() ); assertTrue( b.getElementCount() == 3 ); b.addElement( 2, new Element() ); assertTrue( b.getElementCount() == 4 ); try { b.addElement( 5, new Element() ); fail(); } catch ( IllegalArgumentException iob ) { b.addElement( null ); fail(); } catch ( NullPointerException npe ) { b.addElement( b ); fail(); } catch ( IllegalArgumentException ia ) { final Band b1 = new Band(); final Band b2 = new Band(); final Band b3 = new Band(); b1.addElement( b2 ); b2.addElement( b3 ); b3.addElement( b1 );