From 853fa6eaac4fea071346bd87a8af1efb809c6a11 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sun, 3 Apr 2016 21:29:48 +0200 Subject: [PATCH] added some documentation --- .../gui/components/data/DataSample.java | 45 ++++++++++++++++--- .../digital/gui/components/data/DataSet.java | 37 +++++++++++++++ .../gui/components/data/DataSetComponent.java | 19 +++++--- .../gui/components/data/DataSetDialog.java | 9 ++++ .../gui/components/data/package-info.java | 8 ++++ 5 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 src/main/java/de/neemann/digital/gui/components/data/package-info.java diff --git a/src/main/java/de/neemann/digital/gui/components/data/DataSample.java b/src/main/java/de/neemann/digital/gui/components/data/DataSample.java index bedb4ae25..a6d9ab2ce 100644 --- a/src/main/java/de/neemann/digital/gui/components/data/DataSample.java +++ b/src/main/java/de/neemann/digital/gui/components/data/DataSample.java @@ -5,35 +5,68 @@ import de.neemann.digital.core.Model; import java.util.ArrayList; /** + * A DataSample contains all the values of the signals to collect data for. + * Only the data of a single timestamp is stored in one sample. + * * @author hneemann */ public class DataSample { - private final int mainTime; + private final int timeStamp; private final long[] values; - public DataSample(int mainTime, int valueCount) { - this.mainTime = mainTime; + /** + * Creates a new sample + * + * @param timeStamp the time stamp + * @param valueCount the number of values, all values are set to zero + */ + public DataSample(int timeStamp, int valueCount) { + this.timeStamp = timeStamp; values = new long[valueCount]; } + /** + * @param sample a deep copy of the given sample + */ public DataSample(DataSample sample) { - this(sample.mainTime, sample.values.length); + this(sample.timeStamp, sample.values.length); System.arraycopy(sample.values, 0, values, 0, values.length); } - public int getMainTime() { - return mainTime; + /** + * @return returns the timestamp + */ + public int getTimeStamp() { + return timeStamp; } + /** + * returns a value + * + * @param i indes of the value + * @return the value + */ public long getValue(int i) { return values[i]; } + /** + * sets a value in the sample + * + * @param i the index of the value + * @param value the value + */ public void setValue(int i, long value) { values[i] = value; } + /** + * Fills this sample with the actual signals values + * + * @param signals the signals to create a sample from + * @return the sample to allow chained calls + */ public DataSample fillWith(ArrayList signals) { for (int i = 0; i < signals.size(); i++) values[i] = signals.get(i).getValue().getValueIgnoreBurn(); diff --git a/src/main/java/de/neemann/digital/gui/components/data/DataSet.java b/src/main/java/de/neemann/digital/gui/components/data/DataSet.java index 2fefdc77a..38bd43057 100644 --- a/src/main/java/de/neemann/digital/gui/components/data/DataSet.java +++ b/src/main/java/de/neemann/digital/gui/components/data/DataSet.java @@ -6,6 +6,9 @@ import java.util.ArrayList; import java.util.Iterator; /** + * The dataSet stores the collected DataSamples. + * Every DataSample contains the values of al signals at a given time. + * * @author hneemann */ public class DataSet implements Iterable { @@ -15,11 +18,21 @@ public class DataSet implements Iterable { private DataSample min; private DataSample max; + /** + * Creates a new instance + * + * @param signals the signals used to collect DataSamples + */ public DataSet(ArrayList signals) { this.signals = signals; samples = new ArrayList<>(); } + /** + * Adds a new Datasample + * + * @param sample the DataSample + */ public void add(DataSample sample) { if (samples.size() < MAX_SAMPLES) { samples.add(sample); @@ -37,10 +50,16 @@ public class DataSet implements Iterable { } } + /** + * @return the mumber of samples + */ public int size() { return samples.size(); } + /** + * @return the number of signals + */ public int signalSize() { return signals.size(); } @@ -50,18 +69,36 @@ public class DataSet implements Iterable { return samples.iterator(); } + /** + * @return a sample which contains all the minimum values + */ public DataSample getMin() { return min; } + /** + * @return a sample which contains all the maximum values + */ public DataSample getMax() { return max; } + /** + * Gets the width of the signal with the given index + * + * @param i the index of the signal + * @return max-min + */ public long getWidth(int i) { return max.getValue(i) - min.getValue(i); } + /** + * return the signal with the given index + * + * @param i the index + * @return the signal + */ public Model.Signal getSignal(int i) { return signals.get(i); } diff --git a/src/main/java/de/neemann/digital/gui/components/data/DataSetComponent.java b/src/main/java/de/neemann/digital/gui/components/data/DataSetComponent.java index 016553eb8..01056d959 100644 --- a/src/main/java/de/neemann/digital/gui/components/data/DataSetComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/data/DataSetComponent.java @@ -4,6 +4,9 @@ import javax.swing.*; import java.awt.*; /** + * The component to show the trace window. + * It shows the data in the given dataSet. + * * @author hneemann */ public class DataSetComponent extends JComponent { @@ -13,9 +16,15 @@ public class DataSetComponent extends JComponent { private static final int SEP = SEP2 * 2; private static final Stroke NORMAL = new BasicStroke(0); private static final Stroke THICK = new BasicStroke(2); + private static final int MIN_COUNT = 20; private final DataSet dataSet; private int textWidth; + /** + * Creates a new dataSet + * + * @param dataSet the dataSet to paint + */ public DataSetComponent(DataSet dataSet) { this.dataSet = dataSet; } @@ -48,7 +57,7 @@ public class DataSetComponent extends JComponent { g.drawLine(x, y - SEP2, x + SIZE * dataSet.size(), y - SEP2); - int[] last_ry = new int[dataSet.signalSize()]; + int[] lastRy = new int[dataSet.signalSize()]; boolean first = true; for (DataSample s : dataSet) { g2.setStroke(NORMAL); @@ -64,10 +73,10 @@ public class DataSetComponent extends JComponent { //int ry = (int) (SIZE-(SIZE*(s.getValue(i)-dataSet.getMin().getValue(i)))/ width); int ry = (int) (SIZE - (SIZE * s.getValue(i)) / width); g.drawLine(x, y + ry, x + SIZE, y + ry); - if (!first && ry != last_ry[i]) - g.drawLine(x, y + last_ry[i], x, y + ry); + if (!first && ry != lastRy[i]) + g.drawLine(x, y + lastRy[i], x, y + ry); - last_ry[i] = ry; + lastRy[i] = ry; y += SIZE + SEP; } first = false; @@ -81,7 +90,7 @@ public class DataSetComponent extends JComponent { @Override public Dimension getPreferredSize() { int count = dataSet.size(); - if (count < 10) count = 10; + if (count < MIN_COUNT) count = MIN_COUNT; return new Dimension(SIZE * count + BORDER * 2 + textWidth, (SIZE + SEP) * dataSet.signalSize() + BORDER * 2); } } diff --git a/src/main/java/de/neemann/digital/gui/components/data/DataSetDialog.java b/src/main/java/de/neemann/digital/gui/components/data/DataSetDialog.java index 9a715d974..12ab9b79c 100644 --- a/src/main/java/de/neemann/digital/gui/components/data/DataSetDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/data/DataSetDialog.java @@ -12,6 +12,8 @@ import java.awt.event.WindowEvent; import java.util.ArrayList; /** + * The Dialog which shows the data to plot. + * * @author hneemann */ public class DataSetDialog extends JDialog implements ModelStateObserver { @@ -22,6 +24,13 @@ public class DataSetDialog extends JDialog implements ModelStateObserver { private int maintime; private DataSet dataSet; + /** + * Creates a new instance + * + * @param owner the parent frame + * @param model the model used to collect the data + * @param type the event type which triggers a new DataSample + */ public DataSetDialog(Frame owner, Model model, ModelEvent.Event type) { super(owner, Lang.get("win_measures"), false); setDefaultCloseOperation(DISPOSE_ON_CLOSE); diff --git a/src/main/java/de/neemann/digital/gui/components/data/package-info.java b/src/main/java/de/neemann/digital/gui/components/data/package-info.java new file mode 100644 index 000000000..b71517d18 --- /dev/null +++ b/src/main/java/de/neemann/digital/gui/components/data/package-info.java @@ -0,0 +1,8 @@ +/** + * In this package you can find the trace windows and its helper classes. + * The trace window is used to show the avolution of signals as a plot value vs. time. + * The time in this case is a generic step count. + * + * @author hneemann + */ +package de.neemann.digital.gui.components.data;