コード例 #1
0
 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);
   }
 }
コード例 #2
0
  private void initHtmlFromFile(String fileName) {
    try {
      FileInputStream fileS = new FileInputStream(fileName);
      HTMLEditorKit kit = new HTMLEditorKit();

      htmlDoc = (HTMLDocument) kit.createDefaultDocument();
      Reader HTMLReader = new InputStreamReader(fileS, "UTF-8");
      htmlDoc.putProperty("IgnoreCharsetDirective", new Boolean(true));
      kit.read(HTMLReader, htmlDoc, 0);

    } catch (Exception e) {
      logger.error("", e);
    }
  }
コード例 #3
0
ファイル: OEServerImpl.java プロジェクト: alaib/coursework
    public void appendArchive(String s) {
      HTMLEditorKit editor = (HTMLEditorKit) archivePane.getEditorKit();
      StringReader reader = new StringReader(s);

      try {
        editor.read(reader, archivePane.getDocument(), archivePane.getDocument().getLength());
      } catch (BadLocationException ex) {
        // This happens if your offset is out of bounds.
        System.out.println(ex);
      } catch (IOException ex) {
        // I/O error
        System.out.println(ex);
      }
    }
コード例 #4
0
  private void initHtmlFromStringList(List<String> buff) {
    String htmlText = "";
    for (String str : buff) htmlText += str;

    try {
      InputStream is = new ByteArrayInputStream(htmlText.getBytes("UTF-8"));
      HTMLEditorKit kit = new HTMLEditorKit();
      htmlDoc = (HTMLDocument) kit.createDefaultDocument();
      Reader HTMLReader = new InputStreamReader(is, "UTF-8");
      htmlDoc.putProperty("IgnoreCharsetDirective", new Boolean(true));
      kit.read(HTMLReader, htmlDoc, 0);
      // printProps();

    } catch (UnsupportedEncodingException uee) {
      logger.error("", uee);
    } catch (Exception e) {
      logger.error("", e);
    }
  }
コード例 #5
0
  About() {
    window = new JWindow();
    this.setPreferredSize(new Dimension(650, 550));
    this.setVisible(true);
    this.setLayout(null);

    JTextPane text = new JTextPane();
    text.setBounds(5, 150, 625, 525);
    text.setVisible(true);
    text.setEditable(false);
    text.setOpaque(false);
    HTMLEditorKit htmlKit =
        new HTMLEditorKit() {
          public Parser getParser() {
            return super.getParser();
          }
        };
    HTMLDocument htmlDoc = new HTMLDocument();
    text.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              if (Desktop.isDesktopSupported()) {
                try {
                  Desktop.getDesktop().browse(e.getURL().toURI());
                  return;
                } catch (IOException e1) {
                } catch (URISyntaxException e1) {
                }
              }
              try {
                Runtime.getRuntime().exec("xdg-open ".concat(e.getURL().toString()));
              } catch (IOException ioex) {
                ControlRoom.log(
                    Level.WARNING,
                    "Failed to show file: '"
                        + e.getURL().toString()
                        + "'. Possible unsupported File Manager...",
                    null);
              }
            }
          }
        });
    text.setEditorKit(htmlKit);
    text.setDocument(htmlDoc);
    try {
      BufferedReader reader =
          new BufferedReader(
              new InputStreamReader(
                  this.getClass().getResourceAsStream("/resources/about.html"), "UTF-8"));
      htmlKit.read(reader, htmlDoc, htmlDoc.getLength());
    } catch (IOException ioex) {
      ControlRoom.log(Level.SEVERE, "Failed to read about.html", ioex);
    } catch (BadLocationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    text.addMouseListener(this);
    window.getContentPane().add(text);
    window.getContentPane().add(this);
    window.addMouseListener(this);
    window.pack();
    ControlRoom.setWindowRelativeToCentral(window);
    window.setVisible(true);
    window.setAlwaysOnTop(true);
  }