Class ListField
- All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener
-
Field Summary
Fields inherited from class GuiComponent
ICON_FONT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeselect()Resets the ListField's selection tonull.Gets the spritesheet used for the button.Gets the list of change consumers.Object[][]Gets the content of the list field.Gets the spritesheet used for the list entries.intGets the current horizontal lower bound of the list field.Gets the horizontal slider associated with the list field.getListEntry(int column) Returns all list items of a specified column.getListEntry(int column, int row) Returns item at a specified column and row.intReturns the number of rows of the tallest column.intGets the number of columns currently shown in the list field.intGets the number of rows currently shown in the list field.Gets the currently selected component in the list field.Gets the object associated with the currently selected component in the list field.intReturns the selected column.intReturns the selected row.intGets the current vertical lower bound of the list field.Gets the vertical slider associated with the list field.booleanChecks if arrow key navigation is enabled for the list field.booleanbooleanbooleanVerify if sliders are set to be inside the ListField.voidRegisters a new change consumer to be executed when the selection changes.voidrefresh()Refreshes the list field by updating the list entries and selecting the current component.voidrender(Graphics2D g) Note: If you override this and are modifying swing components, be sure you are in the AWT thread when you do so!voidsetArrowKeyNavigation(boolean arrowKeyNavigation) Enables or disables arrow key navigation for the list field.voidsetButtonSprite(Spritesheet buttonSprite) Sets the spritesheet for the button and reinitializes the content list.voidsetEntrySprite(Spritesheet entrySprite) Sets the spritesheet for the list entries and reinitializes the content list.voidsetForwardMouseEvents(int column, boolean forwardMouseEvents) Sets whether mouse events should be forwarded for all components in the specified column.voidsetHorizontalLowerBound(int lowerBound) Sets the horizontal lower bound of the list field.voidsetSelectEntireColumn(boolean selectEntireColumn) If set to true, selecting an element will show a selection of the entire column on which that element is on.voidsetSelectEntireRow(boolean selectEntireRow) If set to true, selecting an element will show a selection of the entire row on which that element is on.voidsetSelection(int column, int row) voidsetSliderInside(boolean sliderInside) If set to true, the sliders of this ListField will be displayed within its boundaries.voidsetVerticalLowerBound(int lowerBound) Sets the vertical lower bound of the list field.voidSlides the ListField down by one row.voidslideUp()Slides the ListField up by one row.Methods inherited from class GuiComponent
addRenderedListener, addRenderListener, getAppearance, getAppearanceDisabled, getAppearanceHovered, getBoundingBox, getCenterX, getCenterY, getClickConsumer, getComponentId, getComponents, getCurrentAppearance, getFocusedComponent, getFont, getHeight, getHoverConsumer, getHoverSound, getLocation, getMouseDraggedConsumer, getMouseEnterConsumer, getMouseLeaveConsumer, getMouseMovedConsumer, getMousePressedConsumer, getMouseReleasedConsumer, getMouseWheelConsumer, getName, getShape, getTag, getText, getTextAlign, getTextAngle, getTextShadowColor, getTextShadowRadius, getTextToRender, getTextValign, getTextX, getTextY, getTweenValues, getWidth, getX, getY, hasAutomaticLineBreaks, hasInputFocus, hasTextAntialiasing, hasTextShadow, initializeComponents, isAutoScaling, isEnabled, isFocusable, isForwardMouseEvents, isHovered, isPressed, isSelected, isSuspended, isVisible, mouseClicked, mouseDragged, mouseEntered, mouseEventShouldBeForwarded, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, onClicked, onHovered, onMouseDragged, onMouseEnter, onMouseLeave, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelScrolled, onResolutionChanged, onTextChanged, prepare, removeListener, removeListener, setAutomaticLineBreaks, setAutoScaling, setDimension, setEnabled, setFocusable, setFont, setFontSize, setForwardMouseEvents, setHeight, setHovered, setHoverSound, setLocation, setLocation, setName, setSelected, setTag, setText, setTextAlign, setTextAngle, setTextAntialiasing, setTextShadow, setTextShadowColor, setTextShadowRadius, setTextValign, setTextX, setTextY, setTweenValues, setVisible, setWidth, setX, setY, suspend, toggleSelection, toggleSuspension
-
Constructor Details
-
ListField
Creates a vertical list field.
The content of this list field can only be accessed through the first column (column 0).
Examples:
content[0][0] - ok
content[0][1] - ok
content[0][8] - ok
content[1][5] - NOK
content[2][0] - NOK
- Parameters:
x- The x-coordinate of the ListField.y- The y-coordinate of the ListField.width- The width of the ListField.height- The height of the ListField.content- The 1 dimension array to show in the ListField.shownRows- The number of rows/elements to display before the user needs to scroll for more possible rows/elements.- See Also:
-
ListField
public ListField(double x, double y, double width, double height, Object[][] content, int shownRows, int shownColumns) Creates a 2D vertical list field.
The given content should be arranged as columns of elements.
Examples:
content[0][0] - column 0, row 0
content[0][1] - column 0, row 1
content[2][8] - column 2, row 8
- Parameters:
x- The x-coordinate of the ListField.y- The y-coordinate of the ListField.width- The width of the ListField.height- The height of the ListField.content- The 2 dimension array to show in the ListField.shownRows- The number of rows to display before the user needs to scroll for more possible rows.shownColumns- The number of columns to display before the user needs to scroll for more possible columns.
-
-
Method Details
-
deselect
public void deselect()Resets the ListField's selection to
null.The ListField will then show no selection.
-
getButtonSprite
Gets the spritesheet used for the button.- Returns:
- The spritesheet for the button.
-
setButtonSprite
Sets the spritesheet for the button and reinitializes the content list.- Parameters:
buttonSprite- The spritesheet to set for the button.
-
getChangeConsumer
Gets the list of change consumers. Change consumers are functions that are executed when the selection changes.- Returns:
- A list of IntConsumer objects representing the change consumers.
-
getContent
Gets the content of the list field.- Returns:
- A 2D array of objects representing the content of the list field.
-
getEntrySprite
Gets the spritesheet used for the list entries.- Returns:
- The spritesheet for the list entries.
-
setEntrySprite
Sets the spritesheet for the list entries and reinitializes the content list.- Parameters:
entrySprite- The spritesheet to set for the list entries.
-
getHorizontalLowerBound
public int getHorizontalLowerBound()Gets the current horizontal lower bound of the list field.- Returns:
- The horizontal lower bound.
-
setHorizontalLowerBound
public void setHorizontalLowerBound(int lowerBound) Sets the horizontal lower bound of the list field.- Parameters:
lowerBound- The new horizontal lower bound to set.
-
getHorizontalSlider
Gets the horizontal slider associated with the list field.- Returns:
- The horizontal slider.
-
getListEntry
Returns all list items of a specified column.- Parameters:
column- the column- Returns:
- a list of items
-
getListEntry
Returns item at a specified column and row.- Parameters:
column- the columnrow- the row- Returns:
- ImageComponent at [column,row]
-
getMaxRows
public int getMaxRows()Returns the number of rows of the tallest column.- Returns:
- int representing the length of the tallest column
-
getNumberOfShownRows
public int getNumberOfShownRows()Gets the number of rows currently shown in the list field.- Returns:
- The number of rows displayed in the list field.
-
getNumberOfShownColumns
public int getNumberOfShownColumns()Gets the number of columns currently shown in the list field.- Returns:
- The number of columns displayed in the list field.
-
getSelectedComponent
Gets the currently selected component in the list field.- Returns:
- The selected ImageComponent, or null if no component is selected.
-
getSelectedObject
Gets the object associated with the currently selected component in the list field.- Returns:
- The object at the selected position, or null if no component is selected.
-
getSelectionColumn
public int getSelectionColumn()Returns the selected column.- Returns:
- number of the column; -1 if isEntireRowSelected() is true
-
getSelectionRow
public int getSelectionRow()Returns the selected row.- Returns:
- number of the row
-
getVerticalLowerBound
public int getVerticalLowerBound()Gets the current vertical lower bound of the list field.- Returns:
- The vertical lower bound.
-
setVerticalLowerBound
public void setVerticalLowerBound(int lowerBound) Sets the vertical lower bound of the list field.- Parameters:
lowerBound- The new vertical lower bound to set.
-
getVerticalSlider
Gets the vertical slider associated with the list field.- Returns:
- The vertical slider.
-
onChange
Registers a new change consumer to be executed when the selection changes.- Parameters:
c- The IntConsumer to be added to the list of change consumers.
-
refresh
public void refresh()Refreshes the list field by updating the list entries and selecting the current component. -
render
Description copied from class:GuiComponentNote: If you override this and are modifying swing components, be sure you are in the AWT thread when you do so!- Specified by:
renderin interfaceIRenderable- Overrides:
renderin classGuiComponent- Parameters:
g- The current graphics object onto which this instance will render its visual contents.- See Also:
-
setForwardMouseEvents
public void setForwardMouseEvents(int column, boolean forwardMouseEvents) Sets whether mouse events should be forwarded for all components in the specified column.- Parameters:
column- The column index for which to set the mouse event forwarding.forwardMouseEvents- True to enable forwarding of mouse events, false to disable it.
-
setSelection
public void setSelection(int column, int row) -
setSelectEntireColumn
public void setSelectEntireColumn(boolean selectEntireColumn) If set to true, selecting an element will show a selection of the entire column on which that element is on. Without taking account of its row.
Set to false as default.
- Parameters:
selectEntireColumn- a boolean
-
setSelectEntireRow
public void setSelectEntireRow(boolean selectEntireRow) If set to true, selecting an element will show a selection of the entire row on which that element is on. Without taking account of its column.
Set to false as default.
- Parameters:
selectEntireRow- a boolean
-
isEntireColumnSelected
public boolean isEntireColumnSelected()- Returns:
- true if selection is set to select the entire column; false otherwise
-
isEntireRowSelected
public boolean isEntireRowSelected()- Returns:
- true if selection is set to select the entire row; false otherwise
-
isSliderInside
public boolean isSliderInside()Verify if sliders are set to be inside the ListField.- Returns:
- true if slider is set to be inside the ListField; false otherwise
-
setSliderInside
public void setSliderInside(boolean sliderInside) If set to true, the sliders of this ListField will be displayed within its boundaries. This is necessary, for example, when a ListField covers an entire screen.
Set to false as default.
- Parameters:
sliderInside- a boolean
-
slideUp
public void slideUp()Slides the ListField up by one row. -
slideDown
public void slideDown()Slides the ListField down by one row.
-