1 14 package wingset; 15 16 import org.wings.*; 17 18 import javax.swing.tree.TreeNode ; 19 import java.awt.*; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 import java.awt.event.ItemEvent ; 23 import java.awt.event.ItemListener ; 24 import java.util.ArrayList ; 25 26 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 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 node, ArrayList list, int indent) { 65 if (node != null) { 66 StringBuffer name = new StringBuffer (); 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 [] listData = createData(); 79 80 static Object [] createData() { 81 TreeNode root = HugeTreeModel.generateTree(); 82 83 ArrayList data = new ArrayList (); 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 [] visRowsValues = {new Integer (4), new Integer (8), new Integer (12), 94 new Integer (16), new Integer (20), new Integer (50)}; 95 final SComboBox visRows = new SComboBox(visRowsValues); 96 visRows.addItemListener(new ItemListener () { 97 public void itemStateChanged(ItemEvent e) { 98 list.setVisibleRowCount(((Integer ) visRows.getSelectedItem()).intValue()); 99 } 100 }); 101 visRows.setSelectedItem(new Integer (list.getVisibleRowCount())); 102 add(visRows); 103 104 add(new SLabel("Direct Pages: ")); 105 Object [] values = {new Integer (5), new Integer (10), new Integer (15), 106 new Integer (20), new Integer (50)}; 107 final SComboBox comboBox = new SComboBox(values); 108 comboBox.addItemListener(new ItemListener () { 109 public void itemStateChanged(ItemEvent e) { 110 scrollbar.setDirectPages(((Integer ) comboBox.getSelectedItem()).intValue()); 111 } 112 }); 113 comboBox.setSelectedItem(new Integer (scrollbar.getDirectPages())); 114 add(comboBox); 115 116 117 add(new SLabel("Layout: ")); 118 Object [] constraints = {"Top", "Left", "Bottom", "Right"}; 119 final SComboBox layout = new SComboBox(constraints); 120 layout.addItemListener(new ItemListener () { 121 public void itemStateChanged(ItemEvent 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 () { 147 public void actionPerformed(ActionEvent 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 () { 156 public void actionPerformed(ActionEvent 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 () { 165 public void actionPerformed(ActionEvent 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 |