java-org.hwo.servicelink/src/org/hwo/ui/servicelink/register/FloatRegisterEditor.java

63 lines
1.6 KiB
Java

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.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();
}
}