2014-07-25 23:33:15 +02:00
|
|
|
package org.hwo.bitfields.ui;
|
|
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
import java.awt.FlowLayout;
|
|
|
|
|
|
|
|
import javax.swing.BoxLayout;
|
|
|
|
import javax.swing.JLabel;
|
|
|
|
|
|
|
|
import org.hwo.bitfields.BitField;
|
|
|
|
import org.hwo.bitfields.Field;
|
|
|
|
|
|
|
|
public class BitFieldEditor extends JPanel {
|
|
|
|
private BitField bitField;
|
|
|
|
|
|
|
|
private FieldControl[] controls;
|
|
|
|
|
|
|
|
public BitFieldEditor() {
|
|
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer getIntValue() {
|
2014-07-26 01:34:19 +02:00
|
|
|
int value = 0;
|
|
|
|
for (FieldControl fc:controls)
|
|
|
|
{
|
|
|
|
value = fc.getValue(value);
|
|
|
|
}
|
|
|
|
return value;
|
2014-07-25 23:33:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setIntValue(Integer intValue) {
|
2014-07-26 01:34:19 +02:00
|
|
|
for (FieldControl fc:controls)
|
|
|
|
{
|
|
|
|
fc.setValue(intValue);
|
|
|
|
}
|
|
|
|
|
2014-07-25 23:33:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public BitField getBitField() {
|
|
|
|
return bitField;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBitField(BitField bitField) {
|
|
|
|
this.bitField = bitField;
|
|
|
|
|
|
|
|
initializeView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initializeView()
|
|
|
|
{
|
|
|
|
if (controls != null)
|
|
|
|
{
|
|
|
|
for (FieldControl fc: controls)
|
|
|
|
{
|
|
|
|
remove(fc.getEditorComponent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Field[] fields = bitField.getFields();
|
|
|
|
controls = new FieldControl[fields.length];
|
|
|
|
|
|
|
|
for (int i=0;i<fields.length;i++)
|
|
|
|
{
|
|
|
|
if (fields[i].getLength() == 1)
|
|
|
|
controls[i] = new BoolFieldEditor(fields[i]);
|
|
|
|
else
|
|
|
|
controls[i] = new IntFieldEditor(fields[i]);
|
|
|
|
|
|
|
|
add(controls[i].getEditorComponent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean requestFocusInWindow() {
|
|
|
|
if ((controls != null) && controls.length != 0)
|
|
|
|
{
|
2014-07-26 01:34:19 +02:00
|
|
|
return controls[0].requestFocusInWindow();
|
2014-07-25 23:33:15 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|