11package edofro.tutorialomatic
22
3- // TODO
3+ import edofro.tutorialomatic.ToM_ui as tomui
4+ import edofro.tutorialomatic.ToM_actions as toma
5+
6+ import org.freeplane.core.ui.components.UITools as ui
7+
8+
9+ class ToM {
10+
11+ static final String tabName = ' Tutorial'
12+
13+ static final Map styles = [
14+ tutorial : ' ToM-Tutorial' ,
15+ ini : ' ToM_' ,
16+ note : ' ToM_note' ,
17+ nextPage : ' ToM_nextPage' ,
18+ showMenu : ' ToM_showMenu' ,
19+ ]
20+
21+ // region: getting tutorial components nodes
22+
23+ def static getNextTutNodes (n ){
24+ def tutNodes = getTutNodes(getTutorialNode(n))
25+ def pos = tutNodes. indexOf(n)
26+ return tutNodes. drop(pos + 1 )
27+ }
28+
29+ def static getTutNodes (nTutorial ){
30+ return nTutorial. find{it. style. name?. startsWith(styles. ini)?: false }
31+ }
32+
33+ def static getTutorialNode (n ){
34+ return n. pathToRoot. find{it. style. name == styles. tutorial}
35+ }
36+
37+ // end:
38+
39+ // region: loop fill contentPane
40+ def static fillContentPane (myPanel , nextTutNodes ){
41+ def interruptLoop = false
42+ // loop TutNodes
43+ for (tutNode in nextTutNodes){
44+ switch (tutNode. style. name){
45+ case styles. note:
46+ addNotes(myPanel, tutNode. children)
47+ break
48+ case styles. nextPage:
49+ addNextPagePane(myPanel, tutNode)
50+ interruptLoop = true
51+ break
52+ case styles. showMenu:
53+ addShowMenuItemPane(myPanel, tutNode. children)
54+ break
55+ default :
56+ ui. informationMessage(' node style not defined' )
57+ break
58+ }
59+ if (interruptLoop) break
60+ }
61+ if (! interruptLoop) addNextPagePane(myPanel, null )
62+ tomui. adjustHeight(myPanel)
63+ }
64+
65+ // end:
66+
67+ // region: component node to tutorial
68+
69+ def static addNotes (myP , nodos ){
70+ nodos. each{n ->
71+ if (n. note) {
72+ myP. add(tomui. createInstructionsPane(n), tomui. GBC )
73+ }
74+ }
75+ }
76+
77+ def static addNextPagePane (myP , lastNode ){
78+ def closeLabel = ' Close tutorial'
79+ def closeToolTip = ' Click to exit the tutorial and close the tutorial tab'
80+ def nextLabel = ' Next page'
81+ def nextToolTip = ' Click to continue to the next page of the tutorial'
82+ def bttnAction = lastNode? { e ->
83+ myP. removeAll()
84+ def nextNodes = getNextTutNodes(lastNode)
85+ fillContentPane(myP, nextNodes)
86+ }: null
87+ def nextButtonPanel = tomui. getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip , bttnAction)
88+ myP. add(nextButtonPanel, tomui. GBC )
89+ }
90+
91+ def static addShowMenuItemPane (myP , nodos ){
92+ nodos. findAll{n -> toma. hasAction(n)}. each{nodo ->
93+ def infoAccion = toma. getActionInfoMap(nodo)
94+ def msgHtml = infoAccion. instructions
95+ def bttnText = ' Show me'
96+ def bttnToolTip = " Click to see where is ${ toma.apos(infoAccion.label)} in Freeplane Menu"
97+ def bttnAction = { e ->
98+ def bttn = e. source
99+ def sel = bttn. isSelected()
100+ toma. closeMenus(infoAccion. action)
101+ if (sel) {
102+ toma. openMenus(infoAccion. action, 400 )
103+ bttn. label = ' Close menu'
104+ } else {
105+ bttn. label = ' Show me'
106+ }
107+ }
108+
109+ def buttonPanel = tomui. getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, true )
110+ myP. add(buttonPanel, tomui. GBC )
111+ }
112+ }
113+
114+ // end:
115+
116+ }
0 commit comments