-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathSplitPanel.java
More file actions
executable file
·205 lines (178 loc) · 5.01 KB
/
Copy pathSplitPanel.java
File metadata and controls
executable file
·205 lines (178 loc) · 5.01 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package javaforce.webui;
/** SplitPanel - divides two Panels vertically or horizontally.
*
* @author pquiring
*/
public class SplitPanel extends Panel {
private int dir;
private int pos = 50;
private int side;
private Container div;
private Container t1, t2;
private static final int DIV_SIZE = 5;
/** Create SplitPanel with vertical or horizontal divider.
*
* The divider will control the size of the left/top component.
* The other component will flex as needed.
*
* @param direction = VERTICAL or HORIZONTAL
*/
public SplitPanel(int direction) {
init(direction, direction == VERTICAL ? RIGHT : BOTTOM);
}
/** Create SplitPanel with vertical or horizontal divider.
*
* Based on the flexSide param the divider will control the size of the left/top or bottom/right component.
* The other component will flex as needed.
*
* @param direction = VERTICAL or HORIZONTAL
* @param flexSide = the side that will flex (the divider controls the other component's size)
* VERTICAL = LEFT or RIGHT (Default = RIGHT)
* HORIZONTAL = TOP or BOTTOM (Default = BOTTOM)
*/
public SplitPanel(int direction, int flexSide) {
init(direction, flexSide);
}
private void init(int direction, int flexSide) {
dir = direction;
side = flexSide;
div = new Container();
div.setClass("splitDivider");
div.setBackColor(Color.grey);
switch (dir) {
case VERTICAL:
setClass("splitPanelRow");
t1 = new Panel(); //left component
t1.setMaxHeight();
t1.setVerticalAlign(TOP);
t1.add(new Label("left"));
t2 = new Panel(); //right component
t2.setMaxHeight();
t2.setVerticalAlign(TOP);
t2.add(new Label("right"));
div.setWidth(DIV_SIZE);
div.setMaxHeight();
switch (side) {
case LEFT:
t1.setFlex(true);
// t1.setMaxWidth();
t2.setWidth(pos);
break;
case RIGHT:
t1.setWidth(pos);
t2.setFlex(true);
// t2.setMaxWidth();
break;
}
break;
case HORIZONTAL:
setClass("splitPanelColumn");
t1 = new Panel(); //top component
t1.setMaxWidth();
t1.setVerticalAlign(TOP);
t1.add(new Label("top"));
t2 = new Panel(); //bottom component
t2.setMaxHeight();
t2.setVerticalAlign(TOP);
t2.add(new Label("bottom"));
div.setHeight(DIV_SIZE);
div.setMaxWidth();
switch (side) {
case TOP:
t1.setFlex(true);
// t1.setMaxHeight();
t2.setHeight(pos);
break;
case BOTTOM:
t1.setHeight(pos);
t2.setFlex(true);
// t2.setMaxHeight();
break;
}
break;
}
add(t1); //left/top component
add(div);
add(t2); //right/bottom component
setMaxWidth();
setMaxHeight();
}
public void init() {
super.init();
div.addEvent("onmousedown", "onmousedownSplitPanel("
+ "event,"
+ "this,"
+ "\"" + t1.id + "\","
+ "\"" + div.id + "\","
+ "\"" + t2.id + "\","
+ "\"" + this.id + "\","
+ "\"" + (dir == VERTICAL ? 'v' : 'h') + "\","
+ "\"" + (dir == VERTICAL ? (side == LEFT ? 'l' : 'r') : (side == TOP ? 't' : 'b')) + "\""
+ ");"
);
}
//
public int getDirection() {
return dir;
}
public void setDividerPosition(int pos) {
this.pos = pos;
switch (dir) {
case VERTICAL:
switch (side) {
case LEFT: t2.setWidth(pos); break;
case RIGHT: t1.setWidth(pos); break;
}
break;
case HORIZONTAL:
switch (side) {
case TOP: t2.setHeight(pos); break;
case BOTTOM: t1.setHeight(pos); break;
}
break;
}
}
public int getDividerPosition() {
return pos;
}
public Component getLeftComponent() {
return t1.get(0);
}
public Component getTopComponent() {
return t1.get(0);
}
public Component getRightComponent() {
return t2.get(0);
}
public Component getBottomComponent() {
return t2.get(0);
}
public void setLeftComponent(Component c) {
t1.set(0, c);
this.sendOnResize();
}
public void setTopComponent(Component c) {
t1.set(0, c);
this.sendOnResize();
}
public void setRightComponent(Component c) {
t2.set(0, c);
this.sendOnResize();
}
public void setBottomComponent(Component c) {
t2.set(0, c);
this.sendOnResize();
}
public void onEvent(String event, String[] args) {
switch (event) {
case "dividerpos":
for(String arg : args) {
if (arg.startsWith("pos=")) {
pos = Integer.valueOf(arg.substring(4));
onChanged(null);
}
}
break;
}
}
}