01: package xui.samples.carousel.components;
02:
03: import com.xoetrope.swing.XCheckCombo;
04: import com.xoetrope.swing.XCheckList;
05: import javax.swing.JCheckBox;
06: import javax.swing.ListModel;
07: import net.xoetrope.optional.annotation.Find;
08: import net.xoetrope.swing.XLabel;
09: import net.xoetrope.xui.*;
10:
11: /**
12: * A response class for check list page
13: * <p>Copyright: Xoetrope Ltd. (c) 2001-2006</p>
14: * <p>License: see license.txt</p>
15: * <p>$Revision: 1.6 $</p>
16: */
17: public class CheckLists extends XPage {
18: @Find
19: private XCheckCombo checkCombo;
20:
21: private XCheckList attributeTable;
22: private XLabel description;
23: private String[] options = { "Mp3 Player", "CD Player", "Laptop",
24: "Earphones" };
25:
26: public CheckLists() {
27: }
28:
29: public void pageCreated() {
30: attributeTable = (XCheckList) findComponent("resultsTable");
31: description = (XLabel) findComponent("description");
32: checkCombo.setSeparator(",");
33:
34: for (int i = 0; i < options.length; i++) {
35: checkCombo.addItem(options[i]);
36: }
37: }
38:
39: /**
40: * Interact with the table
41: */
42: public void showDescription() {
43: // Count the checked items in the table
44: int selectedItems = 0;
45: Object[] selection = attributeTable.getSelectedValues();
46: ListModel model = attributeTable.getModel();
47: int itemCount = model.getSize();
48: for (int i = 0; i < itemCount; i++) {
49: if (((JCheckBox) model.getElementAt(i)).isSelected())
50: selectedItems++;
51: }
52:
53: String text = "The number of checked list items is: "
54: + selectedItems;
55: // Get the current selection
56: if (selection.length > 0)
57: text += ", and the current items is: "
58: + ((JCheckBox) selection[0]).getText();
59:
60: // Output the text
61: description.setText(text);
62: }
63: }
|