mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 23:36:27 -04:00
made DataSet a Drawable
This commit is contained in:
parent
4647426d39
commit
f6c7014f1b
@ -1,16 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<circuit>
|
||||
<version>1</version>
|
||||
<visualElements>
|
||||
<visualElement>
|
||||
<elementName>And</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="300" y="180"/>
|
||||
<pos x="600" y="360"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Const</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="220" y="210"/>
|
||||
<pos x="440" y="420"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Clock</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>Takt</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="400" y="280"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>Feuer</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="260" y="400"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
@ -21,7 +44,7 @@
|
||||
<string>Rot</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="350" y="150"/>
|
||||
<pos x="700" y="300"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
@ -41,7 +64,19 @@
|
||||
<string>Gelb</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="350" y="170"/>
|
||||
<pos x="700" y="340"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Or</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="340" y="360"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Not</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="280" y="400"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
@ -61,172 +96,138 @@
|
||||
<string>Grün</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="350" y="190"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Clock</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>Clock</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="200" y="140"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Or</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="170" y="180"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Not</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="140" y="200"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<string>Label</string>
|
||||
<string>Feuer</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="130" y="200"/>
|
||||
<pos x="700" y="380"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>T-JK.dig</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="240" y="130"/>
|
||||
<pos x="480" y="260"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>T-JK.dig</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="240" y="190"/>
|
||||
<pos x="480" y="380"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="220" y="210"/>
|
||||
<p2 x="240" y="210"/>
|
||||
<p1 x="540" y="400"/>
|
||||
<p2 x="600" y="400"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="230" y="130"/>
|
||||
<p2 x="240" y="130"/>
|
||||
<p1 x="440" y="400"/>
|
||||
<p2 x="480" y="400"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="270" y="130"/>
|
||||
<p2 x="290" y="130"/>
|
||||
<p1 x="260" y="400"/>
|
||||
<p2 x="280" y="400"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="210" y="180"/>
|
||||
<p2 x="290" y="180"/>
|
||||
<p1 x="320" y="400"/>
|
||||
<p2 x="340" y="400"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="160" y="180"/>
|
||||
<p2 x="170" y="180"/>
|
||||
<p1 x="440" y="420"/>
|
||||
<p2 x="480" y="420"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="290" y="180"/>
|
||||
<p2 x="300" y="180"/>
|
||||
<p1 x="460" y="260"/>
|
||||
<p2 x="480" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="230" y="150"/>
|
||||
<p2 x="240" y="150"/>
|
||||
<p1 x="540" y="260"/>
|
||||
<p2 x="580" y="260"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="150"/>
|
||||
<p2 x="350" y="150"/>
|
||||
<p1 x="460" y="340"/>
|
||||
<p2 x="560" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="270" y="200"/>
|
||||
<p2 x="300" y="200"/>
|
||||
<p1 x="320" y="340"/>
|
||||
<p2 x="420" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="220" y="200"/>
|
||||
<p2 x="240" y="200"/>
|
||||
<p1 x="560" y="340"/>
|
||||
<p2 x="700" y="340"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="130" y="200"/>
|
||||
<p2 x="140" y="200"/>
|
||||
<p1 x="420" y="360"/>
|
||||
<p2 x="580" y="360"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="160" y="200"/>
|
||||
<p2 x="170" y="200"/>
|
||||
<p1 x="320" y="360"/>
|
||||
<p2 x="340" y="360"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="230" y="170"/>
|
||||
<p2 x="280" y="170"/>
|
||||
<p1 x="580" y="360"/>
|
||||
<p2 x="600" y="360"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="160" y="170"/>
|
||||
<p2 x="210" y="170"/>
|
||||
<p1 x="400" y="280"/>
|
||||
<p2 x="440" y="280"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="170"/>
|
||||
<p2 x="350" y="170"/>
|
||||
<p1 x="540" y="280"/>
|
||||
<p2 x="560" y="280"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="200" y="140"/>
|
||||
<p2 x="220" y="140"/>
|
||||
<p1 x="440" y="280"/>
|
||||
<p2 x="480" y="280"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="270" y="140"/>
|
||||
<p2 x="280" y="140"/>
|
||||
<p1 x="460" y="300"/>
|
||||
<p2 x="480" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="220" y="140"/>
|
||||
<p2 x="240" y="140"/>
|
||||
<p1 x="560" y="300"/>
|
||||
<p2 x="700" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="270" y="190"/>
|
||||
<p2 x="280" y="190"/>
|
||||
<p1 x="540" y="380"/>
|
||||
<p2 x="560" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="330" y="190"/>
|
||||
<p2 x="350" y="190"/>
|
||||
<p1 x="660" y="380"/>
|
||||
<p2 x="700" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="200" y="190"/>
|
||||
<p2 x="240" y="190"/>
|
||||
<p1 x="400" y="380"/>
|
||||
<p2 x="480" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="160" y="170"/>
|
||||
<p2 x="160" y="180"/>
|
||||
<p1 x="320" y="340"/>
|
||||
<p2 x="320" y="360"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="290" y="130"/>
|
||||
<p2 x="290" y="180"/>
|
||||
<p1 x="560" y="340"/>
|
||||
<p2 x="560" y="380"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="210" y="170"/>
|
||||
<p2 x="210" y="180"/>
|
||||
<p1 x="560" y="280"/>
|
||||
<p2 x="560" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="230" y="130"/>
|
||||
<p2 x="230" y="150"/>
|
||||
<p1 x="580" y="260"/>
|
||||
<p2 x="580" y="360"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="230" y="150"/>
|
||||
<p2 x="230" y="170"/>
|
||||
<p1 x="420" y="340"/>
|
||||
<p2 x="420" y="360"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="170"/>
|
||||
<p2 x="280" y="190"/>
|
||||
<p1 x="440" y="280"/>
|
||||
<p2 x="440" y="400"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="280" y="140"/>
|
||||
<p2 x="280" y="150"/>
|
||||
<p1 x="460" y="260"/>
|
||||
<p2 x="460" y="300"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="220" y="140"/>
|
||||
<p2 x="220" y="200"/>
|
||||
<p1 x="460" y="300"/>
|
||||
<p2 x="460" y="340"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
@ -1,6 +1,11 @@
|
||||
package de.neemann.digital.gui.components.data;
|
||||
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.draw.graphics.Graphic;
|
||||
import de.neemann.digital.draw.graphics.Orientation;
|
||||
import de.neemann.digital.draw.graphics.Style;
|
||||
import de.neemann.digital.draw.graphics.Vector;
|
||||
import de.neemann.digital.draw.shapes.Drawable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@ -11,10 +16,11 @@ import java.util.Iterator;
|
||||
*
|
||||
* @author hneemann
|
||||
*/
|
||||
public class DataSet implements Iterable<DataSample> {
|
||||
public class DataSet implements Iterable<DataSample>, Drawable {
|
||||
private static final int MAX_SAMPLES = 1000;
|
||||
private final ArrayList<Model.Signal> signals;
|
||||
private final ArrayList<DataSample> samples;
|
||||
private final int maxTextLength;
|
||||
private DataSample min;
|
||||
private DataSample max;
|
||||
|
||||
@ -26,6 +32,13 @@ public class DataSet implements Iterable<DataSample> {
|
||||
public DataSet(ArrayList<Model.Signal> signals) {
|
||||
this.signals = signals;
|
||||
samples = new ArrayList<>();
|
||||
int tl = 0;
|
||||
for (int i = 0; i < signalSize(); i++) {
|
||||
String text = getSignal(i).getName();
|
||||
int w = text.length();
|
||||
if (w > tl) tl = w;
|
||||
}
|
||||
maxTextLength = tl;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,4 +115,62 @@ public class DataSet implements Iterable<DataSample> {
|
||||
public Model.Signal getSignal(int i) {
|
||||
return signals.get(i);
|
||||
}
|
||||
|
||||
|
||||
private static final int BORDER = 10;
|
||||
private static final int SIZE = 25;
|
||||
private static final int SEP2 = 5;
|
||||
private static final int SEP = SEP2 * 2;
|
||||
|
||||
|
||||
@Override
|
||||
public void drawTo(Graphic g, boolean highLight) {
|
||||
int x = getTextBorder();
|
||||
|
||||
int yOffs = SIZE / 2;
|
||||
int y = BORDER;
|
||||
for (int i = 0; i < signalSize(); i++) {
|
||||
String text = getSignal(i).getName();
|
||||
g.drawText(new Vector(x - 2, y + yOffs), new Vector(x + 1, y + yOffs), text, Orientation.RIGHTCENTER, Style.NORMAL);
|
||||
g.drawLine(new Vector(x, y - SEP2), new Vector(x + SIZE * size(), y - SEP2), Style.DASH);
|
||||
y += SIZE + SEP;
|
||||
}
|
||||
g.drawLine(new Vector(x, y - SEP2), new Vector(x + SIZE * size(), y - SEP2), Style.DASH);
|
||||
|
||||
|
||||
int[] lastRy = new int[signalSize()];
|
||||
boolean first = true;
|
||||
for (DataSample s : this) {
|
||||
g.drawLine(new Vector(x, BORDER - SEP2), new Vector(x, (SIZE + SEP) * signalSize() + BORDER - SEP2), Style.DASH);
|
||||
y = BORDER;
|
||||
for (int i = 0; i < signalSize(); i++) {
|
||||
|
||||
long width = getWidth(i);
|
||||
if (width == 0) width = 1;
|
||||
//int ry = (int) (SIZE-(SIZE*(s.getValue(i)-dataSet.getMin().getValue(i)))/ width);
|
||||
int ry = (int) (SIZE - (SIZE * s.getValue(i)) / width);
|
||||
g.drawLine(new Vector(x, y + ry), new Vector(x + SIZE, y + ry), Style.NORMAL);
|
||||
if (!first && ry != lastRy[i])
|
||||
g.drawLine(new Vector(x, y + lastRy[i]), new Vector(x, y + ry), Style.NORMAL);
|
||||
|
||||
lastRy[i] = ry;
|
||||
y += SIZE + SEP;
|
||||
}
|
||||
first = false;
|
||||
x += SIZE;
|
||||
}
|
||||
g.drawLine(new Vector(x, BORDER - SEP2), new Vector(x, (SIZE + SEP) * signalSize() + BORDER - SEP2), Style.DASH);
|
||||
}
|
||||
|
||||
private int getTextBorder() {
|
||||
return maxTextLength * Style.NORMAL.getFontSize() / 2 + BORDER + SEP;
|
||||
}
|
||||
|
||||
public int getGraphicWidth() {
|
||||
return getTextBorder() + size() * SIZE;
|
||||
}
|
||||
|
||||
public int getGraphicHeight() {
|
||||
return signalSize() * (SIZE + SEP) + 2 * BORDER;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.neemann.digital.gui.components.data;
|
||||
|
||||
import de.neemann.digital.draw.graphics.GraphicSwing;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@ -10,15 +12,7 @@ import java.awt.*;
|
||||
* @author hneemann
|
||||
*/
|
||||
public class DataSetComponent extends JComponent {
|
||||
private static final int BORDER = 10;
|
||||
private static final int SIZE = 20;
|
||||
private static final int SEP2 = 3;
|
||||
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
|
||||
@ -35,62 +29,13 @@ public class DataSetComponent extends JComponent {
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
textWidth = 0;
|
||||
for (int i = 0; i < dataSet.signalSize(); i++) {
|
||||
String text = dataSet.getSignal(i).getName();
|
||||
int w = g.getFontMetrics().stringWidth(text);
|
||||
if (w > textWidth) textWidth = w;
|
||||
}
|
||||
int x = textWidth + BORDER + SEP;
|
||||
|
||||
int yOffs = SIZE / 2 + g.getFontMetrics().getHeight() / 2;
|
||||
g.setColor(Color.BLACK);
|
||||
int y = BORDER;
|
||||
for (int i = 0; i < dataSet.signalSize(); i++) {
|
||||
String text = dataSet.getSignal(i).getName();
|
||||
g2.setColor(Color.BLACK);
|
||||
g.drawString(text, BORDER, y + yOffs);
|
||||
g2.setColor(Color.LIGHT_GRAY);
|
||||
g.drawLine(x, y - SEP2, x + SIZE * dataSet.size(), y - SEP2);
|
||||
y += SIZE + SEP;
|
||||
}
|
||||
g.drawLine(x, y - SEP2, x + SIZE * dataSet.size(), y - SEP2);
|
||||
|
||||
|
||||
int[] lastRy = new int[dataSet.signalSize()];
|
||||
boolean first = true;
|
||||
for (DataSample s : dataSet) {
|
||||
g2.setStroke(NORMAL);
|
||||
g2.setColor(Color.LIGHT_GRAY);
|
||||
g.drawLine(x, BORDER - SEP2, x, (SIZE + SEP) * dataSet.signalSize() + BORDER - SEP2);
|
||||
g2.setStroke(THICK);
|
||||
g2.setColor(Color.BLACK);
|
||||
y = BORDER;
|
||||
for (int i = 0; i < dataSet.signalSize(); i++) {
|
||||
|
||||
long width = dataSet.getWidth(i);
|
||||
if (width == 0) width = 1;
|
||||
//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 != lastRy[i])
|
||||
g.drawLine(x, y + lastRy[i], x, y + ry);
|
||||
|
||||
lastRy[i] = ry;
|
||||
y += SIZE + SEP;
|
||||
}
|
||||
first = false;
|
||||
x += SIZE;
|
||||
}
|
||||
g2.setStroke(NORMAL);
|
||||
g2.setColor(Color.LIGHT_GRAY);
|
||||
g.drawLine(x, BORDER - SEP2, x, (SIZE + SEP) * dataSet.signalSize() + BORDER - SEP2);
|
||||
dataSet.drawTo(new GraphicSwing(g2), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
int count = dataSet.size();
|
||||
if (count < MIN_COUNT) count = MIN_COUNT;
|
||||
return new Dimension(SIZE * count + BORDER * 2 + textWidth, (SIZE + SEP) * dataSet.signalSize() + BORDER * 2);
|
||||
int w = dataSet.getGraphicWidth();
|
||||
if (w < 800) w = 800;
|
||||
return new Dimension(w, dataSet.getGraphicHeight());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user