public interface IlvMapAttributeFilter extends IlvPersistentObject
IlvMapAttributeFilter
interface represents a filter used
to dynamically change attribute values.
class ColorAttributeFilter implements IlvMapAttributeFilter { public ColorAttributeFilter() { // need a public constructor . } public ColorAttributeFilter(IlvInputStream stream) { // need a public constructor with IlvInputStream. } Color convertObjectToColor(Object o) { if(o == null) return Color.white; return new Color(o.hashCode()); } Color computeColorFrom(IlvGraphic g) { IlvAttributeProperty p = getAttributeProperty(g); if(p == null) return null; Object o = p.getValue("VALUE"); return convertObjectToColor(o); } static IlvAttributeProperty getAttributeProperty(IlvGraphic g) { if (g == null) return null; IlvAttributeProperty p = (IlvAttributeProperty) g.getNamedProperty(IlvAttributeProperty.NAME); if (p != null) return p; if (g instanceof IlvGraphicSet) { IlvGraphicSet gs = (IlvGraphicSet) g; IlvGraphicEnumeration e = gs.getObjects(); while (e.hasMoreElements()) { IlvGraphic child = e.nextElement(); p = getAttributeProperty(child, true); if (p != null) return p; } } if (g.getGraphicBag() instanceof IlvGraphicSet) { p = getAttributeProperty((IlvGraphic) g.getGraphicBag(), false); if (p != null) return p; } return null; } public Object get(IlvGraphic g, String attributeName) { if(IlvPolylineStyle.FOREGROUND.equals(attributeName)) { Color ret = computeColorFrom(g); if(ret == null) return DEFAULT_VALUE; return ret; } return DEFAULT_VALUE; } public void write(IlvOutputStream stream) throws IOException { // implements IlvPersistentObject } }
IlvMapStyle
for an
IlvMapLayer
.
IlvMapLayer layer = getLayer(); lvMapStyle style = layer.getStyle(); style.setAttributeFilter(new ColorAttributeFilter());
Modifier and Type | Field and Description |
---|---|
static Object |
DEFAULT_VALUE
The value returned by the
get method if a different
value has not been calculated. |
Modifier and Type | Method and Description |
---|---|
Object |
get(IlvGraphic g,
String attributeName)
This method is is invoked when the
IlvMapStyle instance this
object is attached to attempts to retrieve an attribute value. |
write
static final Object DEFAULT_VALUE
get
method if a different
value has not been calculated.Object get(IlvGraphic g, String attributeName)
IlvMapStyle
instance this
object is attached to attempts to retrieve an attribute value.
This method can return a value different from the one that is stored in the
style. The value returned depends on the metadata found in the
IlvAttributeProperty
instance stored in g
.
g
- The current IlvGraphic
.attributeName
- The name of the attribute to be retrieved.this.DEFAULT_VALUE
if no change
is calculated.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.