sarj
Class Sarj

java.lang.Object
  extended by java.awt.event.WindowAdapter
      extended by sarj.Sarj
All Implemented Interfaces:
java.awt.event.WindowFocusListener, java.awt.event.WindowListener, java.awt.event.WindowStateListener, java.lang.Runnable, java.util.EventListener, ConnectionListener, GUIListener, ScriptingFacade

public class Sarj
extends java.awt.event.WindowAdapter
implements java.lang.Runnable, GUIListener, ConnectionListener, ScriptingFacade

The main SARJ application class


Field Summary
static javax.swing.ImageIcon CANCEL_ICON
           
static javax.swing.ImageIcon OK_ICON
           
 
Constructor Summary
Sarj()
           
 
Method Summary
 void clearConsole()
          Clears the console on the main window
 void connectClient()
          Connects the client to the IP and port displayed on the main window
 void connectClient(java.lang.String ip, int port)
          Connects the client to the specified IP and port
 void disconnectClient()
          Disconnects the client from any connected server
 void dispatchScript(java.lang.String scriptFile)
          Runs the specified script file
static java.lang.String formatTime(int seconds)
          Formats seconds into mm:ss format
 java.lang.String getCommandBox()
          Returns the value of the command combo box on the main window
 java.lang.String getCurrentMap()
          Returns the name of the map currently being played on the server
 java.lang.String getGameType()
          Returns the type of game running on the server
 java.lang.String getIPField()
          Returns the value of the IP field on the main window
 int getNumPlayers()
          Returns the number of players connected to the server
 java.lang.String getPasswordField()
          Returns the current value stored in the password field on the main window
 java.lang.String[][] getPlayerData()
          Returns all data within the player table on the main window
 java.lang.String[] 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 value of the port field on the main window
 int getScoreLimit()
          Returns the score limit of the game
 java.lang.String[][] getTeamData()
          Returns all data within the team table on the main window
 java.lang.String[] getTeamData(java.lang.String teamName)
          Returns the row of the team table with the team name matching that provided
 int getTimeLeft()
          Returns the time left within the current game
 int getTimeLimit()
          Returns the time limit of the current game
 java.lang.String getWindowTitle()
          Returns the main SARJ window title
static Sarj instance()
          Returns the instance of the SARJ program
static void main(java.lang.String[] args)
          The main method
 void onAction(int actionID)
          Called when the Perform button is clicked on the GUI
 void onAddAdmin(java.lang.String playerIP)
          Called when the user chooses to add a player to the remote administrators list
 void onBanPlayer(int playerNumber)
          Called when the user chooses to ban a player from the list of currently connected players
 void onCommand(java.lang.String command)
          Called when a command is sent from the user
 void onConnect(java.lang.String address, int port, java.lang.String password)
          Called when the Connect button is clicked on the GUI
 void onConnected()
          Called when a connection is successfully established with a server, as a result of calling the connect method of a Connection object.
 void onDisconnect()
          Called when the Disconnect button is clicked on the GUI
 void onDisconnected()
          Called when a connection to a server is lost, either gracefully or due to error
 void onError(java.lang.String message)
          Called when a connection error occurrs
 void onExit()
          Called when the Exit button is clicked on the GUI, or the main GUI window is closed
 void onKickPlayer(int playerNumber)
          Called when the user chooses to kick a player from the list of currently connected players
 void onRefresh()
          Called when the Refresh button is clicked on the GUI, or the refresh timer triggers
 void onRemoveAdmin(java.lang.String playerIP)
          Called when the user chooses to remove a player from the remote administrators list
 void onScriptButtonClick(java.lang.String name, java.lang.String scriptFile)
          Called when the user clicks on a ScriptButton
 void onSetTeam(int playerNumber, int teamNumber)
          Called when the user chooses to assign a connected player to a particular team
static void printError(java.lang.String errorString)
          Displays error messages
 void run()
          Called when the main execution thread is started by a call to Thread.start()
protected  void Sarj()
          Default constructor
 void sendData(java.lang.String data)
          Sends data to a connected server
 void setCommandBox(java.lang.String command)
          Sets the command combo box field on the main window
 void setIPField(java.lang.String ip)
          Sets the IP field on the main window
 void setPasswordField(java.lang.String password)
          Sets the password field on the main window
 void setPortField(java.lang.String port)
          Sets the port field on the main window
 void setWindowTitle(java.lang.String title)
          Sets the main SARJ window title to that specified
 void writeToConsole(java.lang.String text)
          Writes text to the main command console
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowClosing, 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

OK_ICON

public static javax.swing.ImageIcon OK_ICON

CANCEL_ICON

public static javax.swing.ImageIcon CANCEL_ICON
Constructor Detail

Sarj

public Sarj()
Method Detail

main

public static void main(java.lang.String[] args)
The main method


Sarj

protected void Sarj()
Default constructor


instance

public static Sarj instance()
Returns the instance of the SARJ program


run

public void run()
Called when the main execution thread is started by a call to Thread.start()

Specified by:
run in interface java.lang.Runnable

printError

public static void printError(java.lang.String errorString)
Displays error messages

Parameters:
errorString - the error message to display

onConnect

public void onConnect(java.lang.String address,
                      int port,
                      java.lang.String password)
Called when the Connect button is clicked on the GUI

Specified by:
onConnect in interface GUIListener
Parameters:
address - the address of the Soldat server, in dotted IP format (X.X.X.X)
port - the port number of the Soldat server
password - the remote administration password for the server

onDisconnect

public void onDisconnect()
Called when the Disconnect button is clicked on the GUI

Specified by:
onDisconnect in interface GUIListener

onExit

public void onExit()
Called when the Exit button is clicked on the GUI, or the main GUI window is closed

Specified by:
onExit in interface GUIListener

onAction

public void onAction(int actionID)
Called when the Perform button is clicked on the GUI

Specified by:
onAction in interface GUIListener
Parameters:
actionID - the ID of the action to be performed

onRefresh

public void onRefresh()
Called when the Refresh button is clicked on the GUI, or the refresh timer triggers

Specified by:
onRefresh in interface GUIListener

onCommand

public void onCommand(java.lang.String command)
Called when a command is sent from the user

Specified by:
onCommand in interface GUIListener
Parameters:
command - the command string issued by the user

onKickPlayer

public void onKickPlayer(int playerNumber)
Called when the user chooses to kick a player from the list of currently connected players

Specified by:
onKickPlayer in interface GUIListener
Parameters:
playerNumber - the unique in-game ID number of the player

onBanPlayer

public void onBanPlayer(int playerNumber)
Called when the user chooses to ban a player from the list of currently connected players

Specified by:
onBanPlayer in interface GUIListener
Parameters:
playerNumber - the unique in-game ID number of the player

onAddAdmin

public void onAddAdmin(java.lang.String playerIP)
Called when the user chooses to add a player to the remote administrators list

Specified by:
onAddAdmin in interface GUIListener
Parameters:
playerIP - the IP address of the player

onRemoveAdmin

public void onRemoveAdmin(java.lang.String playerIP)
Called when the user chooses to remove a player from the remote administrators list

Specified by:
onRemoveAdmin in interface GUIListener
Parameters:
playerIP - the IP address of the player

onSetTeam

public void onSetTeam(int playerNumber,
                      int teamNumber)
Called when the user chooses to assign a connected player to a particular team

Specified by:
onSetTeam in interface GUIListener
Parameters:
playerNumber - the unique in-game ID number of the player
teamNumber - the ID of the team to assign the player to, where 1 = alpha, 2 = beta, 3 = charlie and 4 = delta

onScriptButtonClick

public void onScriptButtonClick(java.lang.String name,
                                java.lang.String scriptFile)
Called when the user clicks on a ScriptButton

Specified by:
onScriptButtonClick in interface GUIListener
Parameters:
name - the name/caption of the button
scriptFile - the script file associated with the button

onConnected

public void onConnected()
Called when a connection is successfully established with a server, as a result of calling the connect method of a Connection object.

Specified by:
onConnected in interface ConnectionListener

onDisconnected

public void onDisconnected()
Called when a connection to a server is lost, either gracefully or due to error

Specified by:
onDisconnected in interface ConnectionListener

onError

public void onError(java.lang.String message)
Called when a connection error occurrs

Specified by:
onError in interface ConnectionListener
Parameters:
message - the error message

formatTime

public static java.lang.String formatTime(int seconds)
Formats seconds into mm:ss format

Parameters:
seconds - the time to translate, in second

dispatchScript

public void dispatchScript(java.lang.String scriptFile)
Runs the specified script file

Parameters:
scriptFile - the path of the script file to execute

getCurrentMap

public java.lang.String getCurrentMap()
Returns the name of the map currently being played on the server

Specified by:
getCurrentMap in interface ScriptingFacade
Returns:
a String containing the name of the current map

getGameType

public java.lang.String getGameType()
Returns the type of game running on the server

Specified by:
getGameType in interface ScriptingFacade
Returns:
a String containing the name of the current game type

getTimeLimit

public int getTimeLimit()
Returns the time limit of the current game

Specified by:
getTimeLimit in interface ScriptingFacade
Returns:
the current time limit, in seconds

getTimeLeft

public int getTimeLeft()
Returns the time left within the current game

Specified by:
getTimeLeft in interface ScriptingFacade
Returns:
the time remaining, in seconds

getScoreLimit

public int getScoreLimit()
Returns the score limit of the game

Specified by:
getScoreLimit in interface ScriptingFacade
Returns:
the score limit

getNumPlayers

public int getNumPlayers()
Returns the number of players connected to the server

Specified by:
getNumPlayers in interface ScriptingFacade
Returns:
the number of players currently connected

setWindowTitle

public void setWindowTitle(java.lang.String title)
Sets the main SARJ window title to that specified

Specified by:
setWindowTitle in interface ScriptingFacade
Parameters:
title - the new title for the window

getWindowTitle

public java.lang.String getWindowTitle()
Returns the main SARJ window title

Specified by:
getWindowTitle in interface ScriptingFacade
Returns:
a String containing the title of the main window

getIPField

public java.lang.String getIPField()
Returns the value of the IP field on the main window

Specified by:
getIPField in interface ScriptingFacade
Returns:
a String containing the value of the IP field

getPortField

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

Specified by:
getPortField in interface ScriptingFacade
Returns:
a String 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

Specified by:
getPasswordField in interface ScriptingFacade
Returns:
a String object containing the unmasked value of the password field

getCommandBox

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

Specified by:
getCommandBox in interface ScriptingFacade
Returns:
a String containing the value of the command combo box

setIPField

public void setIPField(java.lang.String ip)
Sets the IP field on the main window

Specified by:
setIPField in interface ScriptingFacade
Parameters:
ip - the new IP address value

setPortField

public void setPortField(java.lang.String port)
Sets the port field on the main window

Specified by:
setPortField in interface ScriptingFacade
Parameters:
port - the new port value

setPasswordField

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

Specified by:
setPasswordField in interface ScriptingFacade
Parameters:
password - the new password value

setCommandBox

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

Specified by:
setCommandBox in interface ScriptingFacade
Parameters:
command - the new value to set the command combo box to

clearConsole

public void clearConsole()
Clears the console on the main window

Specified by:
clearConsole in interface ScriptingFacade

disconnectClient

public void disconnectClient()
Disconnects the client from any connected server

Specified by:
disconnectClient in interface ScriptingFacade

connectClient

public void connectClient(java.lang.String ip,
                          int port)
Connects the client to the specified IP and port

Specified by:
connectClient in interface ScriptingFacade
Parameters:
ip - the IP address of the server
port - the port number of the server

connectClient

public void connectClient()
Connects the client to the IP and port displayed on the main window

Specified by:
connectClient in interface ScriptingFacade

writeToConsole

public void writeToConsole(java.lang.String text)
Writes text to the main command console

Specified by:
writeToConsole in interface ScriptingFacade
Parameters:
text - the text to print on the console

sendData

public void sendData(java.lang.String data)
Sends data to a connected server

Specified by:
sendData in interface ScriptingFacade
Parameters:
data - the data to send

getPlayerData

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

Specified by:
getPlayerData in interface ScriptingFacade
Parameters:
playerName - the name of the player to match
Returns:
the data contained in the table relating to the player

getPlayerData

public java.lang.String[][] getPlayerData()
Returns all data within the player table on the main window

Specified by:
getPlayerData in interface ScriptingFacade
Returns:
a 2D array of String objects containing the data in the table

getTeamData

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

Specified by:
getTeamData in interface ScriptingFacade
Parameters:
teamName - the name of the team to match
Returns:
the data contained in the table relating to the team

getTeamData

public java.lang.String[][] getTeamData()
Returns all data within the team table on the main window

Specified by:
getTeamData in interface ScriptingFacade
Returns:
a 2D array of String objects containing the data in the table