public void actionPerformed(ActionEvent e) {
JTextComponent c = getTextComponent(e);
if (c.isEditable() || !(c instanceof JEditorPane)) {
return;
}
JEditorPane editor = (JEditorPane)c;
Document d = editor.getDocument();
if (d == null || !(d instanceof HTMLDocument)) {
return;
}
HTMLDocument doc = (HTMLDocument)d;
ElementIterator ei = new ElementIterator(doc);
int currentOffset = editor.getCaretPosition();
// invoke the next link or object action
String urlString = null;
String objString = null;
Element currentElement = null;
while ((currentElement = ei.next()) != null) {
String name = currentElement.getName();
AttributeSet attr = currentElement.getAttributes();
Object href = getAttrValue(attr, HTML.Attribute.HREF);
if (href != null) {
if (currentOffset >= currentElement.getStartOffset() &&
currentOffset < = currentElement.getEndOffset()) {
activateLink((String)href, doc, editor, currentOffset);
return;
}
} else if (name.equals(HTML.Tag.OBJECT.toString())) {
Object obj = getAttrValue(attr, HTML.Attribute.CLASSID);
if (obj != null) {
if (currentOffset >= currentElement.getStartOffset() &&
currentOffset < = currentElement.getEndOffset()) {
doObjectAction(editor, currentElement);
return;
}
}
}
}
}
|