Class GenericDialog

java.lang.Object
com.badlogic.gdx.scenes.scene2d.Actor
com.badlogic.gdx.scenes.scene2d.Group
com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup
com.badlogic.gdx.scenes.scene2d.ui.Table
All Implemented Interfaces:
com.badlogic.gdx.scenes.scene2d.utils.Cullable, com.badlogic.gdx.scenes.scene2d.utils.Layout, IScreen
Direct Known Subclasses:
AboutWindow, AddShapeDialog, ArchiveViewWindow, BatchDownloadWindow, BookmarkInfoDialog, BookmarkNameDialog, DataInfoWindow, DataLocationCheckWindow, DatasetFiltersWindow, DatasetInfoWindow, DatasetLoadDialog, DatasetManagerWindow, DatasetTransformsWindow, DatasetVisualSettingsWindow, DateDialog, FileChooser, FileNameWindow, GalaxyGenerationWindow, GamepadConfigWindow, IndexNameConflictsWindow, IndividualVisibilityWindow, KeyframePreferencesWindow, KeyframesWindow, LandAtWindow, LogWindow, MemInfoWindow, MinimapWindow, NewBookmarkFolderDialog, ObjectDebugWindow, PreferencesWindow, ProceduralGenerationWindow, QuitWindow, ReleaseNotesWindow, SearchDialog, SlaveConfigWindow, TextureWindow, UpdatePopup

public abstract class GenericDialog extends CollapsibleWindow implements IScreen
An abstract, extensible GenericDialog intended to be subclassed for creating custom interactive dialog windows. It serves as a wrapper around a main content table and a bottom row for action buttons (Accept/Cancel).

This class provides a layout manager that automatically arranges the main content area and the footer button group. Subclasses must implement the build() method to populate the content table before showing the dialog. It supports multiple tabs, modal/non-modal behavior, and captures input (mouse, keyboard, gamepad) to prevent interference with the rest of the application while the dialog is open.

Layout Structure

  • Content Table: Defined by the build() method implementation in the subclass.
  • Footer Table: Contains the action buttons (Accept/Cancel) if configured.
  • Tab System: Subclasses can add multiple tabs using addTabContent(Group). Tabs are managed via a stack and a button group that restricts selection to one tab at a time.

Subclassing Guidelines

To create a functional dialog, the subclass must:

  1. Implement the build() method to add UI actors to the content table.
  2. Implement the accept() method, which returns true if the dialog should close upon clicking the accept button.
  3. Implement the cancel() method, which is called upon clicking cancel or pressing Escape.
  4. (Optional) Override dispose() for cleanup resources.

Common Operations

Subclasses typically override the following methods or use the provided helpers:

The class handles internal logic for:

  • Input multiplexing (pausing other listeners when modal, restoring them on hide).
  • Focus management (setting initial focus, tracking previous focus).
  • Tab state persistence (remembering the last active tab per subclass type).
  • Window positioning (centering or custom coordinates).
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

    com.badlogic.gdx.scenes.scene2d.ui.Table.Debug, com.badlogic.gdx.scenes.scene2d.ui.Table.DebugRect
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected com.badlogic.gdx.scenes.scene2d.ui.TextButton
     
    protected Runnable
     
    protected Set<com.badlogic.gdx.controllers.ControllerListener>
     
     
    protected com.badlogic.gdx.scenes.scene2d.ui.Table
     
    protected com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
     
    protected com.badlogic.gdx.scenes.scene2d.ui.TextButton
     
    protected Runnable
     
    protected Runnable
     
    protected com.badlogic.gdx.scenes.scene2d.ui.Table
     
    protected boolean
     
    protected boolean
     
    protected boolean
     
    protected boolean
     
     
    protected com.badlogic.gdx.scenes.scene2d.InputListener
     
    protected boolean
     
    protected float
     
    protected float
     
    protected GenericDialog
     
    protected boolean
     
     
    protected com.badlogic.gdx.utils.Array<OwnScrollPane>
     
    protected int
    Currently selected tab
    protected final com.badlogic.gdx.scenes.scene2d.ui.Skin
     
    protected final com.badlogic.gdx.scenes.scene2d.Stage
     
    protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton>
    If this dialog has tabs, this list holds them.
    protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.Group>
    Actual actor for each tab.
    protected com.badlogic.gdx.scenes.scene2d.ui.Stack
    Tab contents stack.

    Fields inherited from class CollapsibleWindow

    collapseSpeed
    Modifier and Type
    Field
    Description
    protected float
    Collapse speed in pixels per second.

    Fields inherited from class OwnWindow

    dragging, edge, pad10, pad18, pad20, pad34
    Modifier and Type
    Field
    Description
    protected boolean
     
    protected int
     
    protected static final float
     
    protected static final float
     
    protected static final float
     
    protected static final float
     

    Fields inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

    backgroundBottom, backgroundLeft, backgroundRight, backgroundTop, debugActorColor, debugCellColor, debugTableColor

    Fields inherited from class com.badlogic.gdx.scenes.scene2d.Actor

    POOLS
  • Constructor Summary

    Constructors
    Constructor
    Description
    GenericDialog(String title, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.Stage stage)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract boolean
    The accept function, if any.
    com.badlogic.gdx.scenes.scene2d.ui.Button
     
    void
    act(float delta)
     
    void
    Adds a horizontal separator to the main content table with the default colspan of 1.
    void
    addSeparator(int colSpan)
    Adds a horizontal separator to the main content table with the given colspan.
    protected void
    addTabContent(com.badlogic.gdx.scenes.scene2d.Group tabContent)
    Add tab contents to the list of tabs.
    protected abstract void
    Build the content here.
    void
     
    protected abstract void
    The cancel function, if any.
    com.badlogic.gdx.scenes.scene2d.ui.Button
     
    boolean
    Closes the window with the accept action.
    boolean
    Closes the window with the cancel action.
    abstract void
     
    protected void
    enableComponents(boolean enabled, com.badlogic.gdx.scenes.scene2d.utils.Disableable... components)
    Sets the enabled property on the given components.
    void
     
    com.badlogic.gdx.scenes.scene2d.ui.Table
     
    com.badlogic.gdx.scenes.scene2d.Group
     
    com.badlogic.gdx.scenes.scene2d.Group
     
    com.badlogic.gdx.scenes.scene2d.ui.Table
     
    com.badlogic.gdx.scenes.scene2d.Group
     
    com.badlogic.gdx.scenes.scene2d.Stage
     
    com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton>
     
    boolean
     
    boolean
     
    boolean
     
    void
    Hides the dialog.
    void
    hide(com.badlogic.gdx.scenes.scene2d.Action action)
    Hides the dialog with the given action and then removes it from the stage.
    protected void
     
    void
    setAcceptButtonColor(com.badlogic.gdx.graphics.Color col)
     
    void
     
    void
    Sets a listener that runs when accept is clicked.
    void
    setAcceptText(String acceptText)
     
    void
    setCancelButtonColors(com.badlogic.gdx.graphics.Color textColor, com.badlogic.gdx.graphics.Color buttonColor)
     
    void
     
    void
    Sets a listener that runs when cancel is clicked.
    void
    setCancelText(String cancelText)
     
    void
    Sets a listener that runs when the dialog is closed.
    void
    Sets the keyboard focus, override in case you want to set the focus to a specific item.
    void
    setModal(boolean modal)
     
    protected void
    Prepares the tab button listeners that make tab buttons actually change the content.
    show(com.badlogic.gdx.scenes.scene2d.Stage stage)
    Packs the dialog and adds it to the stage, centered with default fadeIn action.
    show(com.badlogic.gdx.scenes.scene2d.Stage stage, float x, float y)
    Packs the dialog and adds it to the stage at the specified position.
    show(com.badlogic.gdx.scenes.scene2d.Stage stage, com.badlogic.gdx.scenes.scene2d.Action action)
    Packs the dialog and adds it to the stage with custom action which can be null for instant show.
    protected void
    showDialogHook(com.badlogic.gdx.scenes.scene2d.Stage stage)
     
    boolean
     
    boolean
     
    void
    Override this method to update the contents of this dialog before displaying it.

    Methods inherited from class CollapsibleWindow

    collapse, collapseInstant, drawBackground, expand, expandInstant, getHeight, getMaxHeight, getMaxWidth, getPrefHeight, getPrefWidth, getWidth, isCollapsed, isCollapsible, pack, setCollapsible, setResizable, toggleCollapsed
    Modifier and Type
    Method
    Description
    void
     
    void
     
    protected void
    drawBackground(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha, float x, float y)
     
    void
     
    void
     
    float
     
    float
     
    float
     
    float
     
    float
     
    float
     
    boolean
     
    boolean
     
    void
     
    void
    setCollapsible(boolean collapsible)
     
    void
    setResizable(boolean w, boolean h)
     
    void
     

    Methods inherited from class OwnWindow

    draw, drawStageBackground, getStyle, getTitleLabel, getTitleTable, hg, hit, isModal, isResizable, keepWithinStage, setMovable, setResizable, setStyle
    Modifier and Type
    Method
    Description
    void
    draw(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha)
     
    protected void
    drawStageBackground(com.badlogic.gdx.graphics.g2d.Batch batch, float parentAlpha, float x, float y, float width, float height)
     
    com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle
    Returns the window's style.
    com.badlogic.gdx.scenes.scene2d.ui.Label
     
    com.badlogic.gdx.scenes.scene2d.ui.Table
     
    protected com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
    hg(com.badlogic.gdx.scenes.scene2d.Actor... actors)
     
    com.badlogic.gdx.scenes.scene2d.Actor
    hit(float x, float y, boolean touchable)
     
    boolean
     
    boolean
     
    void
     
    void
    setMovable(boolean isMovable)
     
    void
    setResizable(boolean isResizable)
     
    void
    setStyle(com.badlogic.gdx.scenes.scene2d.ui.Window.WindowStyle style)
     

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Table

    add, add, add, add, add, add, add, align, background, background, bottom, center, clearChildren, clip, clip, columnDefaults, debug, debug, debugActor, debugAll, debugCell, debugTable, defaults, drawDebug, drawDebugBounds, getAlign, getBackground, getCell, getCells, getClip, getColumnMinWidth, getColumnPrefWidth, getColumns, getColumnWidth, getMinHeight, getMinWidth, getPadBottom, getPadBottomValue, getPadLeft, getPadLeftValue, getPadRight, getPadRightValue, getPadTop, getPadTopValue, getPadX, getPadY, getRow, getRowHeight, getRowMinHeight, getRowPrefHeight, getRows, getSkin, getTableDebug, invalidate, layout, left, pad, pad, pad, pad, padBottom, padBottom, padLeft, padLeft, padRight, padRight, padTop, padTop, removeActor, removeActor, removeActorAt, reset, right, row, setBackground, setBackground, setClip, setDebug, setRound, setSkin, stack, top

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup

    childrenChanged, invalidateHierarchy, needsLayout, setFillParent, setLayoutEnabled, sizeChanged, validate

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.Group

    addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, clear, clearChildren, computeTransform, drawChildren, drawDebugChildren, findActor, getChild, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor, toString

    Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor

    addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getTop, getTouchable, getUserObject, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • stage

      protected final com.badlogic.gdx.scenes.scene2d.Stage stage
    • skin

      protected final com.badlogic.gdx.scenes.scene2d.ui.Skin skin
    • acceptButton

      protected com.badlogic.gdx.scenes.scene2d.ui.TextButton acceptButton
    • cancelButton

      protected com.badlogic.gdx.scenes.scene2d.ui.TextButton cancelButton
    • me

      protected GenericDialog me
    • content

      protected com.badlogic.gdx.scenes.scene2d.ui.Table content
    • bottom

      protected com.badlogic.gdx.scenes.scene2d.ui.Table bottom
    • defaultMouseKbdListener

      protected boolean defaultMouseKbdListener
    • defaultGamepadListener

      protected boolean defaultGamepadListener
    • lastPosX

      protected float lastPosX
    • lastPosY

      protected float lastPosY
    • buttonGroup

      protected com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup buttonGroup
    • enterExit

      protected boolean enterExit
    • escExit

      protected boolean escExit
    • keysListener

      protected boolean keysListener
    • acceptListener

      protected Runnable acceptListener
    • cancelListener

      protected Runnable cancelListener
    • closeListener

      protected Runnable closeListener
    • mouseKbdListener

      protected AbstractMouseKbdListener mouseKbdListener
    • gamepadListener

      protected AbstractGamepadListener gamepadListener
    • tabButtons

      protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton> tabButtons
      If this dialog has tabs, this list holds them.
    • selectedTab

      protected int selectedTab
      Currently selected tab
    • tabContents

      protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.Group> tabContents
      Actual actor for each tab.
    • tabStack

      protected com.badlogic.gdx.scenes.scene2d.ui.Stack tabStack
      Tab contents stack.
    • ignoreTouchDown

      protected com.badlogic.gdx.scenes.scene2d.InputListener ignoreTouchDown
    • scrolls

      protected com.badlogic.gdx.utils.Array<OwnScrollPane> scrolls
    • backupMouseKbdListeners

      protected Set<AbstractMouseKbdListener> backupMouseKbdListeners
    • backupGamepadListeners

      protected Set<com.badlogic.gdx.controllers.ControllerListener> backupGamepadListeners
  • Constructor Details

    • GenericDialog

      public GenericDialog(String title, com.badlogic.gdx.scenes.scene2d.ui.Skin skin, com.badlogic.gdx.scenes.scene2d.Stage stage)
  • Method Details

    • setAcceptText

      public void setAcceptText(String acceptText)
    • setAcceptButtonStyle

      public void setAcceptButtonStyle(String style)
    • setAcceptButtonColor

      public void setAcceptButtonColor(com.badlogic.gdx.graphics.Color col)
    • setCancelText

      public void setCancelText(String cancelText)
    • setCancelButtonStyle

      public void setCancelButtonStyle(String style)
    • setCancelButtonColors

      public void setCancelButtonColors(com.badlogic.gdx.graphics.Color textColor, com.badlogic.gdx.graphics.Color buttonColor)
    • addTabContent

      protected void addTabContent(com.badlogic.gdx.scenes.scene2d.Group tabContent)
      Add tab contents to the list of tabs.
      Parameters:
      tabContent - The contents.
    • setUpTabListeners

      protected void setUpTabListeners()
      Prepares the tab button listeners that make tab buttons actually change the content. It also sets up the button group, which restricts the number of tabs that can be checked at once to one.
    • setModal

      public void setModal(boolean modal)
      Overrides:
      setModal in class CollapsibleWindow
    • recalculateButtonSize

      protected void recalculateButtonSize()
    • buildSuper

      public void buildSuper()
    • build

      protected abstract void build()
      Build the content here.
    • closeAccept

      public boolean closeAccept()
      Closes the window with the accept action.
      Specified by:
      closeAccept in interface IScreen
    • closeCancel

      public boolean closeCancel()
      Closes the window with the cancel action.
      Specified by:
      closeCancel in interface IScreen
      Returns:
      Whether the cancel operation succeeded.
    • accept

      protected abstract boolean accept()
      The accept function, if any.
      Returns:
      True if the dialog must close after the call, false otherwise.
    • cancel

      protected abstract void cancel()
      The cancel function, if any.
    • show

      public GenericDialog show(com.badlogic.gdx.scenes.scene2d.Stage stage, com.badlogic.gdx.scenes.scene2d.Action action)
      Packs the dialog and adds it to the stage with custom action which can be null for instant show.
      Parameters:
      stage - The stage.
      action - Action to run.
      Returns:
      The generic dialog instance.
    • touch

      public void touch()
      Override this method to update the contents of this dialog before displaying it.
    • getCurrentContentContainer

      public com.badlogic.gdx.scenes.scene2d.Group getCurrentContentContainer()
      Specified by:
      getCurrentContentContainer in interface IScreen
    • getBottomGroup

      public com.badlogic.gdx.scenes.scene2d.Group getBottomGroup()
      Specified by:
      getBottomGroup in interface IScreen
    • getButtonsGroup

      public com.badlogic.gdx.scenes.scene2d.Group getButtonsGroup()
      Specified by:
      getButtonsGroup in interface IScreen
    • show

      public GenericDialog show(com.badlogic.gdx.scenes.scene2d.Stage stage)
      Packs the dialog and adds it to the stage, centered with default fadeIn action.
    • showDialogHook

      protected void showDialogHook(com.badlogic.gdx.scenes.scene2d.Stage stage)
    • show

      public GenericDialog show(com.badlogic.gdx.scenes.scene2d.Stage stage, float x, float y)
      Packs the dialog and adds it to the stage at the specified position.
    • setKeyboardFocus

      public void setKeyboardFocus()
      Sets the keyboard focus, override in case you want to set the focus to a specific item.
    • hide

      public void hide(com.badlogic.gdx.scenes.scene2d.Action action)
      Hides the dialog with the given action and then removes it from the stage.
    • hide

      public void hide()
      Hides the dialog. Called automatically when a button is clicked. The default implementation fades out the dialog over 400 milliseconds and then removes it from the stage.
    • addSeparator

      public void addSeparator()
      Adds a horizontal separator to the main content table with the default colspan of 1.
    • addSeparator

      public void addSeparator(int colSpan)
      Adds a horizontal separator to the main content table with the given colspan.
      Parameters:
      colSpan - The column span to use.
    • setAcceptListener

      public void setAcceptListener(Runnable r)
      Sets a listener that runs when accept is clicked.
      Parameters:
      r - The listener.
    • hasAcceptRunnable

      public boolean hasAcceptRunnable()
    • setCancelListener

      public void setCancelListener(Runnable r)
      Sets a listener that runs when cancel is clicked.
      Parameters:
      r - The listener.
    • hasCancelRunnable

      public boolean hasCancelRunnable()
    • setCloseListener

      public void setCloseListener(Runnable r)
      Sets a listener that runs when the dialog is closed. It runs when either the accept or the cancel button is clicked.
      Parameters:
      r - The listener.
    • hasCloseRunnable

      public boolean hasCloseRunnable()
    • enableComponents

      protected void enableComponents(boolean enabled, com.badlogic.gdx.scenes.scene2d.utils.Disableable... components)
      Sets the enabled property on the given components.
      Parameters:
      enabled - The state to set.
      components - The components to enable or disable.
    • tabRight

      public boolean tabRight()
      Specified by:
      tabRight in interface IScreen
    • tabLeft

      public boolean tabLeft()
      Specified by:
      tabLeft in interface IScreen
    • focusFirstInputWidget

      public void focusFirstInputWidget()
    • getContent

      public com.badlogic.gdx.scenes.scene2d.ui.Table getContent()
    • getBottom

      public com.badlogic.gdx.scenes.scene2d.ui.Table getBottom()
    • getTabButtons

      public com.badlogic.gdx.utils.Array<com.badlogic.gdx.scenes.scene2d.ui.TextButton> getTabButtons()
    • dispose

      public abstract void dispose()
    • act

      public void act(float delta)
      Overrides:
      act in class CollapsibleWindow
    • getStage

      public com.badlogic.gdx.scenes.scene2d.Stage getStage()
      Specified by:
      getStage in interface IScreen
      Overrides:
      getStage in class com.badlogic.gdx.scenes.scene2d.Actor
    • acceptButton

      public com.badlogic.gdx.scenes.scene2d.ui.Button acceptButton()
      Specified by:
      acceptButton in interface IScreen
    • cancelButton

      public com.badlogic.gdx.scenes.scene2d.ui.Button cancelButton()
      Specified by:
      cancelButton in interface IScreen