ServiceLinkPlotProvider, JServiceRegisterSourceEditor: Hinzugefügt

thobaben_diagram
Harald Wolff 2015-08-12 22:24:52 +02:00
parent dfeff4eedd
commit 0d6222bad9
2 changed files with 282 additions and 0 deletions

View File

@ -0,0 +1,122 @@
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.readFloatValue();
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;
}
}

View File

@ -0,0 +1,160 @@
package org.hwo.ui.servicelink.register;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JSpinner;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import java.util.List;
import javax.swing.SpinnerNumberModel;
import javax.swing.JCheckBox;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
public class JServiceRegisterSourceEditor extends JPanel {
private JSpinner spRegister;
private JSpinner spNode;
private JSpinner spAx;
private List<ActionListener> actionListeners;
private ServiceRegister serviceRegister;
/**
* Create the panel.
*/
public JServiceRegisterSourceEditor() {
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0};
gridBagLayout.rowHeights = new int[]{0, 0};
gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
setLayout(gridBagLayout);
JLabel lblAx = new JLabel("AX:");
GridBagConstraints gbc_lblAx = new GridBagConstraints();
gbc_lblAx.insets = new Insets(0, 0, 0, 5);
gbc_lblAx.gridx = 0;
gbc_lblAx.gridy = 0;
add(lblAx, gbc_lblAx);
spAx = new JSpinner();
spAx.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
fireAction();
}
});
spAx.setModel(new SpinnerNumberModel(0, 0, 14, 1));
GridBagConstraints gbc_spAx = new GridBagConstraints();
gbc_spAx.fill = GridBagConstraints.HORIZONTAL;
gbc_spAx.insets = new Insets(0, 0, 0, 5);
gbc_spAx.gridx = 1;
gbc_spAx.gridy = 0;
add(spAx, gbc_spAx);
JLabel lblNode = new JLabel("NODE:");
GridBagConstraints gbc_lblNode = new GridBagConstraints();
gbc_lblNode.insets = new Insets(0, 0, 0, 5);
gbc_lblNode.gridx = 2;
gbc_lblNode.gridy = 0;
add(lblNode, gbc_lblNode);
spNode = new JSpinner();
spNode.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
fireAction();
}
});
spNode.setModel(new SpinnerNumberModel(0, 0, 15, 1));
GridBagConstraints gbc_spNode = new GridBagConstraints();
gbc_spNode.fill = GridBagConstraints.HORIZONTAL;
gbc_spNode.insets = new Insets(0, 0, 0, 5);
gbc_spNode.gridx = 3;
gbc_spNode.gridy = 0;
add(spNode, gbc_spNode);
JLabel lblRegister = new JLabel("REGISTER:");
GridBagConstraints gbc_lblRegister = new GridBagConstraints();
gbc_lblRegister.insets = new Insets(0, 0, 0, 5);
gbc_lblRegister.gridx = 4;
gbc_lblRegister.gridy = 0;
add(lblRegister, gbc_lblRegister);
spRegister = new JSpinner();
spRegister.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
fireAction();
}
});
spRegister.setModel(new SpinnerNumberModel(0, 0, 65535, 1));
GridBagConstraints gbc_spRegister = new GridBagConstraints();
gbc_spRegister.fill = GridBagConstraints.HORIZONTAL;
gbc_spRegister.gridx = 5;
gbc_spRegister.gridy = 0;
add(spRegister, gbc_spRegister);
this.initialize();
}
private void initialize(){
actionListeners = new LinkedList<ActionListener>();
}
public void addActionListener(ActionListener actionListener){
actionListeners.add(actionListener);
}
public void removeActionListener(ActionListener actionListener){
actionListeners.remove(actionListener);
}
public ServiceRegister getServiceRegister(){
return this.serviceRegister;
}
public void setServiceRegister(ServiceRegister serviceRegister){
this.serviceRegister = serviceRegister;
}
void fireAction(){
if (serviceRegister != null){
serviceRegister.setAx(getAx());
serviceRegister.setNode(getNode());
serviceRegister.setRegister(getRegister());
}
for (ActionListener l:actionListeners)
l.actionPerformed(new ActionEvent(this, 0, ""));
}
public Integer getAx(){
return (Integer)spAx.getValue();
}
public void setAx(Integer value){
spAx.setValue(value);
}
public Integer getNode(){
return (Integer)spNode.getValue();
}
public void setNode(Integer value){
spNode.setValue(value);
}
public Integer getRegister(){
return (Integer)spRegister.getValue();
}
public void setRegister(Integer value){
spAx.setValue(value);
}
}