1+ package com .eviware .soapui .ui .navigator ;
2+
3+ import com .eviware .soapui .model .tree .SoapUITreeModel ;
4+
5+ import javax .swing .JTree ;
6+ import java .awt .Insets ;
7+ import java .awt .Point ;
8+ import java .awt .Rectangle ;
9+ import java .awt .dnd .Autoscroll ;
10+
11+ class NavigatorTree extends JTree implements Autoscroll {
12+ public NavigatorTree (SoapUITreeModel treeModel ) {
13+ super (treeModel );
14+ }
15+
16+ private static final int AUTOSCROLL_MARGIN = 12 ;
17+
18+ public void autoscroll (Point pt ) {
19+ // Figure out which row we�re on.
20+ int nRow = getRowForLocation (pt .x , pt .y );
21+
22+ // If we are not on a row then ignore this autoscroll request
23+ if (nRow < 0 ) {
24+ return ;
25+ }
26+
27+ Rectangle raOuter = getBounds ();
28+ // Now decide if the row is at the top of the screen or at the
29+ // bottom. We do this to make the previous row (or the next
30+ // row) visible as appropriate. If we�re at the absolute top or
31+ // bottom, just return the first or last row respectively.
32+
33+ nRow = (pt .y + raOuter .y <= AUTOSCROLL_MARGIN ) // Is row at top of
34+ // screen?
35+ ? (nRow <= 0 ? 0 : nRow - 1 ) // Yes, scroll up one row
36+ : (nRow < getRowCount () - 1 ? nRow + 1 : nRow ); // No,
37+ // scroll
38+ // down one
39+ // row
40+
41+ scrollRowToVisible (nRow );
42+ }
43+
44+ // Calculate the insets for the *JTREE*, not the viewport
45+ // the tree is in. This makes it a bit messy.
46+ public Insets getAutoscrollInsets () {
47+ Rectangle raOuter = getBounds ();
48+ Rectangle raInner = getParent ().getBounds ();
49+ return new Insets (raInner .y - raOuter .y + AUTOSCROLL_MARGIN , raInner .x - raOuter .x + AUTOSCROLL_MARGIN ,
50+ raOuter .height - raInner .height - raInner .y + raOuter .y + AUTOSCROLL_MARGIN , raOuter .width
51+ - raInner .width - raInner .x + raOuter .x + AUTOSCROLL_MARGIN );
52+ }
53+ }
0 commit comments