Package docking.widgets.filechooser

# Class GhidraFileChooser

java.lang.Object
docking.DialogComponentProvider
docking.ReusableDialogComponentProvider
docking.widgets.filechooser.GhidraFileChooser

All Implemented Interfaces:
  `ActionContextProvider`, `StatusListener`, `TaskListener`, `FileFilter`

public class GhidraFileChooser extends ReusableDialogComponentProvider implements FileFilter
An implementation of a file chooser dialog. This class is designed to emulate the JFileChooser, but it removes the network locking issue. When a network drive is down, the JFileChooser can take several minutes to come up. Why use this file chooser over JFileChooser?? Let me enumerate the reasons...

1. JFileChooser cannot show hidden/system files, but we can!
2. JFileChooser does not properly consume key strokes (global actions in docking windows)
3. This class is threaded, so loading delays do not lock the GUI
4. This class provides shortcut buttons similar to those of the Windows native chooser

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DIRECTORIES_ONLY`
  Instruction to display only directories.
  `static final int`
  `FILES_AND_DIRECTORIES`
  Instruction to display both files and directories.
  `static final int`
  `FILES_ONLY`
  Instruction to display only files.

  ### Fields inherited from class docking.DialogComponentProvider

  `applyButton, buttonPanel, cancelButton, dismissButton, okButton, rootPanel`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GhidraFileChooser(Component parent)`
  Constructs a new ghidra file chooser.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `accept(File file)`
  `void`
  `addFileFilter(GhidraFileFilter f)`
  Adds the specified file filter.
  `protected void`
  `cancelCallback()`
  The callback method for when the "Cancel" button is pressed.
  `void`
  `close()`
  `void`
  `dispose()`
  Disposes this dialog.
  `File`
  `getCurrentDirectory()`
  Returns the current directory.
  `File`
  `getSelectedFile()`
  Returns the selected file.
  `File`
  `getSelectedFile(boolean show)`
  Returns the selected file.
  `List<File>`
  `getSelectedFiles()`
  Returns the selected files.
  `boolean`
  `isMultiSelectionEnabled()`
  Returns true if multiple files can be selected.
  `protected void`
  `okCallback()`
  The callback method for when the "OK" button is pressed.
  `void`
  `rescanCurrentDirectory()`
  Causes the file chooser to refresh its contents with the content of the currently displayed directory.
  `void`
  `setApproveButtonText(String buttonText)`
  Sets the text used in the `OK` button
  `void`
  `setApproveButtonToolTipText(String tooltipText)`
  Sets the tooltip text used in the `OK` button
  `void`
  `setCurrentDirectory(File directory)`
  Sets the current directory.
  `void`
  `setFileFilter(GhidraFileFilter filter)`
  Sets the current file filter.
  `void`
  `setFileSelectionMode(int mode)`
  Deprecated.
  use instead `setFileSelectionMode(GhidraFileChooserMode)`
  `void`
  `setFileSelectionMode(GhidraFileChooserMode mode)`
  Sets this file chooser to allow the user to just select files, just select directories, or select both files and directories.
  `void`
  `setLastDirectoryPreference(String newKey)`
  Sets the preference key for this chooser to use when saving the last directory that was used to successfully choose a file.
  `void`
  `setMultiSelectionEnabled(boolean b)`
  Sets the file chooser to allow multiple file selections.
  `void`
  `setSelectedFile(File file)`
  Sets the selected file.
  `void`
  `setSelectedFileFilter(GhidraFileFilter filter)`
  Set the selected filter to the given filter
  `void`
  `setShowDetails(boolean showDetails)`
  When true is passed the chooser will use a detailed table view to show the files; false will show a simplified list of files.
  `void`
  `show()`
  `boolean`
  `wasCancelled()`
  Returns true if the user clicked the "cancel" button on the file chooser.

  ### Methods inherited from class docking.DialogComponentProvider

  `addAction, addApplyButton, addButton, addCancelButton, addDismissButton, addOKButton, addWorkPanel, alertMessage, alertMessage, applyCallback, cancelCurrentTask, clearScheduledTask, clearStatusText, closeDialog, dialogClosed, dialogShown, dismissCallback, doInitialize, escapeCallback, executeProgressTask, getActionContext, getActions, getBackground, getBounds, getComponent, getDefaultButton, getDefaultSize, getDialogSize, getFocusComponent, getGlassPane, getHelpLocation, getId, getInitialLocation, getLocationOnScreen, getParent, getPreferredSize, getRememberLocation, getRememberSize, getStatusColor, getStatusLabel, getStatusText, getTaskMonitorComponent, getTaskScheduler, getTitle, getUseSharedLocation, hideTaskMonitorComponent, isApplyEnabled, isCancelEnabled, isModal, isOKEnabled, isResizeable, isRunningTask, isShowing, isTransient, isVisible, notifyContextChanged, removeAction, removeButton, removeWorkPanel, repack, setApplyEnabled, setApplyToolTip, setBackground, setCancelButtonText, setCancelEnabled, setCancelToolTip, setCursor, setDefaultButton, setDefaultSize, setDialogSize, setDismissToolTip, setFocusComponent, setGlassPane, setHelpLocation, setInitialLocation, setMinimumSize, setMinimumSize, setOkButtonText, setOkEnabled, setOkToolTip, setPreferredSize, setRememberLocation, setRememberSize, setResizable, setStatusJustification, setStatusText, setStatusText, setStatusText, setTitle, setTransient, setUseSharedLocation, showProgressBar, showTaskMonitorComponent, stopProgressTimer, taskCancelled, taskCompleted, toFront, toString, waitForCurrentTask`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### 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

- ## Constructor Details

  - ### GhidraFileChooser

    public GhidraFileChooser(Component parent)
    Constructs a new ghidra file chooser.
    Parameters:
      `parent` - the parent component

- ## Method Details

  - ### setShowDetails

    public void setShowDetails(boolean showDetails)
    When true is passed the chooser will use a detailed table view to show the files; false will show a simplified list of files.
    Parameters:
      `showDetails` - true to show details

  - ### accept

    public boolean accept(File file)
    Specified by:
      `accept` in interface `FileFilter`

  - ### setFileSelectionMode

    @Deprecated public void setFileSelectionMode(int mode)
    Deprecated.
    use instead `setFileSelectionMode(GhidraFileChooserMode)`
    Sets the `GhidraFileChooser` 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:
      - GhidraFileChooser.FILES_ONLY
      - GhidraFileChooser.DIRECTORIES_ONLY
      - GhidraFileChooser.FILES_AND_DIRECTORIES
    Throws:
      `IllegalArgumentException` - if `mode` is an illegal Dialog mode

  - ### setFileSelectionMode

    public void setFileSelectionMode(GhidraFileChooserMode mode)
    Sets this file chooser to allow the user to just select files, just select directories, or select both files and directories. The default is `GhidraFileChooserMode.FILES_ONLY`.
    Parameters:
      `mode` - the type of files to be displayed

  - ### isMultiSelectionEnabled

    public boolean isMultiSelectionEnabled()
    Returns true if multiple files can be selected.
    Returns:
      true if multiple files can be selected
    See Also:
      - `setMultiSelectionEnabled(boolean)`

  - ### setMultiSelectionEnabled

    public void setMultiSelectionEnabled(boolean b)
    Sets the file chooser to allow multiple file selections.
    Parameters:
      `b` - true if multiple files may be selected
    See Also:
      - `isMultiSelectionEnabled()`

  - ### setApproveButtonText

    public void setApproveButtonText(String buttonText)
    Sets the text used in the `OK` button
    Parameters:
      `buttonText` - the text

  - ### setApproveButtonToolTipText

    public void setApproveButtonToolTipText(String tooltipText)
    Sets the tooltip text used in the `OK` button
    Parameters:
      `tooltipText` - the tooltip text

  - ### setLastDirectoryPreference

    public void setLastDirectoryPreference(String newKey)
    Sets the preference key for this chooser to use when saving the last directory that was used to successfully choose a file.
    Parameters:
      `newKey` - the key

  - ### getSelectedFile

    public File getSelectedFile()
    Returns the selected file. This can be set either by the programmer via `setSelectedFile(File)` or by a user action, such as either typing the filename into the UI or selecting the file from a list in the UI.
    Returns:
      the selected file; null if cancelled or no file was selected

  - ### getSelectedFiles

    public List<File> getSelectedFiles()
    Returns the selected files. This will show the file chooser
    Returns:
      the selected files; an empty array if cancelled or no file was selected

  - ### getSelectedFile

    public File getSelectedFile(boolean show)
    Returns the selected file. This can be set either by the programmer via `setSelectedFile(File)` or by a user action, such as either typing the filename into the UI or selecting the file from a list in the UI.

    Note: this method can be called after the chooser has been shown, in which case the value returned has been validated by the chooser. Also, the method may be called while the chooser is showing (like from a test thread). In this case, the selected file will not have been validated by the chooser.

    Parameters:
      `show` - if true then the dialog is displayed
    Returns:
      the selected file; null if cancelled or no file was selected

  - ### setSelectedFile

    public void setSelectedFile(File file)
    Sets the selected file. If the file's parent directory is not the current directory, changes the current directory to be the file's parent directory.

    If the given file is a directory, then it's parent directory will be made the current directory and the directory represented by the file will be selected within the parent directory.

    If the given file does not exist, then the following will happen:

    - If the parent directory of the file exists, then the parent directory will be made the current directory and the name of the file will be put into the filename textfield; otherwise,
    - If the parent file does not exist, then the selection is cleared.

    If the given file is null, then the selected file state is cleared.

    Parameters:
      `file` - the selected file
    See Also:
      - `getSelectedFile()`

  - ### show

    public void show()

  - ### close

    public void close()
    Overrides:
      `close` in class `ReusableDialogComponentProvider`

  - ### getCurrentDirectory

    public File getCurrentDirectory()
    Returns the current directory.
    Returns:
      the current directory
    See Also:
      - `setCurrentDirectory(java.io.File)`

  - ### setCurrentDirectory

    public void setCurrentDirectory(File directory)
    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:
      `directory` - the current directory to point to
    See Also:
      - `getCurrentDirectory()`

  - ### rescanCurrentDirectory

    public void rescanCurrentDirectory()
    Causes the file chooser to refresh its contents with the content of the currently displayed directory.

  - ### dispose

    public void dispose()
    Description copied from class: `DialogComponentProvider`
    Disposes this dialog. Only call this when the dialog is no longer used. Calling this method will close the dialog if it is open.
    Overrides:
      `dispose` in class `ReusableDialogComponentProvider`

  - ### addFileFilter

    public void addFileFilter(GhidraFileFilter f)
    Adds the specified file filter.
    Parameters:
      `f` - the new file filter

  - ### setSelectedFileFilter

    public void setSelectedFileFilter(GhidraFileFilter filter)
    Set the selected filter to the given filter
    Parameters:
      `filter` - the filter to initially set

  - ### setFileFilter

    public void setFileFilter(GhidraFileFilter filter)
    Sets the current file filter.
    Parameters:
      `filter` - the file filter to make current

  - ### wasCancelled

    public boolean wasCancelled()
    Returns true if the user clicked the "cancel" button on the file chooser.
    Returns:
      true if the user clicked the "cancel" button on the file chooser

  - ### cancelCallback

    protected void cancelCallback()
    Description copied from class: `DialogComponentProvider`
    The callback method for when the "Cancel" button is pressed. The default behavior is to call setVisible(false) and dispose() on the dialog.
    Overrides:
      `cancelCallback` in class `DialogComponentProvider`

  - ### okCallback

    protected void okCallback()
    Description copied from class: `DialogComponentProvider`
    The callback method for when the "OK" button is pressed.
    Overrides:
      `okCallback` in class `DialogComponentProvider`