01: //THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: //CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: //BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: //FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: //OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: //INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: //LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: //EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: //POSSIBILITY OF SUCH DAMAGE.
13: //
14: //Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.applications.designstudio.designtree;
16:
17: import java.awt.Insets;
18: import java.awt.Point;
19: import java.awt.Rectangle;
20: import java.awt.dnd.Autoscroll;
21:
22: import javax.swing.JTree;
23: import javax.swing.tree.DefaultTreeModel;
24:
25: /* Design Tree control class */
26:
27: public class DesignTree extends JTree implements Autoscroll {
28: private int margin = 30;
29:
30: public DesignTree() {
31: super ();
32: }
33:
34: public DesignTree(DefaultTreeModel pModel) {
35: super (pModel);
36: }
37:
38: public void autoscroll(Point p) {
39: int realrow = getRowForLocation(p.x, p.y);
40: if (realrow > -1) {
41: Rectangle outer = getBounds();
42: int newRealrow = (p.y + outer.y <= margin ? realrow < 1 ? 0
43: : realrow - 1
44: : realrow < getRowCount() - 1 ? realrow + 1
45: : realrow);
46: if (newRealrow != realrow)
47: scrollRowToVisible(newRealrow);
48: }
49: }
50:
51: public Insets getAutoscrollInsets() {
52: Rectangle outer = getBounds();
53: Rectangle inner = getParent().getBounds();
54: return new Insets(inner.y - outer.y + margin, inner.x - outer.x
55: + margin, outer.height - inner.height - inner.y
56: + outer.y + margin, outer.width - inner.width - inner.x
57: + outer.x + margin);
58: }
59: }
|