sarj
Class GUI

java.lang.Object
  extended by java.awt.event.WindowAdapter
      extended by sarj.GUI
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.KeyListener, 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, java.awt.event.KeyListener

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, java.lang.String scriptSettingsFilePath, java.lang.String scriptButtonSettingsFileLocation, 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 addScriptButton(java.lang.String name, java.lang.String command)
          Adds a new button to the ScriptButton panel
 void addTeam(java.lang.String name, int score, int kills, int deaths, int ping)
          Adds details of a team to the team table.
 java.lang.String[] checkTimedScripts(long timePassed)
          Checks all of the timed scripts to see if any should run
 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 getCommandBox()
          Returns the value of the command combo box field on the main window
 java.lang.String getFilenameForEvent(java.lang.String eventName)
          Returns the name of the file to execute for the specified event
 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.Object[][] getPlayerData()
          Returns all the data in the player table
 java.lang.Object[] getPlayerData(java.lang.String playerName)
          Returns the row of the player table with the player name matching that provided
 java.lang.String getPortField()
          Returns the current value stored in the port field on the main window
 ScriptButton[] getScriptButtons()
          Returns the buttons on the ScriptButton panel
 java.lang.Object[][] getTeamData()
          Returns all the data in the team table
 java.lang.Object[] getTeamData(java.lang.String teamName)
          Returns the row of the team table with the team name matching that provided
 void hide()
          Hide the GUI
 boolean isEventEnabled(java.lang.String eventName)
          Returns whether or not the specified event is enabled
 void keyPressed(java.awt.event.KeyEvent e)
          Called as a result of implementing KeyListener
 void keyReleased(java.awt.event.KeyEvent e)
          Called as a result of implementing KeyListener
 void keyTyped(java.awt.event.KeyEvent e)
          Called as a result of implementing KeyListener
 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)
           
static void printError(java.lang.String errorString)
          Displays error messages in the log console
 void removeScriptButton(java.lang.String name)
          Removes a button from the ScriptButton panel
 void setAutoRefresh(boolean refresh)
          Sets the automatic refresh timer to on or off
 void setCommandBox(java.lang.String command)
          Sets the command combo box field on the main window to the specified string
 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 setPasswordField(java.lang.String password)
          Sets the password field on the main window to the specified string
 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 scoreLimit)
          Sets the score limit label on the main window to the one specified
 void setTimeLeft(java.lang.String timeLeft)
          Sets the time left label on the main window to the one specified
 void setTimeLimit(java.lang.String timeLimit)
          Sets the time 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,
           java.lang.String scriptSettingsFilePath,
           java.lang.String scriptButtonSettingsFileLocation,
           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


printError

public static void printError(java.lang.String errorString)
Displays error messages in the log console

Parameters:
errorString - the error message to display

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

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Called as a result of implementing KeyListener

Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - object containing details of the key event

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Called as a result of implementing KeyListener

Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - object containing details of the key event

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Called as a result of implementing KeyListener

Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - object containing details of the key 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

setPasswordField

public void setPasswordField(java.lang.String password)
Sets the password field on the main window to the specified string

Parameters:
password - the password to set

setCommandBox

public void setCommandBox(java.lang.String command)
Sets the command combo box field on the main window to the specified string

Parameters:
command - the command to set the combo box to

getCommandBox

public java.lang.String getCommandBox()
Returns the value of the command combo box field on the main window

Returns:
the value of the command combo box

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 scoreLimit)
Sets the score limit label on the main window to the one specified

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

setTimeLimit

public void setTimeLimit(java.lang.String timeLimit)
Sets the time limit label on the main window to the one specified

Parameters:
timeLimit - the time limit to set the field to

setTimeLeft

public void setTimeLeft(java.lang.String timeLeft)
Sets the time left label on the main window to the one specified

Parameters:
timeLeft - the time 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


addScriptButton

public void addScriptButton(java.lang.String name,
                            java.lang.String command)
Adds a new button to the ScriptButton 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

removeScriptButton

public void removeScriptButton(java.lang.String name)
Removes a button from the ScriptButton panel

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

getScriptButtons

public ScriptButton[] getScriptButtons()
Returns the buttons on the ScriptButton panel

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

getFilenameForEvent

public java.lang.String getFilenameForEvent(java.lang.String eventName)
                                     throws EventNotFoundException
Returns the name of the file to execute for the specified event

Parameters:
eventName - the name of the event
Returns:
the file path of the script to execute
Throws:
EventNotFoundException - if the event isn't found

isEventEnabled

public boolean isEventEnabled(java.lang.String eventName)
                       throws EventNotFoundException
Returns whether or not the specified event is enabled

Parameters:
eventName - the name of the event
Returns:
true if the event is enabled, or false other wise
Throws:
EventNotFoundException - if the event isn't found

getPlayerData

public java.lang.Object[] getPlayerData(java.lang.String playerName)
Returns the row of the player table with the player name matching that provided

Parameters:
playerName - the name of the player to match
Returns:
the data contained in the table relating to the player

getPlayerData

public java.lang.Object[][] getPlayerData()
Returns all the data in the player table

Returns:
a 2D array of objects containing the fields of the player table

getTeamData

public java.lang.Object[] getTeamData(java.lang.String teamName)
Returns the row of the team table with the team name matching that provided

Parameters:
teamName - the name of the team to match
Returns:
the data contained in the table relating to the team

getTeamData

public java.lang.Object[][] getTeamData()
Returns all the data in the team table

Returns:
a 2D array of objects containing the fields of the team table

checkTimedScripts

public java.lang.String[] checkTimedScripts(long timePassed)
Checks all of the timed scripts to see if any should run

Parameters:
timePassed - the time passed, in milliseconds, since the last call to this function
Returns:
an array of String objects containing the filenames of the scripts to be executed