Skip to content

Commit 73c6ffc

Browse files
committed
WIP
scrollContentPaneBackToTop setNextPagePanelEnabled pending state
1 parent 9669f22 commit 73c6ffc

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class ToM{
3737
// end:
3838

3939
// region: loop fill contentPane
40-
def static fillContentPane(myPanel, nextTutNodes){
40+
def static fillContentPane(myPanel, nextTutNodes, boolean doClear = true){
4141
def interruptLoop = false
42-
// loop TutNodes
42+
if(doClear) myPanel.removeAll()
43+
tomui.resizeContentPanel(myPanel,tomui.maxContentPaneHeigth)
4344
for (tutNode in nextTutNodes){
4445
switch(tutNode.style.name){
4546
case styles.note:
@@ -59,7 +60,7 @@ class ToM{
5960
if(interruptLoop) break
6061
}
6162
if(!interruptLoop) addNextPagePane(myPanel, null)
62-
tomui.adjustHeight(myPanel)
63+
tomui.adjustHeight(myPanel, doClear)
6364
}
6465

6566
// end:
@@ -80,9 +81,8 @@ class ToM{
8081
def nextLabel = 'Next page'
8182
def nextToolTip = 'Click to continue to the next page of the tutorial'
8283
def bttnAction = lastNode?{ e ->
83-
myP.removeAll()
8484
def nextNodes = getNextTutNodes(lastNode)
85-
fillContentPane(myP, nextNodes)
85+
fillContentPane(myP, nextNodes, true)
8686
}:null
8787
def nextButtonPanel = tomui.getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip , bttnAction)
8888
myP.add(nextButtonPanel, tomui.GBC)
@@ -97,16 +97,21 @@ class ToM{
9797
def bttnAction = { e ->
9898
def bttn = e.source
9999
def sel = bttn.isSelected()
100+
def bttnPanel = tomui.getButtonPanel(bttn)
101+
bttnPanel.pending = sel
100102
toma.closeMenus(infoAccion.action)
101103
if (sel) {
102104
toma.openMenus(infoAccion.action, 400)
103105
bttn.label = 'Close menu'
106+
tomui.setNextPagePanelEnabled(myP, false)
104107
} else {
105108
bttn.label = 'Show me'
109+
if(! tomui.anyCompPending(myP) ) tomui.setNextPagePanelEnabled(myP, true)
106110
}
107111
}
108112

109113
def buttonPanel = tomui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, true)
114+
buttonPanel.metaClass.pending = false
110115
myP.add(buttonPanel, tomui.GBC)
111116
}
112117
}

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import java.awt.Insets
1010
import java.awt.GridBagConstraints
1111
import java.awt.Dimension
1212
import java.awt.GridBagLayout
13+
import java.awt.Point
1314

1415
// import javax.swing.*
1516
import javax.swing.border.EmptyBorder
1617
import javax.swing.border.LineBorder
1718
import javax.swing.border.CompoundBorder
1819
import javax.swing.SwingUtilities as SU
20+
import javax.swing.JPanel
1921

2022
import groovy.swing.SwingBuilder
2123

@@ -30,6 +32,7 @@ class ToM_ui{
3032
static final int maxContentPaneHeigth = 50000
3133
static final String myPaneName = 'myContentPanel'
3234
static final String myButtonPanelName = 'aButtonPane'
35+
static final String myNextPanelName = 'nextPane'
3336

3437
static SwingBuilder swing = new SwingBuilder()
3538

@@ -113,11 +116,14 @@ class ToM_ui{
113116
}
114117

115118

116-
def static adjustHeight(comp){
119+
def static adjustHeight(comp, boolean backToTop = false){
120+
if (backToTop) scrollContentPaneBackToTop(comp)
117121
TabPane.repaint()
118122
def timer = new Timer()
119123
timer.runAfter(1000) {
120124
resizeContentPanel(comp, comp.height + 200)
125+
if (backToTop) scrollContentPaneBackToTop(comp)
126+
// TabPane.revalidate() <--- no funciona
121127
TabPane.repaint()
122128
}
123129
}
@@ -212,7 +218,7 @@ class ToM_ui{
212218
def static getNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip, nextButtonAction ){
213219
def panel = swing.panel(
214220
border : new LineBorder(Color.gray, 1),
215-
name : myButtonPanelName,
221+
name : myNextPanelName,
216222
) {
217223
borderLayout()
218224
panel(
@@ -242,4 +248,34 @@ class ToM_ui{
242248
}
243249

244250

251+
def static getNextButtonPanel(myP){
252+
return myP.components.find{it.name == myNextPanelName}
253+
}
254+
255+
def static setNextPagePanelEnabled(JPanel myP, boolean isEnabled){
256+
setPanelEnabled(getNextButtonPanel(myP), isEnabled)
257+
}
258+
259+
def static setPanelEnabled(JPanel panel, boolean isEnabled) {
260+
panel.setEnabled(isEnabled)
261+
262+
panel.components.each{ comp ->
263+
if (comp instanceof JPanel) {
264+
setPanelEnabled(comp, isEnabled)
265+
}
266+
comp.setEnabled(isEnabled)
267+
}
268+
}
269+
270+
def static anyCompPending(myP){
271+
return myP.components.any{it.hasProperty('pending') && it.pending}
272+
}
273+
// scrollPane
274+
def static getScrollPaneViewport(comp){
275+
return SU.getAncestorOfClass(javax.swing.JViewport, comp)
276+
}
277+
278+
def static scrollContentPaneBackToTop(comp){
279+
getScrollPaneViewport(comp).setViewPosition(new Point(0,0))
280+
}
245281
}

0 commit comments

Comments
 (0)