Class JnaFileChooser

java.lang.Object
anlavn.ui.filechooser.JnaFileChooser

public class JnaFileChooser extends Object
JnaFileChooser is a wrapper around the native Windows file chooser and folder browser that falls back to the Swing JFileChooser on platforms other than Windows or if the user chooses a combination of features that are not supported by the native dialogs (for example multiple selection of directories). Example: JnaFileChooser fc = new JnaFileChooser(); fc.setFilter("All Files", "*"); fc.setFilter("Pictures", "jpg", "jpeg", "gif", "png", "bmp"); fc.setMultiSelectionEnabled(true); fc.setMode(JnaFileChooser.Mode.FilesAndDirectories); if (fc.showOpenDialog(parent)) { Files[] selected = fc.getSelectedFiles(); // do something with selected }
  • Field Details

    • selectedFiles

      protected File[] selectedFiles
    • currentDirectory

      protected File currentDirectory
    • filters

      protected ArrayList<String[]> filters
    • multiSelectionEnabled

      protected boolean multiSelectionEnabled
    • mode

      protected JnaFileChooser.Mode mode
    • defaultFile

      protected String defaultFile
    • dialogTitle

      protected String dialogTitle
    • openButtonText

      protected String openButtonText
    • saveButtonText

      protected String saveButtonText
  • Constructor Details

    • JnaFileChooser

      public JnaFileChooser()
      creates a new file chooser with multiselection disabled and mode set to allow file selection only.
    • JnaFileChooser

      public JnaFileChooser(File currentDirectory)
      creates a new file chooser with the specified initial directory
      Parameters:
      currentDirectory - the initial directory
    • JnaFileChooser

      public JnaFileChooser(String currentDirectoryPath)
      creates a new file chooser with the specified initial directory
      Parameters:
      currentDirectoryPath - the initial directory
  • Method Details

    • showOpenDialog

      public boolean showOpenDialog(Window parent)
      shows a dialog for opening files
      Parameters:
      parent - the parent window
      Returns:
      true if the user clicked OK
    • showSaveDialog

      public boolean showSaveDialog(Window parent)
      shows a dialog for saving files
      Parameters:
      parent - the parent window
      Returns:
      true if the user clicked OK
    • addFilter

      public void addFilter(String name, String... filter)
      add a filter to the user-selectable list of file filters
      Parameters:
      name - name of the filter
      filter - you must pass at least 1 argument, the arguments are the file extensions.
    • setMode

      public void setMode(JnaFileChooser.Mode mode)
      sets the selection mode
      Parameters:
      mode - the selection mode
    • getMode

      public JnaFileChooser.Mode getMode()
    • setCurrentDirectory

      public void setCurrentDirectory(String currentDirectoryPath)
    • setMultiSelectionEnabled

      public void setMultiSelectionEnabled(boolean enabled)
      sets whether to enable multiselection
      Parameters:
      enabled - true to enable multiselection, false to disable it
    • isMultiSelectionEnabled

      public boolean isMultiSelectionEnabled()
    • setDefaultFileName

      public void setDefaultFileName(String dfile)
    • setTitle

      public void setTitle(String title)
      set a title name
      Parameters:
      title - of dialog
    • setOpenButtonText

      public void setOpenButtonText(String buttonText)
      set a open button name
      Parameters:
      buttonText - button text
    • setSaveButtonText

      public void setSaveButtonText(String buttonText)
      set a save button name
      Parameters:
      buttonText - button text
    • getSelectedFiles

      public File[] getSelectedFiles()
    • getSelectedFile

      public File getSelectedFile()
    • getCurrentDirectory

      public File getCurrentDirectory()