1 package org.catacomb.dataview;
2
3 import org.catacomb.datalish.Box;
4 import org.catacomb.dataview.build.Displayable;
5 import org.catacomb.dataview.build.Line;
6 import org.catacomb.graph.gui.*;
7 import org.catacomb.numeric.data.DataExtractor;
8
9 import java.util.ArrayList;
10
11
12 public class DataPlotPainter implements PaintInstructor {
13
14
15 DataExtractor dataExtractor;
16
17 Displayable[] items;
18
19 int currentFrame;
20
21 Box limitBox;
22
23 Labeller labeller;
24
25 int widthFactor;
26
27
28 public DataPlotPainter(ArrayList<Displayable> arl) {
29 widthFactor = 1;
30
31 if (arl == null) {
32 items = new Displayable[0];
33
34 } else {
35 int n = arl.size();
36 items = new Displayable[n];
37 int iit = 0;
38 for (Displayable dbl : arl) {
39 items[iit++] = dbl;
40 }
41 }
42 }
43
44
45 public void setPaintWidthFactor(int ithick) {
46 widthFactor = ithick;
47 }
48
49
50 public void markNeeded() {
51 for (int i = 0; i < items.length; i++) {
52 items[i].markNeeded(dataExtractor);
53 }
54
55 }
56
57
58
59 public void setDataSource(DataExtractor dex) {
60 currentFrame = -1;
61 dataExtractor = dex;
62
63 showFrame(0);
64 }
65
66
67 public void showFrame(int iframe) {
68 if (iframe != currentFrame && dataExtractor != null) {
69 currentFrame = iframe;
70
71 for (int i = 0; i < items.length; i++) {
72 items[i].getData(dataExtractor, currentFrame);
73 if (items[i] instanceof Line) {
74 }
75 }
76 }
77
78
79 makeLims();
80
81 if (labeller == null) {
82 labeller = new Labeller(items.length);
83 for (int i = 0; i < items.length; i++) {
84 if (items[i] instanceof Line) {
85 Line ll = (Line)(items[i]);
86 Labellee lle = ll.getLabellee();
87 if (lle != null) {
88 labeller.updateLabellee(i, lle);
89 }
90 }
91 }
92 labeller.initLabels(limitBox);
93 } else {
94 labeller.adjustLabels(limitBox);
95 }
96
97
98 }
99
100
101 private void makeLims() {
102 Box limits = new Box();
103 for (int i = 0; i < items.length; i++) {
104 items[i].pushBox(limits);
105 }
106 limits.pad();
107 limitBox = limits;
108 }
109
110
111 public Box getLimitBox() {
112 makeLims();
113 return limitBox;
114 }
115
116 public boolean antialias() {
117 return true;
118 }
119
120
121
122 public void instruct(Painter p) {
123
124
125 for (int i = 0; i < items.length; i++) {
126 items[i].instruct(p, widthFactor);
127 }
128
129 if (labeller != null) {
130 labeller.instruct(p);
131 }
132 }
133
134
135 }