22 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;
126 private final JFrame
frame =
new JFrame(
"");
140 @SuppressWarnings(
"FieldCanBeLocal")
144 public void windowLostFocus(
final WindowEvent e) {
157 public void delinvReceived(
final int tag) {
162 public void delitemReceived(@NotNull
final int[] tags) {
167 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) {
172 public void playerReceived(
final int tag,
final int weight,
final int faceNum, @NotNull
final String name) {
174 SwingUtilities.invokeLater(
new Runnable() {
185 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) {
195 @SuppressWarnings(
"FieldCanBeLocal")
199 public void windowClosing(@NotNull
final WindowEvent e) {
206 public void windowClosed(@NotNull
final WindowEvent e) {
207 if (!frame.isVisible()) {
218 @SuppressWarnings(
"FieldCanBeLocal")
222 public void keyTyped(@NotNull
final KeyEvent e) {
227 public void keyPressed(@NotNull
final KeyEvent e) {
232 public void keyReleased(@NotNull
final KeyEvent e) {
246 public void commandQueryReceived(@NotNull
final String prompt,
final int queryType) {
247 SwingUtilities.invokeLater(
new Runnable() {
264 @SuppressWarnings(
"FieldCanBeLocal")
268 public void start() {
277 public void metaserver() {
283 public void preConnecting(@NotNull
final String serverInfo) {
288 public void connecting(@NotNull
final String serverInfo) {
299 public void connected() {
304 public void connectFailed(@NotNull
final String reason) {
315 @SuppressWarnings(
"FieldCanBeLocal")
319 public void replySent() {
329 @SuppressWarnings(
"FieldCanBeLocal")
333 public void manageAccount() {
335 SwingUtilities.invokeLater(
new Runnable() {
347 SwingUtilities.invokeLater(
new Runnable() {
359 public void startAccountList(@NotNull
final String accountName) {
360 SwingUtilities.invokeLater(
new Runnable() {
372 public void endAccountList(
final int count) {
373 SwingUtilities.invokeLater(
new Runnable() {
385 public void startPlaying() {
387 SwingUtilities.invokeLater(
new Runnable() {
398 public void selectCharacter(@NotNull
final String accountName, @NotNull
final String characterName) {
399 SwingUtilities.invokeLater(
new Runnable() {
433 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
436 }
catch (
final IOException ex) {
437 System.err.println(
"Cannot find application icon: "+ex.getMessage());
439 frame.setFocusTraversalKeysEnabled(
false);
442 frame.addComponentListener(
new ComponentListener() {
445 public void componentResized(
final ComponentEvent e) {
446 final int width =
frame.getContentPane().getWidth();
447 final int height =
frame.getContentPane().getHeight();
448 guiManager.updateWindowSize(width, height);
452 public void componentMoved(
final ComponentEvent e) {
457 public void componentShown(
final ComponentEvent e) {
462 public void componentHidden(
final ComponentEvent e) {
471 connection.setFrame(
frame);
481 public void init(@Nullable
final Resolution resolution, @NotNull
final String skinName,
final boolean fullScreen, @NotNull
final SkinLoader skinLoader) {
484 skin = skinLoader.loadSkin(skinName);
487 System.err.println(
"cannot load skin "+skinName+
": "+ex.getMessage());
491 System.err.println(
"cannot load skin "+skinName+
": "+ex.getMessage()+
", trying default skin");
495 System.err.println(
"cannot load default skin "+
Options.
DEFAULT_SKIN+
": "+ex2.getMessage());
497 throw new AssertionError(ex2);
505 final Dimension minSize = minResolution.
asDimension();
507 final Insets insets =
frame.getInsets();
508 minSize.width += insets.left+insets.right;
509 minSize.height += insets.top+insets.bottom;
510 maxSize.width += insets.left+insets.right;
511 maxSize.height += insets.top+insets.bottom;
512 frame.setMinimumSize(minSize);
513 frame.setMaximumSize(maxSize);
void addCrossfireUpdateItemListener(@NotNull CrossfireUpdateItemListener crossfireUpdateItemListener)
Adds a listener to be notified about item changes.
void selectCharacter(@NotNull final String accountName, @NotNull final String characterName)
Updates the selected character name in an account.
boolean setFullScreenMode(@NotNull final JFrame frame, @Nullable final Resolution resolution)
Tries to switch to the given resolution.
Interface for listeners interested gui state changes.
final WindowFocusListener windowFocusListener
The WindowFocusListener registered for this window.
Maintains the current GuiState.
void setKeyBindings(@NotNull final KeyBindings keyBindings)
Sets the active KeyBindings.
static final String APPLICATION_ICON
The resource name for the application icon.
void removeCrossfireUpdateItemListener(@NotNull CrossfireUpdateItemListener crossfireUpdateItemListener)
Removes a listener to be notified about item changes.
void keyPressed(@NotNull final KeyEvent e)
Handles a "key pressed" event.
final KeyListener keyListener
The KeyListener attached to the main window.
void setAccountName(@NotNull final String accountName)
Updates the current account name.
void updateWindowSize(final int width, final int height)
Sets a new window size.
final GuiManager guiManager
The GuiManager for controlling the main GUI state.
static final boolean DISABLE_START_GUI
TODO: Remove when more options are implemented in the start screen gui.
boolean stopRunning()
Tells the server to stop running.
KeyBindings getDefaultKeyBindings()
Returns the default key bindings for this skin.
Dimension asDimension()
Returns the resolution as a Dimension instance.
Maintains a set of named options.
boolean equals(@Nullable final Object obj)
void hideAccountWindows()
Hides all account-related windows.
Resolution getMaxResolution()
Returns the maximal resolution of this skin.
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.
final OptionManager optionManager
The option manager for this window.
void openQueryDialog(@NotNull final String prompt, final int queryType)
Opens the "query" dialog.
static ImageIcon loadImage(@NotNull final String name)
Loads an image file.
Defines a JXClient skin consisting of a main Gui and zero or more dialog Guis.
Utility class to store or restore the dialog states to/from a file.
Listener for classes interested in sent "reply" commands.
void commit()
Finishes an update transaction.
void term()
Frees all resources.
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)
Creates a new instance.
Renders a Gui instance into a Frame.
void setSkin(@NotNull final JXCSkin skin)
Sets a new skin.
void setWindowMode(@NotNull final JFrame frame, @Nullable final Resolution resolution, @NotNull final Resolution minResolution, final boolean fixedSize)
Tries to switch to the given resolution.
Utility class for loading information from resources.
boolean openQuitDialog()
Opens the "quit" dialog.
final CrossfireServerConnection server
The CrossfireServerConnection to use.
final CommandQueue commandQueue
The command queue instance for this window.
Maintains the application's main GUI state.
Handles keyboard input processing.
void loadOptions()
Loads all options' states from the backing settings instance.
void term()
Terminates the GUI.
Interface for listeners interested in account information related messages received from the Crossfir...
final SentReplyListener sentReplyListener
The SentReplyListener for detecting "reply" commands sent to the server.
void unsetSkin()
Unsets the current skin.
final KeyHandler keyHandler
The KeyHandler for processing keyboard input.
Maintains the character list for an account.
static void load(@NotNull final JXCSkin skin, @NotNull final JXCWindowRenderer windowRenderer)
Loads the dialogs state from a file.
void begin()
Starts an update transaction.
final CrossfireAccountListener accountListener
The CrossfireAccountListener attached to server.
void init(@Nullable final Resolution resolution, @NotNull final String skinName, final boolean fullScreen, @NotNull final SkinLoader skinLoader)
Initializes the instance: loads and displays the skin.
void terminate()
Terminates the application.
void playerReceived()
A "player" protocol command has been received.
final Exiter exiter
The Exiter to use.
Exception thrown if a skin related problem occurs.
Allows to exit the application.
final WindowListener windowListener
The window listener attached to this frame.
void addCrossfireQueryListener(@NotNull CrossfireQueryListener listener)
Adds a new listener monitoring the query S->C messages.
final CrossfireQueryListener crossfireQueryListener
The CrossfireQueryListener attached to server.
Adds encoding/decoding of crossfire protocol packets to a ServerConnection.
void saveOptions()
Saves all options' states to the backing settings instance.
Maintains the pending (ncom) commands sent to the server.
void showCharacters(final int count)
Displays the window with the characters for an account.
final JFrame frame
The main window.
Information about JXClient's screen/window resolution.
Loader for JXCSkins and attaching them to the client.
void closeQueryDialog()
Closes the "query" dialog.
Command line argument parser.
final JXCWindowRenderer windowRenderer
The JXCWindowRenderer for this window.
Interface for listeners interested in query messages received from the Crossfire server.
final CharacterModel characterModel
The CharacterModel to update.
Connection progress states of the Crossfire server connection.
void add(@NotNull final CharacterInformation characterInformation)
Adds an entry.
final CrossfireUpdateItemListener crossfireUpdateItemListener
The CrossfireUpdateItemListener to receive item updates.
void manageAccount()
Displays the main account dialog, to let the player login or create a new account.
void keyReleased(@NotNull final KeyEvent e)
Handles a "key released" event.
void removeCrossfireQueryListener(@NotNull CrossfireQueryListener listener)
Removes the given listener from the list of objects listening to the query S->C messages.
Interface for listeners interested in item related commands.
static final String DEFAULT_SKIN
The default skin name.
Resolution getMinResolution()
Returns the minimal resolution of this skin.