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