Class K2DElement
java.lang.Object
com.kheops.jmap.client.graphics2D.K2DElement
- All Implemented Interfaces:
Shareable,Serializable,Cloneable
- Direct Known Subclasses:
K2DComplexElement,K2DEllipse,K2DImage,K2DPoint,K2DPolygon,K2DPolyline,K2DStyledElement,K2DText,KLabel,KLabelBox
An abstract class that graphic element classes overrides to be displayed on
a map in a JMap view. New types of elements can be created by overriding
the methods of this class. The main elements represent points, lines,
polygons (areas), text and images.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionObject[]Defines the values associated with this elements.static final intprotected longThe unique id of this element, -1 by default.protected booleanDefines whether this element is selected or not. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Objectclone()This will clone the current instance of K2DElement.protected static Object[]copyAttributes(Object[] attribs) abstract voiddraw(GraphicsRef gr, K2DTransform t, Style s) Deprecated.use draw(GraphicsRef, ViewState, Style) insteadvoiddraw(GraphicsRef gr, ViewState vs, Style s) Draws the element on the specified graphics object using the specified transformation and style.abstract voiddrawHandles(GraphicsRef gr, K2DTransform t, Style s) Deprecated.use drawHandles(GraphicsRef, ViewState, Style) insteadvoiddrawHandles(GraphicsRef gr, ViewState vs, Style s) This method draws handles around the element.booleanTests the equality of this element compared to the specified element.
Two elements are equals if they have the same id.static K2DElementfromByteArray(byte[] buf) Transforms a byte array buffer to a K2DElementstatic longUtility method that generates a unique element id based on current time.Object[]Gets the attributes of the element.abstract RectangleDeprecated.use getDisplayBounds(ViewState, Style) insteadgetDisplayBounds(ViewState vs, Style s) Determines the bounding box of the displayed element in DC.getDisplayBoundsWc(ViewState vs, Style s) Determines the bounding box including the style of element in WC (World Coordinates).abstract GeometryReturns the geometry object associated with the element.longgetId()Gets the id of the element.abstract intgetType()Return the current element type.inthashCode()booleanDetermines if the element is selected.voidsetAttributes(Object[] attributes) Sets the attributes of the element.abstract voidsetGeometry(Geometry geometry) Sets the geometry object associated with the element.voidsetId(long id) Sets the id of the element.voidsetSelected(boolean selected) Sets the selection state of the element.abstract Shareableshare()Creates a clone of the current element excluding the geometry which remains the same instance in both elements.
Useclone()to create a real copy of the current element.intsizeOf()Returns the estimated memory used by this object in bytes.protected static intsizeOfAttributes(Object[] attributes) Returns the estimated memory used by the specified attributes in bytes.static byte[]toByteArray(K2DElement elem) Transforms the specified K2DElement into an array of bytes.static byte[]toByteArray(ByteArrayOutputStream baos, K2DElement elem) Transforms the specified K2DElement into an array of bytes.abstract booleantouches(Point dcCoord, K2DTransform t, Style s) Deprecated.use touches(Point, ViewState, Style) insteadbooleanDetermines if the specified device coordinate touches the displayed element.
-
Field Details
-
DEFAULT_DC_BUFFER
public static final int DEFAULT_DC_BUFFER- See Also:
-
id
protected long idThe unique id of this element, -1 by default. -
selected
protected boolean selectedDefines whether this element is selected or not. -
attributes
Defines the values associated with this elements. Can be null.
-
-
Constructor Details
-
K2DElement
public K2DElement()
-
-
Method Details
-
generateUniqueId
public static long generateUniqueId()Utility method that generates a unique element id based on current time.- Returns:
- the generated id
-
getId
public long getId()Gets the id of the element.- Returns:
- the id of the element
-
setId
public void setId(long id) Sets the id of the element.- Parameters:
id- of the element
-
getAttributes
Gets the attributes of the element.- Returns:
- the attributes of the element
-
setAttributes
Sets the attributes of the element.- Parameters:
attributes- array of attributes.
-
isSelected
public boolean isSelected()Determines if the element is selected.- Returns:
- true if the element is selected, false otherwise
- See Also:
-
setSelected
public void setSelected(boolean selected) Sets the selection state of the element.- Parameters:
selected- if true, the element will be selected else it will be unselected
-
getGeometry
Returns the geometry object associated with the element.- Returns:
- The geometry object associated with the element.
-
setGeometry
Sets the geometry object associated with the element.- Parameters:
geometry- the geometry
-
touches
Deprecated.use touches(Point, ViewState, Style) insteadDetermines if the specified device coordinate touches the displayed element. A point touches the element if it overlaps the graphical representation of the element. The style of the element influences the result.- Parameters:
dcCoord- the device coordinatet- the transformation used to display the elements- the style used to display the element- Returns:
- true if the element contains the point, false otherwise
- See Also:
-
touches
Determines if the specified device coordinate touches the displayed element. A point touches the element if it overlaps the graphical representation of the element. The style of the element influences the result.- Parameters:
dcCoord- the device coordinatevs- the view state that provides context information to draw the element.s- the style used to display the element- Returns:
- true if the element contains the point, false otherwise
- See Also:
-
getDisplayBounds
Deprecated.use getDisplayBounds(ViewState, Style) insteadDetermines the bounding box of the displayed element in DC. The bounding box is the smallest possible rectangle in which the displayed element fits entirely.- Parameters:
t- the transformation used to calculate the display bounds of the element.s- the style used to calculate the display bounds of the element.- Returns:
- the bounding box of the displayed element
-
getDisplayBounds
Determines the bounding box of the displayed element in DC. The bounding box is the smallest possible rectangle in which the displayed element fits entirely.- Parameters:
vs- the view state that provides context information to calculate the display bounds of the element.s- the style used to calculate the display bounds of the element.- Returns:
- the bounding box of the displayed element
-
sizeOf
public int sizeOf()Returns the estimated memory used by this object in bytes.- Returns:
- the estimated memory used by this object in bytes.
-
draw
Deprecated.use draw(GraphicsRef, ViewState, Style) insteadDraws the element on the specified graphics object using the specified transformation and style.- Parameters:
gr- a wrapper to the Graphics object to draw ont- the transformation to apply to the elements- the style that defines the appearance of the element
-
draw
Draws the element on the specified graphics object using the specified transformation and style.- Parameters:
gr- a wrapper to the Graphics object to draw onvs- the view state that provides context information to draw the element.s- the style that defines the appearance of the element
-
drawHandles
Deprecated.use drawHandles(GraphicsRef, ViewState, Style) insteadThis method draws handles around the element. The position of the handles is implementation dependent. These handles are typically used to modify the geometry of the element.- Parameters:
gr- the Graphics object to draw on.t- the transformation to apply to the element.s- the style of the element.
-
drawHandles
This method draws handles around the element. The position of the handles is implementation dependent. These handles are typically used to modify the geometry of the element.- Parameters:
gr- the Graphics object to draw on.vs- the view state that provides context information to draw the handles of the element.s- the style of the element.
-
clone
This will clone the current instance of K2DElement. The cloned element is always a deep copy of the source element. -
getType
public abstract int getType()Return the current element type.- Returns:
- the element type.
- See Also:
-
copyAttributes
-
sizeOfAttributes
Returns the estimated memory used by the specified attributes in bytes.- Parameters:
attributes- attributes to include in the computation.- Returns:
- the estimated memory used by the specified attributes in bytes.
- See Also:
-
hashCode
public int hashCode() -
equals
Tests the equality of this element compared to the specified element.
Two elements are equals if they have the same id. -
toByteArray
Transforms the specified K2DElement into an array of bytes.- Parameters:
elem- the K2DElement to be transformed.- Returns:
- byte[] the result byte array.
-
toByteArray
Transforms the specified K2DElement into an array of bytes.- Parameters:
baos- the ByteArrayOutputStream to use.elem- the K2DElement to be transformed.- Returns:
- byte[] the result byte array.
-
fromByteArray
Transforms a byte array buffer to a K2DElement- Parameters:
buf- the byte array buffer- Returns:
- K2Delement the corresponding element.
-
getDisplayBoundsWc
Determines the bounding box including the style of element in WC (World Coordinates). The bounding box is the smallest possible rectangle in which the displayed element fits entirely. This method offers a basic implementation by transforming the DC getDisplayBounds method result in WC. To optimize performance, each K2DElement should override this method with its own implementation. See existing implementations (K2DPolygon, K2DPoint, K2DPolyline, etc.) for examples.- Parameters:
vs- the view state that provides context information to calculate the display bounds of the element.s- the style used used to calculate the display bounds of the element.- Returns:
- the bounding box of the displayed element in WC
- Since:
- 6.0j
-