org.peace_tools.core
Class WorkspaceChooser

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Dialog
                  extended by javax.swing.JDialog
                      extended by org.peace_tools.core.WorkspaceChooser
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants

public class WorkspaceChooser
extends javax.swing.JDialog
implements java.awt.event.ActionListener

This class provides a pretty sophisticated dialog box that is displayed initially to the user to select a work space. A work space is simply a directory in which PEACE GUI stores all the files that are pertinent to a given GUI session. This class is used in the following manner:

  1. The main() method creates an instance of this class and calls the createTabs() method to create all the necessary tabs in this dialog box. If the tab creation fails, then the GUI exits.
  2. If this is the first time PEACE is being launched (that is the default PEACE directory does not exist) then this method ensures that the user accepts the license agreement, creates the default working directory for PEACE.
  3. When a user selects a valid work space this method sets up the work space instance variable and the dialog winds up.
  4. The main method uses the work space directory for further use to create the main frame.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JDialog
javax.swing.JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog, java.awt.Dialog.ModalExclusionType, java.awt.Dialog.ModalityType
 
Nested classes/interfaces inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  CustomPanel cp
          A custom panel that actually has the PEACE logo as the background image.
private  boolean firstLaunch
          Flag to indicate if this is the first time ever the user is running PEACE GUI.
private static java.lang.String FirstTimeMsg
          A static piece of text that is prepended to the license text when PEACE is launched for the first time to provide the user with some additional information.
private  PEACE peace
          Reference to the main PEACE class.
private static java.lang.String Separator
          A simple separator to make the license text look pretty.
private static long serialVersionUID
          The generated serial version ID to keep the Java compiler happy about serializing this class.
private  boolean showFirstTimeMsg
          Flag that tracks if the first time welcome message has already been displayed or now.
private  javax.swing.JTabbedPane tabs
          The set of tabs that are displayed in this dialog for the user to work with.
private  java.lang.String workspace
          The selected work space that is set after the user successfully chooses a work space.
private  javax.swing.JComboBox wsList
          The list of work spaces that the user can choose from or edit to start up the GUI session.
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Dialog
DEFAULT_MODALITY_TYPE
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
WorkspaceChooser(javax.swing.JFrame owner, PEACE peace)
          The constructor.
 
Method Summary
private  void accept(java.awt.event.ActionEvent event)
          This is a refactored (to keep code clutter to a minimum in the actionPerformed() method) method that is called only from the actionPerformed() method whenever the user clicks on the "Accept" button in the license tab.
 void actionPerformed(java.awt.event.ActionEvent event)
          This method handles the actions associated with various controls in the dialog.
private  javax.swing.JComponent createChooserDialog(boolean firstTime)
          This is a helper method that creates the work space chooser dialog that prompts the user to choose a work space for this session of the GUI.
private  javax.swing.JComponent createLicenceTab(boolean firstTime)
          This is a helper method that is used to create the license tab in the work space chooser.
 boolean createTabs()
          Helper method to setup the tabs to be displayed in this frame.
 java.lang.String getWorkspace()
          Obtain the work space that was successfully selected by the user.
private  void loadWorkspaceList(boolean firstTime, javax.swing.JComboBox list)
          This is a helper method that is used to load the list of previously used work space paths from the default ".workspace_list" file in the default working directory.
private  void okAction()
          This is a refactored (to keep code clutter to a minimum in the actionPerformed() method) method that is called only from the actionPerformed() method whenever the user clicks on the "OK" button in the workspace tab.
private  void saveWorkspaceList(javax.swing.JComboBox list)
          This is a helper method that is used to save the current list of work space paths to the work space list file.
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Dialog
addNotify, getModalityType, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setModalityType, setResizable, setTitle, setUndecorated, setVisible, show, toBack
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeNotify, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImage, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, 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, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

firstLaunch

private boolean firstLaunch
Flag to indicate if this is the first time ever the user is running PEACE GUI. In this situation the user is forced to accept our license before proceeding further.


showFirstTimeMsg

private boolean showFirstTimeMsg
Flag that tracks if the first time welcome message has already been displayed or now.


tabs

private javax.swing.JTabbedPane tabs
The set of tabs that are displayed in this dialog for the user to work with.


wsList

private javax.swing.JComboBox wsList
The list of work spaces that the user can choose from or edit to start up the GUI session.


workspace

private java.lang.String workspace
The selected work space that is set after the user successfully chooses a work space.


peace

private final PEACE peace
Reference to the main PEACE class. The reference is used to create the main frame after the user has selected a valid work space.


cp

private CustomPanel cp
A custom panel that actually has the PEACE logo as the background image. This panel is used to hold all the components just to make the GUI look nice.


serialVersionUID

private static final long serialVersionUID
The generated serial version ID to keep the Java compiler happy about serializing this class.

See Also:
Constant Field Values

FirstTimeMsg

private static java.lang.String FirstTimeMsg
A static piece of text that is prepended to the license text when PEACE is launched for the first time to provide the user with some additional information.


Separator

private static java.lang.String Separator
A simple separator to make the license text look pretty.

Constructor Detail

WorkspaceChooser

public WorkspaceChooser(javax.swing.JFrame owner,
                        PEACE peace)
The constructor. The constructor essentially sets up the default properties of this frame and logs the top image for display. The core setup of various tabs is done when the createTabs() method is called.

Method Detail

createTabs

public boolean createTabs()
Helper method to setup the tabs to be displayed in this frame. This method creates the various tabs and configures the tabs for "First time Launch" as well.

Returns:
This method returns true if the data in the tabs and license information was populated successfully. On errors, this method returns false (after displaying suitable error messages).

getWorkspace

public java.lang.String getWorkspace()
Obtain the work space that was successfully selected by the user. If a work space was not successfully selected then this method returns null.

Returns:
The workspace selected by the user. If a valid workspace has not yet been selected, then this method returns null.

createChooserDialog

private javax.swing.JComponent createChooserDialog(boolean firstTime)
This is a helper method that creates the work space chooser dialog that prompts the user to choose a work space for this session of the GUI. This method places all the components into a suitable panel and returns the panel back to the caller. Most of the code is dedicated to just laying out the various components correctly in the dialog.

Parameters:
firstTime - This flag indicates if PEACE is being run for the first time ever (or not).
Returns:
The panel that contains the work space chooser dialog components.

createLicenceTab

private javax.swing.JComponent createLicenceTab(boolean firstTime)
                                         throws java.lang.Exception
This is a helper method that is used to create the license tab in the work space chooser. This method creates an accept button at the bottom of the license tab if the firstLaunch instance variable is "true"

Parameters:
firstTime - If this parameter is true, then this method creates an accept button at the bottom of the license panel. In addition, it also adds an introductory message to the license information.
Returns:
A panel containing the license/copyright information to be displayed to the user.
Throws:
java.lang.Exception

loadWorkspaceList

private void loadWorkspaceList(boolean firstTime,
                               javax.swing.JComboBox list)
This is a helper method that is used to load the list of previously used work space paths from the default ".workspace_list" file in the default working directory. If no previous work spaces were found, then this method adds a suggested default work space for the user.

Parameters:
firstTime - If this flag is true then it indicates that the PEACE program is being launched for the first time.
list - The combo box to be populated with the list of work space paths.

saveWorkspaceList

private void saveWorkspaceList(javax.swing.JComboBox list)
This is a helper method that is used to save the current list of work space paths to the work space list file.

Parameters:
list - The combo box whose data is to be saved.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
This method handles the actions associated with various controls in the dialog. Specifically it handles the actions associated with the following components: the "Accept" button (shown only the first time the GUI is launched to accept the license), the "Browse..." button, the "OK" button and the "Cancel" button.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

accept

private void accept(java.awt.event.ActionEvent event)
This is a refactored (to keep code clutter to a minimum in the actionPerformed() method) method that is called only from the actionPerformed() method whenever the user clicks on the "Accept" button in the license tab. This button is displayed only when the GUI is launched for the first time. Accordingly, this method performs the following action(s):
  1. Creates a default working directory. If errors occur then this method displays an error and returns immediately.
  2. It hides the "Accept" button (as the user has already accepted the license there is no need to display it).
  3. It activates the "Workspace" tab so user can now choose a workspace.
  4. It informs the user that the default working directory has been created.
  5. Switches tabs to the "Workspace" tab so user can choose the workspace.

Parameters:
event - The action event that triggered this action.

okAction

private void okAction()
This is a refactored (to keep code clutter to a minimum in the actionPerformed() method) method that is called only from the actionPerformed() method whenever the user clicks on the "OK" button in the workspace tab. This method performs the following operations.
  1. Checks and creates the selected work space directory. If the directory already exists checks are made to ensure that the directory is actually a directory and is readable.
  2. If errors occur during directory creation or verification then a suitable error message is displayed and the method exists immediately.
  3. The list of recently used workspaces is updated and the list is saved.
  4. The method sets up the workspace instance variable and disposes the dialog to return control back to the main method.