public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) fc.setSelectedFile(new File(name));
    else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)
        && !fc.getSelectedFile().isDirectory()) name = fc.getSelectedFile().getName();
  }
示例#2
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
示例#3
0
 private void saveAs() {
   if (saveFC == null) {
     saveFC = new SaveDataFileChooser();
   }
   int ret = saveFC.showSaveDialog(this);
   if (ret == JFileChooser.APPROVE_OPTION) {
     saveDataToFile(saveFC.getSelectedFile());
   }
 }
 public void save() {
   if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = chooser.getSelectedFile();
       XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));
       encoder.writeObject(frame);
       encoder.close();
     } catch (IOException e) {
       JOptionPane.showMessageDialog(null, e);
     }
   }
 }
示例#5
0
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showSaveDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      frame.setTitle(f.getName());
      Thread saver = new FileSaver(f, editor.getDocument());
      saver.start();
    }
  public void load() {
    // show file chooser dialog
    int r = chooser.showOpenDialog(null);

    // if file selected, open
    if (r == JFileChooser.APPROVE_OPTION) {
      try {
        File file = chooser.getSelectedFile();
        XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
        decoder.readObject();
        decoder.close();
      } catch (IOException e) {
        JOptionPane.showMessageDialog(null, e);
      }
    }
  }
    /**
     * Show the selector for selecting the default folder.
     *
     * @return true if the user selected a default folder and false if not.
     */
    protected boolean showDefaultFolderSelector() throws Exception {
      final JFileChooser selector = new JFileChooser(_activeFileChooser.getCurrentDirectory());
      selector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      final String title =
          (_subfolderName == null)
              ? "Default Folder"
              : "Default Parent Folder of " + _subfolderName;
      selector.setDialogTitle(title);
      final int status = selector.showDialog(_view, "Make Default");

      switch (status) {
        case JFileChooser.APPROVE_OPTION:
          final File defaultFolder = selector.getSelectedFile();
          if (defaultFolder != null) {
            _folderTracker.cacheURL(defaultFolder.toURI().toURL());
            return true;
          } else {
            return false;
          }
        default:
          return false;
      }
    }