Package sc.fiji.snt.gui
Class OntologyBrowser
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
sc.fiji.snt.gui.OntologyBrowser
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
A reusable panel that presents one or more hierarchical ontologies as
searchable checkbox trees. Users pick terms and selections are serialized
as "::"-delimited hierarchical strings (e.g.,
"Isocortex::Visual areas::VISp").
Ontology tabs can be added from existing DefaultTreeModels (e.g.,
Allen CCF via AllenUtils.getTreeModel(boolean)), or from simple
nested Maps for user-defined term hierarchies.
- Author:
- Tiago Ferreira
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefault cell renderer for Allen CCF ontology trees.classRepresents a single ontology tab containing a searchable checkbox tree.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionA predefined path formatter that builds a "::"-delimited string using only acronyms.A predefined path formatter that returns only the leaf node's name.static final StringSeparator used for serializing hierarchical paths.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty OntologyBrowser with multi-selection enabled.OntologyBrowser(boolean singleSelection) Creates an empty OntologyBrowser. -
Method Summary
Modifier and TypeMethodDescriptionConvenience method to add the Allen CCF ontology as a tab, including all compartments.addAllenCCFOntology(boolean meshesOnly) Adds the Allen CCF ontology as a tab.voidAdds all the default ontologies as tabs.addDeepOntology(String tabLabel, Map<String, Object> tree) Adds a custom ontology tab built from a deeply nested map.Adds the Drosophila adult brain ontology (FBbt) as a tab.Adds a custom ontology tab from a nested map.addOntology(String tabLabel, DefaultTreeModel model) Adds an ontology tab backed by an existingDefaultTreeModel.voidaddSelectionListener(Consumer<List<String>> listener) Registers a listener that is notified whenever the checked selection changes in any tab.voidClears all checked selections across all tabs.voidCopies the checked terms to the system clipboard.<T> List<T> getCheckedUserObjects(Class<T> type) Returns the checked user objects from all tabs, cast to the given type.Returns only the leaf-level names of checked selections (without ancestor prefixes).Returns the checked selections from all tabs as "::"- delimited hierarchical paths.getTab(int index) Returns the tab at the given index.intReturns the number of ontology tabs.static StringserializePath(TreePath treePath) voidsetPathFormatter(Function<TreePath, String> formatter) Sets a custom formatter for converting checkedTreePaths into strings.showDialog(Component parent, String title) Shows this browser in a modal dialog and returns the selected paths, ornullif the user cancelled.showModelessDialog(Component parent, String title) Shows this browser in a modeless (non-modal) dialog for reference browsing.voidshowSelectionInfo(Component parent) Displays an HTML info table for the currently checked compartments.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
SEPARATOR
Separator used for serializing hierarchical paths.- See Also:
-
LEAF_ONLY_FORMATTER
A predefined path formatter that returns only the leaf node's name. ForBrainAnnotationuser objects, returns the acronym (if available and different from the name) prefixed to the name, e.g.,"PB: protocerebral bridge". Otherwise falls back totoString(). Useful when the full hierarchical path would be too long for display. -
ACRONYM_ONLY_FORMATTER
A predefined path formatter that builds a "::"-delimited string using only acronyms. For each node in the path (excluding the root), theBrainAnnotation.acronym()is used if available, otherwise the name. E.g.,"CX::PB"instead of"adult central complex (CX)::protocerebral bridge (PB) (3669)".
-
-
Constructor Details
-
OntologyBrowser
public OntologyBrowser()Creates an empty OntologyBrowser with multi-selection enabled. Add ontology tabs viaaddOntology(String, DefaultTreeModel)or convenience methods. -
OntologyBrowser
public OntologyBrowser(boolean singleSelection) Creates an empty OntologyBrowser.- Parameters:
singleSelection- iftrue, only one term can be checked at a time across all tabs (radio-group behavior)
-
-
Method Details
-
addOntology
Adds an ontology tab backed by an existingDefaultTreeModel.- Parameters:
tabLabel- the tab titlemodel- the tree model (nodes should have meaningfultoString()on their user objects)- Returns:
- the created
OntologyBrowser.OntologyTabfor further customization
-
addAllenCCFOntology
Convenience method to add the Allen CCF ontology as a tab, including all compartments.- Returns:
- the created
OntologyBrowser.OntologyTab
-
addAllenCCFOntology
Adds the Allen CCF ontology as a tab.- Parameters:
meshesOnly- iftrue, only compartments with available meshes are included in the tree- Returns:
- the created
OntologyBrowser.OntologyTab
-
addAllOntologies
public void addAllOntologies()Adds all the default ontologies as tabs. -
addDrosophilaOntology
Adds the Drosophila adult brain ontology (FBbt) as a tab.- Returns:
- the created
OntologyBrowser.OntologyTab
-
addOntology
Adds a custom ontology tab from a nested map. Each key is a parent term and the value is the list of child terms. Anullor empty list means the key is a leaf. The root of the tree is not shown.Example:
Map<String, List<String>> map = new LinkedHashMap<>(); map.put("Cortex", List.of("L1", "L2/3", "L4", "L5", "L6")); map.put("White Matter", List.of("cc", "ic")); browser.addOntology("Histological Landmarks", map);- Parameters:
tabLabel- the tab titlehierarchy- a map of parent term to child terms (single-level)- Returns:
- the created
OntologyBrowser.OntologyTab
-
addDeepOntology
Adds a custom ontology tab built from a deeply nested map. Each key maps to either another map (subtree) ornull(leaf).- Parameters:
tabLabel- the tab titletree- a recursively nested map representing the ontology- Returns:
- the created
OntologyBrowser.OntologyTab
-
getSelectedPaths
Returns the checked selections from all tabs as "::"- delimited hierarchical paths. The root node is excluded from the path.- Returns:
- list of serialized paths, e.g.,
["Isocortex::Visual areas::VISp"]
-
getSelectedLeaves
Returns only the leaf-level names of checked selections (without ancestor prefixes).- Returns:
- list of leaf names
-
getCheckedUserObjects
Returns the checked user objects from all tabs, cast to the given type.- Type Parameters:
T- the expected user-object type- Parameters:
type- the class to cast to- Returns:
- list of checked user objects
-
addSelectionListener
Registers a listener that is notified whenever the checked selection changes in any tab.- Parameters:
listener- the selection listener
-
clearSelection
public void clearSelection()Clears all checked selections across all tabs. -
setPathFormatter
Sets a custom formatter for converting checkedTreePaths into strings. By default, paths are serialized as "::"- delimited hierarchical strings viaserializePath(TreePath).- Parameters:
formatter- the function to apply to each checked tree path- See Also:
-
getTabCount
public int getTabCount()Returns the number of ontology tabs. -
getTab
Returns the tab at the given index.- Parameters:
index- the tab index- Returns:
- the ontology tab
-
showDialog
Shows this browser in a modal dialog and returns the selected paths, ornullif the user cancelled.- Parameters:
parent- the parent component for dialog positioningtitle- the dialog title- Returns:
- the selected hierarchical paths, or
nullif cancelled
-
showModelessDialog
Shows this browser in a modeless (non-modal) dialog for reference browsing. The dialog stays open while the user works in other windows. Includes an info button and a copy-to-clipboard button.- Parameters:
parent- the parent component for initial positioningtitle- the dialog title- Returns:
- the modeless
JDialog
-
showSelectionInfo
Displays an HTML info table for the currently checked compartments. Works with anyBrainAnnotationuser objects (Allen CCF, Drosophila FBbt, etc.).- Parameters:
parent- the parent component for the info dialog
-
copySelectionToClipboard
public void copySelectionToClipboard()Copies the checked terms to the system clipboard. Each term is placed on its own line, formatted as"acronym (id): name". -
serializePath
- Parameters:
treePath- the tree path- Returns:
- the serialized hierarchical string
-