Search in sources :

Example 11 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project adempiere by adempiere.

the class Worker method run.

/**
	 *  Worker: Read available Online Help Pages
	 */
public void run() {
    if (m_links == null)
        return;
    URL url = null;
    try {
        url = new URL(m_urlString);
    } catch (Exception e) {
        System.err.println("OnlineHelp.Worker.run (url) - " + e);
    }
    if (url == null)
        return;
    //  Read Reference Page
    try {
        URLConnection conn = url.openConnection();
        InputStream is = conn.getInputStream();
        HTMLEditorKit kit = new HTMLEditorKit();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
        kit.read(new InputStreamReader(is), doc, 0);
        //  Get The Links to the Help Pages
        HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
        Object target = null;
        Object href = null;
        while (it != null && it.isValid()) {
            AttributeSet as = it.getAttributes();
            //  key keys
            if (target == null || href == null) {
                Enumeration en = as.getAttributeNames();
                while (en.hasMoreElements()) {
                    Object o = en.nextElement();
                    if (target == null && o.toString().equals("target"))
                        //	javax.swing.text.html.HTML$Attribute
                        target = o;
                    else if (href == null && o.toString().equals("href"))
                        href = o;
                }
            }
            if (target != null && "Online".equals(as.getAttribute(target))) {
                //  Format: /help/<AD_Window_ID>/index.html
                String hrefString = (String) as.getAttribute(href);
                if (hrefString != null) {
                    try {
                        //		System.err.println(hrefString);
                        String AD_Window_ID = hrefString.substring(hrefString.indexOf('/', 1), hrefString.lastIndexOf('/'));
                        m_links.put(AD_Window_ID, hrefString);
                    } catch (Exception e) {
                        System.err.println("OnlineHelp.Worker.run (help) - " + e);
                    }
                }
            }
            it.next();
        }
        is.close();
    } catch (ConnectException e) {
    //	System.err.println("OnlineHelp.Worker.run URL=" + url + " - " + e);
    } catch (UnknownHostException uhe) {
    //	System.err.println("OnlineHelp.Worker.run " + uhe);
    } catch (Exception e) {
        System.err.println("OnlineHelp.Worker.run (e) " + e);
    //	e.printStackTrace();
    } catch (Throwable t) {
        System.err.println("OnlineHelp.Worker.run (t) " + t);
    //	t.printStackTrace();
    }
//	System.out.println("OnlineHelp - Links=" + m_links.size());
}
Also used : Enumeration(java.util.Enumeration) InputStreamReader(java.io.InputStreamReader) UnknownHostException(java.net.UnknownHostException) InputStream(java.io.InputStream) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) URL(java.net.URL) UnknownHostException(java.net.UnknownHostException) ConnectException(java.net.ConnectException) URLConnection(java.net.URLConnection) AttributeSet(javax.swing.text.AttributeSet) ConnectException(java.net.ConnectException)

Example 12 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project adempiere by adempiere.

the class HTMLRenderer method get.

/**
	 * 	Get View from HTML String
	 *	@param html html string
	 *	@return renderer view
	 */
public static HTMLRenderer get(String html) {
    HTMLEditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
    try {
        doc.remove(0, doc.getLength());
        Reader r = new StringReader(html);
        kit.read(r, doc, 0);
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
    }
    //	Create Renderer
    Element element = doc.getDefaultRootElement();
    ViewFactory factory = kit.getViewFactory();
    //	Y_AXIS is main
    View view = factory.create(element);
    HTMLRenderer renderer = new HTMLRenderer(factory, view);
    renderer.preferenceChanged(null, true, true);
    return renderer;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.Element) ViewFactory(javax.swing.text.ViewFactory) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) View(javax.swing.text.View) BadLocationException(javax.swing.text.BadLocationException)

Example 13 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project adempiere by adempiere.

the class HelpInfo method createAndShowGui.

// METHODS
// =======
/**
	 * Create the GUI and show it
	 * @param component the calling component
	 */
public void createAndShowGui(Component component) {
    // title
    setTitle(s_logger.localizeMessage("guiHelpTitle"));
    // load icons
    ArrayList<Image> images = new ArrayList<Image>();
    images.add(getImage("AD16.png"));
    images.add(getImage("AD32.png"));
    setIconImages(images);
    // content pane
    Container pane = getContentPane();
    Locale locale = Locale.getDefault();
    pane.setComponentOrientation(ComponentOrientation.getOrientation(locale));
    pane.setLayout(new GridBagLayout());
    // help text
    JEditorPane info = new JEditorPane();
    info.setEditable(false);
    info.setContentType("text/html");
    HTMLDocument htmlDoc = (HTMLDocument) info.getEditorKit().createDefaultDocument();
    info.setDocument(htmlDoc);
    info.setText(getHelpText());
    info.setCaretPosition(0);
    // scrollable pane for help text
    JScrollPane infoPane = new JScrollPane();
    infoPane.setBorder(BorderFactory.createLoweredBevelBorder());
    infoPane.setPreferredSize(new Dimension(500, 400));
    infoPane.getViewport().add(info, null);
    pane.add(infoPane, getInfoPaneConstraints());
    // close button
    m_buttonClose = new JButton(s_logger.localizeMessage("guiButtonClose"));
    m_buttonClose.setMnemonic(new Integer(s_logger.localizeMessage("guiButtonCloseMnemonic")));
    m_buttonClose.setIcon(new ImageIcon(getImage("Cancel16.png")));
    m_buttonClose.addActionListener(this);
    pane.add(m_buttonClose, getCloseConstraints());
    // show dialog
    pack();
    validate();
    m_buttonClose.requestFocusInWindow();
    setLocationRelativeTo(component);
    setVisible(true);
}
Also used : Locale(java.util.Locale) JScrollPane(javax.swing.JScrollPane) ImageIcon(javax.swing.ImageIcon) GridBagLayout(java.awt.GridBagLayout) HTMLDocument(javax.swing.text.html.HTMLDocument) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) Image(java.awt.Image) Container(java.awt.Container) JEditorPane(javax.swing.JEditorPane)

Example 14 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project intellij-community by JetBrains.

the class DocumentationComponent method getLinkCount.

private int getLinkCount() {
    HTMLDocument document = (HTMLDocument) myEditorPane.getDocument();
    int linkCount = 0;
    for (HTMLDocument.Iterator it = document.getIterator(HTML.Tag.A); it.isValid(); it.next()) {
        if (it.getAttributes().isDefined(HTML.Attribute.HREF))
            linkCount++;
    }
    return linkCount;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument)

Example 15 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project intellij-community by JetBrains.

the class DocumentationComponent method getLink.

@Nullable
private HTMLDocument.Iterator getLink(int n) {
    if (n >= 0) {
        HTMLDocument document = (HTMLDocument) myEditorPane.getDocument();
        int linkCount = 0;
        for (HTMLDocument.Iterator it = document.getIterator(HTML.Tag.A); it.isValid(); it.next()) {
            if (it.getAttributes().isDefined(HTML.Attribute.HREF) && linkCount++ == n)
                return it;
        }
    }
    return null;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

HTMLDocument (javax.swing.text.html.HTMLDocument)30 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)10 Element (javax.swing.text.Element)6 StyleSheet (javax.swing.text.html.StyleSheet)6 URL (java.net.URL)5 AttributeSet (javax.swing.text.AttributeSet)5 BadLocationException (javax.swing.text.BadLocationException)5 IOException (java.io.IOException)4 Document (javax.swing.text.Document)4 Style (javax.swing.text.Style)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 StringReader (java.io.StringReader)2 URLConnection (java.net.URLConnection)2 ArrayList (java.util.ArrayList)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2 HTMLFrameHyperlinkEvent (javax.swing.text.html.HTMLFrameHyperlinkEvent)2 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1