public class JXCWindowRenderer
extends java.lang.Object
Gui
instance into a Frame
.Modifier and Type | Class and Description |
---|---|
private class |
JXCWindowRenderer.OpenDialogsIterator
An
Iterator that returns all open dialogs in painting order. |
Modifier and Type | Field and Description |
---|---|
private java.awt.image.BufferStrategy |
bufferStrategy
The current
BufferStrategy . |
private java.awt.event.ComponentListener |
componentListener
The
ComponentListener attached to frame . |
private CrossfireServerConnection |
crossfireServerConnection
The
CrossfireServerConnection to monitor. |
private Gui |
currentGui
The currently displayed
Gui . |
private java.io.Writer |
debugScreen
The
Writer to write screen debug to or null . |
private static int |
DEFAULT_MAP_HEIGHT
The default map height to request from the server.
|
private static int |
DEFAULT_MAP_WIDTH
The default map width to request from the server.
|
private static int |
DEFAULT_NUM_LOOK_OBJECTS
The default number of ground view objects.
|
private java.awt.DisplayMode |
defaultDisplayMode
The default screen mode that was active when the client did start.
|
private java.util.Collection<GUIFloorList> |
floorLists
|
private javax.swing.JFrame |
frame
The associated
JFrame . |
private java.awt.GraphicsDevice |
graphicsDevice
The used
GraphicsDevice . |
private java.awt.GraphicsEnvironment |
graphicsEnvironment
The used
GraphicsEnvironment . |
private boolean |
isFullScreen
Records whether full-screen mode is active.
|
private java.awt.Container |
layeredPane
The
JLayeredPane added as the top-level component to frame . |
private java.util.Collection<GUIMap> |
maps
|
private java.awt.Rectangle |
maximumWindowBounds
The maximal size of a window.
|
private javax.swing.event.MouseInputListener |
mouseInputListener
A
MouseInputListener that forwards to mouseTracker . |
private MouseTracker |
mouseTracker
The
MouseTracker instance. |
private int |
offsetX
The x-offset of the visible window.
|
private int |
offsetY
The y-offset of the visible window.
|
private java.util.List<Gui> |
openDialogs
Currently opened dialogs.
|
private RendererGuiState |
rendererGuiState
The current gui state.
|
private EventListenerList2<RendererGuiStateListener> |
rendererGuiStateListeners
Listeners to be notified about
rendererGuiState changes. |
private java.text.DateFormat |
simpleDateFormat
A formatter for timestamps.
|
private java.awt.Component |
tooltip
The tooltip to use, or
null if no tooltips should be shown. |
private boolean |
wasDisplayed
Records whether the
frame has been displayed before. |
private int |
windowHeight
The height of the client area in pixels.
|
private int |
windowWidth
The width of the client area in pixels.
|
Constructor and Description |
---|
JXCWindowRenderer(MouseTracker mouseTracker,
CrossfireServerConnection crossfireServerConnection,
java.io.Writer debugScreen)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
GUIText |
activateCommandInput()
Activates the command input text field.
|
static GUIText |
activateCommandInput(Gui gui)
Returns the first command text field of a gui and make it active.
|
private void |
addComponent(java.awt.Component component)
Adds a
Component . |
void |
addGuiStateListener(RendererGuiStateListener listener)
Adds a gui state listener to be notified about
rendererGuiState
changes. |
private void |
addMouseTracker(java.awt.Component component)
Adds
mouseTracker to a Component . |
private void |
addMouseTrackerRecursively(java.awt.Component component)
Adds
mouseTracker recursively to all children of a Component . |
private void |
addToLayeredPane(java.awt.Component component,
int layer,
int index)
Adds a component to
layeredPane . |
void |
clearGUI(Gui gui)
Sets a gui to display and clears the display.
|
boolean |
closeDialog(Gui dialog)
Closes a dialog.
|
boolean |
deactivateCommandInput()
Deactivates the command input text field.
|
private void |
debugScreenWrite(java.lang.CharSequence message)
Writes a message to the screen debug.
|
void |
endRendering()
Ends rendering and reverts the display settings.
|
private static AbstractGUIElement |
findElement(java.awt.Component component,
java.awt.event.MouseEvent mouseEvent)
Finds the gui element a given
Component is part of. |
private AbstractGUIElement |
findElement(java.awt.event.MouseEvent e)
Finds the gui element for a given
MouseEvent . |
Buffer |
getActiveMessageBuffer()
Returns the active message buffer.
|
private static Buffer |
getActiveMessageBuffer(Gui gui)
Returns the active message buffer for a
Gui instance. |
private java.awt.Point |
getCenterPoint()
Returns the
Point where windows should be centered. |
private java.awt.DisplayMode |
getDisplayMode()
Returns the current display mode of the
graphicsDevice . |
private AbstractGUIElement |
getElementFromPoint(Gui gui,
int eX,
int eY)
Determines the
GUIElement for a given coordinate with a given
Gui instance. |
RendererGuiState |
getGuiState()
Returns the current gui state.
|
private java.awt.Dimension |
getMapSize()
Returns the map size in squares.
|
private java.awt.Dimension |
getMaxWindowDimension(java.awt.Insets frameInsets)
Returns the maximum dimension of a frame to fit on the screen.
|
private int |
getNumLookObjects()
Returns the number of ground view objects to request from the server.
|
java.lang.Iterable<Gui> |
getOpenDialogs()
Returns all open dialogs in reverse painting order; the first element is
the top-most dialog.
|
int |
getWindowHeight()
Returns the height of the client area.
|
int |
getWindowWidth()
Returns the width of the client area.
|
boolean |
handleKeyPress(KeyEvent2 e)
Dispatches a key press
KeyEvent . |
boolean |
isDialogOpen(Gui dialog)
Returns whether a given dialog is currently visible.
|
private boolean |
isDisplayChangeSupported()
Returns the
graphicsDevice supports low-level display changes. |
private boolean |
isFullScreenSupported()
Returns whether the
graphicsDevice supports full-screen
exclusive mode. |
boolean |
openDialog(Gui dialog,
boolean autoCloseOnDeactivate)
Opens a dialog.
|
private void |
openDialogInt(Gui dialog)
Opens a dialog.
|
private void |
openDialogsAdd(Gui dialog)
Adds a dialog to
openDialogs . |
private boolean |
openDialogsRemove(Gui dialog)
Removes a dialog to
openDialogs . |
void |
raiseDialog(Gui dialog)
Raises an already opened dialog.
|
void |
redraw(java.awt.Graphics g)
Paints the view into the given graphics instance.
|
private void |
redrawBlack(java.awt.Graphics g)
Repaints all to black.
|
private void |
removeComponent(java.awt.Component component)
Removes a
Component . |
private void |
removeFromLayeredPane(java.awt.Component component)
Removes a component from
layeredPane . |
private void |
removeMouseTracker(java.awt.Component component)
Removes
mouseTracker from a Component . |
private void |
removeMouseTrackerRecursively(java.awt.Component component)
Removes
mouseTracker recursively from all children of a Component . |
void |
setCurrentGui(Gui gui)
Sets the
Gui to display. |
private void |
setDisplayMode(java.awt.DisplayMode displayMode)
Sets the display mode of the
graphicsDevice . |
boolean |
setFullScreenMode(javax.swing.JFrame frame,
Resolution resolution)
Tries to switch to the given resolution.
|
private void |
setFullScreenWindow(java.awt.Window window)
Enter full-screen mode, or return to windowed mode.
|
void |
setGuiState(RendererGuiState rendererGuiState)
Sets the current gui state.
|
private void |
setResolutionPost(java.awt.Window frame,
java.awt.Dimension dimension)
Tries to switch to the given resolution.
|
private void |
setResolutionPre(java.awt.Window frame)
Tries to switch to the given resolution.
|
void |
setSelectedHostname(java.lang.String serverName)
Selects a server entry.
|
void |
setTooltip(java.awt.Component tooltip)
Sets the tooltip to use, or
null if no tooltips should be shown. |
void |
setWindowMode(javax.swing.JFrame frame,
Resolution resolution,
Resolution minResolution,
boolean fixedSize)
Tries to switch to the given resolution.
|
boolean |
toggleDialog(Gui dialog)
Toggles a dialog: if the dialog is not shown, show it; else hide it.
|
void |
updateServerSettings()
Updates server based settings to current screen size.
|
private void |
updateWindowSize(int windowWidth,
int windowHeight)
Updates the window size for rendering from the main window size.
|
@Nullable private java.awt.image.BufferStrategy bufferStrategy
BufferStrategy
. Set to null
until setFullScreenMode(JFrame, Resolution)
or setWindowMode(JFrame,
Resolution, Resolution, boolean)
has been called.@NotNull private final java.awt.event.ComponentListener componentListener
ComponentListener
attached to frame
.@NotNull private final CrossfireServerConnection crossfireServerConnection
CrossfireServerConnection
to monitor.@Nullable private final java.io.Writer debugScreen
Writer
to write screen debug to or null
.private static final int DEFAULT_MAP_HEIGHT
private static final int DEFAULT_MAP_WIDTH
private static final int DEFAULT_NUM_LOOK_OBJECTS
@NotNull private final java.awt.DisplayMode defaultDisplayMode
@NotNull private final java.util.Collection<GUIFloorList> floorLists
@Nullable private javax.swing.JFrame frame
JFrame
. Set to null
while not visible.@NotNull private final java.awt.GraphicsDevice graphicsDevice
GraphicsDevice
.@NotNull private final java.awt.GraphicsEnvironment graphicsEnvironment
GraphicsEnvironment
.private boolean isFullScreen
@NotNull private final java.awt.Container layeredPane
JLayeredPane
added as the top-level component to frame
.@NotNull private final java.util.Collection<GUIMap> maps
@NotNull private final java.awt.Rectangle maximumWindowBounds
@NotNull private final javax.swing.event.MouseInputListener mouseInputListener
MouseInputListener
that forwards to mouseTracker
.@NotNull private final MouseTracker mouseTracker
MouseTracker
instance.private int offsetX
private int offsetY
@NotNull private final java.util.List<Gui> openDialogs
@NotNull private RendererGuiState rendererGuiState
@NotNull private final EventListenerList2<RendererGuiStateListener> rendererGuiStateListeners
rendererGuiState
changes.@NotNull private final java.text.DateFormat simpleDateFormat
@Nullable private java.awt.Component tooltip
null
if no tooltips should be shown.private boolean wasDisplayed
frame
has been displayed before.private int windowHeight
private int windowWidth
public JXCWindowRenderer(@NotNull MouseTracker mouseTracker, @NotNull CrossfireServerConnection crossfireServerConnection, @Nullable java.io.Writer debugScreen)
mouseTracker
- the mouse tracker instancecrossfireServerConnection
- the server connection to monitordebugScreen
- the writer to write screen debug to or null
@Nullable public GUIText activateCommandInput()
null
if no command input
text field exists@Nullable public static GUIText activateCommandInput(@NotNull Gui gui)
gui
- the gui to checknull
if this gui does not
contain any command text fieldsprivate void addComponent(@NotNull java.awt.Component component)
Component
.component
- the component to addpublic void addGuiStateListener(@NotNull RendererGuiStateListener listener)
rendererGuiState
changes.listener
- the listener to addprivate void addMouseTracker(@NotNull java.awt.Component component)
mouseTracker
to a Component
.component
- the component to add toprivate void addMouseTrackerRecursively(@NotNull java.awt.Component component)
mouseTracker
recursively to all children of a Component
.component
- the component to add toprivate void addToLayeredPane(@NotNull java.awt.Component component, int layer, int index)
layeredPane
.component
- the componentlayer
- the layer to add toindex
- the index within the layer to add topublic void clearGUI(@NotNull Gui gui)
gui
- the gui to setpublic boolean closeDialog(@NotNull Gui dialog)
dialog
- the dialog to closefalse
if the dialog
was not openpublic boolean deactivateCommandInput()
private void debugScreenWrite(@NotNull java.lang.CharSequence message)
message
- the message to writepublic void endRendering()
@Nullable private static AbstractGUIElement findElement(@NotNull java.awt.Component component, @NotNull java.awt.event.MouseEvent mouseEvent)
Component
is part of.component
- the component to searchmouseEvent
- the mouse event to updatenull
if none was found@Nullable private AbstractGUIElement findElement(@NotNull java.awt.event.MouseEvent e)
MouseEvent
. If a gui element
was found, update the event mouse coordinates to be relative to the gui
element.e
- the mouse event to processnull
if none was found@Nullable public Buffer getActiveMessageBuffer()
null
if none is active@Nullable private static Buffer getActiveMessageBuffer(@NotNull Gui gui)
Gui
instance.gui
- the gui instancenull
@NotNull private java.awt.Point getCenterPoint()
Point
where windows should be centered.@NotNull private java.awt.DisplayMode getDisplayMode()
graphicsDevice
.@Nullable private AbstractGUIElement getElementFromPoint(@NotNull Gui gui, int eX, int eY)
GUIElement
for a given coordinate with a given
Gui
instance.gui
- the gui to searcheX
- the x-coordinate to checkeY
- the y-coordinate to checkGUIElement
at the given coordinate or null
if
none was found@NotNull public RendererGuiState getGuiState()
@NotNull private java.awt.Dimension getMapSize()
@NotNull private java.awt.Dimension getMaxWindowDimension(@NotNull java.awt.Insets frameInsets)
frameInsets
- the frame's insetsprivate int getNumLookObjects()
@NotNull public java.lang.Iterable<Gui> getOpenDialogs()
public int getWindowHeight()
public int getWindowWidth()
public boolean handleKeyPress(@NotNull KeyEvent2 e)
KeyEvent
.e
- the event to dispatchpublic boolean isDialogOpen(@NotNull Gui dialog)
dialog
- the dialog to checkprivate boolean isDisplayChangeSupported()
graphicsDevice
supports low-level display changes.private boolean isFullScreenSupported()
graphicsDevice
supports full-screen
exclusive mode.public boolean openDialog(@NotNull Gui dialog, boolean autoCloseOnDeactivate)
dialog
- the dialog to showautoCloseOnDeactivate
- whether the dialog should auto-close when it
becomes inactive; ignored if the dialog is already openfalse
if the
dialog already was opened as the topmost dialogprivate void openDialogInt(@NotNull Gui dialog)
dialog
- the dialog to openprivate void openDialogsAdd(@NotNull Gui dialog)
openDialogs
. Generates mouse events if
necessary.dialog
- the dialogprivate boolean openDialogsRemove(@NotNull Gui dialog)
openDialogs
. Generates mouse events if
necessary.dialog
- the dialogpublic void raiseDialog(@NotNull Gui dialog)
dialog
- the dialog to showpublic void redraw(@NotNull java.awt.Graphics g)
g
- the graphics instance to paint toprivate void redrawBlack(@NotNull java.awt.Graphics g)
g
- the graphics to paint intoprivate void removeComponent(@NotNull java.awt.Component component)
Component
.component
- the component to removeprivate void removeFromLayeredPane(@NotNull java.awt.Component component)
layeredPane
.component
- the componentprivate void removeMouseTracker(@NotNull java.awt.Component component)
mouseTracker
from a Component
.component
- the component to remove fromprivate void removeMouseTrackerRecursively(@NotNull java.awt.Component component)
mouseTracker
recursively from all children of a Component
.component
- the component to add topublic void setCurrentGui(@NotNull Gui gui)
Gui
to display.gui
- the gui to displayprivate void setDisplayMode(@NotNull java.awt.DisplayMode displayMode)
graphicsDevice
.displayMode
- the new display modepublic boolean setFullScreenMode(@NotNull javax.swing.JFrame frame, @Nullable Resolution resolution)
frame
- the associated frameresolution
- the resolution to switch to; null
to keep
current resolutionprivate void setFullScreenWindow(@Nullable java.awt.Window window)
window
- the window to enter full-screen mode or null
to
leave full-screen modepublic void setGuiState(@NotNull RendererGuiState rendererGuiState)
rendererGuiState
- the gui stateprivate void setResolutionPost(@NotNull java.awt.Window frame, @NotNull java.awt.Dimension dimension)
frame
- the associated framedimension
- the window size to switch toprivate void setResolutionPre(@NotNull java.awt.Window frame)
frame
- the associated framepublic void setSelectedHostname(@NotNull java.lang.String serverName)
serverName
- the server name to selectpublic void setTooltip(@Nullable java.awt.Component tooltip)
null
if no tooltips should be shown.tooltip
- the tooltip to use, or null
public void setWindowMode(@NotNull javax.swing.JFrame frame, @Nullable Resolution resolution, @NotNull Resolution minResolution, boolean fixedSize)
frame
- the associated frameresolution
- the resolution to switch to, null
for defaultminResolution
- the minimal supported resolutionfixedSize
- whether the window should have fixed sizepublic boolean toggleDialog(@NotNull Gui dialog)
dialog
- the dialog to togglepublic void updateServerSettings()
private void updateWindowSize(int windowWidth, int windowHeight)
windowWidth
- the window width including insetswindowHeight
- the window height including insets