187 lines
3.5 KiB
Java
187 lines
3.5 KiB
Java
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
|
|
|
|
}
|
|
|
|
}
|