FileTransfer.v1_1
Class FTClientWindow

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--FileTransfer.v1_1.FTClientWindow
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public class FTClientWindow
extends javax.swing.JFrame

FTClientWindow is the Graphical User Interface (GUI) of the FileTransfer application. It contains two panels called transferPane and receivePane. It is used when the FTClient is transfering a file to another FTClient and receiving a file from another FTClient, respectively.

Version:
1.0
Author:
Lars Erik Liljebäck
See Also:
Serialized Form

Inner Class Summary
 class FTClientWindow.CancelThread
          CancelThread extends Thread.
 class FTClientWindow.FTListener
          FTListener is an internal listener class which handles both WindowEvents and ActionEvents generated in the FTClientWindow.
(package private)  class FTClientWindow.TransferThread
          TransferThread extends Thread.
 
Inner classes inherited from class javax.swing.JFrame
javax.swing.JFrame.AccessibleJFrame
 
Inner classes inherited from class java.awt.Frame
java.awt.Frame.AccessibleAWTFrame
 
Inner classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock
 
Field Summary
private  java.lang.String actorName
           
private  java.awt.Color background
           
private  javax.swing.JButton browse
           
private  int bytesize
           
private  javax.swing.JMenuItem bytesizeMenu
           
private  javax.swing.JButton cancelReceive
           
private  javax.swing.JButton cancelTransfer
           
private  java.awt.CardLayout card
          The layoutmanager of the contentpane
private  FTClient client
          Reference to the FTClient.
private  javax.swing.JPanel contentPane
          The contentpane
private  javax.swing.JMenuItem destDirMenu
           
private  java.lang.String destinationDirectory
           
private  javax.swing.JMenuItem exitMenu
           
private  java.io.File file
           
private  java.awt.Font font
           
private  java.io.FileOutputStream fos
           
private  javax.swing.JPanel receivePane
          The panel used for configuring reception of a file
private  javax.swing.JProgressBar receiveProgressBar
           
private  javax.swing.JButton send
           
private  FTClientWindow.TransferThread thread
           
private  javax.swing.JPanel transferPane
          The panel used for configuring transfer of a file
private  javax.swing.JProgressBar transferProgressBar
           
private  javax.swing.JTextField txtDestinationFile
           
private  javax.swing.JTextField txtReceiver
           
private  javax.swing.JTextField txtSender
           
private  javax.swing.JTextField txtSourceFile
           
 
Fields inherited from class javax.swing.JFrame
accessibleContext, defaultCloseOperation, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
base, CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, frameSerializedDataVersion, HAND_CURSOR, icon, ICONIFIED, mbManagement, menuBar, MOVE_CURSOR, N_RESIZE_CURSOR, nameCounter, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, ownedWindows, resizable, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, serialVersionUID, state, SW_RESIZE_CURSOR, TEXT_CURSOR, title, W_RESIZE_CURSOR, WAIT_CURSOR, weakThis
 
Fields inherited from class java.awt.Window
active, dbg, focusMgr, inputContext, inputContextLock, OPENED, ownedWindowList, showWithParent, warningString, windowListener, windowSerializedDataVersion
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, width, windowClosingException, windowListenerK, visible, x, y
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FTClientWindow(FTClient client)
          Creates a new FTClientWindow.
 
Method Summary
 void cancelFileTransfer()
          Called when either the transmitter or the receiver has selected to cancel the filetransfer.
private  void dbg(java.lang.String dbg)
          Writes a debugging line to the actor's baseframe window.
 void filePart(byte[] bytes)
          Called when the FTClient received a new part of the file being transferred.
 void fileTransferFinished()
          Called to notify the receiving FTClient that the filetransfer is finished.
 boolean fileTransferRequest(java.lang.String sender, java.lang.String filename, java.lang.String filesize)
          Called when the FTClient receives a request for filetransfer from another FTClient.
 int getBytesize()
          Returns the size of the byte array used to transfer file parts.
 java.lang.String getDestinationDirectory()
          Returns the current directory used to store received files.
 java.lang.String getReceiver()
          Returns the GAI of the receiving FTClient.
 java.lang.String getSourceFile()
          Returns the path to the file selected to be transferred.
private  void initReceivePane(javax.swing.JPanel p)
          Creates the components for the receive panel, initializes them and lays them out using GridBagLayout.
private  void initTransferPane(javax.swing.JPanel p)
          Creates the components for the transfer panel, initializes them and lays them out using GridBagLayout.
static void main(java.lang.String[] args)
          Used for debugging GUI.
 void resumeFileTransfer(java.lang.String receiverGAI, java.lang.String filepath, java.lang.String filesize, java.lang.String numOfBytes)
          Called when the FTClient has been resumed and a filetransfer shall be resumed.
 boolean resumeFileTransferRequest(java.lang.String sender, java.lang.String sourceFile, java.lang.String filesize, int bytesTransferred)
          Called when the FTClient receives a request for resuming a filetransfer from another FTClient.
 void setActorName(java.lang.String name)
          Sets the name of the FTClient belonging to this FTClientWindow.
 void setBytesize(int size)
          Sets the size of the byte array used to transfer file parts.
private  void setComponentsEnabled(boolean isTransfering)
          Sets some of the GUI components enabled, disabled, editable or not editable depending on the specified boolean value.
 void setDestinationDirectory(java.lang.String dir)
          Sets the current directory used to store received files.
 void setReceiver(java.lang.String gai)
          Sets the GAI of the receiving FTClient.
 void setSourceFile(java.lang.String filepath)
          Sets the path to the file selected to be transferred.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, createRootPaneException, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled, paramString, processKeyEvent, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
, addNotify, addToFrameList, constructComponentName, finalize, getCursorType, getFrames, getIconImage, getMenuBar, getState, getTitle, initIDs, isResizable, postProcessKeyEvent, readObject, remove, removeFromFrameList, removeNotify, setCursor, setIconImage, setMenuBar, setResizable, setState, setTitle, writeObject
 
Methods inherited from class java.awt.Window
addOwnedWindow, addWindowListener, adjustListeningChildren, applyResourceBundle, applyResourceBundle, connectOwnedWindow, dispatchEventImpl, dispose, eventEnabled, getFocusOwner, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getOwnedWindows, getOwner, getToolkit, getWarningString, hide, isActive, isShowing, nextFocus, ownedInit, pack, postEvent, postWindowEvent, preProcessKeyEvent, processEvent, removeOwnedWindow, removeWindowListener, resetGC, setCursor, setFocusOwner, setWarningString, show, toBack, toFront, transferFocus
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventToSelf, doLayout, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getMouseEventTarget, getPreferredSize, getWindow, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, numListening, paint, paintComponents, paintHeavyweightComponents, postsOldMouseEvents, preferredSize, print, printComponents, printHeavyweightComponents, processContainerEvent, proxyEnableEvents, proxyRequestFocus, remove, removeAll, removeContainerListener, setFont, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getSize, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isRecursivelyVisible, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

client

private FTClient client
Reference to the FTClient.

contentPane

private javax.swing.JPanel contentPane
The contentpane

receivePane

private javax.swing.JPanel receivePane
The panel used for configuring reception of a file

transferPane

private javax.swing.JPanel transferPane
The panel used for configuring transfer of a file

card

private java.awt.CardLayout card
The layoutmanager of the contentpane

browse

private javax.swing.JButton browse

cancelReceive

private javax.swing.JButton cancelReceive

cancelTransfer

private javax.swing.JButton cancelTransfer

send

private javax.swing.JButton send

receiveProgressBar

private javax.swing.JProgressBar receiveProgressBar

transferProgressBar

private javax.swing.JProgressBar transferProgressBar

txtDestinationFile

private javax.swing.JTextField txtDestinationFile

txtReceiver

private javax.swing.JTextField txtReceiver

txtSender

private javax.swing.JTextField txtSender

txtSourceFile

private javax.swing.JTextField txtSourceFile

destDirMenu

private javax.swing.JMenuItem destDirMenu

bytesizeMenu

private javax.swing.JMenuItem bytesizeMenu

exitMenu

private javax.swing.JMenuItem exitMenu

font

private java.awt.Font font

background

private java.awt.Color background

file

private java.io.File file

thread

private FTClientWindow.TransferThread thread

fos

private java.io.FileOutputStream fos

actorName

private java.lang.String actorName

destinationDirectory

private java.lang.String destinationDirectory

bytesize

private int bytesize
Constructor Detail

FTClientWindow

public FTClientWindow(FTClient client)
Creates a new FTClientWindow. Creates and configures the GUI components.
Parameters:
client - Reference to the FTClient.
Method Detail

cancelFileTransfer

public void cancelFileTransfer()
Called when either the transmitter or the receiver has selected to cancel the filetransfer. If the reference to the TransferThread is not null, it is a sign that the receiver was the one cancelling. The transfer thread is then asked to stop transfering. If the reference is null, it is a sign that the transmitter was the one cancelling. Then the GUI is just configured appropriately.

filePart

public void filePart(byte[] bytes)
Called when the FTClient received a new part of the file being transferred. The filepart is a byte array of a predefined size (the bytesize property). The bytes in the array are appended to the file.
Parameters:
bytes - The byte array constituting the filepart.

fileTransferFinished

public void fileTransferFinished()
Called to notify the receiving FTClient that the filetransfer is finished. The FileOutputStream is closed, the transfer panel is shown and the GUI components are configured appropriately.

fileTransferRequest

public boolean fileTransferRequest(java.lang.String sender,
                                   java.lang.String filename,
                                   java.lang.String filesize)
Called when the FTClient receives a request for filetransfer from another FTClient. Shows a Popup box asking the user if he accepts the file. If he accepts the receive panel is shown and the GUI components are configured.
Parameters:
sender - The GAI of the FTClient sending the request.
filename - The name of the file.
filesize - The size of the file.
Returns:
Returns true if the user accepted the file, false otherwise.

getBytesize

public int getBytesize()
Returns the size of the byte array used to transfer file parts.
Returns:
The current bytesize.

getDestinationDirectory

public java.lang.String getDestinationDirectory()
Returns the current directory used to store received files.
Returns:
The current destination directory.

getReceiver

public java.lang.String getReceiver()
Returns the GAI of the receiving FTClient.
Returns:
The GAI of the receiver.

getSourceFile

public java.lang.String getSourceFile()
Returns the path to the file selected to be transferred.
Returns:
The current sourcefile.

resumeFileTransfer

public void resumeFileTransfer(java.lang.String receiverGAI,
                               java.lang.String filepath,
                               java.lang.String filesize,
                               java.lang.String numOfBytes)
Called when the FTClient has been resumed and a filetransfer shall be resumed. Uses the parameters to configure a TransferThread to start transfering where another thread left off.
Parameters:
receiverGAI - The GAI of the receiving FTClient.
filepath - The path to the file to be transferred.
filesize - The size of the file to be transferred.
numOfBytes - Specifies how much of the file that has been transferred.

resumeFileTransferRequest

public boolean resumeFileTransferRequest(java.lang.String sender,
                                         java.lang.String sourceFile,
                                         java.lang.String filesize,
                                         int bytesTransferred)
Called when the FTClient receives a request for resuming a filetransfer from another FTClient. Shows a Popup box asking the user if he accepts to resume the filetransfer. If he accepts the receive panel is shown and the GUI components are configured.
Parameters:
sender - The GAI of the FTClient sending the request.
filename - The name of the file.
filesize - The size of the file.
bytesTransferred - The number of bytes that have been transferred.
Returns:
Returns true if the user accepted the resuming, false otherwise.

setActorName

public void setActorName(java.lang.String name)
Sets the name of the FTClient belonging to this FTClientWindow. This is used in the title of the window.
Parameters:
name - The name of the FTClient.

setBytesize

public void setBytesize(int size)
Sets the size of the byte array used to transfer file parts.
Parameters:
size - The new bytesize.

setDestinationDirectory

public void setDestinationDirectory(java.lang.String dir)
Sets the current directory used to store received files.
Parameters:
dir - The new destination directory.

setReceiver

public void setReceiver(java.lang.String gai)
Sets the GAI of the receiving FTClient.
Parameters:
gai - The new GAI of the receiver.

setSourceFile

public void setSourceFile(java.lang.String filepath)
Sets the path to the file selected to be transferred.
Parameters:
filename - The new sourcefile.

dbg

private void dbg(java.lang.String dbg)
Writes a debugging line to the actor's baseframe window.
Parameters:
dbg - The debugging line.

initReceivePane

private void initReceivePane(javax.swing.JPanel p)
Creates the components for the receive panel, initializes them and lays them out using GridBagLayout.
Parameters:
p - The receive panel.

initTransferPane

private void initTransferPane(javax.swing.JPanel p)
Creates the components for the transfer panel, initializes them and lays them out using GridBagLayout.
Parameters:
p - The transfer panel.

setComponentsEnabled

private void setComponentsEnabled(boolean isTransfering)
Sets some of the GUI components enabled, disabled, editable or not editable depending on the specified boolean value.
Parameters:
isTransfering - Is true if this FTClient is currently transfering a file, else if it false.

main

public static void main(java.lang.String[] args)
Used for debugging GUI.