01: package wingset;
02:
03: import org.wings.*;
04: import org.wings.border.SEmptyBorder;
05: import org.wingx.XScrollablePanel;
06:
07: import java.awt.*;
08: import java.awt.event.ActionEvent;
09:
10: /**
11: * @author <a href="mailto:B.Schmid@eXXcellent.de">Benjamin Schmid</a>
12: */
13: public class XScrollablePanelTest extends WingSetPane {
14: private final SComboBox selectComboBox = new SComboBox();
15: private final SPanel mainPanel = new SPanel(new SGridLayout(1, 2,
16: 10, 0));
17: private Color[] colors = new Color[] { Color.red, Color.green,
18: Color.yellow };
19:
20: protected SComponent createControls() {
21: for (int i = 2; i < 10; i++) {
22: selectComboBox.addItem(new Integer(i));
23: }
24: selectComboBox
25: .addActionListener(new java.awt.event.ActionListener() {
26: public void actionPerformed(ActionEvent e) {
27: update();
28: }
29: });
30: selectComboBox.setSelectedIndex(0);
31: selectComboBox.setHorizontalAlignment(SConstants.LEFT_ALIGN);
32: return selectComboBox;
33: }
34:
35: protected SComponent createExample() {
36: update();
37: return mainPanel;
38: }
39:
40: private void update() {
41: mainPanel.removeAll();
42: SPanel nestedPanel = nestPanel((Integer) selectComboBox
43: .getSelectedItem());
44: mainPanel.add(nestedPanel);
45: }
46:
47: private SPanel nestPanel(int depth) {
48: SPanel panel = new SPanel(new SGridLayout());
49: panel.add(new SLabel("Depth " + depth));
50: panel.setBackground(colors[depth % colors.length]);
51: panel.setBorder(new SEmptyBorder(20, 20, 20, 20));
52: if (depth > 1)
53: panel.add(nestPanel(depth - 1));
54: return panel;
55: }
56:
57: public SScrollPane addScrollable(final SComponent component,
58: final int height) {
59: XScrollablePanel panel = new XScrollablePanel(component);
60: panel.setPreferredSize(SDimension.FULLWIDTH);
61: return panel.asScrollPane();
62: }
63: }
|