JAL-1807 update
[jalviewjs.git] / src / javajs / swing / JSplitPane.java
1 package javajs.swing;
2
3 import javajs.awt.Container;
4 import javajs.util.SB;
5
6 public class JSplitPane extends JComponent {
7
8         public static final int HORIZONTAL_SPLIT = 1;
9         boolean isH = true;
10         private int split = 1;
11         private Container right;
12         private Container left;
13
14         public JSplitPane(int split) {
15                 super("JSpP");
16                 this.split = split;
17                 isH = (split == HORIZONTAL_SPLIT);
18         }
19         
20         public void setRightComponent(JComponent r) {
21                 right = new JComponentImp(null);
22                 right.add(r); 
23         }
24
25         public void setLeftComponent(JComponent l) {
26                 left = new JComponentImp(null);
27                 left.add(l);
28         }
29
30         @Override
31         public int getSubcomponentWidth() {
32                 int w = this.width;
33                 if (w == 0) {
34                         int wleft = left.getSubcomponentWidth();
35                         int wright = right.getSubcomponentWidth();
36                         if (wleft > 0 && wright > 0) {
37                                 if (isH)
38                                         w = wleft + wright;
39                                 else
40                                         w = Math.max(wleft, wright);
41                         }
42                 }
43                 return w;
44         }
45         
46         @Override
47         public int getSubcomponentHeight() {
48                 int h = this.height;
49                 if (h == 0) {
50                         int hleft = left.getSubcomponentHeight();
51                         int hright = right.getSubcomponentHeight();
52                         if (hleft > 0 && hright > 0) {
53                                 if (isH)
54                                         h = Math.max(hleft, hright);
55                                 else
56                                         h = hleft + hright;
57                         }
58                 }
59                 return h;
60         }
61         
62         @Override
63         public String toHTML() {
64                 if (left == null || right == null)
65                         return "";
66                 boolean isH = (split == HORIZONTAL_SPLIT);
67                 if (width == 0)
68                   width = getSubcomponentWidth();
69                 if (height == 0)
70                   height = getSubcomponentHeight();
71                 SB sb = new SB();
72                 sb.append("<div id='" + id + "' class='JSplitPane' style='" + getCSSstyle(100, 100) + "'>");
73                 if (isH) 
74                         sb.append("<div id='" + id + "_left' style='width:50%;height:100%;position:absolute;top:0%;left:0%'>");
75                 else
76                         sb.append("<div id='" + id + "_top' style='width:100%;height:50%;position:absolute;top:0%;left:0%'>");
77                 sb.append(left.getComponents()[0].toHTML());
78                 if (isH) 
79                         sb.append("</div><div id='" + id + "_right' style='width:50%;height:100%;position:absolute;top:0%;left:50%'>");
80                 else
81                         sb.append("</div><div id='" + id + "_bottom' style='width:100%;height:50%;position:absolute;top:50%;left:0%'>");
82                 sb.append(right.getComponents()[0].toHTML());
83                 sb.append("</div></div>\n");
84                 return sb.toString();
85         }
86
87
88 }