Class GButton

  • All Implemented Interfaces:
    java.lang.Iterable<sag.elements.GElement>, sag.elements.Drawable
    Direct Known Subclasses:
    GCableInfo

    public class GButton
    extends sag.elements.GGroup
    A GGroup that can handle mouse events.

    The GButton forms the basis for almost all interactive elements in the GUI. It itself does not have any visual representation, but can be extended to create various elements that the user can interact with via mouse events. The GButton is a GGroup, which means it can contain other GElements. The event handling is done in a functional style. The user can define what happens when an event occurs by passing a lambda to the respective method.

    Here is an example:

    GButton button = new GButton()
        .onClick((e, s) -> {
            // do something when the button is pressed
        });
    

    Like other modifiers, the methods return the GButton itself, so they can be chained. Here is an example from the CableStore where a GAsset is added to a GButton. The asset is then updated when the cursor enters or exits the button.

    GButton doneButton = new GButton();
    GAsset doneIcon = new GAsset(Asset.CONFIRM);
    doneButton.addChild(doneIcon);
    
    doneButton
        .onEnter((e, s) -> doneIcon.setAsset(Asset.CONFIRM_HOVER))
        .onExit((e, s) -> doneIcon.setAsset(Asset.CONFIRM))
        .onClick((e, s) -> {
            // ...
        });
    
    Author:
    Luna Otte
    • Field Summary

      • Fields inherited from class sag.elements.GElement

        handleMouseEvents, mouseListener, mouseListenerSync, positionX, positionY, rawSVGElement, rotation, scaleX, scaleY, skewX, skewY
    • Constructor Summary

      Constructors 
      Constructor Description
      GButton()
      Creates a new GButton
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void clickedEvent​(sag.events.MouseButtonEvent e, sag.elements.GElement self)  
      protected void enterEvent​(sag.events.MouseMotionEvent e, sag.elements.GElement self)  
      protected void exitEvent​(sag.events.MouseMotionEvent e, sag.elements.GElement self)  
      protected void movedEvent​(sag.events.MouseMotionEvent e, sag.elements.GElement self)  
      GButton onClick​(java.util.function.BiConsumer<sag.events.MouseButtonEvent,​sag.elements.GElement> action)
      This action is performed when the element is clicked.
      GButton onEnter​(java.util.function.BiConsumer<sag.events.MouseMotionEvent,​sag.elements.GElement> action)
      This action is performed when the cursor enters the element.
      GButton onExit​(java.util.function.BiConsumer<sag.events.MouseMotionEvent,​sag.elements.GElement> action)
      This action is performed when the cursor exits the element.
      GButton onMove​(java.util.function.BiConsumer<sag.events.MouseMotionEvent,​sag.elements.GElement> action)
      This action is performed when the cursor moves over the element.
      GButton onPress​(java.util.function.BiConsumer<sag.events.MouseButtonEvent,​sag.elements.GElement> action)
      This action is performed when the element is pressed.
      GButton onRelease​(java.util.function.BiConsumer<sag.events.MouseButtonEvent,​sag.elements.GElement> action)
      This action is performed when the element is released.
      GButton onScroll​(java.util.function.BiConsumer<sag.events.MouseWheelEvent,​sag.elements.GElement> action)
      This action is performed when the cursor scrolls on the element.
      protected void pressEvent​(sag.events.MouseButtonEvent e, sag.elements.GElement self)  
      protected void releaseEvent​(sag.events.MouseButtonEvent e, sag.elements.GElement self)  
      protected void scrollEvent​(sag.events.MouseWheelEvent e, sag.elements.GElement self)  
      • Methods inherited from class sag.elements.GGroup

        addChild, addChild, getChildByRenderingIndex, getNumChildren, getRawSVGGroup, indexOfChild, iterator, processMouseButtonEvent, processMouseMotionEvent, processMouseWheelEvent, removeChild, renderChildAfter, renderChildBefore, renderChildEarlier, renderChildFirst, renderChildLast, renderChildLater, setChildRenderingIndex, setRootSAGPanel, swapChildren
      • Methods inherited from class sag.elements.GElement

        amIPicked, executeUpdate, flipHorizontal, flipVertical, getGElement, getParent, getPositionX, getPositionY, getRGBStringFromColor, getRootSAGPanel, getRotation, getScaleX, getScaleY, getSkewX, getSkewY, move, removeCSSAttribute, removeXMLAttribute, rotate, scale, scale, setAttribute, setCSSAttribute, setCSSAttribute, setDisplay, setFill, setFill, setFillOpacity, setMouseEventListener, setOpacity, setParent, setPosition, setRotation, setScale, setScale, setSkew, setStroke, setStroke, setStroke, setStrokeLinecap, setStrokeLinejoin, setStrokeOpacity, setStrokePattern, setStrokePatternOffset, setStrokeWidth, setXMLAttribute, setXMLAttribute, skew, unsetFill, unsetFillOpacity, unsetOpacity, unsetStroke, unsetStrokeLinecap, unsetStrokeLinejoin, unsetStrokeOpacity, unsetStrokePattern, unsetStrokePatternOffset, unsetStrokeWidth, update, updateTransform
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • GButton

        public GButton()
        Creates a new GButton
    • Method Detail

      • onPress

        public GButton onPress​(java.util.function.BiConsumer<sag.events.MouseButtonEvent,​sag.elements.GElement> action)
        This action is performed when the element is pressed.
        Parameters:
        action - A lambda that defines what happens on press
        Returns:
        This GButton
      • onRelease

        public GButton onRelease​(java.util.function.BiConsumer<sag.events.MouseButtonEvent,​sag.elements.GElement> action)
        This action is performed when the element is released.
        Parameters:
        action - A lambda that defines what happens on release
        Returns:
        This GButton
      • onClick

        public GButton onClick​(java.util.function.BiConsumer<sag.events.MouseButtonEvent,​sag.elements.GElement> action)
        This action is performed when the element is clicked.
        Parameters:
        action - A lambda that defines what happens on click
        Returns:
        This GButton
      • onEnter

        public GButton onEnter​(java.util.function.BiConsumer<sag.events.MouseMotionEvent,​sag.elements.GElement> action)
        This action is performed when the cursor enters the element.
        Parameters:
        action - A lambda that defines what happens on release
        Returns:
        This GButton
      • onExit

        public GButton onExit​(java.util.function.BiConsumer<sag.events.MouseMotionEvent,​sag.elements.GElement> action)
        This action is performed when the cursor exits the element.
        Parameters:
        action - A lambda that defines what happens on exit
        Returns:
        This GButton
      • onMove

        public GButton onMove​(java.util.function.BiConsumer<sag.events.MouseMotionEvent,​sag.elements.GElement> action)
        This action is performed when the cursor moves over the element.
        Parameters:
        action - A lambda that defines what happens on move
        Returns:
        This GButton
      • onScroll

        public GButton onScroll​(java.util.function.BiConsumer<sag.events.MouseWheelEvent,​sag.elements.GElement> action)
        This action is performed when the cursor scrolls on the element.
        Parameters:
        action - A lambda that defines what happens on scroll
        Returns:
        This GButton
      • pressEvent

        protected void pressEvent​(sag.events.MouseButtonEvent e,
                                  sag.elements.GElement self)
      • releaseEvent

        protected void releaseEvent​(sag.events.MouseButtonEvent e,
                                    sag.elements.GElement self)
      • clickedEvent

        protected void clickedEvent​(sag.events.MouseButtonEvent e,
                                    sag.elements.GElement self)
      • enterEvent

        protected void enterEvent​(sag.events.MouseMotionEvent e,
                                  sag.elements.GElement self)
      • exitEvent

        protected void exitEvent​(sag.events.MouseMotionEvent e,
                                 sag.elements.GElement self)
      • movedEvent

        protected void movedEvent​(sag.events.MouseMotionEvent e,
                                  sag.elements.GElement self)
      • scrollEvent

        protected void scrollEvent​(sag.events.MouseWheelEvent e,
                                   sag.elements.GElement self)