ti.chimera
Class FileChooser

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byti.chimera.FileChooser
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class FileChooser
extends javax.swing.JComponent

Like JFileChooser, but displays itself within the provided Dialog, rather than a JDialog. This is done because we abstract windows away, so that they can either be, for example JInternalFrame or JDialog. (Having an interface that JInternalFrame, JWindow, JDialog, etc., all implement would have been a pretty smart way of doing things, but I guess I'm expecting too much.)

It works something like this:

      FileChooser chooser = new FileChooser( main.getWindowManager().getDialog("Open File") );
      
      chooser.setFileFilter( ... );
      
      if( chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION )
      {
        AbstractFile file = chooser.getSelectedFile();
        ...
      }
 

Version:
0.1
Author:
Rob Clark
See Also:
Serialized Form

Nested Class Summary
static class FileChooser.AbstractFileFilter
          The file-filter interface.
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static FileChooser.AbstractFileFilter ALL_FILES_FILTER
           
static int APPROVE_OPTION
          Return value if approve (yes, ok) is chosen.
static int CANCEL_OPTION
          Return value if cancel is chosen.
static int ERROR_OPTION
          Return value if an error occured.
static int OPEN_DIALOG
          The dialog is to be an "Open File" type dialog.
static int SAVE_DIALOG
          The dialog is to be a "Save File" type dialog.
 
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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FileChooser(Dialog dialog)
          Class Constructor.
FileChooser(Dialog dialog, oscript.fs.AbstractFile file)
          Class Constructor.
 
Method Summary
 void addChoosableFileFilter(FileChooser.AbstractFileFilter filter)
          Add a file filter to the list of choosable file filters.
 void addNotify()
           
 java.lang.String getApproveButtonText()
          Get the approve button text.
 java.lang.String getDialogTitle()
          Get the title of this dialog.
 FileChooser.AbstractFileFilter getFileFilter()
          Get the current file filter.
 java.awt.Dimension getMaximumSize()
           
 java.awt.Dimension getMinimumSize()
           
 java.awt.Dimension getPreferredSize()
           
 oscript.fs.AbstractFile getSelectedFile()
          Get the selected file.
 oscript.fs.AbstractFile[] getSelectedFiles()
          Get the set of selected files.
 boolean removeChoosableFileFilter(FileChooser.AbstractFileFilter filter)
          Remove a file filter from the list of choosable file filters.
 void removeNotify()
           
 void setDialogType(int dialogType)
          Set the dialog type, ie.
 void setFileFilter(FileChooser.AbstractFileFilter filter)
          Set the file filter.
 void setSelectedFile(oscript.fs.AbstractFile file)
          Set the file selected by this file chooser.
 void setSelectedFiles(oscript.fs.AbstractFile[] files)
          Set the files select by this file chooser.
 int showDialog(java.awt.Component parent, java.lang.String approveButtonText)
          Show the dialog.
 int showOpenDialog(java.awt.Component parent)
          Show an "Open" file chooser dialog.
 int showSaveDialog(java.awt.Component parent)
          Show a "Save" file chooser dialog.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, 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, remove, remove, removeAll, 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
 

Field Detail

CANCEL_OPTION

public static final int CANCEL_OPTION
Return value if cancel is chosen.

See Also:
Constant Field Values

APPROVE_OPTION

public static final int APPROVE_OPTION
Return value if approve (yes, ok) is chosen.

See Also:
Constant Field Values

ERROR_OPTION

public static final int ERROR_OPTION
Return value if an error occured.

See Also:
Constant Field Values

OPEN_DIALOG

public static final int OPEN_DIALOG
The dialog is to be an "Open File" type dialog.

See Also:
Constant Field Values

SAVE_DIALOG

public static final int SAVE_DIALOG
The dialog is to be a "Save File" type dialog.

See Also:
Constant Field Values

ALL_FILES_FILTER

public static final FileChooser.AbstractFileFilter ALL_FILES_FILTER
Constructor Detail

FileChooser

public FileChooser(Dialog dialog)
Class Constructor.

Parameters:
dialog - the dialog to contain the FileChooser

FileChooser

public FileChooser(Dialog dialog,
                   oscript.fs.AbstractFile file)
Class Constructor.

Parameters:
dialog - the dialog to contain the FileChooser
file - the currently selected file
Method Detail

addNotify

public void addNotify()

removeNotify

public void removeNotify()

getDialogTitle

public java.lang.String getDialogTitle()
Get the title of this dialog.


getApproveButtonText

public java.lang.String getApproveButtonText()
Get the approve button text.


setSelectedFile

public void setSelectedFile(oscript.fs.AbstractFile file)
Set the file selected by this file chooser.

Parameters:
file - the file to select

setSelectedFiles

public void setSelectedFiles(oscript.fs.AbstractFile[] files)
Set the files select by this file chooser.

Parameters:
files - the files to select

getSelectedFile

public oscript.fs.AbstractFile getSelectedFile()
Get the selected file. If there are more than one selected files, this returns the first selected file.

Returns:
the selected file or null if none

getSelectedFiles

public oscript.fs.AbstractFile[] getSelectedFiles()
Get the set of selected files.

Returns:
an array of selected files, of length 0 or more

setFileFilter

public void setFileFilter(FileChooser.AbstractFileFilter filter)
Set the file filter. The file filter will determine what types of files are visible.


getFileFilter

public FileChooser.AbstractFileFilter getFileFilter()
Get the current file filter.


addChoosableFileFilter

public void addChoosableFileFilter(FileChooser.AbstractFileFilter filter)
Add a file filter to the list of choosable file filters.


removeChoosableFileFilter

public boolean removeChoosableFileFilter(FileChooser.AbstractFileFilter filter)
Remove a file filter from the list of choosable file filters.


showSaveDialog

public int showSaveDialog(java.awt.Component parent)
Show a "Save" file chooser dialog.

Parameters:
parent - the parent of this dialog, can be null
Returns:
CANCEL_OPTION, APPROVE_OPTION, or ERROR_OPTION (if an arror occurs or dialog is dismissed)

showOpenDialog

public int showOpenDialog(java.awt.Component parent)
Show an "Open" file chooser dialog.

Parameters:
parent - the parent of this dialog, can be null
Returns:
CANCEL_OPTION, APPROVE_OPTION, or ERROR_OPTION (if an arror occurs or dialog is dismissed)

showDialog

public int showDialog(java.awt.Component parent,
                      java.lang.String approveButtonText)
Show the dialog.

Parameters:
parent - the parent component of the dialog
approveButtonText - text to show on the approve button. By default, ie. if null, the approve button text is determined by the dialog type
Returns:
CANCEL_OPTION, APPROVE_OPTION, or ERROR_OPTION

setDialogType

public void setDialogType(int dialogType)
Set the dialog type, ie. OPEN_DIALOG or SAVE_DIALOG


getPreferredSize

public java.awt.Dimension getPreferredSize()

getMinimumSize

public java.awt.Dimension getMinimumSize()

getMaximumSize

public java.awt.Dimension getMaximumSize()