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

public abstract class K2DElement extends Object implements Serializable, Shareable, Cloneable
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 Details

    • DEFAULT_DC_BUFFER

      public static final int DEFAULT_DC_BUFFER
      See Also:
    • id

      protected long id
      The unique id of this element, -1 by default.
    • selected

      protected boolean selected
      Defines whether this element is selected or not.
    • attributes

      public Object[] 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

      public Object[] getAttributes()
      Gets the attributes of the element.
      Returns:
      the attributes of the element
    • setAttributes

      public void setAttributes(Object[] attributes)
      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

      public abstract Geometry getGeometry()
      Returns the geometry object associated with the element.
      Returns:
      The geometry object associated with the element.
    • setGeometry

      public abstract void setGeometry(Geometry geometry)
      Sets the geometry object associated with the element.
      Parameters:
      geometry - the geometry
    • touches

      @Deprecated public abstract boolean touches(Point dcCoord, K2DTransform t, Style s)
      Deprecated.
      use touches(Point, ViewState, Style) instead
      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 coordinate
      t - the transformation used to display the element
      s - the style used to display the element
      Returns:
      true if the element contains the point, false otherwise
      See Also:
    • touches

      public boolean touches(Point dcCoord, ViewState vs, Style s)
      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 coordinate
      vs - 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 public abstract Rectangle getDisplayBounds(K2DTransform t, Style s)
      Deprecated.
      use getDisplayBounds(ViewState, Style) instead
      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:
      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

      public Rectangle getDisplayBounds(ViewState vs, Style s)
      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 public abstract void draw(GraphicsRef gr, K2DTransform t, Style s)
      Deprecated.
      use draw(GraphicsRef, ViewState, Style) instead
      Draws the element on the specified graphics object using the specified transformation and style.
      Parameters:
      gr - a wrapper to the Graphics object to draw on
      t - the transformation to apply to the element
      s - the style that defines the appearance of the element
    • draw

      public void draw(GraphicsRef gr, ViewState vs, Style s)
      Draws the element on the specified graphics object using the specified transformation and style.
      Parameters:
      gr - a wrapper to the Graphics object to draw on
      vs - the view state that provides context information to draw the element.
      s - the style that defines the appearance of the element
    • drawHandles

      @Deprecated public abstract void drawHandles(GraphicsRef gr, K2DTransform t, Style s)
      Deprecated.
      use drawHandles(GraphicsRef, ViewState, Style) instead
      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.
      t - the transformation to apply to the element.
      s - the style of the element.
    • drawHandles

      public void drawHandles(GraphicsRef gr, ViewState vs, Style s)
      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

      public abstract Object clone()
      This will clone the current instance of K2DElement. The cloned element is always a deep copy of the source element.
      Overrides:
      clone in class Object
      Returns:
      a new instance of K2DElement which is equal to the specified the current element.
    • getType

      public abstract int getType()
      Return the current element type.
      Returns:
      the element type.
      See Also:
    • copyAttributes

      protected static Object[] copyAttributes(Object[] attribs)
    • sizeOfAttributes

      protected static int sizeOfAttributes(Object[] attributes)
      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()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Tests the equality of this element compared to the specified element.
      Two elements are equals if they have the same id.
      Overrides:
      equals in class Object
      Parameters:
      o - the element to be tested.
      Returns:
      whether these elements are equals.
    • toByteArray

      public static byte[] toByteArray(K2DElement elem)
      Transforms the specified K2DElement into an array of bytes.
      Parameters:
      elem - the K2DElement to be transformed.
      Returns:
      byte[] the result byte array.
    • toByteArray

      public static byte[] toByteArray(ByteArrayOutputStream baos, K2DElement elem)
      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

      public static K2DElement fromByteArray(byte[] buf)
      Transforms a byte array buffer to a K2DElement
      Parameters:
      buf - the byte array buffer
      Returns:
      K2Delement the corresponding element.
    • share

      public abstract Shareable share()
      Creates a clone of the current element excluding the geometry which remains the same instance in both elements.
      Use clone() to create a real copy of the current element.
      Specified by:
      share in interface Shareable
      Returns:
      a shared instance of the current element.
      See Also:
    • getDisplayBoundsWc

      public Rectangle getDisplayBoundsWc(ViewState vs, Style s)
      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