public TreePath getPathClosestTo(final int x, final int y) { if (getStateRoot() == null) { return null; } if (isFixedRowHeight()) { return getFixedHeightPathClosestToImpl(x, y); } if (!getStateRoot().isExpanded()) { return isRootVisible() ? getStateRoot().getModelPath() : null; } int cummulativeHeight = 0; VariableHeightStateNode currentParent = (VariableHeightStateNode) getStateRoot(); if (isRootVisible()) { if (currentParent.getHeight() > y) { return currentParent.getModelPath(); } cummulativeHeight += currentParent.getHeight(); } while (true) { int modelChildCount = currentParent.getModelChildCount(); if (modelChildCount == 0) { return currentParent.getModelPath(); } for (int i = 0; i < modelChildCount; i++) { if (cummulativeHeight + currentParent.getChildrenHeights()[i] > y || i + 1 == modelChildCount) { Object modelChild = currentParent.getModelChildNode(i); VariableHeightStateNode childNode = (VariableHeightStateNode) currentParent.getChild(modelChild); if (childNode != null) { currentParent = childNode; if (cummulativeHeight + currentParent.getHeight() > y || !currentParent.isExpanded()) { return currentParent.getModelPath(); } cummulativeHeight += currentParent.getHeight(); break; } return currentParent.getModelPath().pathByAddingChild(modelChild); } cummulativeHeight += currentParent.getChildrenHeights()[i]; } } }
public Rectangle getBounds(final TreePath path, final Rectangle placeIn) { if (!isRoot(path) && !isVisible(path)) { return null; } if (isFixedRowHeight()) { return getFixedHeightBoundsImpl(path, placeIn); } if (getNodeDimensions() == null) { return new Rectangle(); } if (isRoot(path)) { Rectangle result = getNodeDimensions( getStateRoot().getModelNode(), isRootVisible() ? 0 : -1, 0, getStateRoot().isExpanded(), placeIn); result.y = 0; return result; } VariableHeightStateNode parentNode = (VariableHeightStateNode) getStateNodeForPath(path.getParentPath()); StateNode node = parentNode.getChild(path.getLastPathComponent()); Rectangle result = getNodeDimensions( path.getLastPathComponent(), getRowForPath(path), getPathDepth(path), node != null && node.isExpanded(), placeIn); result.y = 0; Object currentModelNode = path.getLastPathComponent(); while (parentNode != null) { if (!parentNode.isRoot() || isRootVisible()) { result.y += parentNode.getHeight(); } if (parentNode.isExpanded()) { int modelIndex = parentNode.getModelIndexOfChild(currentModelNode); for (int i = 0; i < modelIndex; i++) { result.y += parentNode.getChildrenHeights()[i]; } } currentModelNode = parentNode.getModelNode(); parentNode = (VariableHeightStateNode) parentNode.getParent(); } return result; }