Beispiel #1
0
  private boolean checkForSave() {
    // build warning message
    String message;
    if (file == null) {
      message = "File has been modified.  Save changes?";
    } else {
      message = "File \"" + file.getName() + "\" has been modified.  Save changes?";
    }

    // show confirm dialog
    int r =
        JOptionPane.showConfirmDialog(
            this,
            new JLabel(message),
            "Warning!",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.WARNING_MESSAGE);

    if (r == JOptionPane.YES_OPTION) {
      // Save File
      if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // write the file
        physWriteTextFile(fileChooser.getSelectedFile(), textView.getText());
      } else {
        // user cancelled save after all
        return false;
      }
    }
    return r != JOptionPane.CANCEL_OPTION;
  }
Beispiel #2
0
 /**
  * The ActionListener implementation
  *
  * @param event the event.
  */
 public void actionPerformed(ActionEvent event) {
   String searchText = textField.getText().trim();
   if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) {
     textPane.setText("Blank search text is not allowed for large IdTables.");
   } else {
     File outputFile = null;
     if (saveAs.isSelected()) {
       outputFile = chooser.getSelectedFile();
       if (outputFile != null) {
         String name = outputFile.getName();
         int k = name.lastIndexOf(".");
         if (k != -1) name = name.substring(0, k);
         name += ".txt";
         File parent = outputFile.getAbsoluteFile().getParentFile();
         outputFile = new File(parent, name);
         chooser.setSelectedFile(outputFile);
       }
       if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0);
       outputFile = chooser.getSelectedFile();
     }
     textPane.setText("");
     Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile);
     searcher.start();
   }
 }
Beispiel #3
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     JFileChooser f = new JFileChooser();
     f.setFileFilter(new MyFileFilter());
     int choose = f.showSaveDialog(getContentPane());
     if (choose == JFileChooser.APPROVE_OPTION) {
       BufferedWriter brw = null;
       try {
         File file = f.getSelectedFile();
         brw = new BufferedWriter(new FileWriter(file));
         int i = td.getSelectedIndex();
         TextDocument ta = (TextDocument) td.getComponentAt(i);
         ta.write(brw);
         ta.fileName = file.getName(); // 將檔案名稱更新為存檔的名稱
         td.setTitleAt(td.getSelectedIndex(), ta.fileName);
         ta.file = file;
         ta.save = true; // 設定已儲存
         System.out.println("Save as pass!");
         td.setTitleAt(i, ta.fileName); // 更新標題名稱
       } catch (Exception exc) {
         exc.printStackTrace();
       } finally {
         try {
           brw.close();
         } catch (Exception ecx) {
           ecx.printStackTrace();
         }
       }
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
Beispiel #4
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();
    }
Beispiel #5
0
 public void saveFileAs() {
   // Force user to enter new file name
   if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
     file = fileChooser.getSelectedFile();
   } else {
     // user cancelled save after all
     return;
   }
   // file selected, so write it.
   physWriteTextFile(file, textView.getText());
   // update status
   statusView.setText(" Saved file \"" + file.getName() + "\".");
   // reset dirty bit
   dirty = false;
 }
    // Query user for a filename and attempt to open and write the text
    // component’s content to the file.
    public void actionPerformed(ActionEvent ev) {
      JFileChooser chooser = new JFileChooser();
      if (chooser.showSaveDialog(SimpleEditor.this) != JFileChooser.APPROVE_OPTION) return;
      File file = chooser.getSelectedFile();
      if (file == null) return;

      FileWriter writer = null;
      try {
        writer = new FileWriter(file);
        textComp.write(writer);
      } catch (IOException ex) {
        JOptionPane.showMessageDialog(
            SimpleEditor.this, "File Not Saved", "ERROR", JOptionPane.ERROR_MESSAGE);
      } finally {
        if (writer != null) {
          try {
            writer.close();
          } catch (IOException x) {
          }
        }
      }
    }
 private void saveFileAs() {
   if (dialog.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)
     saveFile(dialog.getSelectedFile().getAbsolutePath());
 }