Class GuiComponent
- All Implemented Interfaces:
KeyboardInputHandler, MouseInteractionController
- Direct Known Subclasses:
TextEditComponent
GuiComponent combines a composite shape with keyboard and mouse interaction
handling. When clicked, it acquires keyboard focus (via the KeyboardFocusStack),
and a red wireframe border is displayed to indicate focus. Pressing ESC releases focus.
This class is the foundation for interactive widgets like the
TextEditComponent.
Usage example - creating a custom GUI component:
GuiComponent myWidget = new GuiComponent(
new Transform(new Point3D(0, 0, 300)),
viewPanel,
new Point3D(400, 300, 0) // width, height, depth
);
// Add visual content to the widget
myWidget.addShape(someTextCanvas);
// Add to the scene
viewPanel.getRootShapeCollection().addShape(myWidget);
- See Also:
-
Field Summary
FieldsFields inherited from class AbstractShape
cachedBoundingBox, mouseInteractionController -
Constructor Summary
ConstructorsConstructorDescriptionGuiComponent(Transform transform, ViewPanel viewPanel, Point3D size) Creates a GUI component with the specified transform, view panel, and bounding box size. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCalled when the component loses keyboard focus.booleanfocusReceived(ViewPanel viewPanel) Called when the component receives keyboard focus.Returns the wireframe border box for this component.intgetDepth()Returns the depth of this component's bounding box.intReturns the height of this component's bounding box.intgetWidth()Returns the width of this component's bounding box.booleanReturns whether this component currently holds keyboard focus.voidHides the focus border around this component.booleankeyPressed(KeyEvent event, ViewPanel viewPanel) Called when a key is pressed while the component has focus.booleankeyReleased(KeyEvent event, ViewPanel viewPanel) Called when a key is released while the component has focus.booleanmouseClicked(int button) Called when mouse is clicked on component.booleanmouseClicked(int button, double textureU, double textureV, KeyboardFocusStack focusStack) Called when mouse is clicked on component, additionally carrying the keyboard focus stack of the dispatching view.booleanCalled when mouse gets over given component.booleanCalled when mouse leaves screen area occupied by component.booleanmouseWheelMoved(int verticalUnits, int horizontalUnits) Called when the mouse wheel is turned while this component has keyboard focus.Methods inherited from class AbstractCompositeShape
addShape, addShape, beforeTransformHook, collectMeshBlocks, collectRenderTriangles, extractSolidPolygons, getBoundingBox, getGlobalRenderListVersion, getGroup, getLocation, getSubShapesRegistry, getTransform, getTransformWeight, getViewSpaceTracker, hideGroup, intersect, postprocessRenderList, removeGroup, setBackfaceCulling, setCacheNeedsRebuild, setColor, setGroupForUngrouped, setMouseInteractionController, setRootComposite, setShadingEnabled, setTransform, showGroup, subtract, transform, unionMethods inherited from class AbstractShape
invalidateBoundsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface MouseInteractionController
mouseClicked, mouseHover
-
Field Details
-
viewPanel
The view panel this component is attached to.
-
-
Constructor Details
-
GuiComponent
Creates a GUI component with the specified transform, view panel, and bounding box size.- Parameters:
transform- the position and orientation of the component in 3D spaceviewPanel- the view panel this component belongs tosize- the bounding box dimensions (width, height, depth)
-
-
Method Details
-
focusLost
Description copied from interface:KeyboardInputHandlerCalled when the component loses keyboard focus.- Specified by:
focusLostin interfaceKeyboardInputHandler- Parameters:
viewPanel- the view panel that owns this handler- Returns:
trueif view needs to be re-rendered
-
focusReceived
Description copied from interface:KeyboardInputHandlerCalled when the component receives keyboard focus.- Specified by:
focusReceivedin interfaceKeyboardInputHandler- Parameters:
viewPanel- the view panel that owns this handler- Returns:
trueif view needs to be re-rendered
-
hasKeyboardFocus
public boolean hasKeyboardFocus()Returns whether this component currently holds keyboard focus.- Returns:
truewhen focused (focus border is shown)
-
getBorders
Returns the wireframe border box for this component.- Returns:
- the border wireframe box
-
getDepth
public int getDepth()Returns the depth of this component's bounding box.- Returns:
- the depth in pixels
-
getHeight
public int getHeight()Returns the height of this component's bounding box.- Returns:
- the height in pixels
-
getWidth
public int getWidth()Returns the width of this component's bounding box.- Returns:
- the width in pixels
-
hideBorder
public void hideBorder()Hides the focus border around this component. -
keyPressed
Description copied from interface:KeyboardInputHandlerCalled when a key is pressed while the component has focus.- Specified by:
keyPressedin interfaceKeyboardInputHandler- Parameters:
event- the key eventviewPanel- the view panel that owns this handler- Returns:
trueif view needs to be re-rendered
-
keyReleased
Description copied from interface:KeyboardInputHandlerCalled when a key is released while the component has focus.- Specified by:
keyReleasedin interfaceKeyboardInputHandler- Parameters:
event- the key eventviewPanel- the view panel that owns this handler- Returns:
trueif view needs to be re-rendered
-
mouseClicked
public boolean mouseClicked(int button) Description copied from interface:MouseInteractionControllerCalled when mouse is clicked on component.- Specified by:
mouseClickedin interfaceMouseInteractionController- Parameters:
button- the mouse button that was clicked (1 = left, 2 = middle, 3 = right)- Returns:
trueif view update is needed as a consequence of this mouse click
-
mouseClicked
public boolean mouseClicked(int button, double textureU, double textureV, KeyboardFocusStack focusStack) Description copied from interface:MouseInteractionControllerCalled when mouse is clicked on component, additionally carrying the keyboard focus stack of the dispatching view.Components that take keyboard focus on click should override THIS method rather than reaching for a stored ViewPanel reference: scenes built headlessly (golden-image harness) construct components with a null panel, but the dispatching view always has a focus stack.
The default implementation ignores the focus stack and delegates to
MouseInteractionController.mouseClicked(int, double, double).- Specified by:
mouseClickedin interfaceMouseInteractionController- Parameters:
button- the mouse button that was clicked (1 = left, 2 = middle, 3 = right)textureU- texture-space X of the clicked point, orDouble.NaNtextureV- texture-space Y of the clicked point, orDouble.NaNfocusStack- keyboard focus stack of the dispatching view- Returns:
trueif view update is needed as a consequence of this mouse click
-
mouseWheelMoved
public boolean mouseWheelMoved(int verticalUnits, int horizontalUnits) Description copied from interface:MouseInteractionControllerCalled when the mouse wheel is turned while this component has keyboard focus. Both axes are reported: horizontal wheel input arrives from AWT as shift-modified vertical rotation and is separated by the input manager.Returning
falselets the wheel fall through to the default camera movement.- Specified by:
mouseWheelMovedin interfaceMouseInteractionController- Parameters:
verticalUnits- wheel notches; positive = wheel away from the user (content scrolls down)horizontalUnits- wheel notches; positive = scroll right- Returns:
trueif the component consumed the scroll
-
mouseEntered
public boolean mouseEntered()Description copied from interface:MouseInteractionControllerCalled when mouse gets over given component.- Specified by:
mouseEnteredin interfaceMouseInteractionController- Returns:
trueif view update is needed as a consequence of this mouse enter.
-
mouseExited
public boolean mouseExited()Description copied from interface:MouseInteractionControllerCalled when mouse leaves screen area occupied by component.- Specified by:
mouseExitedin interfaceMouseInteractionController- Returns:
trueif view update is needed as a consequence of this mouse exit.
-