📄 band.java
字号:
{
final Element e = (Element) it.next();
if (e.getName() != null)
{
if (e.getName().equals(name))
{
return e;
}
}
}
return null;
}
/**
* Removes an element from the band.
* <p>
* You should not use this method on a band acquired from a <code>ReportState</code> or
* <code>Function</code>.
*
* @param e the element to be removed.
*/
public void removeElement(final Element e)
{
if (e == null)
{
throw new NullPointerException();
}
if (e.getParent() != this)
{
// this is none of my childs, ignore the request ...
return;
}
e.getStyle().removeDefaultParent(getBandDefaults());
e.setParent(null);
if (getStyleSheetCollection() != null)
{
e.unregisterStyleSheetCollection(getStyleSheetCollection());
}
allElements.remove(e);
allElementsCached = null;
invalidateLayout();
}
/**
* Returns all child-elements of this band as immutable list.
*
* @return an immutable list of all registered elements for this band.
*/
public List getElements()
{
return Collections.unmodifiableList(allElements);
}
/**
* Returns the number of elements in this band.
*
* @return the number of elements of this band.
*/
public int getElementCount()
{
return allElements.size();
}
/**
* Returns an array of the elements in the band. This method never returns null.
*
* @return the elements.
*/
public synchronized Element[] getElementArray()
{
if (allElementsCached == null)
{
Element[] elements = new Element[allElements.size()];
elements = (Element[]) allElements.toArray(elements);
allElementsCached = elements;
}
return allElementsCached;
}
/**
* Returns the element stored add the given index.
*
* @param index the element position within this band
* @return the element
* @throws IndexOutOfBoundsException if the index is invalid.
*/
public Element getElement(final int index)
{
if (allElementsCached == null)
{
Element[] elements = new Element[allElements.size()];
elements = (Element[]) allElements.toArray(elements);
allElementsCached = elements;
}
return allElementsCached[index];
}
/**
* Returns a string representation of the band and all the elements it contains, useful
* mainly for debugging purposes.
*
* @return a string representation of this band.
*/
public String toString()
{
final StringBuffer b = new StringBuffer();
b.append(this.getClass().getName());
b.append("={name=\"");
b.append(getName());
b.append("\", size=\"");
b.append(allElements.size());
b.append("\"}");
return b.toString();
}
/**
* Clones this band and all elements contained in this band.
*
* @return the clone of this band.
*
* @throws CloneNotSupportedException if this band or an element contained in this band does not
* support cloning.
*/
public Object clone() throws CloneNotSupportedException
{
final Band b = (Band) super.clone();
b.bandDefaults = bandDefaults.getCopy();
final int elementSize = allElements.size();
b.allElements = new ArrayList(elementSize);
b.allElementsCached = new Element[elementSize];
b.setParent(null);
final ElementStyleSheet myBandDefaults = bandDefaults;
final ElementStyleSheet cloneBandDefaults = b.bandDefaults;
if (allElementsCached != null)
{
for (int i = 0; i < allElementsCached.length; i++)
{
final Element eC = (Element) allElementsCached[i].clone();
b.allElements.add(eC);
b.allElementsCached[i] = eC;
eC.setParent(b);
eC.getStyle().removeDefaultParent(myBandDefaults);
eC.getStyle().addDefaultParent(cloneBandDefaults);
}
}
else
{
for (int i = 0; i < elementSize; i++)
{
final Element e = (Element) allElements.get(i);
final Element eC = (Element) e.clone();
b.allElements.add(eC);
b.allElementsCached[i] = eC;
eC.setParent(b);
eC.getStyle().removeDefaultParent(myBandDefaults);
eC.getStyle().addDefaultParent(cloneBandDefaults);
}
}
return b;
}
/**
* Returns the content type of the element. For bands, the content type is by
* default "X-container".
*
* @return the content type
*/
public String getContentType()
{
return CONTENT_TYPE;
}
/**
* Invalidates the layout. This method is called whenever a new element has been
* added. You should also call this method if you modified one of the elements of
* the band (eg. redefined the max, min or preferred size).
*/
public void invalidateLayout()
{
getLayout().invalidateLayout(this);
if (getParent() != null)
{
getParent().invalidateLayout();
}
}
/**
* Handles the unregistration of the stylesheet collection.
*/
protected void handleUnregisterStyleSheetCollection()
{
final Element[] elements = getElementArray();
for (int i = 0; i < elements.length; i++)
{
elements[i].unregisterStyleSheetCollection(getStyleSheetCollection());
}
//getStyleSheetCollection().remove(getBandDefaults());
getBandDefaults().unregisterStyleSheetCollection(getStyleSheetCollection());
super.handleUnregisterStyleSheetCollection();
}
/**
* Handles the registration of the stylesheet collection.
*/
protected void handleRegisterStyleSheetCollection()
{
final Element[] elements = getElementArray();
for (int i = 0; i < elements.length; i++)
{
elements[i].registerStyleSheetCollection(getStyleSheetCollection());
}
//getStyleSheetCollection().addStyleSheet(getBandDefaults());
getBandDefaults().registerStyleSheetCollection(getStyleSheetCollection());
super.handleRegisterStyleSheetCollection();
}
/**
* Updates the stylesheet collection for this element and all substylesheets.
* This method must be called after the element was cloned, to make sure that
* all stylesheets are registered properly.
* <p>
* If you don't call this function after cloning prepare to be doomed.
* This method will replace all inherited stylesheets with clones from the stylesheet
* collection.
*
* @param sc the stylesheet collection that contains the updated information and
* that should be assigned with that element.
* @throws NullPointerException if the given stylesheet collection is null.
* @throws InvalidStyleSheetCollectionException
* if there is an other stylesheet collection already registered with that element.
*/
public void updateStyleSheetCollection(final StyleSheetCollection sc)
throws InvalidStyleSheetCollectionException
{
if (sc == null)
{
throw new NullPointerException("StyleSheetCollection is null.");
}
if (getStyleSheetCollection() != null)
{
throw new NullPointerException("There is a stylesheet collection already registered.");
}
final Element[] elements = getElementArray();
for (int i = 0; i < elements.length; i++)
{
elements[i].updateStyleSheetCollection(sc);
}
sc.updateStyleSheet(getBandDefaults());
super.updateStyleSheetCollection(sc);
registerStyleSheetCollection(sc);
}
/**
* 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
(BandStyleSheet.PAGEBREAK_BEFORE);
}
/**
* Defines, 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.
*
* @param pagebreakBeforePrint set to true, if to force a pagebreak before
* this band is printed, false otherwise
*/
public void setPagebreakBeforePrint(final boolean pagebreakBeforePrint)
{
getStyle().setBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_BEFORE, pagebreakBeforePrint);
}
/**
* 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 isPagebreakAfterPrint()
{
return getStyle().getBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_AFTER);
}
/**
* Defines, 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.
*
* @param pagebreakAfterPrint set to true, if to force a pagebreak before
* this band is printed, false otherwise
*/
public void setPagebreakAfterPrint(final boolean pagebreakAfterPrint)
{
getStyle().setBooleanStyleProperty
(BandStyleSheet.PAGEBREAK_AFTER, pagebreakAfterPrint);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -