Class HudLinkList<E>

Type Parameters:
E - the type of the list's items
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class HudLinkList<E> extends JList<E>
A JList whose rows can hold clickable links and tooltips anywhere inside them.

A list's rows are drawn by its renderer as pictures, not live components, so a label inside a row cannot be clicked or hovered on its own. This list works out which part of a row is under the pointer by laying out the renderer's component for that row. A renderer marks a part as a link with markLink(C, java.lang.Object), and draws it hovered when isLinkHovered(javax.swing.JList<?>, int, java.lang.Object) says so. Clicking a link calls the HudLinkList.LinkHandler and leaves the selection alone; clicking anywhere else selects as usual.

Tooltips come from the innermost part of the row that has one, so a badge inside a row can explain itself, and are drawn as HudToolTips.

Links inside rows cannot be reached from the keyboard, so anything a row links to should also be reachable another way, such as a real link in a detail panel for the selected row.

Since:
0.51.01
See Also:
  • Field Details

  • Constructor Details

    • HudLinkList

      public HudLinkList(ListModel<E> model)
      Parameters:
      model - the list's items
  • Method Details

    • setLinkHandler

      public void setLinkHandler(HudLinkList.LinkHandler<E> linkHandler)
      Parameters:
      linkHandler - called when the player clicks a link in a row
      Since:
      0.51.01
    • markLink

      public static <C extends JComponent> C markLink(C component, @Nullable Object link)
      Marks part of a rendered row as a link. The renderer calls this each time it configures that part.
      Type Parameters:
      C - the component's type
      Parameters:
      component - the part of the row
      link - what the link points to, given back to the HudLinkList.LinkHandler; null makes the part an ordinary label again
      Returns:
      the same component, for chaining
      Since:
      0.51.01
    • isLinkHovered

      public static boolean isLinkHovered(JList<?> list, int index, Object link)
      For renderers: whether the pointer is over a link, so it can be drawn hovered.
      Parameters:
      list - the list the renderer is drawing for
      index - the row
      link - the link's value
      Returns:
      true if the list is a HudLinkList and the pointer is over that link in that row
      Since:
      0.51.01
    • processMouseEvent

      protected void processMouseEvent(MouseEvent event)
      Overrides:
      processMouseEvent in class JComponent
    • processMouseMotionEvent

      protected void processMouseMotionEvent(MouseEvent event)
      Overrides:
      processMouseMotionEvent in class JComponent
    • getToolTipText

      @Nullable public String getToolTipText(MouseEvent event)
      Overrides:
      getToolTipText in class JList<E>
    • createToolTip

      public JToolTip createToolTip()
      Overrides:
      createToolTip in class JComponent