Class AbstractExtensionFileFilterFileChooser<F extends ExtensionFileFilter>

Type Parameters:
F - the type of extension file filters to use
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public abstract class AbstractExtensionFileFilterFileChooser<F extends ExtensionFileFilter> extends BaseFileChooser
A specialized JFileChooser that lists all available file Readers and Writers for reports.

Based on weka.gui.ConverterFileChooser
Version:
$Revision: 10824 $
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
  • Field Details

    • UNHANDLED_DIALOG

      public static final int UNHANDLED_DIALOG
      unhandled type of dialog.
      See Also:
    • m_DialogType

      protected int m_DialogType
      the type of dialog to display.
    • m_CurrentHandler

      protected Object m_CurrentHandler
      the converter that was chosen by the user.
    • m_Listener

      protected PropertyChangeListener m_Listener
      the propertychangelistener.
    • m_LastFilter

      protected ExtensionFileFilter m_LastFilter
      the last filter that was used for opening/saving.
    • m_FileMustExist

      protected boolean m_FileMustExist
      whether the file to be opened must exist (only open dialog).
  • Constructor Details

    • AbstractExtensionFileFilterFileChooser

      protected AbstractExtensionFileFilterFileChooser()
      onstructs a FileChooser pointing to the user's default directory.
    • AbstractExtensionFileFilterFileChooser

      protected AbstractExtensionFileFilterFileChooser(File currentDirectory)
      Constructs a FileChooser using the given File as the path.
      Parameters:
      currentDirectory - the path to start in
    • AbstractExtensionFileFilterFileChooser

      protected AbstractExtensionFileFilterFileChooser(String currentDirectory)
      Constructs a FileChooser using the given path.
      Parameters:
      currentDirectory - the path to start in
  • Method Details

    • initialize

      protected void initialize()
      Further initializations.
      Overrides:
      initialize in class BaseFileChooser
    • getFiltersInitialized

      protected abstract boolean getFiltersInitialized()
      Returns whether the filters have already been initialized.
      Returns:
      true if the filters have been initialized
    • doInitializeFilters

      protected abstract void doInitializeFilters()
      Performs the actual initialization of the filters.
    • initializeFilters

      protected static void initializeFilters(AbstractExtensionFileFilterFileChooser chooser)
      Performs the initialization of the file filters, if necessary.
      Parameters:
      chooser - the chooser that is being initialized currently
      See Also:
    • setFileMustExist

      public void setFileMustExist(boolean value)
      Whether the selected file must exst (only open dialog).
      Parameters:
      value - if true the file must exist
    • getFileMustExist

      public boolean getFileMustExist()
      Returns whether the selected file must exist (only open dialog).
      Returns:
      true if the file must exist
    • getOpenFileFilters

      protected abstract List<F> getOpenFileFilters()
      Returns the file filters for opening files.
      Returns:
      the file filters
    • getSaveFileFilters

      protected abstract List<F> getSaveFileFilters()
      Returns the file filters for writing files.
      Returns:
      the file filters
    • getDefaultFileFilter

      protected F getDefaultFileFilter(int dialogType)
      Returns the default file filter to use.
      Parameters:
      dialogType - the dialog type: open/save
      Returns:
      the default file filter, null if unable find default one
    • restoreLastFilter

      protected F restoreLastFilter(int dialogType)
      Attempts to restore the last filter in use.
      Parameters:
      dialogType - the dialog type: open/save
      Returns:
      the filter that was selected, null if none
    • initGUI

      protected void initGUI(int dialogType)
      initializes the GUI.
      Parameters:
      dialogType - the type of dialog to setup the GUI for
    • showDialog

      public int showDialog(Component parent, String approveButtonText)
      Pops a custom file chooser dialog with a custom approve button. Throws an exception, if the dialog type is UNHANDLED_DIALOG.
      Overrides:
      showDialog in class BaseFileChooser
      Parameters:
      parent - the parent of this dialog
      approveButtonText - the text for the OK button
      Returns:
      the user's action
    • getDialogType

      public int getDialogType()
      Returns the current dialog type.
      Overrides:
      getDialogType in class JFileChooser
      Returns:
      the type
      See Also:
    • showOpenDialog

      public int showOpenDialog(Component parent)
      Pops up an "Open File" file chooser dialog.
      Overrides:
      showOpenDialog in class JFileChooser
      Parameters:
      parent - the parent of this file chooser
      Returns:
      the result of the user's action
    • showSaveDialog

      public int showSaveDialog(Component parent)
      Pops up an "Save File" file chooser dialog.
      Overrides:
      showSaveDialog in class JFileChooser
      Parameters:
      parent - the parent of this file chooser
      Returns:
      the result of the user's action
    • updateCurrentHandlerHook

      protected void updateCurrentHandlerHook()
      Sets the current handler according to the current filefilter.

      Default implementation does nothing.
      See Also:
    • configureCurrentHandlerHook

      protected void configureCurrentHandlerHook(int dialogType)
      Configures the current handler.

      Default implementation does nothing.
      Parameters:
      dialogType - the type of dialog to configure for
      See Also:
    • setAcceptAllFileFilterUsed

      public void setAcceptAllFileFilterUsed(boolean b)
      Is always using false, since we can't determine the reader/writer based on the extension.
      Overrides:
      setAcceptAllFileFilterUsed in class JFileChooser
      Parameters:
      b - ignored
    • setCorrectOpenFileFilter

      public boolean setCorrectOpenFileFilter(File file)
      Attempts to set the correct file filter for the specified file, using its extension to determine the file filter.
      Parameters:
      file - the file to set the filter for
      Returns:
      true if successfully set filter
    • setCorrectSaveFileFilter

      public boolean setCorrectSaveFileFilter(File file)
      Attempts to set the correct file filter for the specified file, using its extension to determine the file filter.
      Parameters:
      file - the file to set the filter for
      Returns:
      true if successfully set filter
    • isAllFilter

      public static boolean isAllFilter(ExtensionFileFilter filter)
      Checks whether the filter uses "*.*".
      Parameters:
      filter - the filter to check
      Returns:
      true if filter has extension .*