1
2 package org.catacomb.druid.blocks;
3
4 import java.util.ArrayList;
5
6 import org.catacomb.druid.build.Context;
7 import org.catacomb.druid.build.GUIPath;
8 import org.catacomb.druid.gui.base.DruListColorRenderer;
9 import org.catacomb.druid.gui.base.DruListProgressRenderer;
10 import org.catacomb.druid.gui.base.DruListQuantityRenderer;
11 import org.catacomb.druid.gui.base.DruPanel;
12 import org.catacomb.druid.gui.edit.DruListPanel;
13 import org.catacomb.druid.gui.edit.DruScrollingCheckboxListPanel;
14 import org.catacomb.interlish.structure.AddableTo;
15 import org.catacomb.report.E;
16
17 public class ScrollingCheckboxList extends Panel implements AddableTo {
18
19
20 public String action;
21 public String toggleAction;
22 public int nrow;
23
24 public String renderer;
25
26 public String order;
27 public boolean multiple;
28
29 public String clickAction;
30
31 ArrayList<ListClickArea> clickAreas;
32
33
34
35 public void add(Object obj) {
36 if (obj instanceof ListClickArea) {
37 if (clickAreas == null) {
38 clickAreas = new ArrayList<ListClickArea>();
39 }
40 clickAreas.add((ListClickArea)obj);
41 }
42 }
43
44
45 public DruPanel instantiatePanel() {
46 if (nrow == 0) {
47 nrow = 10;
48 }
49 return new DruScrollingCheckboxListPanel(nrow);
50 }
51
52
53 public void populatePanel(DruPanel dp, Context ctx, GUIPath gpath) {
54
55 DruScrollingCheckboxListPanel drup = (DruScrollingCheckboxListPanel)dp;
56 drup.setAction(action);
57 if (toggleAction != null) {
58 drup.setToggleAction(toggleAction);
59 }
60
61 if (renderer != null) {
62
63
64
65 if (renderer.equals("quantity")) {
66 drup.setCellRenderer(new DruListQuantityRenderer());
67
68 } else if (renderer.equals("progress")) {
69 drup.setCellRenderer(new DruListProgressRenderer());
70
71 } else if (renderer.equals("color")) {
72 drup.setCellRenderer(new DruListColorRenderer());
73
74 } else {
75 E.error("unrecognized renderer " + renderer);
76 }
77 }
78
79 if (multiple) {
80 drup.setMultiple();
81 }
82
83 if (clickAction != null) {
84 if (clickAction.equals("toggle")) {
85 drup.setToggleAction();
86 } else {
87 E.warning("unrecognized action " + clickAction);
88 }
89 }
90
91
92 if (order != null) {
93 if (order.equals("reverse")) {
94 drup.setOrder(DruListPanel.REVERSE_ORDER);
95
96 } else {
97 E.warning("unknown list order " + order + " (only know reverse)");
98 }
99 }
100
101
102 if (clickAreas != null) {
103 for (ListClickArea lca : clickAreas) {
104 drup.addClickAction(lca.makeActor());
105 }
106 }
107
108 }
109
110 }
111
112