001: package wingset;
002:
003: import org.wings.*;
004: import org.wings.border.SEmptyBorder;
005:
006: import java.awt.*;
007: import java.awt.event.ActionEvent;
008:
009: /**
010: * @author <a href="mailto:B.Schmid@eXXcellent.de">Benjamin Schmid</a>
011: */
012: public class NestingTest extends WingSetPane {
013: private final SComboBox selectComboBox = new SComboBox();
014: private final SPanel mainPanel = new SPanel(new SGridLayout(1, 2,
015: 10, 0));
016: private Color[] colors = new Color[] { Color.red, Color.green,
017: Color.yellow };
018:
019: protected SComponent createControls() {
020: for (int i = 5; i < 30; i++) {
021: selectComboBox.addItem(i);
022: }
023: selectComboBox
024: .addActionListener(new java.awt.event.ActionListener() {
025: public void actionPerformed(ActionEvent e) {
026: update();
027: }
028: });
029: selectComboBox.setSelectedIndex(0);
030: selectComboBox.setHorizontalAlignment(SConstants.LEFT_ALIGN);
031: return selectComboBox;
032: }
033:
034: protected SComponent createExample() {
035: update();
036: return mainPanel;
037: }
038:
039: private void update() {
040: mainPanel.removeAll();
041:
042: SPanel buttonPanel = new SPanel(new SFlowDownLayout());
043: buttonPanel.setBackground(new Color(0xD0, 0xD0, 0xFF));
044: buttonPanel.setPreferredSize(new SDimension(150, -1));
045: buttonPanel.add(createButton(0, "Root"));
046: buttonPanel.add(createButton(1, "Menu 1"));
047: buttonPanel.add(createButton(1, "Menu 2"));
048: buttonPanel.add(createButton(2, "Menu 2a"));
049: buttonPanel.add(createButton(2, "Menu 2b"));
050: buttonPanel.add(createButton(1, "Menu 3"));
051:
052: SPanel labelPanel = new SPanel(new SFlowDownLayout());
053: labelPanel.setBackground(new Color(0xD0, 0xFF, 0xD0));
054: labelPanel.setPreferredSize(new SDimension(150, -1));
055: labelPanel.add(createLabel(0, "Root"));
056: labelPanel.add(createLabel(1, "Menu 1"));
057: labelPanel.add(createLabel(1, "Menu 2"));
058: labelPanel.add(createLabel(2, "Menu 2a"));
059: labelPanel.add(createLabel(2, "Menu 2b"));
060: labelPanel.add(createLabel(1, "Menu 3"));
061:
062: SLabel leftLabel = new SLabel(
063: "Below you will see panels with GridLayout nested into panels.\n"
064: + "You will realize that the browsers stop rendering at a specific level of table nesting.\n"
065: + "(in IE try 9 vs. 10; in FireFox 20 vs. 21");
066: leftLabel.setHorizontalAlignment(LEFT_ALIGN);
067: SPanel nestedPanel = nestPanel(((Integer) selectComboBox
068: .getSelectedItem()).intValue());
069: nestedPanel.setHorizontalAlignment(LEFT_ALIGN);
070:
071: SLabel rightLabel = new SLabel("\nPadding test");
072: rightLabel.setHorizontalAlignment(LEFT_ALIGN);
073: buttonPanel.setHorizontalAlignment(LEFT_ALIGN);
074: labelPanel.setHorizontalAlignment(LEFT_ALIGN);
075:
076: SPanel left = new SPanel(new SBoxLayout(SConstants.VERTICAL));
077: left.add(leftLabel);
078: left.add(nestedPanel);
079:
080: SPanel right = new SPanel(new SBoxLayout(SConstants.VERTICAL));
081: right.add(rightLabel);
082: right.add(buttonPanel);
083: right.add(labelPanel);
084:
085: mainPanel.add(left);
086: mainPanel.add(right);
087: }
088:
089: private SPanel nestPanel(int depth) {
090: SPanel panel = new SPanel(new SGridLayout());
091: panel.add(new SLabel("Depth " + depth));
092: panel.setBackground(colors[depth % colors.length]);
093: panel.setBorder(new SEmptyBorder(20, 20, 20, 20));
094: if (depth > 1)
095: panel.add(nestPanel(depth - 1));
096: return panel;
097: }
098:
099: private SButton createButton(int level, String text) {
100: SButton button = new SButton(text);
101: //button.setShowAsFormComponent(false);
102: button.setBorder(new SEmptyBorder(0, level * 20, 0, 0));
103: return button;
104: }
105:
106: private SLabel createLabel(int level, String text) {
107: SLabel button = new SLabel(text);
108: button.setBorder(new SEmptyBorder(0, level * 20, 0, 0));
109: return button;
110: }
111:
112: }
|