KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > PageScrollerExample


1 /*
2  * $Id: PageScrollerExample.java,v 1.8 2005/01/11 17:41:18 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16 import org.wings.*;
17
18 import javax.swing.tree.TreeNode JavaDoc;
19 import java.awt.*;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22 import java.awt.event.ItemEvent JavaDoc;
23 import java.awt.event.ItemListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25
26 /**
27  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
28  * @version $Revision: 1.8 $
29  */

30 public class PageScrollerExample
31         extends WingSetPane {
32
33     SList list;
34     SPageScroller scrollbar;
35     SScrollPane scrollPane;
36     private PageScrollerControls controls;
37
38     public SComponent createExample() {
39         list = new SList(listData);
40         list.setVisibleRowCount(8);
41         list.setShowAsFormComponent(false);
42
43         scrollbar = new SPageScroller(Adjustable.VERTICAL);
44         scrollbar.setName("scrollbar");
45
46         // its a horizontal scrollbar, but scrolls vertical...
47
scrollbar.setLayoutMode(Adjustable.HORIZONTAL);
48         scrollbar.setDirectPages(10);
49
50         scrollPane = new SScrollPane(list);
51         scrollPane.setHorizontalScrollBar(null);
52         scrollPane.setVerticalScrollBar(null);
53         scrollPane.setVerticalExtent(50);
54
55         controls = new PageScrollerControls();
56         controls.addSizable(scrollPane);
57
58         SForm form = new SForm(new SBorderLayout());
59         form.add(controls, SBorderLayout.NORTH);
60         form.add(scrollPane, SBorderLayout.CENTER);
61         return form;
62     }
63
64     static void addChildNodes(TreeNode JavaDoc node, ArrayList JavaDoc list, int indent) {
65         if (node != null) {
66             StringBuffer JavaDoc name = new StringBuffer JavaDoc();
67             for (int i = 0; i < indent; i++) {
68                 name.append(".");
69             }
70             name.append(node.toString());
71             list.add(name.toString());
72             for (int i = 0; i < node.getChildCount(); i++) {
73                 addChildNodes(node.getChildAt(i), list, indent + 1);
74             }
75         }
76     }
77
78     static Object JavaDoc[] listData = createData();
79
80     static Object JavaDoc[] createData() {
81         TreeNode JavaDoc root = HugeTreeModel.generateTree();
82
83         ArrayList JavaDoc data = new ArrayList JavaDoc();
84         addChildNodes(root, data, 0);
85
86         return data.toArray();
87     }
88
89
90     class PageScrollerControls extends ComponentControls {
91         public PageScrollerControls() {
92             add(new SLabel("Visible Rows: "));
93             Object JavaDoc[] visRowsValues = {new Integer JavaDoc(4), new Integer JavaDoc(8), new Integer JavaDoc(12),
94                                       new Integer JavaDoc(16), new Integer JavaDoc(20), new Integer JavaDoc(50)};
95             final SComboBox visRows = new SComboBox(visRowsValues);
96             visRows.addItemListener(new ItemListener JavaDoc() {
97                 public void itemStateChanged(ItemEvent JavaDoc e) {
98                     list.setVisibleRowCount(((Integer JavaDoc) visRows.getSelectedItem()).intValue());
99                 }
100             });
101             visRows.setSelectedItem(new Integer JavaDoc(list.getVisibleRowCount()));
102             add(visRows);
103
104             add(new SLabel("Direct Pages: "));
105             Object JavaDoc[] values = {new Integer JavaDoc(5), new Integer JavaDoc(10), new Integer JavaDoc(15),
106                                new Integer JavaDoc(20), new Integer JavaDoc(50)};
107             final SComboBox comboBox = new SComboBox(values);
108             comboBox.addItemListener(new ItemListener JavaDoc() {
109                 public void itemStateChanged(ItemEvent JavaDoc e) {
110                     scrollbar.setDirectPages(((Integer JavaDoc) comboBox.getSelectedItem()).intValue());
111                 }
112             });
113             comboBox.setSelectedItem(new Integer JavaDoc(scrollbar.getDirectPages()));
114             add(comboBox);
115
116
117             add(new SLabel("Layout: "));
118             Object JavaDoc[] constraints = {"Top", "Left", "Bottom", "Right"};
119             final SComboBox layout = new SComboBox(constraints);
120             layout.addItemListener(new ItemListener JavaDoc() {
121                 public void itemStateChanged(ItemEvent JavaDoc e) {
122                     if ("Top".equals(layout.getSelectedItem())) {
123                         scrollbar.setLayoutMode(Adjustable.HORIZONTAL);
124                         scrollPane.setHorizontalScrollBar(scrollbar,
125                                 SScrollPaneLayout.NORTH);
126                     } else if ("Bottom".equals(layout.getSelectedItem())) {
127                         scrollbar.setLayoutMode(Adjustable.HORIZONTAL);
128                         scrollPane.setHorizontalScrollBar(scrollbar,
129                                 SScrollPaneLayout.SOUTH);
130                     } else if ("Left".equals(layout.getSelectedItem())) {
131                         scrollbar.setLayoutMode(Adjustable.VERTICAL);
132                         scrollPane.setHorizontalScrollBar(scrollbar,
133                                 SScrollPaneLayout.WEST);
134                     } else if ("Right".equals(layout.getSelectedItem())) {
135                         scrollbar.setLayoutMode(Adjustable.VERTICAL);
136                         scrollPane.setHorizontalScrollBar(scrollbar,
137                                 SScrollPaneLayout.EAST);
138                     }
139                 }
140             });
141             layout.setSelectedItem("Bottom");
142             add(layout);
143
144
145             final SCheckBox margin = new SCheckBox("Margin");
146             margin.addActionListener(new ActionListener JavaDoc() {
147                 public void actionPerformed(ActionEvent JavaDoc e) {
148                     scrollbar.setMarginVisible(margin.isSelected());
149                 }
150             });
151             margin.setSelected(scrollbar.isMarginVisible());
152             add(margin);
153
154             final SCheckBox step = new SCheckBox("Step");
155             step.addActionListener(new ActionListener JavaDoc() {
156                 public void actionPerformed(ActionEvent JavaDoc e) {
157                     scrollbar.setStepVisible(step.isSelected());
158                 }
159             });
160             step.setSelected(scrollbar.isStepVisible());
161             add(step);
162
163             final SCheckBox paging = new SCheckBox("Paged Scrolling");
164             paging.addActionListener(new ActionListener JavaDoc() {
165                 public void actionPerformed(ActionEvent JavaDoc e) {
166                     boolean selected = paging.isSelected();
167                     ((SScrollPaneLayout)scrollPane.getLayout()).setPaging(selected);
168                 }
169             });
170             paging.setSelected(true);
171             add(paging);
172         }
173     }
174 }
175
Popular Tags