示例#1
0
  protected void showFileChooser() {
    File p;
    FileDialog fDlg;
    String fDir, fFile; // , fPath;
    //		int			i;
    Component win;

    for (win = this; !(win instanceof Frame); ) {
      win = SwingUtilities.getWindowAncestor(win);
      if (win == null) return;
    }

    p = getPath();
    switch (type & PathField.TYPE_BASICMASK) {
      case PathField.TYPE_INPUTFILE:
        fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.LOAD);
        break;
      case PathField.TYPE_OUTPUTFILE:
        fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.SAVE);
        break;
      case PathField.TYPE_FOLDER:
        fDlg = new FileDialog((Frame) win, dlgTxt, FileDialog.SAVE);
        // fDlg = new FolderDialog( (Frame) win, dlgTxt );
        break;
      default:
        fDlg = null;
        assert false : (type & PathField.TYPE_BASICMASK);
        break;
    }
    if (p != null) {
      fDlg.setFile(p.getName());
      fDlg.setDirectory(p.getParent());
    }
    if (filter != null) {
      fDlg.setFilenameFilter(filter);
    }
    showDialog(fDlg);
    fDir = fDlg.getDirectory();
    fFile = fDlg.getFile();

    if (((type & PathField.TYPE_BASICMASK) != PathField.TYPE_FOLDER) && (fDir == null)) {
      fDir = "";
    }

    if ((fFile != null) && (fDir != null)) {

      if ((type & PathField.TYPE_BASICMASK) == PathField.TYPE_FOLDER) {
        p = new File(fDir);
      } else {
        p = new File(fDir + fFile);
      }
      setPathAndDispatchEvent(p);
    }

    fDlg.dispose();
  }
示例#2
0
  /** Handle ItemEvents. */
  public void itemStateChanged(ItemEvent e) {

    final String dialog_title = ResourceHandler.getMessage("template_dialog.title");

    Component target = (Component) e.getSource();

    if (target == recursiveCheckBox) {
      converter.setRecurse(recursiveCheckBox.isSelected());
    } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) {
      converter.setStaticVersioning(staticVersioningRadioButton.isSelected());
    } else if (target == templateCh
        && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected

      // Get the current template selection
      String choiceStr = (String) templateCh.getSelectedItem();

      // If the user chooses 'other', display a file dialog to allow
      // them to select a template file.
      if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) {
        String templatePath = null;
        FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD);
        fd.show();

        // Capture the path entered, if any.
        if (fd.getDirectory() != null && fd.getFile() != null) {
          templatePath = fd.getDirectory() + fd.getFile();
        }

        // If the template file is valid add it and select it.
        if (templatePath != null && setTemplateFile(templatePath)) {
          if (!templateCh.testIfInList(templatePath)) {
            templateCh.addItem(templatePath);
          }
          templateCh.select(templatePath);
        } else {
          templateCh.select(templateCh.getPreviousSelection());
        }
        fd.dispose();
      } else {
        templateCh.select(choiceStr);
      }
    }
  }
示例#3
0
  /**
   * Shows a file-open selection dialog for the given working directory.
   *
   * @param aOwner the owning window to show the dialog in;
   * @param aCurrentDirectory the working directory to start the dialog in, can be <code>null</code>
   *     .
   * @return the selected file, or <code>null</code> if the user aborted the dialog.
   */
  public static final File showFileOpenDialog(
      final Window aOwner,
      final String aCurrentDirectory,
      final javax.swing.filechooser.FileFilter... aFileFilters) {
    if (HostUtils.isMacOS()) {
      final FileDialog dialog;
      if (aOwner instanceof Dialog) {
        dialog = new FileDialog((Dialog) aOwner, "Open file", FileDialog.LOAD);
      } else {
        dialog = new FileDialog((Frame) aOwner, "Open file", FileDialog.LOAD);
      }
      dialog.setDirectory(aCurrentDirectory);

      if ((aFileFilters != null) && (aFileFilters.length > 0)) {
        dialog.setFilenameFilter(new FilenameFilterAdapter(aFileFilters));
      }

      try {
        dialog.setVisible(true);
        final String selectedFile = dialog.getFile();
        return selectedFile == null ? null : new File(dialog.getDirectory(), selectedFile);
      } finally {
        dialog.dispose();
      }
    } else {
      final JFileChooser dialog = new JFileChooser();
      dialog.setCurrentDirectory((aCurrentDirectory == null) ? null : new File(aCurrentDirectory));

      for (javax.swing.filechooser.FileFilter filter : aFileFilters) {
        dialog.addChoosableFileFilter(filter);
      }

      File result = null;
      if (dialog.showOpenDialog(aOwner) == JFileChooser.APPROVE_OPTION) {
        result = dialog.getSelectedFile();
      }

      return result;
    }
  }