Difference between revisions of "Scripting API"

From Freeplane - free mind mapping and knowledge management software
(Category:Scripting)
Line 19: Line 19:
  
 
public interface Proxy {
 
public interface Proxy {
/** simplistic interface for unique keys */
+
    /** simplistic interface for unique keys */
interface Attributes {
+
    interface Attributes {
String get(String key);
+
        String get(String key);
  
boolean remove(String key); // returns true on success
+
        public List<String> getAttributeNames();
  
void set(String key, String value);
+
        /** returns the index of an attribute if it is set or -1 otherwise */
}
+
        public int findAttribute(final String key);
  
 +
        /** returns true on removal of an existing attribute and false otherwise. */
 +
        boolean remove(String key);
  
interface Connector {
+
        void set(String key, String value);
Color getColor();
+
    }
  
ArrowType getEndArrow();
+
    interface Connector {
 +
        Color getColor();
  
String getMiddleLabel();
+
        ArrowType getEndArrow();
  
Node getSource();
+
        String getMiddleLabel();
  
String getSourceLabel();
+
        Node getSource();
  
ArrowType getStartArrow();
+
        String getSourceLabel();
  
Node getTarget();
+
        ArrowType getStartArrow();
  
String getTargetLabel();
+
        Node getTarget();
  
void setColor(Color color);
+
        String getTargetLabel();
  
void setEndArrow(ArrowType arrowType);
+
        void setColor(Color color);
  
void setMiddleLabel(String label);
+
        void setEndArrow(ArrowType arrowType);
  
void setSimulatesEdge(boolean simulatesEdge);
+
        void setMiddleLabel(String label);
  
void setSourceLabel(String label);
+
        void setSimulatesEdge(boolean simulatesEdge);
  
void setStartArrow(ArrowType arrowType);
+
        void setSourceLabel(String label);
  
void setTargetLabel(String label);
+
        void setStartArrow(ArrowType arrowType);
  
boolean simulatesEdge();
+
        void setTargetLabel(String label);
}
 
  
interface Controller {
+
        boolean simulatesEdge();
void centerOnNode(Node center);
+
    }
  
Node getSelected();
+
    interface Controller {
 +
        void centerOnNode(Node center);
  
List<Node> getSelecteds();
+
        /** if multiple nodes are selected returns one (arbitrarily chosen)
 +
        * selected node or the selected node for a single node selection. */
 +
        Node getSelected();
  
/** returns List<Node> of Node objects sorted on Y
+
        List<Node> getSelecteds();
* @param differentSubtrees true if only parent nodes of subtrees should be returned*/
 
List<Node> getSortedSelection(boolean differentSubtrees);
 
  
void select(Node toSelect);
+
        /** returns List<Node> of Node objects sorted on Y
 +
        *
 +
        * @param differentSubtrees set to true to exclude
 +
        *  children/grandchildren/grandgrandchildren nodes of selected
 +
        *  parent nodes from the result. */
 +
        List<Node> getSortedSelection(boolean differentSubtrees);
  
/** selects branchRoot and all children */
+
        void select(Node toSelect);
void selectBranch(Node branchRoot);
 
  
/** toSelect is a List<Node> of Node objects */
+
        /** selects branchRoot and all children */
void selectMultipleNodes(java.util.List<Node> toSelect);
+
        void selectBranch(Node branchRoot);
 
/** reset undo / redo lists and deactivate Undo for current script */
 
void deactivateUndo();
 
}
 
  
interface Edge {
+
        /** toSelect is a List<Node> of Node objects */
Color getColor();
+
        void selectMultipleNodes(List<Node> toSelect);
  
EdgeStyle getType();
+
        /** reset undo / redo lists and deactivate Undo for current script */
 +
        void deactivateUndo();
 +
}
 +
 
 +
    interface Edge {
 +
        Color getColor();
 +
 
 +
        EdgeStyle getType();
  
int getWidth();
+
        int getWidth();
  
void setColor(Color color);
+
        void setColor(Color color);
  
void setType(EdgeStyle type);
+
        void setType(EdgeStyle type);
  
/** can be -1 for default, 0 for thin, >0 */
+
        /** can be -1 for default, 0 for thin, >0 */
void setWidth(int width);
+
        void setWidth(int width);
}
+
    }
  
interface ExternalObject {
+
    interface ExternalObject {
/** empty string means that there's no external object */
+
        /** empty string means that there's no external object */
String getURI();  
+
        String getURI();
  
float getZoom();
+
        float getZoom();
  
/** setting empty String uri means remove external object (as for Links); */
+
        /** setting empty String uri means remove external object (as for Links); */
void setURI(String uri);  
+
        void setURI(String uri);
  
void setZoom(float zoom);
+
        void setZoom(float zoom);
}
+
    }
  
interface Font {
+
    interface Font {
String getName();
+
        String getName();
  
int getSize();
+
        int getSize();
  
boolean isBold();
+
        boolean isBold();
  
boolean isBoldSet();
+
        boolean isBoldSet();
  
boolean isItalic();
+
        boolean isItalic();
  
boolean isItalicSet();
+
        boolean isItalicSet();
  
boolean isNameSet();
+
        boolean isNameSet();
  
boolean isSizeSet();
+
        boolean isSizeSet();
  
void resetBold();
+
        void resetBold();
  
void resetItalic();
+
        void resetItalic();
  
void resetName();
+
        void resetName();
  
void resetSize();
+
        void resetSize();
  
void setBold(boolean bold);
+
        void setBold(boolean bold);
  
void setItalic(boolean italic);
+
        void setItalic(boolean italic);
  
void setName(String name);
+
        void setName(String name);
  
void setSize(int size);
+
        void setSize(int size);
}
+
    }
  
interface Icons {
+
    interface Icons {
void addIcon(String name);
+
        void addIcon(String name);
  
/** returns List<Node> of Strings (corresponding to iconID above);
+
        /** returns List<Node> of Strings (corresponding to iconID above);
iconID is one of "Idea","Question","Important", etc.
+
        * iconID is one of "Idea","Question","Important", etc. */
*/
+
        List<String> getIcons();
java.util.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
success (icon existed);
+
        * success (icon existed); */
*/
+
        boolean removeIcon(String iconID);
boolean removeIcon(String iconID);
+
    }
}
 
  
interface Link {
+
    interface Link {
String get();
+
        String get();
  
boolean set(String target); // empty String means remove link (as in
+
        /** empty String means remove link (as in user interface). */
// user interface);
+
        boolean set(String target);
}
+
    }
  
interface Node {
+
    interface Node {
Connector addConnectorTo(Node target);
+
        Connector addConnectorTo(Node target);
  
/** adds a new Connector object to List<Node> connectors and returns
+
        /** 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. */
*/
+
        Connector addConnectorTo(String targetNodeID);
Connector addConnectorTo(String targetNodeID);
 
  
/** inserts *new* node as child, takes care of all construction work and
+
        /** inserts *new* node as child, takes care of all construction work and
internal stuff inserts as last child
+
        * internal stuff inserts as last child. */
*/
+
        Node createChild();
Node createChild();
 
  
/** inserts *new* node as child, takes care of all construction work and
+
        /** inserts *new* node as child, takes care of all construction work and
internal stuff */
+
        * internal stuff */
Node createChild(int position);
+
        Node createChild(int position);
  
void delete();
+
        void delete();
  
Attributes getAttributes();
+
        Attributes getAttributes();
  
int getChildPosition(Node childNode);
+
        int getChildPosition(Node childNode);
  
List<Node> getChildren();
+
        List<Node> getChildren();
  
Collection<Connector> getConnectorsIn();
+
        Collection<Connector> getConnectorsIn();
  
Collection<Connector> getConnectorsOut();
+
        Collection<Connector> getConnectorsOut();
  
ExternalObject getExternalObject();
+
        ExternalObject getExternalObject();
  
Icons getIcons();
+
        Icons getIcons();
  
Link getLink();
+
        Link getLink();
  
String getNodeID();
+
        String getNodeID();
  
int getNodeLevel(boolean countHidden);
+
        /** if countHidden is false then only nodes that are matched by the
 +
        * current filter are counted. */
 +
        int getNodeLevel(boolean countHidden);
  
String getNoteText();
+
        String getNoteText();
  
Node getParentNode();
+
        Node getParentNode();
  
String getPlainTextContent();
+
        /** use this method to remove all tags from an HTML node. */
 +
        String getPlainTextContent();
  
Node getRootNode();
+
        Node getRootNode();
  
NodeStyle getStyle();
+
        NodeStyle getStyle();
  
String getText();
+
        String getText();
  
boolean isDescendantOf(Node p);
+
        boolean isDescendantOf(Node p);
  
boolean isFolded();
+
        boolean isFolded();
  
boolean isLeaf();
+
        boolean isLeaf();
  
boolean isLeft();
+
        boolean isLeft();
  
boolean isRoot();
+
        boolean isRoot();
  
boolean isVisible();
+
        boolean isVisible();
  
/** removes connector from List<Node> connectors; does the corresponding
+
        /** 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);
  
void moveTo(Node parentNode, int position);
+
        void moveTo(Node parentNode, int position);
  
/** as above, using String nodeID instead of Node object to establish the connector*/
+
        /** as above, using String nodeID instead of Node object to establish the connector*/
void removeConnector(Connector connectorToBeRemoved);
+
        void removeConnector(Connector connectorToBeRemoved);
  
void setFolded(boolean folded);
+
        void setFolded(boolean folded);
  
void setNoteText(String text);
+
        void setNoteText(String text);
  
void setText(String text);
+
        void setText(String text);
}
+
    }
  
interface NodeStyle {
+
    interface NodeStyle {
void applyPattern(String patternName);
+
        void applyPattern(String patternName);
  
Color getBackgroundColor();
+
        Color getBackgroundColor();
  
Edge getEdge();
+
        Edge getEdge();
  
Font getFont();
+
        Font getFont();
  
Color getNodeTextColor();
+
        Color getNodeTextColor();
  
void setBackgroundColor(Color color);
+
        void setBackgroundColor(Color color);
  
void setNodeTextColor(Color color);
+
        void setNodeTextColor(Color color);
}
+
    }
 
}
 
}
 
 
</groovy>
 
</groovy>
  
 
[[Category:Scripting]]
 
[[Category:Scripting]]

Revision as of 01:19, 25 January 2010

Each script is given two variables:

<groovy> final Proxy.Node node; final Proxy.Controller c; </groovy>

with the interfaces defined as follows:

<groovy> package org.freeplane.plugin.script.proxy;

import java.awt.Color; import java.util.Collection; import java.util.List;

import org.freeplane.features.common.edge.EdgeStyle; import org.freeplane.features.common.link.ArrowType;

public interface Proxy {

   /** simplistic interface for unique keys */
   interface Attributes {
       String get(String key);
       public List<String> getAttributeNames();
       /** returns the index of an attribute if it is set or -1 otherwise */
       public int findAttribute(final String key);
       /** returns true on removal of an existing attribute and false otherwise. */
       boolean remove(String key);
       void set(String key, String value);
   }
   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 set to true to exclude
        *   children/grandchildren/grandgrandchildren nodes of selected
        *   parent nodes 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();

}

   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();
       /** empty String means remove link (as in user interface). */
       boolean set(String target);
   }
   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();
       int getChildPosition(Node childNode);
       List<Node> getChildren();
       Collection<Connector> getConnectorsIn();
       Collection<Connector> getConnectorsOut();
       ExternalObject getExternalObject();
       Icons getIcons();
       Link getLink();
       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();
       Node getRootNode();
       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);
   }
   interface NodeStyle {
       void applyPattern(String patternName);
       Color getBackgroundColor();
       Edge getEdge();
       Font getFont();
       Color getNodeTextColor();
       void setBackgroundColor(Color color);
       void setNodeTextColor(Color color);
   }

} </groovy>