mirror of https://github.com/rusefi/RomRaider.git
updated graph view
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@551 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
cd9bd8b70e
commit
190c95368d
|
@ -17,6 +17,7 @@ import org.jfree.data.xy.XYSeriesCollection;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JToggleButton;
|
||||||
import javax.swing.SpringLayout;
|
import javax.swing.SpringLayout;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import static java.awt.BorderLayout.CENTER;
|
import static java.awt.BorderLayout.CENTER;
|
||||||
|
@ -37,80 +38,37 @@ public final class GraphUpdateHandler implements DataUpdateHandler, ConvertorUpd
|
||||||
private final Map<EcuData, ChartPanel> chartMap = synchronizedMap(new HashMap<EcuData, ChartPanel>());
|
private final Map<EcuData, ChartPanel> chartMap = synchronizedMap(new HashMap<EcuData, ChartPanel>());
|
||||||
private final Map<EcuData, XYSeries> seriesMap = synchronizedMap(new HashMap<EcuData, XYSeries>());
|
private final Map<EcuData, XYSeries> seriesMap = synchronizedMap(new HashMap<EcuData, XYSeries>());
|
||||||
private final Map<EcuData, Integer> datasetIndexes = synchronizedMap(new HashMap<EcuData, Integer>());
|
private final Map<EcuData, Integer> datasetIndexes = synchronizedMap(new HashMap<EcuData, Integer>());
|
||||||
private final long startTime = System.currentTimeMillis();
|
private long startTime = System.currentTimeMillis();
|
||||||
private final JPanel graphPanel;
|
private final JPanel graphPanel;
|
||||||
private boolean combinedChart = false;
|
private boolean combinedChart = false;
|
||||||
|
private boolean paused = false;
|
||||||
|
private long pauseStartTime = System.currentTimeMillis();
|
||||||
private ChartPanel combinedChartPanel = null;
|
private ChartPanel combinedChartPanel = null;
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
|
|
||||||
|
|
||||||
public GraphUpdateHandler(final JPanel panel) {
|
public GraphUpdateHandler(final JPanel panel) {
|
||||||
this.graphPanel = new JPanel(new SpringLayout());
|
this.graphPanel = new JPanel(new SpringLayout());
|
||||||
final JCheckBox combinedCheckbox = new JCheckBox("Combine Graphs", combinedChart);
|
JCheckBox combinedCheckbox = new JCheckBox("Combine Graphs", combinedChart);
|
||||||
combinedCheckbox.addActionListener(new ActionListener() {
|
combinedCheckbox.addActionListener(new CombinedActionListener(combinedCheckbox));
|
||||||
|
JToggleButton playPauseButton = new JToggleButton("Pause Graphs");
|
||||||
|
playPauseButton.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
if (actionEvent.getSource() == combinedCheckbox) {
|
paused = !paused;
|
||||||
new Thread(new Runnable() {
|
if (paused) {
|
||||||
public void run() {
|
pauseStartTime = System.currentTimeMillis();
|
||||||
try {
|
} else {
|
||||||
SwingUtilities.invokeAndWait(new Runnable() {
|
startTime = startTime + (System.currentTimeMillis() - pauseStartTime);
|
||||||
public void run() {
|
|
||||||
synchronized (this) {
|
|
||||||
combinedChart = combinedCheckbox.isSelected();
|
|
||||||
if (combinedChart) {
|
|
||||||
removeAllFromPanel();
|
|
||||||
addAllToCombined();
|
|
||||||
layoutForCombined();
|
|
||||||
// combinedChartPanel.repaint();
|
|
||||||
} else {
|
|
||||||
removeAllFromCombined();
|
|
||||||
addAllToPanel();
|
|
||||||
layoutForPanel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// panel.doLayout();
|
|
||||||
// panel.repaint();
|
|
||||||
graphPanel.doLayout();
|
|
||||||
graphPanel.repaint();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(combinedCheckbox, NORTH);
|
JPanel controlPanel = new JPanel();
|
||||||
|
controlPanel.add(combinedCheckbox);
|
||||||
|
controlPanel.add(playPauseButton);
|
||||||
|
panel.add(controlPanel, NORTH);
|
||||||
panel.add(this.graphPanel, CENTER);
|
panel.add(this.graphPanel, CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAllToCombined() {
|
|
||||||
for (EcuData ecuData : seriesMap.keySet()) {
|
|
||||||
addToCombined(ecuData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeAllFromPanel() {
|
|
||||||
for (EcuData ecuData : seriesMap.keySet()) {
|
|
||||||
removeFromPanel(ecuData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAllToPanel() {
|
|
||||||
for (EcuData ecuData : seriesMap.keySet()) {
|
|
||||||
addToPanel(ecuData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeAllFromCombined() {
|
|
||||||
for (EcuData ecuData : seriesMap.keySet()) {
|
|
||||||
removeFromCombined(ecuData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void registerData(EcuData ecuData) {
|
public synchronized void registerData(EcuData ecuData) {
|
||||||
// add to charts
|
// add to charts
|
||||||
registerSeries(ecuData);
|
registerSeries(ecuData);
|
||||||
|
@ -121,7 +79,7 @@ public final class GraphUpdateHandler implements DataUpdateHandler, ConvertorUpd
|
||||||
addToPanel(ecuData);
|
addToPanel(ecuData);
|
||||||
layoutForPanel();
|
layoutForPanel();
|
||||||
}
|
}
|
||||||
repaintGraphPanel(2);
|
graphPanel.updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void addToPanel(EcuData ecuData) {
|
private synchronized void addToPanel(EcuData ecuData) {
|
||||||
|
@ -161,7 +119,7 @@ public final class GraphUpdateHandler implements DataUpdateHandler, ConvertorUpd
|
||||||
public synchronized void handleDataUpdate(EcuData ecuData, final double value, final long timestamp) {
|
public synchronized void handleDataUpdate(EcuData ecuData, final double value, final long timestamp) {
|
||||||
// update chart
|
// update chart
|
||||||
final XYSeries series = seriesMap.get(ecuData);
|
final XYSeries series = seriesMap.get(ecuData);
|
||||||
if (series != null) {
|
if (series != null && !paused) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
series.add((timestamp - startTime) / 1000.0, value);
|
series.add((timestamp - startTime) / 1000.0, value);
|
||||||
|
@ -178,7 +136,7 @@ public final class GraphUpdateHandler implements DataUpdateHandler, ConvertorUpd
|
||||||
removeFromPanel(ecuData);
|
removeFromPanel(ecuData);
|
||||||
layoutForPanel();
|
layoutForPanel();
|
||||||
}
|
}
|
||||||
repaintGraphPanel(1);
|
graphPanel.updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeFromCombined(EcuData ecuData) {
|
private void removeFromCombined(EcuData ecuData) {
|
||||||
|
@ -246,24 +204,51 @@ public final class GraphUpdateHandler implements DataUpdateHandler, ConvertorUpd
|
||||||
return ecuData.getName() + " (" + ecuData.getSelectedConvertor().getUnits() + ")";
|
return ecuData.getName() + " (" + ecuData.getSelectedConvertor().getUnits() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repaintGraphPanel(final int parentRepaintLevel) {
|
|
||||||
new Thread(new Runnable() {
|
private final class CombinedActionListener implements ActionListener {
|
||||||
public void run() {
|
private final JCheckBox combinedCheckbox;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
private CombinedActionListener(JCheckBox combinedCheckbox) {
|
||||||
if (datasetIndexes.size() < parentRepaintLevel) {
|
this.combinedCheckbox = combinedCheckbox;
|
||||||
graphPanel.doLayout();
|
}
|
||||||
graphPanel.repaint();
|
|
||||||
} else {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
if (datasetIndexes.size() == 1) {
|
combinedChart = combinedCheckbox.isSelected();
|
||||||
graphPanel.doLayout();
|
if (combinedChart) {
|
||||||
}
|
removeAllFromPanel();
|
||||||
graphPanel.getParent().doLayout();
|
addAllToCombined();
|
||||||
graphPanel.getParent().repaint();
|
layoutForCombined();
|
||||||
}
|
} else {
|
||||||
}
|
removeAllFromCombined();
|
||||||
});
|
addAllToPanel();
|
||||||
|
layoutForPanel();
|
||||||
}
|
}
|
||||||
}).start();
|
graphPanel.updateUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAllToCombined() {
|
||||||
|
for (EcuData ecuData : seriesMap.keySet()) {
|
||||||
|
addToCombined(ecuData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeAllFromPanel() {
|
||||||
|
for (EcuData ecuData : seriesMap.keySet()) {
|
||||||
|
removeFromPanel(ecuData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAllToPanel() {
|
||||||
|
for (EcuData ecuData : seriesMap.keySet()) {
|
||||||
|
addToPanel(ecuData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeAllFromCombined() {
|
||||||
|
for (EcuData ecuData : seriesMap.keySet()) {
|
||||||
|
removeFromCombined(ecuData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue