com.jbbres.lib.actions.tools.swing
Class JFileSelection

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jbbres.lib.actions.tools.swing.JFileSelection
All Implemented Interfaces:
com.jbbres.lib.PropertiesOwner, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class JFileSelection
extends javax.swing.JPanel
implements com.jbbres.lib.PropertiesOwner

This panel allow the user to select a file, either by choosing one of the variables of the workflow, either by choosing a file on the hard drive.


Release Notes:

v1.1.0:

  • Use JXFileChooser instead of JXFileChooser
  • Since:
    1.0.0
    Version:
    1.1.0
    Author:
    Jean-Baptiste Bres
    See Also:
    Serialized Form

    Nested Class Summary
     
    Nested classes/interfaces inherited from class javax.swing.JComponent
    javax.swing.JComponent.AccessibleJComponent
     
    Nested classes/interfaces inherited from class java.awt.Component
    java.awt.Component.BaselineResizeBehavior
     
    Field Summary
    static int DIRECTORIES_ONLY
              Instruction to display only directories.
    static int FILES_AND_DIRECTORIES
              Instruction to display both files and directories.
    static int FILES_ONLY
              Instruction to display only files.
    static int OPEN_DIALOG
              Type value indicating that the JXFileChoosers associated to this action support an "Open" file operation.
    static int SAVE_DIALOG
              Type value indicating that the JXFileChoosers associated to this action support a "Save" file operation.
     
    Fields inherited from class javax.swing.JComponent
    TOOL_TIP_TEXT_KEY, 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
    JFileSelection()
              Create the JFileSelection.
    JFileSelection(java.io.File defaultFile)
              Create the JFileSelection.
    JFileSelection(java.lang.String defaultPath)
              Create the JFileSelection.
    JFileSelection(Workflow workflow)
              Create the JFileSelection.
    JFileSelection(Workflow workflow, java.io.File defaultFile)
              Create the JFileSelection.
    JFileSelection(Workflow workflow, java.io.File defaultFile, boolean diplayPath)
              Create the JFileSelection.
    JFileSelection(Workflow workflow, java.lang.String defaultPath)
              Create the JFileSelection.
     
    Method Summary
     void addActionListener(java.awt.event.ActionListener l)
              Add a file selection listener.
     void addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
              Adds a filter to the list of user choosable file filters.
     void addStaticFile(java.io.File file)
              Add a static file to the list.
     void displayPath(boolean d)
              If TRUE the whole path of the file will be display.
     void fireActionPerformed()
              Reports a file selection.
     javax.swing.filechooser.FileFilter[] getChoosableFileFilters()
              Gets the list of user choosable file filters.
     java.io.File getCurrentDirectory()
              Returns the current directory.
     int getDialogType()
              Return the type of dialog window display when the user choose a file.
     int getFileSelectionMode()
              Returns the current file-selection mode.
     java.util.Properties getProperties()
              Returns an Properties object that can be used by an Element for saving the selected file.
     java.io.File getSelectedFile()
              Return the selected path.
     java.lang.String getSelectedFilePath()
              Return the selected path.
     boolean isAcceptAllFileFilterUsed()
              Returns whether the AcceptAll FileFilter is used.
     boolean isPathDisplayed()
              Return TRUE if the whole path of the file will be display.
     void refresh()
              Refresh the panel: Display or hide the manually selected file depending on the value choosen in the combo box, and call validate.
     void removeActionListener(java.awt.event.ActionListener l)
              Remove a file selection listener.
     boolean removeChoosableFileFilter(javax.swing.filechooser.FileFilter f)
              Removes a filter from the list of user choosable file filters.
     void removeStaticFile(java.io.File file)
              Remove a static file.
     void resetChoosableFileFilters()
              Resets the choosable file filter list to its starting state.
     int selectFile()
              Open a window to select a file.
     int selectFile(java.awt.Component parent, java.lang.String title)
              Open a window to select a file.
     void setAcceptAllFileFilterUsed(boolean b)
              Determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.
     void setCurrentDirectory(java.io.File dir)
              Sets the current directory.
     void setDialogType(int type)
              Set the type of dialog window display when the user choose a file.
     boolean setEditable(boolean e)
              Set the panel editable.
     void setEnabled(boolean e)
              Set the panel enabled.
     void setFileSelectionMode(int mode)
              Sets the JXFileChooser to allow the user to just select files, just select directories, or select both files and directories.
     void setProperties(java.util.Properties properties)
              Restore the selected file based on the properties provided.
     void setSelectedFile(java.io.File file)
              Set the current file.
     void setSelectedFilePath(java.lang.String path)
              Set the current path and the current selected file.
     void setSelectedItem(java.lang.Object object)
              Sets the selected item in the combo box display area to the object in the argument.
     void setWorkflow(Workflow workflow)
              Set the workflow that this panel is working on.
     
    Methods inherited from class javax.swing.JPanel
    getAccessibleContext, getUI, getUIClassID, setUI, updateUI
     
    Methods inherited from class javax.swing.JComponent
    addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
     
    Methods inherited from class java.awt.Container
    add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
     
    Methods inherited from class java.awt.Component
    action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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
    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Field Detail

    FILES_ONLY

    public static final int FILES_ONLY
    Instruction to display only files.

    See Also:
    Constant Field Values

    DIRECTORIES_ONLY

    public static final int DIRECTORIES_ONLY
    Instruction to display only directories.

    See Also:
    Constant Field Values

    FILES_AND_DIRECTORIES

    public static final int FILES_AND_DIRECTORIES
    Instruction to display both files and directories.

    See Also:
    Constant Field Values

    OPEN_DIALOG

    public static final int OPEN_DIALOG
    Type value indicating that the JXFileChoosers associated to this action support an "Open" file operation.

    See Also:
    Constant Field Values

    SAVE_DIALOG

    public static final int SAVE_DIALOG
    Type value indicating that the JXFileChoosers associated to this action support a "Save" file operation.

    See Also:
    Constant Field Values
    Constructor Detail

    JFileSelection

    public JFileSelection(Workflow workflow)
    Create the JFileSelection.

    Parameters:
    workflow - Associated workflow.

    JFileSelection

    public JFileSelection(Workflow workflow,
                          java.io.File defaultFile)
    Create the JFileSelection.

    Parameters:
    workflow - Associated workflow.
    defaultFile - File

    JFileSelection

    public JFileSelection(Workflow workflow,
                          java.lang.String defaultPath)
    Create the JFileSelection.

    Parameters:
    workflow - Associated workflow.
    defaultPath - String

    JFileSelection

    public JFileSelection()
    Create the JFileSelection.
    In order to access to the variables, you have to set the workflow by calling the setWorkflow method.


    JFileSelection

    public JFileSelection(java.lang.String defaultPath)
    Create the JFileSelection.
    In order to access to the variables, you have to set the workflow by calling the setWorkflow method.

    Parameters:
    defaultPath - String

    JFileSelection

    public JFileSelection(java.io.File defaultFile)
    Create the JFileSelection.
    In order to access to the variables, you have to set the workflow by calling the setWorkflow method.

    Parameters:
    defaultFile - File

    JFileSelection

    public JFileSelection(Workflow workflow,
                          java.io.File defaultFile,
                          boolean diplayPath)
    Create the JFileSelection.

    Parameters:
    workflow - Associated workflow.
    defaultFile - File
    diplayPath - if TRUE the whole path of the file is displayed. Otherwise only the file name.
    Method Detail

    addStaticFile

    public void addStaticFile(java.io.File file)
    Add a static file to the list. Use this function if you want the user to see a file that can be selected directly from the list, without having to select "other..." and then choose a file.

    Parameters:
    file - - file to be added
    See Also:
    removeStaticFile(java.io.File)

    removeStaticFile

    public void removeStaticFile(java.io.File file)
    Remove a static file.

    Parameters:
    file - - file to be removed.
    See Also:
    addStaticFile(java.io.File)

    setWorkflow

    public void setWorkflow(Workflow workflow)
    Set the workflow that this panel is working on. The variables of the workflow will be available in the list.

    Parameters:
    workflow - - Workflow

    selectFile

    public int selectFile(java.awt.Component parent,
                          java.lang.String title)
    Open a window to select a file.

    Parameters:
    parent - - the parent component of the dialog, can be null; see showDialog for details
    title - - the dialog title
    Returns:
    the int
    See Also:
    Component.show()

    selectFile

    public int selectFile()
    Open a window to select a file.

    Returns:
    the int

    setFileSelectionMode

    public void setFileSelectionMode(int mode)
    Sets the JXFileChooser to allow the user to just select files, just select directories, or select both files and directories. The default is JFilesChooser.FILES_ONLY.

    Parameters:
    mode - the type of files to be displayed:
    • JXFileChooser.FILES_ONLY
    • JXFileChooser.DIRECTORIES_ONLY
    • JXFileChooser.FILES_AND_DIRECTORIES
    Throws:
    java.lang.IllegalArgumentException - if mode is an illegal file selection mode
    See Also:
    getFileSelectionMode()

    getFileSelectionMode

    public int getFileSelectionMode()
    Returns the current file-selection mode. The default is JFilesChooser.FILES_ONLY.

    Returns:
    the type of files to be displayed, one of the following:
    • JXFileChooser.FILES_ONLY
    • JXFileChooser.DIRECTORIES_ONLY
    • JXFileChooser.FILES_AND_DIRECTORIES
    See Also:
    setFileSelectionMode(int)

    getDialogType

    public int getDialogType()
    Return the type of dialog window display when the user choose a file.

    Returns:
    the type of dialog window to be displayed, one of the following:
    • JPanelFileSelection.OPEN_DIALOG
    • JPanelFileSelection.SAVE_DIALOG

    setDialogType

    public void setDialogType(int type)
    Set the type of dialog window display when the user choose a file.

    Parameters:
    type - - he type of dialog window to be displayed, one of the following:
    • JPanelFileSelection.OPEN_DIALOG
    • JPanelFileSelection.SAVE_DIALOG

    setSelectedFilePath

    public void setSelectedFilePath(java.lang.String path)
    Set the current path and the current selected file.

    Parameters:
    path - (String) Path of the selected file.

    getSelectedFilePath

    public java.lang.String getSelectedFilePath()
    Return the selected path.

    Returns:
    String

    setSelectedFile

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

    Parameters:
    file - the file

    setSelectedItem

    public void setSelectedItem(java.lang.Object object)
    Sets the selected item in the combo box display area to the object in the argument. If object is in the list, the display area shows object selected.

    If object is not in the list and the combo box is uneditable, it will not change the current selection.

    Parameters:
    object - the new selected item

    getSelectedFile

    public java.io.File getSelectedFile()
    Return the selected path.

    Returns:
    File

    setAcceptAllFileFilterUsed

    public void setAcceptAllFileFilterUsed(boolean b)
    Determines whether the AcceptAll FileFilter is used as an available choice in the choosable filter list. If false, the AcceptAll file filter is removed from the list of available file filters. If true, the AcceptAll file filter will become the the actively used file filter.

    Parameters:
    b - - If false, the AcceptAll file filter is removed from the list of available file filters. If true, the AcceptAll file filter will become the the actively used file filter

    isAcceptAllFileFilterUsed

    public boolean isAcceptAllFileFilterUsed()
    Returns whether the AcceptAll FileFilter is used.

    Returns:
    true if the AcceptAll FileFilter is used

    addChoosableFileFilter

    public void addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)
    Adds a filter to the list of user choosable file filters.

    Parameters:
    filter - the FileFilter to add to the choosable file filter list
    See Also:
    getChoosableFileFilters(), removeChoosableFileFilter(javax.swing.filechooser.FileFilter), resetChoosableFileFilters()

    getChoosableFileFilters

    public javax.swing.filechooser.FileFilter[] getChoosableFileFilters()
    Gets the list of user choosable file filters.

    Returns:
    a FileFilter array containing all the choosable file filters
    See Also:
    addChoosableFileFilter(javax.swing.filechooser.FileFilter), removeChoosableFileFilter(javax.swing.filechooser.FileFilter), resetChoosableFileFilters()

    removeChoosableFileFilter

    public boolean removeChoosableFileFilter(javax.swing.filechooser.FileFilter f)
    Removes a filter from the list of user choosable file filters. Returns true if the file filter was removed.

    Parameters:
    f - the file filter
    Returns:
    true, if removes the choosable file filter
    See Also:
    addChoosableFileFilter(javax.swing.filechooser.FileFilter), getChoosableFileFilters(), resetChoosableFileFilters()

    resetChoosableFileFilters

    public void resetChoosableFileFilters()
    Resets the choosable file filter list to its starting state. Normally, this removes all added file filters while leaving the AcceptAll file filter.

    See Also:
    addChoosableFileFilter(javax.swing.filechooser.FileFilter), getChoosableFileFilters(), removeChoosableFileFilter(javax.swing.filechooser.FileFilter)

    displayPath

    public void displayPath(boolean d)
    If TRUE the whole path of the file will be display.
    Otherwise only the file name will be displayed in the list.

    Parameters:
    d - - If TRUE the whole path of the file will be display

    isPathDisplayed

    public boolean isPathDisplayed()
    Return TRUE if the whole path of the file will be display.
    Otherwise only the file name will be displayed in the list.

    Returns:
    true, if checks if is path displayed

    setCurrentDirectory

    public void setCurrentDirectory(java.io.File dir)
    Sets the current directory. Passing in null sets the file chooser to point to the user's default directory. This default depends on the operating system. It is typically the "My Documents" folder on Windows, and the user's home directory on Unix. If the file passed in as currentDirectory is not a directory, the parent of the file will be used as the currentDirectory. If the parent is not traversable, then it will walk up the parent tree until it finds a traversable directory, or hits the root of the file system.

    Parameters:
    dir - - the current directory to point to

    getCurrentDirectory

    public java.io.File getCurrentDirectory()
    Returns the current directory.

    Returns:
    the current directory

    getProperties

    public java.util.Properties getProperties()
    Returns an Properties object that can be used by an Element for saving the selected file.

    Specified by:
    getProperties in interface com.jbbres.lib.PropertiesOwner
    Returns:
    - An Properties object

    setProperties

    public void setProperties(java.util.Properties properties)
    Restore the selected file based on the properties provided.

    Specified by:
    setProperties in interface com.jbbres.lib.PropertiesOwner
    Parameters:
    properties - - properties to applied.

    setEditable

    public boolean setEditable(boolean e)
    Set the panel editable.

    Parameters:
    e - boolean
    Returns:
    true, if sets the editable

    setEnabled

    public void setEnabled(boolean e)
    Set the panel enabled.

    Overrides:
    setEnabled in class javax.swing.JComponent
    Parameters:
    e - boolean

    refresh

    public void refresh()
    Refresh the panel: Display or hide the manually selected file depending on the value choosen in the combo box, and call validate.


    addActionListener

    public void addActionListener(java.awt.event.ActionListener l)
    Add a file selection listener.

    Parameters:
    l - - FilesSelectionListener

    removeActionListener

    public void removeActionListener(java.awt.event.ActionListener l)
    Remove a file selection listener.

    Parameters:
    l - - FilesSelectionListener

    fireActionPerformed

    public void fireActionPerformed()
    Reports a file selection.



    To file bugs or suggest feature enhancements, visit the app.jbbres.com Bug Reporter website.

    Additional documentation available online at http://app.jbbres.com/actions/developers.

    Copyright � 2009-2011 app.jbbres.com. All Rights Reserved.