43
43
import jdk .javadoc .internal .doclets .formats .html .markup .HtmlId ;
44
44
import jdk .javadoc .internal .doclets .formats .html .markup .HtmlStyle ;
45
45
import jdk .javadoc .internal .doclets .formats .html .markup .HtmlTree ;
46
- import jdk .javadoc .internal .doclets .formats .html .markup .Text ;
47
46
import jdk .javadoc .internal .doclets .formats .html .markup .TagName ;
48
47
import jdk .javadoc .internal .doclets .toolkit .Content ;
49
48
77
76
public class Table extends Content {
78
77
private final HtmlStyle tableStyle ;
79
78
private Content caption ;
80
- private Map <String , Predicate <Element >> tabMap ;
81
- private String defaultTab ;
82
- private Set <String > tabs ;
79
+ private Map <Content , Predicate <Element >> tabMap ;
80
+ private Content defaultTab ;
81
+ private Set <Content > tabs ;
83
82
private HtmlStyle tabListStyle = HtmlStyle .tableTabs ;
84
83
private HtmlStyle activeTabStyle = HtmlStyle .activeTableTab ;
85
84
private HtmlStyle tabStyle = HtmlStyle .tableTab ;
@@ -118,28 +117,28 @@ public Table setCaption(Content captionContent) {
118
117
* predicate for the tab, and an element associated with each row.
119
118
* Tabs will appear left-to-right in the order they are added.
120
119
*
121
- * @param name the name of the tab
120
+ * @param label the tab label
122
121
* @param predicate the predicate
123
122
* @return this object
124
123
*/
125
- public Table addTab (String name , Predicate <Element > predicate ) {
124
+ public Table addTab (Content label , Predicate <Element > predicate ) {
126
125
if (tabMap == null ) {
127
126
tabMap = new LinkedHashMap <>(); // preserves order that tabs are added
128
127
tabs = new HashSet <>(); // order not significant
129
128
}
130
- tabMap .put (name , predicate );
129
+ tabMap .put (label , predicate );
131
130
return this ;
132
131
}
133
132
134
133
/**
135
- * Sets the name for the default tab, which displays all the rows in the table.
134
+ * Sets the label for the default tab, which displays all the rows in the table.
136
135
* This tab will appear first in the left-to-right list of displayed tabs.
137
136
*
138
- * @param name the name
137
+ * @param label the default tab label
139
138
* @return this object
140
139
*/
141
- public Table setDefaultTab (String name ) {
142
- defaultTab = name ;
140
+ public Table setDefaultTab (Content label ) {
141
+ defaultTab = label ;
143
142
return this ;
144
143
}
145
144
@@ -266,7 +265,7 @@ public void addRow(List<Content> contents) {
266
265
* If tabs have been added to the table, the specified element will be used
267
266
* to determine whether the row should be displayed when any particular tab
268
267
* is selected, using the predicate specified when the tab was
269
- * {@link #addTab(String, Predicate) added}.
268
+ * {@link #addTab(Content, Predicate) added}.
270
269
*
271
270
* @param element the element
272
271
* @param contents the contents for the row
@@ -285,7 +284,7 @@ public void addRow(Element element, Content... contents) {
285
284
* If tabs have been added to the table, the specified element will be used
286
285
* to determine whether the row should be displayed when any particular tab
287
286
* is selected, using the predicate specified when the tab was
288
- * {@link #addTab(String, Predicate) added}.
287
+ * {@link #addTab(Content, Predicate) added}.
289
288
*
290
289
* @param element the element
291
290
* @param contents the contents for the row
@@ -312,11 +311,11 @@ public void addRow(Element element, List<Content> contents) {
312
311
// The values are used to determine the cells to make visible when a tab is selected.
313
312
tabClasses .add (id .name ());
314
313
int tabIndex = 1 ;
315
- for (Map .Entry <String , Predicate <Element >> e : tabMap .entrySet ()) {
316
- String name = e .getKey ();
314
+ for (Map .Entry <Content , Predicate <Element >> e : tabMap .entrySet ()) {
315
+ Content label = e .getKey ();
317
316
Predicate <Element > predicate = e .getValue ();
318
317
if (predicate .test (element )) {
319
- tabs .add (name );
318
+ tabs .add (label );
320
319
tabClasses .add (HtmlIds .forTab (id , tabIndex ).name ());
321
320
}
322
321
tabIndex ++;
@@ -380,8 +379,7 @@ private Content toContent() {
380
379
if (tabMap == null ) {
381
380
main .add (caption );
382
381
} else {
383
- String tabName = tabs .iterator ().next ();
384
- main .add (getCaption (Text .of (tabName )));
382
+ main .add (getCaption (tabs .iterator ().next ()));
385
383
}
386
384
table .add (getTableBody ());
387
385
main .add (table );
@@ -393,10 +391,10 @@ private Content toContent() {
393
391
int tabIndex = 0 ;
394
392
tablist .add (createTab (HtmlIds .forTab (id , tabIndex ), activeTabStyle , true , defaultTab ));
395
393
table .put (HtmlAttr .ARIA_LABELLEDBY , HtmlIds .forTab (id , tabIndex ).name ());
396
- for (String tabName : tabMap .keySet ()) {
394
+ for (Content tabLabel : tabMap .keySet ()) {
397
395
tabIndex ++;
398
- if (tabs .contains (tabName )) {
399
- HtmlTree tab = createTab (HtmlIds .forTab (id , tabIndex ), tabStyle , false , tabName );
396
+ if (tabs .contains (tabLabel )) {
397
+ HtmlTree tab = createTab (HtmlIds .forTab (id , tabIndex ), tabStyle , false , tabLabel );
400
398
tablist .add (tab );
401
399
}
402
400
}
@@ -414,7 +412,7 @@ private Content toContent() {
414
412
return main ;
415
413
}
416
414
417
- private HtmlTree createTab (HtmlId tabId , HtmlStyle style , boolean defaultTab , String tabName ) {
415
+ private HtmlTree createTab (HtmlId tabId , HtmlStyle style , boolean defaultTab , Content tabLabel ) {
418
416
HtmlTree tab = new HtmlTree (TagName .BUTTON )
419
417
.setId (tabId )
420
418
.put (HtmlAttr .ROLE , "tab" )
@@ -425,7 +423,7 @@ private HtmlTree createTab(HtmlId tabId, HtmlStyle style, boolean defaultTab, St
425
423
.put (HtmlAttr .ONCLICK , "show('" + id .name () + "', '" + (defaultTab ? id : tabId ).name ()
426
424
+ "', " + columnStyles .size () + ")" )
427
425
.setStyle (style );
428
- tab .add (tabName );
426
+ tab .add (tabLabel );
429
427
return tab ;
430
428
}
431
429
0 commit comments