当前位置: 首页>>代码示例>>Java>>正文


Java HTMLEditorKit.createDefaultDocument方法代码示例

本文整理汇总了Java中javax.swing.text.html.HTMLEditorKit.createDefaultDocument方法的典型用法代码示例。如果您正苦于以下问题:Java HTMLEditorKit.createDefaultDocument方法的具体用法?Java HTMLEditorKit.createDefaultDocument怎么用?Java HTMLEditorKit.createDefaultDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.html.HTMLEditorKit的用法示例。


在下文中一共展示了HTMLEditorKit.createDefaultDocument方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
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");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:bug8005391.java

示例2: main

import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:bug8028616.java

示例3: main

import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
public static void main(String[] args) {
    String htmlDoc = "<pre><p> </pre>";
    try {
        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();
    } catch (Exception ex) {
        throw new RuntimeException("Test Failed " + ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:HTMLEditorKitWriterBug.java

示例4: initHistoryWidget

import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
protected void initHistoryWidget() {
    HTMLEditorKit kit = new HTMLEditorKit() {
        @Override
        public ViewFactory getViewFactory() {
            return new WrapHTMLFactory();
        }
    };
    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("body {text-align: left;}");
    styleSheet.addRule("div.my {font-size: 1.2rem; font-style: italic;}");
    styleSheet.addRule("div.error {color: red;}");
    styleSheet.addRule("img {max-width: 100%;}");
    try {
        styleSheet.importStyleSheet(
                new URL("http://dl.ieclipse.cn/r/smartim.css"));
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    }
    HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
    String initText = String.format(
            "<html><head></head><body>%s</body></html>", "欢迎使用SmartIM");
    historyWidget.setEditorKit(kit);
    historyWidget.setDocument(doc);
    // historyWidget.setText(initText);
    historyWidget.setEditable(false);
    historyWidget.setBackground(null);
    historyWidget.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                String desc = e.getDescription();
                if (!StringUtils.isEmpty(desc)) {
                    hyperlinkActivated(desc);
                }
            }
        }
    });
}
 
开发者ID:Jamling,项目名称:SmartQQ4IntelliJ,代码行数:40,代码来源:IMChatConsole.java

示例5: generateHTML

import javax.swing.text.html.HTMLEditorKit; //导入方法依赖的package包/类
public void generateHTML() throws BadLocationException, IOException {
    StringReader stringReader = new StringReader(HTML_TEMPLATE);
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument html = (HTMLDocument)htmlKit.createDefaultDocument();
    htmlKit.read(stringReader, html, 0);
    Element licenseList = html.getElement("licenses");
    Element intro = html.getElement("my-account");
    String introText = I18N.getGUILabel("manage_licenses.intro", new Object[0]);
    html.setInnerHTML(intro, introText);
    DateFormat format = DateFormat.getDateTimeInstance(2, 3);
    Iterator css = this.licenses.iterator();

    while(css.hasNext()) {
        License backgroundURL = (License)css.next();
        String productName = LicenseTools.translateProductName(backgroundURL);
        String productEdition = LicenseTools.translateProductEdition(backgroundURL);
        String expiration = I18N.getGUILabel("manage_licenses.perpetual_license", new Object[0]);
        if(backgroundURL.getExpirationDate() != null) {
            expiration = I18N.getGUILabel("manage_licenses.valid_until", new Object[]{format.format(backgroundURL.getExpirationDate())});
        }

        String annotations = null;
        if(backgroundURL.getAnnotations() != null && !backgroundURL.getAnnotations().trim().isEmpty()) {
            annotations = I18N.getGUILabel("manage_licenses.annotations", new Object[]{backgroundURL.getAnnotations()});
        }

        String licenseUser = null;
        if(backgroundURL.getLicenseUser().getName() != null && !backgroundURL.getLicenseUser().getName().trim().isEmpty()) {
            licenseUser = I18N.getGUILabel("manage_licenses.registered_to", new Object[]{backgroundURL.getLicenseUser().getName()});
        }

        StringBuffer entry = new StringBuffer();
        entry.append("<tr><td>" + Ionicon.ARROW_RIGHT_B.getHtml() + "</td><td>");
        entry.append(String.format("<strong>%s %s</strong>", new Object[]{productName, productEdition}));
        if(licenseUser != null) {
            entry.append(String.format("<br />%s", new Object[]{licenseUser}));
        }

        if(annotations != null) {
            entry.append(String.format("<br />%s", new Object[]{annotations}));
        }

        entry.append(String.format("<br />%s", new Object[]{expiration}));
        entry.append("</td></tr>");
        html.insertBeforeEnd(licenseList, entry.toString());
    }

    StyleSheet css1 = html.getStyleSheet();
    String backgroundURL1 = Tools.getResource("license/dialog/license_dialog_background.png").toString();
    css1.addRule("body {background-image: url(\'" + backgroundURL1 + "\');}");
    this.setDocument(html);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:53,代码来源:LicenseContentPanel.java


注:本文中的javax.swing.text.html.HTMLEditorKit.createDefaultDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。