Fixes #39: Added logic to restore missing strip chart properties when loaded from a TV file.

This commit is contained in:
Derek Bankieris 2015-04-02 14:16:13 -05:00
parent df39400847
commit 203a1bd31d
4 changed files with 59 additions and 185 deletions

View File

@ -56,8 +56,6 @@ import trick.common.utils.vs.Variable;
*/
public class StripChart extends JXPanel {
private static final long serialVersionUID = -1568655620576675021L;
/** available display modes */
public enum Mode {All, Strip, Fixed};
@ -96,7 +94,7 @@ public class StripChart extends JXPanel {
* @param rangeVariables the dependent variables
* @param allVariables all variables available for plotting
* @param mode the initial mode
* @param autoRange the widge of the range when in auto-range mode
* @param autoRange the width of the range when in auto-range mode
* @param linesVisible the visibility of the lines
* @param pointsVisible the visibility of the points
* @param legendVisible the visibility of the legend
@ -105,7 +103,7 @@ public class StripChart extends JXPanel {
@SuppressWarnings("deprecation")
StripChart(StripChartManager stripChartManager, final Variable domainVariable,
Collection<Variable> rangeVariables, Collection<Variable> allVariables,
final Mode mode, double autoRange, final boolean linesVisisble,
final Mode mode, double autoRange, final boolean linesVisible,
final boolean pointsVisible, final boolean legendVisible) {
this.stripChartManager = stripChartManager;
@ -270,7 +268,7 @@ public class StripChart extends JXPanel {
renderer.setBaseLinesVisible(((JCheckBox)event.getSource()).isSelected());
}
}) {{
setSelected(linesVisisble);
setSelected(linesVisible);
fireActionPerformed(new ActionEvent(this, 0, ""));
}}, constraints);

View File

@ -1,26 +1,12 @@
package trick.stripchart;
/** Deprecated imports to be removed in the next release. ********************/
import java.awt.Font;
import java.awt.Paint;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.Range;
import org.jfree.data.xy.XYSeries;
import trick.common.utils.vs.Variable;
/*****************************************************************************/
/**
* manages any number of strip charts and their accompanying data
@ -221,133 +207,6 @@ public class StripChartManager {
stripCharts.remove(stripChart);
}
/**
* saves the state of the strip charts
*
* @param objectOutputStream the save destination
*/
@Deprecated
public void saveStripCharts(ObjectOutputStream objectOutputStream) throws IOException {
objectOutputStream.writeObject(new ArrayList<Variable>(valueLogs.keySet()));
objectOutputStream.writeObject(new Integer(stripCharts.size()));
for (StripChart stripChart : stripCharts) {
objectOutputStream.writeObject(stripChart.getDomainVariable());
objectOutputStream.writeObject(stripChart.getPlottedVariables());
objectOutputStream.writeObject(stripChart.getMode());
objectOutputStream.writeObject(new Double(stripChart.getFixedAutoRange()));
objectOutputStream.writeObject(new Boolean(stripChart.areLinesVisible()));
objectOutputStream.writeObject(new Boolean(stripChart.arePointsVisible()));
objectOutputStream.writeObject(new Boolean(stripChart.isLegendVisible()));
objectOutputStream.writeObject(stripChart.areSettingsVisible());
JFreeChart chart = stripChart.getChart();
objectOutputStream.writeObject(new Boolean(chart.getAntiAlias()));
objectOutputStream.writeObject(chart.getBackgroundPaint());
TextTitle textTitle = stripChart.getTitle();
if (textTitle != null) {
objectOutputStream.writeObject(Boolean.TRUE);
objectOutputStream.writeObject(textTitle.getText());
objectOutputStream.writeObject(textTitle.getFont());
objectOutputStream.writeObject(textTitle.getPaint());
}
else {
objectOutputStream.writeObject(Boolean.FALSE);
}
XYPlot plot = chart.getXYPlot();
objectOutputStream.writeObject(plot.getOrientation());
objectOutputStream.writeObject(plot.getOutlinePaint());
objectOutputStream.writeObject(plot.getBackgroundPaint());
for (ValueAxis axis : new ValueAxis[] {plot.getDomainAxis(), plot.getRangeAxis()}) {
objectOutputStream.writeObject(axis.getLabel());
objectOutputStream.writeObject(axis.getLabelFont());
objectOutputStream.writeObject(axis.getLabelPaint());
objectOutputStream.writeObject(axis.isTickMarksVisible());
objectOutputStream.writeObject(axis.isTickLabelsVisible());
objectOutputStream.writeObject(axis.getTickLabelFont());
objectOutputStream.writeObject(axis.getTickLabelPaint());
}
if (stripChart.getMode() == StripChart.Mode.Fixed) {
objectOutputStream.writeObject(stripChart.getDomainBounds());
objectOutputStream.writeObject(stripChart.getRangeBounds());
}
}
}
/**
* restores a set of strip charts
*
* @param objectInputStream the source of the strip charts
*
* @return the restored strip charts
*/
@SuppressWarnings("unchecked")
@Deprecated
public ArrayList<StripChart> loadStripCharts(ObjectInputStream objectInputStream)
throws IOException, ClassNotFoundException {
for (Variable variable : (ArrayList<Variable>)objectInputStream.readObject()) {
addVariable(variable);
}
ArrayList<StripChart> loadedStripCharts = new ArrayList<StripChart>();
int count = ((Integer)objectInputStream.readObject()).intValue();
while (count-- > 0) {
StripChart stripChart = createStripChart(
(Variable)objectInputStream.readObject(),
(ArrayList<Variable>)objectInputStream.readObject(),
(StripChart.Mode)objectInputStream.readObject(),
((Double)objectInputStream.readObject()).doubleValue(),
((Boolean)objectInputStream.readObject()).booleanValue(),
((Boolean)objectInputStream.readObject()).booleanValue(),
((Boolean)objectInputStream.readObject()).booleanValue());
stripChart.setSettingsVisible(((Boolean)(objectInputStream.readObject())).booleanValue());
JFreeChart chart = stripChart.getChart();
chart.setAntiAlias(((Boolean)objectInputStream.readObject()).booleanValue());
chart.setBackgroundPaint((Paint)objectInputStream.readObject());
if (((Boolean)objectInputStream.readObject()).booleanValue()) {
TextTitle textTitle = stripChart.getTitle();
textTitle.setText((String)objectInputStream.readObject());
textTitle.setFont((Font)objectInputStream.readObject());
textTitle.setPaint((Paint)objectInputStream.readObject());
}
else {
stripChart.getChart().setTitle((TextTitle)null);
}
XYPlot plot = stripChart.getChart().getXYPlot();
plot.setOrientation((PlotOrientation)objectInputStream.readObject());
plot.setOutlinePaint((Paint)objectInputStream.readObject());
plot.setBackgroundPaint((Paint)objectInputStream.readObject());
for (ValueAxis axis : new ValueAxis[] {plot.getDomainAxis(), plot.getRangeAxis()}) {
axis.setLabel((String)objectInputStream.readObject());
axis.setLabelFont((Font)objectInputStream.readObject());
axis.setLabelPaint((Paint)objectInputStream.readObject());
axis.setTickMarksVisible(((Boolean)objectInputStream.readObject()).booleanValue());
axis.setTickLabelsVisible(((Boolean)objectInputStream.readObject()).booleanValue());
axis.setTickLabelFont((Font)objectInputStream.readObject());
axis.setTickLabelPaint((Paint)objectInputStream.readObject());
}
if (stripChart.getMode() == StripChart.Mode.Fixed) {
stripChart.setDomainBounds((Range)objectInputStream.readObject());
stripChart.setRangeBounds((Range)objectInputStream.readObject());
}
loadedStripCharts.add(stripChart);
}
return loadedStripCharts;
}
/**
* a log of a variable's values
*/

View File

@ -1,11 +1,9 @@
package trick.tv;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
@ -21,10 +19,8 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.StringReader;
import java.lang.reflect.ParameterizedType;
import java.net.URI;
@ -70,7 +66,6 @@ import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
@ -91,11 +86,6 @@ import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXLabel;
import org.jdesktop.swingx.JXPanel;
import org.jdesktop.swingx.JXTextField;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.TextTitle;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import trick.common.RunTimeTrickApplication;
@ -711,15 +701,8 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi
fill = BOTH;
}};
//add(new JXLabel("Sorting: "), constraints);
add(comboBox, constraints);
/*constraints.gridy = 1;
constraints.gridx = 0;
constraints.gridwidth = GridBagConstraints.REMAINDER;
add(new JXButton(" Edit Filters "), constraints);*/
settingsDialog.addBecomingVisibleListener(new BecomingVisibleListener() {
@Override
public void becomingVisible() {
@ -1367,7 +1350,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent windowEvent) {
public void windowClosed(WindowEvent windowEvent) {
if (stripChartsOnly && stripChartManager.getStripChartCount() == 0) {
exit();
}
@ -1799,27 +1782,8 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi
StripChart stripChart = stripChartManager.createStripChart(
domainVariable, plottedVariables, stripChartBean.mode, stripChartBean.fixedAutoRange,
stripChartBean.areLinesVisible, stripChartBean.arePointsVisible,
stripChartBean.isLegendVisible);
stripChart.setSettingsVisible(stripChartBean.areSettingsVisible);
JFreeChart chart = stripChart.getChart();
chart.setAntiAlias(stripChartBean.isAntiAliased);
if (stripChartBean.isBackgroundSet) {
chart.setBackgroundPaint(new Color(stripChartBean.backgroundRgb));
}
if (stripChartBean.title != null) {
TextTitle textTitle = stripChart.getTitle();
textTitle.setText(stripChartBean.title.text);
textTitle.setFont(new Font(stripChartBean.title.font.name,
stripChartBean.title.font.style,
stripChartBean.title.font.size));
textTitle.setPaint(new Color(stripChartBean.title.rgb));
}
else {
chart.setTitle((TextTitle)null);
}
stripChartBean.areLinesVisible, stripChartBean.arePointsVisible, stripChartBean.isLegendVisible);
stripChartBean.restore(stripChart);
launchStripChart(stripChart, new Rectangle(
stripChartBean.bounds.x, stripChartBean.bounds.y,

View File

@ -120,6 +120,32 @@ public class TVBean {
this.bounds = new BoundsBean(bounds.x, bounds.y, bounds.width, bounds.height);
}
public void restore(StripChart stripChart) {
stripChart.setSettingsVisible(areSettingsVisible);
JFreeChart chart = stripChart.getChart();
chart.setAntiAlias(isAntiAliased);
if (isBackgroundSet) {
chart.setBackgroundPaint(new Color(backgroundRgb));
}
if (title != null) {
title.restore(stripChart.getTitle());
}
else {
chart.setTitle((TextTitle)null);
}
XYPlot plot = chart.getXYPlot();
plot.setOrientation(isHorizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL);
plot.setOutlinePaint(new Color(outlineRgb));
plot.setBackgroundPaint(new Color(plotBackgroundRgb));
boolean restoreRange = mode == StripChart.Mode.Fixed;
domainAxis.restore(plot.getDomainAxis(), restoreRange);
rangeAxis.restore(plot.getRangeAxis(), restoreRange);
}
@XmlType(name = "title")
public static class TitleBean {
@ -137,6 +163,12 @@ public class TVBean {
rgb = ((Color)textTitle.getPaint()).getRGB();
}
public void restore(TextTitle title) {
title.setText(text);
title.setFont(font.restore());
title.setPaint(new Color(rgb));
}
}
@XmlType(name = "font")
@ -155,6 +187,10 @@ public class TVBean {
size = font.getSize();
}
public Font restore() {
return new Font(name, style, size);
}
}
@XmlType(name = "axis")
@ -186,6 +222,19 @@ public class TVBean {
range = new RangeBean(axis.getRange());
}
public void restore(ValueAxis axis, boolean restoreRange) {
axis.setLabel(label);
axis.setLabelFont(font.restore());
axis.setLabelPaint(new Color(rgb));
axis.setTickMarksVisible(areTickMarksVisible);
axis.setTickLabelsVisible(areTickLabelsVisible);
axis.setTickLabelFont(tickLabelFont.restore());
axis.setTickLabelPaint(new Color(tickLabelRgb));
if (restoreRange) {
axis.setRange(range.restore());
}
}
@XmlType(name = "range")
public static class RangeBean {
@ -199,6 +248,10 @@ public class TVBean {
upper = range.getUpperBound();
}
public Range restore() {
return new Range(lower, upper);
}
}
}