1 14 package wingset; 15 16 import org.wings.*; 17 18 import javax.swing.*; 19 import javax.swing.event.ListDataListener ; 20 import java.awt.*; 21 22 26 public class ListExample 27 extends WingSetPane { 28 static final SResourceIcon javaCup = new SResourceIcon("org/wings/icons/JavaCup.gif"); 29 private ComponentControls controls; 30 31 public SComponent createExample() { 32 controls = new ComponentControls(); 33 34 SPanel p = new SPanel(new SGridLayout(2, 2)); 35 p.add(createListSingleSelExample()); 36 p.add(createListMultSelExample()); 37 p.add(createComboBoxExample()); 38 p.add(createAnchorListExample()); 39 40 SForm form = new SForm(new SBorderLayout()); 41 form.add(controls, SBorderLayout.NORTH); 42 form.add(p, SBorderLayout.CENTER); 43 form.add(new SButton("SUBMIT"), SBorderLayout.SOUTH); 44 return form; 45 } 46 47 public SContainer createListSingleSelExample() { 48 SContainer cont = new SPanel(new SFlowDownLayout()); 49 cont.add(new SLabel("List with single selection")); 50 SList sinlgeSelectionList = new SList(); 51 sinlgeSelectionList.setName("single"); 52 sinlgeSelectionList.setSelectionMode(SList.SINGLE_SELECTION); 53 addListElements(sinlgeSelectionList); 54 cont.add(sinlgeSelectionList); 55 controls.addSizable(sinlgeSelectionList); 56 57 return cont; 58 } 59 60 public SContainer createListMultSelExample() { 61 SContainer cont = new SPanel(new SFlowDownLayout()); 62 cont.add(new SLabel("List with multiple selection")); 63 SList multiSelectionList = new SList(); 64 multiSelectionList.setName("multiple"); 65 multiSelectionList.setSelectionMode(SList.MULTIPLE_SELECTION); 66 addListElements(multiSelectionList); 67 cont.add(multiSelectionList); 68 controls.addSizable(multiSelectionList); 69 70 return cont; 71 } 72 73 public SContainer createComboBoxExample() { 74 SContainer cont = new SPanel(new SFlowDownLayout()); 75 cont.add(new SLabel("ComboBox")); 76 SComboBox comboBox = new SComboBox(); 77 comboBox.setName("combo"); 78 addComboBoxElements(comboBox); 79 cont.add(comboBox); 80 81 return cont; 82 } 83 84 public SContainer createAnchorListExample() { 85 SContainer cont = new SPanel(new SFlowDownLayout()); 86 cont.add(new SLabel("List with showAsFormComponent = false")); 87 SList anchorList = new SList(); 88 anchorList.setName("noform"); 89 anchorList.setShowAsFormComponent(false); 90 anchorList.setSelectionMode(SList.SINGLE_SELECTION); 91 addAnchorElements(anchorList); 92 cont.add(anchorList); 93 controls.addSizable(anchorList); 94 95 return cont; 96 } 97 98 public void addListElements(SList list) { 99 list.setListData(createElements()); 100 } 101 102 public void addComboBoxElements(SComboBox comboBox) { 103 comboBox.setModel(new DefaultComboBoxModel(createElements())); 104 } 105 106 public static Object [] createElements() { 107 SLabel color = new SLabel(""); 108 color.setForeground(Color.green); 109 color.setText(Color.green.toString()); 110 111 Object [] values = { 112 "element1", 113 color, 114 "element3", 115 "element4", 116 "element5", 117 "element6" 118 }; 119 120 return values; 121 } 122 123 public static ListModel createListModel() { 124 final SLabel img = 125 new SLabel(javaCup); 126 127 final SLabel color = new SLabel(""); 128 color.setForeground(Color.green); 129 color.setText(Color.green.toString()); 130 131 ListModel listModel = new ListModel() { 132 Object [] values = { 133 "element1", 134 color, 135 img, 136 "element4", 137 "element5", 138 "element6" 139 }; 140 141 public int getSize() { 142 return values.length; 143 } 144 145 public Object getElementAt(int i) { 146 return values[i]; 147 } 148 149 public void addListDataListener(ListDataListener l) { 150 } 151 152 public void removeListDataListener(ListDataListener l) { 153 } 154 }; 155 156 return listModel; 157 } 158 159 private final ListModel listModel = createListModel(); 160 161 public void addAnchorElements(SList list) { 162 final SLabel img = new SLabel(javaCup); 163 164 final SLabel color = new SLabel(""); 165 color.setForeground(Color.green); 166 color.setText(Color.green.toString()); 167 168 list.setModel(listModel); 169 list.setType(SList.ORDER_TYPE_NORMAL); 170 } 171 } 172 | Popular Tags |