java.lang.Object
com.realtime.crossfire.jxclient.gui.gui.Gui

public class Gui extends Object
Combines a list of GUIElements to for a gui.

A dialog can be modal. Such dialogs do not propagate key or mouse events to lower dialogs.

  • Constructor Details

    • Gui

      public Gui(@NotNull @NotNull String name, @NotNull @NotNull KeyBindings keyBindings)
      Creates a new instance.
      Parameters:
      name - the name of this GUI
      keyBindings - the keybindings to use
  • Method Details

    • getComponent

      @NotNull public @NotNull JComponent getComponent()
      Returns the JComponent for this instance.
      Returns:
      the component
    • setAutoSize

      public void setAutoSize(@Nullable @Nullable Extent autoSize)
      Sets the auto-size state. Auto-size dialogs cannot be moved or resized manually.
      Parameters:
      autoSize - the new auto-size or null
    • isAutoSize

      public boolean isAutoSize()
      Returns whether this dialog is an auto-size dialog. Auto-size dialogs cannot be moved or resized manually.
      Returns:
      whether this dialog is auto-size
    • setModal

      public void setModal(boolean modal)
      Sets the modal state.
      Parameters:
      modal - the new modal state
    • isModal

      public boolean isModal()
      Returns the modal state.
      Returns:
      the modal state
    • setUserResizable

      public void setUserResizable(boolean userResizable)
      Sets whether the dialog is user-resizable.
      Parameters:
      userResizable - whether the dialog is user-resizable
    • isUserResizable

      public boolean isUserResizable()
      Returns whether the dialog is user-resizable.
      Returns:
      whether the dialog is user-resizable
    • activateDefaultElement

      public void activateDefaultElement()
      Activates the first default gui element of this gui.
    • getFirstElementEndingWith

      @Nullable public <T extends GUIElement> T getFirstElementEndingWith(@NotNull @NotNull Class<T> class_, @NotNull @NotNull String ending)
      Returns the first gui element of this gui which belongs to the given class and that's name ends with the given ending.
      Type Parameters:
      T - the class to search for
      Parameters:
      class_ - the class to search for
      ending - the ending to search for
      Returns:
      the gui element or null if not found
    • getFirstElementNotEndingWith

      @Nullable public <T extends GUIElement> T getFirstElementNotEndingWith(@NotNull @NotNull Class<T> class_, @NotNull @NotNull String ending)
      Returns the first gui element of this gui which belongs to the given class and that's name does not end with the given ending.
      Type Parameters:
      T - the class to search for
      Parameters:
      class_ - the class to search for
      ending - the ending to search for
      Returns:
      the gui element or null if not found
    • getFirstElement

      @Nullable public <T extends GUIElement> T getFirstElement(@NotNull @NotNull Class<T> class_)
      Returns the first gui element of this gui belonging to the given class.
      Type Parameters:
      T - the class to search for
      Parameters:
      class_ - the class to search for
      Returns:
      the gui element or null if not found
    • getElementFromPoint

      @Nullable public @Nullable AbstractGUIElement getElementFromPoint(int x, int y)
      Determines the GUIElement for a given coordinate.
      Parameters:
      x - the x-coordinate to check
      y - the y-coordinate to check
      Returns:
      the GUIElement at the given coordinate or null if none was found
    • setActiveElement

      public void setActiveElement(@NotNull @NotNull ActivatableGUIElement activeElement, boolean active)
      Sets the gui element owning the focus.
      Parameters:
      activeElement - the gui element
      active - the new active state
    • isActiveElement

      public boolean isActiveElement(@Nullable @Nullable ActivatableGUIElement activeElement)
      Returns whether a given gui element is the active element of this dialog.
      Parameters:
      activeElement - the gui element
      Returns:
      whether the given gui element is active
    • setActiveElementActive

      public void setActiveElementActive(boolean active)
      Activates or deactivates the GUI element owning the focus. Does nothing if no focus owner exists.
      Parameters:
      active - whether to activate the GUI element
    • handleKeyPress

      public boolean handleKeyPress(@NotNull @NotNull KeyEvent2 e)
      Dispatches a key press KeyEvent.
      Parameters:
      e - the event to dispatch
      Returns:
      whether a gui element did handle the event
    • deactivateCommandInput

      public boolean deactivateCommandInput()
      Deactivates the command text input field of this dialog. Does nothing if the command text input field is not active or if this dialog has no command text input field.
      Returns:
      whether the command text input field has been deactivated
    • getFirstElement

      @Nullable public <T extends GUIElement> T getFirstElement(@NotNull @NotNull Class<T> class_, @NotNull @NotNull String name)
      Returns the first gui element of this gui belonging to the given class and having the given name.
      Type Parameters:
      T - the class to search for
      Parameters:
      class_ - the class to search for
      name - the button's name
      Returns:
      the button or null if no button matches
    • getKeyBindings

      @NotNull public @NotNull KeyBindings getKeyBindings()
      Returns the key bindings instance for this gui.
      Returns:
      the key bindings
    • hideInState

      public void hideInState(@NotNull @NotNull RendererGuiState state)
      Hides the dialog in a state.
      Parameters:
      state - the state
    • isHidden

      public boolean isHidden(@NotNull @NotNull RendererGuiState state)
      Returns whether this gui is visible in a state.
      Parameters:
      state - the state
      Returns:
      whether this gui is hidden
    • setGuiAutoCloseListener

      public void setGuiAutoCloseListener(@Nullable @Nullable GuiAutoCloseListener guiAutoCloseListener)
      Sets the GuiAutoCloseListener to be notified when this dialog becomes inactive.
      Parameters:
      guiAutoCloseListener - the listener to be notified or null
    • isWithinDrawingArea

      public boolean isWithinDrawingArea(int x, int y)
      Returns whether a given point is within this dialog's drawing area.
      Parameters:
      x - the x-coordinate of the point
      y - the y-coordinate of the point
      Returns:
      whether the coordinate is within the drawing area
    • setForcedActive

      public void setForcedActive(@Nullable @Nullable ActivatableGUIElement forcedActive)
      Sets an ActivatableGUIElement that is always active. It prevents any other element from getting active.
      Parameters:
      forcedActive - the element to set or null to unset
    • toString

      @NotNull public @NotNull String toString()
      Overrides:
      toString in class Object
    • autoSize

      public void autoSize(int screenWidth, int screenHeight)
      Auto-resizes the dialog. This makes sure that the dialog is completely visible on the screen.
      Parameters:
      screenWidth - the screen width
      screenHeight - the screen height
    • setDefaultPosition

      public void setDefaultPosition(@NotNull @NotNull Expression defaultX, @NotNull @NotNull Expression defaultY)
      Sets the default position for this dialog.
      Parameters:
      defaultX - the default x-coordinate
      defaultY - the default y-coordinate
    • isSaveDialog

      public boolean isSaveDialog()
      Returns whether this dialog retains its position across restarts.
      Returns:
      whether this dialog retains its position across restarts
    • setSaveDialog

      public void setSaveDialog()
      Makes this dialog retain its position across restarts.
    • notifyOpen

      public void notifyOpen()
      Call GUIElement.notifyOpen() for all GUI elements.
    • getHelp

      @Nullable public @Nullable GUIPicture getHelp()
      Returns the help icon of this dialog.
      Returns:
      the help icon or null if this is not a dialog or if this dialog has no help icon
    • setHelp

      public void setHelp(@NotNull @NotNull GUIPicture help)
      Sets the help icon of this dialog.
      Parameters:
      help - the help icon
    • setBounds

      public void setBounds(int x, int y, int width, int height, int windowWidth, int windowHeight)
      Sets the position and size of this dialog. The location may be modified to make sure the dialog is fully visible in the main window. The size will be increased if it is smaller than the allowed minimum size or decreased if it is larger than the allowed maximum size.
      Parameters:
      x - the x-coordinate of the dialog
      y - the y-coordinate of the dialog
      width - the width of the dialog
      height - the height of the dialog
      windowWidth - the main window's width
      windowHeight - the main window's height
    • repaint

      public void repaint()
      Repaints this component.
    • setOpaqueDialogBackground

      public void setOpaqueDialogBackground(boolean opaque)
      Sets whether the dialog's background is opaque.
      Parameters:
      opaque - whether the background is opaque
    • setShowSentCommands

      public void setShowSentCommands(boolean showSentCommands)
      Sets whether the commands sent to the server should be shown in the messages dialog.
      Parameters:
      showSentCommands - whether to show the commands
    • setShowTimestamps

      public void setShowTimestamps(boolean showTimestamps)
      Sets whether timestamps should be shown in the messages dialog.
      Parameters:
      showTimestamps - whether to show timestamps