001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package wingset;
014:
015: import org.wings.SBorderLayout;
016: import org.wings.SButton;
017: import org.wings.SComboBox;
018: import org.wings.SComponent;
019: import org.wings.SConstants;
020: import org.wings.SDimension;
021: import org.wings.SLabel;
022: import org.wings.SPanel;
023: import org.wings.STabbedPane;
024: import org.wings.STextArea;
025: import org.wings.style.CSSProperty;
026: import org.wings.style.CSSStyleSheet;
027: import org.wings.text.DefaultDocument;
028: import org.wings.text.SDocument;
029:
030: import javax.swing.event.ChangeEvent;
031: import javax.swing.event.ChangeListener;
032: import java.awt.*;
033: import java.awt.event.ActionEvent;
034:
035: /**
036: * Example for STabbedPane.
037: *
038: * @author <a href="mailto:andre@lison.de">Andre Lison</a>
039: * @author <a href="mailto:B.Schmid@eXXcellent.de">Benjamin Schmid</a>
040: */
041: public class TabbedPaneExample extends WingSetPane {
042: private final static int INITIAL_TAB_COUNT = 10;
043: private final static Object[] TAB_PLACEMENTS = new Object[] {
044: new Object[] { "Top", new Integer(SConstants.TOP) },
045: new Object[] { "Left", new Integer(SConstants.LEFT) },
046: new Object[] { "Right", new Integer(SConstants.RIGHT) },
047: new Object[] { "Bottom", new Integer(SConstants.BOTTOM) } };
048: private TabbedPaneControls controls;
049: private STabbedPane tabbedPane;
050: private SDocument logText = new DefaultDocument();
051:
052: protected SComponent createControls() {
053: controls = new TabbedPaneControls();
054: return controls;
055: }
056:
057: protected SComponent createExample() {
058:
059: // Create tabbed pane and tabulators
060: tabbedPane = new STabbedPane();
061: tabbedPane.setPreferredSize(new SDimension("700px", null));
062: for (int i = 0; i < INITIAL_TAB_COUNT; ++i) {
063: addTab();
064: }
065: tabbedPane.setShowAsFormComponent(false);
066: tabbedPane.setEnabledAt(1, false); // disable a tab
067: tabbedPane.addChangeListener(new ChangeListener() {
068: public void stateChanged(ChangeEvent ce) {
069: logText.setText(logText.getText() + "Changed to tab: "
070: + tabbedPane.getSelectedIndex() + "\n");
071: }
072: });
073: controls.addControllable(tabbedPane);
074:
075: SPanel panel = new SPanel(new SBorderLayout(10, 10));
076: panel.add(tabbedPane);
077: return panel;
078: }
079:
080: protected void addTab() {
081: int i = tabbedPane.getTabCount();
082: SPanel panel = new SPanel(new SBorderLayout(10, 10));
083: STextArea textArea = new STextArea(logText, null, 6, 60);
084: textArea.setPreferredSize(SDimension.FULLWIDTH);
085: panel.add(new SLabel("Tab # " + i), SBorderLayout.NORTH);
086: panel.add(textArea, SBorderLayout.CENTER);
087: tabbedPane.add("Tab " + i, panel);
088: }
089:
090: /**
091: * Extended component control for this wingset demo.
092: */
093: private class TabbedPaneControls extends ComponentControls {
094: private int tabCount = INITIAL_TAB_COUNT;
095:
096: public TabbedPaneControls() {
097: widthTextField.setText("700px");
098: final SComboBox placement = new SComboBox(TAB_PLACEMENTS);
099: placement
100: .addActionListener(new java.awt.event.ActionListener() {
101: public void actionPerformed(ActionEvent e) {
102: Object[] objects = (Object[]) placement
103: .getSelectedItem();
104: Integer integer = (Integer) objects[1];
105: tabbedPane.setTabPlacement(integer
106: .intValue());
107: }
108: });
109: placement.setRenderer(new ObjectPairCellRenderer());
110: addControl(new SLabel(" tab placement"));
111: addControl(placement);
112:
113: final SComboBox unselectedTabColor = new SComboBox(COLORS);
114: unselectedTabColor
115: .addActionListener(new java.awt.event.ActionListener() {
116: public void actionPerformed(ActionEvent e) {
117: Color color = (Color) ((Object[]) unselectedTabColor
118: .getSelectedItem())[1];
119: tabbedPane
120: .setAttribute(
121: STabbedPane.SELECTOR_UNSELECTED_TAB,
122: CSSProperty.BACKGROUND_COLOR,
123: CSSStyleSheet
124: .getAttribute(color));
125: }
126: });
127: unselectedTabColor
128: .setRenderer(new ObjectPairCellRenderer());
129: addControl(new SLabel(" unselected tab"));
130: addControl(unselectedTabColor);
131:
132: final SComboBox selectedTabColor = new SComboBox(COLORS);
133: selectedTabColor
134: .addActionListener(new java.awt.event.ActionListener() {
135: public void actionPerformed(ActionEvent e) {
136: Color color = (Color) ((Object[]) selectedTabColor
137: .getSelectedItem())[1];
138: tabbedPane.setAttribute(
139: STabbedPane.SELECTOR_SELECTED_TAB,
140: CSSProperty.BACKGROUND_COLOR,
141: CSSStyleSheet.getAttribute(color));
142: }
143: });
144: selectedTabColor.setRenderer(new ObjectPairCellRenderer());
145: addControl(new SLabel(" selected tab"));
146: addControl(selectedTabColor);
147:
148: final SComboBox disabledTabColor = new SComboBox(COLORS);
149: disabledTabColor
150: .addActionListener(new java.awt.event.ActionListener() {
151: public void actionPerformed(ActionEvent e) {
152: Color color = (Color) ((Object[]) disabledTabColor
153: .getSelectedItem())[1];
154: tabbedPane.setAttribute(
155: STabbedPane.SELECTOR_DISABLED_TAB,
156: CSSProperty.BACKGROUND_COLOR,
157: CSSStyleSheet.getAttribute(color));
158: }
159: });
160: disabledTabColor.setRenderer(new ObjectPairCellRenderer());
161: addControl(new SLabel(" disabled tab"));
162: addControl(disabledTabColor);
163:
164: final SComboBox contentColor = new SComboBox(COLORS);
165: contentColor
166: .addActionListener(new java.awt.event.ActionListener() {
167: public void actionPerformed(ActionEvent e) {
168: Color color = (Color) ((Object[]) contentColor
169: .getSelectedItem())[1];
170: tabbedPane.setAttribute(
171: STabbedPane.SELECTOR_CONTENT,
172: CSSProperty.BACKGROUND_COLOR,
173: CSSStyleSheet.getAttribute(color));
174: }
175: });
176: contentColor.setRenderer(new ObjectPairCellRenderer());
177: addControl(new SLabel(" content"));
178: addControl(contentColor);
179:
180: final SButton addTab = new SButton("add new tab");
181: addTab
182: .addActionListener(new java.awt.event.ActionListener() {
183: public void actionPerformed(ActionEvent e) {
184: addTab();
185: }
186: });
187: addControl(addTab);
188:
189: final SButton removeTab = new SButton("remove selected tab");
190: removeTab
191: .addActionListener(new java.awt.event.ActionListener() {
192: public void actionPerformed(ActionEvent e) {
193: removeTab();
194: }
195: });
196: addControl(removeTab);
197: }
198:
199: protected void removeTab() {
200: int index = tabbedPane.getSelectedIndex();
201: if (index != -1) {
202: tabCount--;
203: tabbedPane.removeTabAt(index);
204: }
205: }
206:
207: }
208: }
|