]>
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 | |
53 | this.setCellRenderer(cellrenderer);\r | |
54 | this.setModel(model);\r | |
55 | this.addMouseListener(listener);\r | |
56 | this.addKeyListener(listener);\r | |
57 | }\r | |
58 | \r | |
59 | /**\r | |
60 | Set all items of the CheckBoxList component.\r | |
61 | \r | |
62 | @param items\r | |
63 | \r | |
64 | **/\r | |
65 | public void setAllItems(Vector<String> items) {\r | |
66 | if (items != null) {\r | |
67 | model.removeAllElements();\r | |
68 | for (int index = 0; index < items.size(); index++) {\r | |
69 | model.addElement(new ICheckBoxListItem(items.elementAt(index)));\r | |
70 | }\r | |
71 | }\r | |
72 | }\r | |
73 | \r | |
74 | /**\r | |
75 | Get All Checked Items of the CheckBoxList component.\r | |
76 | \r | |
77 | @return All Checked Items\r | |
78 | **/\r | |
79 | public Vector<ICheckBoxListItem> getAllCheckedItems() {\r | |
80 | Vector<ICheckBoxListItem> result = new Vector<ICheckBoxListItem>();\r | |
81 | \r | |
82 | for (int i = 0; i < this.getModel().getSize(); i++) {\r | |
83 | if (((ICheckBoxListItem) this.getModel().getElementAt(i)).isChecked()) {\r | |
84 | result.addElement((ICheckBoxListItem) this.getModel().getElementAt(i));\r | |
85 | }\r | |
86 | }\r | |
87 | return result;\r | |
88 | }\r | |
92e29378 | 89 | \r |
90 | /**\r | |
91 | Get All Checked Items index of the CheckBoxList component.\r | |
92 | \r | |
93 | @return All Checked Items index\r | |
94 | **/\r | |
95 | public Vector<Integer> getAllCheckedItemsIndex() {\r | |
96 | Vector<Integer> result = new Vector<Integer>();\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(i);\r | |
101 | }\r | |
102 | }\r | |
103 | return result;\r | |
104 | }\r | |
a13899c5 | 105 | \r |
106 | /**\r | |
107 | Get All Checked Items String of the CheckBoxList component.\r | |
108 | \r | |
109 | @return Vector\r | |
110 | **/\r | |
111 | public Vector<String> getAllCheckedItemsString() {\r | |
112 | Vector<String> result = new Vector<String>();\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(((ICheckBoxListItem) this.getModel().getElementAt(i)).text);\r | |
117 | }\r | |
118 | }\r | |
119 | return result;\r | |
120 | }\r | |
121 | \r | |
122 | /**\r | |
123 | Get All Items String of the CheckBoxList component.\r | |
124 | \r | |
125 | @return Vector\r | |
126 | **/\r | |
127 | public Vector<String> getAllItemsString() {\r | |
128 | Vector<String> result = new Vector<String>();\r | |
129 | \r | |
130 | for (int i = 0; i < this.getModel().getSize(); i++) {\r | |
131 | result.addElement(((ICheckBoxListItem) this.getModel().getElementAt(i)).text);\r | |
132 | }\r | |
133 | return result;\r | |
134 | }\r | |
135 | \r | |
136 | /**\r | |
137 | Set Checked status for all input items.\r | |
138 | \r | |
139 | **/\r | |
140 | public void initCheckedItem(boolean bool, Vector<String> items) {\r | |
141 | if (items != null && items.size() != 0) {\r | |
142 | for (int indexI = 0; indexI < items.size(); indexI++) {\r | |
143 | for (int indexJ = 0; indexJ < model.size(); indexJ++) {\r | |
144 | if (items.elementAt(indexI).equals(model.getAllElements().elementAt(indexJ).getText())) {\r | |
145 | ICheckBoxListItem listItem = (ICheckBoxListItem) model.get(indexJ);\r | |
146 | listItem.setChecked(bool);\r | |
147 | break;\r | |
148 | }\r | |
149 | }\r | |
150 | }\r | |
151 | }\r | |
152 | this.validate();\r | |
153 | }\r | |
154 | \r | |
155 | /**\r | |
156 | Set all items of the compontent checked\r | |
157 | \r | |
158 | **/\r | |
159 | public void setAllItemsChecked() {\r | |
160 | initCheckedItem(true, this.getAllItemsString());\r | |
161 | }\r | |
162 | \r | |
163 | /**\r | |
164 | Set all items of the compontent unchecked\r | |
165 | \r | |
166 | **/\r | |
167 | public void setAllItemsUnchecked() {\r | |
168 | initCheckedItem(false, this.getAllItemsString());\r | |
169 | }\r | |
170 | \r | |
171 | /**\r | |
172 | Remove all items of list\r | |
173 | \r | |
174 | **/\r | |
175 | public void removeAllItem() {\r | |
176 | model.removeAllElements();\r | |
177 | }\r | |
178 | }\r |