Skip to content

Commit e697f1d

Browse files
committed
TOC
1 parent 18b9973 commit e697f1d

2 files changed

Lines changed: 59 additions & 6 deletions

File tree

Tutorial-o-Matic/src/main/groovy/ToM.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ToM{
1717
nextPage : 'ToM_nextPage' ,
1818
newPage : 'ToM_newPage' ,
1919
showMenu : 'ToM_showMenu' ,
20+
toc : 'ToM_TOC' ,
2021
]
2122

2223
// region: getting tutorial components nodes
@@ -68,6 +69,9 @@ class ToM{
6869
case styles.showMenu:
6970
addShowMenuItemPane(myPanel, tutNode.children)
7071
break
72+
case styles.toc:
73+
addTOCPane(myPanel, tutNode)
74+
break
7175
default:
7276
ui.informationMessage('node style not defined')
7377
break
@@ -109,6 +113,11 @@ class ToM{
109113
}:null
110114
def nextButtonPanel = tomui.getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip , bttnAction)
111115
def bttnAction = lastNode? { e -> fillPage(myP, lastNode, included, true) } : null
116+
def tocLabel = 'Table of Contents'
117+
def tocToolTip = 'Click to show the Table of Contents of the tutorial'
118+
def tocBttnAction = { e -> showTOC(myP,lastNode) }
119+
120+
def nextButtonPanel = tomui.getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip , bttnAction, tocLabel, tocToolTip, tocBttnAction)
112121
myP.add(nextButtonPanel, tomui.GBC)
113122
}
114123

@@ -117,6 +126,13 @@ class ToM{
117126
fillContentPane(myP, nextNodes, doClear)
118127
}
119128

129+
130+
def static showTOC(myP,nodo){
131+
myP.removeAll()
132+
tomui.resizeContentPanel(myP,tomui.maxContentPaneHeigth)
133+
addTOCPane(myP,nodo)
134+
tomui.adjustHeight(myP, true)
135+
}
120136

121137
def static addShowMenuItemPane(myP, nodos){
122138
nodos.findAll{n -> toma.hasAction(n)}.each{nodo ->
@@ -151,6 +167,18 @@ class ToM{
151167
}
152168
}
153169

170+
def static addTOCPane(myP,nodo){
171+
def titleNodes = getNewPageNodes(getTutorialNode(nodo))
172+
def pane = tomui.createEmptyGridBagPanel()
173+
titleNodes.each{ tn ->
174+
def title = tn.text
175+
def bttnAction = { e -> fillPage(myP, tn, true, true) }
176+
def button = tomui.createButton(title, bttnAction)
177+
pane.add(button, tomui.GBC)
178+
}
179+
myP.add(pane, tomui.GBC)
180+
}
181+
154182
// end:
155183

156184
}

Tutorial-o-Matic/src/main/groovy/ToM_ui.groovy

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ToM_ui{
5757
ipadx : 0, // This field specifies the internal padding of the component, how much space to add to the minimum width of the component. The width of the component is at least its minimum width plus ipadx pixels.
5858
ipady : 0 // This field specifies the internal padding, that is, how much space to add to the minimum height of the component. The height of the component is at least its minimum height plus ipady pixels.
5959
)
60-
60+
6161
def static showTextMessage(msg, lapseTime){
6262
def win = swing.dialog(
6363
undecorated : true,
@@ -138,8 +138,8 @@ class ToM_ui{
138138
if (backToTop) scrollContentPaneBackToTop(comp)
139139
TabPane.repaint()
140140
def timer = new Timer()
141-
timer.runAfter(3000) {
142-
resizeContentPanel(comp, comp.height + 500)
141+
timer.runAfter(100) {
142+
resizeContentPanel(comp, comp.height + 100)
143143
if (backToTop) scrollContentPaneBackToTop(comp)
144144
// TabPane.revalidate() <--- no funciona
145145
TabPane.repaint()
@@ -205,7 +205,7 @@ class ToM_ui{
205205
vbox(constraints:SOUTH) {
206206
panel(
207207
// border : new LineBorder(Color.black, 1),
208-
border : new EmptyBorder(5, 10, 5, 10), // <------- éste
208+
border : new EmptyBorder(2, 10, 2, 10), // <------- éste
209209
//border: new CompoundBorder(new LineBorder(Color.red, 1),new EmptyBorder(5, 10, 5, 10)) // éste es de prueba poder ver el borde
210210
//insets : new Insets(30,10,30,10),
211211
) {
@@ -235,14 +235,14 @@ class ToM_ui{
235235

236236
// genera panel close - next page
237237
//nextButtonAction == null --> no 'Next page' button
238-
def static getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip, nextButtonAction ){
238+
def static getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip, nextButtonAction, tocLabel = '', tocToolTip = '', tocButtonAction = null ){
239239
def panel = swing.panel(
240240
border : new LineBorder(Color.gray, 1),
241241
name : myNextPanelName,
242242
) {
243243
borderLayout()
244244
panel(
245-
border : new EmptyBorder(5, 10, 5, 10), // <------- éste
245+
border : new EmptyBorder(2, 10, 2, 10), // <------- éste
246246
constraints : NORTH
247247
) {
248248
borderLayout()
@@ -253,6 +253,15 @@ class ToM_ui{
253253
toolTipText : closeToolTip,
254254
actionPerformed : {TabPane.removeTab(tabName)},
255255
)
256+
if(tocButtonAction && nextButtonAction){
257+
button(
258+
label : tocLabel,
259+
constraints : CENTER,
260+
margin : new Insets(10,15,10,15),
261+
toolTipText : tocToolTip,
262+
actionPerformed : tocButtonAction,
263+
)
264+
}
256265
if(nextButtonAction){
257266
button(
258267
label : nextLabel,
@@ -298,4 +307,20 @@ class ToM_ui{
298307
def static scrollContentPaneBackToTop(comp){
299308
getScrollPaneViewport(comp).setViewPosition(new Point(0,0))
300309
}
310+
311+
def static createEmptyGridBagPanel(){
312+
return swing.panel(
313+
layout: new GridBagLayout(),
314+
border : new EmptyBorder(2, 10, 2, 0), //new LineBorder(Color.black, 1),
315+
// background: Color.gray
316+
){}
317+
}
318+
319+
def static createButton(title, bttnAction){
320+
return swing.button(
321+
label : title,
322+
margin : new Insets(10,15,10,15),
323+
actionPerformed : bttnAction,
324+
)
325+
}
301326
}

0 commit comments

Comments
 (0)