Example usage for javax.swing.text.html HTMLDocument HTMLDocument

List of usage examples for javax.swing.text.html HTMLDocument HTMLDocument

Introduction

In this page you can find the example usage for javax.swing.text.html HTMLDocument HTMLDocument.

Prototype

public HTMLDocument() 

Source Link

Document

Constructs an HTML document using the default buffer size and a default StyleSheet.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    HTMLDocument doc = new HTMLDocument() {
        public HTMLEditorKit.ParserCallback getReader(int pos) {
            return new HTMLEditorKit.ParserCallback() {
                public void handleText(char[] data, int pos) {
                    System.out.println(data);
                }//ww  w.  j a v a2s  .  c o  m
            };
        }
    };

    URL url = new URI("http://www.google.com").toURL();
    URLConnection conn = url.openConnection();
    Reader rd = new InputStreamReader(conn.getInputStream());

    EditorKit kit = new HTMLEditorKit();
    kit.read(rd, doc, 0);
}

From source file:Main.java

public static void main(String[] args) {
    String HTMLTEXT = "<html><head><style>.foot{color:red} .head{color:black}</style></head>"
            + "<span style='font-family:consolas'>java2s.com</span><br/>"
            + "<span style='font-family:tahoma'>java2s.com</span>";
    JTextPane textPane1 = new JTextPane();

    textPane1.setContentType("text/html");
    textPane1.setFont(new Font("courier new", Font.PLAIN, 32));
    textPane1.setDocument(new HTMLDocument() {
        @Override//  w w  w.  jav a 2 s  .  c  o m
        public Font getFont(AttributeSet attr) {
            StyleContext styles = (StyleContext) getAttributeContext();
            Font f = styles.getFont(attr);
            String ff = f.getFamily();
            System.out.println(ff);
            return textPane1.getFont();
        }
    });
    textPane1.setText(HTMLTEXT);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(textPane1));
    f.setSize(320, 240);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:io.wcm.tooling.netbeans.sightly.completion.BaseTest.java

public StyledDocument createDocument(String content) throws BadLocationException {
    StyledDocument doc = new HTMLDocument();
    doc.insertString(0, content, null);/*from  w  w w.  j  ava2  s .c  o  m*/
    return doc;
}

From source file:de.quadrillenschule.azocamsyncd.gui.ConfigurationWizardJFrame.java

void showDocument(String resource) {
    HTMLDocument h1 = new HTMLDocument();
    h1.setBase(getClass().getResource("/de/quadrillenschule/azocamsyncd/ftpservice/res/"));
    jTextPane1.setDocument(h1);//from ww w . j  a v a  2 s . c o m

    try {
        jTextPane1.setText(FileUtils.readFileToString(new File(getClass().getResource(resource).toURI())));
    } catch (URISyntaxException | IOException ex) {
        Logger.getLogger(ConfigurationWizardJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.fedroot.dacs.swing.DacsNoticePresentationDialog.java

/**
 * Sets the HTML content to be displayed.
 *
 * @param content an HTML document string
 *///from  ww  w  .j  ava2 s .  c o m
private void setDocumentContent(String contenttype, String content) {
    HTMLDocument doc = new HTMLDocument();
    try {
        doc.remove(0, doc.getLength());
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    // doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

    try {
        htmlpane.setContentType(contenttype);
        htmlpane.read(new ByteArrayInputStream(content.getBytes()), doc);
        htmlpane.setDocument(doc);
        htmlpane.setCaretPosition(0);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:fedroot.dacs.swingdemo.DacsClientFrame.java

/**
 * Sets the HTML content to be displayed.
 *
 * @param content an HTML document string
 *//*from  w w w.j a v a 2 s  .  co  m*/
private void setDocumentContent(String contenttype, String content) {
    HTMLDocument doc = new HTMLDocument();
    try {
        doc.remove(0, doc.getLength());
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

    try {
        htmlPane.setContentType(contenttype);
        htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc);
        htmlPane.setDocument(doc);
        htmlPane.setCaretPosition(0);
    } catch (IOException e) {
        e.printStackTrace();
    }

    responseTextArea.setText(content);
    responseTextArea.setCaretPosition(0);
    responseTextArea.requestFocus();
}

From source file:fedroot.dacs.swingdemo.DacsSwingDemo.java

/**
 * Sets the HTML content to be displayed.
 *
 * @param content an HTML document string
 *///ww  w. j  a  v  a 2 s  .c o m
private void setDocumentContent(String contenttype, String content) {
    HTMLDocument doc = new HTMLDocument();
    try {
        doc.remove(0, doc.getLength());
    } catch (BadLocationException ex) {
        logger.log(Level.WARNING, ex.getMessage());
    }
    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

    try {
        htmlPane.setContentType(contenttype);
        htmlPane.read(new ByteArrayInputStream(content.getBytes()), doc);
        htmlPane.setDocument(doc);
        htmlPane.setCaretPosition(0);
    } catch (IOException ex) {
        logger.log(Level.WARNING, ex.getMessage());
    }

    responseTextArea.setText(content);
    responseTextArea.setCaretPosition(0);
    responseTextArea.requestFocus();
}

From source file:es.ubu.XRayDetector.interfaz.PanelAplicacion.java

/**
 * Gets the application log.//from ww w. ja  v a  2 s. c  o  m
 * 
 * @param panelLog The panel of the log.
 * @return The application log.
 */
private JTextPane getTxtLog(JPanel panelLog) {
    JTextPane textPaneLog = new JTextPane();
    textPaneLog.setBounds(4, 4, 209, 195);
    textPaneLog.setEditable(false);
    panelLog.add(textPaneLog);
    textPaneLog.setContentType("text/html");
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    panelLog_1.setLayout(null);
    textPaneLog.setEditorKit(kit);
    textPaneLog.setDocument(doc);

    textPaneLog.setText("<!DOCTYPE html>" + "<html>" + "<head>" + "<style>" + "p.normal {font-weight:normal;}"
            + "p.error {font-weight:bold; color:red}" + "p.exito {font-weight:bold; color:green}"
            + "p.stop {font-weight:bold; color:blue}" + "</style>" + "</head>" + "<body>");
    JScrollPane scroll = new JScrollPane(textPaneLog);
    scroll.setBounds(10, 16, 242, 254);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    panelLog.add(scroll);
    return textPaneLog;
}

From source file:net.minelord.gui.panes.IRCPane.java

synchronized public static void refreshLogs() {
    SwingUtilities.invokeLater(new Runnable() {

        @Override/*  ww w. j a v  a2 s.  c  om*/
        public void run() {
            doc = new HTMLDocument();
            if (doc != null && text != null && !text.getDocument().equals(doc))
                text.setDocument(doc);
            StringBuilder logHTML = new StringBuilder();
            for (String message : IRCLog) {
                logHTML.append(message);
            }
            addHTML(logHTML.toString());
        }
    });
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

public Container CreateContentPane() {
    //Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);//  w  w w .j a v a 2  s. c o m

    // the log panel
    log = new JTextPane();
    log.setEditable(false);
    log.setBackground(Color.BLACK);
    logPane = new JScrollPane(log);
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    log.setEditorKit(kit);
    log.setDocument(doc);
    DefaultCaret c = (DefaultCaret) log.getCaret();
    c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ClearLog();

    settingsPane = SettingsPanel();
    previewPane = new DrawPanel(machineConfiguration);
    preparePane = ProcessImages();
    driveControls = new MakelangeloDriveControls();
    driveControls.createPanel(this, translator, machineConfiguration);
    driveControls.updateButtonAccess(false, false);
    statusBar = new StatusBar(translator);

    contextMenu = new JTabbedPane();
    contextMenu.addTab(translator.get("MenuSettings"), null, settingsPane, null);
    contextMenu.addTab(translator.get("MenuGCODE"), null, preparePane, null);
    contextMenu.addTab(translator.get("MenuDraw"), null, driveControls, null);
    contextMenu.addTab("Log", null, logPane, null);

    // major layout
    split_left_right = new Splitter(JSplitPane.HORIZONTAL_SPLIT);
    split_left_right.add(previewPane);
    split_left_right.add(contextMenu);

    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(split_left_right, BorderLayout.CENTER);

    return contentPane;
}