Package com.avrix.ui.widgets
Class TableWidget
java.lang.Object
com.avrix.ui.widgets.Widget
com.avrix.ui.widgets.PanelWidget
com.avrix.ui.widgets.ScrollPanelWidget
com.avrix.ui.widgets.TableWidget
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.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTableWidget
(int x, int y, int width, int height) Constructs a newTableWidget
with the specified position and size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new column to the table with the specified name and an undefined width.void
Adds a new column to the table with the specified name and width.void
Adds a new row to the table with the specified values.void
Clears all rows from the table.Gets the accent color used in theWidget
.int
Gets the border offset in theWidget
.Gets the list of column names in theWidget
.Gets the font name used for rendering text in theWidget
.Gets the color of the header in theWidget
.int
Gets the height of the header in theWidget
.Gets the color of the header text in theWidget
.Gets the icon used for indicating a downward sort direction in theWidget
.Gets the icon font name used for rendering icons in theWidget
.Gets the icon used for indicating an upward sort direction in theWidget
.Gets the name of the last sorted column in theWidget
.Gets the color of the line used for borders and separators in theWidget
.int
Gets the thickness of the lines in theWidget
.getRowByIndex
(int index) Retrieves a row by its index.int
Gets the height of each row in theWidget
.Gets the color of the row hover background in theWidget
.getRows()
Gets the list of rows in theWidget
.Gets the color of the row text in theWidget
.Retrieves the currently selected row.void
onLeftMouseDown
(int x, int y) Handles left mouse button down events to perform column sorting or row selection.void
onMouseMove
(int x, int y) Handles mouse movement events to update the hovered row index.void
onRightMouseDown
(int x, int y) Handles right mouse button down events to perform a right-click action on a row.void
render()
Renders theWidget
, including drawing the table headers, rows, and borders.void
setAccentColor
(NanoColor accentColor) Sets the accent color used in theWidget
.void
setBorderOffset
(int borderOffset) Sets the border offset in theWidget
.void
Sets the list of column names in theWidget
.void
setFontName
(String fontName) Sets the font name used for rendering text in theWidget
.void
setHeaderColor
(NanoColor headerColor) Sets the color of the header in theWidget
.void
setHeaderHeight
(int headerHeight) Sets the height of the header in theWidget
.void
setHeaderTextColor
(NanoColor headerTextColor) Sets the color of the header text in theWidget
.void
setIconDown
(String iconDown) Sets the icon used for indicating a downward sort direction in theWidget
.void
setIconFontName
(String iconFontName) Sets the icon font name used for rendering icons in theWidget
.void
Sets the icon used for indicating an upward sort direction in theWidget
.void
setLastSortedColumn
(String lastSortedColumn) Sets the name of the last sorted column in theWidget
.void
setLineColor
(NanoColor lineColor) Sets the color of the line used for borders and separators in theWidget
.void
setLineThickness
(int lineThickness) Sets the thickness of the lines in theWidget
.void
setOnDoubleSelectAction
(Consumer<Map<String, String>> onDoubleSelectAction) Sets the action to be performed when a row is double-clicked.void
setOnRightClickAction
(Consumer<Map<String, String>> onRightClickAction) Sets the action to be performed when a row is right-clicked.void
setOnSelectAction
(Consumer<Map<String, String>> onSelectAction) Sets the action to be performed when a row is selected.void
setRowHeight
(int rowHeight) Sets the height of each row in theWidget
.void
setRowHoverColor
(NanoColor rowHoverColor) Sets the color of the row hover background in theWidget
.void
Sets the list of rows in theWidget
.void
setRowTextColor
(NanoColor rowTextColor) Sets the color of the row text in theWidget
.void
sortByColumn
(String columnName, boolean ascending) Sorts the table rows by the specified column in the given order.void
update()
Updates theWidget
state, including recalculating column widths and scrollbar positions.void
Updates an existing row at the specified index with the new values.Methods inherited from class com.avrix.ui.widgets.ScrollPanelWidget
addChild, getHorizontalScrollbar, getVerticalScrollbar, onInitialize, removeChild, renderChildren, setMaxScrollX, setMaxScrollY
Methods inherited from class com.avrix.ui.widgets.PanelWidget
isDraggable, onLeftMouseUp, onLeftMouseUpOutside, postRender, setBackgroundColor, setBorderColor, setBorderRadius, setBorderWidth, setDraggable, setDrawBorder
Methods inherited from class com.avrix.ui.widgets.Widget
addToScreen, bringToTop, drawArc, drawArc, drawCircle, drawEllipse, drawImage, drawLine, drawRect, drawRectOutline, drawRoundedRect, drawRoundedRectOutline, drawText, getAbsoluteParent, getChildren, getHeight, getMaxScrollX, getMaxScrollY, getParent, getScrollSpeed, getScrollX, getScrollY, getWidth, getX, getXA, getY, getYA, intersectScissor, isAlwaysOnTop, isHovered, isPointOver, isScrollable, isScrollLock, isVisible, isVisibleWithinParent, isVisibleWithinWindow, onKeyPress, onKeyRelease, onKeyRepeat, onLeftMouseDownOutside, onMouseEnter, onMouseExit, onMouseMoveOutside, onMouseWheel, onRightMouseDownOutside, onRightMouseUp, onRightMouseUpOutside, preRender, removeFromScreen, setAlwaysOnTop, setHeight, setScrollable, setScrollLock, setScrollSpeed, setScrollX, setScrollY, setVisible, setWidth, setX, setXA, setY, setYA
-
Constructor Details
-
TableWidget
public TableWidget(int x, int y, int width, int height) Constructs a newTableWidget
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 classWidget
- 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 classPanelWidget
- 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 classWidget
- Parameters:
x
- The relative X coordinate of the mouse click.y
- The relative Y coordinate of the mouse click.
-
sortByColumn
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
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
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
Sets the action to be performed when a row is selected.- Parameters:
onSelectAction
- The action to be performed when a row is selected.
-
setOnDoubleSelectAction
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
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
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
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
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
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
Gets the font name used for rendering text in theWidget
.- Returns:
- the font name as a
String
.
-
setFontName
Sets the font name used for rendering text in theWidget
.- Parameters:
fontName
- the font name to set.
-
getIconFontName
Gets the icon font name used for rendering icons in theWidget
.- Returns:
- the icon font name as a
String
.
-
setIconFontName
Sets the icon font name used for rendering icons in theWidget
.- Parameters:
iconFontName
- the icon font name to set.
-
getIconDown
Gets the icon used for indicating a downward sort direction in theWidget
.- Returns:
- the downward sort icon as a
String
.
-
setIconDown
Sets the icon used for indicating a downward sort direction in theWidget
.- Parameters:
iconDown
- the downward sort icon to set.
-
getIconUp
Gets the icon used for indicating an upward sort direction in theWidget
.- Returns:
- the upward sort icon as a
String
.
-
setIconUp
Sets the icon used for indicating an upward sort direction in theWidget
.- Parameters:
iconUp
- the upward sort icon to set.
-
getLastSortedColumn
Gets the name of the last sorted column in theWidget
.- Returns:
- the name of the last sorted column as a
String
.
-
setLastSortedColumn
Sets the name of the last sorted column in theWidget
.- Parameters:
lastSortedColumn
- the name of the last sorted column to set.
-
getHeaderHeight
public int getHeaderHeight()Gets the height of the header in theWidget
.- Returns:
- the header height as an
int
.
-
setHeaderHeight
public void setHeaderHeight(int headerHeight) Sets the height of the header in theWidget
.- Parameters:
headerHeight
- the header height to set.
-
getBorderOffset
public int getBorderOffset()Gets the border offset in theWidget
.- Returns:
- the border offset as an
int
.
-
setBorderOffset
public void setBorderOffset(int borderOffset) Sets the border offset in theWidget
.- Parameters:
borderOffset
- the border offset to set.
-
getLineThickness
public int getLineThickness()Gets the thickness of the lines in theWidget
.- Returns:
- the line thickness as an
int
.
-
setLineThickness
public void setLineThickness(int lineThickness) Sets the thickness of the lines in theWidget
.- Parameters:
lineThickness
- the line thickness to set.
-
getRowHeight
public int getRowHeight()Gets the height of each row in theWidget
.- Returns:
- the row height as an
int
.
-
setRowHeight
public void setRowHeight(int rowHeight) Sets the height of each row in theWidget
.- Parameters:
rowHeight
- the row height to set.
-
getColumn
Gets the list of column names in theWidget
. -
setColumn
Sets the list of column names in theWidget
.- Parameters:
column
- the list of column names to set.
-
getRows
Gets the list of rows in theWidget
. -
setRows
Sets the list of rows in theWidget
.- Parameters:
rows
- the list of rows to set.
-
getHeaderColor
Gets the color of the header in theWidget
.- Returns:
- the header color as a
NanoColor
.
-
setHeaderColor
Sets the color of the header in theWidget
.- Parameters:
headerColor
- the header color to set.
-
getHeaderTextColor
Gets the color of the header text in theWidget
.- Returns:
- the header text color as a
NanoColor
.
-
setHeaderTextColor
Sets the color of the header text in theWidget
.- Parameters:
headerTextColor
- the header text color to set.
-
getAccentColor
Gets the accent color used in theWidget
.- Returns:
- the accent color as a
NanoColor
.
-
setAccentColor
Sets the accent color used in theWidget
.- Parameters:
accentColor
- the accent color to set.
-
getRowTextColor
Gets the color of the row text in theWidget
.- Returns:
- the row text color as a
NanoColor
.
-
setRowTextColor
Sets the color of the row text in theWidget
.- Parameters:
rowTextColor
- the row text color to set.
-
getRowHoverColor
Gets the color of the row hover background in theWidget
.- Returns:
- the row hover color as a
NanoColor
.
-
setRowHoverColor
Sets the color of the row hover background in theWidget
.- Parameters:
rowHoverColor
- the row hover color to set.
-
getLineColor
Gets the color of the line used for borders and separators in theWidget
.- Returns:
- the line color as a
NanoColor
.
-
setLineColor
Sets the color of the line used for borders and separators in theWidget
.- Parameters:
lineColor
- the line color to set.
-
update
public void update()Updates theWidget
state, including recalculating column widths and scrollbar positions.- Overrides:
update
in classScrollPanelWidget
-
render
public void render()Renders theWidget
, including drawing the table headers, rows, and borders.- Overrides:
render
in classPanelWidget
-