示例#1
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);
      }
    }
示例#2
0
 public void actionPerformed(ActionEvent e) {
   Document oldDoc = getEditor().getDocument();
   if (oldDoc != null) {
     oldDoc.removeUndoableEditListener(undoHandler);
   }
   getEditor().setDocument(new PlainDocument());
   getEditor().getDocument().addUndoableEditListener(undoHandler);
   resetUndoManager();
   getFrame().setTitle(resources.getString("Title"));
   revalidate();
 }