📄 band.java
字号:
final Iterator it = allElements.iterator();
while (it.hasNext())
{
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;
}
if (getStyleSheetCollection() != null)
{
e.unregisterStyleSheetCollection(getStyleSheetCollection());
}
e.getStyle().removeDefaultParent(getBandDefaults());
e.setParent(null);
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 com.jrefinery.report.targets.style.InvalidStyleSheetCollectionException
* if there is an other stylesheet collection already registered with that element.
*/
public void updateStyleSheetCollection(final StyleSheetCollection sc)
{
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);
}
/// DEPRECATED METHODS //////////////////////////////////////////////////////////////////////////
/**
* Defines the minimum height of the band.
* <p>
* This property is deprecated, please don't use it anymore.
* The minimum height can be defined using the MINIMUMSIZE property in the
* ElementStyleSheet if needed.
* <p>
* Using this method will remove any previously set minimumsize of this band.
*
* @param height the new height. The minimum width is set to '0'.
* @deprecated do not manipulate the element properties that way, use a stylesheet
*/
public void setHeight(final float height)
{
getStyle().setStyleProperty(ElementStyleSheet.MINIMUMSIZE, new FloatDimension(0, height));
}
/**
* Queries the minimum size of this band and returns the height portion.
*
* @return the minimum height of this band.
* @deprecated do not manipulate the element properties that way, use a stylesheet
* and an suitable layoutmanager using the correct stylesheet properties ...
*/
public float getHeight()
{
final Dimension2D d = (Dimension2D) getStyle().getStyleProperty(ElementStyleSheet.MINIMUMSIZE,
new FloatDimension(0, 0));
return (float) d.getHeight();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -