Normand Briere
2019-09-15 d5fac992bb6a91e52a90e8318060f5f26ddab982
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
/**/
import java.awt.*;
import java.awt.dnd.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.event.*;
 
class cTree extends JTree implements Autoscroll //, DragGestureListener
{
    JPopupMenu popup = new JPopupMenu();
 
    public cTree() // TreeModel newModel)
    {
        //super(newModel);
 
        //setRootVisible(false);
 
        addMouseListener(new MouseAdapter()
        {
            public void mousePressed(MouseEvent e)
            {
                //if (e.isPopupTrigger()) // Works only on mouse released on Windows.
                if (e.getModifiers() == InputEvent.BUTTON3_MASK)
                {
                    int row = getClosestRowForLocation(e.getX(), e.getY());
                    if (!isRowSelected(row))
                        setSelectionRow(row);
                    popup.show((JComponent) e.getSource(), e.getX(), e.getY());
                }
            }
        });
    }
 
    /*
    public void dragGestureRecognized(DragGestureEvent dge)
    {
    System.out.println("DGFGDFJDFJGDSFGJSDFGJDSFGJSDFGJF  ------------------ " + dge);
    }
     */
    protected void processKeyEvent(java.awt.event.KeyEvent e)
    {
        //System.out.println("KEY PRESSED");
        Globals.theRenderer.processKeyEvent(e);
    }
    private int margin = 12;
 
//    public AutoScrollingJTree(TreeModel tm) {
//      super(tm);
//    }
    public void autoscroll(Point p)
    {
        int realrow = getRowForLocation(p.x, p.y);
        Rectangle outer = getBounds();
        realrow = (p.y + outer.y <= margin ? realrow < 1 ? 0 : realrow - 1
                : realrow < getRowCount() - 1 ? realrow + 1 : realrow);
        scrollRowToVisible(realrow);
    }
 
    public Insets getAutoscrollInsets()
    {
        Rectangle outer = getBounds();
        Rectangle inner = getParent().getBounds();
        return new Insets(inner.y - outer.y + margin, inner.x - outer.x + margin, outer.height - inner.height - inner.y + outer.y + margin, outer.width - inner.width - inner.x + outer.x + margin);
    }
//@Override
//public void mouseClicked(java.awt.event.MouseEvent e) {
//
//    if (SwingUtilities.isRightMouseButton(e)) {
//
//        int row = getClosestRowForLocation(e.getX(), e.getY());
//        setSelectionRow(row);
//        popupMenu.show(e.getComponent(), e.getX(), e.getY());
//    }
//}
// Use this method if you want to see the boundaries of the
    // autoscroll active region
 
    /* bug
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Rectangle outer = getBounds();
    Rectangle inner = getParent().getBounds();
    g.setColor(Color.red);
    g.drawRect(-outer.x + 12, -outer.y + 12, inner.width - 24,
    inner.height - 24);
    }
    /**/
}
/**/