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; } }