Beispiel #1
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 #2
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 #3
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);
      }
    }
Beispiel #4
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 #5
0
 @Override
 public void actionPerformed(ActionEvent e) {
   JFileChooser f = new JFileChooser();
   f.setFileFilter(new MyFileFilter()); // 設定檔案選擇器
   int choose = f.showOpenDialog(getContentPane()); // 顯示檔案選取
   if (choose == JFileChooser.OPEN_DIALOG) { // 有開啟檔案的話,開始讀檔
     BufferedReader br = null;
     try {
       File file = f.getSelectedFile();
       br = new BufferedReader(new FileReader(file));
       TextDocument ta = new TextDocument(file.getName(), file);
       ta.addKeyListener(new SystemTrackSave());
       ta.read(br, null);
       td.add(ta);
       td.setTitleAt(docCount++, file.getName());
     } catch (Exception exc) {
       exc.printStackTrace();
     } finally {
       try {
         br.close();
       } catch (Exception ecx) {
         ecx.printStackTrace();
       }
     }
   }
 }
 public void actionPerformed(ActionEvent e) {
   saveOld();
   if (dialog.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
     readInFile(dialog.getSelectedFile().getAbsolutePath());
   }
   SaveAs.setEnabled(true);
 }
Beispiel #7
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 #8
0
 void getTable() {
   if (chooser == null) {
     File userdir = new File(System.getProperty("user.dir"));
     chooser = new JFileChooser(userdir);
   }
   if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
     file = chooser.getSelectedFile();
     fileLength = file.length();
     setTitle(windowTitle + ": " + file.getAbsolutePath());
     int size = Key.getEncryptionKeySize(this, true);
     key = Key.getEncryptionKey(this, true, size);
     if (key == null) key = defaultKey;
     initCipher();
   } else System.exit(0);
 }
Beispiel #9
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;
 }
Beispiel #10
0
 public void openFile() {
   if (!dirty || checkForSave()) {
     if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
       file = fileChooser.getSelectedFile();
     } else {
       // user cancelled open after all
       return;
     }
     // load file into text view
     textView.setText(physReadTextFile(file));
     // update status
     statusView.setText(" Loaded 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());
 }