buoy.widget
Class BFileChooser

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.BFileChooser

public class BFileChooser
extends Widget

A BFileChooser is a Widget that allows the user to select files or directories from the file system. It has modes for loading files, saving files, and choosing directories. It supports both single and multiple selection modes, and you can optionally restrict the list of files shown in the dialog by setting a FileFilter.

BFileChooser can be used in two different ways. First, it can be added to a container like any other Widget. This is useful when you want it to appear inside of a window along with other Widgets.

Most often, however, BFileChooser is used in a modal dialog as a self contained user interface element. To use it this way, you simply instantiate a BFileChooser, set any properties, and then call showDialog() to display it. showDialog() will automatically create a dialog, add the BFileChooser, display it, and block until the user dismisses the dialog. You can reuse a single BFileChooser by repeatedly calling showDialog().

In addition to the event types generated by all Widgets, BFileChoosers generate the following event types:

Author:
Peter Eastman

Nested Class Summary
static class BFileChooser.SelectionMode
          This inner class represents a mode for the file chooser.
 
Field Summary
static BFileChooser.SelectionMode OPEN_FILE
           
static BFileChooser.SelectionMode SAVE_FILE
           
static BFileChooser.SelectionMode SELECT_FOLDER
           
 
Constructor Summary
BFileChooser()
          Create a new BFileChooser in OPEN_FILE mode.
BFileChooser(BFileChooser.SelectionMode mode, java.lang.String title)
          Create a new BFileChooser
BFileChooser(BFileChooser.SelectionMode mode, java.lang.String title, java.io.File directory)
          Create a new BFileChooser.
 
Method Summary
 javax.swing.JFileChooser getComponent()
          Get the java.awt.Component corresponding to this Widget.
 java.io.File getDirectory()
          Get the directory displayed in this file chooser.
 javax.swing.filechooser.FileFilter getFileFilter()
          Get the FileFilter which restricts the list of files shown in the dialog.
 BFileChooser.SelectionMode getMode()
          Get the select mode for this file chooser (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER).
 java.io.File getSelectedFile()
          Get the file selected in the file chooser.
 java.io.File[] getSelectedFiles()
          Get the list of selected files.
 java.lang.String getTitle()
          Get the title displayed on the dialog.
 boolean isMultipleSelectionEnabled()
          Get whether the user is allowed to select multiple files.
 void setDirectory(java.io.File directory)
          Set the directory displayed in this file chooser.
 void setFileFilter(javax.swing.filechooser.FileFilter filter)
          Set the FileFilter which restricts the list of files shown in the dialog.
 void setMode(BFileChooser.SelectionMode mode)
          Set the select mode for this file chooser (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER).
 void setMultipleSelectionEnabled(boolean multiple)
          Set whether the user is allowed to select multiple files.
 void setSelectedFile(java.io.File file)
          Set the file selected in the file chooser.
 void setSelectedFiles(java.io.File[] files)
          Set the list of selected files.
 void setTitle(java.lang.String title)
          Set the title displayed on the dialog.
 boolean showDialog(Widget parent)
          Show a dialog containing this BFileChooser and block until the user closes it.
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible
 
Methods inherited from class buoy.event.EventSource
addEventLink, addEventLink, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN_FILE

public static final BFileChooser.SelectionMode OPEN_FILE

SAVE_FILE

public static final BFileChooser.SelectionMode SAVE_FILE

SELECT_FOLDER

public static final BFileChooser.SelectionMode SELECT_FOLDER
Constructor Detail

BFileChooser

public BFileChooser()
Create a new BFileChooser in OPEN_FILE mode.


BFileChooser

public BFileChooser(BFileChooser.SelectionMode mode,
                    java.lang.String title)
Create a new BFileChooser

Parameters:
mode - the selection mode (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER)
title - the title displayed on the dialog

BFileChooser

public BFileChooser(BFileChooser.SelectionMode mode,
                    java.lang.String title,
                    java.io.File directory)
Create a new BFileChooser.

Parameters:
mode - the selection mode (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER)
title - the title displayed on the dialog
directory - the directory which the file chooser should initially display
Method Detail

getComponent

public javax.swing.JFileChooser getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

getTitle

public java.lang.String getTitle()
Get the title displayed on the dialog.


setTitle

public void setTitle(java.lang.String title)
Set the title displayed on the dialog.


getMode

public BFileChooser.SelectionMode getMode()
Get the select mode for this file chooser (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER).


setMode

public void setMode(BFileChooser.SelectionMode mode)
Set the select mode for this file chooser (OPEN_FILE, SAVE_FILE, or SELECT_FOLDER).


isMultipleSelectionEnabled

public boolean isMultipleSelectionEnabled()
Get whether the user is allowed to select multiple files.


setMultipleSelectionEnabled

public void setMultipleSelectionEnabled(boolean multiple)
Set whether the user is allowed to select multiple files.


getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Get the FileFilter which restricts the list of files shown in the dialog.


setFileFilter

public void setFileFilter(javax.swing.filechooser.FileFilter filter)
Set the FileFilter which restricts the list of files shown in the dialog.


getDirectory

public java.io.File getDirectory()
Get the directory displayed in this file chooser.


setDirectory

public void setDirectory(java.io.File directory)
Set the directory displayed in this file chooser.


getSelectedFile

public java.io.File getSelectedFile()
Get the file selected in the file chooser. If multiple files are selected, no guarantees are made about which one will be returned, so you should use getSelectedFiles() instead of this method whenever multiple selection is enabled.

If no file is selected, this returns null.


setSelectedFile

public void setSelectedFile(java.io.File file)
Set the file selected in the file chooser.


getSelectedFiles

public java.io.File[] getSelectedFiles()
Get the list of selected files. This should be used instead of getSelectedFile() when multiple selection is enabled.


setSelectedFiles

public void setSelectedFiles(java.io.File[] files)
                      throws java.lang.IllegalArgumentException
Set the list of selected files.

Throws:
java.lang.IllegalArgumentException - if multiple selection is not enabled

showDialog

public boolean showDialog(Widget parent)
Show a dialog containing this BFileChooser and block until the user closes it. After this method returns, you can call getSelectedFile() or getSelectedFiles() to determine which file or files were selected.

Parameters:
parent - the dialog's parent Widget (usually a WindowWidget). This may be null.
Returns:
true if the user clicked the accept button (usually labelled "Open" or "Save"), false if they clicked the cancel button


Written by Peter Eastman.