int i = 0; public void process(TreeElement element) { i++; String linkID = >the link ID generated from the element> logger.appendLink("the element " + i, linkID); }
{[0-9 _A-Za-z]+}
pattern for each link. The content inside the accolades will be used for the text of the link.int i = 0; public void process(TreeElement element) { i++; String linkID = >the link ID generated from the element> String text = "This is the {element " + i + "} link"; logger.appendLinks(text, linkID); }
HyperlinkElement
contains both the link associated text and the element associated with the link. The element will be converted to a link ID with the associated LinkIndexConverter.public void process(TreeElement element) { HyperlinkElement linkElt = new HyperlinkElement("the text shown for the link", element); logger.appendObjectLink(linkElt); }
%\d+
pattern for each link, and will refer to the i-th HyperlinkElement
in the arguments.public void process(TreeElement element) { HyperlinkElement linkElt = new HyperlinkElement(element.name, element); logger.appendObjectLinks("The element is %1", linkElt); }
public void process(TreeElement element) { HyperlinkElement linkElt = new HyperlinkElement("the text shown for the link", element); logger.appendObjectLink(linkElt); }
GroovyScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; ScriptLoggerHyperLinkListener linkListener = new MyLoggerHyperLinkListener(); ScriptLogger logger = new DefaultSwingScriptLogger(); logger.registerHyperLinkListener(linkListener); wrapper.setScriptLogger(logger);The method called for a visited link notification depends on if a LinkIndexConverter has been registered or not:
public class MyLoggerHyperLinkListener implements ScriptLoggerHyperLinkListener { @Override public void visitHyperLink(String linkID) { // get the associated elemet from the linkID and do something with it } }
public class MyLoggerHyperLinkListener implements ScriptLoggerHyperLinkListener<TreeElement> { @Override public void visitHyperLink(TreeElement element) { // do something with the tree element } }Note that you are not required to specify the type of the Object used for the
ScriptLoggerHyperLinkListener
, If you don't do it, you will have this method to implement:public class MyLoggerHyperLinkListener implements ScriptLoggerHyperLinkListener { @Override public void visitHyperLink(Object o) { // do something with the Object } }
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence