User-contributed example scripts

From FreeMind
Revision as of 21:57, 13 March 2007 by DimitriPolivaev (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

A node with the current time

If you need a node that shows the last saving time, just add the following script and start it once each time, you are opening the map for editing.

<groovy> import freemind.modes.MindMapNode; import freemind.modes.mindmapmode.MindMapController; import java.util.Timer;

class DateTimer extends java.util.TimerTask { MindMapNode mNode; MindMapController mC; DateTimer(node, c) { mNode = node; mC = c; }

void run() { mNode.setText("Save Time: " + new java.util.Date()); mC.nodeRefresh(mNode); } }

t = new Timer(); t.schedule(new DateTimer(node, c),2000,2000); </groovy>

WARNING! I have now played with Groovy for 30 minutes and I am unsure of the side effects to FreeMind of using these examples, as they modify children of a node. - Dave Torok

Prepend the modified date at the beginning of the node text

This is an example of using some more Node methods.

<groovy>=(new java.text.SimpleDateFormat("M/d/yyyy")).format(node.getHistoryInformation().getLastModifiedAt())

  + " " + node.getText()</groovy>

Add up all subnodes and set them into the first row, second column.

Copy the script into subnodes if you want go more than one level. As far as I can tell you can't grab the values by attribute name, just by row / column, but I didn't spend forever looking over the source.. (Maybe someone could push some javadoc?)


<groovy> def i = node.childrenUnfolded(); def total=0; while (i.hasNext()) { d = i.next(); def val=d.getAttributes().getValueAt(0,1); if (val!=null) total=total+java.lang.Integer.parseInt(val); }; node.getAttributes().setValueAt(total, 0,1);</groovy>

The above code has a problem that it will let leaf node and its parent nodes with the script to yield 0 value. The following code would work recursively.

<groovy> if (!node.isLeaf()) {def i = node.childrenUnfolded(); def total=0; while (i.hasNext()) { d = i.next(); def val=d.getAttributes().getValueAt(0,1); if (val!=null) total=total+java.lang.Integer.parseInt(val); }; node.getAttributes().setValueAt(total, 0,1);};</groovy>

--yushen 15:35, 15 Jan 2007 (PST)



Set the color for all children

This is an example of iteration over child nodes. Also, a call to c.nodeStructureChanged(node) is necessary to force a refresh to paint the new color.

<groovy> def i = node.childrenUnfolded(); while (i.hasNext()) { d = i.next(); d.setColor(java.awt.Color.BLUE); }; c.nodeStructureChanged();</groovy>

Swap two CHILD nodes

This works. My goal is to get a foundation for a SORT script, to sort children by alphabet, by created date, etc. until the functionality is added to the software. WARNING WARNING WARNING this is just an example to swap the 2nd and 4th child nodes.

<groovy>def swap (a,b) {

   na = node.getChildAt(a);
   nb = node.getChildAt(b);
   node.remove(a); 
   node.remove(b - 1); 
   node.insert(nb,a);
   node.insert(na,b);
   c.nodeStructureChanged(node);

};

swap(1,3);</groovy>

Add/Replace today

<groovy> =nt=node.toString(); pos=nt.indexOf(" / "); return ((pos>=0)?nt.substring(0,pos):nt) + " / "

  + (new java.text.SimpleDateFormat("yyyy-M-d")).format(new Date())

</groovy>