Skip to content

Commit 6cda0b8

Browse files
committed
tab name can now be customized
1 parent 328b101 commit 6cda0b8

4 files changed

Lines changed: 59 additions & 15 deletions

File tree

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ class TabPane{
1212
//region: methods
1313

1414
def static removeTab(String tabName, boolean hideTabPane = false){
15-
def index = tabPane.indexOfTab(tabName)
16-
//eliminar
15+
int index = tabPane.indexOfTab(tabName)
16+
//msg("removeTab String - index: $index")
17+
removeTab(index, hideTabPane)
18+
}
19+
20+
def static removeTab(javax.swing.JComponent comp, boolean hideTabPane = false){
21+
int index = tabPane.indexOfComponent(comp)
22+
//msg("removeTab Component - index: $index")
23+
removeTab(index, hideTabPane)
24+
}
25+
26+
def static removeTab(int index, boolean hideTabPane = false){
27+
//msg("removeTab index - index: $index")
1728
if (index >= 0) {
1829
tabPane.removeTabAt(index)
1930
def previousTab = tabPane.hasProperty('previousTab')? tabPane.previousTab : 0
@@ -67,5 +78,9 @@ class TabPane{
6778
def static repaint(){
6879
tabPane.repaint()
6980
}
81+
82+
def static msg(texto){
83+
ui.informationMessage(texto.toString())
84+
}
7085
//end:
7186
}

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ class ToM{
1515
// region: properties
1616
// this region has all the properties for the ToM class
1717

18-
static final String version = '0.0.4'
19-
static final c = ScriptUtils.c()
20-
static final String tabName = 'Tutorial'
21-
static final String idDictStorage = 'ToM_idDictionary'
18+
static final String version = '0.0.6'
19+
static final c = ScriptUtils.c()
20+
static final String idDictStorage = 'ToM_idDictionary'
21+
static final String attributeTabLabel = 'ToM_TabLabel'
22+
static final String defaultTabLabel = 'Tutorial'
23+
static final String defaultMapTutorialsTabLabel = 'Tutorials'
24+
2225

2326
static final Map styles = [
2427
tutorial : 'ToM-Tutorial' ,
@@ -199,7 +202,7 @@ class ToM{
199202
def tocToolTip = 'Click to show the Table of Contents of the tutorial'
200203
def tocBttnAction = { e -> showTOC(myP,lastNode) }
201204

202-
def nextButtonPanel = tomui.createNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip , bttnAction, tocLabel, tocToolTip, tocBttnAction)
205+
def nextButtonPanel = tomui.createNextButtonPanel(closeLabel, closeToolTip, nextLabel, nextToolTip , bttnAction, tocLabel, tocToolTip, tocBttnAction)
203206
myP.add(nextButtonPanel, tomui.GBC)
204207
}
205208

@@ -513,15 +516,17 @@ class ToM{
513516
def bttnAction = { e ->
514517
def tutNodes = getTutNodes(nT)
515518
if(tutNodes) {
516-
fillContentPane(myP, tutNodes)
519+
def tutorialTabName = nT[attributeTabLabel] ?: defaultTabLabel
520+
def myP_thisTutorial = tomui.getContentPaneFromMyTab(tutorialTabName.toString(), true)
521+
fillContentPane(myP_thisTutorial, tutNodes)
517522
} else {
518523
ui.informationMessage( "no tutorial components(nodes) found for tutorial '${nT.text}'".toString() )
519524
}
520525
}
521526
def button = tomui.createButton(title, bttnAction)
522527
pane.add(button, tomui.GBC)
523528
}
524-
def stopButton = tomui.createButton('Exit tutorial', {tomui.closeTab(tabName)})
529+
def stopButton = tomui.createButton('CLOSE', { e -> tomui.closeTab(e.source)})
525530
pane.add(stopButton, tomui.GBC)
526531
myP.add(pane, tomui.GBC)
527532
} else {
@@ -548,7 +553,8 @@ class ToM{
548553
}
549554

550555
def static showTutorials(mapa){
551-
def myP = tomui.getContentPaneFromMyTab(tabName, true)
556+
def tutorialTabName = mapa.root[attributeTabLabel] ?: defaultMapTutorialsTabLabel
557+
def myP = tomui.getContentPaneFromMyTab(tutorialTabName.toString(), true)
552558
myP.removeAll()
553559
tomui.resizeContentPanel(myP,tomui.maxContentPaneHeigth)
554560
addTutorialsPane(myP, mapa)

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class ToM_ui{
295295

296296
// genera panel close - next page
297297
//nextButtonAction == null --> no 'Next page' button
298-
def static createNextButtonPanel(tabName, closeLabel, closeToolTip, nextLabel, nextToolTip, nextButtonAction, tocLabel = '', tocToolTip = '', tocButtonAction = null ){
298+
def static createNextButtonPanel(closeLabel, closeToolTip, nextLabel, nextToolTip, nextButtonAction, tocLabel = '', tocToolTip = '', tocButtonAction = null ){
299299
def panel = swing.panel(
300300
//border : new LineBorder(Color.gray, 1),
301301
name : myNextPanelName,
@@ -311,7 +311,7 @@ class ToM_ui{
311311
constraints : WEST,
312312
margin : new Insets(10,15,10,15),
313313
toolTipText : closeToolTip,
314-
actionPerformed : {closeTab(tabName)},
314+
actionPerformed : { e -> closeTab(e.source) },
315315
)
316316
if(tocButtonAction /* && nextButtonAction */ ){
317317
button(
@@ -415,10 +415,17 @@ class ToM_ui{
415415

416416
//region: other methods
417417

418-
def static closeTab(tabName, boolean hideTabPane = false) {
418+
def static closeTab(String tabName, boolean hideTabPane = false) {
419419
TabPane.removeTab(tabName, hideTabPane)
420420
}
421421

422+
def static closeTab(javax.swing.JComponent comp, boolean hideTabPane = false) {
423+
//msg(comp.class)
424+
def componente = getScrollPaneViewport(comp).parent
425+
//msg(componente.class)
426+
TabPane.removeTab(componente, hideTabPane)
427+
}
428+
422429
def static setNextPagePanelEnabled(JPanel myP, boolean isEnabled){
423430
setPanelEnabled(getNextButtonPanel(myP), isEnabled)
424431
}
@@ -442,6 +449,10 @@ class ToM_ui{
442449
getScrollPaneViewport(comp).setViewPosition(new Point(0,0))
443450
}
444451

452+
def static msg(texto){
453+
ui.informationMessage(texto.toString())
454+
}
455+
445456
//end:
446457

447458

Tutorial-o-Matic/zips/doc/Tutorial-o-Matic/SimpleTutorialSample.mm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
</p>
136136
</body>
137137
</html></richcontent>
138+
<attribute_layout NAME_WIDTH="86.25 pt" VALUE_WIDTH="87 pt"/>
139+
<attribute NAME="ToM_TabLabel" VALUE="ToM - Samples"/>
138140
<node TEXT="SIMPLE DEMO" STYLE_REF="ToM-Tutorial" FOLDED="true" POSITION="right" ID="ID_390003608">
139141
<node TEXT="greetings" ID="ID_659572764">
140142
<node TEXT="Welcome to the Tutorial-o-Matic Simple Tutorial Demo!" STYLE_REF="ToM_newPage" ID="ID_577559944"/>
@@ -1794,9 +1796,19 @@ candle indicates that executes only one time (then button gets disabled)
17941796
<p>
17951797
Buttons &quot;inspect&quot; and &quot;reload&quot; appear on page's top.
17961798
</p>
1799+
<p>
1800+
1801+
</p>
1802+
<p>
1803+
the attribute &quot;ToM_TabLabel&quot; indicates which Tab should the tutorial be shown in.
1804+
</p>
1805+
<p>
1806+
If not present -&gt; default is &quot;Tutorial&quot;
1807+
</p>
17971808
</body>
1798-
</html>
1799-
</richcontent>
1809+
</html></richcontent>
1810+
<attribute_layout NAME_WIDTH="86.25 pt" VALUE_WIDTH="66.75 pt"/>
1811+
<attribute NAME="ToM_TabLabel" VALUE="in new tab"/>
18001812
<node TEXT="Introduction" FOLDED="true" ID="ID_791969447">
18011813
<node TEXT="Introduction" STYLE_REF="ToM_newPage" ID="ID_615110223">
18021814
<node TEXT="nodes with style newPage defines the title for the page and indicates where the page starts" ID="ID_963032450"/>

0 commit comments

Comments
 (0)