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
91
92
93
94
95
96
97
98
|
package NET.worlds.scape;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.Point;
import java.util.Vector;
class TabbedDisplayPanel extends Panel {
private int count;
private Vector cards = new Vector();
private Vector cardNames = new Vector();
TabbedDisplayPanel() {
this.setLayout(new CardLayout());
}
void addItem(Component c) {
this.insertItem(this.cards.size(), c);
}
void insertItem(int index, Component c) {
String cardName = "" + this.count++;
this.cardNames.insertElementAt(cardName, index);
this.cards.insertElementAt(c, index);
this.add(cardName, c);
this.validate();
this.repaint();
}
void removeItem(int index) {
this.remove((Component)this.cards.elementAt(index));
this.cards.removeElementAt(index);
this.cardNames.removeElementAt(index);
}
@Override
public Component getComponent(int index) {
return (Component)this.cards.elementAt(index);
}
void setChoice(int index) {
((CardLayout)this.getLayout()).show(this, (String)this.cardNames.elementAt(index));
}
@Override
public Insets insets() {
return new Insets(0, 2, 2, 0);
}
@Override
public void paint(Graphics g) {
g.setColor(this.getBackground());
if (this.cards.size() != 0) {
Dimension size = this.size();
vLine(g, 1, 0, size.height);
g.setColor(this.getBackground().brighter());
vLine(g, 0, 0, size.height - 2);
g.setColor(this.getBackground().darker());
hLine(g, 0, size.height - 1, size.width - 1);
vLine(g, size.width - 1, size.height - 1, 0);
hLine(g, 1, size.height - 2, size.width - 2);
vLine(g, size.width - 2, size.height - 2, 0);
} else {
g.fillRect(0, 0, this.size().width, this.size().height);
}
}
private static void vLine(Graphics g, int x1, int y1, int y2) {
g.drawLine(x1, y1, x1, y2);
}
private static void hLine(Graphics g, int x1, int y1, int x2) {
g.drawLine(x1, y1, x2, y1);
}
@Override
public Component locate(int x, int y) {
if (!this.inside(x, y)) {
return null;
} else {
int n = this.countComponents();
for (int i = 0; i < n; i++) {
Component c = this.getComponent(i);
Point loc = c.location();
if (c != null && c.isVisible() && c.inside(x - loc.x, y - loc.y)) {
return c;
}
}
return this;
}
}
}
|