Class K2DStyledElement

java.lang.Object
com.kheops.jmap.client.graphics2D.K2DElement
com.kheops.jmap.client.graphics2D.K2DStyledElement
All Implemented Interfaces:
Shareable, Serializable, Cloneable
Direct Known Subclasses:
StyleAnimationWrapper

public class K2DStyledElement extends K2DElement
A class encapsulating a Style object and a K2DElement object. When drawn, the element will have the appearance specified by the associated style. This class is useful when elements must have a specific style, independent from the style of the layer they belong to.
See Also:
  • Field Details

    • style

      protected Style style
    • selectionStyle

      protected Style selectionStyle
    • element

      protected K2DElement element
  • Constructor Details

    • K2DStyledElement

      public K2DStyledElement()
      Constructor for bean compliance only.
    • K2DStyledElement

      public K2DStyledElement(K2DElement element, Style style)
      Creates an object containing a K2DElement and a Style. The id of this element will be the same as the specified element.
      Parameters:
      element - The K2DElement
      style - The Style associated with the K2DElement
    • K2DStyledElement

      public K2DStyledElement(K2DElement element, Style style, Style selectionStyle)
      Creates an object containing a K2DElement and a Style. The id of this element will be the same as the specified element.
      Parameters:
      element - The K2DElement
      style - The Style associated with the K2DElement
      selectionStyle - The selection Style associated with the K2DElement. If null, the default style will be used.
  • Method Details

    • clone

      public Object clone()
      Clones the current K2DStyledElement.
      Specified by:
      clone in class K2DElement
      Returns:
      a new instance of the current K2DStyledElement
    • getElement

      public K2DElement getElement()
      Gets the K2DElement
      Returns:
      the element of this StyledElement
    • getStyle

      public Style getStyle()
      Gets the Style associated with the K2DElement
      Returns:
      style the corresponding style.
    • setElement

      public void setElement(K2DElement element)
      Sets the K2DElement
      Parameters:
      element - the associated element.
    • setStyle

      public void setStyle(Style style)
      Sets the Style associated with the K2DElement
      Parameters:
      style - the corresponding style
    • setElementAndStyle

      public void setElementAndStyle(K2DElement element, Style style)
      Sets the Style and The K2DElement
      Parameters:
      element - the K2Delement that will associated with this K2DStyledElement instance
      style - the style that will associated with this K2DElement instance
    • getId

      public long getId()
      Gets the id of the element.
      Overrides:
      getId in class K2DElement
      Returns:
      the id of the element
    • setId

      public void setId(long id)
      Sets the id of the element.
      Overrides:
      setId in class K2DElement
      Parameters:
      id - the new id of the element
    • getAttributes

      public Object[] getAttributes()
      Description copied from class: K2DElement
      Gets the attributes of the element.
      Overrides:
      getAttributes in class K2DElement
      Returns:
      the attributes
    • isSelected

      public boolean isSelected()
      Description copied from class: K2DElement
      Determines if the element is selected.
      Overrides:
      isSelected in class K2DElement
      Returns:
      if the element is selected
      See Also:
    • setAttributes

      public void setAttributes(Object[] attributes)
      Description copied from class: K2DElement
      Sets the attributes of the element.
      Overrides:
      setAttributes in class K2DElement
      Parameters:
      attributes -
    • setSelected

      public void setSelected(boolean selected)
      Description copied from class: K2DElement
      Sets the selection state of the element.
      Overrides:
      setSelected in class K2DElement
      Parameters:
      selected -
    • draw

      @Deprecated public 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. If the element is selected the style sent will be used to draw the element. Else the style specified in the constructor will be used to draw the element.
      Specified by:
      draw in class K2DElement
      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, only used if the style of this K2DStyledElement is null
    • draw

      public void draw(GraphicsRef gr, ViewState vs, Style s)
      Draws the element on the specified graphics object using the specified ViewState. If the element is selected the style sent will be used to draw the element. Else the style specified in the constructor will be used to draw the element.
      Overrides:
      draw in class K2DElement
      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, only used if the style of this K2DStyledElement is null
    • sizeOf

      public int sizeOf()
      Returns the estimated memory used by this object in bytes.
      Overrides:
      sizeOf in class K2DElement
      Returns:
      the estimated memory used by this object in bytes.
    • share

      public Shareable share()
      Description copied from class: K2DElement
      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
      Specified by:
      share in class K2DElement
      Returns:
      a shared instance of the current element.
      See Also:
    • drawHandles

      public void drawHandles(GraphicsRef gr, K2DTransform t, Style s)
      Description copied from class: K2DElement
      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.
      Specified by:
      drawHandles in class K2DElement
      Parameters:
      gr - the Graphics object to draw on.
      t - the transformation to apply to the element.
      s - the style of the element.
    • getDisplayBounds

      public Rectangle getDisplayBounds(K2DTransform t, Style s)
      Description copied from class: K2DElement
      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.
      Specified by:
      getDisplayBounds in class K2DElement
      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
    • getGeometry

      public Geometry getGeometry()
      Description copied from class: K2DElement
      Returns the geometry object associated with the element.
      Specified by:
      getGeometry in class K2DElement
      Returns:
      The geometry object associated with the element.
    • setGeometry

      public void setGeometry(Geometry geometry)
      Description copied from class: K2DElement
      Sets the geometry object associated with the element.
      Specified by:
      setGeometry in class K2DElement
      Parameters:
      geometry - the geometry
    • touches

      public boolean touches(Point dcCoord, K2DTransform t, 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.
      Specified by:
      touches in class K2DElement
      Parameters:
      dcCoord - the device coordinate
      t - the transformation used to display the element
      s - the style used to display the element - not used by the K2DStyledElement.
      Returns:
      true if the element contains the point, false otherwise
      See Also:
    • getType

      public int getType()
      Description copied from class: K2DElement
      Return the current element type.
      Specified by:
      getType in class K2DElement
      Returns:
      the element type.
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class K2DElement
    • 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.
      Overrides:
      getDisplayBoundsWc in class K2DElement
      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