Class Component

java.lang.Object
com.spinyowl.legui.component.Component
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AbstractTextComponent, ImageView, Layer, Panel, ProgressBar, ScrollablePanel, ScrollBar, SelectBox, Slider, TextArea, Widget

public abstract class Component extends Object implements Serializable
Component is an object that have graphical representation in legui system.
See Also:
  • Constructor Details

    • Component

      public Component()
      Default constructor. Used to create component instance without any parameters.

      Also if you want to make it easy to use with Json marshaller/unmarshaller component should contain empty constructor.

    • Component

      public Component(float x, float y, float width, float height)
      Constructor with position and size parameters.
      Parameters:
      x - x position position in parent component.
      y - y position position in parent component.
      width - width of component.
      height - height of component.
    • Component

      public Component(org.joml.Vector2f position, org.joml.Vector2f size)
      Constructor with position and size parameters.
      Parameters:
      position - position position in parent component.
      size - size of component.
  • Method Details

    • getFocusedStyle

      public Style getFocusedStyle()
    • getHoveredStyle

      public Style getHoveredStyle()
    • getPressedStyle

      public Style getPressedStyle()
    • getStyle

      public Style getStyle()
      Returns component style.
      Returns:
      component style.
    • setStyle

      public void setStyle(Style style)
      Used to set component style.
      Parameters:
      style - component style to set.
    • getParent

      public Component getParent()
      Returns parent component. If returns null - current component is root component.
      Returns:
      null or parent component.
    • setParent

      public void setParent(Component parent)
      Used to set parent component. By default used by containers to attach component to container. Parent component used by renderers and event listeners and processors.

      Don't use this method if you want to attach component to container. In this case use add(Component) method.

      Parameters:
      parent - component container.
    • getListenerMap

      public ListenerMap getListenerMap()
      Returns event listeners for component instance.
      Returns:
      event listeners map.
    • setListenerMap

      public void setListenerMap(ListenerMap listenerMap)
      Used to set event listener map for component.
      Parameters:
      listenerMap - map of event listeners.
    • getPosition

      public org.joml.Vector2f getPosition()
      Returns position vector. Be careful during changing this vector.
      Returns:
      position vector.
    • setPosition

      public void setPosition(org.joml.Vector2f position)
      Used to set position of component.
      Parameters:
      position - new position for component.
    • setPosition

      public void setPosition(float x, float y)
      Used to set current position.
      Parameters:
      x - x position relative to parent component.
      y - y position relative to parent component.
    • getSize

      public org.joml.Vector2f getSize()
      Returns size vector of component. So to get width you can use.
       
       Vector2f size = component.getSize();
       float width = size.x;
       float height = size.y;
       
       
      Returns:
      size of component.
    • setSize

      public void setSize(org.joml.Vector2f size)
      Used to set size vector.
      Parameters:
      size - size vector.
    • setSize

      public void setSize(float width, float height)
      Used to set size vector.
      Parameters:
      width - width to set.
      height - height to set.
    • getAbsolutePosition

      public org.joml.Vector2f getAbsolutePosition()
      Returns absolute component position.
      Returns:
      position vector.
    • isEnabled

      public boolean isEnabled()
      Returns true if component enabled. By default if component enabled it receives and proceed events.
      Returns:
      true if component enabled. default value is Boolean.TRUE.
    • setEnabled

      public void setEnabled(boolean enabled)
      Used to enable or disable component. By default if component enabled it receives and proceed events.
      Parameters:
      enabled - flag to set.
    • isVisible

      public boolean isVisible()
      Returns true if component visible. By default if component visible it will be rendered and will receive events.
      Returns:
      true if component visible. default value is Boolean.TRUE.
    • intersects

      public boolean intersects(org.joml.Vector2f point)
      Used to determine if point intersects component (in screen space). This method uses component intersector.
      Parameters:
      point - point to check.
      Returns:
      true if component intersected by point.
    • getIntersector

      public Intersector getIntersector()
      Returns component intersector which used to check if cursor intersect component or not.
      Returns:
      intersector.
    • setIntersector

      public void setIntersector(Intersector intersector)
      Used to set intersector for component.
      Parameters:
      intersector - intersector.
    • getMetadata

      public Map<String,Object> getMetadata()
      Returns component metadata. Storage of some temporary statements. Can be used for example by stateless renderers.
      Returns:
      map of objects.
    • isHovered

      public boolean isHovered()
      Returns true if component is hovered.
      Returns:
      true if component is hovered.
    • setHovered

      public void setHovered(boolean hovered)
      Used to make component hovered or not.
      Parameters:
      hovered - new hovered value.
    • isFocused

      public boolean isFocused()
      Returns true if component is focused.
      Returns:
      true if component is focused.
    • setFocused

      public void setFocused(boolean focused)
      Used to make component focused or not.
      Parameters:
      focused - new hovered value.
    • isPressed

      public boolean isPressed()
      Returns true if component is pressed.
      Returns:
      true if component is pressed.
    • setPressed

      public void setPressed(boolean pressed)
      Used to make component pressed or not.
      Parameters:
      pressed - new hovered value.
    • getTooltip

      public Tooltip getTooltip()
      Returns tooltip if it persist.
      Returns:
      tooltip.
    • setTooltip

      public void setTooltip(Tooltip tooltip)
      Used to set tooltip to component.
      Parameters:
      tooltip - tooltip to set.
    • getTabIndex

      public int getTabIndex()
      Returns tab index.
      Returns:
      tab index.
    • setTabIndex

      public void setTabIndex(int tabIndex)
      Used to set tab index.
      Parameters:
      tabIndex - tab index.
    • isTabFocusable

      public boolean isTabFocusable()
      Returns true if component focused by tabbing.
      Returns:
      true if component focused by tabbing.
    • setTabFocusable

      public void setTabFocusable(boolean tabFocusable)
      Used to set tab affecting for component.
      Parameters:
      tabFocusable - new tab affecting state.
    • isFocusable

      public boolean isFocusable()
      Returns true if component focused.
      Returns:
      true if component focused.
    • setFocusable

      public void setFocusable(boolean focusable)
      Used to set component focusable.
      Note! You should take in consideration that component that marked as non-focusable will not receive any events. In fact this could be used to organize elements using containers.
      Parameters:
      focusable - new focusable state.
    • count

      public int count()
      Returns count of child components.
      Returns:
      count of child components.
      See Also:
    • isEmpty

      public boolean isEmpty()
      Returns true if component contains no elements.
      Returns:
      true if component contains no elements.
      See Also:
    • contains

      public boolean contains(Component component)
      Returns true if component contains specified component.
      Parameters:
      component - component to check.
      Returns:
      true if component contains specified component.
      See Also:
    • containerIterator

      public Iterator<Component> containerIterator()
      Returns an iterator over the elements in this component. The elements are returned in no particular order.
      Returns:
      an iterator over the elements in this component.
      See Also:
    • add

      public boolean add(Component component)
      Used to add component to component.
      Parameters:
      component - component to add.
      Returns:
      true if component is added.
      See Also:
    • add

      public void add(int index, Component component)
    • addAll

      public void addAll(Collection<? extends Component> components)
      Used to add components.
      Parameters:
      components - components nodes to add.
    • remove

      public boolean remove(Component component)
      Used to remove component.
      Parameters:
      component - component to remove.
      Returns:
      true if removed.
      See Also:
    • remove

      public Component remove(int index)
    • removeAll

      public void removeAll(Collection<? extends Component> components)
      Used to remove components.
      Parameters:
      components - components to remove.
      See Also:
    • removeIf

      public void removeIf(Predicate<? super Component> filter)
      Removes all of the elements of this component that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.
      Parameters:
      filter - a predicate which returns true for elements to be removed.
      See Also:
    • clearChildComponents

      public void clearChildComponents()
      Used to remove all child components from component.
      See Also:
    • containsAll

      public boolean containsAll(Collection<Component> components)
      Returns true if this Container contains all of the elements of the specified collection.
      Parameters:
      components - components collection to check.
      Returns:
      true if this Container contains all of the elements of the specified collection.
      See Also:
    • stream

      public Stream<Component> stream()
      Returns a sequential Stream with this collection as its source.
      Returns:
      a sequential Stream with this collection as its source.
      See Also:
    • parallelStream

      public Stream<Component> parallelStream()
      Returns a possibly parallel Stream with this collection as its source. It is allowable for this method to return a sequential stream.
      Returns:
      possibly parallel Stream with this collection as its source.
      See Also:
    • forEach

      public void forEach(Consumer<? super Component> action)
      Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.
      Parameters:
      action - The action to be performed for each element.
    • getChildComponents

      public List<Component> getChildComponents()
      Used to retrieve child components as List.

      NOTE: this method returns NEW List of components.

      Returns:
      list of child components.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • indexOfChild

      public int indexOfChild(Component component)
    • getLayer

      public Layer getLayer()
    • getFrame

      public Frame getFrame()
    • keepRendering

      public boolean keepRendering()
      Shows if rendering pipeline should be redefined to not skip element rendering if it is not visible in parent components (is out of view).
      Returns:
      true if component should be rendered out of view.
    • keepRendering

      public void keepRendering(boolean keepRendering)
      Used to redefine rendering pipeline to not skip element rendering if it is not visible in parent components (is out of view).
      Parameters:
      keepRendering - set to true to allow component be rendered even if it is out of view.