parent
ab7ddc7e13
commit
dd3e273fa8
|
@ -19,7 +19,7 @@ import java.nio.ByteBuffer;
|
||||||
import static com.devexperts.logging.Logging.getLogging;
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
|
|
||||||
public abstract class BaseConfigField {
|
public abstract class BaseConfigField {
|
||||||
private static final Logging log = getLogging(BaseConfigField.class);
|
protected static final Logging log = getLogging(BaseConfigField.class);
|
||||||
|
|
||||||
protected final JLabel status = new JLabel("P");
|
protected final JLabel status = new JLabel("P");
|
||||||
private final JPanel panel = new JPanel(new BorderLayout());
|
private final JPanel panel = new JPanel(new BorderLayout());
|
||||||
|
|
|
@ -11,6 +11,7 @@ import com.rusefi.ui.UIContext;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.rmi.UnexpectedException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -43,7 +44,11 @@ public class EnumConfigField extends BaseConfigField {
|
||||||
Pair<Integer, ?> p = FieldCommandResponse.parseResponse(message);
|
Pair<Integer, ?> p = FieldCommandResponse.parseResponse(message);
|
||||||
if (p != null && p.first == field.getOffset()) {
|
if (p != null && p.first == field.getOffset()) {
|
||||||
int ordinal = (Integer) p.second;
|
int ordinal = (Integer) p.second;
|
||||||
setValue(ordinal);
|
try {
|
||||||
|
setValue(ordinal);
|
||||||
|
} catch (UnexpectedEnumOridnalException e) {
|
||||||
|
System.out.println("ERROR " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,12 +68,14 @@ public class EnumConfigField extends BaseConfigField {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setValue(int ordinal) {
|
private void setValue(int ordinal) throws UnexpectedEnumOridnalException {
|
||||||
String item;
|
String item;
|
||||||
if (ordinal >= options.length) {
|
if (ordinal >= options.length) {
|
||||||
item = "unexpected_" + ordinal;
|
item = "unexpected_" + ordinal;
|
||||||
view.addItem(item);
|
view.addItem(item);
|
||||||
} else {
|
} else {
|
||||||
|
if (ordinal >= options.length)
|
||||||
|
throw new UnexpectedEnumOridnalException(ordinal + " unexpected on " + field);
|
||||||
item = options[ordinal];
|
item = options[ordinal];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +96,10 @@ public class EnumConfigField extends BaseConfigField {
|
||||||
} else {
|
} else {
|
||||||
ordinal = getByteBuffer(ci).getInt();
|
ordinal = getByteBuffer(ci).getInt();
|
||||||
}
|
}
|
||||||
setValue(ordinal);
|
try {
|
||||||
|
setValue(ordinal);
|
||||||
|
} catch (UnexpectedEnumOridnalException e) {
|
||||||
|
log.error("Error loading value " + e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.rusefi.ui.config;
|
||||||
|
|
||||||
|
public class UnexpectedEnumOridnalException extends Throwable {
|
||||||
|
public UnexpectedEnumOridnalException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue