Class TableWidget


public class TableWidget extends ScrollPanelWidget
Represents a Widget that displays tabular data in a scrollable table format.

The TableWidget provides features such as sorting by column, row selection, and rendering of the table with headers and rows.

  • Constructor Details

    • TableWidget

      public TableWidget(int x, int y, int width, int height)
      Constructs a new TableWidget with the specified position and size.
      Parameters:
      x - The X position of the table.
      y - The Y position of the table.
      width - The width of the table.
      height - The height of the table.
  • Method Details

    • onMouseMove

      public void onMouseMove(int x, int y)
      Handles mouse movement events to update the hovered row index.
      Overrides:
      onMouseMove in class Widget
      Parameters:
      x - The relative X coordinate of the mouse.
      y - The relative Y coordinate of the mouse.
    • onLeftMouseDown

      public void onLeftMouseDown(int x, int y)
      Handles left mouse button down events to perform column sorting or row selection.
      Overrides:
      onLeftMouseDown in class PanelWidget
      Parameters:
      x - The relative X coordinate of the mouse click.
      y - The relative Y coordinate of the mouse click.
    • onRightMouseDown

      public void onRightMouseDown(int x, int y)
      Handles right mouse button down events to perform a right-click action on a row.
      Overrides:
      onRightMouseDown in class Widget
      Parameters:
      x - The relative X coordinate of the mouse click.
      y - The relative Y coordinate of the mouse click.
    • sortByColumn

      public void sortByColumn(String columnName, boolean ascending)
      Sorts the table rows by the specified column in the given order.
      Parameters:
      columnName - The name of the column to sort by.
      ascending - true to sort in ascending order, false for descending order.
    • addRow

      public void addRow(String... values)
      Adds a new row to the table with the specified values.
      Parameters:
      values - The values for the new row. Each value corresponds to a column in the table.
    • updateRow

      public void updateRow(int index, String... values)
      Updates an existing row at the specified index with the new values.
      Parameters:
      index - The index of the row to update.
      values - The new values for the row. Each value corresponds to a column in the table.
    • setOnSelectAction

      public void setOnSelectAction(Consumer<Map<String,String>> onSelectAction)
      Sets the action to be performed when a row is selected.
      Parameters:
      onSelectAction - The action to be performed when a row is selected.
    • setOnDoubleSelectAction

      public void setOnDoubleSelectAction(Consumer<Map<String,String>> onDoubleSelectAction)
      Sets the action to be performed when a row is double-clicked.
      Parameters:
      onDoubleSelectAction - The action to be performed when a row is double-clicked.
    • setOnRightClickAction

      public void setOnRightClickAction(Consumer<Map<String,String>> onRightClickAction)
      Sets the action to be performed when a row is right-clicked.
      Parameters:
      onRightClickAction - The action to be performed when a row is right-clicked.
    • addColumn

      public void addColumn(String name, int width)
      Adds a new column to the table with the specified name and width.
      Parameters:
      name - The name of the new column.
      width - The width of the new column.
    • addColumn

      public void addColumn(String name)
      Adds a new column to the table with the specified name and an undefined width.
      Parameters:
      name - The name of the new column.
    • clearRows

      public void clearRows()
      Clears all rows from the table.
    • getSelectedRow

      public Map<String,String> getSelectedRow()
      Retrieves the currently selected row.
      Returns:
      The selected row as a map of column names to values, or null if no row is selected.
    • getRowByIndex

      public Map<String,String> getRowByIndex(int index)
      Retrieves a row by its index.
      Parameters:
      index - The index of the row to retrieve.
      Returns:
      The row at the specified index as a map of column names to values, or null if the index is out of bounds.
    • getFontName

      public String getFontName()
      Gets the font name used for rendering text in the Widget.
      Returns:
      the font name as a String.
    • setFontName

      public void setFontName(String fontName)
      Sets the font name used for rendering text in the Widget.
      Parameters:
      fontName - the font name to set.
    • getIconFontName

      public String getIconFontName()
      Gets the icon font name used for rendering icons in the Widget.
      Returns:
      the icon font name as a String.
    • setIconFontName

      public void setIconFontName(String iconFontName)
      Sets the icon font name used for rendering icons in the Widget.
      Parameters:
      iconFontName - the icon font name to set.
    • getIconDown

      public String getIconDown()
      Gets the icon used for indicating a downward sort direction in the Widget.
      Returns:
      the downward sort icon as a String.
    • setIconDown

      public void setIconDown(String iconDown)
      Sets the icon used for indicating a downward sort direction in the Widget.
      Parameters:
      iconDown - the downward sort icon to set.
    • getIconUp

      public String getIconUp()
      Gets the icon used for indicating an upward sort direction in the Widget.
      Returns:
      the upward sort icon as a String.
    • setIconUp

      public void setIconUp(String iconUp)
      Sets the icon used for indicating an upward sort direction in the Widget.
      Parameters:
      iconUp - the upward sort icon to set.
    • getLastSortedColumn

      public String getLastSortedColumn()
      Gets the name of the last sorted column in the Widget.
      Returns:
      the name of the last sorted column as a String.
    • setLastSortedColumn

      public void setLastSortedColumn(String lastSortedColumn)
      Sets the name of the last sorted column in the Widget.
      Parameters:
      lastSortedColumn - the name of the last sorted column to set.
    • getHeaderHeight

      public int getHeaderHeight()
      Gets the height of the header in the Widget.
      Returns:
      the header height as an int.
    • setHeaderHeight

      public void setHeaderHeight(int headerHeight)
      Sets the height of the header in the Widget.
      Parameters:
      headerHeight - the header height to set.
    • getBorderOffset

      public int getBorderOffset()
      Gets the border offset in the Widget.
      Returns:
      the border offset as an int.
    • setBorderOffset

      public void setBorderOffset(int borderOffset)
      Sets the border offset in the Widget.
      Parameters:
      borderOffset - the border offset to set.
    • getLineThickness

      public int getLineThickness()
      Gets the thickness of the lines in the Widget.
      Returns:
      the line thickness as an int.
    • setLineThickness

      public void setLineThickness(int lineThickness)
      Sets the thickness of the lines in the Widget.
      Parameters:
      lineThickness - the line thickness to set.
    • getRowHeight

      public int getRowHeight()
      Gets the height of each row in the Widget.
      Returns:
      the row height as an int.
    • setRowHeight

      public void setRowHeight(int rowHeight)
      Sets the height of each row in the Widget.
      Parameters:
      rowHeight - the row height to set.
    • getColumn

      public List<String> getColumn()
      Gets the list of column names in the Widget.
      Returns:
      the list of column names as a List of String.
    • setColumn

      public void setColumn(List<String> column)
      Sets the list of column names in the Widget.
      Parameters:
      column - the list of column names to set.
    • getRows

      public List<Map<String,String>> getRows()
      Gets the list of rows in the Widget.
      Returns:
      the list of rows as a List of Map objects, where each map represents a row.
    • setRows

      public void setRows(List<Map<String,String>> rows)
      Sets the list of rows in the Widget.
      Parameters:
      rows - the list of rows to set.
    • getHeaderColor

      public NanoColor getHeaderColor()
      Gets the color of the header in the Widget.
      Returns:
      the header color as a NanoColor.
    • setHeaderColor

      public void setHeaderColor(NanoColor headerColor)
      Sets the color of the header in the Widget.
      Parameters:
      headerColor - the header color to set.
    • getHeaderTextColor

      public NanoColor getHeaderTextColor()
      Gets the color of the header text in the Widget.
      Returns:
      the header text color as a NanoColor.
    • setHeaderTextColor

      public void setHeaderTextColor(NanoColor headerTextColor)
      Sets the color of the header text in the Widget.
      Parameters:
      headerTextColor - the header text color to set.
    • getAccentColor

      public NanoColor getAccentColor()
      Gets the accent color used in the Widget.
      Returns:
      the accent color as a NanoColor.
    • setAccentColor

      public void setAccentColor(NanoColor accentColor)
      Sets the accent color used in the Widget.
      Parameters:
      accentColor - the accent color to set.
    • getRowTextColor

      public NanoColor getRowTextColor()
      Gets the color of the row text in the Widget.
      Returns:
      the row text color as a NanoColor.
    • setRowTextColor

      public void setRowTextColor(NanoColor rowTextColor)
      Sets the color of the row text in the Widget.
      Parameters:
      rowTextColor - the row text color to set.
    • getRowHoverColor

      public NanoColor getRowHoverColor()
      Gets the color of the row hover background in the Widget.
      Returns:
      the row hover color as a NanoColor.
    • setRowHoverColor

      public void setRowHoverColor(NanoColor rowHoverColor)
      Sets the color of the row hover background in the Widget.
      Parameters:
      rowHoverColor - the row hover color to set.
    • getLineColor

      public NanoColor getLineColor()
      Gets the color of the line used for borders and separators in the Widget.
      Returns:
      the line color as a NanoColor.
    • setLineColor

      public void setLineColor(NanoColor lineColor)
      Sets the color of the line used for borders and separators in the Widget.
      Parameters:
      lineColor - the line color to set.
    • update

      public void update()
      Updates the Widget state, including recalculating column widths and scrollbar positions.
      Overrides:
      update in class ScrollPanelWidget
    • render

      public void render()
      Renders the Widget, including drawing the table headers, rows, and borders.
      Overrides:
      render in class PanelWidget