]>
Commit | Line | Data |
---|---|---|
a13899c5 | 1 | /** @file\r |
2 | \r | |
3 | The file is used to override JList to create a List with CheckBox item \r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | package org.tianocore.frameworkwizard.common.ui.iCheckBoxList;\r | |
16 | \r | |
17 | import java.util.Vector;\r | |
18 | \r | |
19 | import javax.swing.JList;\r | |
20 | \r | |
21 | public class ICheckBoxList extends JList {\r | |
22 | ///\r | |
23 | /// Define class Serial Version UID\r | |
24 | ///\r | |
25 | private static final long serialVersionUID = -2843059688070447632L;\r | |
26 | \r | |
27 | protected ICheckBoxListCellRenderer cellrenderer = new ICheckBoxListCellRenderer();\r | |
28 | \r | |
29 | protected ICheckBoxListener listener = new ICheckBoxListener(this);\r | |
30 | \r | |
31 | protected ICheckBoxListModel model = new ICheckBoxListModel();\r | |
32 | \r | |
33 | /**\r | |
34 | This the default Constructor\r | |
35 | \r | |
36 | **/\r | |
37 | public ICheckBoxList() {\r | |
38 | this(null);\r | |
39 | }\r | |
40 | \r | |
41 | /**\r | |
42 | This the override constructor to create checkbox item with input vector\r | |
43 | \r | |
44 | @param options\r | |
45 | \r | |
46 | **/\r | |
47 | public ICheckBoxList(Vector<ICheckBoxListItem> items) {\r | |
48 | if (items != null) {\r | |
49 | for (int index = 0; index < items.size(); index++) {\r | |
50 | model.addElement(items.elementAt(index));\r | |
51 | }\r | |
52 | }\r | |
453a815b | 53 | \r |
54 | //\r | |
55 | // If there exists at least one item, set first item selected.\r | |
56 | //\r | |
57 | if (model.size() > 0) {\r | |
58 | ICheckBoxListItem listItem = (ICheckBoxListItem) model.get(0);\r | |
59 | listItem.setSelected(true);\r | |
60 | }\r | |
a13899c5 | 61 | this.setCellRenderer(cellrenderer);\r |
62 | this.setModel(model);\r | |
63 | this.addMouseListener(listener);\r | |
64 | this.addKeyListener(listener);\r | |
65 | }\r | |
66 | \r | |
67 | /**\r | |
68 | Set all items of the CheckBoxList component.\r | |
69 | \r | |
70 | @param items\r | |
71 | \r | |
72 | **/\r | |
73 | public void setAllItems(Vector<String> items) {\r | |
74 | if (items != null) {\r | |
75 | model.removeAllElements();\r | |
76 | for (int index = 0; index < items.size(); index++) {\r | |
77 | model.addElement(new ICheckBoxListItem(items.elementAt(index)));\r | |
78 | }\r | |
79 | }\r | |
453a815b | 80 | \r |
81 | //\r | |
82 | // If there exists at least one item, set first item selected.\r | |
83 | //\r | |
84 | if (model.size() > 0) {\r | |
85 | ICheckBoxListItem listItem = (ICheckBoxListItem) model.get(0);\r | |
86 | listItem.setSelected(true);\r | |
87 | }\r | |
a13899c5 | 88 | }\r |
89 | \r | |
90 | /**\r | |
91 | Get All Checked Items of the CheckBoxList component.\r | |
92 | \r | |
93 | @return All Checked Items\r | |
94 | **/\r | |
95 | public Vector<ICheckBoxListItem> getAllCheckedItems() {\r | |
96 | Vector<ICheckBoxListItem> result = new Vector<ICheckBoxListItem>();\r | |
97 | \r | |
98 | for (int i = 0; i < this.getModel().getSize(); i++) {\r | |
99 | if (((ICheckBoxListItem) this.getModel().getElementAt(i)).isChecked()) {\r | |
100 | result.addElement((ICheckBoxListItem) this.getModel().getElementAt(i));\r | |
101 | }\r | |
102 | }\r | |
103 | return result;\r | |
104 | }\r | |
92e29378 | 105 | \r |
106 | /**\r | |
107 | Get All Checked Items index of the CheckBoxList component.\r | |
108 | \r | |
109 | @return All Checked Items index\r | |
110 | **/\r | |
111 | public Vector<Integer> getAllCheckedItemsIndex() {\r | |
112 | Vector<Integer> result = new Vector<Integer>();\r | |
113 | \r | |
114 | for (int i = 0; i < this.getModel().getSize(); i++) {\r | |
115 | if (((ICheckBoxListItem) this.getModel().getElementAt(i)).isChecked()) {\r | |
116 | result.addElement(i);\r | |
117 | }\r | |
118 | }\r | |
119 | return result;\r | |
120 | }\r | |
a13899c5 | 121 | \r |
122 | /**\r | |
123 | Get All Checked Items String of the CheckBoxList component.\r | |
124 | \r | |
125 | @return Vector\r | |
126 | **/\r | |
127 | public Vector<String> getAllCheckedItemsString() {\r | |
128 | Vector<String> result = new Vector<String>();\r | |
129 | \r | |
130 | for (int i = 0; i < this.getModel().getSize(); i++) {\r | |
131 | if (((ICheckBoxListItem) this.getModel().getElementAt(i)).isChecked()) {\r | |
132 | result.addElement(((ICheckBoxListItem) this.getModel().getElementAt(i)).text);\r | |
133 | }\r | |
134 | }\r | |
135 | return result;\r | |
136 | }\r | |
137 | \r | |
138 | /**\r | |
139 | Get All Items String of the CheckBoxList component.\r | |
140 | \r | |
141 | @return Vector\r | |
142 | **/\r | |
143 | public Vector<String> getAllItemsString() {\r | |
144 | Vector<String> result = new Vector<String>();\r | |
145 | \r | |
146 | for (int i = 0; i < this.getModel().getSize(); i++) {\r | |
147 | result.addElement(((ICheckBoxListItem) this.getModel().getElementAt(i)).text);\r | |
148 | }\r | |
149 | return result;\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | Set Checked status for all input items.\r | |
154 | \r | |
155 | **/\r | |
156 | public void initCheckedItem(boolean bool, Vector<String> items) {\r | |
157 | if (items != null && items.size() != 0) {\r | |
158 | for (int indexI = 0; indexI < items.size(); indexI++) {\r | |
159 | for (int indexJ = 0; indexJ < model.size(); indexJ++) {\r | |
160 | if (items.elementAt(indexI).equals(model.getAllElements().elementAt(indexJ).getText())) {\r | |
161 | ICheckBoxListItem listItem = (ICheckBoxListItem) model.get(indexJ);\r | |
162 | listItem.setChecked(bool);\r | |
163 | break;\r | |
164 | }\r | |
165 | }\r | |
166 | }\r | |
167 | }\r | |
453a815b | 168 | \r |
169 | //\r | |
170 | // If there exists at least one item, set first item selected.\r | |
171 | //\r | |
172 | if (model.size() > 0) {\r | |
173 | ICheckBoxListItem listItem = (ICheckBoxListItem) model.get(0);\r | |
174 | listItem.setSelected(true);\r | |
175 | }\r | |
176 | \r | |
a13899c5 | 177 | this.validate();\r |
178 | }\r | |
179 | \r | |
180 | /**\r | |
181 | Set all items of the compontent checked\r | |
182 | \r | |
183 | **/\r | |
184 | public void setAllItemsChecked() {\r | |
185 | initCheckedItem(true, this.getAllItemsString());\r | |
186 | }\r | |
187 | \r | |
188 | /**\r | |
189 | Set all items of the compontent unchecked\r | |
190 | \r | |
191 | **/\r | |
192 | public void setAllItemsUnchecked() {\r | |
193 | initCheckedItem(false, this.getAllItemsString());\r | |
194 | }\r | |
195 | \r | |
196 | /**\r | |
197 | Remove all items of list\r | |
198 | \r | |
199 | **/\r | |
200 | public void removeAllItem() {\r | |
201 | model.removeAllElements();\r | |
202 | }\r | |
203 | }\r |