forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplitPanel.java
More file actions
executable file
·159 lines (138 loc) · 4.09 KB
/
Copy pathSplitPanel.java
File metadata and controls
executable file
·159 lines (138 loc) · 4.09 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package javaforce.webui;
/** SplitPanel - divides two Panels vertically or horizontally.
*
* @author pquiring
*/
public class SplitPanel extends Panel {
private int dir;
private int pos = 50; //pixels of left/top component
private Container div;
private Container t1, t2; //NOTE:table-cells ignore specify sizes
private Container c1, c2;
public static final int VERTICAL = 1;
public static final int HORIZONTAL = 2;
public SplitPanel(int direction) {
dir = direction;
div = new Container();
div.setClass("splitDivider");
div.setBackColor(Color.grey);
switch (dir) {
case VERTICAL:
t1 = new Panel(); //left component
t1.setWidth(pos);
t1.setMaxHeight();
t1.addClass("splitPanelCell");
t1.setVerticalAlign(TOP);
c1 = new Panel();
c1.setWidth(pos);
c1.setMaxHeight();
c1.addClass("block");
c1.add(new Label("left"));
t1.add(c1);
t2 = new Panel(); //right component
t2.setMaxWidth();
t2.setMaxHeight();
t2.addClass("splitPanelCell");
t2.setVerticalAlign(TOP);
c2 = new Panel();
c2.setMaxWidth();
c2.setMaxHeight();
c2.addClass("block");
c2.add(new Label("right"));
t2.add(c2);
div.setWidth(5);
div.setMaxHeight();
break;
case HORIZONTAL:
t1 = new Panel(); //top component
t1.setHeight(pos);
t1.setMaxWidth();
t1.addClass("splitPanelRow");
t1.setVerticalAlign(TOP);
c1 = new Panel();
c1.setHeight(pos);
c1.setMaxWidth();
c1.addClass("block");
c1.add(new Label("top"));
t1.add(c1);
t2 = new Panel(); //bottom component
t2.setMaxWidth();
t2.setMaxHeight();
t2.addClass("splitPanelRow");
t2.setVerticalAlign(TOP);
c2 = new Panel();
c2.setMaxWidth();
c2.setMaxHeight();
c2.addClass("block");
c2.add(new Label("bottom"));
t2.add(c2);
div.setMaxWidth();
div.setHeight(5);
break;
}
add(t1); //left/top component
add(div);
add(t2); //right/bottom component
addClass("splitPanelTop");
setMaxWidth();
setMaxHeight();
}
public void init() {
super.init();
switch(dir) {
case VERTICAL:
div.addEvent("onmousedown", "onmousedownSplitPanel(event, this,\"" + c1.id + "\",\"" + div.id + "\",\"" + c2.id + "\",\"" + this.id + "\", \"v\");");
addEvent("onresize", "onresizeSplitPanelWidth(event, this,\"" + c1.id + "\",\"" + div.id + "\",\"" + c2.id + "\")");
break;
case HORIZONTAL:
div.addEvent("onmousedown", "onmousedownSplitPanel(event, this,\"" + c1.id + "\",\"" + div.id + "\",\"" + c2.id + "\",\"" + this.id + "\", \"h\");");
addEvent("onresize", "onresizeSplitPanelHeight(event, this,\"" + c1.id + "\",\"" + div.id + "\",\"" + c2.id + "\")");
break;
}
}
public int getDirection() {
return dir;
}
public void setDividerPosition(int pos) {
this.pos = pos;
switch (dir) {
case VERTICAL:
t1.setWidth(pos);
c1.setWidth(pos);
getLeftComponent().setWidth(pos);
break;
case HORIZONTAL:
t1.setHeight(pos);
c1.setHeight(pos);
getTopComponent().setHeight(pos);
break;
}
}
public int getDividerPosition() {
return pos;
}
public Component getLeftComponent() {
return c1.get(0);
}
public Component getTopComponent() {
return c1.get(0);
}
public Component getRightComponent() {
return c2.get(0);
}
public Component getBottomComponent() {
return c2.get(0);
}
public void setLeftComponent(Component c) {
c1.set(0, c);
}
public void setTopComponent(Component c) {
c1.set(0, c);
}
public void setRightComponent(Component c) {
c2.set(0, c);
}
public void setBottomComponent(Component c) {
c2.set(0, c);
}
}