thinkAlike
Class ProgramControl

java.lang.Object
  extended by thinkAlike.ProgramControl
All Implemented Interfaces:
XmppListener

public class ProgramControl
extends java.lang.Object
implements XmppListener

This class handels all the logic of the application. It also implements the XMPPListener interface for handeling actions that happend on the XMPP connection. It is created by the a ScreenControl object, that is the startingpoint of the MIDlet.


Constructor Summary
ProgramControl(ScreenControl sc)
          Initiates the ProgramControl object to handle the logic of the application
 
Method Summary
 void captureImage()
          Handels the actual captering from the video source.
 void clearThinkAlikeSession()
          Run at the end of a session, clears the chat log and resets the thinkrequest variable.
 boolean connect()
          Generates a new Jxa object that automatically connects to an XMPP server.
 javax.microedition.lcdui.Item getCameraItem()
          Returns the actual item containg the feed from the camera to put on the display
 javax.microedition.lcdui.Image getImage()
          Returns the image assosiated with ThinkRequest session
 Jxa getJxa()
          Returns the Jxa object that handels the XMPP connection going on.
 ScreenControl getSc()
          Returns the pointer for the ScreenControl object that created this object
 ThinkRequest getThinkRequest()
          Returns the ThinkRequest object on going at the moment.
 void initilizaCamera()
          Initializes the camera with it's related media manager.
 void makeThinkRequest(java.lang.String to, java.lang.String from, java.lang.String pic, java.lang.String thinkword)
          The method creating the ThinkRequest, doing thinkgs a bit different depending on bein the initiator or the recipient.
 void onAuth()
          XmppListener internface: initiated when authorization is sucsessful
 void onAuthFailed(java.lang.String message)
          XmppListener internface: initiated when authorization fials
 void onConnFailed()
          XmppListener internface: initiated when connecting to the XMPP server fails
 void onContactEvent(java.lang.String jid, java.lang.String name, java.lang.String group, java.lang.String subscription)
          see XmppListener internface
 void onContactRemoveEvent(java.lang.String jid)
          see XmppListener internface
 void onMessageEvent(java.lang.String from, java.lang.String body)
          XmppListener internface: initiated when a message is recieved
 void onStatusEvent(java.lang.String jid, java.lang.String show, java.lang.String status)
          see XmppListener internface
 void onSubscribeEvent(java.lang.String jid)
          see XmppListener internface:
 void onThinkEvent(java.lang.String thinktype, java.lang.String from, java.lang.String pic, java.lang.String thinkword, java.lang.String word1, java.lang.String word2, java.lang.String word3)
          A special method added to the XmppListener class handeling IQ messages related to the ThinkAlike application.
 void onUnsubscribeEvent(java.lang.String jid)
          see XmppListener internface:
 void sendChatMessage()
          Initiated when in EndForm, sending the text inputted in the text box to the other part of the session-
 boolean sendMessage(java.lang.String to, java.lang.String message)
          Used to send a simple message with the Jxa object
 void setLoginParameters(java.lang.String host, java.lang.String port, java.lang.String username, java.lang.String password, java.lang.String resource)
          Setting the login parameters of the XMPP session that will later be initiated
 boolean setStatus(java.lang.String show, java.lang.String status, int priority)
          Sets the status of the XMPP connection using the Jxa object
 void setWords()
          Gets the words inputed by the recipient of the ThinkRequest from the screen and put them in the thinkrequest object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgramControl

public ProgramControl(ScreenControl sc)
Initiates the ProgramControl object to handle the logic of the application

Parameters:
sc - a pointer to the ScreenControl object that handeles all the interaction with the display
Method Detail

connect

public boolean connect()
                throws java.io.IOException
Generates a new Jxa object that automatically connects to an XMPP server.

Returns:
always true, can be used to reply if connection fails, but as implementation is now this is not necessary
Throws:
java.io.IOException - if initial connection fails

sendMessage

public boolean sendMessage(java.lang.String to,
                           java.lang.String message)
Used to send a simple message with the Jxa object

Parameters:
to - the recipient of the message
message - the message string
Returns:
not in use, can be used to return the outcome of sending the message.

setStatus

public boolean setStatus(java.lang.String show,
                         java.lang.String status,
                         int priority)
Sets the status of the XMPP connection using the Jxa object

Parameters:
show - string explaining status
status - actual status (available/unavailable)
priority - default 5, not elsewise in use
Returns:
not in use, can be used to respond to result of trying to set the status

setLoginParameters

public void setLoginParameters(java.lang.String host,
                               java.lang.String port,
                               java.lang.String username,
                               java.lang.String password,
                               java.lang.String resource)
Setting the login parameters of the XMPP session that will later be initiated

Parameters:
host - the XMPP host name
port - the port in use, most common 5222 (if secure connection: 5223)
username - the username of the actor, username@xmpphostdomain
password - password in clear text, this is one of the weakest security points of the application
resource - the resource parameter of the XMPP client, in this case, always set to /thinkalike

getSc

public ScreenControl getSc()
Returns the pointer for the ScreenControl object that created this object

Returns:
pointer to ScreenControl object

getJxa

public Jxa getJxa()
Returns the Jxa object that handels the XMPP connection going on.

Returns:
pointer to the Jxa object

getThinkRequest

public ThinkRequest getThinkRequest()
Returns the ThinkRequest object on going at the moment. Should be changed if one wants more than one ThinkRequest session going, this is not possible at the moment.

Returns:
the ongoing ThinkRequest session

clearThinkAlikeSession

public void clearThinkAlikeSession()
Run at the end of a session, clears the chat log and resets the thinkrequest variable.


makeThinkRequest

public void makeThinkRequest(java.lang.String to,
                             java.lang.String from,
                             java.lang.String pic,
                             java.lang.String thinkword)
The method creating the ThinkRequest, doing thinkgs a bit different depending on bein the initiator or the recipient. If it is the recipient it also converts the incoming string representing the picture to a raw image.

Parameters:
to - address of the recipient
from - address of the initiator
pic - picture represented by a text string
thinkword - the word that is the word

sendChatMessage

public void sendChatMessage()
Initiated when in EndForm, sending the text inputted in the text box to the other part of the session-


initilizaCamera

public void initilizaCamera()
Initializes the camera with it's related media manager.


getCameraItem

public javax.microedition.lcdui.Item getCameraItem()
Returns the actual item containg the feed from the camera to put on the display

Returns:
Camera item

captureImage

public void captureImage()
Handels the actual captering from the video source. Then resets the camera.


getImage

public javax.microedition.lcdui.Image getImage()
Returns the image assosiated with ThinkRequest session

Returns:
raw image

setWords

public void setWords()
Gets the words inputed by the recipient of the ThinkRequest from the screen and put them in the thinkrequest object. This method is called when the send button is pushed


onConnFailed

public void onConnFailed()
XmppListener internface: initiated when connecting to the XMPP server fails

Specified by:
onConnFailed in interface XmppListener

onAuth

public void onAuth()
XmppListener internface: initiated when authorization is sucsessful

Specified by:
onAuth in interface XmppListener

onAuthFailed

public void onAuthFailed(java.lang.String message)
XmppListener internface: initiated when authorization fials

Specified by:
onAuthFailed in interface XmppListener
Parameters:
message - error message related to the failiar

onMessageEvent

public void onMessageEvent(java.lang.String from,
                           java.lang.String body)
XmppListener internface: initiated when a message is recieved

Specified by:
onMessageEvent in interface XmppListener
Parameters:
from - the sender of the message
body - message body

onContactRemoveEvent

public void onContactRemoveEvent(java.lang.String jid)
see XmppListener internface

Specified by:
onContactRemoveEvent in interface XmppListener
Parameters:
jid - .

onContactEvent

public void onContactEvent(java.lang.String jid,
                           java.lang.String name,
                           java.lang.String group,
                           java.lang.String subscription)
see XmppListener internface

Specified by:
onContactEvent in interface XmppListener
Parameters:
jid - .
name - .
group - .
subscription - .

onStatusEvent

public void onStatusEvent(java.lang.String jid,
                          java.lang.String show,
                          java.lang.String status)
see XmppListener internface

Specified by:
onStatusEvent in interface XmppListener
Parameters:
jid - .
show - .
status - .

onSubscribeEvent

public void onSubscribeEvent(java.lang.String jid)
see XmppListener internface:

Specified by:
onSubscribeEvent in interface XmppListener
Parameters:
jid - .

onUnsubscribeEvent

public void onUnsubscribeEvent(java.lang.String jid)
see XmppListener internface:

Specified by:
onUnsubscribeEvent in interface XmppListener
Parameters:
jid - .

onThinkEvent

public void onThinkEvent(java.lang.String thinktype,
                         java.lang.String from,
                         java.lang.String pic,
                         java.lang.String thinkword,
                         java.lang.String word1,
                         java.lang.String word2,
                         java.lang.String word3)
A special method added to the XmppListener class handeling IQ messages related to the ThinkAlike application. Some of the parameters might be null depending on if the event is a request or response.

Specified by:
onThinkEvent in interface XmppListener
Parameters:
thinktype - either request or response
from - the sender of the request
pic - text representation of the picture
thinkword - the word
word1 - .
word2 - .
word3 - .