Example #1
0
 @Override
 public void actionPerformed(ActionEvent e) {
   boolean isHaveNewDocument = false;
   for (int i = 0; i < td.getTabCount(); i++) { // 依序將檔案撈出
     TextDocument ta = (TextDocument) td.getComponentAt(i);
     if (ta.file == null) { // 判斷是否有新黨案,有的會將運用到預設儲存路徑
       isHaveNewDocument = true;
       break;
     }
   }
   // 有新黨案,但是卻沒設定預設路徑,將跳出警告
   if (isHaveNewDocument && default_auto_save_path == null) {
     JOptionPane.showMessageDialog(
         null,
         "請先設定自動儲存預設位置!\nEdit->Default AutoSave-Path",
         "Save error",
         JOptionPane.ERROR_MESSAGE);
     return;
   }
   if (td.getTabCount() > 0) {
     for (int i = 0; i < td.getTabCount(); i++) { // 依序儲存
       save(i);
     }
     System.out.println("Save pass!");
     JOptionPane.showMessageDialog(
         null, "可儲存的檔案已儲存檔案。\n新檔案儲存於預設位置" + default_auto_save_path + "目錄下.");
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
    public void actionPerformed(ActionEvent e) {
      if (readOnly) {
        return;
      }
      JFileChooser fc = getFileChooser();
      File currentDirectory = fc.getCurrentDirectory();

      if (!currentDirectory.exists()) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderParentDoesntExistText,
            newFolderParentDoesntExistTitleText,
            JOptionPane.WARNING_MESSAGE);
        return;
      }

      File newFolder;
      try {
        newFolder = fc.getFileSystemView().createNewFolder(currentDirectory);
        if (fc.isMultiSelectionEnabled()) {
          fc.setSelectedFiles(new File[] {newFolder});
        } else {
          fc.setSelectedFile(newFolder);
        }
      } catch (IOException exc) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderErrorText + newFolderErrorSeparator + exc,
            newFolderErrorText,
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      fc.rescanCurrentDirectory();
    }
Example #3
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     TextDocument ta = (TextDocument) td.getComponentAt(td.getSelectedIndex());
     Pattern pn = Pattern.compile(tf1.getText());
     Matcher mt = pn.matcher(ta.getText());
     if (e.getSource() == jb2) { // 取代
       ta.setText(mt.replaceAll(tf2.getText()));
     } else if (e.getSource() == jb1) { // 尋找
       Highlighter hl = ta.getHighlighter();
       hl.removeAllHighlights();
       while (mt.find()) {
         try {
           hl.addHighlight(
               mt.start(), mt.end(), new DefaultHighlighter.DefaultHighlightPainter(null));
         } catch (Exception ex) {
         }
       } // 開啟及關閉介面
     } else if (e.getSource() == replace_searchMenuItem) {
       System.out.println("Replace/Search is show:" + !show);
       if (show) {
         getContentPane().remove(jp);
         show = false;
       } else {
         getContentPane().add(jp, BorderLayout.SOUTH);
         show = true;
       }
       validate(); // 刷新容器
     }
   } else if (e.getSource() == replace_searchMenuItem) {
     JOptionPane.showMessageDialog(
         null, "尚無檔案,無法使用!", "Repace/Search error", JOptionPane.ERROR_MESSAGE);
   }
 }
Example #4
0
 public void save(int i) {
   BufferedWriter brw = null;
   TextDocument ta = (TextDocument) td.getComponentAt(i);
   try {
     File file = null;
     if (ta.file == null) { // 判斷是否為新黨案,是的話使用預設路徑儲存
       file = new File(default_auto_save_path + "\\" + ta.fileName);
     } else {
       file = ta.file; // 儲存於原檔案
     }
     brw = new BufferedWriter(new FileWriter(file));
     ta.write(brw);
     ta.save = true;
     td.setTitleAt(i, ta.fileName); // 更新標題名稱
   } catch (FileNotFoundException ffe) { // 若預設路徑不存在,則跳出警告
     JOptionPane.showMessageDialog(
         null,
         ta.fileName + "儲存失敗!\n請檢查Default AutoSave-Path是否存在,或是權限不足.",
         "Save error",
         JOptionPane.ERROR_MESSAGE);
   } catch (Exception exc) {
     exc.printStackTrace();
   } finally {
     try {
       brw.close();
     } catch (Exception exc) {
     }
   }
 }
Example #5
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, "沒有檔案可以儲存!");
   }
 }
Example #6
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) { // 判斷是否有檔案
     TextDocument ta = (TextDocument) td.getComponentAt(td.getSelectedIndex());
     if (ta.file == null) { // 判斷是否為新黨案
       new SystemFileSaveAS().actionPerformed(e); // 做另存新黨
       System.out.println("Save->Save as pass!");
     } else {
       new SystemFileSaveAll().save(td.getSelectedIndex()); // 直接儲存於原檔案
       System.out.println("Save->Save pass!");
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
Example #7
0
  void openButton_actionPerformed(ActionEvent e) {
    String name = nameTextField.getText().trim();
    if (mode == ProfileChooser.MODE_OPEN) { // open
      if (name.equals("")) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notSelect"));
        return;
      }

      UniProfile prof = isSameProfile(name);
      if (prof == null) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notExist") + ": " + name);
        return;
      }

      values = new Object[1];
      values[0] = prof;
    } else { // save as 或 save
      if (name.equals("")) {
        JOptionPane.showMessageDialog(
            this, SanBootView.res.getString("ProfileChooser.errMsg.notName"));
        return;
      }

      String tmpName = name;
      Pattern pattern = Pattern.compile(".+\\.prf");
      Matcher matcher = pattern.matcher(tmpName);
      if (!matcher.find()) {
        tmpName += ".prf";
      }

      UniProfile pf = isSameProfile(tmpName);
      if (pf != null) { // 存 在 相 同 的 名 字 的profile ( pf )
        if (view.initor.mdb.getSchNumOnProfName(pf.getProfileName()) > 0) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("EditProfileDialog.error.hasSch"));
          return;
        }

        if (JOptionPane.showConfirmDialog( // 提示信息更换
                (Dialog) bakable,
                SanBootView.res.getString("ProfileChooser.confirmmsg1"),
                SanBootView.res.getString("common.confirm"),
                JOptionPane.OK_CANCEL_OPTION)
            == JOptionPane.CANCEL_OPTION) {
          return;
        } else {
          values = new Object[2];
          values[0] = pf;
          values[1] = saveAsProfile;
        }
      } else { // 不 存 在 相 同 的 名 字
        String pname = ResourceCenter.PROFILE_DIR + name + ".prf";

        if (pname.indexOf("\"") >= 0
            || pname.indexOf("'") >= 0
            || pname.indexOf(' ') >= 0
            || pname.indexOf('\t') >= 0) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("ProfileChooser.errmsg.badname"));
          return;
        }

        if (pname.getBytes().length >= 1000) {
          JOptionPane.showMessageDialog(
              this, SanBootView.res.getString("ProfileChooser.errmsg.tooLargePname"));
          return;
        }

        values = new Object[1];
        saveAsProfile.setProfileName(pname);
        values[0] = saveAsProfile;
      }
    }

    dispose();
  }
Example #8
0
 @Override
 public void actionPerformed(ActionEvent arg0) {
   default_auto_save_path =
       JOptionPane.showInputDialog(
           null, "自動儲存路徑:", "Default AutoSave-Path", JOptionPane.QUESTION_MESSAGE);
 }