/** * Adds a collection of elements to the band. * * @param elements * the element collection. * @throws NullPointerException * if one of the given elements is null * @throws IllegalArgumentException * if one of the given element is a parent of this element. */ public void addElements( final Collection elements ) { if ( elements == null ) { throw new NullPointerException( "Band.addElements(...): collection is null." ); } final Iterator iterator = elements.iterator(); while ( iterator.hasNext() ) { final Element element = (Element) iterator.next(); addElement( 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 ); }
/** * Done parsing. * * @throws SAXException * if there is a parsing error. */ protected void doneParsing() throws SAXException { super.doneParsing(); final Band band = getElement(); for ( int i = 0; i < elementHandlers.size(); i++ ) { final ElementReadHandler readHandler = elementHandlers.get( i ); band.addElement( readHandler.getElement() ); } }
private ArrayList<Element> buildLabelElementList( final Band band, final int numRows, final int numElement, final int height, final int width ) { final ArrayList<Element> elementList = new ArrayList<Element>(); int currentX = 0; int currentY = 0; for ( int row = 0; row < numRows; row++ ) { for ( int elemNum = 0; elemNum < numElement; elemNum++ ) { final Rectangle coordinates = new Rectangle( currentX, currentY, width, height ); final String labelText = "Label-" + currentX + currentY; final Element label = createLabelElement( labelText, coordinates ); currentX += width; band.addElement( label ); elementList.add( label ); } currentY += height; } return elementList; }
protected void doneParsing() throws SAXException { super.doneParsing(); for ( int i = 0; i < items.size(); i++ ) { final XmlReadHandler handler = (XmlReadHandler) items.get( i ); final Element element = (Element) handler.getObject(); band.addElement( element ); } } }
public void testAddElementTooBigPosition() { try { Band band = new Band(); band.addElement( 10, mock( Element.class ) ); fail( "should throw exception" ); } catch ( IllegalArgumentException e ) { // expected } }
/** * Done parsing. * * @throws org.xml.sax.SAXException * if there is a parsing error. */ protected void doneParsing() throws SAXException { super.doneParsing(); final Band band = (Band) getElement(); for ( int i = 0; i < elementHandlers.size(); i++ ) { final ElementReadHandler readHandler = (ElementReadHandler) elementHandlers.get( i ); band.addElement( readHandler.getElement() ); } for ( int i = 0; i < styleExpressionHandlers.size(); i++ ) { final StyleExpressionHandler handler = (StyleExpressionHandler) styleExpressionHandlers.get( i ); final StyleKey key = handler.getKey(); if ( handler.getKey() != null ) { final Expression expression = handler.getExpression(); band.setStyleExpression( key, expression ); } } } }
public void testAddElementWrongPosition() { try { Band band = new Band(); band.addElement( -1, mock( Element.class ) ); fail( "should throw exception" ); } catch ( IllegalArgumentException e ) { // expected } }
/** * Done parsing. * * @throws SAXException * if there is a parsing error. */ protected void doneParsing() throws SAXException { for ( int i = 0; i < elementHandlers.size(); i++ ) { final XmlReadHandler readHandler = elementHandlers.get( i ); final Element e = (Element) readHandler.getObject(); band.addElement( e ); } for ( int i = 0; i < styleExpressionHandlers.size(); i++ ) { final StyleExpressionHandler handler = styleExpressionHandlers.get( i ); if ( handler.getKey() != null ) { band.setStyleExpression( handler.getKey(), handler.getExpression() ); } } band.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.SOURCE, getRootHandler().getSource() ); super.doneParsing(); }
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; }
@Test( expected = NullPointerException.class ) public void testAddNullElement() { try { Band band = new Band(); band.addElement( 0, null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } }
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" ) ); }
private Element process( final javax.swing.text.Element textElement ) throws BadLocationException { if ( textElement.isLeaf() ) { final int endOffset = textElement.getEndOffset(); final int startOffset = textElement.getStartOffset(); final String text = textElement.getDocument().getText( startOffset, endOffset - startOffset ); final Element result = new Element(); result.setElementType( LabelType.INSTANCE ); result.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text ); configureStyle( textElement.getAttributes(), result ); return result; } final Band band = new Band(); configureStyle( textElement.getAttributes(), band ); configureBand( textElement, band ); final int size = textElement.getElementCount(); for ( int i = 0; i < size; i++ ) { final Element element = process( textElement.getElement( i ) ); band.addElement( element ); } return band; }
public static Band createRow( final Element... boxes ) { final Band tableRow = new Band(); tableRow.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, BandStyleKeys.LAYOUT_TABLE_ROW ); tableRow.getStyle().setStyleProperty( ElementStyleKeys.MIN_WIDTH, 100f ); tableRow.getStyle().setStyleProperty( ElementStyleKeys.MIN_HEIGHT, 200f ); for ( int i = 0; i < boxes.length; i++ ) { tableRow.addElement( boxes[i] ); } return tableRow; }
public static Band convertToBand( final List<StyleKey> definedStyleKeys, final ReportElement element, final Element child ) { final Band b = new Band( element.getObjectID() ); final ElementStyleSheet targetStyle = b.getStyle(); final ElementStyleSheet sourceStyle = element.getStyle(); for ( StyleKey key : definedStyleKeys ) { targetStyle.setStyleProperty( key, sourceStyle.getStyleProperty( key ) ); } final String[] attrNs = element.getAttributeNamespaces(); for ( int i = 0; i < attrNs.length; i++ ) { final String attrNamespace = attrNs[ i ]; final String[] attrNames = element.getAttributeNames( attrNamespace ); for ( int j = 0; j < attrNames.length; j++ ) { final String attrName = attrNames[ j ]; final Object attrValue = element.getAttribute( attrNamespace, attrName ); b.setAttribute( attrNamespace, attrName, attrValue ); } } b.addElement( child ); b.getStyle().setStyleProperty( BandStyleKeys.LAYOUT, "block" ); return b; }
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 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 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; }
public void testSetElementAt() { Band band = new Band(); band.addElement( mock( Element.class ) ); Element elem = mock( Element.class ); try { band.setElementAt( -1, elem ); fail( "should throw exception" ); } catch ( IllegalArgumentException e ) { // expected } try { band.setElementAt( 10, elem ); fail( "should throw exception" ); } catch ( IllegalArgumentException e ) { // expected } try { band.setElementAt( 0, null ); fail( "should throw exception" ); } catch ( NullPointerException e ) { // expected } band.setElementAt( 0, elem ); assertEquals( 1, band.getElementCount() ); assertEquals( elem, band.getElement( 0 ) ); assertEquals( band, elem.getParentSection() ); }
@Test public void testDeepSubBandInlineSubReportDetection() { SubReport srInner = new SubReport(); Band band = new Band(); band.addElement( srInner ); SubReport sr = new SubReport(); sr.getReportHeader().addElement( band ); MasterReport report = new MasterReport(); report.getReportHeader().addSubReport( sr ); ReportStructureValidator v = new ReportStructureValidator(); Assert.assertFalse( v.isValidForFastProcessing( report ) ); }