123 lines
2.4 KiB
Java
123 lines
2.4 KiB
Java
package org.hwo.ui.servicelink;
|
|
|
|
import java.awt.Color;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.hwo.ui.diagram.PlotProvider;
|
|
import org.hwo.ui.servicelink.register.ServiceRegister;
|
|
|
|
public class ServiceLinkPlotProvider implements PlotProvider{
|
|
|
|
public class Plot{
|
|
ServiceRegister serviceRegister;
|
|
Float[] values;
|
|
|
|
public Plot(ServiceRegister serviceRegister){
|
|
this.serviceRegister = serviceRegister;
|
|
this.values = new Float[samples];
|
|
}
|
|
|
|
public Float[] getSamples(){
|
|
return this.values;
|
|
}
|
|
|
|
public void sample(int pos){
|
|
if (this.serviceRegister.getAsFloat())
|
|
this.values[pos] = this.serviceRegister.readFloatValueSynchron();
|
|
else
|
|
this.values[pos] = this.serviceRegister.readIntegerValue().floatValue();
|
|
}
|
|
|
|
public void resize(){
|
|
this.values = new Float[samples];
|
|
}
|
|
}
|
|
|
|
private int samples;
|
|
private List<Plot> plots;
|
|
|
|
private int samplePosition;
|
|
|
|
public ServiceLinkPlotProvider() {
|
|
this.samples = 128;
|
|
this.samplePosition = 0;
|
|
this.plots = new ArrayList<ServiceLinkPlotProvider.Plot>();
|
|
}
|
|
|
|
public synchronized void resize(int size){
|
|
|
|
this.samples = size;
|
|
this.samplePosition = 0;
|
|
|
|
for (Plot p: this.plots){
|
|
p.resize();
|
|
}
|
|
|
|
}
|
|
|
|
public synchronized void addPlot(ServiceRegister sr){
|
|
Plot p = new Plot(sr);
|
|
|
|
this.plots.add(p);
|
|
}
|
|
|
|
public synchronized void sample(){
|
|
for (Plot p: this.plots){
|
|
p.sample(this.samplePosition);
|
|
}
|
|
|
|
this.samplePosition++;
|
|
if (this.samplePosition == this.samples)
|
|
this.samplePosition = 0;
|
|
|
|
for (Plot p: this.plots){
|
|
p.getSamples()[this.samplePosition] = null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public synchronized int getPoints() {
|
|
return this.samples;
|
|
}
|
|
|
|
@Override
|
|
public synchronized int getPlots() {
|
|
return this.plots.size();
|
|
}
|
|
|
|
@Override
|
|
public synchronized Float[][] getMatrix() {
|
|
Float[][] matrix = new Float[this.plots.size()][];
|
|
|
|
for (int i=0;i<this.plots.size();i++){
|
|
matrix[i] = this.plots.get(i).values;
|
|
}
|
|
|
|
return matrix;
|
|
}
|
|
|
|
@Override
|
|
public synchronized String getLabel(int plot) {
|
|
return this.plots.get(plot).serviceRegister.getRegisterName();
|
|
}
|
|
|
|
@Override
|
|
public synchronized String getPointLabel(int point) {
|
|
return String.format("%d",point);
|
|
}
|
|
|
|
@Override
|
|
public synchronized Color[] getColors() {
|
|
Color[] cl = new Color[this.plots.size()];
|
|
for (int i=0;i<this.plots.size();i++){
|
|
cl[i] = Color.BLACK;
|
|
}
|
|
return cl;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|