public void setPlainText(String text) {
   try {
     resetDocument();
     StringReader stringReader = new StringReader(text);
     HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
     htmlEditorKit.read(stringReader, document, 0);
   } catch (Exception e) {
     ExceptionHandler.log(e);
   }
 }
  public String getPlainText() {

    try {
      StringWriter stringWriter = new StringWriter();
      HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
      htmlEditorKit.write(stringWriter, document, 0, document.getLength());
      return stringWriter.toString();
    } catch (Exception e) {
      ExceptionHandler.log(e);
    }
    return null;
  }
 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);
   }
 }
示例#4
0
 /**
  * Return a label for the given point on the graph axis
  *
  * @param value the value on the graph
  * @return the label for the given value
  */
 private String getLeafLabel(double value) {
   String label = Double.toString(value);
   try {
     int v = (int) value;
     int r = idxMap.getSrc(v);
     if (r < 0 || r >= tm.getRowCount()) {
       return "";
     }
     if (labelColumn >= 0 && labelColumn < tm.getColumnCount()) {
       Object o = tm.getValueAt(r, labelColumn);
       return o != null ? o.toString() : "";
     }
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   try {
     label = Integer.toString((int) value);
   } catch (Exception ex) {
     ExceptionHandler.popupException("" + ex);
   }
   return label;
 }
 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);
   }
 }
  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();
    }
  }