forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
60 lines
1.5 KiB
package leaf.ui;
|
|
|
|
import java.awt.Insets;
|
|
import java.awt.Point;
|
|
import java.awt.Rectangle;
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
import javax.swing.tree.TreeModel;
|
|
import javax.swing.tree.TreePath;
|
|
|
|
|
|
public abstract class DraggableLeafTree extends LeafTree
|
|
{
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
public DraggableLeafTree( TreeModel model )
|
|
{
|
|
super(model);
|
|
setDragEnabled( true );
|
|
setAutoscrolls( true );
|
|
setDropTarget();
|
|
}
|
|
|
|
public abstract void setDropTarget( );
|
|
|
|
public void autoscroll( Point cursorLocation )
|
|
{
|
|
Insets insets = getAutoscrollInsets();
|
|
Rectangle outer = getVisibleRect();
|
|
Rectangle inner = new Rectangle( outer.x + insets.left, outer.y + insets.top, outer.width - ( insets.left+insets.right ), outer.height - ( insets.top+insets.bottom ) );
|
|
|
|
if ( !inner.contains(cursorLocation ) )
|
|
{
|
|
Rectangle scrollRect = new Rectangle( cursorLocation.x - insets.left, cursorLocation.y - insets.top, insets.left + insets.right, insets.top + insets.bottom );
|
|
scrollRectToVisible(scrollRect);
|
|
}
|
|
}
|
|
|
|
public Insets getAutoscrollInsets()
|
|
{
|
|
return new Insets( 20, 20, 20, 20 );
|
|
}
|
|
|
|
|
|
|
|
public Object getSelectedObject()
|
|
{
|
|
DefaultMutableTreeNode node = getSelectedNode();
|
|
return node == null ? null : node.getUserObject();
|
|
}
|
|
|
|
public DefaultMutableTreeNode getSelectedNode()
|
|
{
|
|
TreePath path = getSelectionPath();
|
|
return path == null ? null : (DefaultMutableTreeNode) path.getLastPathComponent();
|
|
}
|
|
|
|
}
|