KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > ListExample


1 /*
2  * $Id: ListExample.java,v 1.7 2005/04/08 17:42:26 blueshift 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.*;
19 import javax.swing.event.ListDataListener JavaDoc;
20 import java.awt.*;
21
22 /**
23  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
24  * @version $Revision: 1.7 $
25  */

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 JavaDoc[] createElements() {
107         SLabel color = new SLabel("");
108         color.setForeground(Color.green);
109         color.setText(Color.green.toString());
110
111         Object JavaDoc[] 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 JavaDoc[] 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 JavaDoc getElementAt(int i) {
146                 return values[i];
147             }
148
149             public void addListDataListener(ListDataListener JavaDoc l) {
150             }
151
152             public void removeListDataListener(ListDataListener JavaDoc 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