1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.widgets;
17
18 import java.awt.Component;
19 import java.awt.Dimension;
20
21 import javax.swing.JComponent;
22 import javax.swing.JSplitPane;
23
24 import org.xulux.api.gui.IWidget;
25 import org.xulux.gui.ContainerWidget;
26
27
28
29
30
31
32
33 public class SplitPane extends ContainerWidget {
34
35
36
37
38 private JSplitPane pane;
39
40
41
42
43 public SplitPane(String name) {
44 super(name);
45 }
46
47
48
49
50 public Object getNativeWidget() {
51 if (!initialized) {
52 initialize();
53 }
54 return this.pane;
55 }
56
57
58
59
60 public void initialize() {
61 if (initialized) {
62 return;
63 }
64 initialized = true;
65 pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
66 initializeChildren();
67
68 pane.setContinuousLayout(true);
69 refresh();
70 }
71
72
73
74
75 public void refresh() {
76 if (isRefreshing()) {
77 return;
78 }
79 if (!initialized) {
80 initialize();
81 }
82 isRefreshing = true;
83 String orientation = getProperty("orientation");
84 if (orientation != null) {
85 if ("horizontal".equalsIgnoreCase(orientation)) {
86 pane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
87 } else if ("vertical".equalsIgnoreCase(orientation)) {
88 pane.setOrientation(JSplitPane.VERTICAL_SPLIT);
89 }
90 }
91 int divLocation = pane.getDividerLocation();
92 try {
93 divLocation = Integer.parseInt(getProperty("dividerlocation"));
94 } catch(NumberFormatException nfe) {
95 }
96 pane.setDividerLocation(divLocation);
97 isRefreshing = false;
98 }
99
100
101
102
103 public Object getGuiValue() {
104 return null;
105 }
106
107
108
109
110 public void focus() {
111
112 }
113
114
115
116
117 public boolean isValueEmpty() {
118 return false;
119 }
120
121
122
123
124 public boolean canContainValue() {
125 return false;
126 }
127
128
129
130
131 private boolean bottomProcessed;
132
133
134
135 private boolean topProcessed;
136
137
138
139 public void addToParent(IWidget widget) {
140 String position = widget.getProperty("pane");
141 JComponent comp = (JComponent) widget.getNativeWidget();
142 int divLocation = 10;
143 try {
144 divLocation = Integer.parseInt(getProperty("dividerlocation"));
145 } catch(NumberFormatException nfe) {
146 }
147 pane.setDividerLocation(divLocation);
148 comp.setMinimumSize(new Dimension(divLocation, 10));
149 if (position == null) {
150 if (!topProcessed) {
151 topProcessed = true;
152 pane.setTopComponent((Component) widget.getNativeWidget());
153 } else if (!bottomProcessed) {
154 bottomProcessed = true;
155 pane.setBottomComponent((Component) widget.getNativeWidget());
156 } else {
157 System.out.println("Ignoring widget " + widget + " since we already have a bottom and top component");
158 }
159 } else if ("bottom".equalsIgnoreCase(position)) {
160 pane.setBottomComponent((Component) widget.getNativeWidget());
161 } else if ("top".equalsIgnoreCase(position)) {
162 pane.setTopComponent((Component) widget.getNativeWidget());
163 }
164 widget.refresh();
165 }
166
167 }