public class Gui
extends javax.swing.JComponent
GUIElements
to for a gui.
A dialog can be modal. Such dialogs do not propagate key or mouse events to lower dialogs.
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
private ActivatableGUIElement |
activeElement
The gui element which has the focus.
|
private Extent |
autoSize
The extent of the dialog if it is auto-sizing or
null otherwise. |
private Expression |
defaultX
The default x-coordinate for this dialog.
|
private Expression |
defaultY
The default y-coordinate for this dialog.
|
private ActivatableGUIElement |
forcedActive
If non-
null , this element is always active. |
private GuiAutoCloseListener |
guiAutoCloseListener
If set, the auto-close listener to notify if this dialog looses the
active gui element.
|
private java.util.Collection<RendererGuiState> |
hideInStates
The gui states that do not show this dialog.
|
private boolean |
initialPositionSet
Whether an initial position has been set.
|
private KeyBindings |
keyBindings
The
KeyBindings for this gui. |
private boolean |
modal
Whether this dialog is modal.
|
private boolean |
saveDialog
Whether this dialog retains its position across restarts.
|
private static long |
serialVersionUID
The serial version UID.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
Gui(KeyBindings keyBindings)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
activateDefaultElement()
Activates the first default gui element of this gui.
|
void |
autoSize(int screenWidth,
int screenHeight)
Auto-resizes the dialog.
|
boolean |
deactivateCommandInput()
Deactivates the command text input field of this dialog.
|
private ActivatableGUIElement |
getDefaultElement()
Returns the first default gui element of this gui.
|
AbstractGUIElement |
getElementFromPoint(int x,
int y)
Determines the
GUIElement for a given coordinate. |
<T extends GUIElement> |
getFirstElement(java.lang.Class<T> class_)
Returns the first gui element of this gui belonging to the given class.
|
<T extends GUIElement> |
getFirstElement(java.lang.Class<T> class_,
java.lang.String name)
Returns the first gui element of this gui belonging to the given class
and having the given name.
|
<T extends GUIElement> |
getFirstElementEndingWith(java.lang.Class<T> class_,
java.lang.String ending)
Returns the first gui element of this gui which belongs to the given
class and that's name ends with the given ending.
|
<T extends GUIElement> |
getFirstElementNotEndingWith(java.lang.Class<T> class_,
java.lang.String ending)
Returns the first gui element of this gui which belongs to the given
class and that's name does not end with the given ending.
|
KeyBindings |
getKeyBindings()
Returns the key bindings instance for this gui.
|
boolean |
handleKeyPress(KeyEvent2 e)
Dispatches a key press
KeyEvent . |
void |
hideInState(RendererGuiState state)
Hides the dialog in a state.
|
boolean |
isActiveElement(ActivatableGUIElement activeElement)
Returns whether a given gui element is the active element of this
dialog.
|
boolean |
isAutoSize()
Returns whether this dialog is an auto-size dialog.
|
boolean |
isHidden(RendererGuiState state)
Returns whether this gui is visible in a state.
|
boolean |
isModal()
Returns the modal state.
|
boolean |
isSaveDialog()
Returns whether this dialog retains its position across restarts.
|
boolean |
isWithinDrawingArea(int x,
int y)
Returns whether a given point is within this dialog's drawing area.
|
void |
setActiveElement(ActivatableGUIElement activeElement,
boolean active)
Sets the gui element owning the focus.
|
void |
setActiveElementActive(boolean active)
Activates or deactivates the GUI element owning the focus.
|
void |
setAutoSize(Extent autoSize)
Sets the auto-size state.
|
void |
setDefaultPosition(Expression defaultX,
Expression defaultY)
Sets the default position for this dialog.
|
void |
setForcedActive(ActivatableGUIElement forcedActive)
Sets an
ActivatableGUIElement that is always active. |
void |
setGuiAutoCloseListener(GuiAutoCloseListener guiAutoCloseListener)
Sets the
GuiAutoCloseListener to be notified when this dialog
becomes inactive. |
void |
setModal(boolean modal)
Sets the modal state.
|
void |
setPosition(int x,
int y)
Sets the position of this dialog.
|
void |
setSaveDialog()
Makes this dialog retain its position across restarts.
|
void |
showDialog(int x,
int y,
int windowWidth,
int windowHeight)
Sets the position of a dialog but makes sure the dialog is fully
visible.
|
java.lang.String |
toString() |
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
@Nullable private ActivatableGUIElement activeElement
null
if no such
element exists.@Nullable private Extent autoSize
null
otherwise.
Auto-sizing dialogs cannot be moved or resized manually.@Nullable private Expression defaultX
null
for
default.@Nullable private Expression defaultY
null
for
default.@Nullable private ActivatableGUIElement forcedActive
null
, this element is always active. No other element can
become active.@Nullable private GuiAutoCloseListener guiAutoCloseListener
@NotNull private final java.util.Collection<RendererGuiState> hideInStates
private boolean initialPositionSet
@NotNull private final KeyBindings keyBindings
KeyBindings
for this gui.private boolean modal
private boolean saveDialog
private static final long serialVersionUID
public Gui(@NotNull KeyBindings keyBindings)
keyBindings
- the keybindings to usepublic void activateDefaultElement()
public void autoSize(int screenWidth, int screenHeight)
screenWidth
- the screen widthscreenHeight
- the screen heightpublic boolean deactivateCommandInput()
@Nullable private ActivatableGUIElement getDefaultElement()
null
@Nullable public AbstractGUIElement getElementFromPoint(int x, int y)
GUIElement
for a given coordinate.x
- the x-coordinate to checky
- the y-coordinate to checkGUIElement
at the given coordinate or null
if
none was found@Nullable public <T extends GUIElement> T getFirstElement(@NotNull java.lang.Class<T> class_)
T
- the class to search forclass_
- the class to search fornull
if not found@Nullable public <T extends GUIElement> T getFirstElement(@NotNull java.lang.Class<T> class_, @NotNull java.lang.String name)
T
- the class to search forclass_
- the class to search forname
- the button's namenull
if no button matches@Nullable public <T extends GUIElement> T getFirstElementEndingWith(@NotNull java.lang.Class<T> class_, @NotNull java.lang.String ending)
T
- the class to search forclass_
- the class to search forending
- the ending to search fornull
if not found@Nullable public <T extends GUIElement> T getFirstElementNotEndingWith(@NotNull java.lang.Class<T> class_, @NotNull java.lang.String ending)
T
- the class to search forclass_
- the class to search forending
- the ending to search fornull
if not found@NotNull public KeyBindings getKeyBindings()
public boolean handleKeyPress(@NotNull KeyEvent2 e)
KeyEvent
.e
- the event to dispatchpublic void hideInState(@NotNull RendererGuiState state)
state
- the statepublic boolean isActiveElement(@Nullable ActivatableGUIElement activeElement)
activeElement
- the gui elementpublic boolean isAutoSize()
public boolean isHidden(@NotNull RendererGuiState state)
state
- the statepublic boolean isModal()
public boolean isSaveDialog()
public boolean isWithinDrawingArea(int x, int y)
x
- the x-coordinate of the the pointy
- the y-coordinate of the the pointpublic void setActiveElement(@NotNull ActivatableGUIElement activeElement, boolean active)
activeElement
- the gui elementactive
- the new active statepublic void setActiveElementActive(boolean active)
active
- whether to activate the GUI elementpublic void setAutoSize(@Nullable Extent autoSize)
autoSize
- the new auto-size or null
public void setDefaultPosition(@NotNull Expression defaultX, @NotNull Expression defaultY)
defaultX
- the default x-coordinatedefaultY
- the default y-coordinatepublic void setForcedActive(@Nullable ActivatableGUIElement forcedActive)
ActivatableGUIElement
that is always active. It prevents
any other element from getting active.forcedActive
- the element to set or null
to unsetpublic void setGuiAutoCloseListener(@Nullable GuiAutoCloseListener guiAutoCloseListener)
GuiAutoCloseListener
to be notified when this dialog
becomes inactive.guiAutoCloseListener
- the listener to be notified or null
public void setModal(boolean modal)
modal
- the new modal statepublic void setPosition(int x, int y)
x
- the x-coordinatey
- the y-coordinatepublic void setSaveDialog()
public void showDialog(int x, int y, int windowWidth, int windowHeight)
x
- the dialog's x coordinatey
- the dialog's y coordinatewindowWidth
- the main window's widthwindowHeight
- the main window's height@NotNull public java.lang.String toString()
toString
in class java.awt.Component