Class FloatingActionButton

All Implemented Interfaces:
Animation, Editable, ActionSource<ActionEvent>, StyleListener, IconHolder, ReleasableComponent, SelectableIconHolder, TextHolder

public class FloatingActionButton extends Button

Floating action buttons are a material design element used to promote a special action in a Form. They are represented as a floating circle with a flat icon floating above the UI typically in the bottom right area.

Simple use cases include just the button as a standalone:

FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_ADD);
fab.addActionListener(e -> ToastBar.showErrorMessage("Not implemented yet..."));
fab.bindFabToContainer(hi.getContentPane());

The button can also nest sub actions

FloatingActionButton fab = FloatingActionButton.createFAB(FontImage.MATERIAL_ADD);
fab.createSubFAB(FontImage.MATERIAL_PEOPLE, "");
fab.createSubFAB(FontImage.MATERIAL_IMPORT_CONTACTS, "");
fab.bindFabToContainer(hi.getContentPane());
  • Constructor Details

    • FloatingActionButton

      protected FloatingActionButton(char icon, String text, float size)

      Constructor

      Parameters
      • icon: one of the FontImage.MATERIAL_* constants

      • text: the text of the sub FloatingActionButton

      • size: the size in millimeters

    • FloatingActionButton

      protected FloatingActionButton(char icon, String text, String uiid, float size)

      Constructor

      Parameters
      • icon: one of the FontImage.MATERIAL_* constants

      • text: the text of the sub FloatingActionButton

      • uiid: the uiid of the FAB

      • size: the size in millimeters

  • Method Details

    • getIconDefaultSize

      public static float getIconDefaultSize()

      The default icon size for the fab icon in millimeters

      Returns

      the fabDefaultSize

    • setIconDefaultSize

      public static void setIconDefaultSize(float aFabDefaultSize)

      The default icon size for the fab icon in millimeters

      Parameters
      • aFabDefaultSize: the fabDefaultSize to set
    • isAutoSizing

      public static boolean isAutoSizing()

      The FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored. Setting this to false disables that behavior

      Returns

      the autoSizing

    • setAutoSizing

      public static void setAutoSizing(boolean aAutoSizing)

      The FloatingActionButton tries to size/pad itself automatically but this means that manual padding is ignored. Setting this to false disables that behavior

      Parameters
      • aAutoSizing: the autoSizing to set
    • createBadge

      public static FloatingActionButton createBadge(String text)

      Creates a text badge

      Parameters
      • text: the text of the badge
      Returns

      a badge component

    • createFAB

      public static FloatingActionButton createFAB(char icon)

      a factory method to create a FloatingActionButton.

      Parameters
      • icon: one of the FontImage.MATERIAL_* constants
      Returns

      a FloatingActionButton instance

    • createFAB

      public static FloatingActionButton createFAB(char icon, String uiid)

      a factory method to create a FloatingActionButton.

      Parameters
      • icon: one of the FontImage.MATERIAL_* constants

      • uiid: the uiid for the fab

      Returns

      a FloatingActionButton instance

    • setUIID

      public void setUIID(String id)

      Overriden to update the icon

      Overriden to workaround issue with caps text and different UIID's

      This method sets the Component the Unique identifier. This method should be used before a component has been initialized

      Parameters
      • id: UIID unique identifier for component type
      Overrides:
      setUIID in class Button
    • styleChanged

      public void styleChanged(String propertyName, Style source)

      We override this method to track style changes to the background color and map them to the border

      Invoked to indicate a change in a propertyName of a Style

      NOTE By default this will trigger a call to Container#revalidate() on the parent container, which is expensive. You can disable this behavior by calling CN.setProperty("Component.revalidateOnStyleChange", "false"). The intention is to change this behavior so that the default is to "not" revalidate on style change, so we encourage you to set this to "false" to ensure for future compatibility.

      Parameters
      • propertyName: the property name that was changed

      • source: The changed Style object

      Specified by:
      styleChanged in interface StyleListener
      Overrides:
      styleChanged in class Label
    • createSubFAB

      public FloatingActionButton createSubFAB(char icon, String text)

      Adds a sub FAB to the FloatingActionButton instance. Once pressed all its sub FAB's are displayed.

      Parameters
      • icon: one of the FontImage.MATERIAL_* constants

      • text: the text of the sub FloatingActionButton

      Returns

      a FloatingActionButton instance for the sub FAB added

    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Button

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class Button
    • bindFabToContainer

      public Container bindFabToContainer(Component cnt)

      This is a utility method to bind the FAB to a given Container, it will return a new container to add or will use the layered pane if the container is a content pane.

      Parameters
      • cnt: the Container to add the FAB to
      Returns

      a new Container that contains the cnt and the FAB on top or null in the case of a content pane

    • bindFabToContainer

      public Container bindFabToContainer(Component cnt, int orientation, int valign)

      This is a utility method to bind the FAB to a given Container, it will return a new container to add or will use the layered pane if the container is a content pane.

      Parameters
      • cnt: the Container to add the FAB to

      • orientation: one of Component.RIGHT/LEFT/CENTER

      • valign: one of Component.TOP/BOTTOM/CENTER

      Returns

      a new Container that contains the cnt and the FAB on top or null in the case of a content pane

    • unbind

      public void unbind()
      Removes the floating action button from its parent
    • setText

      public void setText(String text)
      Description copied from class: Button

      Overriden to implement the caps mode #setCapsText(boolean)

      Sets the Label text

      Parameters
      • text: the string that the label presents.
      Specified by:
      setText in interface TextHolder
      Overrides:
      setText in class Button
    • fireActionEvent

      protected void fireActionEvent(int x, int y)
      Description copied from class: Button

      Allows subclasses to override action event behavior

      Parameters
      • x: the x position of the click if applicable (can be 0 or -1 otherwise)

      • y: the y position of the click if applicable (can be 0 or -1 otherwise)

      Overrides:
      fireActionEvent in class Button
    • released

      public void released(int x, int y)
      Description copied from class: Button

      Invoked to change the state of the button to the released state

      Parameters
      • x: the x position if a touch event triggered this, -1 if this isn't relevant

      • y: the y position if a touch event triggered this, -1 if this isn't relevant

      Overrides:
      released in class Button
    • createPopupContent

      protected Container createPopupContent(List<FloatingActionButton> fabs)

      Creates the popup content container to display on the dialog.

      Parameters
      • fabs: List of sub FloatingActionButton
      Returns

      a Container that contains all fabs

    • showPopupDialog

      protected void showPopupDialog(Dialog dialog)

      Shows the popup Dialog with the sub FABs.

      Parameters
      • dialog: the Dialog with all sub FAB's Components
    • getFloatingActionTextUIID

      public String getFloatingActionTextUIID()
      Returns

      the floatingActionTextUIID

    • setFloatingActionTextUIID

      public void setFloatingActionTextUIID(String floatingActionTextUIID)
      Parameters
      • floatingActionTextUIID: the floatingActionTextUIID to set