コード例 #1
0
 public void createNewDocument() {
   view.selectHtmlTab();
   resetDocument();
   view.setTitle("HTML редактор");
   view.resetUndo();
   currentFile = null;
 }
コード例 #2
0
 public void saveDocument() {
   try {
     view.selectHtmlTab();
     if (currentFile != null) {
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     } else saveDocumentAs();
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
コード例 #3
0
 public void saveDocumentAs() {
   try {
     view.selectHtmlTab();
     JFileChooser jFileChooser = new JFileChooser();
     jFileChooser.setFileFilter(new HTMLFileFilter());
     jFileChooser.setDialogTitle("Save File");
     int n = jFileChooser.showSaveDialog(view);
     if (n == JFileChooser.APPROVE_OPTION) {
       currentFile = jFileChooser.getSelectedFile();
       view.setTitle(currentFile.getName());
       try (FileWriter writer = new FileWriter(currentFile)) {
         new HTMLEditorKit().write(writer, document, 0, document.getLength());
       }
     }
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
コード例 #4
0
  public void openDocument() {
    view.selectHtmlTab();
    JFileChooser fileopen = new JFileChooser();
    fileopen.setFileFilter(new HTMLFileFilter());
    int ret = fileopen.showOpenDialog(view);
    if (ret == JFileChooser.APPROVE_OPTION) {
      currentFile = fileopen.getSelectedFile();
      resetDocument();
      view.setTitle(currentFile.getName());
      try (FileReader reader = new FileReader(currentFile)) {
        new HTMLEditorKit()
            .read(
                reader, document,
                0); // Вызови метод read() из класса HTMLEditorKit, который вычитает данные из
                    // реадера в документ document.

      } catch (Exception e) {
        ExceptionHandler.log(
            e); // Проследи, чтобы метод не кидал исключения. Их необходимо просто логировать.
      }
      view.resetUndo();
    }
  }