java.lang.Object com.realtime.crossfire.jxclient.gui.gui.JXCWindowRenderer
public class JXCWindowRenderer
Renders a Gui
instance into a Frame
.
Nested Class Summary | |
---|---|
private class |
JXCWindowRenderer.OpenDialogsIterator
An Iterator that returns all open dialogs in painting order. |
Field Summary | |
---|---|
private java.awt.event.ActionListener |
actionListener
Called periodically to update the display contents. |
private java.awt.image.BufferStrategy |
bufferStrategy
The current BufferStrategy . |
private CrossfireUpdateMapListener |
crossfireUpdateMapListener
The listener to detect map model changes. |
private Gui |
currentGui
The currently displayed Gui . |
private boolean |
currentGuiChanged
If set, currentGui has changed. |
private java.io.Writer |
debugScreen
The Writer to write screen debug to or null . |
private java.awt.DisplayMode |
defaultDisplayMode
The default screen mode that was active when the client did start. |
private boolean |
forcePaint
If set, force a full repaint. |
private java.awt.Frame |
frame
The associated Frame . |
private java.awt.GraphicsDevice |
graphicsDevice
The used GraphicsDevice . |
private java.awt.GraphicsEnvironment |
graphicsEnvironment
The used GraphicsEnvironment . |
private GuiAutoCloseListener |
guiAutoCloseListener
The GuiAutoCloseListener used to track auto-closing dialogs. |
private boolean |
inhibitPaintIconified
If set, do not repaint anything. |
private boolean |
inhibitPaintMapUpdate
If set, do not repaint anything. |
private boolean |
isFullScreen
Records whether full-screen mode is active. |
private java.awt.event.MouseListener |
mouseTracker
The MouseTracker instance. |
private int |
offsetH
The y-difference between the visible window and the real window. |
private int |
offsetW
The x-difference between the visible window to the real window. |
private int |
offsetX
The x-offset of the visible window. |
private int |
offsetY
The y-offset of the visible window. |
private java.util.concurrent.CopyOnWriteArrayList<Gui> |
openDialogs
Currently opened dialogs. |
private boolean |
openDialogsChanged
If set, the content of openDialogs has changed. |
private java.lang.Object |
redrawSemaphore
The semaphore used to synchronize map model updates and map view redraws. |
private RendererGuiState |
rendererGuiState
The current gui state. |
private java.util.Collection<RendererGuiStateListener> |
rendererGuiStateListeners
Listeners to be notified about rendererGuiState changes. |
private java.text.DateFormat |
simpleDateFormat
A formatter for timestamps. |
private boolean |
skippedPaint
If set, at least one call to redrawGUI() has been dropped while
inhibitPaintMapUpdate or inhibitPaintIconified was
set. |
private javax.swing.Timer |
timer
The timer used to update the display contents. |
private GUIElement |
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 Summary | |
---|---|
JXCWindowRenderer(java.awt.event.MouseListener mouseTracker,
java.lang.Object redrawSemaphore,
CrossfireServerConnection crossfireServerConnection,
java.io.Writer debugScreen)
Creates a new instance. |
Method Summary | |
---|---|
GUIText |
activateCommandInput()
Activates the command input text field. |
void |
addGuiStateListener(RendererGuiStateListener listener)
Adds a gui state listener to be notified about rendererGuiState
changes. |
void |
clearGUI(Gui gui)
Sets a gui to display and clears the display. |
void |
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. |
GUIElement |
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. |
RendererGuiState |
getGuiState()
Returns the current gui state. |
private java.awt.Dimension |
getMaxWindowDimension(java.awt.Insets frameInsets)
Returns the maximum dimension of a frame to fit on the screen. |
int |
getOffsetX()
Returns the x-offset of the visible window. |
int |
getOffsetY()
Returns the y-offset of the visible window. |
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(java.awt.event.KeyEvent e)
|
boolean |
handleKeyTyped(java.awt.event.KeyEvent e)
|
boolean |
isDialogOpen(Gui dialog)
Returns whether a given dialog is currently visible. |
private GUIElement |
manageMouseEvents(Gui gui,
java.awt.event.MouseEvent e)
|
private boolean |
needRedraw()
Checks whether any gui element has changed and needs a redraw. |
boolean |
openDialog(Gui dialog,
boolean autoCloseOnDeactivate)
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)
|
private void |
redrawGUI()
Redraws the current gui. |
private void |
redrawGUIBasic(java.awt.Graphics g)
|
private void |
redrawGUIDialog(java.awt.Graphics g)
|
private void |
redrawTooltip(java.awt.Graphics g)
|
void |
repaint()
Repaints the window. |
void |
setCurrentGui(Gui gui)
Sets the Gui to display. |
boolean |
setFullScreenMode(java.awt.Frame frame,
Resolution resolution)
Tries to switch to the given resolution. |
void |
setGuiState(RendererGuiState rendererGuiState)
Sets the current gui state. |
void |
setInhibitPaintIconified(boolean inhibitPaintIconified)
Inhibits or allows painting while the main window is iconified. |
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(GUIElement tooltip)
Sets the tooltip to use, or null if no tooltips should be
shown. |
void |
setWindowMode(java.awt.Frame frame,
Resolution resolution,
Resolution minResolution,
boolean fixedSize)
Tries to switch to the given resolution. |
private void |
showDialog(Gui dialog)
Makes sure the dialog is fully visible. |
void |
showDialog(Gui dialog,
int x,
int y)
Sets the position of a dialog but makes sure the dialog is fully visible. |
void |
showDialogAuto(Gui dialog)
Auto-resizes a dialog (or does nothing for non-auto-size dialogs). |
void |
start()
Starts repainting the window. |
void |
stop()
Stops repainting the window. |
boolean |
toggleDialog(Gui dialog)
Toggles a dialog: if the dialog is not shown, show it; else hide it. |
void |
updateWindowSize(int windowWidth,
int windowHeight)
Updates the window size for rendering from the main window size. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@NotNull private final java.awt.event.ActionListener actionListener
@Nullable private java.awt.image.BufferStrategy bufferStrategy
BufferStrategy
. Set to null
until setFullScreenMode(Frame, Resolution)
or setWindowMode(Frame,
Resolution, Resolution, boolean)
has been called.
@NotNull private final CrossfireUpdateMapListener crossfireUpdateMapListener
@NotNull private Gui currentGui
Gui
.
private boolean currentGuiChanged
currentGui
has changed.
@Nullable private final java.io.Writer debugScreen
Writer
to write screen debug to or null
.
@NotNull private final java.awt.DisplayMode defaultDisplayMode
private volatile boolean forcePaint
@Nullable private java.awt.Frame frame
Frame
. Set to null
while not
visible.
@NotNull private final java.awt.GraphicsDevice graphicsDevice
GraphicsDevice
.
@NotNull private final java.awt.GraphicsEnvironment graphicsEnvironment
GraphicsEnvironment
.
@NotNull private final GuiAutoCloseListener guiAutoCloseListener
GuiAutoCloseListener
used to track auto-closing dialogs.
private volatile boolean inhibitPaintIconified
private volatile boolean inhibitPaintMapUpdate
private boolean isFullScreen
@NotNull private final java.awt.event.MouseListener mouseTracker
MouseTracker
instance.
private int offsetH
private int offsetW
private int offsetX
private int offsetY
@NotNull private final java.util.concurrent.CopyOnWriteArrayList<Gui> openDialogs
private boolean openDialogsChanged
openDialogs
has changed.
@NotNull private final java.lang.Object redrawSemaphore
@NotNull private RendererGuiState rendererGuiState
@NotNull private final java.util.Collection<RendererGuiStateListener> rendererGuiStateListeners
rendererGuiState
changes.
@NotNull private final java.text.DateFormat simpleDateFormat
private volatile boolean skippedPaint
redrawGUI()
has been dropped while
inhibitPaintMapUpdate
or inhibitPaintIconified
was
set.
@NotNull private final javax.swing.Timer timer
@Nullable private GUIElement tooltip
null
if no tooltips should be shown.
private boolean wasDisplayed
frame
has been displayed before.
private int windowHeight
private int windowWidth
Constructor Detail |
---|
public JXCWindowRenderer(@NotNull java.awt.event.MouseListener mouseTracker, @NotNull java.lang.Object redrawSemaphore, @NotNull CrossfireServerConnection crossfireServerConnection, @Nullable java.io.Writer debugScreen)
mouseTracker
- the mouse tracker instanceredrawSemaphore
- the semaphore used to synchronized map model
updates and map view redrawscrossfireServerConnection
- the server connection to monitordebugScreen
- the writer to write screen debug to or
null
Method Detail |
---|
@Nullable public GUIText activateCommandInput()
null
if no command
input text field existspublic void addGuiStateListener(@NotNull RendererGuiStateListener listener)
rendererGuiState
changes.
listener
- the listener to addpublic void clearGUI(@NotNull Gui gui)
gui
- the gui to setpublic void closeDialog(@NotNull Gui dialog)
dialog
- the dialog to closepublic boolean deactivateCommandInput()
private void debugScreenWrite(@NotNull java.lang.CharSequence message)
message
- the message to writepublic void endRendering()
@Nullable public GUIElement 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 process
null
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 instance
null
@NotNull public RendererGuiState getGuiState()
@NotNull private java.awt.Dimension getMaxWindowDimension(@NotNull java.awt.Insets frameInsets)
frameInsets
- the frame's insets
public int getOffsetX()
public int getOffsetY()
@NotNull public java.lang.Iterable<Gui> getOpenDialogs()
public int getWindowHeight()
public int getWindowWidth()
public boolean handleKeyPress(@NotNull java.awt.event.KeyEvent e)
public boolean handleKeyTyped(@NotNull java.awt.event.KeyEvent e)
public boolean isDialogOpen(@NotNull Gui dialog)
dialog
- the dialog to check
@Nullable private GUIElement manageMouseEvents(@NotNull Gui gui, @NotNull java.awt.event.MouseEvent e)
private boolean needRedraw()
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 open
false
if
the dialog already was opened as the topmost dialogprivate 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 dialog
public 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)
private void redrawGUI()
private void redrawGUIBasic(@NotNull java.awt.Graphics g)
private void redrawGUIDialog(@NotNull java.awt.Graphics g)
private void redrawTooltip(@NotNull java.awt.Graphics g)
public void repaint()
public void setCurrentGui(@NotNull Gui gui)
Gui
to display.
gui
- the gui to displaypublic boolean setFullScreenMode(@NotNull java.awt.Frame frame, @Nullable Resolution resolution)
frame
- the associated frameresolution
- the resolution to switch to; null
to keep
current resolution
public void setGuiState(@NotNull RendererGuiState rendererGuiState)
rendererGuiState
- the gui statepublic void setInhibitPaintIconified(boolean inhibitPaintIconified)
inhibitPaintIconified
- whether the main window is iconifiedprivate 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 GUIElement tooltip)
null
if no tooltips should be
shown.
tooltip
- the tooltip to use, or null
public void setWindowMode(@NotNull java.awt.Frame 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 sizeprivate void showDialog(@NotNull Gui dialog)
dialog
- the dialog to showpublic void showDialog(@NotNull Gui dialog, int x, int y)
dialog
- the dialog to showx
- the dialog's x coordinatey
- the dialog's y coordinatepublic void showDialogAuto(@NotNull Gui dialog)
dialog
- the dialog to showpublic void start()
public void stop()
public boolean toggleDialog(@NotNull Gui dialog)
dialog
- the dialog to toggle
public void updateWindowSize(int windowWidth, int windowHeight)
windowWidth
- the window width including insetswindowHeight
- the window height including insets