public void mouseClicked(MouseEvent ev) { JTextPane editor = (JTextPane) ev.getSource(); editor.setEditable(false); Point pt = new Point(ev.getX(), ev.getY()); int pos = editor.viewToModel(pt); if (pos >= 0) { Document eDoc = editor.getDocument(); if (eDoc instanceof DefaultStyledDocument) { DefaultStyledDocument hdoc = (DefaultStyledDocument) eDoc; Element e = hdoc.getCharacterElement(pos); AttributeSet a = e.getAttributes(); AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A); String href = null; if (tagA!=null){ href = (String)tagA.getAttribute(HTML.Attribute.HREF); } if (href != null) { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(new URI(href)); } catch (IOException e1) { s_log.error("mouseClicked: Unexpected exception "+e1.getMessage()); } catch (URISyntaxException e1) { s_log.error("mouseClicked: Unexpected exception "+e1.getMessage()); } } } } }
public void mouseClicked(MouseEvent ev) { JTextPane editor = (JTextPane) ev.getSource(); editor.setEditable(false); Point pt = new Point(ev.getX(), ev.getY()); int pos = editor.viewToModel(pt); if (pos >= 0) { Document eDoc = editor.getDocument(); if (eDoc instanceof DefaultStyledDocument) { DefaultStyledDocument hdoc = (DefaultStyledDocument) eDoc; Element e = hdoc.getCharacterElement(pos); AttributeSet a = e.getAttributes(); AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A); String href = null; if (tagA!=null){ href = (String)tagA.getAttribute(HTML.Attribute.HREF); } if (href != null) { Desktop desktop = Desktop.getDesktop(); try { desktop.browse(new URI(href)); } catch (IOException e1) { s_log.error("mouseClicked: Unexpected exception "+e1.getMessage()); } catch (URISyntaxException e1) { s_log.error("mouseClicked: Unexpected exception "+e1.getMessage()); } } } } }
final Element el = doc.getCharacterElement(i); final AttributeSet a = el.getAttributes(); final AttributeSet anchor = (AttributeSet)a.getAttribute(HTML.Tag.A);
field.setSelectionStart(doc.getCharacterElement(field.getCaretPosition()).getParentElement().getStartOffset()); field.setSelectionEnd(doc.getCharacterElement(field.getCaretPosition()).getParentElement().getEndOffset());
if (pos >= 0 && editor.getDocument() instanceof HTMLDocument) { HTMLDocument hdoc = (HTMLDocument) editor.getDocument(); Element elem = hdoc.getCharacterElement(pos); if (elem.getAttributes().getAttribute(HTML.Tag.A) != null) { return elem;
DefaultStyledDocument hdoc = (DefaultStyledDocument) eDoc; Element e = hdoc.getCharacterElement(pos); AttributeSet a = e.getAttributes(); AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A);
DefaultStyledDocument hdoc = (DefaultStyledDocument) eDoc; Element e = hdoc.getCharacterElement(pos); AttributeSet a = e.getAttributes(); AttributeSet tagA = (AttributeSet) a.getAttribute(HTML.Tag.A);
Element leaf = doc.getCharacterElement( branch.getStartOffset() ); AttributeSet as = leaf.getAttributes();
if (pos >= 0 && doc instanceof HTMLDocument) { HTMLDocument hdoc = (HTMLDocument) doc; Element elem = hdoc.getCharacterElement(pos); if (elem.getAttributes().getAttribute(HTML.Tag.A) != null) { return elem;
if (pos >= 0 && editor.getDocument() instanceof HTMLDocument) { HTMLDocument hdoc = (HTMLDocument) editor.getDocument(); Element elem = hdoc.getCharacterElement(pos); if (elem.getAttributes().getAttribute(HTML.Tag.A) != null) { return elem;
Element leaf = m_Self.getCharacterElement(branch.getStartOffset()); AttributeSet as = leaf.getAttributes();
Element leaf = m_Self.getCharacterElement(branch.getStartOffset()); AttributeSet as = leaf.getAttributes();