blob: d95badc3a964e1f851ba8c6708dba873a2c20084 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package bjc.utils.gui.browser;
/** Data model for JBrowser (hierarchical, like TreeModel but simpler). */
public interface JBrowserModel {
Object getRoot();
int getChildCount(Object parent);
Object getChild(Object parent, int index);
default int indexOfChild(Object parent, Object child) {
int n = getChildCount(parent);
for (int i = 0; i < n; i++)
if (getChild(parent, i).equals(child))
return i;
return -1;
}
boolean isLeaf(Object node);
/** Display text for nodes (used by default renderer & default filter). */
default String getText(Object node) {
return String.valueOf(node);
}
/** True if node can expand (used by default renderer). */
default boolean isExpandable(Object node) {
return !isLeaf(node);
}
/** Header text for the column that is showing the children of parentNode. */
default String getColumnHeader(Object parentNode, int depthFromRoot) {
String t = getText(parentNode);
return (t == null || t.isEmpty()) ? "(root)" : t;
}
}
|