Difference between revisions of "Scripting: Freeplane Utility Classes"

From Freeplane - free mind mapping and knowledge management software
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://ecoquvejoz.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
 +
----
 +
=[http://ecoquvejoz.co.cc CLICK HERE]=
 +
----
 +
</div>
 
[[Scripting|Back to Scripting overview]]
 
[[Scripting|Back to Scripting overview]]
  
Line 8: Line 16:
  
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/ui/components/UITools.java UITools.java]
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/ui/components/UITools.java UITools.java]
<groovy>
+
&lt;groovy&gt;
 
public class UITools {
 
public class UITools {
     public static String MAIN_FREEPLANE_FRAME = "mainFreeplaneFrame";
+
     public static String MAIN_FREEPLANE_FRAME = &quot;mainFreeplaneFrame&quot;;
  
 
     public static void addEscapeActionToDialog(JDialog dialog);
 
     public static void addEscapeActionToDialog(JDialog dialog);
Line 45: Line 53:
 
         String text, String title, int type);
 
         String text, String title, int type);
 
}
 
}
</groovy>
+
&lt;/groovy&gt;
  
  
Line 51: Line 59:
  
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/util/HtmlTools.java HtmlTools.java]
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/util/HtmlTools.java HtmlTools.java]
<groovy>
+
&lt;groovy&gt;
 
public class HtmlTools {
 
public class HtmlTools {
 
     public static HtmlTools getInstance();
 
     public static HtmlTools getInstance();
Line 60: Line 68:
 
     public static String removeAllTagsFromString(String text);
 
     public static String removeAllTagsFromString(String text);
 
     /**
 
     /**
     * Removes all tags (<..>) from a string if it starts with "<html>..." to
+
     * Removes all tags (&lt;..&gt;) from a string if it starts with &quot;&lt;html&gt;...&quot; to
 
     * make it compareable.
 
     * make it compareable.
 
     */
 
     */
Line 68: Line 76:
 
     public static String toXMLUnescapedText(String text);
 
     public static String toXMLUnescapedText(String text);
 
     /**
 
     /**
     * warning: only decodes unicode entities like &#xe4;. Use
+
     * warning: only decodes unicode entities like &amp;#xe4;. Use
     * toXMLUnescapedText(unescapeHTMLUnicodeEntity(text)) to decode &amp;
+
     * toXMLUnescapedText(unescapeHTMLUnicodeEntity(text)) to decode &amp;amp;
 
     * etc. too.
 
     * etc. too.
 
     */
 
     */
Line 95: Line 103:
 
     static public int endOfText(String html);
 
     static public int endOfText(String html);
 
}
 
}
</groovy>
+
&lt;/groovy&gt;
  
 
== LogTool ==
 
== LogTool ==
Line 102: Line 110:
  
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/util/LogTool.java LogTool.java]
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/util/LogTool.java LogTool.java]
<groovy>
+
&lt;groovy&gt;
 
public class LogTool {
 
public class LogTool {
 
     public static void createLogger();
 
     public static void createLogger();
Line 114: Line 122:
 
     public static void warn(Throwable e);
 
     public static void warn(Throwable e);
 
}
 
}
</groovy>
+
&lt;/groovy&gt;
  
 
== FreeplaneVersion ==
 
== FreeplaneVersion ==
  
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/controller/FreeplaneVersion.java FreeplaneVersion.java]
 
[http://freeplane.bzr.sf.net/bzr/freeplane/freeplane_program/release_branches/1_0_x/annotate/head%3A/freeplane/src/org/freeplane/core/controller/FreeplaneVersion.java FreeplaneVersion.java]
<groovy>
+
&lt;groovy&gt;
public class FreeplaneVersion implements Comparable<FreeplaneVersion> {
+
public class FreeplaneVersion implements Comparable&lt;FreeplaneVersion&gt; {
     public static String XML_VERSION = "0.9.0";
+
     public static String XML_VERSION = &quot;0.9.0&quot;;
 
     /** returns a initialized version. */
 
     /** returns a initialized version. */
 
     public static FreeplaneVersion getVersion();
 
     public static FreeplaneVersion getVersion();
     /** major version, the 1 in "1.0.38 rc" */
+
     /** major version, the 1 in &quot;1.0.38 rc&quot; */
 
     public int getMaj();
 
     public int getMaj();
     /** mid version, the 0 in "1.0.38 rc" */
+
     /** mid version, the 0 in &quot;1.0.38 rc&quot; */
 
     public int getMid();
 
     public int getMid();
     /** minor version, the 38 in "1.0.38 rc" */
+
     /** minor version, the 38 in &quot;1.0.38 rc&quot; */
 
     public int getMin();
 
     public int getMin();
 
     /** optional patch level (testversion only). */
 
     /** optional patch level (testversion only). */
 
     public int getNum();
 
     public int getNum();
     /** release type e.g. "", "rc", "beta", "alpha" or "nightly_build". */
+
     /** release type e.g. &quot;&quot;, &quot;rc&quot;, &quot;beta&quot;, &quot;alpha&quot; or &quot;nightly_build&quot;. */
 
     public String getType();
 
     public String getType();
 
     /** Use it like this:
 
     /** Use it like this:
     * <pre>
+
     * &lt;pre&gt;
     *  FreeplaneVersion required = FreeplaneVersion.getVersion("1.0.38");
+
     *  FreeplaneVersion required = FreeplaneVersion.getVersion(&quot;1.0.38&quot;);
     *  if (FreeplaneVersion.getVersion().compareTo(required) < 0)
+
     *  if (FreeplaneVersion.getVersion().compareTo(required) &lt; 0)
     *      UITools.errorMessage("Freeplane version not supported"
+
     *      UITools.errorMessage(&quot;Freeplane version not supported&quot;
     *          + " - update to at least " + required);
+
     *          + &quot; - update to at least &quot; + required);
     * </pre>
+
     * &lt;/pre&gt;
 
     */
 
     */
 
     public int compareTo(FreeplaneVersion o);
 
     public int compareTo(FreeplaneVersion o);
     /** returns the full version number, e.g. "1.0.38 rc". */
+
     /** returns the full version number, e.g. &quot;1.0.38 rc&quot;. */
 
     public String toString();
 
     public String toString();
     /** returns the version number only, e.g. "1.0.38". */
+
     /** returns the version number only, e.g. &quot;1.0.38&quot;. */
 
     public String numberToString();
 
     public String numberToString();
 
}
 
}
</groovy>
+
&lt;/groovy&gt;
  
 
[[Category:Scripting]]
 
[[Category:Scripting]]

Revision as of 04:06, 24 November 2010


Back to Scripting overview

There are a few utility classes in Freeplane that are of special use for scripting. (For details look up the code.) For example:

UITools

UITools.java <groovy> public class UITools {

   public static String MAIN_FREEPLANE_FRAME = "mainFreeplaneFrame";
   public static void addEscapeActionToDialog(JDialog dialog);
   public void actionPerformed(ActionEvent e);
   public static void addEscapeActionToDialog(JDialog dialog, Action action);
   public static void addKeyActionToDialog(JDialog dialog, Action action,
       String keyStroke, String actionId);
   public static void convertPointFromAncestor(Component source, Point p,
       Component c);
   public static void convertPointToAncestor(Component source, Point point,
       Class ancestorClass);
   public static void convertPointToAncestor(Component c, Point p,
       Component destination);
   public static void errorMessage(Object message);
   public void run();
   public static Frame getFrame();
   public static KeyStroke getKeyStroke(String keyStrokeDescription);
   public static void informationMessage(Frame frame, String message);
   public static void informationMessage(Frame frame, String message, String title);
   public static void informationMessage(Frame frame, String message, String title,
       int type);
   public static void setBounds(Component frame, int win_x, int win_y,
       int win_width, int win_height);
   public static void setDialogLocationRelativeTo(JDialog dialog, Component c);
   public static void setDialogLocationRelativeTo(JDialog dialog,
       Controller controller, NodeModel node);
   public static void setDialogLocationUnder(JDialog dialog, Controller controller,
       NodeModel node);
   public static int showConfirmDialog(Controller controller, NodeModel node,
       Object message, String title, int optionType);
   public static String showInputDialog(Controller controller, NodeModel node,
       String text, String string);
   public static String showInputDialog(Controller controller, NodeModel node,
       String text, String title, int type);

} </groovy>


HtmlTools

HtmlTools.java <groovy> public class HtmlTools {

   public static HtmlTools getInstance();
   public static String htmlToPlain(String text);
   public static String htmlToPlain(String text, boolean strictHTMLOnly);
   public static boolean isHtmlNode(String text);
   public static String plainToHTML(String text);
   public static String removeAllTagsFromString(String text);
   /**
    * Removes all tags (<..>) from a string if it starts with "<html>..." to
    * make it compareable.
    */
   public static String removeHtmlTagsFromString(String text);
   public static String toXMLEscapedText(String text);
   public static String toXMLEscapedTextExpandingWhitespace(String text);
   public static String toXMLUnescapedText(String text);
   /**
    * warning: only decodes unicode entities like &#xe4;. Use
    * toXMLUnescapedText(unescapeHTMLUnicodeEntity(text)) to decode &amp;
    * etc. too.
    */
   public static String unescapeHTMLUnicodeEntity(String text);
   public static String unicodeToHTMLUnicodeEntity(String text);
   // the remainder could/should be static as well (use getInstance() to get the singleton
   /**
    * @return the maximal index i such that pI is mapped to i by removing all
    *         tags from the original input.
    */
   public int getMaximalOriginalPosition(int pI, ArrayList pListOfIndices);
   public int getMinimalOriginalPosition(int pI, ArrayList pListOfIndices);
   /**
    * Replaces text in node content without replacing tags.
    */
   public String getReplaceResult(Pattern pattern, String replacement, String text);
   /**
    * @return true, if well formed XML.
    */
   public boolean isWellformedXml(String xml);
   public String toHtml(String xhtmlText);
   public String toXhtml(String htmlText);
   static public int endOfText(String html);

} </groovy>

LogTool

Gives access to Freeplane's standard logging facility:

LogTool.java <groovy> public class LogTool {

   public static void createLogger();
   public static void info(String string);
   public static void info(Transferable t);
   public static void severe(String message);
   public static void severe(String comment, Throwable e);
   public static void severe(Throwable e);
   public static void warn(String msg);
   public static void warn(String comment, Throwable e);
   public static void warn(Throwable e);

} </groovy>

FreeplaneVersion

FreeplaneVersion.java <groovy> public class FreeplaneVersion implements Comparable<FreeplaneVersion> {

   public static String XML_VERSION = "0.9.0";
   /** returns a initialized version. */
   public static FreeplaneVersion getVersion();
   /** major version, the 1 in "1.0.38 rc" */
   public int getMaj();
   /** mid version, the 0 in "1.0.38 rc" */
   public int getMid();
   /** minor version, the 38 in "1.0.38 rc" */
   public int getMin();
   /** optional patch level (testversion only). */
   public int getNum();
   /** release type e.g. "", "rc", "beta", "alpha" or "nightly_build". */
   public String getType();
   /** Use it like this:
    * <pre>
    *   FreeplaneVersion required = FreeplaneVersion.getVersion("1.0.38");
    *   if (FreeplaneVersion.getVersion().compareTo(required) < 0)
    *       UITools.errorMessage("Freeplane version not supported"
    *           + " - update to at least " + required);
    * </pre>
    */
   public int compareTo(FreeplaneVersion o);
   /** returns the full version number, e.g. "1.0.38 rc". */
   public String toString();
   /** returns the version number only, e.g. "1.0.38". */
   public String numberToString();

} </groovy>