Class GUIList<T extends GUIElement>

Type Parameters:
T - the type of the list elements
All Implemented Interfaces:
GUIElement, GUIScrollable, ImageObserver, MenuContainer, Serializable
Direct Known Subclasses:
GUICharacterList, GUIItemList, GUIMetaElementList

public abstract class GUIList<T extends GUIElement> extends ActivatableGUIElement implements GUIScrollable
A GUIElement that displays a list of entries.
See Also:
  • Constructor Details

    • GUIList

      protected GUIList(@NotNull @NotNull TooltipManager tooltipManager, @NotNull @NotNull GUIElementListener elementListener, @NotNull @NotNull String name, int cellWidth, int cellHeight, @NotNull @NotNull GUIListCellRenderer<T> listCellRenderer, @Nullable @Nullable CommandList doubleClickCommandList, @NotNull @NotNull GuiFactory guiFactory)
      Creates a new instance.
      Parameters:
      tooltipManager - the tooltip manager to update
      elementListener - the element listener to notify
      name - the name of this element
      cellWidth - the width of each cell
      cellHeight - the height of each cell
      listCellRenderer - the renderer for the list
      doubleClickCommandList - the command list to execute on double-click or null to ignore double-clicks
      guiFactory - the global GUI factory instance
  • Method Details

    • dispose

      public void dispose()
      Description copied from interface: GUIElement
      Releases all allocated resources.
      Specified by:
      dispose in interface GUIElement
      Overrides:
      dispose in class AbstractGUIElement
    • getElement

      @NotNull public T getElement(int index)
      Returns the GUIElement for a given index.
      Parameters:
      index - the index
      Returns:
      the gui element
    • addElement

      protected void addElement(@NotNull T element)
      Adds an GUIElement to the list.
      Parameters:
      element - the element to add
    • resizeElements

      protected int resizeElements(int newSize)
      Changes the number of list elements. If the new element count is less than the current count, excess elements are cut off. Otherwise, the caller has to add elements with addElement(GUIElement).
      Parameters:
      newSize - the new element count
      Returns:
      the number of elements to add by the caller
    • canMoveSelection

      public boolean canMoveSelection(int diffLines, int diffElements)
      Returns whether the selection can be moved.
      Parameters:
      diffLines - the distance in lines to move
      diffElements - the distance in elements to move
      Returns:
      whether moving is possible
    • moveSelection

      public void moveSelection(int diffLines, int diffElements)
      Moves the selection.
      Parameters:
      diffLines - the distance in lines to move
      diffElements - the distance in elements to move
    • canScroll

      public boolean canScroll(int distance)
      Returns whether the list can be scrolled.
      Specified by:
      canScroll in interface GUIScrollable
      Parameters:
      distance - the distance to scroll
      Returns:
      whether scrolling is possible
    • scroll

      public void scroll(int distance)
      Moves the list.
      Specified by:
      scroll in interface GUIScrollable
      Parameters:
      distance - the distance to scroll
    • resetScroll

      public void resetScroll()
      Description copied from interface: GUIScrollable
      Resets the scroll index to the default value.
      Specified by:
      resetScroll in interface GUIScrollable
    • mouseClicked

      public void mouseClicked(@NotNull @NotNull MouseEvent e)
      Description copied from interface: GUIElement
      Will be called when the user has clicked (pressed+released) this element. This event will be delivered after GUIElement.mouseReleased(MouseEvent).
      Specified by:
      mouseClicked in interface GUIElement
      Overrides:
      mouseClicked in class AbstractGUIElement
      Parameters:
      e - the mouse event relative to this element
    • mouseEntered

      public void mouseEntered(@NotNull @NotNull MouseEvent e)
      Description copied from interface: GUIElement
      Will be called when the mouse has entered the bounding box of this element.
      Specified by:
      mouseEntered in interface GUIElement
      Overrides:
      mouseEntered in class AbstractGUIElement
      Parameters:
      e - the mouse event relative to this element
    • mouseExited

      public void mouseExited(@NotNull @NotNull MouseEvent e)
      Description copied from interface: GUIElement
      Will be called when the mouse has left the bounding box of this element. This function will not be called unless GUIElement.mouseEntered(MouseEvent) has been called before.
      Specified by:
      mouseExited in interface GUIElement
      Overrides:
      mouseExited in class AbstractGUIElement
      Parameters:
      e - the mouse event relative to this element
    • mousePressed

      public void mousePressed(@NotNull @NotNull MouseEvent e)
      Description copied from class: ActivatableGUIElement
      Will be called when the user has pressed the mouse inside this element.
      Specified by:
      mousePressed in interface GUIElement
      Overrides:
      mousePressed in class ActivatableGUIElement
      Parameters:
      e - the mouse event relative to this element
    • mouseMoved

      public void mouseMoved(@NotNull @NotNull MouseEvent e)
      Description copied from interface: GUIElement
      Will be called when the mouse moves within this component. before.
      Specified by:
      mouseMoved in interface GUIElement
      Overrides:
      mouseMoved in class AbstractGUIElement
      Parameters:
      e - the mouse event relative to this element
    • mouseDragged

      public void mouseDragged(@NotNull @NotNull MouseEvent e)
      Description copied from interface: GUIElement
      Will be called when the mouse moves within this component while the button is pressed. This event will be delivered after GUIElement.mouseMoved(MouseEvent).

      Note: if the mouse leaves this element's bounding box while the mouse button is still pressed, further mouseDragged (but no mouseMoved) events will be generated.

      Specified by:
      mouseDragged in interface GUIElement
      Overrides:
      mouseDragged in class AbstractGUIElement
      Parameters:
      e - the mouse event relative to this element
    • mouseWheelMoved

      public void mouseWheelMoved(int wheelRotation)
      Description copied from interface: GUIElement
      Will be called when the mouse wheel has been moved.
      Specified by:
      mouseWheelMoved in interface GUIElement
      Overrides:
      mouseWheelMoved in class AbstractGUIElement
      Parameters:
      wheelRotation - the movement amount; negative=away from the user, positive=towards the user
    • setSelectedIndex

      protected void setSelectedIndex(int newIndex)
      Update the selected list entry.
      Parameters:
      newIndex - the new selected list entry
    • selectionChanged

      protected void selectionChanged()
      Called whenever the selected list entry has changed.
    • selectionChanged

      protected abstract void selectionChanged(int selectedIndex)
      Called whenever the selected list entry has changed.
      Parameters:
      selectedIndex - the selected list entry
    • setChanged

      public void setChanged()
      Description copied from interface: GUIElement
      Records that the contents have changed and must be repainted.
      Specified by:
      setChanged in interface GUIElement
      Overrides:
      setChanged in class AbstractGUIElement
    • getTooltip

      @Nullable public @Nullable TooltipText getTooltip()
      Description copied from class: AbstractGUIElement
      Returns the current tooltip text.
      Specified by:
      getTooltip in class AbstractGUIElement
      Returns:
      the tooltip text or null to not show a tooltip
    • execute

      public void execute()
      Description copied from class: ActivatableGUIElement
      Executes the actions associated with this GUI element. Does nothing if this element has no associated actions.
      Specified by:
      execute in class ActivatableGUIElement
    • getTooltip

      @Nullable protected abstract @Nullable String getTooltip(int index)
      Returns the tooltip text.
      Parameters:
      index - the index to use
      Returns:
      the tooltip text
    • setLayoutOrientation

      protected void setLayoutOrientation(int layoutOrientation, int visibleRowCount)
      Parameters:
      layoutOrientation - the layout orientation
      visibleRowCount - the number of visible rows
    • getSelectedObject

      @NotNull protected @NotNull Object getSelectedObject()
      Returns the selected list object.
      Returns:
      the selected object or null if none is selected
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • getMinimumSize

      public Dimension getMinimumSize()
      Overrides:
      getMinimumSize in class JComponent
    • getMaximumSize

      public Dimension getMaximumSize()
      Overrides:
      getMaximumSize in class JComponent
    • setBounds

      public void setBounds(int x, int y, int width, int height)
      Overrides:
      setBounds in class Component