1
2 package org.catacomb.dataview.build;
3
4
5
6 import org.catacomb.druid.build.Context;
7 import org.catacomb.druid.gui.base.*;
8 import org.catacomb.interlish.structure.AddableTo;
9 import org.catacomb.report.E;
10
11 import java.util.ArrayList;
12
13 public class Dataview implements AddableTo {
14
15
16 public int width;
17 public int height;
18
19 public DataSource dataSource;
20
21 public FrameSelector frameSelector;
22
23 public String layout;
24 public String name;
25
26 public ArrayList<DVPanel> panels;
27
28
29
30
31 public void add(Object obj) {
32 if (obj instanceof DVPanel) {
33 if (panels == null) {
34 panels = new ArrayList<DVPanel>();
35 }
36 panels.add((DVPanel)obj);
37
38 } else {
39 E.debugError("dataview - cant add " + obj +
40 " (" + obj.getClass().getName() + ")");
41 }
42 }
43
44
45
46 public void show() {
47
48 }
49
50
51 public DataSource getDataSource() {
52 return dataSource;
53 }
54
55
56
57 public DruApplication buildApplication(Context ctxt) {
58 DruApplication druapp = new DruApplication();
59 druapp.setName("data viewer");
60
61 DruFrame druf = new DruFrame("data viewer");
62 druf.setBackgroundColor(ctxt.getBg());
63
64 druf.setDruPanel(makePanel(ctxt));
65
66 druapp.setMainFrame(druf);
67
68 return druapp;
69
70 }
71
72
73
74 public DruAppletPrep buildAppletPrep(Context ctxt) {
75 DruAppletPrep druapp = new DruAppletPrep();
76
77 druapp.setDruPanel(makePanel(ctxt));
78
79 return druapp;
80
81 }
82
83
84
85
86 public DruPanel makePanel(Context ctxt) {
87 DruBorderPanel dbp = new DruBorderPanel();
88 dbp.setBg(ctxt.getBg());
89 dbp.setFg(ctxt.getFg());
90
91 DruPanel mainPanel = null;
92
93 int np = panels.size();
94 if (np == 1) {
95 mainPanel = makeIthPanel(ctxt, 0);
96 dbp.addCenter(mainPanel);
97
98
99 } else {
100 DruBoxPanel drubp = null;
101 if (layout != null && layout.equals("vertical")) {
102 drubp = new DruBoxPanel(DruBoxPanel.VERTICAL, 0);
103 } else {
104 drubp = new DruBoxPanel(DruBoxPanel.HORIZONTAL, 0);
105 }
106 drubp.setBg(ctxt.getBg());
107 drubp.setFg(ctxt.getFg());
108
109
110 for (int i = 0; i < panels.size(); i++) {
111 DruPanel dp = makeIthPanel(ctxt, i);
112 drubp.addPanel(dp);
113 }
114 dbp.addCenter(drubp);
115 mainPanel = drubp;
116 }
117
118
119 mainPanel.setID("main");
120 ctxt.addToCache(mainPanel);
121
122 if (frameSelector != null) {
123 DruPanel drufp = frameSelector.makePanel(ctxt);
124 dbp.addSouth(drufp);
125 }
126
127 dbp.addBorder(6, 6, 6, 6);
128 return dbp;
129 }
130
131
132
133 private DruPanel makeIthPanel(Context ctxt, int ipan) {
134 DVPanel dvp = panels.get(ipan);
135
136 DruPanel drup = dvp.makePanel(ctxt);
137 drup.addBorder(4, 4, 4, 4);
138 return drup;
139 }
140
141
142
143 }