/** * Triggers the listener to follow an HTML href link that has been clicked. * * @param e event */ public void mouseClicked(MouseEvent e) { AccessibleJLabel acc = (AccessibleJLabel) getAccessibleContext(); int stringIndexAtPoint = acc.getIndexAtPoint(e.getPoint()); if (stringIndexAtPoint < 0) { return; } AttributeSet attr = (AttributeSet) acc.getCharacterAttribute( acc.getIndexAtPoint(e.getPoint())).getAttribute(HTML.Tag.A); if (attr != null) { String href = (String) attr.getAttribute(HTML.Attribute.HREF); String target = (String) attr.getAttribute(HTML.Attribute.TARGET); try { if (listener == null) { log.warn("No HyperlinkActivatedListener available to follow HTML link for label: " + getText()); } else { listener.followHyperlink(new URL(href), target); } } catch (Exception ex) { log.error("Unable to load URL: " + href, ex); } } }
/** * Triggers the listener to follow an HTML href link that has been clicked. * * @param e event */ public void mouseClicked(MouseEvent e) { AccessibleJLabel acc = (AccessibleJLabel) getAccessibleContext(); int stringIndexAtPoint = acc.getIndexAtPoint(e.getPoint()); if (stringIndexAtPoint < 0) { return; } AttributeSet attr = (AttributeSet) acc.getCharacterAttribute( acc.getIndexAtPoint(e.getPoint())).getAttribute(HTML.Tag.A); if (attr != null) { String href = (String) attr.getAttribute(HTML.Attribute.HREF); String target = (String) attr.getAttribute(HTML.Attribute.TARGET); try { if (listener == null) { log.warn("No HyperlinkActivatedListener available to follow HTML link for label: " + getText()); } else { listener.followHyperlink(new URL(href), target); } } catch (Exception ex) { log.error("Unable to load URL: " + href, ex); } } }