コード例 #1
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
コード例 #2
0
ファイル: RecordingFrame.java プロジェクト: tmbx/kas
  protected boolean browseFile() {
    File currentFile = new File(fnameField.getText());

    FileDialog fd = new FileDialog(this, "Save next session as...", FileDialog.SAVE);
    fd.setDirectory(currentFile.getParent());
    fd.setVisible(true);
    if (fd.getFile() != null) {
      String newDir = fd.getDirectory();
      String sep = System.getProperty("file.separator");
      if (newDir.length() > 0) {
        if (!sep.equals(newDir.substring(newDir.length() - sep.length()))) newDir += sep;
      }
      String newFname = newDir + fd.getFile();
      if (newFname.equals(fnameField.getText())) {
        fnameField.setText(newFname);
        return true;
      }
    }
    return false;
  }
コード例 #3
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
  /**
   * Checks whether the given window is either a FileDialog, or contains a JFileChooser component.
   * If so, its current directory is stored in the given properties.
   *
   * @param aNamespace the name space to use;
   * @param aProperties the properties to store the found directory in;
   * @param aWindow the window to check for.
   */
  private static void loadFileDialogState(final Preferences aProperties, final Window aWindow) {
    final String propKey = "lastDirectory";

    if (aWindow instanceof FileDialog) {
      final String dir = aProperties.get(propKey, null);
      if (dir != null) {
        ((FileDialog) aWindow).setDirectory(dir);
      }
    } else if (aWindow instanceof JDialog) {
      final Container contentPane = ((JDialog) aWindow).getContentPane();
      final JFileChooser fileChooser =
          (JFileChooser) findComponent(contentPane, JFileChooser.class);
      if (fileChooser != null) {
        final String dir = aProperties.get(propKey, null);
        if (dir != null) {
          fileChooser.setCurrentDirectory(new File(dir));
        }
      }
    }
  }
コード例 #4
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
  /**
   * 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;
    }
  }