added some documentation

This commit is contained in:
hneemann 2016-04-03 21:29:48 +02:00
parent 10c89a0598
commit 853fa6eaac
5 changed files with 107 additions and 11 deletions

View File

@ -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<Model.Signal> signals) {
for (int i = 0; i < signals.size(); i++)
values[i] = signals.get(i).getValue().getValueIgnoreBurn();

View File

@ -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<DataSample> {
@ -15,11 +18,21 @@ public class DataSet implements Iterable<DataSample> {
private DataSample min;
private DataSample max;
/**
* Creates a new instance
*
* @param signals the signals used to collect DataSamples
*/
public DataSet(ArrayList<Model.Signal> 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<DataSample> {
}
}
/**
* @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<DataSample> {
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);
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;