Exemplo n.º 1
0
 public void createNewDocument() {
   view.selectHtmlTab();
   resetDocument();
   view.setTitle("HTML редактор");
   view.resetUndo();
   currentFile = null;
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 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);
   }
 }
Exemplo n.º 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();
    }
  }