private boolean calculateCueLine(Point p) {
int row = getClosestRowForLocation(p.x, p.y);
Rectangle rowBounds = getRowBounds(row);
if(rowBounds.y + rowBounds.height < p.y) {
row = this.getRowCount();
}
TreePath path = getPathForRow(row);
if(path == null) {
path = new TreePath(mRootNode);
}
if(mTransferNode != null && !new TreePath(mTransferNode.getPath()).isDescendant(path)) {
FavoriteNode last = (FavoriteNode)path.getLastPathComponent();
FavoriteNode pointed = last;
int target = getTargetFor(pointed, p, row);
if(target == -1 || (target == 1 && !isExpanded(new TreePath(pointed.getPath())))) {
if(!last.isRoot()) {
last = (FavoriteNode)last.getParent();
}
}
if(mTarget == 0 && (System.currentTimeMillis() - mDragOverStart) > 1000 && isCollapsed(new TreePath(last.getPath())) && last.getChildCount() > 0) {
expandPath(new TreePath(last.getPath()));
SwingUtilities.invokeLater(new Runnable() {
public void run() {
mTarget = -2;
}
});
}
if(mTargetNode != last || mTarget != target) {
mTargetNode = last;
mTarget = target;
mDragOverStart = System.currentTimeMillis();
this.paintImmediately(mCueLine.getBounds());
int y = row != getRowCount() ? rowBounds.y : rowBounds.y + rowBounds.height;
if(target == -1) {
Rectangle rect = new Rectangle(rowBounds.x,y-1,rowBounds.width,2);
mCueLine.setRect(rect);
}
else if(target == 0) {
Rectangle rect = new Rectangle(rowBounds.x,rowBounds.y,rowBounds.width,rowBounds.height);
mCueLine.setRect(rect);
}
else if(target == 1) {
Rectangle rect= new Rectangle(rowBounds.x,y + rowBounds.height-1,rowBounds.width,2);
if(row == getRowCount()) {
rect = new Rectangle(0,y-1,getWidth(),2);
}
mCueLine.setRect(rect);
}
Graphics2D g2 = (Graphics2D) getGraphics();