Difference between revisions of "Scripting API"
Irajawapys (talk | contribs) |
m (Reverted edits by Irajawapys (Talk) to last version by Boercher) |
||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
This page describes the current Freeplane's Scripting API. For the newest development version see [[Scripting API (Pre-Release)]]. The Scripting API is in some sense extended by [[Scripting: Freeplane Utility Classes|Freeplane's utility classes]] and by the [[Scripting: Included libraries|Libraries included in Freeplane]]. There is a special page that lists [[Scripting:_API_Changes|Changes of the Scripting API]]. | This page describes the current Freeplane's Scripting API. For the newest development version see [[Scripting API (Pre-Release)]]. The Scripting API is in some sense extended by [[Scripting: Freeplane Utility Classes|Freeplane's utility classes]] and by the [[Scripting: Included libraries|Libraries included in Freeplane]]. There is a special page that lists [[Scripting:_API_Changes|Changes of the Scripting API]]. | ||
Line 12: | Line 4: | ||
Each script is given two variables: | Each script is given two variables: | ||
− | + | <groovy> | |
final Proxy.Node node; | final Proxy.Node node; | ||
final Proxy.Controller c; | final Proxy.Controller c; | ||
− | + | </groovy> | |
==Interface== | ==Interface== | ||
− | + | <groovy> | |
package org.freeplane.plugin.script.proxy; | package org.freeplane.plugin.script.proxy; | ||
Line 39: | Line 31: | ||
* with the same name. */ | * with the same name. */ | ||
interface Attributes { | interface Attributes { | ||
− | /** returns the | + | /** returns the <em>first</em> value of an attribute with the given name or null otherwise. |
* @deprecated use {@link #get(int)} or {@link #getAll(String)} instead. */ | * @deprecated use {@link #get(int)} or {@link #getAll(String)} instead. */ | ||
@Deprecated | @Deprecated | ||
Line 45: | Line 37: | ||
/** returns all values for the attribute name. */ | /** returns all values for the attribute name. */ | ||
− | List | + | List<String> getAll(final String name); |
/** returns all attribute names in the proper sequence. | /** returns all attribute names in the proper sequence. | ||
− | * | + | * <pre> |
* // rename attribute | * // rename attribute | ||
* int i = 0; | * int i = 0; | ||
* for (String name : attributes.getAttributeNames()) { | * for (String name : attributes.getAttributeNames()) { | ||
− | * if (name.equals( | + | * if (name.equals("xy")) |
− | * attributes.set(i, | + | * attributes.set(i, "xyz", attributes.get(i)); |
* ++i; | * ++i; | ||
* } | * } | ||
− | * | + | * </pre> */ |
− | public List | + | public List<String> getAttributeNames(); |
/** returns the attribute value at the given index. | /** returns the attribute value at the given index. | ||
− | * @throws IndexOutOfBoundsException if index is out of range | + | * @throws IndexOutOfBoundsException if index is out of range <tt>(index |
− | * & | + | * < 0 || index >= size())</tt>.*/ |
String get(final int index); | String get(final int index); | ||
/** sets the value of the attribute at an index. This method will not create new attributes. | /** sets the value of the attribute at an index. This method will not create new attributes. | ||
− | * @throws IndexOutOfBoundsException if index is out of range | + | * @throws IndexOutOfBoundsException if index is out of range <tt>(index |
− | * & | + | * < 0 || index >= size())</tt>. */ |
void set(final int index, final String value); | void set(final int index, final String value); | ||
/** sets name and value of the attribute at the given index. This method will not create new attributes. | /** sets name and value of the attribute at the given index. This method will not create new attributes. | ||
− | * @throws IndexOutOfBoundsException if index is out of range | + | * @throws IndexOutOfBoundsException if index is out of range <tt>(index |
− | * & | + | * < 0 || index >= size())</tt>. */ |
void set(final int index, final String name, final String value); | void set(final int index, final String name, final String value); | ||
/** returns the index of the first attribute with the given name if one exists or -1 otherwise. | /** returns the index of the first attribute with the given name if one exists or -1 otherwise. | ||
− | * For searches for | + | * For searches for <em>all</em> attributes with a given name <code>getAttributeNames()</code> |
* must be used. */ | * must be used. */ | ||
public int findAttribute(final String name); | public int findAttribute(final String name); | ||
− | /** removes the | + | /** removes the <em>first</em> attribute with this name. |
* @returns true on removal of an existing attribute and false otherwise. | * @returns true on removal of an existing attribute and false otherwise. | ||
* @deprecated use {@link #remove(int)} or {@link #removeAll(String)} instead. */ | * @deprecated use {@link #remove(int)} or {@link #removeAll(String)} instead. */ | ||
Line 85: | Line 77: | ||
boolean remove(final String name); | boolean remove(final String name); | ||
− | /** removes | + | /** removes <em>all</em> attributes with this name. |
* @returns true on removal of an existing attribute and false otherwise. */ | * @returns true on removal of an existing attribute and false otherwise. */ | ||
boolean removeAll(final String name); | boolean removeAll(final String name); | ||
/** removes the attribute at the given index. | /** removes the attribute at the given index. | ||
− | * @throws IndexOutOfBoundsException if index is out of range | + | * @throws IndexOutOfBoundsException if index is out of range <tt>(index |
− | * & | + | * < 0 || index >= size())</tt>. */ |
void remove(final int index); | void remove(final int index); | ||
/** adds an attribute if there is no attribute with the given name or changes | /** adds an attribute if there is no attribute with the given name or changes | ||
− | * the value | + | * the value <em>of the first</em> attribute with the given name. */ |
void set(final String name, final String value); | void set(final String name, final String value); | ||
Line 101: | Line 93: | ||
void add(final String name, final String value); | void add(final String name, final String value); | ||
− | /** the number of attributes. It is | + | /** the number of attributes. It is <code>size() == getAttributeNames().size()</code>. */ |
int size(); | int size(); | ||
} | } | ||
Line 146: | Line 138: | ||
Node getSelected(); | Node getSelected(); | ||
− | List | + | List<Node> getSelecteds(); |
− | /** returns List | + | /** returns List<Node> of Node objects sorted on Y |
* | * | ||
* @param differentSubtrees if true | * @param differentSubtrees if true | ||
* children/grandchildren/grandgrandchildren/... nodes of selected | * children/grandchildren/grandgrandchildren/... nodes of selected | ||
* parent nodes are excluded from the result. */ | * parent nodes are excluded from the result. */ | ||
− | List | + | List<Node> getSortedSelection(boolean differentSubtrees); |
void select(Node toSelect); | void select(Node toSelect); | ||
Line 160: | Line 152: | ||
void selectBranch(Node branchRoot); | void selectBranch(Node branchRoot); | ||
− | /** toSelect is a List | + | /** toSelect is a List<Node> of Node objects */ |
− | void selectMultipleNodes(List | + | void selectMultipleNodes(List<Node> toSelect); |
/** reset undo / redo lists and deactivate Undo for current script */ | /** reset undo / redo lists and deactivate Undo for current script */ | ||
Line 176: | Line 168: | ||
/** Starting from the root node, recursively searches for nodes for which | /** Starting from the root node, recursively searches for nodes for which | ||
− | * | + | * <code>condition.checkNode(node)</code> returns true. |
* @see Node.find(ICondition) for searches on subtrees */ | * @see Node.find(ICondition) for searches on subtrees */ | ||
− | public List | + | public List<Node> find(ICondition condition); |
/** | /** | ||
− | * Starting from the root node, recursively searches for nodes for which | + | * Starting from the root node, recursively searches for nodes for which <code>closure.call(node)</code> |
* returns true. | * returns true. | ||
− | * | + | * <p> |
− | * A find method that uses a Groovy closure ( | + | * A find method that uses a Groovy closure ("block") for simple custom searches. As this closure |
− | * will be called with a node as an argument (to be referenced by | + | * will be called with a node as an argument (to be referenced by <code>it</code>) the search can |
* evaluate every node property, like attributes, icons, node text or notes. | * evaluate every node property, like attributes, icons, node text or notes. | ||
− | * | + | * <p> |
* Examples: | * Examples: | ||
− | * | + | * <pre> |
* def nodesWithNotes = c.find{ it.noteText != null } | * def nodesWithNotes = c.find{ it.noteText != null } | ||
* | * | ||
− | * def matchingNodes = c.find{ it.text.matches( | + | * def matchingNodes = c.find{ it.text.matches(".*\\d.*") } |
* def texts = matchingNodes.collect{ it.text } | * def texts = matchingNodes.collect{ it.text } | ||
− | * print | + | * print "node texts containing numbers:\n " + texts.join("\n ") |
− | * | + | * </pre> |
* @param closure a Groovy closure that returns a boolean value. The closure will receive | * @param closure a Groovy closure that returns a boolean value. The closure will receive | ||
* a NodeModel as an argument which can be tested for a match. | * a NodeModel as an argument which can be tested for a match. | ||
− | * @return all nodes for which | + | * @return all nodes for which <code>closure.call(NodeModel)</code> returns true. |
* @see Node.find(Closure) for searches on subtrees | * @see Node.find(Closure) for searches on subtrees | ||
*/ | */ | ||
− | public List | + | public List<Node> find(Closure closure); |
} | } | ||
Line 215: | Line 207: | ||
void setType(EdgeStyle type); | void setType(EdgeStyle type); | ||
− | /** can be -1 for default, 0 for thin, | + | /** can be -1 for default, 0 for thin, >0 */ |
void setWidth(int width); | void setWidth(int width); | ||
} | } | ||
Line 268: | Line 260: | ||
void addIcon(String name); | void addIcon(String name); | ||
− | /** returns List | + | /** returns List<Node> of Strings (corresponding to iconID above); |
− | * iconID is one of | + | * iconID is one of "Idea","Question","Important", etc. */ |
− | List | + | List<String> getIcons(); |
/** deletes first occurence of icon with name iconID, returns true if | /** deletes first occurence of icon with name iconID, returns true if | ||
Line 282: | Line 274: | ||
/** target is a URI. | /** target is a URI. | ||
* An empty String will remove the link. | * An empty String will remove the link. | ||
− | * To get a local link (i.e. to another node) target should be: | + | * To get a local link (i.e. to another node) target should be: "#" + nodeID */ |
boolean set(String target); | boolean set(String target); | ||
} | } | ||
Line 299: | Line 291: | ||
Connector addConnectorTo(Node target); | Connector addConnectorTo(Node target); | ||
− | /** adds a new Connector object to List | + | /** adds a new Connector object to List<Node> connectors and returns |
* reference for optional further editing (style); also enlists the | * reference for optional further editing (style); also enlists the | ||
* Connector on the target Node object. */ | * Connector on the target Node object. */ | ||
Line 322: | Line 314: | ||
/** returns the children of this node ordered by Y coordinate. */ | /** returns the children of this node ordered by Y coordinate. */ | ||
− | List | + | List<Node> getChildren(); |
− | Collection | + | Collection<Connector> getConnectorsIn(); |
− | Collection | + | Collection<Connector> getConnectorsOut(); |
ExternalObject getExternalObject(); | ExternalObject getExternalObject(); | ||
Line 366: | Line 358: | ||
boolean isVisible(); | boolean isVisible(); | ||
− | /** removes connector from List | + | /** removes connector from List<Node> connectors; does the corresponding |
* on the target Node object referenced by connectorToBeRemoved */ | * on the target Node object referenced by connectorToBeRemoved */ | ||
void moveTo(Node parentNode); | void moveTo(Node parentNode); | ||
Line 382: | Line 374: | ||
/** Starting from this node, recursively searches for nodes for which | /** Starting from this node, recursively searches for nodes for which | ||
− | * | + | * <code>condition.checkNode(node)</code> returns true. */ |
− | List | + | List<Node> find(ICondition condition); |
− | /** Starting from this node, recursively searches for nodes for which | + | /** Starting from this node, recursively searches for nodes for which <code>closure.call(node)</code> |
* returns true. See {@link Controller#find(Closure)} for details. */ | * returns true. See {@link Controller#find(Closure)} for details. */ | ||
− | List | + | List<Node> find(Closure closure); |
Date getLastModifiedAt(); | Date getLastModifiedAt(); | ||
Line 414: | Line 406: | ||
} | } | ||
} | } | ||
− | + | </groovy> | |
[[Category:Scripting]] | [[Category:Scripting]] |
Revision as of 18:33, 24 November 2010
This page describes the current Freeplane's Scripting API. For the newest development version see Scripting API (Pre-Release). The Scripting API is in some sense extended by Freeplane's utility classes and by the Libraries included in Freeplane. There is a special page that lists Changes of the Scripting API.
Entry Points
Each script is given two variables:
<groovy> final Proxy.Node node; final Proxy.Controller c; </groovy>
Interface
<groovy> package org.freeplane.plugin.script.proxy;
import groovy.lang.Closure;
import java.awt.Color; import java.io.File; import java.util.Collection; import java.util.Date; import java.util.List;
import javax.swing.Icon;
import org.freeplane.core.filter.condition.ICondition; import org.freeplane.features.common.edge.EdgeStyle; import org.freeplane.features.common.link.ArrowType;
public interface Proxy {
/** Attributes are name - value pairs assigned to a node. A node may have multiple attributes * with the same name. */ interface Attributes { /** returns the first value of an attribute with the given name or null otherwise. * @deprecated use {@link #get(int)} or {@link #getAll(String)} instead. */ @Deprecated String get(final String name);
/** returns all values for the attribute name. */ List<String> getAll(final String name);
/** returns all attribute names in the proper sequence.
*
* // rename attribute * int i = 0; * for (String name : attributes.getAttributeNames()) { * if (name.equals("xy")) * attributes.set(i, "xyz", attributes.get(i)); * ++i; * } *
*/
public List<String> getAttributeNames();
/** returns the attribute value at the given index. * @throws IndexOutOfBoundsException if index is out of range (index * < 0 || index >= size()).*/ String get(final int index);
/** sets the value of the attribute at an index. This method will not create new attributes. * @throws IndexOutOfBoundsException if index is out of range (index * < 0 || index >= size()). */ void set(final int index, final String value);
/** sets name and value of the attribute at the given index. This method will not create new attributes. * @throws IndexOutOfBoundsException if index is out of range (index * < 0 || index >= size()). */ void set(final int index, final String name, final String value);
/** returns the index of the first attribute with the given name if one exists or -1 otherwise.
* For searches for all attributes with a given name getAttributeNames()
* must be used. */
public int findAttribute(final String name);
/** removes the first attribute with this name. * @returns true on removal of an existing attribute and false otherwise. * @deprecated use {@link #remove(int)} or {@link #removeAll(String)} instead. */ @Deprecated boolean remove(final String name);
/** removes all attributes with this name. * @returns true on removal of an existing attribute and false otherwise. */ boolean removeAll(final String name);
/** removes the attribute at the given index. * @throws IndexOutOfBoundsException if index is out of range (index * < 0 || index >= size()). */ void remove(final int index);
/** adds an attribute if there is no attribute with the given name or changes * the value of the first attribute with the given name. */ void set(final String name, final String value);
/** adds an attribute no matter if an attribute with the given name already exists. */ void add(final String name, final String value);
/** the number of attributes. It is size() == getAttributeNames().size()
. */
int size();
}
interface Connector { Color getColor();
ArrowType getEndArrow();
String getMiddleLabel();
Node getSource();
String getSourceLabel();
ArrowType getStartArrow();
Node getTarget();
String getTargetLabel();
void setColor(Color color);
void setEndArrow(ArrowType arrowType);
void setMiddleLabel(String label);
void setSimulatesEdge(boolean simulatesEdge);
void setSourceLabel(String label);
void setStartArrow(ArrowType arrowType);
void setTargetLabel(String label);
boolean simulatesEdge(); }
interface Controller { void centerOnNode(Node center);
/** if multiple nodes are selected returns one (arbitrarily chosen) * selected node or the selected node for a single node selection. */ Node getSelected();
List<Node> getSelecteds();
/** returns List<Node> of Node objects sorted on Y * * @param differentSubtrees if true * children/grandchildren/grandgrandchildren/... nodes of selected * parent nodes are excluded from the result. */ List<Node> getSortedSelection(boolean differentSubtrees);
void select(Node toSelect);
/** selects branchRoot and all children */ void selectBranch(Node branchRoot);
/** toSelect is a List<Node> of Node objects */ void selectMultipleNodes(List<Node> toSelect);
/** reset undo / redo lists and deactivate Undo for current script */ void deactivateUndo();
/** The main info for the status line, null to remove*/ public void setStatusInfo(String info);
/** Info for status line, null to remove*/ public void setStatusInfo(String key, String info);
/** Info for status line, null to remove*/ public void setStatusInfo(String key, Icon icon);
/** Starting from the root node, recursively searches for nodes for which
* condition.checkNode(node)
returns true.
* @see Node.find(ICondition) for searches on subtrees */
public List<Node> find(ICondition condition);
/**
* Starting from the root node, recursively searches for nodes for which closure.call(node)
* returns true.
*
* A find method that uses a Groovy closure ("block") for simple custom searches. As this closure
* will be called with a node as an argument (to be referenced by it
) the search can
* evaluate every node property, like attributes, icons, node text or notes.
*
* Examples: *
* def nodesWithNotes = c.find{ it.noteText != null } * * def matchingNodes = c.find{ it.text.matches(".*\\d.*") } * def texts = matchingNodes.collect{ it.text } * print "node texts containing numbers:\n " + texts.join("\n ") *
* @param closure a Groovy closure that returns a boolean value. The closure will receive
* a NodeModel as an argument which can be tested for a match.
* @return all nodes for which closure.call(NodeModel)
returns true.
* @see Node.find(Closure) for searches on subtrees
*/
public List<Node> find(Closure closure);
}
interface Edge { Color getColor();
EdgeStyle getType();
int getWidth();
void setColor(Color color);
void setType(EdgeStyle type);
/** can be -1 for default, 0 for thin, >0 */ void setWidth(int width); }
interface ExternalObject { /** empty string means that there's no external object */ String getURI();
float getZoom();
/** setting empty String uri means remove external object (as for Links); */ void setURI(String uri);
void setZoom(float zoom); }
interface Font { String getName();
int getSize();
boolean isBold();
boolean isBoldSet();
boolean isItalic();
boolean isItalicSet();
boolean isNameSet();
boolean isSizeSet();
void resetBold();
void resetItalic();
void resetName();
void resetSize();
void setBold(boolean bold);
void setItalic(boolean italic);
void setName(String name);
void setSize(int size); }
interface Icons { void addIcon(String name);
/** returns List<Node> of Strings (corresponding to iconID above); * iconID is one of "Idea","Question","Important", etc. */ List<String> getIcons();
/** deletes first occurence of icon with name iconID, returns true if * success (icon existed); */ boolean removeIcon(String iconID); }
interface Link { String get();
/** target is a URI. * An empty String will remove the link. * To get a local link (i.e. to another node) target should be: "#" + nodeID */ boolean set(String target); }
interface Map { Node getRootNode();
/** returns the node if the map contains it or null otherwise. */ Node node(String id);
/** returns the physical location of the map if available or null otherwise. */ File getFile(); }
interface Node { Connector addConnectorTo(Node target);
/** adds a new Connector object to List<Node> connectors and returns * reference for optional further editing (style); also enlists the * Connector on the target Node object. */ Connector addConnectorTo(String targetNodeID);
/** inserts *new* node as child, takes care of all construction work and * internal stuff inserts as last child. */ Node createChild();
/** inserts *new* node as child, takes care of all construction work and * internal stuff */ Node createChild(int position);
void delete();
Attributes getAttributes();
/** returns the index (0..) of this node in the (by Y coordinate sorted) * list of this node's children. Returns -1 if childNode is not a child * of this node. */ int getChildPosition(Node childNode);
/** returns the children of this node ordered by Y coordinate. */ List<Node> getChildren();
Collection<Connector> getConnectorsIn();
Collection<Connector> getConnectorsOut();
ExternalObject getExternalObject();
Icons getIcons();
Link getLink();
/** the map this node belongs to. */ Map getMap();
String getNodeID();
/** if countHidden is false then only nodes that are matched by the * current filter are counted. */ int getNodeLevel(boolean countHidden);
String getNoteText();
Node getParentNode();
/** use this method to remove all tags from an HTML node. */ String getPlainTextContent();
NodeStyle getStyle();
String getText();
boolean isDescendantOf(Node p);
boolean isFolded();
boolean isLeaf();
boolean isLeft();
boolean isRoot();
boolean isVisible();
/** removes connector from List<Node> connectors; does the corresponding * on the target Node object referenced by connectorToBeRemoved */ void moveTo(Node parentNode);
void moveTo(Node parentNode, int position);
/** as above, using String nodeID instead of Node object to establish the connector*/ void removeConnector(Connector connectorToBeRemoved);
void setFolded(boolean folded);
void setNoteText(String text);
void setText(String text);
/** Starting from this node, recursively searches for nodes for which
* condition.checkNode(node)
returns true. */
List<Node> find(ICondition condition);
/** Starting from this node, recursively searches for nodes for which closure.call(node)
* returns true. See {@link Controller#find(Closure)} for details. */
List<Node> find(Closure closure);
Date getLastModifiedAt();
void setLastModifiedAt(Date date);
Date getCreatedAt();
void setCreatedAt(Date date); }
interface NodeStyle { void applyPattern(String patternName);
Color getBackgroundColor();
Edge getEdge();
Font getFont();
Color getNodeTextColor();
void setBackgroundColor(Color color);
void setNodeTextColor(Color color); }
} </groovy>