1
2 package org.catacomb.druid.blocks;
3
4 import org.catacomb.druid.build.Context;
5 import org.catacomb.druid.build.GUIPath;
6 import org.catacomb.druid.gui.base.DruListColorRenderer;
7 import org.catacomb.druid.gui.base.DruListProgressRenderer;
8 import org.catacomb.druid.gui.base.DruListQuantityRenderer;
9 import org.catacomb.druid.gui.base.DruPanel;
10 import org.catacomb.druid.gui.edit.DruListPanel;
11 import org.catacomb.druid.gui.edit.DruScrollingListPanel;
12 import org.catacomb.interlish.structure.AddableTo;
13 import org.catacomb.report.E;
14
15
16 import java.util.ArrayList;
17
18 public class ScrollingList extends Panel implements AddableTo {
19
20
21 public String action;
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 DruScrollingListPanel(nrow);
50 }
51
52
53 public void populatePanel(DruPanel dp, Context ctx, GUIPath gpath) {
54
55 DruScrollingListPanel drup = (DruScrollingListPanel)dp;
56 drup.setAction(action);
57
58
59 if (renderer != null) {
60
61
62
63 if (renderer.equals("quantity")) {
64 drup.setCellRenderer(new DruListQuantityRenderer());
65
66 } else if (renderer.equals("progress")) {
67 drup.setCellRenderer(new DruListProgressRenderer());
68
69 } else if (renderer.equals("color")) {
70 drup.setCellRenderer(new DruListColorRenderer());
71
72 } else {
73 E.error("unrecognized renderer " + renderer);
74 }
75 }
76
77 if (multiple) {
78 drup.setMultiple();
79 }
80
81 if (clickAction != null) {
82 if (clickAction.equals("toggle")) {
83 drup.setToggleAction();
84 } else {
85 E.warning("unrecognized action " + clickAction);
86 }
87 }
88
89
90 if (order != null) {
91 if (order.equals("reverse")) {
92 drup.setOrder(DruListPanel.REVERSE_ORDER);
93
94 } else {
95 E.warning("unknown list order " + order + " (only know reverse)");
96 }
97 }
98
99
100 if (clickAreas != null) {
101 for (ListClickArea lca : clickAreas) {
102 drup.addClickAction(lca.makeActor());
103 }
104 }
105
106 }
107
108 }
109
110