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.*;
016:
017: import javax.swing.tree.DefaultTreeModel;
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020:
021: /**
022: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
023: */
024: public class ScrollPaneExample extends WingSetPane {
025: private ScrollPaneControls controls;
026: private STable table;
027: private STree tree;
028: private SList list;
029: private SScrollPane scrollPane;
030:
031: protected SComponent createControls() {
032: controls = new ScrollPaneControls();
033: return controls;
034: }
035:
036: public SComponent createExample() {
037: table = new STable(new TableExample.ROTableModel(15, 42));
038: table.setDefaultRenderer(new TableExample.MyCellRenderer());
039:
040: tree = new STree(new DefaultTreeModel(HugeTreeModel.ROOT_NODE));
041:
042: list = createTestList(42);
043:
044: scrollPane = new SScrollPane(table);
045: scrollPane.setHorizontalExtent(10);
046: scrollPane.setVerticalExtent(20);
047: scrollPane.getHorizontalScrollBar().setBlockIncrement(3);
048: scrollPane.getVerticalScrollBar().setBlockIncrement(3);
049: scrollPane.setVerticalAlignment(SConstants.TOP_ALIGN);
050: scrollPane.setPreferredSize(SDimension.FULLAREA);
051:
052: controls.addControllable(scrollPane);
053: return scrollPane;
054: }
055:
056: protected void showInPane(SComponent comp) {
057: scrollPane.setViewportView(comp);
058: }
059:
060: class ScrollPaneControls extends ComponentControls {
061: public ScrollPaneControls() {
062: String[] scrollables = { "table", "tree", "list" };
063: final SComboBox scrollable = new SComboBox(scrollables);
064: scrollable.addActionListener(new ActionListener() {
065: public void actionPerformed(ActionEvent e) {
066: int newScrollable = scrollable.getSelectedIndex();
067: switch (newScrollable) {
068: case 0:
069: showInPane(table);
070: break;
071: case 1:
072: showInPane(tree);
073: break;
074: case 2:
075: showInPane(list);
076: break;
077: }
078: }
079: });
080:
081: String[] scrollpaneModes = { "scrolling", "complete",
082: "paging" };
083: final SComboBox mode = new SComboBox(scrollpaneModes);
084: mode.addActionListener(new ActionListener() {
085: public void actionPerformed(ActionEvent e) {
086: scrollPane.setMode(mode.getSelectedIndex());
087: scrollPane.setPreferredSize(SDimension.FULLAREA);
088: widthTextField.setText("100%");
089: heightTextField.setText("100%");
090: }
091: });
092:
093: Integer[] horizontalExtents = { new Integer(5),
094: new Integer(10), new Integer(15) };
095: final SComboBox hScrollpaneExtent = new SComboBox(
096: horizontalExtents);
097: hScrollpaneExtent.setSelectedIndex(1);
098: hScrollpaneExtent.addActionListener(new ActionListener() {
099: public void actionPerformed(ActionEvent e) {
100: int extent = ((Integer) hScrollpaneExtent
101: .getSelectedItem()).intValue();
102: scrollPane.setHorizontalExtent(extent);
103: }
104: });
105:
106: Integer[] verticalExtents = { new Integer(10),
107: new Integer(15), new Integer(20) };
108: final SComboBox vScrollpaneExtent = new SComboBox(
109: verticalExtents);
110: vScrollpaneExtent.setSelectedIndex(2);
111: vScrollpaneExtent.addActionListener(new ActionListener() {
112: public void actionPerformed(ActionEvent e) {
113: int extent = ((Integer) vScrollpaneExtent
114: .getSelectedItem()).intValue();
115: scrollPane.setVerticalExtent(extent);
116: }
117: });
118:
119: final SPageScroller horizontalPageScrollerH = new SPageScroller(
120: SPageScroller.HORIZONTAL);
121: horizontalPageScrollerH
122: .setLayoutMode(SPageScroller.HORIZONTAL);
123: final SPageScroller horizontalPageScrollerV = new SPageScroller(
124: SPageScroller.VERTICAL);
125: horizontalPageScrollerV
126: .setLayoutMode(SPageScroller.HORIZONTAL);
127: String[] horizontalScrollBars = { "normal", "page (H)",
128: "page (V)", "null" };
129: final SComboBox hScrollBar = new SComboBox(
130: horizontalScrollBars);
131: hScrollBar.addActionListener(new ActionListener() {
132: public void actionPerformed(ActionEvent e) {
133: int newScrollbar = hScrollBar.getSelectedIndex();
134: switch (newScrollbar) {
135: case 0:
136: scrollPane
137: .setHorizontalScrollBar(new SScrollBar(
138: SScrollBar.HORIZONTAL));
139: break;
140: case 1:
141: scrollPane
142: .setHorizontalScrollBar(horizontalPageScrollerH);
143: break;
144: case 2:
145: scrollPane
146: .setHorizontalScrollBar(horizontalPageScrollerV);
147: break;
148: case 3:
149: scrollPane.setHorizontalScrollBar(null);
150: break;
151: }
152: }
153: });
154:
155: final SPageScroller verticalPageScrollerH = new SPageScroller(
156: SPageScroller.HORIZONTAL);
157: verticalPageScrollerH.setLayoutMode(SPageScroller.VERTICAL);
158: final SPageScroller verticalPageScrollerV = new SPageScroller(
159: SPageScroller.VERTICAL);
160: verticalPageScrollerV.setLayoutMode(SPageScroller.VERTICAL);
161: String[] verticalScrollBars = { "normal", "page (H)",
162: "page (V)", "null" };
163: final SComboBox vScrollBar = new SComboBox(
164: verticalScrollBars);
165: vScrollBar.addActionListener(new ActionListener() {
166: public void actionPerformed(ActionEvent e) {
167: int newScrollbar = vScrollBar.getSelectedIndex();
168: switch (newScrollbar) {
169: case 0:
170: scrollPane.setVerticalScrollBar(new SScrollBar(
171: SScrollBar.VERTICAL));
172: break;
173: case 1:
174: scrollPane
175: .setVerticalScrollBar(verticalPageScrollerH);
176: break;
177: case 2:
178: scrollPane
179: .setVerticalScrollBar(verticalPageScrollerV);
180: break;
181: case 3:
182: scrollPane.setVerticalScrollBar(null);
183: break;
184: }
185: }
186: });
187:
188: String[] horizontalPolicies = { "as needed", "always",
189: "never" };
190: final SComboBox hScrollBarPolicy = new SComboBox(
191: horizontalPolicies);
192: hScrollBarPolicy.addActionListener(new ActionListener() {
193: public void actionPerformed(ActionEvent e) {
194: int newPolicy = hScrollBarPolicy.getSelectedIndex();
195: switch (newPolicy) {
196: case 0:
197: scrollPane
198: .setHorizontalScrollBarPolicy(SScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
199: break;
200: case 1:
201: scrollPane
202: .setHorizontalScrollBarPolicy(SScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
203: break;
204: case 2:
205: scrollPane
206: .setHorizontalScrollBarPolicy(SScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
207: break;
208: }
209: }
210: });
211:
212: String[] verticalPolicies = { "as needed", "always",
213: "never" };
214: final SComboBox vScrollBarPolicy = new SComboBox(
215: verticalPolicies);
216: vScrollBarPolicy.addActionListener(new ActionListener() {
217: public void actionPerformed(ActionEvent e) {
218: int newPolicy = vScrollBarPolicy.getSelectedIndex();
219: switch (newPolicy) {
220: case 0:
221: scrollPane
222: .setVerticalScrollBarPolicy(SScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
223: break;
224: case 1:
225: scrollPane
226: .setVerticalScrollBarPolicy(SScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
227: break;
228: case 2:
229: scrollPane
230: .setVerticalScrollBarPolicy(SScrollPane.VERTICAL_SCROLLBAR_NEVER);
231: break;
232: }
233: }
234: });
235:
236: addControl(new SLabel("scrollable"));
237: addControl(scrollable);
238: addControl(new SLabel(" mode"));
239: addControl(mode);
240: addControl(new SLabel(" extent (H/V)"));
241: addControl(hScrollpaneExtent);
242: addControl(vScrollpaneExtent);
243: addControl(new SLabel(" scrollbar (H/V)"));
244: addControl(hScrollBar);
245: addControl(vScrollBar);
246: addControl(new SLabel(" policy (H/V)"));
247: addControl(hScrollBarPolicy);
248: addControl(vScrollBarPolicy);
249: }
250: }
251:
252: private SList createTestList(int rows) {
253: String[] modelData = new String[rows];
254: for (int i = 0; i < rows; ++i) {
255: modelData[i] = "This is list item number " + (i + 1);
256: }
257:
258: SList testList = new SList(new SDefaultListModel(modelData));
259: testList.setShowAsFormComponent(false);
260:
261: return testList;
262: }
263:
264: }
|