edu.neu.ccs.gui
Class FileView

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byedu.neu.ccs.gui.DisplayPanel
                      extended byedu.neu.ccs.gui.FileView
All Implemented Interfaces:
Accessible, AlertListener, Displayable, EventListener, Fragile, ImageObserver, JPTConstants, MalformedDataListener, MenuContainer, Serializable, SwingConstants, TypedView

public class FileView
extends DisplayPanel
implements TypedView, Fragile

A TypedView for input of a filename that either represents a path to an existing file or a path to which a file could be written. Provides a button that brings up a JFileChooser for easy choice of an existing file.

Since:
1.0
Version:
2.4.0
See Also:
Fragile, Serialized Form

Nested Class Summary
static class FileView.ExtensionFileFilter
          A file filter that accepts all files with a specific extension.
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  int align
          Alignment of the browse button relative to the field.
protected static FileFilter ALL_FILES_FILTER
          File filter that accepts all files.
protected  JButton browse
          Button that brings up the file chooser.
static int DEFAULT_ALIGNMENT
          Default alignment of browse button relative to field.
static String DEFAULT_BUTTON_LABEL
          Default button label text.
static String DEFAULT_FILENAME
          Default filename.
protected  TextFieldView field
          Text field containing the currently selected filename.
static String LAST_PATH
          Bound property name for the last path property.
protected static String lastPath
          Path to which a FileView was last navigated.
protected  InputProperties properties
          Property list for this view object.
 
Fields inherited from class edu.neu.ccs.gui.DisplayPanel
background, codec, CODEC
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface edu.neu.ccs.gui.TypedView
DATA_TYPE
 
Fields inherited from interface edu.neu.ccs.gui.Displayable
DEFAULT_VIEW_STATE, VIEW_STATE
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FileView()
          Constructs a file view with the default initial filename and the default alignment.
FileView(String name)
          Constructs a file view with the given default filename and the default alignment.
FileView(String name, int align)
          Constructs a file view with the given default filename and the given alignment value.
 
Method Summary
 void addMalformedDataListener(MalformedDataListener l)
          Registers the given MalformedDataListener to receive MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.
 File demandExistingFile()
          Returns a File object representing a path to an existing file.
 String demandExistingFilename()
          Returns a String representing a path to an existing file.
 File demandFile()
          Returns a File object representing a valid path for the file system.
 String demandFilename()
          Returns a String representing a valid path for the file system.
 Stringable demandObject()
          Returns an XString representing the currently selected path.
protected  void fireDataMalformed(MalformedDataEvent evt)
          Delivers MalformedDataEvents to registered listeners.
 int getAlignment()
          Returns the value for the current alignment of the browse button relative to the editable field.
protected  JButton getBrowseButton()
          Returns the browse button component for this view.
 Class getDataType()
          Returns the XString class object.
 String getDefaultViewState(String data)
          Returns the default path.
 InputProperties getInputProperties()
          Returns the input properties for this view.
 String getLastPath()
          Returns the path to which a file view last navigated.
 String getViewState()
          Returns the currently selected path.
protected  String performRequest(boolean anyValid, boolean mandatory)
          Returns a String path that was either input into the filename field directly, selected using the file chooser brought up by browsing, or selected using the file chooser brought up as part of the error recovery strategy.
 void removeMalformedDataListener(MalformedDataListener l)
          De-registers the given MalformedDataListener from receiving MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.
 File requestExistingFile()
          Returns a File object representing a path to an existing file.
 String requestExistingFilename()
          Returns a String representing a path to an existing file.
 File requestFile()
          Returns a File object representing a valid path for the file system.
 String requestFilename()
          Returns a String representing a valid path for the file system.
 Stringable requestObject()
          Returns an XString representing the currently selected path.
 void reset()
          Resets the view state of this object to the default view state for this object.
 void setAlignment(int alignment)
          Sets the alignment of the browse button relative to the filename field.
 void setDefaultViewState(String data)
          Sets the default path to the given String.
 void setEnabled(boolean isEnabled)
          Sets whether or not this object is enabled.
 void setInputProperties(InputProperties p)
          Sets the input properties for this view to the provided input properties.
 void setLastPath(String path)
          Sets the last navigated path to the given path.
 void setViewState(String data)
          Sets the currently selected path to the given String.
 
Methods inherited from class edu.neu.ccs.gui.DisplayPanel
add, add, add, add, add, addBorder, addObject, addObject, addObject, addObject, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, compoundBorder, compoundBorder, dataMalformed, emptyBorder, emptyBorder, emptyBorder, endAlert, etchBorderLowered, etchBorderLowered, etchBorderLowered, etchBorderRaised, etchBorderRaised, etchBorderRaised, frame, frame, frame, frame, frame, frame, generalDialog, generalDialog, generalDialog, generalDialog, getCodec, getDefaultViewState, getDefaultViewStates, getDisplayables, getViewStates, lineBorder, lineBorder, lineBorder, lineBorder, makeComponent, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, OKCancelDialog, OKCancelDialog, OKDialog, OKDialog, refreshComponent, remove, remove, removeAll, removeBorder, sandwichBorder, setCodec, setDeepBackground, setDeepBackground, setDefaultViewStates, setViewStates, startAlert, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, uniformizeHeight, uniformizeSize, uniformizeWidth, YesNoCancelDialog, YesNoCancelDialog
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.neu.ccs.gui.Displayable
getDefaultViewState
 

Field Detail

LAST_PATH

public static final String LAST_PATH
Bound property name for the last path property.

See Also:
Constant Field Values

DEFAULT_FILENAME

public static final String DEFAULT_FILENAME
Default filename.

See Also:
Constant Field Values

DEFAULT_BUTTON_LABEL

public static final String DEFAULT_BUTTON_LABEL
Default button label text.

See Also:
Constant Field Values

DEFAULT_ALIGNMENT

public static final int DEFAULT_ALIGNMENT
Default alignment of browse button relative to field.

See Also:
Constant Field Values

ALL_FILES_FILTER

protected static final FileFilter ALL_FILES_FILTER
File filter that accepts all files.


lastPath

protected static String lastPath
Path to which a FileView was last navigated.


align

protected int align
Alignment of the browse button relative to the field.


field

protected TextFieldView field
Text field containing the currently selected filename.


browse

protected JButton browse
Button that brings up the file chooser.


properties

protected InputProperties properties
Property list for this view object.

Constructor Detail

FileView

public FileView()
Constructs a file view with the default initial filename and the default alignment.

See Also:
FileView(String), FileView(String, int)

FileView

public FileView(String name)
Constructs a file view with the given default filename and the default alignment.

Parameters:
name - the default filename for the view
See Also:
FileView(), FileView(String, int)

FileView

public FileView(String name,
                int align)
Constructs a file view with the given default filename and the given alignment value.

Parameters:
name - the default filename for the view
align - the alignment of the browse button relative to the filename field
See Also:
FileView(), FileView(String)
Method Detail

demandObject

public Stringable demandObject()
Returns an XString representing the currently selected path. The returned representation may not be a path to an existing file, or may not be a valid filename at all.

Specified by:
demandObject in interface TypedView
Returns:
a Stringable model object
See Also:
demandFile(), demandExistingFile(), demandFilename(), demandExistingFilename(), requestObject(), TypedView

requestObject

public Stringable requestObject()
                         throws CancelledException
Returns an XString representing the currently selected path. The returned representation may not be a path to an existing file, or may not be a valid filename at all.

Specified by:
requestObject in interface TypedView
Returns:
a Stringable model object
Throws:
CancelledException
See Also:
requestFile(), requestExistingFile(), requestFilename(), requestExistingFilename(), demandObject(), TypedView

setInputProperties

public void setInputProperties(InputProperties p)
Description copied from interface: TypedView

Sets the input properties for this view to the provided input properties.

If the given input properties list is null, the property list for this view is set to the base property list containing default property values.

Specified by:
setInputProperties in interface TypedView
Parameters:
p - the new input properties for the view
See Also:
TypedView.getInputProperties()

getInputProperties

public InputProperties getInputProperties()
Description copied from interface: TypedView
Returns the input properties for this view.

Specified by:
getInputProperties in interface TypedView
Returns:
the input properties
See Also:
TypedView.setInputProperties(InputProperties)

getDataType

public Class getDataType()
Returns the XString class object.

Specified by:
getDataType in interface TypedView
Returns:
the current class of a model object
See Also:
TypedView

setViewState

public void setViewState(String data)
Sets the currently selected path to the given String. The provided filename need not point to an existing file, or represent a valid filename at all.

Specified by:
setViewState in interface Displayable
Overrides:
setViewState in class DisplayPanel
Parameters:
data - the new selected path
See Also:
getViewState(), Displayable

getViewState

public String getViewState()
Returns the currently selected path.

Specified by:
getViewState in interface Displayable
Overrides:
getViewState in class DisplayPanel
See Also:
setViewState(String), Displayable

setDefaultViewState

public void setDefaultViewState(String data)
Sets the default path to the given String.

Specified by:
setDefaultViewState in interface Displayable
Overrides:
setDefaultViewState in class DisplayPanel
Parameters:
data - the new default path
See Also:
DisplayPanel.getDefaultViewState(), reset(), Displayable

getDefaultViewState

public String getDefaultViewState(String data)
Returns the default path.

See Also:
setDefaultViewState(String), reset()

reset

public void reset()
Description copied from interface: Displayable

Resets the view state of this object to the default view state for this object.

Equivalent to: setViewState(getDefaultViewState()).

Specified by:
reset in interface Displayable
Overrides:
reset in class DisplayPanel

setEnabled

public void setEnabled(boolean isEnabled)
Description copied from interface: Displayable
Sets whether or not this object is enabled.

Specified by:
setEnabled in interface Displayable
Overrides:
setEnabled in class DisplayPanel
Parameters:
isEnabled - whether or not this panel is to be enabled

addMalformedDataListener

public void addMalformedDataListener(MalformedDataListener l)
Description copied from interface: Fragile
Registers the given MalformedDataListener to receive MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.

Specified by:
addMalformedDataListener in interface Fragile
Parameters:
l - the listener to register
See Also:
Fragile.removeMalformedDataListener(MalformedDataListener)

removeMalformedDataListener

public void removeMalformedDataListener(MalformedDataListener l)
Description copied from interface: Fragile
De-registers the given MalformedDataListener from receiving MalformedDataEvents when the view state data is found to be malformed and when the view state data is returned to a well-formed value.

Specified by:
removeMalformedDataListener in interface Fragile
Parameters:
l - the listener to de-register
See Also:
Fragile.addMalformedDataListener(MalformedDataListener)

demandExistingFile

public File demandExistingFile()
Returns a File object representing a path to an existing file. This method enforces the mandatory input model, and uses a JFileChooser to implement an error recovery strategy.

See Also:
demandFile(), demandExistingFilename(), demandFilename(), demandExistingFile(), requestFile(), requestExistingFilename(), requestFilename(), demandObject(), requestObject()

demandFile

public File demandFile()
Returns a File object representing a valid path for the file system. The returned File may or may not point to an already existing file. This method enforces the mandatory input model, and uses a JFileChooser to implement an error recovery strategy.

See Also:
demandExistingFile(), demandExistingFilename(), demandFilename(), demandExistingFile(), requestFile(), requestExistingFilename(), requestFilename(), demandObject(), requestObject()

demandExistingFilename

public String demandExistingFilename()
Returns a String representing a path to an existing file. This method enforces the mandatory input model, and uses a JFileChooser to implement an error recovery strategy.

See Also:
demandExistingFile(), demandFile(), demandFilename(), demandExistingFile(), requestFile(), requestExistingFilename(), requestFilename(), demandObject(), requestObject()

demandFilename

public String demandFilename()
Returns a String representing a valid path for the file system. The returned path may or may not point to an already existing file. This method enforces the mandatory input model, and uses a JFileChooser to implement an error recovery strategy.

See Also:
demandExistingFile(), demandFile(), demandExistingFilename(), demandExistingFile(), requestFile(), requestExistingFilename(), requestFilename(), demandObject(), requestObject()

requestExistingFile

public File requestExistingFile()
                         throws CancelledException
Returns a File object representing a path to an existing file. This method enforces the optional input model, and uses a dismissable JFileChooser to implement an error recovery strategy.

Throws:
CancelledException
See Also:
demandExistingFile(), demandFile(), demandExistingFilename(), demandFilename(), requestFile(), requestExistingFilename(), requestFilename(), demandObject(), requestObject()

requestFile

public File requestFile()
                 throws CancelledException
Returns a File object representing a valid path for the file system. The returned File may or may not point to an already existing file. This method enforces the optional input model, and uses a dismissable JFileChooser to implement an error recovery strategy.

Throws:
CancelledException
See Also:
demandExistingFile(), demandFile(), demandExistingFilename(), demandFilename(), demandExistingFile(), requestExistingFilename(), requestFilename(), demandObject(), requestObject()

requestExistingFilename

public String requestExistingFilename()
                               throws CancelledException
Returns a String representing a path to an existing file. This method enforces the optional input model, and uses a dismissable JFileChooser to implement an error recovery strategy.

Throws:
CancelledException
See Also:
demandExistingFile(), demandFile(), demandExistingFilename(), demandFilename(), demandExistingFile(), requestFile(), requestFilename(), demandObject(), requestObject()

requestFilename

public String requestFilename()
                       throws CancelledException
Returns a String representing a valid path for the file system. The returned path may or may not point to an already existing file. This method enforces the optional input model, and uses a dismissable JFileChooser to implement an error recovery strategy.

Throws:
CancelledException
See Also:
demandExistingFile(), demandFile(), demandExistingFilename(), demandFilename(), demandExistingFile(), requestFile(), requestExistingFilename(), demandObject(), requestObject()

setAlignment

public void setAlignment(int alignment)
Sets the alignment of the browse button relative to the filename field. If the given alignment value is invalid, the current alignment is not changed.

Parameters:
alignment - the new alignment of the browse button relative to the filename field
See Also:
getAlignment(), JPTConstants.ABOVE, JPTConstants.BELOW, SwingConstants.LEFT, SwingConstants.RIGHT, JPTConstants.DEFAULT

getAlignment

public int getAlignment()
Returns the value for the current alignment of the browse button relative to the editable field.

See Also:
setAlignment(int), JPTConstants.ABOVE, JPTConstants.BELOW, SwingConstants.LEFT, SwingConstants.RIGHT, JPTConstants.DEFAULT

setLastPath

public void setLastPath(String path)
Sets the last navigated path to the given path.

Parameters:
path - the desired directory to start browsing in
See Also:
getLastPath()

getLastPath

public String getLastPath()
Returns the path to which a file view last navigated.

See Also:
setLastPath(String)

getBrowseButton

protected JButton getBrowseButton()
Returns the browse button component for this view.


fireDataMalformed

protected void fireDataMalformed(MalformedDataEvent evt)
Delivers MalformedDataEvents to registered listeners.

Parameters:
evt - the MalformedDataEvent to deliver
See Also:
addMalformedDataListener(MalformedDataListener), removeMalformedDataListener(MalformedDataListener)

performRequest

protected String performRequest(boolean anyValid,
                                boolean mandatory)
                         throws CancelledException
Returns a String path that was either input into the filename field directly, selected using the file chooser brought up by browsing, or selected using the file chooser brought up as part of the error recovery strategy.

Parameters:
anyValid - whether or not any valid filename is enough
mandatory - whether or not the operation is mandatory
Throws:
CancelledException - if the user cancels the action and the operation is not mandatory
See Also:
demandFile(), demandExistingFile(), demandFilename(), demandExistingFilename(), requestFile(), requestExistingFile(), requestFilename(), requestExistingFilename()