 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
23 package com.realtime.crossfire.jxclient.main;
45 import java.awt.Dimension;
46 import java.awt.Insets;
47 import java.awt.event.ComponentEvent;
48 import java.awt.event.ComponentListener;
49 import java.awt.event.KeyEvent;
50 import java.awt.event.KeyListener;
51 import java.awt.event.WindowAdapter;
52 import java.awt.event.WindowEvent;
53 import java.awt.event.WindowFocusListener;
54 import java.awt.event.WindowListener;
55 import java.io.IOException;
56 import javax.swing.JFrame;
57 import javax.swing.SwingUtilities;
58 import javax.swing.WindowConstants;
59 import org.jetbrains.annotations.NotNull;
60 import org.jetbrains.annotations.Nullable;
120 private final JFrame
frame =
new JFrame(
"");
134 @SuppressWarnings(
"FieldCanBeLocal")
138 @SuppressWarnings(
"MethodDoesntCallSuperMethod")
139 public void windowLostFocus(
final WindowEvent e) {
154 public void delinvReceived(
final int tag) {
159 public void delitemReceived(
final int @NotNull [] tags) {
164 public void addItemReceived(
final int location,
final int tag,
final int flags,
final int weight,
final int faceNum, @NotNull
final String name, @NotNull
final String namePl,
final int anim,
final int animSpeed,
final int nrof,
final int type) {
169 public void playerReceived(
final int tag,
final int weight,
final int faceNum, @NotNull
final String name) {
170 SwingUtilities.invokeLater(guiManager::playerReceived);
174 public void upditemReceived(
final int flags,
final int tag,
final int valLocation,
final int valFlags,
final int valWeight,
final int valFaceNum, @NotNull
final String valName, @NotNull
final String valNamePl,
final int valAnim,
final int valAnimSpeed,
final int valNrof) {
184 @SuppressWarnings(
"FieldCanBeLocal")
188 @SuppressWarnings(
"MethodDoesntCallSuperMethod")
189 public void windowClosing(@NotNull
final WindowEvent e) {
196 @SuppressWarnings(
"MethodDoesntCallSuperMethod")
197 public void windowClosed(@NotNull
final WindowEvent e) {
198 if (!
frame.isVisible()) {
209 @SuppressWarnings(
"FieldCanBeLocal")
213 public void keyTyped(@NotNull
final KeyEvent e) {
218 public void keyPressed(@NotNull
final KeyEvent e) {
223 public void keyReleased(@NotNull
final KeyEvent e) {
237 public void commandQueryReceived(@NotNull
final String prompt,
final int queryType) {
248 @SuppressWarnings(
"FieldCanBeLocal")
252 public void start() {
261 public void metaserver() {
267 public void preConnecting(@NotNull
final String serverInfo) {
272 public void connecting(@NotNull
final String serverInfo) {
278 public void connecting(@NotNull
final ClientSocketState clientSocketState, @NotNull
final String param) {
283 public void connected() {
288 public void connectFailed(@NotNull
final String reason) {
299 @SuppressWarnings(
"FieldCanBeLocal")
303 public void markSent(
final int tag) {
308 public void replySent() {
318 @SuppressWarnings(
"FieldCanBeLocal")
322 public void manageAccount() {
323 SwingUtilities.invokeLater(guiManager::manageAccount);
332 public void startAccountList(@NotNull
final String accountName) {
333 SwingUtilities.invokeLater(() -> {
340 public void endAccountList(
final int count) {
341 SwingUtilities.invokeLater(() -> {
348 public void startPlaying() {
349 SwingUtilities.invokeLater(guiManager::hideAccountWindows);
353 public void selectCharacter(@NotNull
final String accountName, @NotNull
final String characterName) {
375 public JXCWindow(@NotNull
final Exiter exiter, @NotNull
final CrossfireServerConnection server, @NotNull
final OptionManager optionManager, @NotNull
final GuiStateManager guiStateManager, @NotNull
final JXCWindowRenderer windowRenderer, @NotNull
final CommandQueue commandQueue, @NotNull
final GuiManager guiManager, @NotNull
final KeyHandler keyHandler, @NotNull
final CharacterModel characterModel, @NotNull
final JXCConnection connection, @Nullable
final Resolution resolution,
final boolean fullScreen, @NotNull
final JXCSkin skin) {
383 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
386 }
catch (
final IOException ex) {
387 System.err.println(
"Cannot find application icon: "+ex.getMessage());
389 frame.setFocusTraversalKeysEnabled(
false);
392 frame.addComponentListener(
new ComponentListener() {
395 public void componentResized(
final ComponentEvent e) {
396 final int width =
frame.getContentPane().getWidth();
397 final int height =
frame.getContentPane().getHeight();
402 public void componentMoved(
final ComponentEvent e) {
407 public void componentShown(
final ComponentEvent e) {
412 public void componentHidden(
final ComponentEvent e) {
421 connection.setFrame(
frame);
427 final Resolution minResolution = skin.getMinResolution();
428 final Dimension minSize = minResolution.
asDimension();
429 final Dimension maxSize = skin.getMaxResolution().asDimension();
430 final Insets insets =
frame.getInsets();
431 minSize.width += insets.left+insets.right;
432 minSize.height += insets.top+insets.bottom;
433 maxSize.width += insets.left+insets.right;
434 maxSize.height += insets.top+insets.bottom;
435 frame.setMinimumSize(minSize);
436 frame.setMaximumSize(maxSize);
438 if (!fullScreen || !windowRenderer.setFullScreenMode(
frame, resolution)) {
439 windowRenderer.setWindowMode(
frame, resolution, minResolution, minSize.
equals(maxSize));
static void load(@NotNull final JXCSkin skin, @NotNull final JXCWindowRenderer windowRenderer)
Loads the dialogs state from a file.
void showCharacters(final int count)
Displays the window with the characters for an account.
final WindowListener windowListener
The window listener attached to this frame.
final KeyHandler keyHandler
The KeyHandler for processing keyboard input.
void term()
Frees all resources.
void selectCharacter(@NotNull final String accountName, @NotNull final String characterName)
Updates the selected character name in an account.
void setDefaultKeyBindings(@NotNull final KeyBindings defaultKeyBindings)
Sets the default KeyBindings of the currently active skin.
void saveOptions()
Saves all options' states to the backing settings instance.
final WindowFocusListener windowFocusListener
The WindowFocusListener registered for this window.
Handles keyboard input processing.
void removeCrossfireQueryListener(@NotNull CrossfireQueryListener listener)
Removes the given listener from the list of objects listening to the query S->C messages.
static ImageIcon loadImage(@NotNull final String name)
Loads an image file.
final Exiter exiter
The Exiter to use.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
boolean equals(@Nullable final Object obj)
void loadOptions()
Loads all options' states from the backing settings instance.
static final String APPLICATION_ICON
The resource name for the application icon.
Maintains the application's main GUI state.
JXCWindow(@NotNull final Exiter exiter, @NotNull final CrossfireServerConnection server, @NotNull final OptionManager optionManager, @NotNull final GuiStateManager guiStateManager, @NotNull final JXCWindowRenderer windowRenderer, @NotNull final CommandQueue commandQueue, @NotNull final GuiManager guiManager, @NotNull final KeyHandler keyHandler, @NotNull final CharacterModel characterModel, @NotNull final JXCConnection connection, @Nullable final Resolution resolution, final boolean fullScreen, @NotNull final JXCSkin skin)
Creates a new instance.
Allows to exit the application.
void setSkin(@NotNull final JXCSkin skin)
Sets a new skin.
void commit()
Finishes an update transaction.
Interface for listeners interested in account information related messages received from the Crossfir...
final CommandQueue commandQueue
The command queue instance for this window.
void openQueryDialog(@NotNull final String prompt, final int queryType)
Opens the "query" dialog.
Interface for listeners interested gui state changes.
void begin()
Starts an update transaction.
void terminate()
Terminates the application.
void updateWindowSize(final int width, final int height)
Sets a new window size.
final CrossfireUpdateItemListener crossfireUpdateItemListener
The CrossfireUpdateItemListener to receive item updates.
final KeyListener keyListener
The KeyListener attached to the main window.
Maintains the character list for an account.
boolean openQuitDialog()
Opens the "quit" dialog.
Dimension asDimension()
Returns the resolution as a Dimension instance.
Listener for classes interested in commands sent to the Crossfire server.
final SentPacketListener sentPacketListener
The SentPacketListener for detecting commands sent to the server.
Maintains the current GuiState.
void addCrossfireQueryListener(@NotNull CrossfireQueryListener listener)
Adds a new listener monitoring the query S->C messages.
Maintains a set of named options.
void add(@NotNull final CharacterInformation characterInformation)
Adds an entry.
boolean isRunningUsingCtrl
Whether the player is running because she is using the Ctrl key or not.
boolean stopRunning()
Tells the server to stop running.
Utility class to store or restore the dialog states to/from a file.
final CrossfireQueryListener crossfireQueryListener
The CrossfireQueryListener attached to server.
Renders a Gui instance into a Frame.
void unsetSkin()
Unsets the current skin.
Interface for listeners interested in query messages received from the Crossfire server.
final GuiManager guiManager
The GuiManager for controlling the main GUI state.
Information about JXClient's screen/window resolution.
final CrossfireServerConnection server
The CrossfireServerConnection to use.
void addSentPacketListener(@NotNull SentPacketListener listener)
Adds a listener to be notified about sent reply packets.
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.
static final boolean DISABLE_START_GUI
TODO: Remove when more options are implemented in the start screen gui.
void removeCrossfireUpdateItemListener(@NotNull CrossfireUpdateItemListener crossfireUpdateItemListener)
Removes a listener to be notified about item changes.
void closeQueryDialog()
Closes the "query" dialog.
void addCrossfireUpdateItemListener(@NotNull CrossfireUpdateItemListener crossfireUpdateItemListener)
Adds a listener to be notified about item changes.
Interface for listeners interested in item related commands.
final CharacterModel characterModel
The CharacterModel to update.
void addCrossfireAccountListener(@NotNull CrossfireAccountListener listener)
Adds a listener to be notified about account events.
void keyReleased(@NotNull final KeyEvent e)
Handles a "key released" event.
void keyPressed(@NotNull final KeyEvent e)
Handles a "key pressed" event.
void term()
Terminates the GUI.
Defines a JXClient skin consisting of a main Gui and zero or more dialog Guis.
final OptionManager optionManager
The option manager for this window.
final JFrame frame
The main window.
final CrossfireAccountListener accountListener
The CrossfireAccountListener attached to server.
Connection progress states of the Crossfire server connection.
Utility class for loading information from resources.
Maintains the pending (ncom) commands sent to the server.
void setAccountName(@NotNull final String accountName)
Updates the current account name.