From 0d6222bad9c92ac8e3a9ff061cbd8e419f30128f Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Wed, 12 Aug 2015 22:24:52 +0200 Subject: [PATCH] =?UTF-8?q?ServiceLinkPlotProvider,=20JServiceRegisterSour?= =?UTF-8?q?ceEditor:=20Hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../servicelink/ServiceLinkPlotProvider.java | 122 +++++++++++++ .../JServiceRegisterSourceEditor.java | 160 ++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 src/org/hwo/ui/servicelink/ServiceLinkPlotProvider.java create mode 100644 src/org/hwo/ui/servicelink/register/JServiceRegisterSourceEditor.java diff --git a/src/org/hwo/ui/servicelink/ServiceLinkPlotProvider.java b/src/org/hwo/ui/servicelink/ServiceLinkPlotProvider.java new file mode 100644 index 0000000..7902103 --- /dev/null +++ b/src/org/hwo/ui/servicelink/ServiceLinkPlotProvider.java @@ -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 plots; + + private int samplePosition; + + public ServiceLinkPlotProvider() { + this.samples = 128; + this.samplePosition = 0; + this.plots = new ArrayList(); + } + + 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 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(); + } + + 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); + } + +}