anecho.JamochaMUD
Class CHandler

java.lang.Object
  extended by anecho.JamochaMUD.CHandler

public final class CHandler
extends java.lang.Object

To allow an easier time of dealing with multiple connections, any input or output from JamochaMUD will pass through the CHandler class. This class will then determine which MU* the outbound traffic will go out (eg. the "active" MU* if from the DataIn window) or the appropriate window to send incoming traffic based on the socket it is received from. CHandler now extends the Container class so that it can act as it's own autonomous "widget" coordinating views of MU*s and their actual connections. CHandler will "hold" the actual MuSockets but for considering which connection is visible/active, we will always ask our display object, be it the JMTextPanel or the JTabbedPane.


Method Summary
 void addNewMU(java.lang.String name, java.lang.String address, int port, MuSocket msock)
          Add the text display component owned by the given MuSocket to our display object.
 void closeActiveMU(java.lang.String stamp)
          Close the connection to the active MU*
 void closeSocket(MuSocket socket)
          Close and "destroy" an existing socket.
 void connectToNewMU()
          Show MU* Connector and set-up a connection to a new MU*
 void connectToNewMU(java.lang.String muName, java.lang.String address, int port)
           
 JMSwingText getActiveMUDSwingText()
          This returns the active JMSwingText
 JMText getActiveMUDText()
          Deprecated. use JMText getActiveMUDText(String stamp)
 JMText getActiveMUDText(java.lang.String stamp)
          Return the active JMText component, verified with the passed timestamp
 MuSocket getActiveMUHandle()
          Return the MuSocket for the currently "active" MU*
 int getActiveMUIndex()
          Return the index of the active MU
 java.lang.String getActiveTitle()
          Return the title of the active MU*
 java.util.Vector getAllMUs()
          Return an array of all the MU*s.
static CHandler getInstance()
          Returns an instance of this class if it has already been instantiated.
 MuSocket getMUHandle(int muNum)
          Return the proper MuSocket for the requested mu
 java.awt.Component getTextObject()
          Deprecated. This method has been moved to MuckMain and broken into three separate methods: getTextPanel(), getFancyTextPanel(), and getLegacyTextPanel()
 java.lang.String getTitle(int index)
          Return the title of the MU based on the given index
 boolean isActiveMU(MuSocket mSock)
          Determines if the given MU* is the currently active MU*.
 boolean isActiveMUDConnected()
          Return the connection status of the active MU*
 boolean isActiveMUEchoState()
          Return the ECHO state for the active MU*
 void nextMU()
          Make the next MU* in the list the active MU* The process that makes the call to this method is responsible for updating the display appropriately
 MuSocket openSocket(java.lang.String name, java.lang.String address, int port, boolean ssl)
          Create a new MuSocket that will be set-up with the supplied information and start its thread.
 void previousMU()
          Make the previous MU* in the list the active MU*.
 void reconnectToMU()
          Reconnect to the currently active (visible) MU*
 void removeActiveMU(java.lang.String stamp)
          Remove the active MU* from our list altogether
 void removeMU(MuSocket mSock)
          Remove the MU* indicated by the MuSocket and timeStamp
 void sendText(java.lang.String send)
          Send the text to the currently active MU*
 void sendText(java.lang.String send, MuSocket msock)
          Send a string to the supplied MU*, using the proper encoding method (ASCII or Unicode)
 void setActiveMU(int target)
          Sets the active MU* (the MU* visible to the user) based on the index number provided.
 void setAllAttribs(java.awt.Font fontFace, java.awt.Color fgColour, java.awt.Color bgColour, java.awt.Color[] newPal)
          Change the font face and size on all the connections
 void setAllColours(java.awt.Color fgColour, java.awt.Color bgColour)
          Set the foreground and background colours for all the MU*s.
 void setAllFonts(java.awt.Font newStyle)
          Set the Font for all active MU*s
 void setAntiAliasing(boolean state)
          Change between aliased and antialised text in our output windows.
 void setCustomPalette(java.awt.Color[] newPal)
          This method sets the custom colours to be used on all our MU* windows.
 void setDoubleBuffer(boolean state)
          Change the drawing type for the JMText...
 void setLogging(boolean state)
          Activate or deactivate logging in all connections
 void setLowColour(boolean state)
          Set the MU* displays to operating in either "low colour" (8 colours, normal and bold) or "high colour" (16 colours).
 void showLatestMU()
          This method displays the last MU* connected to that is still open.
 int totalConnections()
          Get the total number of MU*s open regardless of their connection status
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static CHandler getInstance()
Returns an instance of this class if it has already been instantiated. If this class has not yet been instantiated, a new instance will be created. This is to ensure that there is only one instance of this class occuring.

Returns:
returns the current instance of this class.

getTextObject

public java.awt.Component getTextObject()
Deprecated. This method has been moved to MuckMain and broken into three separate methods: getTextPanel(), getFancyTextPanel(), and getLegacyTextPanel()

Return the layout object that contains our MU* views

Returns:
Returns a component that houses JamochaMUD's output display.

setActiveMU

public void setActiveMU(int target)
Sets the active MU* (the MU* visible to the user) based on the index number provided.

Parameters:
target - The index number repesenting which MU* should be set active.

showLatestMU

public void showLatestMU()
This method displays the last MU* connected to that is still open.


addNewMU

public void addNewMU(java.lang.String name,
                     java.lang.String address,
                     int port,
                     MuSocket msock)
Add the text display component owned by the given MuSocket to our display object. Once the component has been added, we set JamochaMUD to show it.

Parameters:
name - The human-readable name of the MU*
address - The numeric or human-readable address for the MU* server
port - The MU* server port to connect to
msock - The MuSocket which is responsible for communicating between JamochaMUD the new MU*.

openSocket

public MuSocket openSocket(java.lang.String name,
                           java.lang.String address,
                           int port,
                           boolean ssl)
Create a new MuSocket that will be set-up with the supplied information and start its thread. Return the given MuSocket to the calling method. AddNewMU is normally called after this if this is a brand new connection.

Parameters:
ssl - Returns whether the connection is to be encrypted (SSL) or plain text. true - encrypted connection false - plain text connection
name - The human-readable name for the new MU*
address - The human-readable or numeric address for the MU* server
port - The MU* server port to connect to
Returns:
Returns a new MuSocket object that will be responsible for this connection.

nextMU

public void nextMU()
Make the next MU* in the list the active MU* The process that makes the call to this method is responsible for updating the display appropriately


previousMU

public void previousMU()
Make the previous MU* in the list the active MU*. As with nextMU, the calling process is responsible for updating the display appropriately.


closeActiveMU

public void closeActiveMU(java.lang.String stamp)
Close the connection to the active MU*

Parameters:
stamp - Timestamp of MU* to be closed (as confirmation)

removeActiveMU

public void removeActiveMU(java.lang.String stamp)
Remove the active MU* from our list altogether

Parameters:
stamp - This is the time stamp used to verify that we are closing the proper MU*.

removeMU

public void removeMU(MuSocket mSock)
Remove the MU* indicated by the MuSocket and timeStamp

Parameters:
mSock - The MuSocket to close and remove

closeSocket

public void closeSocket(MuSocket socket)
Close and "destroy" an existing socket. This allows any of our clases to shut things down

Parameters:
socket - The socket to be closed.

getActiveMUDText

public JMText getActiveMUDText()
Deprecated. use JMText getActiveMUDText(String stamp)

Return the 'address' for the active JMText object

Returns:
Returns a variable representing the active MU*

getActiveMUDSwingText

public JMSwingText getActiveMUDSwingText()
This returns the active JMSwingText

Returns:
JMSwingText of the active MU*

getActiveMUDText

public JMText getActiveMUDText(java.lang.String stamp)
Return the active JMText component, verified with the passed timestamp

Parameters:
stamp - A timestamp to verify the component returned
Returns:
Returns a JMText component of the active MU*

getActiveMUIndex

public int getActiveMUIndex()
Return the index of the active MU

Returns:
Returns the index number of the active MU*

getTitle

public java.lang.String getTitle(int index)
Return the title of the MU based on the given index

Parameters:
index - Index representing the MU* we are to retrieve the title of.
Returns:
The title of the MU* represented by the given index

getMUHandle

public MuSocket getMUHandle(int muNum)
Return the proper MuSocket for the requested mu

Parameters:
muNum - This variable represents the index of the MU* to retrieve
Returns:
MuSocket representing the MU* specified by our muNum

getActiveMUHandle

public MuSocket getActiveMUHandle()
Return the MuSocket for the currently "active" MU*

Returns:
The MuSocket of the currently active MU*

isActiveMUDConnected

public boolean isActiveMUDConnected()
                             throws java.lang.Exception
Return the connection status of the active MU*

Returns:
true - The active MU* is connected to a server false - The active MU* is not connected to a server
Throws:
java.lang.Exception - if there are no current connections

sendText

public void sendText(java.lang.String send)
Send the text to the currently active MU*

Parameters:
send -

sendText

public void sendText(java.lang.String send,
                     MuSocket msock)
Send a string to the supplied MU*, using the proper encoding method (ASCII or Unicode)

Parameters:
send - The String to be sent to the active MU*
msock -

setAllAttribs

public void setAllAttribs(java.awt.Font fontFace,
                          java.awt.Color fgColour,
                          java.awt.Color bgColour,
                          java.awt.Color[] newPal)
Change the font face and size on all the connections

Parameters:
newPal - This array represents the colour palette that is to be used
fontFace - The Font to use for the display.
fgColour - The foreground colour to use
bgColour - The background colour to use

setLogging

public void setLogging(boolean state)
Activate or deactivate logging in all connections

Parameters:
state - true - enable logging false - disable logging

setAllColours

public void setAllColours(java.awt.Color fgColour,
                          java.awt.Color bgColour)
Set the foreground and background colours for all the MU*s.

Parameters:
fgColour - The foreground colour to use
bgColour - The background colour to use

setCustomPalette

public void setCustomPalette(java.awt.Color[] newPal)
This method sets the custom colours to be used on all our MU* windows.

Parameters:
newPal - An array containing our new Colors.

setAllFonts

public void setAllFonts(java.awt.Font newStyle)
Set the Font for all active MU*s

Parameters:
newStyle - The Font style to use

connectToNewMU

public void connectToNewMU(java.lang.String muName,
                           java.lang.String address,
                           int port)
Parameters:
muName -
address -
port -

connectToNewMU

public void connectToNewMU()
Show MU* Connector and set-up a connection to a new MU*


totalConnections

public int totalConnections()
Get the total number of MU*s open regardless of their connection status

Returns:
The number of existing MuSockets

isActiveMU

public boolean isActiveMU(MuSocket mSock)
Determines if the given MU* is the currently active MU*.

Parameters:
mSock - The MuSocket to check to see if it is current the active MU*.
Returns:
true - the provided MU* is the active MU* false - the provided MU* is not the active MU*

getActiveTitle

public java.lang.String getActiveTitle()
Return the title of the active MU*

Returns:
Return a String of the title of the active MU*.

setDoubleBuffer

public void setDoubleBuffer(boolean state)
Change the drawing type for the JMText... either single buffered (false) or double buffered (true)

Parameters:
state - true - set the display to double buffer false - set the display to work without buffering

setAntiAliasing

public void setAntiAliasing(boolean state)
Change between aliased and antialised text in our output windows.

Parameters:
state - true - enable antialiasing false - disalbe antialiasing

setLowColour

public void setLowColour(boolean state)
Set the MU* displays to operating in either "low colour" (8 colours, normal and bold) or "high colour" (16 colours).

Parameters:
state - true - set the display to low colour mode false - set display to high colour mode

isActiveMUEchoState

public boolean isActiveMUEchoState()
Return the ECHO state for the active MU*

Returns:
true - the active MU* echo mode is enabled false - the active MU* is not in echo mode

reconnectToMU

public void reconnectToMU()
Reconnect to the currently active (visible) MU*


getAllMUs

public java.util.Vector getAllMUs()
Return an array of all the MU*s. This can be handy if a change has to be applied to all open connections

Returns:
returns a Vector containing all the current connections.