Class GUI

java.lang.Object
  extended by java.awt.event.WindowAdapter
      extended by GUI
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.WindowFocusListener, java.awt.event.WindowListener, java.awt.event.WindowStateListener, java.util.EventListener

public class GUI
extends java.awt.event.WindowAdapter
implements java.awt.event.ActionListener, java.awt.event.MouseListener

The GUI class contains all the Swing components that comprise the SARJ Graphical User Interface


Field Summary
static boolean STATE_CONNECTED
           
static boolean STATE_DISCONNECTED
           
 
Constructor Summary
GUI(java.lang.String configFilePath, GUIListener listener)
          Creates a new GUI object.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Called as a result of implementing ActionListener
 void addPlayer(java.lang.String name, int score, int deaths, java.lang.String ratio, int ping, int team, java.lang.String ip, int num)
          Adds details of a player to the player table.
 void addQuickButton(java.lang.String name, java.lang.String command)
          Adds a new button to the QuickButton panel
 void addTeam(java.lang.String name, int score, int kills, int deaths, int ping)
          Adds details of a team to the team table.
 void clearConsole()
          Clears the connection console
 void clearPlayerTable()
          Clears the table containing the list of currently connected players
 void clearTeamTable()
          Clears the table containing details of each team
 void connected()
          Updates the GUI components to show that the user is connected.
 void disconnected()
          Updates the GUI components to show that the user is disconnected.
 java.lang.String getIPField()
          Returns the current value stored in the IP address field on the main window
 javax.swing.JFrame getMainFrame()
          Returns the GUI's main window frame
 java.lang.String getPasswordField()
          Returns the current value stored in the password field on the main window
 java.lang.String getPortField()
          Returns the current value stored in the port field on the main window
 QuickButton[] getQuickButtons()
          Returns the buttons on the QuickButton panel
 void hide()
          Hide the GUI
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void removeQuickButton(java.lang.String name)
          Removes a button from the QuickButton panel
 void setAutoRefresh(boolean refresh)
          Sets the automatic refresh timer to on or off
 void setGameType(java.lang.String gameType)
          Sets the game type label on the main window to the one specified
 void setIPField(java.lang.String ip)
          Sets the server address text field on the main window to the one specified
 void setMapName(java.lang.String mapName)
          Sets the map name label on the main window to the one specified
 void setPortField(java.lang.String port)
          Sets the port number text field on the main window to the one specified
 void setRefreshDelay(int delay)
          Sets the delay of the refresh timer for refreshing the player details
 void setScoreLimit(java.lang.String limit)
          Sets the score limit label on the main window to the one specified
 void setTitle(java.lang.String title)
          Sets the window title of the GUI
 void show()
          Display the GUI
 void startRefreshTimer(int delay)
          Starts the automatic refresh timer with the specified millisecond delay
 void stopRefreshTimer()
          Stops the automatic refresh timer
 void windowClosing(java.awt.event.WindowEvent e)
          Called when the main window is being closed
 void writeToConsole(java.lang.String text)
          Writes the specified string of text to the main console
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_CONNECTED

public static final boolean STATE_CONNECTED
See Also:
Constant Field Values

STATE_DISCONNECTED

public static final boolean STATE_DISCONNECTED
See Also:
Constant Field Values
Constructor Detail

GUI

public GUI(java.lang.String configFilePath,
           GUIListener listener)
Creates a new GUI object. The exact appearance of the GUI may change based on the settings within the provided configuration file

Parameters:
configFilePath - the path of the SARJ configuration file (e.g. config.txt)
listener - the object to receive events generated by the GUI
Method Detail

show

public void show()
Display the GUI


hide

public void hide()
Hide the GUI


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called as a result of implementing ActionListener

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the object containing details of the event

setRefreshDelay

public void setRefreshDelay(int delay)
Sets the delay of the refresh timer for refreshing the player details

Parameters:
delay - the time to delay, in milliseconds

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

setTitle

public void setTitle(java.lang.String title)
Sets the window title of the GUI

Parameters:
title - the name of the new title for the window

setIPField

public void setIPField(java.lang.String ip)
Sets the server address text field on the main window to the one specified

Parameters:
ip - the server address to set the text field to

setPortField

public void setPortField(java.lang.String port)
Sets the port number text field on the main window to the one specified

Parameters:
port - the port number to set the text field to

setAutoRefresh

public void setAutoRefresh(boolean refresh)
Sets the automatic refresh timer to on or off

Parameters:
refresh - true or false to set the timer to on or off, respectively

setMapName

public void setMapName(java.lang.String mapName)
Sets the map name label on the main window to the one specified

Parameters:
mapName - the name of the map to set the field to

setGameType

public void setGameType(java.lang.String gameType)
Sets the game type label on the main window to the one specified

Parameters:
gameType - the name of the game type to set the field to (e.g. Deathmatch, CTF, etc)

setScoreLimit

public void setScoreLimit(java.lang.String limit)
Sets the score limit label on the main window to the one specified

Parameters:
limit - the score limit to set the field to

clearConsole

public void clearConsole()
Clears the connection console


clearPlayerTable

public void clearPlayerTable()
Clears the table containing the list of currently connected players


clearTeamTable

public void clearTeamTable()
Clears the table containing details of each team


addPlayer

public void addPlayer(java.lang.String name,
                      int score,
                      int deaths,
                      java.lang.String ratio,
                      int ping,
                      int team,
                      java.lang.String ip,
                      int num)
Adds details of a player to the player table. This should be done for each connected player after clearing the old details from the table with the clearPlayerTable method

Parameters:
name - the name of the player
score - the player's score
deaths - the player's number of deaths
ratio - the player's kill-to-death ratio (Infinity should be represented as '*'
ping - the player's ping
team - the player's current team number, where 1 = alpha, 2 = beta, 3 = charlie and 4 = delta
ip - the player's IP address
num - the player's unique in-game ID, as assigned by the server
See Also:
clearPlayerTable()

addTeam

public void addTeam(java.lang.String name,
                    int score,
                    int kills,
                    int deaths,
                    int ping)
Adds details of a team to the team table. This should be done for each team, when applicable, after clearing the old details from the table with the clearTeamTable method

Parameters:
name - the name of the team (e.g. Alpha, Beta, Charlie, Delta)
score - the team's total score
kills - the total number of kills made by players on the team
deaths - the total number of deaths made by the players on the team
ping - the average player ping of the team

getMainFrame

public javax.swing.JFrame getMainFrame()
Returns the GUI's main window frame

Returns:
a JFrame object containing the main window frame

getIPField

public java.lang.String getIPField()
Returns the current value stored in the IP address field on the main window

Returns:
a String object containing the value of the IP address field

getPortField

public java.lang.String getPortField()
Returns the current value stored in the port field on the main window

Returns:
a String object containing the value of the port field

getPasswordField

public java.lang.String getPasswordField()
Returns the current value stored in the password field on the main window

Returns:
a String object containing the unmasked value of the password field

windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Called when the main window is being closed

Specified by:
windowClosing in interface java.awt.event.WindowListener
Overrides:
windowClosing in class java.awt.event.WindowAdapter
Parameters:
e - the object containing data of the activating window event

writeToConsole

public void writeToConsole(java.lang.String text)
Writes the specified string of text to the main console

Parameters:
text - the string of text to be printed

startRefreshTimer

public void startRefreshTimer(int delay)
Starts the automatic refresh timer with the specified millisecond delay

Parameters:
delay - the timer delay, in milliseconds

stopRefreshTimer

public void stopRefreshTimer()
Stops the automatic refresh timer


connected

public void connected()
Updates the GUI components to show that the user is connected. This should be called whenever a connection is successfully established to a server


disconnected

public void disconnected()
Updates the GUI components to show that the user is disconnected. This should be called whenever a connection to a server is closed


addQuickButton

public void addQuickButton(java.lang.String name,
                           java.lang.String command)
Adds a new button to the QuickButton panel

Parameters:
name - the name of the button. This will also appear as the button caption
command - the command string associated with the button, to be executed when it is activated

removeQuickButton

public void removeQuickButton(java.lang.String name)
Removes a button from the QuickButton panel

Parameters:
name - the name of the button to remove (the caption of the button)

getQuickButtons

public QuickButton[] getQuickButtons()
Returns the buttons on the QuickButton panel

Returns:
an array of the QuickButton objects currently on the panel