1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.diyefi.openlogviewer.graphing;
24
25 import java.awt.Color;
26 import javax.swing.JLayeredPane;
27
28 import org.diyefi.openlogviewer.OpenLogViewer;
29 import org.diyefi.openlogviewer.genericlog.GenericDataElement;
30 import org.diyefi.openlogviewer.genericlog.GenericLog;
31
32 public class MultiGraphLayeredPane extends JLayeredPane {
33 private static final long serialVersionUID = 1L;
34
35 private GenericLog genLog;
36 private InfoPanel infoPanel;
37 private int totalSplits;
38
39 public MultiGraphLayeredPane() {
40 super();
41 init();
42 }
43
44 private void init() {
45 totalSplits = 1;
46 infoPanel = new InfoPanel();
47 infoPanel.setSize(400, 600);
48 this.setLayer(infoPanel, 99);
49 this.setBackground(Color.BLACK);
50 this.setOpaque(true);
51 this.add(infoPanel);
52 }
53
54 public final void addGraph(final String header) {
55 final boolean p = OpenLogViewer.getInstance().getEntireGraphingPanel().isPlaying();
56 if (p) {
57 OpenLogViewer.getInstance().getEntireGraphingPanel().pause();
58 }
59 boolean found = false;
60 for (int i = 0; i < this.getComponentCount() && !found; i++) {
61 if (this.getComponent(i) instanceof SingleGraphPanel) {
62 final SingleGraphPanel gl = (SingleGraphPanel) this.getComponent(i);
63 if (gl.getName().equals(header)) {
64 found = true;
65 }
66 }
67 }
68
69 if (!found) {
70 final SingleGraphPanel graph = new SingleGraphPanel();
71 graph.setSize(this.getSize());
72 graph.setName(header);
73 this.add(graph);
74 this.addHierarchyBoundsListener(graph);
75 genLog.get(header).addPropertyChangeListener("Split", graph);
76 graph.setData(genLog.get(header));
77 }
78
79 if (p) {
80 OpenLogViewer.getInstance().getEntireGraphingPanel().play();
81 }
82 }
83
84 public final boolean removeGraph(final String header) {
85 final GenericDataElement temp = genLog.get(header);
86 for (int i = 0; i < this.getComponentCount(); i++) {
87 if (this.getComponent(i) instanceof SingleGraphPanel) {
88 final SingleGraphPanel t = (SingleGraphPanel) this.getComponent(i);
89 if (t.getData() == temp) {
90 this.remove(t);
91 this.removeHierarchyBoundsListener(t);
92 return true;
93 }
94 }
95 }
96 return false;
97 }
98
99 private void removeAllGraphs() {
100 for (int i = 0; this.getComponentCount() > 1;) {
101 if (this.getComponent(i) instanceof SingleGraphPanel) {
102 this.removeHierarchyBoundsListener((SingleGraphPanel) getComponent(i));
103 this.remove(getComponent(i));
104 } else {
105 i++;
106 }
107 }
108 repaint();
109 }
110
111 public final void setLog(final GenericLog log) {
112 removeAllGraphs();
113 genLog = log;
114 infoPanel.setLog(genLog);
115 repaint();
116 }
117
118 public final InfoPanel getInfoPanel() {
119 return infoPanel;
120 }
121
122 public final void setColor(final String header, final Color newColor) {
123 for (int i = 0; i < this.getComponentCount(); i++) {
124 if (this.getComponent(i) instanceof SingleGraphPanel && this.getComponent(i).getName().equals(header)) {
125 final SingleGraphPanel gl = (SingleGraphPanel) this.getComponent(i);
126 gl.setColor(newColor);
127 }
128 }
129 }
130
131 public final int getTotalSplits() {
132 return totalSplits;
133 }
134
135 public final void setTotalSplits(final int totalSplits) {
136 if (totalSplits > 0) {
137 this.totalSplits = totalSplits;
138 for (int i = 0; i < this.getComponentCount(); i++) {
139 if (this.getComponent(i) instanceof SingleGraphPanel) {
140 final SingleGraphPanel gl = (SingleGraphPanel) this.getComponent(i);
141 gl.sizeGraph();
142 }
143 }
144 }
145 }
146
147
148
149
150
151 public final int graphSize() {
152 int availableData = 0;
153 for (int i = 0; i < this.getComponentCount(); i++) {
154 if (this.getComponent(i) instanceof SingleGraphPanel) {
155 final SingleGraphPanel singleGraph = (SingleGraphPanel) this.getComponent(i);
156 availableData = singleGraph.graphSize();
157 }
158 }
159 return availableData;
160 }
161 }