1 package org.catacomb.druid.blocks;
2
3 import org.catacomb.datalish.SColor;
4 import org.catacomb.druid.build.Context;
5 import org.catacomb.druid.build.GUIPath;
6 import org.catacomb.druid.build.Realizer;
7 import org.catacomb.druid.gui.base.DruPanel;
8 import org.catacomb.druid.gui.edit.Effect;
9 import org.catacomb.interlish.structure.IDd;
10 import org.catacomb.report.E;
11
12
13 import java.awt.Color;
14 import java.util.ArrayList;
15
16
17
18 public abstract class Panel implements Realizer, IDd {
19
20
21 public String id;
22 public String title;
23
24 public String tip;
25 public String info;
26
27
28 public String border;
29
30 public int borderWidth;
31
32 public int paddingLeft;
33 public int paddingRight;
34 public int paddingTop;
35 public int paddingBottom;
36
37 public int prefWidth;
38 public int prefHeight;
39
40
41 public String borderTitle;
42
43 public SColor backgroundColor;
44
45 static int panelcount = 0;
46
47
48 public Panel() {
49 paddingLeft = 0;
50 paddingRight = 0;
51 paddingTop = 0;
52 paddingBottom = 0;
53
54 panelcount += 1;
55 }
56
57
58 public String getID() {
59 return id;
60 }
61
62
63 public final Object realize(Context ctx, GUIPath gpathin) {
64 GUIPath gpath = gpathin;
65 gpath = gpath.extend(id);
66
67
68 DruPanel drup = instantiatePanel();
69
70 if (backgroundColor != null) {
71 drup.setBackgroundColor(backgroundColor.getColor());
72
73 } else {
74 backgroundColor = new SColor(ctx.getBg());
75 drup.setFallbackBackgroundColor(ctx.getBg());
76 }
77
78
79
80 populatePanel(drup, ctx, gpath);
81
82 apply(drup, ctx);
83
84 ctx.addComponent(drup, gpath);
85
86 return drup;
87 }
88
89
90 public abstract DruPanel instantiatePanel();
91
92 public abstract void populatePanel(DruPanel drup, Context ctx, GUIPath gpath);
93
94
95
96
97 private void apply(DruPanel drup, Context ctx) {
98 drup.setFallbackBackgroundColor(ctx.getBg());
99 drup.setFallbackForegroundColor(ctx.getFg());
100
101 if (id != null && id.length() > 0) {
102 drup.setID(id);
103 }
104
105 if (prefWidth > 0 || prefHeight > 0) {
106 if (prefHeight == 0) {
107 prefHeight = prefWidth;
108 }
109 if (prefWidth == 0) {
110 prefWidth = prefHeight;
111 }
112
113 drup.setPreferredSize(prefWidth, prefHeight);
114 }
115
116 applyBorder(drup, ctx);
117
118 if (title != null) {
119 drup.setTitle(title);
120 }
121 drup.setTip(tip);
122 drup.setInfo(info);
123
124
125 drup.setInfoReceiver(ctx.getInfoAggregator());
126
127 drup.postApply();
128 }
129
130
131 private final void applyBorder(DruPanel drup, Context ctx) {
132
133 int[] bds = { paddingLeft, paddingRight, paddingTop, paddingBottom };
134
135 boolean nonzero = false;
136
137 for (int i = 0; i < 4; i++) {
138 if (bds[i] == 0) {
139 bds[i] = borderWidth;
140 }
141 if (bds[i] != 0) {
142 nonzero = true;
143 }
144 }
145
146 if (nonzero) {
147 drup.setEmptyBorder(bds[0], bds[1], bds[2], bds[3]);
148 }
149
150
151
152 if (border != null) {
153 if (border.equals("etched")) {
154 drup.addEtchedBorder(backgroundColor.getColor());
155
156 } else if (border.equals("sunken")) {
157 drup.addSunkenBorder(backgroundColor.getColor());
158
159 } else if (border.equals("none")) {
160
161 } else {
162 E.error(" - border style not recognised " + border + " (only 'etched' is defined)");
163 }
164 }
165 if (borderTitle != null) {
166 Color c = backgroundColor.getColor();
167 if (border != null) {
168
169 } else {
170 c = c.darker();
171 }
172
173 drup.addTitledBorder(borderTitle, c);
174 }
175
176 }
177
178
179
180 public ArrayList<Effect> realizeEffects(ArrayList<BaseEffect> arl, Context ctx, GUIPath gpath) {
181 ArrayList<Effect> ret = null;
182 if (arl != null) {
183 ret = new ArrayList<Effect>();
184
185 for (BaseEffect bef : arl) {
186 ret.add(bef.realize(ctx, gpath));
187 }
188 }
189 return ret;
190 }
191
192 }