T
- The value data type.public class ComboBox<T>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.awt.geom.Rectangle2D |
bounds
The bounds for the main field of this combo box.
|
private static double |
CELL_HEIGHT
Height of the combo box field and drop down item fields.
|
private java.awt.Color |
color
Combo box accent color.
|
private boolean |
focus
Whether this combo box currently has focus.
|
private java.awt.geom.Rectangle2D |
list
The bounds for the drop down list of this combo box.
|
private java.util.function.Function<T,java.lang.String> |
toString
The function to use to turn the values into strings.
|
private T |
value
The currently selected value.
|
private T[] |
values
The list of possible values.
|
Constructor and Description |
---|
ComboBox(T[] values,
java.util.function.Function<T,java.lang.String> toString,
java.awt.Color color)
Constructs a new combo box with the given values, to string
function and accent color.
|
Modifier and Type | Method and Description |
---|---|
private int |
getSelectedIndex(java.awt.geom.Point2D loc)
Computes the drop down list selected index given
the list bounds.
|
T |
getValue()
Gets the value selected in this combo box.
|
void |
handleMouseClick(java.awt.geom.Point2D loc)
Handles a mouse click on this combo box.
|
boolean |
hasFocus()
Checks if this combo box currently has focus.
|
protected void |
render(java.awt.Graphics2D g,
double x,
double y,
double width,
double height,
java.awt.geom.Point2D loc)
Renders this combo box according to the given parameters.
|
private static final double CELL_HEIGHT
private java.awt.Color color
private java.awt.geom.Rectangle2D bounds
private java.awt.geom.Rectangle2D list
private T value
private T[] values
private java.util.function.Function<T,java.lang.String> toString
private boolean focus
public ComboBox(T[] values, java.util.function.Function<T,java.lang.String> toString, java.awt.Color color)
values
- The values for this combo box.toString
- The function to convert the values to a string.color
- The accent color.public T getValue()
public void handleMouseClick(java.awt.geom.Point2D loc)
loc
- The location that was clicked.public boolean hasFocus()
private int getSelectedIndex(java.awt.geom.Point2D loc)
loc
- The location selected.protected void render(java.awt.Graphics2D g, double x, double y, double width, double height, java.awt.geom.Point2D loc)
g
- The graphics context to use.x
- The x coordinate of the top left corner.y
- The y coordinate of the top left corner.width
- The width of the combo box.height
- The height of the main field of the combo box.loc
- The current mouse location.