ControlBeans
Class TCPIPCommunicator

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ControlBeans.AbstractCommunicator
                                |
                                +--ControlBeans.TCPIPCommunicator

public class TCPIPCommunicator
extends AbstractCommunicator
implements java.io.Serializable, java.awt.event.ActionListener, java.awt.event.FocusListener

This class implements a control component which can send and receive values over a TCP/IP network. For each value it wishes to send or receive, it does so according to the following protocol:
Type: an integer value describing what type of value will follow.
Tag: an integer value to allow the recipient to determine where to distribute the data.
Data: either an integer, double or string.
Time: an optional double value timestamp.

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
protected static int DOUBLE_AND_TIME
          Set if two doubles should be received or sent.
protected static int INPUT_SOCKET_ERROR
          Set if an inputsocket error has been caught.
protected static int INPUT_STREAM_BROKEN_ERROR
          Set if the inputstream has been broken.
protected static int INPUT_STREAM_ERROR
          Set if an inputstream error has been caught.
protected static int INPUT_STREAM_LOST_ERROR
          Set if the input stream disapeared for some reason.
protected static int INT_AND_TIME
          Set if both an integer and a double should be received or sent.
protected static int ONLY_DOUBLE
          Set if a single double has been received or should be sent.
protected static int ONLY_INT
          Set if a single integer has been received or should be sent.
protected static int ONLY_STRING
          Set if a single string has been received or should be sent.
protected static int OUTPUT_SOCKET_ERROR
          Set if an outputsocket error has been caught.
protected static int OUTPUT_STREAM_BROKEN_ERROR
          Set if the outputstream has been broken.
protected static int OUTPUT_STREAM_ERROR
          Set if an outputstream error has been caught.
protected static int OUTPUT_STREAM_LOST_ERROR
          Set if the output stream disapeared for some reason.
protected static int PROTOCOL_ERROR
          Set if the received data does not conform to the protocol.
protected static int STRING_AND_TIME
          Set if both a string and a double should be received or sent.
protected static int UNKNOWN_HOST_ERROR
          Set if host cannot be found.
 
Fields inherited from class ControlBeans.AbstractCommunicator
CURRENT_TIME, myID
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
TCPIPCommunicator()
          Constructs a new TCPIPCommunicator.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Invoked when the user either changes the value of one of the textfields or clicks the connectbutton.
 void finalize()
          Closes everything at shutdown.
 void focusGained(java.awt.event.FocusEvent e)
          Invoked when either of the textfields gain focus.
 void focusLost(java.awt.event.FocusEvent e)
          Invoked when either of the textfields lose focus.
 boolean getEditable()
          Gets whether or not the textfields within the communicator are visible and hence editable.
 java.lang.String getHostName()
          Gets the name of host computer.
 int getReceiverPort()
          Gets the number of the port used for incoming values.
 int getSenderPort()
          Gets the number of the port used for outgoing values.
 boolean getStatusfield()
          Gets whether or not the statusfield within the communicator is visible.
protected  void sendValue(double value, int aTag, double time)
          Used for sending a double value over the network.
protected  void sendValue(int value, int aTag, double time)
          Used for sending an integer value over the network.
protected  void sendValue(java.lang.String value, int aTag, double time)
          Used for sending a string value over the network.
 void setEditable(boolean value)
          Sets whether or not the textfields within the communicator should be visible and hence editable.
 void setHostName(java.lang.String value)
          Sets the name of host computer.
 void setReceiverPort(int value)
          Sets the number of the port used for incoming values.
 void setSenderPort(int value)
          Sets the number of the port used for outgoing values.
 void setStatusfield(boolean value)
          Sets whether or not the statusfield within the communicator should be visible.
 
Methods inherited from class ControlBeans.AbstractCommunicator
putValue, putValue, putValue, registerComponentEvent, requestValues
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getWidth, getVisibleRect, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONLY_INT

protected static final int ONLY_INT
Set if a single integer has been received or should be sent.

ONLY_DOUBLE

protected static final int ONLY_DOUBLE
Set if a single double has been received or should be sent.

ONLY_STRING

protected static final int ONLY_STRING
Set if a single string has been received or should be sent.

INT_AND_TIME

protected static final int INT_AND_TIME
Set if both an integer and a double should be received or sent.

DOUBLE_AND_TIME

protected static final int DOUBLE_AND_TIME
Set if two doubles should be received or sent.

STRING_AND_TIME

protected static final int STRING_AND_TIME
Set if both a string and a double should be received or sent.

OUTPUT_SOCKET_ERROR

protected static final int OUTPUT_SOCKET_ERROR
Set if an outputsocket error has been caught.

OUTPUT_STREAM_ERROR

protected static final int OUTPUT_STREAM_ERROR
Set if an outputstream error has been caught.

INPUT_SOCKET_ERROR

protected static final int INPUT_SOCKET_ERROR
Set if an inputsocket error has been caught.

INPUT_STREAM_ERROR

protected static final int INPUT_STREAM_ERROR
Set if an inputstream error has been caught.

OUTPUT_STREAM_BROKEN_ERROR

protected static final int OUTPUT_STREAM_BROKEN_ERROR
Set if the outputstream has been broken.

INPUT_STREAM_BROKEN_ERROR

protected static final int INPUT_STREAM_BROKEN_ERROR
Set if the inputstream has been broken.

PROTOCOL_ERROR

protected static final int PROTOCOL_ERROR
Set if the received data does not conform to the protocol.

UNKNOWN_HOST_ERROR

protected static final int UNKNOWN_HOST_ERROR
Set if host cannot be found.

OUTPUT_STREAM_LOST_ERROR

protected static final int OUTPUT_STREAM_LOST_ERROR
Set if the output stream disapeared for some reason.

INPUT_STREAM_LOST_ERROR

protected static final int INPUT_STREAM_LOST_ERROR
Set if the input stream disapeared for some reason.
Constructor Detail

TCPIPCommunicator

public TCPIPCommunicator()
Constructs a new TCPIPCommunicator.
Method Detail

finalize

public void finalize()
Closes everything at shutdown.
Overrides:
finalize in class java.lang.Object

getEditable

public boolean getEditable()
Gets whether or not the textfields within the communicator are visible and hence editable.
Returns:
true if the textfields are visible; false otherwise.

setEditable

public void setEditable(boolean value)
Sets whether or not the textfields within the communicator should be visible and hence editable.
Parameters:
value - true if the textfields should be visible; false otherwise.

getStatusfield

public boolean getStatusfield()
Gets whether or not the statusfield within the communicator is visible.
Returns:
true if the stausfield is visible; false otherwise.

setStatusfield

public void setStatusfield(boolean value)
Sets whether or not the statusfield within the communicator should be visible.
Parameters:
value - true if the statusfield should be visible; false otherwise.

getHostName

public java.lang.String getHostName()
Gets the name of host computer. This is the computer which this communicator will attempt to connect to.
Returns:
the name of the host computer.

setHostName

public void setHostName(java.lang.String value)
Sets the name of host computer. This is the computer which this communicator will attempt to connect to.
Parameters:
value - the desired name of the host computer.

getReceiverPort

public int getReceiverPort()
Gets the number of the port used for incoming values.
Returns:
the port number.

setReceiverPort

public void setReceiverPort(int value)
Sets the number of the port used for incoming values.
Parameters:
value - the desired port number.

getSenderPort

public int getSenderPort()
Gets the number of the port used for outgoing values.
Returns:
the port number.

setSenderPort

public void setSenderPort(int value)
Sets the number of the port used for outgoing values.
Parameters:
value - the desired port number.

sendValue

protected void sendValue(int value,
                         int aTag,
                         double time)
Used for sending an integer value over the network.
NOTE: This method is automatically invoked by AbstractCommunicator when it wishes to send a value and should therefore not be called directly by the user.
Overrides:
sendValue in class AbstractCommunicator
Parameters:
value - the value to be transmitted
aTag - the tag of components to receive the value
time - a time tag for the value

sendValue

protected void sendValue(double value,
                         int aTag,
                         double time)
Used for sending a double value over the network.
NOTE: This method is automatically invoked by AbstractCommunicator when it wishes to send a value and should therefore not be called directly by the user.
Overrides:
sendValue in class AbstractCommunicator
Parameters:
value - the value to be transmitted
aTag - the tag of components to receive the value
time - a time tag for the value

sendValue

protected void sendValue(java.lang.String value,
                         int aTag,
                         double time)
Used for sending a string value over the network.
NOTE: This method is automatically invoked by AbstractCommunicator when it wishes to send a value and should therefore not be called directly by the user.
Overrides:
sendValue in class AbstractCommunicator
Parameters:
value - the value to be transmitted
aTag - the tag of components to receive the value
time - a time tag for the value

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Invoked when either of the textfields gain focus.
NOTE: This method is invoked by the AWT event handling and should therefore never be called directly by the user.
Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
e - the event describing that a component gained focus.

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Invoked when either of the textfields lose focus. When that happens, this communicator will check to see that no illegal values have been entered in the textfield (such as a invalid portnumber).
NOTE: This method is invoked by the AWT event handling and should therefore never be called directly by the user.
Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
e - the event describing that a component gained focus.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Invoked when the user either changes the value of one of the textfields or clicks the connectbutton.
NOTE: This method is invoked by the AWT event handling and should therefore never be called directly by the user.
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the event describing that someone either clicked the button or changed the text in one of the textfields.