3 The file is used to override JList to create a List with CheckBox item
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.frameworkwizard
.common
.ui
.iCheckBoxList
;
17 import java
.util
.Vector
;
19 import javax
.swing
.JList
;
21 public class ICheckBoxList
extends JList
{
23 /// Define class Serial Version UID
25 private static final long serialVersionUID
= -2843059688070447632L;
27 protected ICheckBoxListCellRenderer cellrenderer
= new ICheckBoxListCellRenderer();
29 protected ICheckBoxListener listener
= new ICheckBoxListener(this);
31 protected ICheckBoxListModel model
= new ICheckBoxListModel();
34 This the default Constructor
37 public ICheckBoxList() {
42 This the override constructor to create checkbox item with input vector
47 public ICheckBoxList(Vector
<ICheckBoxListItem
> items
) {
49 for (int index
= 0; index
< items
.size(); index
++) {
50 model
.addElement(items
.elementAt(index
));
53 this.setCellRenderer(cellrenderer
);
55 this.addMouseListener(listener
);
56 this.addKeyListener(listener
);
60 Set all items of the CheckBoxList component.
65 public void setAllItems(Vector
<String
> items
) {
67 model
.removeAllElements();
68 for (int index
= 0; index
< items
.size(); index
++) {
69 model
.addElement(new ICheckBoxListItem(items
.elementAt(index
)));
75 Get All Checked Items of the CheckBoxList component.
77 @return All Checked Items
79 public Vector
<ICheckBoxListItem
> getAllCheckedItems() {
80 Vector
<ICheckBoxListItem
> result
= new Vector
<ICheckBoxListItem
>();
82 for (int i
= 0; i
< this.getModel().getSize(); i
++) {
83 if (((ICheckBoxListItem
) this.getModel().getElementAt(i
)).isChecked()) {
84 result
.addElement((ICheckBoxListItem
) this.getModel().getElementAt(i
));
91 Get All Checked Items index of the CheckBoxList component.
93 @return All Checked Items index
95 public Vector
<Integer
> getAllCheckedItemsIndex() {
96 Vector
<Integer
> result
= new Vector
<Integer
>();
98 for (int i
= 0; i
< this.getModel().getSize(); i
++) {
99 if (((ICheckBoxListItem
) this.getModel().getElementAt(i
)).isChecked()) {
100 result
.addElement(i
);
107 Get All Checked Items String of the CheckBoxList component.
111 public Vector
<String
> getAllCheckedItemsString() {
112 Vector
<String
> result
= new Vector
<String
>();
114 for (int i
= 0; i
< this.getModel().getSize(); i
++) {
115 if (((ICheckBoxListItem
) this.getModel().getElementAt(i
)).isChecked()) {
116 result
.addElement(((ICheckBoxListItem
) this.getModel().getElementAt(i
)).text
);
123 Get All Items String of the CheckBoxList component.
127 public Vector
<String
> getAllItemsString() {
128 Vector
<String
> result
= new Vector
<String
>();
130 for (int i
= 0; i
< this.getModel().getSize(); i
++) {
131 result
.addElement(((ICheckBoxListItem
) this.getModel().getElementAt(i
)).text
);
137 Set Checked status for all input items.
140 public void initCheckedItem(boolean bool
, Vector
<String
> items
) {
141 if (items
!= null && items
.size() != 0) {
142 for (int indexI
= 0; indexI
< items
.size(); indexI
++) {
143 for (int indexJ
= 0; indexJ
< model
.size(); indexJ
++) {
144 if (items
.elementAt(indexI
).equals(model
.getAllElements().elementAt(indexJ
).getText())) {
145 ICheckBoxListItem listItem
= (ICheckBoxListItem
) model
.get(indexJ
);
146 listItem
.setChecked(bool
);
156 Set all items of the compontent checked
159 public void setAllItemsChecked() {
160 initCheckedItem(true, this.getAllItemsString());
164 Set all items of the compontent unchecked
167 public void setAllItemsUnchecked() {
168 initCheckedItem(false, this.getAllItemsString());
172 Remove all items of list
175 public void removeAllItem() {
176 model
.removeAllElements();