javax.swing.text.html.HTMLDocument Java Examples

The following examples show how to use javax.swing.text.html.HTMLDocument. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BrowserDisplayer.java    From netbeans with Apache License 2.0 7 votes vote down vote up
/**
    * Sets data optained from the View
    */
   public void setViewData(View v) {
myView = v;
doc = (HTMLDocument) myView.getDocument();
base = doc.getBase();

// Set the current font information in the local text attributes
Font font = getFont();
textAttribs = new SimpleAttributeSet();
textAttribs.removeAttribute(StyleConstants.FontSize);
textAttribs.removeAttribute(StyleConstants.Bold);
textAttribs.removeAttribute(StyleConstants.Italic);
textAttribs.addAttribute(StyleConstants.FontFamily,
			 font.getName());
textAttribs.addAttribute(StyleConstants.FontSize,
			 new Integer(font.getSize()));
textAttribs.addAttribute(StyleConstants.Bold,
			 Boolean.valueOf(font.isBold()));
textAttribs.addAttribute(StyleConstants.Italic,
			 Boolean.valueOf(font.isItalic()));
   }
 
Example #2
Source File: bug8058120.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    JFrame frame = new JFrame("bug8058120");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
    editorPane.setEditorKit(new HTMLEditorKit());

    document = (HTMLDocument) editorPane.getDocument();

    editorPane.setText(text);

    frame.add(editorPane);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
 
Example #3
Source File: bug8005391.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #4
Source File: bug8028616.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ParserCB cb = new ParserCB();
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();

    htmlDoc.getParser().parse(new StringReader(text), cb, true);

    synchronized (lock) {
        if (!isCallbackInvoked) {
            lock.wait(5000);
        }
    }

    if (!isCallbackInvoked) {
        throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
    }

    if (exception != null) {
        throw exception;
    }
}
 
Example #5
Source File: HtmlCommentTagParseTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
            MyParser cb = new MyParser();
            HTMLEditorKit htmlKit = new HTMLEditorKit();
            HTMLDocument htmlDoc = (HTMLDocument)
                    htmlKit.createDefaultDocument();
        FileReader reader = null;
        try {
            reader = new FileReader(getDirURL() + "test.html");
            htmlDoc.getParser().parse(reader, cb, true);
            if(failed) {
                throw new RuntimeException("Test failed");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example #6
Source File: EditorPaneDemo.java    From Darcula with Apache License 2.0 6 votes vote down vote up
private HyperlinkListener createHyperLinkListener() {
    return new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (e instanceof HTMLFrameHyperlinkEvent) {
                    ((HTMLDocument) html.getDocument()).processHTMLFrameHyperlinkEvent(
                            (HTMLFrameHyperlinkEvent) e);
                } else {
                    try {
                        html.setPage(e.getURL());
                    } catch (IOException ioe) {
                        System.out.println("IOE: " + ioe);
                    }
                }
            }
        }
    };
}
 
Example #7
Source File: Test6933784.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void checkImages() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            HTMLEditorKit c = new HTMLEditorKit();
            HTMLDocument doc = new HTMLDocument();

            try {
                c.read(new StringReader("<HTML><TITLE>Test</TITLE><BODY><IMG id=test></BODY></HTML>"), doc, 0);
            } catch (Exception e) {
                throw new RuntimeException("The test failed", e);
            }

            Element elem = doc.getElement("test");
            ImageView iv = new ImageView(elem);

            if (iv.getLoadingImageIcon() == null) {
                throw new RuntimeException("getLoadingImageIcon returns null");
            }

            if (iv.getNoImageIcon() == null) {
                throw new RuntimeException("getNoImageIcon returns null");
            }
        }
    });
}
 
Example #8
Source File: bug8005391.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #9
Source File: Test6933784.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void checkImages() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            HTMLEditorKit c = new HTMLEditorKit();
            HTMLDocument doc = new HTMLDocument();

            try {
                c.read(new StringReader("<HTML><TITLE>Test</TITLE><BODY><IMG id=test></BODY></HTML>"), doc, 0);
            } catch (Exception e) {
                throw new RuntimeException("The test failed", e);
            }

            Element elem = doc.getElement("test");
            ImageView iv = new ImageView(elem);

            if (iv.getLoadingImageIcon() == null) {
                throw new RuntimeException("getLoadingImageIcon returns null");
            }

            if (iv.getNoImageIcon() == null) {
                throw new RuntimeException("getNoImageIcon returns null");
            }
        }
    });
}
 
Example #10
Source File: bug8058120.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    JFrame frame = new JFrame("bug8058120");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
    editorPane.setEditorKit(new HTMLEditorKit());

    document = (HTMLDocument) editorPane.getDocument();

    editorPane.setText(text);

    frame.add(editorPane);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
 
Example #11
Source File: Test6933784.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void checkImages() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            HTMLEditorKit c = new HTMLEditorKit();
            HTMLDocument doc = new HTMLDocument();

            try {
                c.read(new StringReader("<HTML><TITLE>Test</TITLE><BODY><IMG id=test></BODY></HTML>"), doc, 0);
            } catch (Exception e) {
                throw new RuntimeException("The test failed", e);
            }

            Element elem = doc.getElement("test");
            ImageView iv = new ImageView(elem);

            if (iv.getLoadingImageIcon() == null) {
                throw new RuntimeException("getLoadingImageIcon returns null");
            }

            if (iv.getNoImageIcon() == null) {
                throw new RuntimeException("getNoImageIcon returns null");
            }
        }
    });
}
 
Example #12
Source File: bug8058120.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    JFrame frame = new JFrame("bug8058120");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
    editorPane.setEditorKit(new HTMLEditorKit());

    document = (HTMLDocument) editorPane.getDocument();

    editorPane.setText(text);

    frame.add(editorPane);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
 
Example #13
Source File: SvnOptionsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form SvnOptionsPanel */
public SvnOptionsPanel() {
    initComponents();
    if(Utilities.isWindows()) {
        jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.windows.text"));
        jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.text"));
    } else {
        jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.unix.text"));
        jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.unix.text"));
    }
    Document doc = textPaneClient.getDocument();
    if (doc instanceof HTMLDocument) { // Issue 185505
        HTMLDocument htmlDoc = (HTMLDocument)doc;
        Font font = UIManager.getFont("Label.font"); // NOI18N
        String bodyRule = "body { font-family: " + font.getFamily() + "; " // NOI18N
            + "color: " + SvnUtils.getColorString(textPaneClient.getForeground()) + "; " //NOI18N
            + "font-size: " + font.getSize() + "pt; }"; // NOI18N
        htmlDoc.getStyleSheet().addRule(bodyRule);
    }
    textPaneClient.setOpaque(false);
    textPaneClient.setBackground(new Color(0,0,0,0)); // windows and nimbus workaround see issue 145826
}
 
Example #14
Source File: bug8005391.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #15
Source File: HtmlCommentTagParseTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
            MyParser cb = new MyParser();
            HTMLEditorKit htmlKit = new HTMLEditorKit();
            HTMLDocument htmlDoc = (HTMLDocument)
                    htmlKit.createDefaultDocument();
        FileReader reader = null;
        try {
            reader = new FileReader(getDirURL() + "test.html");
            htmlDoc.getParser().parse(reader, cb, true);
            if(failed) {
                throw new RuntimeException("Test failed");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example #16
Source File: bug8005391.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #17
Source File: bug8005391.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
Example #18
Source File: HtmlDemo.java    From Darcula with Apache License 2.0 6 votes vote down vote up
public HyperlinkListener createHyperLinkListener() {
return new HyperlinkListener() {
    public void hyperlinkUpdate(HyperlinkEvent e) {
	if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
	    if (e instanceof HTMLFrameHyperlinkEvent) {
		((HTMLDocument)html.getDocument()).processHTMLFrameHyperlinkEvent(
		    (HTMLFrameHyperlinkEvent)e);
	    } else {
		try {
		    html.setPage(e.getURL());
		} catch (IOException ioe) {
		    System.out.println("IOE: " + ioe);
		}
	    }
	}
    }
};
   }
 
Example #19
Source File: bug8028616.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ParserCB cb = new ParserCB();
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();

    htmlDoc.getParser().parse(new StringReader(text), cb, true);

    synchronized (lock) {
        if (!isCallbackInvoked) {
            lock.wait(5000);
        }
    }

    if (!isCallbackInvoked) {
        throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
    }

    if (exception != null) {
        throw exception;
    }
}
 
Example #20
Source File: bug6636983.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void checkComposedTextRun() {
    HTMLDocument d = (HTMLDocument) ep.getDocument();
    ElementIterator it = new ElementIterator(d.getDefaultRootElement());

    while (true) {
        Element e = it.next();
        if (e == null) {
            throw new RuntimeException("no composed text found");
        }
        AttributeSet a = e.getAttributes();
        if (a.isDefined(StyleConstants.ComposedTextAttribute)) {
            if (!AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute))) {
                throw new RuntimeException("AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute)) is false");
            }

            if (a.isDefined(SwingUtilities2.IMPLIED_CR)) {
                throw new RuntimeException("a.isDefined(SwingUtilities2.IMPLIED_CR) is true");
            }

            return;
        }
    }

}
 
Example #21
Source File: HTMLDocumentEditor.java    From egdownloader with GNU General Public License v2.0 6 votes vote down vote up
/** 构造方法 */
public HTMLDocumentEditor() {
	/** 设置主窗体标题 */
	super("HTMLDocumentEditor");
	HTMLEditorKit editorKit = new HTMLEditorKit();
	/** 创建默认文档指向网页引用document */
	document = (HTMLDocument) editorKit.createDefaultDocument();

	// 强制SWINGSET实现跨平台,不改变风格
	try {
		UIManager.setLookAndFeel(UIManager
				.getCrossPlatformLookAndFeelClassName());
		// 如果你想用系统的界面风格替代,请注释掉上一行代码,而取消下一行代码的注释:
		// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception exc) {
		// 产生异常,则显示错误消息:加载L&F错误
		System.err.println("Error loading L&F: " + exc);
	}

	// 调用初始化方法
	init();
}
 
Example #22
Source File: REditorPane.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void setHRef(int pos, Document doc) {
    hRef = null;
    text = null;
    if (!(doc instanceof HTMLDocument)) {
        return;
    }
    HTMLDocument hdoc = (HTMLDocument) doc;
    Iterator iterator = hdoc.getIterator(HTML.Tag.A);
    while (iterator.isValid()) {
        if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) {
            AttributeSet attributes = iterator.getAttributes();
            if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) {
                try {
                    text = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset()).trim();
                    hRef = attributes.getAttribute(HTML.Attribute.HREF).toString();
                    setIndexOfHrefAndText(hdoc, pos, text, hRef);
                } catch (BadLocationException e) {
                    e.printStackTrace();
                }
                return;
            }
        }
        iterator.next();
    }
}
 
Example #23
Source File: ManualHandler.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
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();
      }
    }
  }
}
 
Example #24
Source File: bug8028616.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ParserCB cb = new ParserCB();
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();

    htmlDoc.getParser().parse(new StringReader(text), cb, true);

    synchronized (lock) {
        if (!isCallbackInvoked) {
            lock.wait(5000);
        }
    }

    if (!isCallbackInvoked) {
        throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
    }

    if (exception != null) {
        throw exception;
    }
}
 
Example #25
Source File: UIUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * This method (as opposed to {@link JEditorPane#scrollToReference}) supports also targets using {@code id} HTML attribute.
 */
public static void scrollToReference(@Nonnull JEditorPane editor, @Nonnull String reference) {
  Document document = editor.getDocument();
  if (document instanceof HTMLDocument) {
    Element elementById = ((HTMLDocument)document).getElement(reference);
    if (elementById != null) {
      try {
        int pos = elementById.getStartOffset();
        Rectangle r = editor.modelToView(pos);
        if (r != null) {
          r.height = editor.getVisibleRect().height;
          editor.scrollRectToVisible(r);
          editor.setCaretPosition(pos);
        }
      }
      catch (BadLocationException e) {
        getLogger().error(e);
      }
      return;
    }
  }
  editor.scrollToReference(reference);
}
 
Example #26
Source File: bug6636983.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void checkComposedTextRun() {
    HTMLDocument d = (HTMLDocument) ep.getDocument();
    ElementIterator it = new ElementIterator(d.getDefaultRootElement());

    while (true) {
        Element e = it.next();
        if (e == null) {
            throw new RuntimeException("no composed text found");
        }
        AttributeSet a = e.getAttributes();
        if (a.isDefined(StyleConstants.ComposedTextAttribute)) {
            if (!AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute))) {
                throw new RuntimeException("AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute)) is false");
            }

            if (a.isDefined(SwingUtilities2.IMPLIED_CR)) {
                throw new RuntimeException("a.isDefined(SwingUtilities2.IMPLIED_CR) is true");
            }

            return;
        }
    }

}
 
Example #27
Source File: bug6636983.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void checkComposedTextRun() {
    HTMLDocument d = (HTMLDocument) ep.getDocument();
    ElementIterator it = new ElementIterator(d.getDefaultRootElement());

    while (true) {
        Element e = it.next();
        if (e == null) {
            throw new RuntimeException("no composed text found");
        }
        AttributeSet a = e.getAttributes();
        if (a.isDefined(StyleConstants.ComposedTextAttribute)) {
            if (!AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute))) {
                throw new RuntimeException("AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute)) is false");
            }

            if (a.isDefined(SwingUtilities2.IMPLIED_CR)) {
                throw new RuntimeException("a.isDefined(SwingUtilities2.IMPLIED_CR) is true");
            }

            return;
        }
    }

}
 
Example #28
Source File: HtmlCommentTagParseTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(() -> {
            MyParser cb = new MyParser();
            HTMLEditorKit htmlKit = new HTMLEditorKit();
            HTMLDocument htmlDoc = (HTMLDocument)
                    htmlKit.createDefaultDocument();
        FileReader reader = null;
        try {
            reader = new FileReader(getDirURL() + "test.html");
            htmlDoc.getParser().parse(reader, cb, true);
            if(failed) {
                throw new RuntimeException("Test failed");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example #29
Source File: WebStorePanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private double getAdjustedHeight(){
    JEditorPane fakePane = new JEditorPane();
    fakePane.setEditable(false);
    fakePane.setBorder(null);
    fakePane.setContentType("text/html"); // NOI18N
    fakePane.setFont(description.getFont());
    Dimension size = description.getPreferredSize();
    size.setSize( size.getWidth(), Short.MAX_VALUE);
    fakePane.setSize( size);
    fakePane.setText(description.getText());
    Font font = description.getFont();
    String bodyRule = "body { font-family: " + font.getFamily() + "; " +
            "font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument)fakePane.getDocument()).getStyleSheet().addRule(bodyRule);
    return fakePane.getPreferredSize().getHeight();
}
 
Example #30
Source File: OverviewControllerUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void showInThreads(Instance instance) {
    if (!showThreads) {
        showThreads = true;
        instanceToSelect = instance;
        refreshSummary();
        return;
    }
    String referenceId = String.valueOf(instance.getInstanceId());
    
    dataArea.scrollToReference(referenceId);
    Document d = dataArea.getDocument();
    HTMLDocument doc = (HTMLDocument) d;
    HTMLDocument.Iterator iter = doc.getIterator(HTML.Tag.A);
    for (; iter.isValid(); iter.next()) {
        AttributeSet a = iter.getAttributes();
        String nm = (String) a.getAttribute(HTML.Attribute.NAME);
        if ((nm != null) && nm.equals(referenceId)) {
            dataArea.select(iter.getStartOffset(),iter.getEndOffset());
            dataArea.requestFocusInWindow();
        }
    }
}