swpchat.client
Class ClientControls

java.lang.Object
  |
  +--swpchat.client.ClientControls
All Implemented Interfaces:
ChatTokens, ClientFunctions

public class ClientControls
extends java.lang.Object
implements ClientFunctions, ChatTokens

This class implements all functions of the client.

Author:
Christian Stüllenberg, Andre Brunner, Marc Sturm

Field Summary
private  AudioActivator audioActivator
           
private  boolean audioFlag
           
private  AudioMapper audioMapper
           
private static java.lang.String CLS
           
private  ContactsMapper contactsMapper
           
 ControlConnection controlConnection
           
private  DisplayControler displayControler
           
private  OpenServer fileServer
           
private  java.util.Vector fileVector
           
private  int MAX_FILE_COUNTER
           
private  MemberMap memberMap
           
private  PictureFrame pictureFrame
           
private  ReceiveFileQuestionDialog questDialog
           
 ReceiverServerConnection receiverConnection
           
 SenderServerConnection senderConnection
           
private  java.lang.String sessionKey
           
private static java.lang.String STR_AUDIO_KEY
           
private static java.lang.String STR_CONTACTS_KEY
           
private  SWPOptions swpOptions
           
private  boolean transferIP
           
 
Fields inherited from interface swpchat.protocol.ChatTokens
CHAR_ARG_SEP, CHAR_MSG_END, CHAR_MSG_EOL, CHAR_QUOTE, CHAR_STRING_DELIMITER, STR_ARG_SEP, STR_AUTHORIZE, STR_MSG_END, STR_MSG_EOL, STR_NEG_ARG, STR_NEGATIVE, STR_POS_ARG, STR_POSITIVE, STR_QUOTE, STR_REPLY, STR_STRING_DELIMITER, STR_WAIT
 
Constructor Summary
ClientControls(DisplayControler displayControler)
          Constructor.
 
Method Summary
 void addAudioFile(java.lang.String audioKey, java.lang.String sound)
          Adds an audio file to the properties.
 void addChannelToAvailableList(java.lang.String channelName)
          Adds channel to list of available channels in main frame.
 void addContact(java.lang.String nick)
          Add a contact to the list.
 void addContactAndLocations(java.lang.String nick, java.util.Enumeration channels)
          Add a contact and the channels where is joined to the list.
 void addFileTransfer(FileProtocolHandler file)
          method encapsulates a (assozierte Warteschlange) add fileProtocolHandler to the que.
 void addLocation(java.lang.String nick, java.lang.String channel)
          Add a location to a contact.
 void addNewContact(java.lang.String strNick)
           
 void changeAudioFlag()
          Switches the audio flag to the opposite value.
 boolean changeNick(java.lang.String newNickname)
          Changes the actual nickname.
 void changeTopic(java.lang.String channel)
          prompt for the topic of a specified channel and tell the server about it
 boolean connect(java.lang.String servername, java.lang.String nickname)
          Connects to a given server with a given nickname.
 boolean createNewChannel(java.lang.String name, java.lang.String sendPasswd, java.lang.String recvPasswd)
          Creates a new channel.
 void deleteContact(java.lang.String strNick)
           
 boolean disconnect()
          Disconnects from the server.
 void displayEmotion(java.lang.String channel, java.lang.String from, java.lang.String target, java.lang.String emo)
          Shows received emotion message in the receiver textarea
 void displayMessage(java.lang.String sender, java.lang.String channel, java.lang.String message)
          Shows received message in the receiver textarea
 void displayPlayMessage(java.lang.String sender, java.lang.String channel, java.lang.String message)
          Shows received message in the receiver textarea
 void displayShipMessage(java.lang.String channel, java.lang.String sender, java.lang.String victim, java.lang.String status)
          Shows received ship-message in the receiver textarea If Client is victim something funny happens.!
 void displayUserInfo(java.util.Vector tokenlist)
          method analyses tokenlist
 void displayWhisperMsg(java.lang.String channel, java.lang.String sender, java.lang.String message)
          Shows received whispermessage in the receiver textarea
 boolean emotion(java.lang.String channel, java.lang.String target, java.lang.String emo)
          The Emotionmessage is passed on to the SenderServerConnection
 java.util.Enumeration getAudioEnumeration()
          Gets an enumeration of audio files from the AudioMapper and returns it.
 java.util.Enumeration getAvailableChannelEnumeration()
          Gets an enumeration of available channels and returns it.
 java.util.Enumeration getContactEnumeration()
          Gets an enumeration of all stored Contacts and returns it.
 java.util.Iterator getLocations(java.lang.String nick)
          Get an Iterator over the channels where a contact is joined.
 java.lang.String getMixerPath()
          Gets the stored default path and returns it.
 java.lang.String getNickname()
          Gets the stored default nickname from swpOpions and returns it.
 java.lang.String getPassword(java.lang.String message)
          Opens an InputDialog and returns the entered Text
 java.util.Enumeration getSelectedChannelEnumeration()
          Gets an enumeration of selected channels and returns it.
 java.lang.String getServername()
          Gets the stored default servername from swpOpions and returns it.
 java.lang.String getSFMikePath()
          Gets the stored default path and returns it.
 java.lang.String getSFSpeakerPath()
          Gets the stored default path and returns it.
 void handlingMemberMap(java.lang.String channelName, java.lang.String name, java.lang.Boolean sender, java.lang.Boolean receiver, java.lang.Boolean schiffer)
           
 boolean isConnected()
          Checks if the client is actually connected completely.
 boolean join(java.lang.String channel)
          Joins a channel.
 boolean leave(java.lang.String channel)
          Leaves a channel.
 void notificationRequest(java.lang.String nick)
           
 void openServer()
          starts a new Server for receiving files
 boolean play(java.lang.String channel, java.lang.String audiokey)
          Sends a play request to the specified channel.
 boolean playReceivedAudioRequest(java.lang.String channel, java.lang.String sender, java.lang.String audio)
          Plays an audio file.
 void quit()
          Quits the client program with disconnecting from server.
 void removeAudioFile(java.lang.String audioKey)
          Removes an audio file from the properties.
 boolean removeChannel(java.lang.String name)
          Removes an existing channel.
 void removeChannelFromAvailableList(java.lang.String channelName)
          Removes channel from list of available channels in main frame.
 void removeContact(java.lang.String nick)
          Remove a contact from the list.
 void removeFileTransfer(FileProtocolHandler file)
          method encapsulates a (assozierte Warteschlange) remove fileProtocolHandler from the que.
 void removeLocation(java.lang.String nick, java.lang.String channel)
          Remove a location from a contact.
 boolean renameChannel(java.lang.String oldname, java.lang.String newname)
          Renames an existing channel.
 void requestUserInfo(java.lang.String nickname)
          method is invoked if the infos of another user are requested (delegates task to requestUserInfo in SenderConnection)
 void saveMixerPath(java.lang.String newPath)
          Stores path in properties.
 void saveNickname(java.lang.String nickname)
          Stores nickname in properties.
 void saveReceivedFile(byte[] fileBytes, java.lang.String strFileName, int iFileSize)
           
 void saveServername(java.lang.String servername)
          Stores servername in properties.
 void saveSFMikePath(java.lang.String newPath)
          Stores path in properties.
 void saveSFSpeakerPath(java.lang.String newPath)
          Stores path in properties.
 boolean send(java.lang.String channel, java.lang.String message)
          Sends a given message to a given channel to the server.
 boolean sendFile(java.io.File pictureFile, java.util.Vector vecReceiver)
          Sends a picture to the server.
 boolean sendTelephoneRequest(java.lang.String partner, java.lang.String reason)
          Sends a telephonerequest to the server.
 void sendUserInfo(java.util.HashMap hashUserInfo)
          send user info of the actual client as a long String first hashmap is serialized into a sendable string then sendUserInfo from ControlServerConnection is invoked
 void setContactState(java.lang.String nick, java.lang.String state, java.lang.String channel)
          Set the state of a Contact, that is: online or offline.
 void setTransferIPAddress(boolean allowed)
           
 boolean ship(java.lang.String nick, java.lang.String status, ShipWindow shipWindow)
          Give or fetch someone his ship.
 boolean showAskDialog(java.lang.String name, java.lang.String size)
          shows the receive file dialog.
 void showDialogMessage(java.lang.String msg)
          Creates and shows a dialog with the specified message.
 void showReceivedFile(byte[] fileBytes, java.lang.String strFileName, int iFileSize)
          shows image file in Frame.
 boolean showReceivedPicture(java.io.File pictureFile)
          Shows a received picture.
 void startupUserInfoSend()
          this method checks if the user infos should be send automatically to server when you connect.
 void stopNotification(java.lang.String nick)
           
 void topicChanged(java.lang.String channel, java.lang.String nick, java.lang.String topic)
          Change the current topic
 boolean transferIPAddress()
           
 boolean whisper(java.lang.String channel, java.lang.String receiver, java.lang.String message)
          The Whispermessage is passed on to the SenderServerConnection
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

CLS

private static final java.lang.String CLS

STR_AUDIO_KEY

private static final java.lang.String STR_AUDIO_KEY

STR_CONTACTS_KEY

private static final java.lang.String STR_CONTACTS_KEY

controlConnection

public ControlConnection controlConnection

senderConnection

public SenderServerConnection senderConnection

receiverConnection

public ReceiverServerConnection receiverConnection

fileServer

private OpenServer fileServer

MAX_FILE_COUNTER

private final int MAX_FILE_COUNTER

fileVector

private java.util.Vector fileVector

swpOptions

private SWPOptions swpOptions

audioActivator

private AudioActivator audioActivator

audioMapper

private AudioMapper audioMapper

contactsMapper

private ContactsMapper contactsMapper

displayControler

private DisplayControler displayControler

pictureFrame

private PictureFrame pictureFrame

memberMap

private MemberMap memberMap

questDialog

private ReceiveFileQuestionDialog questDialog

sessionKey

private java.lang.String sessionKey

audioFlag

private boolean audioFlag

transferIP

private boolean transferIP
Constructor Detail

ClientControls

public ClientControls(DisplayControler displayControler)
Constructor.
Parameters:
displayControler - The display controler all frames are registered to.
Method Detail

connect

public boolean connect(java.lang.String servername,
                       java.lang.String nickname)
Connects to a given server with a given nickname. Returns true, if we could connect to the server.
Specified by:
connect in interface ClientFunctions
Parameters:
servername - The server name.
nickname - The user's nickname.

disconnect

public boolean disconnect()
Disconnects from the server. Returns true, if we could disconnect.
Specified by:
disconnect in interface ClientFunctions

sendTelephoneRequest

public boolean sendTelephoneRequest(java.lang.String partner,
                                    java.lang.String reason)
Sends a telephonerequest to the server.
Parameters:
partner - the partner, who is desired to be heart and spoken to
reason - the reason, which the partner gets to see returns true if telephonerequest is sent successfully, false else

send

public boolean send(java.lang.String channel,
                    java.lang.String message)
Sends a given message to a given channel to the server.
Specified by:
send in interface ClientFunctions
Parameters:
channel - The channel the message should be sent to.
message - The message :-)

isConnected

public boolean isConnected()
Checks if the client is actually connected completely.
Specified by:
isConnected in interface ClientFunctions

quit

public void quit()
Quits the client program with disconnecting from server.
Specified by:
quit in interface ClientFunctions

showDialogMessage

public void showDialogMessage(java.lang.String msg)
Creates and shows a dialog with the specified message.
Parameters:
msg - The message to be shown.

changeNick

public boolean changeNick(java.lang.String newNickname)
Changes the actual nickname. Returns true, if the nickname could be changed.
Specified by:
changeNick in interface ClientFunctions
Parameters:
newNickname - The new nickname, what else?

getNickname

public java.lang.String getNickname()
Gets the stored default nickname from swpOpions and returns it.
Specified by:
getNickname in interface ClientFunctions

saveNickname

public void saveNickname(java.lang.String nickname)
Stores nickname in properties.
Specified by:
saveNickname in interface ClientFunctions

getServername

public java.lang.String getServername()
Gets the stored default servername from swpOpions and returns it.
Specified by:
getServername in interface ClientFunctions

saveServername

public void saveServername(java.lang.String servername)
Stores servername in properties.
Specified by:
saveServername in interface ClientFunctions

getSFMikePath

public java.lang.String getSFMikePath()
Gets the stored default path and returns it.

saveSFMikePath

public void saveSFMikePath(java.lang.String newPath)
Stores path in properties.

getSFSpeakerPath

public java.lang.String getSFSpeakerPath()
Gets the stored default path and returns it.

saveSFSpeakerPath

public void saveSFSpeakerPath(java.lang.String newPath)
Stores path in properties.

getMixerPath

public java.lang.String getMixerPath()
Gets the stored default path and returns it.

saveMixerPath

public void saveMixerPath(java.lang.String newPath)
Stores path in properties.

transferIPAddress

public boolean transferIPAddress()
Returns:
true, iff the user has allowed to tranfer the IPAddress

setTransferIPAddress

public void setTransferIPAddress(boolean allowed)
Parameters:
allowed - contains the authorisation to send the IPAddress

play

public boolean play(java.lang.String channel,
                    java.lang.String audiokey)
Sends a play request to the specified channel.
Specified by:
play in interface ClientFunctions
Parameters:
channel - The actual channel.
audiokey - The audio key of the file to be played.

playReceivedAudioRequest

public boolean playReceivedAudioRequest(java.lang.String channel,
                                        java.lang.String sender,
                                        java.lang.String audio)
Plays an audio file.
Specified by:
playReceivedAudioRequest in interface ClientFunctions
Parameters:
channel - The actual channel.
sender - The sender of the play request.
audio - The audio key of the audio file to be played.

addAudioFile

public void addAudioFile(java.lang.String audioKey,
                         java.lang.String sound)
Adds an audio file to the properties.
Specified by:
addAudioFile in interface ClientFunctions
Parameters:
audioKey - The audio key of the audio file to be added.
sound - The URL to the audio file.

removeAudioFile

public void removeAudioFile(java.lang.String audioKey)
Removes an audio file from the properties.
Specified by:
removeAudioFile in interface ClientFunctions
Parameters:
audioKey - The audio key to be removed.

getAudioEnumeration

public java.util.Enumeration getAudioEnumeration()
Gets an enumeration of audio files from the AudioMapper and returns it.
Specified by:
getAudioEnumeration in interface ClientFunctions

sendFile

public boolean sendFile(java.io.File pictureFile,
                        java.util.Vector vecReceiver)
Sends a picture to the server.
Specified by:
sendFile in interface ClientFunctions
Parameters:
actualChannel - The Channel the picture is sent to.
pictureFile - The File containing th picture.

showReceivedFile

public void showReceivedFile(byte[] fileBytes,
                             java.lang.String strFileName,
                             int iFileSize)
shows image file in Frame.

saveReceivedFile

public void saveReceivedFile(byte[] fileBytes,
                             java.lang.String strFileName,
                             int iFileSize)

openServer

public void openServer()
starts a new Server for receiving files

addFileTransfer

public void addFileTransfer(FileProtocolHandler file)
method encapsulates a (assozierte Warteschlange) add fileProtocolHandler to the que.
Parameters:
file, - the ProtocolHandler that is (eingereiht) in the que.

removeFileTransfer

public void removeFileTransfer(FileProtocolHandler file)
method encapsulates a (assozierte Warteschlange) remove fileProtocolHandler from the que.
Parameters:
file, - the ProtocolHandler that is (eingereiht) in the que.

whisper

public boolean whisper(java.lang.String channel,
                       java.lang.String receiver,
                       java.lang.String message)
The Whispermessage is passed on to the SenderServerConnection
Parameters:
channel - The Channel on which the receiver is expected
receiver - The Nick of the Client the message is to be send to
message - The actual message to be send

emotion

public boolean emotion(java.lang.String channel,
                       java.lang.String target,
                       java.lang.String emo)
The Emotionmessage is passed on to the SenderServerConnection
Parameters:
channel - The Channel on which the receiver is expected
target - The Nick of the Client who is the target
emotion - The emotion to be send

showAskDialog

public boolean showAskDialog(java.lang.String name,
                             java.lang.String size)
shows the receive file dialog. returns true, if the user wants to receive the file.

showReceivedPicture

public boolean showReceivedPicture(java.io.File pictureFile)
Shows a received picture.
Specified by:
showReceivedPicture in interface ClientFunctions
Parameters:
pictureFile - The received picture file.

join

public boolean join(java.lang.String channel)
Joins a channel. Returns true on success. Handles, if sender and receiver or only one shall be joined.
Specified by:
join in interface ClientFunctions
Parameters:
channel - The channel to be joined.

leave

public boolean leave(java.lang.String channel)
Leaves a channel. Returns true on success.
Specified by:
leave in interface ClientFunctions
Parameters:
channel - The channel to be left.

createNewChannel

public boolean createNewChannel(java.lang.String name,
                                java.lang.String sendPasswd,
                                java.lang.String recvPasswd)
Creates a new channel. Returns true on success.
Specified by:
createNewChannel in interface ClientFunctions
Parameters:
name - The name of the new channel.

renameChannel

public boolean renameChannel(java.lang.String oldname,
                             java.lang.String newname)
Renames an existing channel. Returns true on success. But i think it's not used yet...maybe later...
Specified by:
renameChannel in interface ClientFunctions
Parameters:
oldname - The old channel name.
newname - The new channel name.

removeChannel

public boolean removeChannel(java.lang.String name)
Removes an existing channel. Returns true on success.
Specified by:
removeChannel in interface ClientFunctions
Parameters:
name - The name of the channel to be removed.

getAvailableChannelEnumeration

public java.util.Enumeration getAvailableChannelEnumeration()
Gets an enumeration of available channels and returns it.
Specified by:
getAvailableChannelEnumeration in interface ClientFunctions

getSelectedChannelEnumeration

public java.util.Enumeration getSelectedChannelEnumeration()
Gets an enumeration of selected channels and returns it.
Specified by:
getSelectedChannelEnumeration in interface ClientFunctions

addChannelToAvailableList

public void addChannelToAvailableList(java.lang.String channelName)
Adds channel to list of available channels in main frame.
Parameters:
channelName - The channel name.

removeChannelFromAvailableList

public void removeChannelFromAvailableList(java.lang.String channelName)
Removes channel from list of available channels in main frame.
Parameters:
channelName - The channel name.

displayMessage

public void displayMessage(java.lang.String sender,
                           java.lang.String channel,
                           java.lang.String message)
Shows received message in the receiver textarea
Parameters:
sender - The sender of the message.
channel - The channel for the message.
message - The message itself.

displayWhisperMsg

public void displayWhisperMsg(java.lang.String channel,
                              java.lang.String sender,
                              java.lang.String message)
Shows received whispermessage in the receiver textarea
Parameters:
sender - The sender of the message.
channel - The channel for the message.
message - The message itself.

displayShipMessage

public void displayShipMessage(java.lang.String channel,
                               java.lang.String sender,
                               java.lang.String victim,
                               java.lang.String status)
Shows received ship-message in the receiver textarea If Client is victim something funny happens.!
Parameters:
channel - The channel for the ship-attac.
sender - The sender of the ship-attac.
victim - The victim of the ship-attac.
status - The status of the ship-attac (ON/OFF).

displayEmotion

public void displayEmotion(java.lang.String channel,
                           java.lang.String from,
                           java.lang.String target,
                           java.lang.String emo)
Shows received emotion message in the receiver textarea
Parameters:
channel - The channel for the emo.
sender - The sender of the emo.
target - The target for the emo.
emo - The emo itself.

displayPlayMessage

public void displayPlayMessage(java.lang.String sender,
                               java.lang.String channel,
                               java.lang.String message)
Shows received message in the receiver textarea
Parameters:
sender - The sender of the message.
channel - The channel for the message.
message - The play message itself.

changeAudioFlag

public void changeAudioFlag()
Switches the audio flag to the opposite value. The audio flag indicates, if sounds shall be played or not.

sendUserInfo

public void sendUserInfo(java.util.HashMap hashUserInfo)
send user info of the actual client as a long String first hashmap is serialized into a sendable string then sendUserInfo from ControlServerConnection is invoked
Parameters:
hashUserInfo - List of attributes and their values

requestUserInfo

public void requestUserInfo(java.lang.String nickname)
method is invoked if the infos of another user are requested (delegates task to requestUserInfo in SenderConnection)
Parameters:
nickname - the nick name of the user we want the infos of

handlingMemberMap

public void handlingMemberMap(java.lang.String channelName,
                              java.lang.String name,
                              java.lang.Boolean sender,
                              java.lang.Boolean receiver,
                              java.lang.Boolean schiffer)

displayUserInfo

public void displayUserInfo(java.util.Vector tokenlist)
method analyses tokenlist
Parameters:
tokenlist - the tokenlist from MessageReceiver

startupUserInfoSend

public void startupUserInfoSend()
this method checks if the user infos should be send automatically to server when you connect. If yes, sendUserInfo is invoked.

notificationRequest

public void notificationRequest(java.lang.String nick)

stopNotification

public void stopNotification(java.lang.String nick)

addNewContact

public void addNewContact(java.lang.String strNick)

deleteContact

public void deleteContact(java.lang.String strNick)

getContactEnumeration

public java.util.Enumeration getContactEnumeration()
Gets an enumeration of all stored Contacts and returns it.

setContactState

public void setContactState(java.lang.String nick,
                            java.lang.String state,
                            java.lang.String channel)
Set the state of a Contact, that is: online or offline. If the contact doesn't exist yet in any of the Contact lists it is added to the online list, unless the state is offline then it is added to the offlinelist of course. If the contact is already set to state, the request is ignored.
Parameters:
strNick - String specifying the contact affected.
state - String specifying the state, i.e. the states specified in NotificationTokens.
channels - if state is STR_STATE_JOINED or STR_STATE_LEFT the channel joined or left. not used yet. If state is STR_STATE_ONLINE channels contains a list of all channels joined by nick divided by ';'s.

ship

public boolean ship(java.lang.String nick,
                    java.lang.String status,
                    ShipWindow shipWindow)
Give or fetch someone his ship.
Parameters:
nick - the person, who you want to give or fetch ship
status - on/off

addContact

public void addContact(java.lang.String nick)
Add a contact to the list. At this moment the contact appears to be in no channel, thence you have to use addLocation to store the channels.
Parameters:
nick - String specifying the contact.

addContactAndLocations

public void addContactAndLocations(java.lang.String nick,
                                   java.util.Enumeration channels)
Add a contact and the channels where is joined to the list.
Parameters:
nick - String specifying the contact.
channels - Enumeration containing the channels, where this contact is joined.

removeContact

public void removeContact(java.lang.String nick)
Remove a contact from the list.
Parameters:
nick - String specifying the contact.

getLocations

public java.util.Iterator getLocations(java.lang.String nick)
Get an Iterator over the channels where a contact is joined.
Parameters:
nick - String specifying the contact.

addLocation

public void addLocation(java.lang.String nick,
                        java.lang.String channel)
Add a location to a contact. If someone has joined a channel you have to invoke this to store this information.
Parameters:
nick - String specifying the contact.
channel - String specifying the channel joined.

removeLocation

public void removeLocation(java.lang.String nick,
                           java.lang.String channel)
Remove a location from a contact. If someone has left a channel you have to invoke this to store this information.
Parameters:
nick - String specifying the contact.
channel - String specifying the channel left.

getPassword

public java.lang.String getPassword(java.lang.String message)
Opens an InputDialog and returns the entered Text
Parameters:
message - The message shown in the Dialog's title

changeTopic

public void changeTopic(java.lang.String channel)
prompt for the topic of a specified channel and tell the server about it
Parameters:
channel - guess...

topicChanged

public void topicChanged(java.lang.String channel,
                         java.lang.String nick,
                         java.lang.String topic)
Change the current topic
Parameters:
channel - which channel should get a new topic?
nick - who changed the topic
topic - the new topic