super("SetLinkByTextFieldAction");
this.panel = panel;
}
public void actionPerformed(final ActionEvent ae) {
SHTMLEditorPane editorPane = panel.getSHTMLEditorPane();
final Element linkElement = editorPane.getCurrentLinkElement();
final boolean foundLink = (linkElement != null);
final String linkAsString;
if (foundLink) {
final AttributeSet elemAttrs = linkElement.getAttributes();
final Object linkAttr = elemAttrs.getAttribute(HTML.Tag.A);
final Object href = ((AttributeSet) linkAttr).getAttribute(HTML.Attribute.HREF);
if (href != null) {
linkAsString = href.toString();
}
else
linkAsString = "http://";
}
else {
linkAsString = "http://";
}
final String inputValue = UITools.showInputDialog(
Controller.getCurrentController().getSelection().getSelected(), TextUtils.getText("edit_link_manually"), linkAsString);
if (inputValue != null && ! inputValue.matches("\\w+://")) {
SHTMLEditorPane editor = panel.getSHTMLEditorPane();
if (inputValue.equals("")) {
editor.setLink(null, null, null);
return;
}
try {
final URI link = LinkController.createURI(inputValue.trim());
editor.setLink(null, link.toString(), null);
}
catch (final URISyntaxException e1) {
LogUtils.warn(e1);
UITools.errorMessage(TextUtils.format("invalid_uri", inputValue));
return;