1 package org.catacomb.druid.swing;
2
3 import java.awt.Color;
4 import java.awt.Rectangle;
5
6 import javax.swing.JComponent;
7 import javax.swing.JScrollPane;
8 import javax.swing.ScrollPaneConstants;
9
10 import org.catacomb.interlish.interact.DComponent;
11
12
13 public final class DScrollPane extends JScrollPane implements DComponent {
14
15 static final long serialVersionUID = 1001;
16
17 int w = 300;
18 int h = 300;
19
20 Color bgcolor;
21
22 boolean sizeSpecified = false;
23
24
25 public DScrollPane() {
26 super();
27 setHorizontalScrollbarNever();
28 setNoBorder();
29 }
30
31
32 public DScrollPane(JComponent jcp) {
33 super(jcp);
34 setNoBorder();
35 }
36
37 public void setTooltip(String s) {
38 setToolTipText(s);
39 }
40
41
42 public void setBg(Color c) {
43 bgcolor = c;
44 getViewport().setBackground(c);
45 setBackground(c);
46
47 }
48
49
50 public void setScrollSize(int w, int h) {
51 this.w = w;
52 this.h = h;
53 super.setSize(w, h);
54 sizeSpecified = true;
55 }
56
57
58 public void setNoBorder() {
59 setBorder(BorderUtil.makeZeroBorder());
60 }
61
62
63 public void scrollToBottom() {
64 JComponent jc = (JComponent)(getViewport().getComponent(0));
65
66 int height = jc.getHeight();
67 jc.scrollRectToVisible(new Rectangle(0, height - 1, 1, height));
68 }
69
70
71
72 public void setViewDComponent(DComponent dcpt) {
73 setViewportView((JComponent)dcpt);
74 }
75
76
77
78
79
80
81
82
83
84
85
86
87 public void setVerticalScrollBarAlways() {
88 setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
89 }
90
91
92 public void setVerticalScrollbarAsNeeded() {
93 setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
94 }
95
96
97 public void setVerticalScrollbarAlways() {
98 setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
99 }
100
101
102 public void setVerticalScrollbarNever() {
103 setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
104 }
105
106
107 public void setHorizontalScrollbarAsNeeded() {
108 setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
109 }
110
111
112 public void setHorizontalScrollbarAlways() {
113 setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
114 }
115
116
117 public void setHorizontalScrollbarNever() {
118 setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
119 }
120
121
122
123 }