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 java.util.ResourceBundle;
27
28 import javax.swing.JLayeredPane;
29
30 import org.diyefi.openlogviewer.Keys;
31 import org.diyefi.openlogviewer.OpenLogViewer;
32 import org.diyefi.openlogviewer.genericlog.GenericDataElement;
33 import org.diyefi.openlogviewer.genericlog.GenericLog;
34
35 public class MultiGraphLayeredPane extends JLayeredPane {
36 private static final long serialVersionUID = 1L;
37 private static final int BOTTOM_LAYER = 999;
38 private static final int PANEL_WIDTH = 600;
39 private static final int PANEL_HEIGHT = 400;
40
41 private GenericLog genLog;
42 private final InfoPanel infoPanel;
43 private int trackCount;
44 private int layer;
45
46 public MultiGraphLayeredPane(final ResourceBundle labels) {
47 setOpaque(true);
48 setLayout(null);
49 setBackground(Color.BLACK);
50
51 layer = BOTTOM_LAYER;
52 trackCount = 1;
53
54 infoPanel = new InfoPanel(labels);
55 infoPanel.setSize(PANEL_WIDTH, PANEL_HEIGHT);
56 setLayer(infoPanel, layer);
57 layer--;
58 add(infoPanel);
59 }
60
61 public final void addGraph(final String header) {
62 final boolean p = OpenLogViewer.getInstance().getEntireGraphingPanel().isPlaying();
63 if (p) {
64 OpenLogViewer.getInstance().getEntireGraphingPanel().pause();
65 }
66 boolean found = false;
67 for (int i = 0; i < this.getComponentCount() && !found; i++) {
68 if (this.getComponent(i) instanceof SingleGraphPanel) {
69 final SingleGraphPanel gl = (SingleGraphPanel) this.getComponent(i);
70 if (gl.getName().equals(header)) {
71 found = true;
72 }
73 }
74 }
75
76 if (!found) {
77 final SingleGraphPanel graph = new SingleGraphPanel();
78 graph.setSize(this.getSize());
79 graph.setName(header);
80 this.setLayer(graph, layer);
81 layer--;
82 this.add(graph);
83 this.addHierarchyBoundsListener(graph);
84 genLog.get(header).addPropertyChangeListener(Keys.SPLIT, graph);
85 graph.setData(genLog.get(header));
86 graph.repaint();
87 }
88
89 this.revalidate();
90 this.repaint();
91
92 if (p) {
93 OpenLogViewer.getInstance().getEntireGraphingPanel().play();
94 }
95 }
96
97 public final void removeGraph(final String header) {
98 final GenericDataElement temp = genLog.get(header);
99 for (int i = 0; i < this.getComponentCount(); i++) {
100 if (this.getComponent(i) instanceof SingleGraphPanel) {
101 final SingleGraphPanel t = (SingleGraphPanel) this.getComponent(i);
102 if (t.getData() == temp) {
103 this.remove(t);
104 this.removeHierarchyBoundsListener(t);
105 this.revalidate();
106 this.repaint();
107 }
108 }
109 }
110 }
111
112 private void removeAllGraphs() {
113 int componentIndex = 0;
114 while (this.getComponentCount() > 1) {
115 if (this.getComponent(componentIndex) instanceof SingleGraphPanel) {
116 final SingleGraphPanel sgp = (SingleGraphPanel) getComponent(componentIndex);
117 this.removeHierarchyBoundsListener(sgp);
118 sgp.getData().setDisplayColor(null);
119 this.remove(sgp);
120 } else {
121 componentIndex++;
122 }
123 }
124 repaint();
125 }
126
127 public final void setLog(final GenericLog log) {
128 removeAllGraphs();
129 genLog = log;
130 infoPanel.setLog(genLog);
131 repaint();
132 }
133
134 public final InfoPanel getInfoPanel() {
135 return infoPanel;
136 }
137
138 public final int getTrackCount() {
139 return trackCount;
140 }
141
142 public final void setTrackCount(final int newTrackCount) {
143 trackCount = newTrackCount;
144 for (int i = 0; i < getComponentCount(); i++) {
145 if (getComponent(i) instanceof SingleGraphPanel) {
146 final SingleGraphPanel gl = (SingleGraphPanel) getComponent(i);
147 gl.sizeGraph();
148 }
149 }
150 }
151
152
153
154
155
156 public final int graphSize() {
157 int availableData = 0;
158 for (int i = 0; i < getComponentCount(); i++) {
159 if (getComponent(i) instanceof SingleGraphPanel) {
160 final SingleGraphPanel singleGraph = (SingleGraphPanel) getComponent(i);
161 availableData = singleGraph.graphSize();
162 }
163 }
164 return availableData;
165 }
166 }