nrs.util.file
Class FileDialog

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Dialog
                  extended bynrs.util.file.FileDialog
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.awt.event.ComponentListener, java.util.EventListener, java.io.FilenameFilter, java.awt.image.ImageObserver, java.awt.event.ItemListener, java.awt.event.KeyListener, java.awt.MenuContainer, java.io.Serializable, java.awt.event.WindowListener

public class FileDialog
extends java.awt.Dialog
implements java.awt.event.ActionListener, java.awt.event.ComponentListener, java.awt.event.KeyListener, java.awt.event.ItemListener, java.io.FilenameFilter, java.awt.event.WindowListener

Extended AWT file dialog with support for selecting multiple files and adding extra components to the borders of the dialog.

Author:
Copyright © 2004-2005 Nick Sydenham <nsydenham@yahoo.co.uk>
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
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 int OPEN
           
static int SAVE
           
 
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
FileDialog(java.awt.Frame owner)
          Creates a new instance of FileDialog
FileDialog(java.awt.Frame owner, java.lang.String title)
           
FileDialog(java.awt.Frame owner, java.lang.String title, int mode)
           
FileDialog(java.awt.Frame owner, java.lang.String title, int mode, java.awt.Component[] comps)
           
 
Method Summary
 boolean accept(java.io.File dir, java.lang.String name)
          Implementation method for FilenameFilter
 void actionPerformed(java.awt.event.ActionEvent e)
          User clicked a button
 void addBorderPanel(java.awt.Panel panel, java.lang.String constraint)
          Add a panel containing components to one of the borders of the FileDialog
 void addFileFilter(java.lang.String displayName, java.lang.String ending)
          Add a file filter
 void addFileSelectionListener(FileSelectionListener listener)
          Add a file selection listener
 void componentHidden(java.awt.event.ComponentEvent arg0)
           
 void componentMoved(java.awt.event.ComponentEvent arg0)
           
 void componentResized(java.awt.event.ComponentEvent e)
           
 void componentShown(java.awt.event.ComponentEvent arg0)
           
 java.lang.String getCancelButtonLabel()
          Get the text of the Cancel button
 java.awt.Dimension getMinimumSize()
           
 java.lang.String getOKButtonLabel()
          Get the text of the OK button
 java.awt.Dimension getPreferredSize()
           
 java.io.File[] getSelectedFiles()
          Get the list of files selected by the user
 boolean isSelectDirectories()
          Return whether directories can be selected
 boolean isSelectMultiple()
          Return the current selection mode
 void itemStateChanged(java.awt.event.ItemEvent e)
          User selected a file type or directory
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
protected  void notifyFileSelectionListeners()
          Notify listeners of any changes
 void removeFileSelectionListener(FileSelectionListener listener)
          Remove a file selection listener
 void setCancelButtonLabel(java.lang.String label)
          Set the text of the Cancel button
 void setOKButtonLabel(java.lang.String label)
          Set the text of the OK button
 void setSelectDirectories(boolean selectDirs)
          Sets whether the user can select directories as well as files
 void setSelectedDirectory(java.io.File dir)
          Set the selected directory
 void setSelectedFile(java.io.File f)
          Set the selected file
 void setSelectedFileFilter(java.lang.String extension)
          Set the selected file filter
 void setSelectMultiple(boolean multiple)
          Set whether the user can select either one or multiple files.
 void windowActivated(java.awt.event.WindowEvent e)
          Invoked when the Window is set to be the active Window.
 void windowClosed(java.awt.event.WindowEvent e)
          Invoked when a window has been closed as the result of calling dispose on the window.
 void windowClosing(java.awt.event.WindowEvent e)
          Invoked when the user attempts to close the window from the window's system menu.
 void windowDeactivated(java.awt.event.WindowEvent e)
          Invoked when a Window is no longer the active Window.
 void windowDeiconified(java.awt.event.WindowEvent e)
          Invoked when a window is changed from a minimized to a normal state.
 void windowIconified(java.awt.event.WindowEvent e)
          Invoked when a window is changed from a normal to a minimized state.
 void windowOpened(java.awt.event.WindowEvent e)
          Invoked the first time a window is made visible.
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getAccessibleContext, getTitle, hide, isModal, isResizable, isUndecorated, paramString, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, isOpaque, 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, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OPEN

public static final int OPEN
See Also:
Constant Field Values

SAVE

public static final int SAVE
See Also:
Constant Field Values
Constructor Detail

FileDialog

public FileDialog(java.awt.Frame owner)
Creates a new instance of FileDialog


FileDialog

public FileDialog(java.awt.Frame owner,
                  java.lang.String title)

FileDialog

public FileDialog(java.awt.Frame owner,
                  java.lang.String title,
                  int mode)

FileDialog

public FileDialog(java.awt.Frame owner,
                  java.lang.String title,
                  int mode,
                  java.awt.Component[] comps)
Method Detail

getSelectedFiles

public java.io.File[] getSelectedFiles()
Get the list of files selected by the user

Returns:
an array of selected File objects

notifyFileSelectionListeners

protected void notifyFileSelectionListeners()
Notify listeners of any changes


setSelectedDirectory

public void setSelectedDirectory(java.io.File dir)
Set the selected directory

Parameters:
dir - selected directory

setSelectedFile

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

Parameters:
f - the file to select

setSelectedFileFilter

public void setSelectedFileFilter(java.lang.String extension)
Set the selected file filter

Parameters:
extension - e.g. jar or mp3

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
User clicked a button

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

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent e)
User selected a file type or directory

Specified by:
itemStateChanged in interface java.awt.event.ItemListener

accept

public boolean accept(java.io.File dir,
                      java.lang.String name)
Implementation method for FilenameFilter

Specified by:
accept in interface java.io.FilenameFilter

setSelectMultiple

public void setSelectMultiple(boolean multiple)
Set whether the user can select either one or multiple files.

Parameters:
multiple - true if user can select multiple files

isSelectMultiple

public boolean isSelectMultiple()
Return the current selection mode


setSelectDirectories

public void setSelectDirectories(boolean selectDirs)
Sets whether the user can select directories as well as files

Parameters:
selectDirs -

isSelectDirectories

public boolean isSelectDirectories()
Return whether directories can be selected


addFileFilter

public void addFileFilter(java.lang.String displayName,
                          java.lang.String ending)
Add a file filter

Parameters:
displayName - e.g. HTML (*.html)
ending - e.g. htm, html

addFileSelectionListener

public void addFileSelectionListener(FileSelectionListener listener)
Add a file selection listener

Parameters:
listener - object that wants to receive file selection events

removeFileSelectionListener

public void removeFileSelectionListener(FileSelectionListener listener)
Remove a file selection listener

Parameters:
listener - the listener to be removed

addBorderPanel

public void addBorderPanel(java.awt.Panel panel,
                           java.lang.String constraint)
Add a panel containing components to one of the borders of the FileDialog

Parameters:
panel - the Panel to add
constraint - one of BorderLayout.EAST, BorderLayout.WEST, BorderLayout.NORTH, BorderLayout.SOUTH

getPreferredSize

public java.awt.Dimension getPreferredSize()

getMinimumSize

public java.awt.Dimension getMinimumSize()

componentHidden

public void componentHidden(java.awt.event.ComponentEvent arg0)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent arg0)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent arg0)
Specified by:
componentShown in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Specified by:
componentResized in interface java.awt.event.ComponentListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

setOKButtonLabel

public void setOKButtonLabel(java.lang.String label)
Set the text of the OK button

Parameters:
label - the label to set on the OK button

setCancelButtonLabel

public void setCancelButtonLabel(java.lang.String label)
Set the text of the Cancel button

Parameters:
label - the label to set on the Cancel button

getOKButtonLabel

public java.lang.String getOKButtonLabel()
Get the text of the OK button

Returns:
OK button text

getCancelButtonLabel

public java.lang.String getCancelButtonLabel()
Get the text of the Cancel button

Returns:
Cancel button text

windowOpened

public void windowOpened(java.awt.event.WindowEvent e)
Invoked the first time a window is made visible.

Specified by:
windowOpened in interface java.awt.event.WindowListener

windowIconified

public void windowIconified(java.awt.event.WindowEvent e)
Invoked when a window is changed from a normal to a minimized state. For many platforms, a minimized window is displayed as the icon specified in the window's iconImage property.

Specified by:
windowIconified in interface java.awt.event.WindowListener
See Also:
Frame.setIconImage(java.awt.Image)

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent e)
Invoked when a window is changed from a minimized to a normal state.

Specified by:
windowDeiconified in interface java.awt.event.WindowListener

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent e)
Invoked when a Window is no longer the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

Specified by:
windowDeactivated in interface java.awt.event.WindowListener

windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Invoked when the user attempts to close the window from the window's system menu. If the program does not explicitly hide or dispose the window while processing this event, the window close operation will be cancelled.

Specified by:
windowClosing in interface java.awt.event.WindowListener

windowClosed

public void windowClosed(java.awt.event.WindowEvent e)
Invoked when a window has been closed as the result of calling dispose on the window.

Specified by:
windowClosed in interface java.awt.event.WindowListener

windowActivated

public void windowActivated(java.awt.event.WindowEvent e)
Invoked when the Window is set to be the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.

Specified by:
windowActivated in interface java.awt.event.WindowListener


Copyright © 2004-2005 Nick Sydenham <nsydenham@yahoo.co.uk>