Difference between revisions of "Scripting API"

From Freeplane - free mind mapping and knowledge management software
m (Added categories)
Line 1: Line 1:
[[User:Dimitry|Dimitry]] 07:54, 3 November 2009 (UTC)
+
Each script is given two variables:
  
== Please use this page to specify the methods which should be available for objects "node" and "c"  ==
+
<groovy>
 +
final Proxy.Node node;
 +
final Proxy.Controller c;
 +
</groovy>
  
This page was started following a suggestion of Dimitry [http://sourceforge.net/projects/freeplane/forums/forum/758437/topic/3446671?message=7744225] in reply of a post of mine.
+
with the interfaces defined as follows:
  
Its first goal is to specify Freeplane Script API which is not implemented yet. Afterwards it can serve as documentation for users with little knowledge of the internals of Freeplane so that they can port their scripts when changing from Freemind.  
+
<groovy>
 +
package org.freeplane.plugin.script.proxy;
  
This is a list of methods (and a variable) of the objects "node" and "c" passed to the scripts by Freemind which I used so far. It is not complete, and in fact I'd like to have methods at hand to access (read/write) attributes and their values, as well as icons. There might be more useful things that one could wish to do in a script.  
+
import java.awt.Color;
 +
import java.util.Collection;
 +
import java.util.List;
  
Finally the list:
+
import org.freeplane.features.common.edge.EdgeStyle;
 +
import org.freeplane.features.common.link.ArrowType;
  
Is is complete? [[User:Dimitry|Dimitry]]
+
public interface Proxy {
 +
/** simplistic interface for unique keys */
 +
interface Attributes {
 +
String get(String key);
  
In the sense of "does it cover all methods that are available in Freemind 0.9.0": No. These are just the ones I am currently using.
+
boolean remove(String key); // returns true on success
  
Would you rather like to have a 'wishlist', or to implement a 100% Freemind compatible API in one step? My feeling is that -- for you, and once you wrote proxy classes partially implementing the Freemind API -- it would be very easy to add one after the other, depending on user requests. I don't know which way you prefer. [[User:Philshvarcz|philshvarcz]]
+
void set(String key, String value);
 +
}
  
Actually neither the first nor the second. I do not want to copy FreeMind API because FreeMind does not use proxy object which is likely to make troubles with undo after script is executed. I would like to implement a new property like API which contains enough methods for changing anything you need but is easy to use and clear, although there are a lot of parameters it can get/set. So may be having only "node" is not enough, maybe we need something like
 
  
node.style.font.setSize(14)
+
interface Connector {
<nowiki>node.note.setHtmlText("<html><b>text")</nowiki>
+
Color getColor();
node.attributes.getAttributePosition(String)
 
  
Therefore I ask you to be creative so that we have an extendable, clear and easy to use API for scripting. Once we see what we need I can implement it in a couple of days because it is not a new functionality but just a new interface. [[User:Dimitry|Dimitry]] 10:18, 3 November 2009 (UTC)  
+
ArrowType getEndArrow();
  
=== node  ===
+
String getMiddleLabel();
<pre>int getAttributePosition(String)</pre>
 
what is it? [[User:Dimitry|Dimitry]]
 
  
this will return the position of the attribute with name xyz in the list of attributes of the node. If there's no attribute with that name, it returns -1. [[User:Philshvarcz|philshvarcz]]
+
Node getSource();
  
<br>
+
String getSourceLabel();
<pre>String getPlainTextContent()
 
int getChildCount()
 
void setBackgroundColor(Color)
 
void setColor(Color)
 
void node.setFont(Font)
 
List getChildren()
 
  
List children</pre>  
+
ArrowType getStartArrow();
=== c  ===
+
 
<pre>void nodeStructureChanged(MindMapNode)
+
Node getTarget();
List getSelecteds()
+
 
MindMapNode getSelected()
+
String getTargetLabel();
void centerNode(MindMapNode)
+
 
</pre>  
+
void setColor(Color color);
--[[User:Philshvarcz|Philshvarcz]] 21:33, 2 November 2009 (UTC)  
+
 
 +
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);
 +
 
 +
Node getSelected();
 +
 
 +
List<Node> getSelecteds();
 +
 
 +
/** returns List<Node> of Node objects sorted on Y */
 +
List<Node> getSortedSelection();
 +
 
 +
void select(Node toSelect);
 +
 
 +
/** selects branchRoot and all children */
 +
void selectBranch(Node branchRoot);
 +
 
 +
/** toSelect is a List<Node> of Node objects */
 +
void selectMultipleNodes(java.util.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.
 +
*/
 +
java.util.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();
 +
 
 +
boolean set(String target); // empty String means remove link (as in
 +
// user interface);
 +
}
 +
 
 +
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();
 +
 
 +
int getNodeLevel(boolean countHidden);
 +
 
 +
String getNoteText();
 +
 
 +
Node getParentNode();
 +
 
 +
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>
  
 
[[Category:Advanced_Users]][[Category:Developer_Documentation]]
 
[[Category:Advanced_Users]][[Category:Developer_Documentation]]

Revision as of 07:55, 30 November 2009

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);

boolean remove(String key); // returns true on success

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);

Node getSelected();

List<Node> getSelecteds();

/** returns List<Node> of Node objects sorted on Y */ List<Node> getSortedSelection();

void select(Node toSelect);

/** selects branchRoot and all children */ void selectBranch(Node branchRoot);

/** toSelect is a List<Node> of Node objects */ void selectMultipleNodes(java.util.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. */ java.util.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();

boolean set(String target); // empty String means remove link (as in // user interface); }

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();

int getNodeLevel(boolean countHidden);

String getNoteText();

Node getParentNode();

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>