/** * Changes the mouse cursor to a hand to indicate when the mouse moves over a clickable * HTML link. * * @param e event */ public void mouseMoved(MouseEvent e) { AccessibleJLabel acc = (AccessibleJLabel) getAccessibleContext(); int stringIndexAtPoint = acc.getIndexAtPoint(e.getPoint()); if (stringIndexAtPoint < 0) { return; } javax.swing.text.AttributeSet attr = acc.getCharacterAttribute(stringIndexAtPoint); if (attr.getAttribute(HTML.Tag.A) == null) { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } else { setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } }
/** * Changes the mouse cursor to a hand to indicate when the mouse moves over a clickable * HTML link. * * @param e event */ public void mouseMoved(MouseEvent e) { AccessibleJLabel acc = (AccessibleJLabel) getAccessibleContext(); int stringIndexAtPoint = acc.getIndexAtPoint(e.getPoint()); if (stringIndexAtPoint < 0) { return; } javax.swing.text.AttributeSet attr = acc.getCharacterAttribute(stringIndexAtPoint); if (attr.getAttribute(HTML.Tag.A) == null) { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } else { setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } }
/** * 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); } } }