Package javax.swing.text.html

Examples of javax.swing.text.html.HTMLDocument


    }

    public static void convertHtmlToText(Reader reader, Writer writer) throws IOException, BadLocationException {

        EditorKit kit = new HTMLEditorKit();
        HTMLDocument doc = new HTMLDocument();
        kit.read(reader, doc, 0);

        HTMLtoPlainTextWriter2 x = new HTMLtoPlainTextWriter2(writer, doc);
        x.write();
        writer.close();
View Full Code Here


    JTextPane html = new JTextPane();
    html.setContentType("text/html");
   
    html.setText("<p id = myOne>my text<i><b id = myTwo>myBold</b></i>xxx");

    HTMLDocument doc = (HTMLDocument) html.getDocument();

    Element el = doc.getElement("myOne");

    harness.check(true, el != null, "p with id must be found");
    harness.check(
                  el.getAttributes().getAttribute(StyleConstants.NameAttribute),
                  HTML.Tag.P, "Type must match");
    harness.check(!el.isLeaf());

    el = doc.getElement("myNone");
    harness.check(el == null, "should not be found");
   
  }
View Full Code Here

    URLConnection connection = url.openConnection();
    InputStream is = connection.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
    HTMLEditorKit.Parser parser = new ParserDelegator();
    HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
    parser.parse(br, callback, true);

    ElementIterator iterator = new ElementIterator(htmlDoc);
    Element element;
    while ((element = iterator.next()) != null)
View Full Code Here

            JEditorPane welcomeTextView = new JEditorPane(url);
            welcomeTextView.setFocusable(false);
            welcomeTextView.setEditable(false);

            // Set font
            HTMLDocument doc = (HTMLDocument)welcomeTextView.getDocument();
            final Style style = doc.addStyle("normal", null);
            doc.setCharacterAttributes(0, doc.getLength(), style, false);

            welcomeText = welcomeTextView;
        } catch (IOException e)
        {
            String text = ResourceUtils.getString(ResourceIDs.LICENSE_WELCOME_TEXT);
View Full Code Here

      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        final JEditorPane pane = (JEditorPane) e.getSource();

        if (e instanceof HTMLFrameHyperlinkEvent) {
          final HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
          final HTMLDocument doc = (HTMLDocument) pane.getDocument();
          doc.processHTMLFrameHyperlinkEvent(evt);
        } else {
          try {
            final String s = e.getURL().toExternalForm();
            pane.setPage(s);
          } catch (final Throwable t) {
            try {
              final Document doc = pane.getDocument();
              final String content = doc.getText(0, doc
                  .getLength());
              String searchString = " \n"
                + e.getDescription().substring(1);
              int pos = content.indexOf(searchString);
              if (pos == -1) {
View Full Code Here

    protected void applyTag(HTML.Tag tag) {
        Document doc = getDocument();
        if (!(doc instanceof HTMLDocument)) {
            return;
        }
        HTMLDocument hdoc = (HTMLDocument)doc;
        int start = getSelectionStart();
        int end = getSelectionEnd();

        Element element = hdoc.getParagraphElement(start);
        MutableAttributeSet newAttrs = new SimpleAttributeSet(element.getAttributes());
        newAttrs.addAttribute(StyleConstants.NameAttribute, tag);

        hdoc.setParagraphAttributes(start, end - start, newAttrs, true);
    }
View Full Code Here

  }

  @Override
  public String getText() {
    String text = super.getText();
    HTMLDocument document = (HTMLDocument) this.getDocument();
    // #0 is the HTML element, #1 the bidi-root
    Element[] roots = document.getRootElements();
    Element body = findElement(roots[0], HTML.Tag.BODY);
    Element p = findElement(body, HTML.Tag.P);

    Document realText = p.getDocument();
    try {
View Full Code Here

    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        JEditorPane pane = (JEditorPane) e.getSource();
        if (e instanceof HTMLFrameHyperlinkEvent) {
          HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
          HTMLDocument doc = (HTMLDocument) pane.getDocument();
          doc.processHTMLFrameHyperlinkEvent(evt);
        } else {
          try {
            pane.setPage(e.getURL());
          } catch (Throwable t) {
            t.printStackTrace();
View Full Code Here

    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        JEditorPane pane = (JEditorPane) e.getSource();
        if (e instanceof HTMLFrameHyperlinkEvent) {
          HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
          HTMLDocument doc = (HTMLDocument) pane.getDocument();
          doc.processHTMLFrameHyperlinkEvent(evt);
        } else {
          try {
            pane.setPage(e.getURL());
          } catch (Throwable t) {
            t.printStackTrace();
View Full Code Here

    private static final long serialVersionUID = 6031640599826858733L;

    // Override createDefaultDocument to force synchronous loading
        @Override
        public Document createDefaultDocument() {
            HTMLDocument doc = (HTMLDocument) super.createDefaultDocument();
            doc.setTokenThreshold(Integer.MAX_VALUE);
            doc.setAsynchronousLoadPriority(-1);
            return doc;
        }
View Full Code Here

TOP

Related Classes of javax.swing.text.html.HTMLDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.