edu.uiuc.cs.net.DPRPManager
Class GUI_DPRPClient

java.lang.Object
  |
  +--edu.uiuc.cs.net.DPRPManager.GUI_DPRPClient
All Implemented Interfaces:
java.awt.event.ActionListener, DPRPClientConstants, DPRPLeaseListener, DPRPLeaseListenerConstants, java.util.EventListener

public class GUI_DPRPClient
extends java.lang.Object
implements java.awt.event.ActionListener, DPRPLeaseListener, DPRPClientConstants

A GUI version of the ubiquituous DPRP client. I'm going to need to keep some sort of list of DPRPClient object instances, so that when I have the JTable setup, and users' mess with individual leases, we can get back with the client that has that lease outstanding, and make the change. Actually, it's going to need to be a list of DPRPClients, and their ThreadID's (so that they can be interrupted while they are sleeping).

Explore JOptionPane, for simple dialogs (errors and such).

For the JTable button thing, I'm going to have to setup a mouse listener, that pokes a bunch of variables with the current data that is highlighted. Also, it will make the button.setEnabled(true) whenever something is highlighted. At start, this will be false, and if we can ever de-select entirely, then it must be false (dunno if I have to worry about that).

Version:
1.1 - October 30th, 2001
Author:
Andy Reitz (areitz@cs.uiuc.edu)

Field Summary
private  javax.swing.JTextField cliIPField
          The text field that holds the client IP address.
private  java.lang.String curProtocolSelected
          A reference to the current protocol selected in the list box.
private  DPRPLease curSelectedLease
          A reference to the DPRPLease object that is in the current, user-selected row in the table.
private  javax.swing.JFrame frame
          The main frame for the entire application.
private  java.lang.String frameTitle
          The name of the main GUI window.
private static java.lang.String HELP_PATH
          The default path for help files.
private  java.util.HashMap lease2ClientMap
          A map of leases that this client has outstanding.
private  javax.swing.JTextField reqDurationField
          The text field for the requested lease duration, in seconds.
private  javax.swing.JTextField reqPortField
          The text field for the requested port.
private  javax.swing.JComboBox reqProtocolList
          The list box, where the protocol is selected.
private  javax.swing.JTextField srvIPField
          The text field that holds the DPRP-enabled gateway's IP address.
private  javax.swing.JTextField srvPortField
          The text field that holds the port on the DPRP-enabled gateway.
private  javax.swing.JTable table
          The table itself is now a global reference, so that the buttons can be grey'd out upon lease termination.
private  DPRPLeaseTableModel tableModel
          My localized model for the JTable of outstanding DPRP leases.
private  javax.swing.JButton terminateButton
          Terminate lease button; Global for table-grey-out purposes.
private  javax.swing.JButton updateButton
          Update lease button; Global for table-grey-out purposes.
 
Fields inherited from interface edu.uiuc.cs.net.DPRPManager.DPRPLeaseListenerConstants
NEW_LEASE_EVENT, REMOVE_LEASE_EVENT, UPDATE_LEASE_EVENT
 
Fields inherited from interface edu.uiuc.cs.net.DPRPManager.DPRPClientConstants
CLI_COMMAND, CLI_FORCE_LEASE_TERMINATE, CLI_FORCE_LEASE_UPDATE, CLI_TERMINATE_THREAD, cliIPFieldString, HALT, HALT_ACQUIRE_LEASE, HALT_INTERRUPTED, HALT_INVALID_SLEEP_TIMER, HALT_NO_RESPONSE, HALT_SERVER_NACK, HALT_T2_EXPIRED, NUM_RETRIES, okButtonString, reqDurationFieldString, reqPortFieldString, reqProtocolFieldString, resetButtonString, srvIPFieldString, srvPortFieldString, terminateButtonString, updateButtonString
 
Constructor Summary
GUI_DPRPClient()
          Constructor.
 
Method Summary
 void acquireNewLease()
          Attempts to get a new DPRPLease, based upon the current form information.
 void actionPerformed(java.awt.event.ActionEvent e)
          This will be called whenever the "get lease" button is smacked, or the "reset to defaults" button.
private  javax.swing.JEditorPane createHelpPane(java.lang.String fname)
          Loads an HTML document into a JEditorPane instance, and returns said instance.
private  void createMainWindowLayout()
          Creates the main window layout, which consists of a top and bottom half.
private  javax.swing.JPanel createManageLeasesPanel()
          Paints the JTabel that displays currently outstanding leases.
 void createMenuBar()
          Create (and populate) the menubar.
 void createNewHelpDialog(java.lang.String labelText, java.lang.String fname)
          Throws up a help dialog, showing the given filename inside.
private  javax.swing.JPanel createNewLeasePanel()
          Creates the panel that accepts user-input and control of requesting new leases.
private  void launchGUI()
          Handles all drawing on the main frame, and display of said frame.
 void loadLeases(java.io.File inpFile)
          Loads in a set of leases from disk, replacing any currently held leases with the from-disk set.
static void main(java.lang.String[] args)
          The main() method: the action starts here.
private  void makeLabelTextLayout(javax.swing.JComponent[][] parts, java.awt.GridBagLayout gridbag, java.awt.Container container)
          Drops the labels and text fields into the grid bag layout.
 void receiveLease(DPRPLeaseEvent ple)
          This gets called whenever a DPRPClient object instance decides that it has a lease that we need to see.
private  void resetTextFieldsToDefaults()
          Reset all of the text input fields for establishing a new lease to their default values.
 void saveLeases(java.io.File outFile)
          Writes out the currently held leases to disk.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

frameTitle

private java.lang.String frameTitle
The name of the main GUI window.

frame

private javax.swing.JFrame frame
The main frame for the entire application.

curProtocolSelected

private java.lang.String curProtocolSelected
A reference to the current protocol selected in the list box.

lease2ClientMap

private java.util.HashMap lease2ClientMap
A map of leases that this client has outstanding. The keys are actual DPRPLease object references, and the associated values are to the DPRPClient objects that manage said lease. This mapping is needed so that the appropriate DPRPClient can be interrupted when the user wants to update and/or terminate a specific lease. HashMap isn't thread-safe. I really should pick something else, ya?

tableModel

private DPRPLeaseTableModel tableModel
My localized model for the JTable of outstanding DPRP leases. I need to have a class-global reference to this model, so that it can be added as a listener to newly-instantiated clients.

table

private final javax.swing.JTable table
The table itself is now a global reference, so that the buttons can be grey'd out upon lease termination.

updateButton

private final javax.swing.JButton updateButton
Update lease button; Global for table-grey-out purposes.

terminateButton

private final javax.swing.JButton terminateButton
Terminate lease button; Global for table-grey-out purposes.

curSelectedLease

private DPRPLease curSelectedLease
A reference to the DPRPLease object that is in the current, user-selected row in the table. For some reason, this seems ugly, yet, I don't know of any better way.

cliIPField

private javax.swing.JTextField cliIPField
The text field that holds the client IP address.

srvIPField

private javax.swing.JTextField srvIPField
The text field that holds the DPRP-enabled gateway's IP address.

srvPortField

private javax.swing.JTextField srvPortField
The text field that holds the port on the DPRP-enabled gateway. I should probably do something fancy, like change the document model, so that only numbers can be inputted. But, I'm doing error checking so, who cares?!?!?

reqProtocolList

private javax.swing.JComboBox reqProtocolList
The list box, where the protocol is selected.

reqPortField

private javax.swing.JTextField reqPortField
The text field for the requested port. 0 means take next available.

reqDurationField

private javax.swing.JTextField reqDurationField
The text field for the requested lease duration, in seconds.

HELP_PATH

private static final java.lang.String HELP_PATH
The default path for help files.
Constructor Detail

GUI_DPRPClient

public GUI_DPRPClient()
Constructor.
Method Detail

main

public static void main(java.lang.String[] args)
The main() method: the action starts here.

launchGUI

private void launchGUI()
Handles all drawing on the main frame, and display of said frame. This method invokes sub-methods, in order to get each half of the display setup, it slaps those JPanels on, and then sets the whole thing to be visible.

createMainWindowLayout

private void createMainWindowLayout()
Creates the main window layout, which consists of a top and bottom half. The top half is where new leases are requested, and the bottom half is where currently-held leases are managed.

createNewLeasePanel

private javax.swing.JPanel createNewLeasePanel()
Creates the panel that accepts user-input and control of requesting new leases. Essentially, it just creates all of the labels and text input fields, and slaps them down in a pseudo 3x4 table arrangement.

createManageLeasesPanel

private javax.swing.JPanel createManageLeasesPanel()
Paints the JTabel that displays currently outstanding leases.

acquireNewLease

public void acquireNewLease()
Attempts to get a new DPRPLease, based upon the current form information. This method goes ahead and extracts the form data, and error checks it. If this data is found to be kosher, it is stuffed into the DPRPClient instance, and the lease fetching process is launched.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
This will be called whenever the "get lease" button is smacked, or the "reset to defaults" button.
Specified by:
actionPerformed in interface java.awt.event.ActionListener

receiveLease

public void receiveLease(DPRPLeaseEvent ple)
This gets called whenever a DPRPClient object instance decides that it has a lease that we need to see. Handling an update request is going to be tricky -- we're going to have to use our list of DPRPClients, and match the getSource() on the event to the appropriate client instance.
Specified by:
receiveLease in interface DPRPLeaseListener

makeLabelTextLayout

private void makeLabelTextLayout(javax.swing.JComponent[][] parts,
                                 java.awt.GridBagLayout gridbag,
                                 java.awt.Container container)
Drops the labels and text fields into the grid bag layout.

resetTextFieldsToDefaults

private void resetTextFieldsToDefaults()
Reset all of the text input fields for establishing a new lease to their default values.

createMenuBar

public void createMenuBar()
Create (and populate) the menubar.

saveLeases

public void saveLeases(java.io.File outFile)
Writes out the currently held leases to disk. The file name that we write to is chosen by the user, via one of those spiffy Swing-standard file chooser dialogs. This method checks to make sure the leases are valid while writing them out, and refuses to write an expired lease. Said lease will then be removed from the client-side of things.
Parameters:
outFile - The output file for the leases.

loadLeases

public void loadLeases(java.io.File inpFile)
Loads in a set of leases from disk, replacing any currently held leases with the from-disk set. Note, this means that if we have currently outstanding leases, they will be TERMINATED. This means that they will be removed not only from the client, but from the server as well. This is because if they are removed from the client, then there is no active way to manage them, and thus these leases should no longer exist. Thus, this functionality must be used with caution. :)
Parameters:
inpFile - The file name, from which we cull the leases.

createNewHelpDialog

public void createNewHelpDialog(java.lang.String labelText,
                                java.lang.String fname)
Throws up a help dialog, showing the given filename inside.

createHelpPane

private javax.swing.JEditorPane createHelpPane(java.lang.String fname)
Loads an HTML document into a JEditorPane instance, and returns said instance. Returns null if any error. Mostly stolen from 'TextSamplerDemo.java', available on from the Swing tutorial on java.sun.com.
Parameters:
fname - The name of the help file to be opened, relative to the cwd.
Returns:
A JEditorPane containing the HTML, or NULL if the file wasn't found.