forked from LupusNobilis/java-org.hwo.ui
ServiceLink in eigenes Projekt migriert
parent
42a50c9b08
commit
ee655ff635
|
@ -1,122 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
|
|
||||||
import org.hwo.bitfields.BitField;
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
import org.hwo.bitfields.ui.BitFieldEditor;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
public class BitFieldServiceRegister extends ServiceRegister {
|
|
||||||
|
|
||||||
BitField bitField;
|
|
||||||
BitFieldEditor
|
|
||||||
editor;
|
|
||||||
|
|
||||||
|
|
||||||
public BitFieldServiceRegister(ServiceLink serviceLink) {
|
|
||||||
super(serviceLink,false);
|
|
||||||
|
|
||||||
editor = new BitFieldEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRegisterNode(Element registerNode) {
|
|
||||||
super.setRegisterNode(registerNode);
|
|
||||||
|
|
||||||
Element fieldsNode = (Element)registerNode.getElementsByTagName("Fields").item(0);
|
|
||||||
bitField = new BitField(fieldsNode);
|
|
||||||
|
|
||||||
editor.setBitField(bitField);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTextRepresentation() {
|
|
||||||
if (bitField == null)
|
|
||||||
return "-";
|
|
||||||
return bitField.toText(readIntegerValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JComponent getEditorComponent() {
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void acceptEditorValue() {
|
|
||||||
writeIntegerValue( editor.getIntValue() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEditorValue() {
|
|
||||||
editor.setIntValue( readIntegerValue() );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.FocusEvent;
|
|
||||||
import java.awt.event.FocusListener;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
|
|
||||||
public class FloatRegisterEditor extends JPanel implements ServiceRegisterControl {
|
|
||||||
|
|
||||||
private ServiceRegister serviceRegister;
|
|
||||||
private JTextField tfValue;
|
|
||||||
|
|
||||||
public FloatRegisterEditor()
|
|
||||||
{
|
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
||||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
||||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
||||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
tfValue = new JTextField();
|
|
||||||
GridBagConstraints gbc_tfValue = new GridBagConstraints();
|
|
||||||
gbc_tfValue.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_tfValue.gridx = 0;
|
|
||||||
gbc_tfValue.gridy = 0;
|
|
||||||
add(tfValue, gbc_tfValue);
|
|
||||||
tfValue.setColumns(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
|
||||||
this.serviceRegister = serviceRegister;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeValue() {
|
|
||||||
this.serviceRegister.writeFloatValue(Float.parseFloat(tfValue.getText()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readValue() {
|
|
||||||
tfValue.setText(this.serviceRegister.readFloatValue().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean requestFocusInWindow() {
|
|
||||||
return tfValue.requestFocusInWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
|
|
||||||
public class FloatServiceRegister extends ServiceRegister {
|
|
||||||
|
|
||||||
FloatRegisterEditor editor;
|
|
||||||
|
|
||||||
public FloatServiceRegister(ServiceLink serviceLink)
|
|
||||||
{
|
|
||||||
super(serviceLink,true);
|
|
||||||
editor = new FloatRegisterEditor();
|
|
||||||
editor.setServiceRegister(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTextRepresentation() {
|
|
||||||
Float f = readFloatValue();
|
|
||||||
if (f == null)
|
|
||||||
return "";
|
|
||||||
return String.format("0x%08X %f",Float.floatToIntBits(f),f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JComponent getEditorComponent() {
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void acceptEditorValue() {
|
|
||||||
editor.writeValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEditorValue() {
|
|
||||||
editor.readValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,127 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.FocusEvent;
|
|
||||||
import java.awt.event.FocusListener;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
import org.hwo.ui.JComboBoxEx;
|
|
||||||
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
|
|
||||||
public class IndexedListRegisterEditor extends JPanel implements ServiceRegisterControl {
|
|
||||||
|
|
||||||
public static class IndexedItem {
|
|
||||||
private Integer index;
|
|
||||||
private String label;
|
|
||||||
|
|
||||||
public IndexedItem(Integer index,String label) {
|
|
||||||
this.index = index;
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("%d: %s", this.index, this.label);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIndex(Integer index) {
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
return label;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLabel(String label) {
|
|
||||||
this.label = label;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
private ServiceRegister serviceRegister;
|
|
||||||
private JComboBoxEx cbValue;
|
|
||||||
|
|
||||||
private IndexedItem[] items;
|
|
||||||
|
|
||||||
|
|
||||||
public IndexedListRegisterEditor()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
||||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
||||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
||||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
cbValue = new JComboBoxEx();
|
|
||||||
GridBagConstraints gbc_tfValue = new GridBagConstraints();
|
|
||||||
gbc_tfValue.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_tfValue.gridx = 0;
|
|
||||||
gbc_tfValue.gridy = 0;
|
|
||||||
add(cbValue, gbc_tfValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
|
||||||
this.serviceRegister = serviceRegister;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeValue() {
|
|
||||||
this.serviceRegister.writeIntegerValue(((IndexedItem)cbValue.getSelectedItem()).getIndex());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readValue() {
|
|
||||||
Integer i = this.serviceRegister.readIntegerValue();
|
|
||||||
if ( i == null )
|
|
||||||
i = 0;
|
|
||||||
|
|
||||||
for (IndexedItem item : items) {
|
|
||||||
if (item.getIndex().equals(i)) {
|
|
||||||
cbValue.setSelectedItem(item);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IndexedItem item = new IndexedItem(i, "Unkown Index");
|
|
||||||
cbValue.setSelectedItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean requestFocusInWindow() {
|
|
||||||
return cbValue.requestFocusInWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndexedItem[] getItems() {
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItems(IndexedItem[] items) {
|
|
||||||
this.items = items;
|
|
||||||
|
|
||||||
cbValue.removeAllItems();
|
|
||||||
for (IndexedItem item: items){
|
|
||||||
cbValue.addItem(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
|
|
||||||
import org.hwo.bitfields.BitField;
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
import org.hwo.ui.servicelink.register.IndexedListRegisterEditor.IndexedItem;
|
|
||||||
import org.hwo.xml.NodeListIterator;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
|
|
||||||
public class IndexedListServiceRegister extends ServiceRegister {
|
|
||||||
|
|
||||||
IndexedListRegisterEditor editor;
|
|
||||||
Hashtable<Integer, IndexedItem> items;
|
|
||||||
|
|
||||||
public IndexedListServiceRegister(ServiceLink serviceLink)
|
|
||||||
{
|
|
||||||
super(serviceLink,false);
|
|
||||||
editor = new IndexedListRegisterEditor();
|
|
||||||
editor.setServiceRegister(this);
|
|
||||||
|
|
||||||
items = new Hashtable<Integer, IndexedListRegisterEditor.IndexedItem>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRegisterNode(Element registerNode) {
|
|
||||||
super.setRegisterNode(registerNode);
|
|
||||||
|
|
||||||
Element listNode = (Element)registerNode.getElementsByTagName("List").item(0);
|
|
||||||
|
|
||||||
LinkedList<IndexedItem> items = new LinkedList<IndexedListRegisterEditor.IndexedItem>();
|
|
||||||
|
|
||||||
for (Element listItem: new NodeListIterator(listNode.getElementsByTagName("Item"))){
|
|
||||||
IndexedItem item = new IndexedItem(Integer.parseInt(listItem.getAttribute("index")), listItem.getTextContent());
|
|
||||||
items.add(item);
|
|
||||||
this.items.put(item.getIndex(), item);
|
|
||||||
}
|
|
||||||
editor.setItems(items.toArray(new IndexedItem[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
private IndexedItem getIndexedItem(Integer index) {
|
|
||||||
if (this.items.containsKey(index)) {
|
|
||||||
return this.items.get(index);
|
|
||||||
}
|
|
||||||
IndexedItem unknown = new IndexedItem(index, "Unkown");
|
|
||||||
return unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTextRepresentation() {
|
|
||||||
Integer i = readIntegerValue();
|
|
||||||
if (i == null)
|
|
||||||
return "";
|
|
||||||
return getIndexedItem(i).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JComponent getEditorComponent() {
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void acceptEditorValue() {
|
|
||||||
editor.writeValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEditorValue() {
|
|
||||||
editor.readValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,66 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.event.FocusEvent;
|
|
||||||
import java.awt.event.FocusListener;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
|
|
||||||
public class IntegerRegisterEditor extends JPanel implements ServiceRegisterControl {
|
|
||||||
|
|
||||||
private ServiceRegister serviceRegister;
|
|
||||||
private JTextField tfValue;
|
|
||||||
|
|
||||||
public IntegerRegisterEditor()
|
|
||||||
{
|
|
||||||
super();
|
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
||||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
||||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
||||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
tfValue = new JTextField();
|
|
||||||
GridBagConstraints gbc_tfValue = new GridBagConstraints();
|
|
||||||
gbc_tfValue.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_tfValue.gridx = 0;
|
|
||||||
gbc_tfValue.gridy = 0;
|
|
||||||
add(tfValue, gbc_tfValue);
|
|
||||||
tfValue.setColumns(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
|
||||||
this.serviceRegister = serviceRegister;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeValue() {
|
|
||||||
this.serviceRegister.writeIntegerValue(Integer.decode(tfValue.getText()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readValue() {
|
|
||||||
Integer i = this.serviceRegister.readIntegerValue();
|
|
||||||
if ( i == null )
|
|
||||||
i = 0;
|
|
||||||
tfValue.setText(i.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean requestFocusInWindow() {
|
|
||||||
return tfValue.requestFocusInWindow();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
|
|
||||||
public class IntegerServiceRegister extends ServiceRegister {
|
|
||||||
|
|
||||||
IntegerRegisterEditor editor;
|
|
||||||
|
|
||||||
public IntegerServiceRegister(ServiceLink serviceLink)
|
|
||||||
{
|
|
||||||
super(serviceLink,false);
|
|
||||||
editor = new IntegerRegisterEditor();
|
|
||||||
editor.setServiceRegister(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTextRepresentation() {
|
|
||||||
Integer i = readIntegerValue();
|
|
||||||
if (i == null)
|
|
||||||
return "";
|
|
||||||
return String.format("0x%08x %d", i, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JComponent getEditorComponent() {
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void acceptEditorValue() {
|
|
||||||
editor.writeValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEditorValue() {
|
|
||||||
editor.readValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,160 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,258 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
|
|
||||||
import org.hwo.i18n.Messages;
|
|
||||||
import org.hwo.interactiveobjects.InteractiveObject;
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
import org.hwo.io.servicelink.ServiceLink.ServiceTelegram;
|
|
||||||
import org.hwo.io.servicelink.ServiceLinkException;
|
|
||||||
import org.hwo.io.servicelink.ServiceLinkRequestFailedException;
|
|
||||||
import org.hwo.io.servicelink.ServiceRegisterListener;
|
|
||||||
import org.hwo.models.TableMapper.TableColumn;
|
|
||||||
import org.hwo.ui.servicelink.register.bitfield.BitFieldEditor;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
|
|
||||||
@InteractiveObject(editor=ServiceRegisterEditorDialog.class)
|
|
||||||
public abstract class ServiceRegister implements ServiceRegisterListener {
|
|
||||||
|
|
||||||
static HashMap<String, Class<? extends ServiceRegister>> serviceRegisterTypes;
|
|
||||||
public static void addServiceRegisterType(String typename,Class<? extends ServiceRegister> clazz)
|
|
||||||
{
|
|
||||||
serviceRegisterTypes.put(typename, clazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ServiceRegister createServiceRegister(ServiceLink serviceLink,String typeName)
|
|
||||||
{
|
|
||||||
ServiceRegister sr = null;
|
|
||||||
|
|
||||||
Class<? extends ServiceRegister> clazz = serviceRegisterTypes.get(typeName);
|
|
||||||
if (clazz != null)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
sr = clazz.getDeclaredConstructor(ServiceLink.class).newInstance(serviceLink);
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sr;
|
|
||||||
}
|
|
||||||
public static ServiceRegister createServiceRegister(ServiceLink serviceLink,Element registerNode)
|
|
||||||
{
|
|
||||||
ServiceRegister sr = null;
|
|
||||||
String registerType = registerNode.getAttribute("type");
|
|
||||||
|
|
||||||
if (registerType == null || registerType.equals(""))
|
|
||||||
registerType = "Integer";
|
|
||||||
|
|
||||||
sr = createServiceRegister(serviceLink, registerType);
|
|
||||||
if (sr != null)
|
|
||||||
{
|
|
||||||
sr.setRegisterNode(registerNode);
|
|
||||||
}
|
|
||||||
return sr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Element registerNode;
|
|
||||||
|
|
||||||
private ServiceLink serviceLink;
|
|
||||||
private Integer ax,
|
|
||||||
node,
|
|
||||||
register;
|
|
||||||
|
|
||||||
private boolean asFloat;
|
|
||||||
|
|
||||||
private String registerType;
|
|
||||||
private String registerName;
|
|
||||||
|
|
||||||
protected Integer lastAsyncIntValue;
|
|
||||||
protected Float lastAsyncFloatValue;
|
|
||||||
|
|
||||||
private ServiceRegisterControl
|
|
||||||
serviceRegisterControl;
|
|
||||||
|
|
||||||
public ServiceRegister(ServiceLink serviceLink,boolean asFloat)
|
|
||||||
{
|
|
||||||
this.serviceLink = serviceLink;
|
|
||||||
this.asFloat = asFloat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dispose(){
|
|
||||||
removeServiceRegisterListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeServiceRegisterListener(){
|
|
||||||
if ((this.serviceLink != null)&&(ax != null)&&(node != null)&&(register != null))
|
|
||||||
this.serviceLink.getAsynchronServiceLinkProvider().removeServiceRegisterListener(this.ax, this.node, this.register, this.asFloat, this);
|
|
||||||
}
|
|
||||||
private void addServiceRegisterListener(){
|
|
||||||
if ((this.serviceLink != null) &&(ax != null)&&(node != null)&&(register != null))
|
|
||||||
this.serviceLink.getAsynchronServiceLinkProvider().addServiceRegisterListener(this.ax, this.node, this.register, this.asFloat, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@TableColumn(label="Bezeichnung",after="Register",width=400)
|
|
||||||
public String getRegisterName() {
|
|
||||||
return registerName;
|
|
||||||
}
|
|
||||||
public void setRegisterName(String registerName) {
|
|
||||||
this.registerName = registerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@TableColumn(label="Register",firstColumn=true,width=80)
|
|
||||||
public Integer getRegister() {
|
|
||||||
return register;
|
|
||||||
}
|
|
||||||
public void setRegister(Integer register) {
|
|
||||||
removeServiceRegisterListener();
|
|
||||||
this.register = register;
|
|
||||||
addServiceRegisterListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
@TableColumn(label="Wert",after="Bezeichnung",width=250)
|
|
||||||
abstract public String getTextRepresentation();
|
|
||||||
|
|
||||||
abstract public JComponent getEditorComponent();
|
|
||||||
abstract public void acceptEditorValue();
|
|
||||||
abstract public void updateEditorValue();
|
|
||||||
|
|
||||||
public Element getRegisterNode()
|
|
||||||
{
|
|
||||||
return registerNode;
|
|
||||||
};
|
|
||||||
public void setRegisterNode(Element registerNode)
|
|
||||||
{
|
|
||||||
this.registerNode = registerNode;
|
|
||||||
|
|
||||||
if (this.registerNode != null)
|
|
||||||
{
|
|
||||||
Element labelNode = (Element)this.registerNode.getElementsByTagName("Label").item(0);
|
|
||||||
Element addressNode = (Element)this.registerNode.getElementsByTagName("Address").item(0);
|
|
||||||
|
|
||||||
register = Integer.decode(addressNode.getTextContent());
|
|
||||||
registerName = Messages.getString(labelNode.getTextContent());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAsFloat(boolean asFloat) {
|
|
||||||
removeServiceRegisterListener();
|
|
||||||
this.asFloat = asFloat;
|
|
||||||
addServiceRegisterListener();
|
|
||||||
}
|
|
||||||
public boolean getAsFloat() {
|
|
||||||
return this.asFloat;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ServiceLink getServiceLink() {
|
|
||||||
return serviceLink;
|
|
||||||
}
|
|
||||||
public void setServiceLink(ServiceLink serviceLink) {
|
|
||||||
this.serviceLink = serviceLink;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getAx() {
|
|
||||||
return ax;
|
|
||||||
}
|
|
||||||
public void setAx(Integer ax) {
|
|
||||||
removeServiceRegisterListener();
|
|
||||||
this.ax = ax;
|
|
||||||
addServiceRegisterListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
public void setNode(Integer node) {
|
|
||||||
removeServiceRegisterListener();
|
|
||||||
this.node = node;
|
|
||||||
addServiceRegisterListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Float readFloatValue()
|
|
||||||
{
|
|
||||||
if (lastAsyncFloatValue != null)
|
|
||||||
return lastAsyncFloatValue;
|
|
||||||
return 0.0f;
|
|
||||||
//return serviceLink.getServiceRegisterCache().getCachedFloat(ax, node, register);
|
|
||||||
}
|
|
||||||
public void writeFloatValue(Float value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.serviceLink.writeFloat(ax.byteValue(), node.byteValue(), register,value);
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Float readFloatValueSynchron()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return serviceLink.readFloat(ax.byteValue(), node.byteValue(), register);
|
|
||||||
} catch (ServiceLinkRequestFailedException e) {
|
|
||||||
} catch (IOException e) {
|
|
||||||
} catch (ServiceLinkException e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Integer readIntegerValue()
|
|
||||||
{
|
|
||||||
if (lastAsyncIntValue != null)
|
|
||||||
return lastAsyncIntValue;
|
|
||||||
return 0;
|
|
||||||
//return serviceLink.getServiceRegisterCache().getCachedInteger(ax, node, register);
|
|
||||||
}
|
|
||||||
public void writeIntegerValue(Integer value)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.serviceLink.writeInt(ax.byteValue(), node.byteValue(), register,value);
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void ServiceRegisterValueUpdated(int ax, int node,
|
|
||||||
int registervalue, Float value) {
|
|
||||||
this.lastAsyncFloatValue = value;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void ServiceRegisterValueUpdated(int ax, int node,
|
|
||||||
int registervalue, Integer value) {
|
|
||||||
this.lastAsyncIntValue = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
serviceRegisterTypes = new HashMap<String, Class<? extends ServiceRegister>>();
|
|
||||||
|
|
||||||
serviceRegisterTypes.put("Integer", IntegerServiceRegister.class);
|
|
||||||
serviceRegisterTypes.put("Float", FloatServiceRegister.class);
|
|
||||||
serviceRegisterTypes.put("BitField", BitFieldServiceRegister.class);
|
|
||||||
serviceRegisterTypes.put("IndexedList", IndexedListServiceRegister.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
|
|
||||||
import javax.tools.JavaCompiler;
|
|
||||||
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
|
|
||||||
public interface ServiceRegisterControl {
|
|
||||||
|
|
||||||
public boolean requestFocusInWindow();
|
|
||||||
|
|
||||||
public Component getComponent();
|
|
||||||
|
|
||||||
public void setServiceRegister(ServiceRegister serviceRegister);
|
|
||||||
|
|
||||||
public void writeValue();
|
|
||||||
public void readValue();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,260 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.FlowLayout;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JDialog;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
|
|
||||||
import org.hwo.interactiveobjects.IInteractiveObjectEditor;
|
|
||||||
import org.hwo.ui.KeyStrokeHelper;
|
|
||||||
import org.hwo.ui.KeyStrokeListener;
|
|
||||||
import org.hwo.ui.KeyStrokeParameters;
|
|
||||||
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
import java.awt.Insets;
|
|
||||||
|
|
||||||
import javax.swing.border.TitledBorder;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
|
|
||||||
import java.awt.event.ComponentAdapter;
|
|
||||||
import java.awt.event.ComponentEvent;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
|
|
||||||
public class ServiceRegisterEditorDialog extends JDialog implements IInteractiveObjectEditor{
|
|
||||||
|
|
||||||
private final JPanel contentPanel = new JPanel();
|
|
||||||
|
|
||||||
private ServiceRegister serviceRegister;
|
|
||||||
private JTextField tfAx;
|
|
||||||
private JTextField tfNode;
|
|
||||||
private JTextField tfRegister;
|
|
||||||
private JPanel panelEditorControl;
|
|
||||||
private JTextField tfRegname;
|
|
||||||
|
|
||||||
private KeyStrokeHelper keyStrokeHelper;
|
|
||||||
private JScrollPane scrollPane;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the dialog.
|
|
||||||
*/
|
|
||||||
public ServiceRegisterEditorDialog() {
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
|
||||||
@Override
|
|
||||||
public void componentShown(ComponentEvent e) {
|
|
||||||
if (serviceRegister != null)
|
|
||||||
serviceRegister.getEditorComponent().requestFocusInWindow();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setBounds(100, 100, 327, 318);
|
|
||||||
getContentPane().setLayout(new BorderLayout());
|
|
||||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
||||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
|
||||||
GridBagLayout gbl_contentPanel = new GridBagLayout();
|
|
||||||
gbl_contentPanel.columnWidths = new int[]{0, 0};
|
|
||||||
gbl_contentPanel.rowHeights = new int[]{0, 0, 0};
|
|
||||||
gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
||||||
contentPanel.setLayout(gbl_contentPanel);
|
|
||||||
{
|
|
||||||
JPanel panel = new JPanel();
|
|
||||||
panel.setBorder(new TitledBorder(null, "Service Register", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
|
||||||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
|
||||||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_panel.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_panel.gridx = 0;
|
|
||||||
gbc_panel.gridy = 0;
|
|
||||||
contentPanel.add(panel, gbc_panel);
|
|
||||||
GridBagLayout gbl_panel = new GridBagLayout();
|
|
||||||
gbl_panel.columnWidths = new int[]{0, 0, 0};
|
|
||||||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0};
|
|
||||||
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
|
||||||
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
|
||||||
panel.setLayout(gbl_panel);
|
|
||||||
{
|
|
||||||
JLabel lblAchse = new JLabel("Achse:");
|
|
||||||
GridBagConstraints gbc_lblAchse = new GridBagConstraints();
|
|
||||||
gbc_lblAchse.insets = new Insets(0, 0, 5, 5);
|
|
||||||
gbc_lblAchse.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_lblAchse.gridx = 0;
|
|
||||||
gbc_lblAchse.gridy = 0;
|
|
||||||
panel.add(lblAchse, gbc_lblAchse);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
tfAx = new JTextField();
|
|
||||||
tfAx.setEditable(false);
|
|
||||||
GridBagConstraints gbc_tfAx = new GridBagConstraints();
|
|
||||||
gbc_tfAx.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_tfAx.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_tfAx.gridx = 1;
|
|
||||||
gbc_tfAx.gridy = 0;
|
|
||||||
panel.add(tfAx, gbc_tfAx);
|
|
||||||
tfAx.setColumns(10);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
JLabel lblKnoten = new JLabel("Knoten:");
|
|
||||||
GridBagConstraints gbc_lblKnoten = new GridBagConstraints();
|
|
||||||
gbc_lblKnoten.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_lblKnoten.insets = new Insets(0, 0, 5, 5);
|
|
||||||
gbc_lblKnoten.gridx = 0;
|
|
||||||
gbc_lblKnoten.gridy = 1;
|
|
||||||
panel.add(lblKnoten, gbc_lblKnoten);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
tfNode = new JTextField();
|
|
||||||
tfNode.setEditable(false);
|
|
||||||
GridBagConstraints gbc_tfNode = new GridBagConstraints();
|
|
||||||
gbc_tfNode.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_tfNode.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_tfNode.gridx = 1;
|
|
||||||
gbc_tfNode.gridy = 1;
|
|
||||||
panel.add(tfNode, gbc_tfNode);
|
|
||||||
tfNode.setColumns(10);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
JLabel lblRegister = new JLabel("Register:");
|
|
||||||
GridBagConstraints gbc_lblRegister = new GridBagConstraints();
|
|
||||||
gbc_lblRegister.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_lblRegister.insets = new Insets(0, 0, 5, 5);
|
|
||||||
gbc_lblRegister.gridx = 0;
|
|
||||||
gbc_lblRegister.gridy = 2;
|
|
||||||
panel.add(lblRegister, gbc_lblRegister);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
tfRegister = new JTextField();
|
|
||||||
tfRegister.setEditable(false);
|
|
||||||
GridBagConstraints gbc_tfRegister = new GridBagConstraints();
|
|
||||||
gbc_tfRegister.insets = new Insets(0, 0, 5, 0);
|
|
||||||
gbc_tfRegister.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_tfRegister.gridx = 1;
|
|
||||||
gbc_tfRegister.gridy = 2;
|
|
||||||
panel.add(tfRegister, gbc_tfRegister);
|
|
||||||
tfRegister.setColumns(10);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
JLabel lblNewLabel = new JLabel("Bezeichnung:");
|
|
||||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
|
||||||
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
|
|
||||||
gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
|
|
||||||
gbc_lblNewLabel.gridx = 0;
|
|
||||||
gbc_lblNewLabel.gridy = 3;
|
|
||||||
panel.add(lblNewLabel, gbc_lblNewLabel);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
tfRegname = new JTextField();
|
|
||||||
tfRegname.setEditable(false);
|
|
||||||
GridBagConstraints gbc_tfRegname = new GridBagConstraints();
|
|
||||||
gbc_tfRegname.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
gbc_tfRegname.gridx = 1;
|
|
||||||
gbc_tfRegname.gridy = 3;
|
|
||||||
panel.add(tfRegname, gbc_tfRegname);
|
|
||||||
tfRegname.setColumns(10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
panelEditorControl = new JPanel();
|
|
||||||
GridBagConstraints gbc_panelEditorControl = new GridBagConstraints();
|
|
||||||
gbc_panelEditorControl.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_panelEditorControl.gridx = 0;
|
|
||||||
gbc_panelEditorControl.gridy = 1;
|
|
||||||
contentPanel.add(panelEditorControl, gbc_panelEditorControl);
|
|
||||||
panelEditorControl.setLayout(new BoxLayout(panelEditorControl, BoxLayout.X_AXIS));
|
|
||||||
{
|
|
||||||
scrollPane = new JScrollPane();
|
|
||||||
panelEditorControl.add(scrollPane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
JPanel buttonPane = new JPanel();
|
|
||||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
|
||||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
||||||
{
|
|
||||||
JButton okButton = new JButton("OK");
|
|
||||||
okButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
|
||||||
accept();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
okButton.setActionCommand("OK");
|
|
||||||
buttonPane.add(okButton);
|
|
||||||
getRootPane().setDefaultButton(okButton);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
JButton cancelButton = new JButton("Cancel");
|
|
||||||
cancelButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cancelButton.setActionCommand("Cancel");
|
|
||||||
buttonPane.add(cancelButton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initialize()
|
|
||||||
{
|
|
||||||
keyStrokeHelper = new KeyStrokeHelper(this.getRootPane());
|
|
||||||
keyStrokeHelper.setFocusedWindow(true);
|
|
||||||
keyStrokeHelper.registerKeyStrokeListener(new KeyStrokeListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyStroke(KeyStrokeParameters parameters) {
|
|
||||||
switch (parameters.getKeyCode())
|
|
||||||
{
|
|
||||||
case KeyEvent.VK_ESCAPE:
|
|
||||||
cancel();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
keyStrokeHelper.addKeyCode(KeyEvent.VK_ESCAPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void accept()
|
|
||||||
{
|
|
||||||
serviceRegister.acceptEditorValue();
|
|
||||||
setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cancel()
|
|
||||||
{
|
|
||||||
setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeView()
|
|
||||||
{
|
|
||||||
scrollPane.setViewportView(null);
|
|
||||||
if (serviceRegister != null)
|
|
||||||
{
|
|
||||||
tfAx.setText(serviceRegister.getAx().toString());
|
|
||||||
tfNode.setText(serviceRegister.getNode().toString());
|
|
||||||
tfRegister.setText(serviceRegister.getRegister().toString());
|
|
||||||
tfRegname.setText(serviceRegister.getRegisterName());
|
|
||||||
scrollPane.setViewportView(serviceRegister.getEditorComponent());
|
|
||||||
serviceRegister.updateEditorValue();
|
|
||||||
};
|
|
||||||
doLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInteractiveObject(Object o) {
|
|
||||||
serviceRegister = (ServiceRegister)o;
|
|
||||||
initializeView();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getInteractiveObject() {
|
|
||||||
return serviceRegister;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,186 +0,0 @@
|
||||||
package org.hwo.ui.servicelink.register.bitfield;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
|
|
||||||
import org.hwo.io.servicelink.ServiceLink;
|
|
||||||
import org.hwo.ui.servicelink.register.ServiceRegister;
|
|
||||||
import org.hwo.ui.servicelink.register.ServiceRegisterControl;
|
|
||||||
|
|
||||||
import java.awt.FlowLayout;
|
|
||||||
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
|
|
||||||
import java.awt.Checkbox;
|
|
||||||
import java.awt.GridBagLayout;
|
|
||||||
import java.awt.GridBagConstraints;
|
|
||||||
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
|
|
||||||
public class BitFieldEditor extends JPanel implements ServiceRegisterControl {
|
|
||||||
|
|
||||||
private ServiceRegister serviceRegister;
|
|
||||||
|
|
||||||
private JCheckBox[] checkboxes;
|
|
||||||
private JScrollPane scrollPane;
|
|
||||||
private JPanel pBits;
|
|
||||||
|
|
||||||
private Integer intValue;
|
|
||||||
|
|
||||||
private List<Field> fields;
|
|
||||||
|
|
||||||
public class Field
|
|
||||||
{
|
|
||||||
int start,
|
|
||||||
len;
|
|
||||||
|
|
||||||
String text;
|
|
||||||
|
|
||||||
JCheckBox checkbox;
|
|
||||||
|
|
||||||
public Field(int start,int len)
|
|
||||||
{
|
|
||||||
this.start = start;
|
|
||||||
this.len = len;
|
|
||||||
this.text = String.format("B%d",start);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Field(int start)
|
|
||||||
{
|
|
||||||
this.start = start;
|
|
||||||
this.len = 1;
|
|
||||||
this.text = String.format("B%d",start);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setText(String text)
|
|
||||||
{
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
public String getText()
|
|
||||||
{
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTextRepresentation()
|
|
||||||
{
|
|
||||||
if (BitFieldEditor.this.getIntValue() != null)
|
|
||||||
{
|
|
||||||
if ((BitFieldEditor.this.getIntValue() & (1<<start)) != 0)
|
|
||||||
{
|
|
||||||
return getText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
public Component getComponent()
|
|
||||||
{
|
|
||||||
if (checkbox == null)
|
|
||||||
{
|
|
||||||
checkbox = new JCheckBox();
|
|
||||||
checkbox.setText(getText());
|
|
||||||
}
|
|
||||||
return checkbox;
|
|
||||||
}
|
|
||||||
public void sync()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BitFieldEditor() {
|
|
||||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
||||||
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
||||||
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
||||||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
||||||
setLayout(gridBagLayout);
|
|
||||||
|
|
||||||
scrollPane = new JScrollPane();
|
|
||||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
|
||||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
|
||||||
gbc_scrollPane.gridx = 0;
|
|
||||||
gbc_scrollPane.gridy = 0;
|
|
||||||
add(scrollPane, gbc_scrollPane);
|
|
||||||
|
|
||||||
pBits = new JPanel();
|
|
||||||
scrollPane.setViewportView(pBits);
|
|
||||||
pBits.setLayout(new BoxLayout(pBits, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
checkboxes = new JCheckBox[0];
|
|
||||||
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initialize()
|
|
||||||
{
|
|
||||||
removeAllFieldComponents();
|
|
||||||
createFieldControls();
|
|
||||||
|
|
||||||
doLayout();
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createFieldControls()
|
|
||||||
{
|
|
||||||
fields = new ArrayList<BitFieldEditor.Field>();
|
|
||||||
for (int i=0;i<32;i++)
|
|
||||||
{
|
|
||||||
Field field = new Field(i);
|
|
||||||
fields.add(field);
|
|
||||||
addFieldComponent(field.getComponent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void removeAllFieldComponents()
|
|
||||||
{
|
|
||||||
pBits.removeAll();
|
|
||||||
}
|
|
||||||
protected void addFieldComponent(Component component)
|
|
||||||
{
|
|
||||||
pBits.add(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void synchronize()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setServiceRegister(ServiceRegister serviceRegister) {
|
|
||||||
this.serviceRegister = serviceRegister;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getIntValue()
|
|
||||||
{
|
|
||||||
return this.intValue;
|
|
||||||
}
|
|
||||||
public void setIntValue(Integer value)
|
|
||||||
{
|
|
||||||
this.intValue = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeValue() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readValue() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue