📄 element.java
字号:
/**
* Returns the datasource for this element. You cannot override this function as the
* element needs always be the last consumer in the chain of filters. This function
* must never return null.
*
* @return the assigned datasource.
*/
public final DataSource getDataSource()
{
return datasource;
}
/**
* Sets the data source for this element. This datasource is queried on populateElements(),
* to fill in the values.
*
* @param ds the datasource (<code>null</code> not permitted).
*/
public void setDataSource(final DataSource ds)
{
if (ds == null)
{
throw new NullPointerException("Element.setDataSource(...) : null data source.");
}
this.datasource = ds;
}
/**
* Queries this element's datasource for a value.
*
* @return the value of the datasource, which can be null.
*/
public Object getValue()
{
final DataSource ds = getDataSource();
return ds.getValue();
}
/**
* Defines whether this element should be painted. The detailed implementation is
* up to the outputtarget.
*
* @return the current visiblity state.
*/
public boolean isVisible()
{
final Boolean b = (Boolean) getStyle().getStyleProperty(ElementStyleSheet.VISIBLE, Boolean.FALSE);
return b.booleanValue();
}
/**
* Defines, whether this element should be drawn.
*
* @param b the new visibility state
*/
public void setVisible(final boolean b)
{
getStyle().setStyleProperty(ElementStyleSheet.VISIBLE, b ? Boolean.TRUE : Boolean.FALSE);
}
/**
* Clones this Element, the datasource and the private stylesheet of this element.
* If this element was previously assigned with an stylesheet collection, then the
* clone is no longer assiged with that collection. You will have to register the
* element manually again.
*
* @return a clone of this element.
*
* @throws CloneNotSupportedException should never happen.
*/
public Object clone() throws CloneNotSupportedException
{
final Element e = (Element) super.clone();
e.style = style.getCopy();
e.datasource = (DataSource) datasource.clone();
e.styleSheetCollectionHelper = new ElementStyleSheetCollectionHelper(e);
return e;
}
/**
* Returns this elements private stylesheet. This sheet can be used to override
* the default values set in one of the parent-stylesheets.
*
* @return the element's stylesheet
*/
public ElementStyleSheet getStyle()
{
return style;
}
/**
* Defines the content-type for this element. The content-type is used as a hint
* how to process the contents of this element. An element implementation should
* restrict itself to the content-type set here, or the reportprocessing may fail
* or the element may not be printed.
* <p>
* An element is not allowed to change its content-type after ther report processing
* has started.
* <p>
* If an content-type is unknown to the output-target, the processor should ignore
* the content or clearly document its internal reprocessing. Ignoring is preferred.
*
* @return the content-type as string.
*/
public abstract String getContentType();
/**
* Returns the stylesheet collection which is assigned with this element and
* all stylesheets of this element.
*
* @return the element stylesheet collection or null, if no collection is assigned.
*/
public StyleSheetCollection getStyleSheetCollection()
{
return styleSheetCollectionHelper.getStyleSheetCollection();
}
/**
* Registers the given StyleSheet collection with this element. If there is already
* another stylesheet collection registered, this method will throw an
* <code>InvalidStyleSheetCollectionException</code>.
*
* @param styleSheetCollection the stylesheet collection that should be registered.
* @throws InvalidStyleSheetCollectionException if there is already an other
* stylesheet registered.
* @throws NullPointerException if the given stylesheet collection is null.
*/
public void registerStyleSheetCollection(final StyleSheetCollection styleSheetCollection)
{
styleSheetCollectionHelper.registerStyleSheetCollection(styleSheetCollection);
}
/**
* Unregisters the given stylesheet collection from this element. If this stylesheet
* collection is not registered with this element, this method will throw an
* <code>InvalidStyleSheetCollectionException</code>
*
* @param styleSheetCollection the stylesheet collection that should be unregistered.
* @throws InvalidStyleSheetCollectionException if there is already an other stylesheet
* registered.
* @throws NullPointerException if the given stylesheet collection is null.
*/
public void unregisterStyleSheetCollection(final StyleSheetCollection styleSheetCollection)
{
styleSheetCollectionHelper.unregisterStyleSheetCollection(styleSheetCollection);
}
/**
* Handles the unregistration of the stylesheet collection.
*/
protected void handleUnregisterStyleSheetCollection()
{
getStyle().unregisterStyleSheetCollection(getStyleSheetCollection());
}
/**
* Handles the registration of the stylesheet collection.
*/
protected void handleRegisterStyleSheetCollection()
{
getStyle().registerStyleSheetCollection(getStyleSheetCollection());
/**
* This is an assertation implementation ... leave it alive to be
* sure that everything works as expected ...
*/
if (getStyle().getStyleSheetCollection() != getStyleSheetCollection())
{
throw new IllegalStateException("HandleRegisterStyleSheetCollection failed: " +
getStyle().getName() + " for element " + getName());
}
}
/**
* 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)
{
if (sc == null)
{
throw new NullPointerException("StyleSheetCollection is null.");
}
if (getStyleSheetCollection() != null)
{
throw new InvalidStyleSheetCollectionException
("There is a stylesheet collection already registered.");
}
sc.updateStyleSheet(getStyle());
registerStyleSheetCollection(sc);
}
/// DEPRECATED METHODS //////////////////////////////////////////////////////////////////////////
// todo: Remove the deprecated method in version 0.8.5
/**
* Returns the paint used to draw this element. There is alway a paint defined
* for an element.
* <p>
* This method will be removed in version 0.8.5.
*
* @deprecated don't store and access the paint directly, use the stylesheet.
* @return The paint.
*/
public Paint getPaint()
{
final Paint retval = (Paint) getStyle().getStyleProperty(ElementStyleSheet.PAINT);
if (retval == null)
{
// assertation
throw new IllegalStateException("Element.getPaint(): no Paint defined.");
}
return retval;
}
/**
* Sets the paint for this element. The paint can be null, in this case the
* default paint of the band used to draw this element is used.
* <p>
* The paint object must be an instance of color. Generic paints are not permitted.
* <p>
* This method will be removed in version 0.8.5.
*
* @param p the paint for this element (null permitted).
*
* @deprecated use a stylesheet to define the paint. The paint object must be an
* instance of color.
*/
public void setPaint(final Paint p)
{
if (p == null)
{
getStyle().setStyleProperty(ElementStyleSheet.PAINT, null);
}
else if (p instanceof Color)
{
getStyle().setStyleProperty(ElementStyleSheet.PAINT, p);
}
else
{
throw new IllegalArgumentException("This style-key requires a Color object");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -