Commit abaed11f authored by Vincent van Beveren's avatar Vincent van Beveren

unified value conversion

fixed build and code to be compatible with Java 6
added more documentation files for reference
parent 48f2d98b
<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
4 apr. 2016 13:06:34
jsfp
Java SFP Library
vincentb
====================================================================== -->
<project name="safaripark" default="default">
<description>
General project build
</description>
<target name="default">
<ant dir="nikhef-tools"/>
<ant dir="rebus"/>
<ant dir="jsfp"/>
<ant dir="safaripark"/>
</target>
<target name="clean">
<ant dir="nikhef-tools" target="clean"/>
<ant dir="rebus" target="clean"/>
<ant dir="jsfp" target="clean"/>
<ant dir="safaripark" target="clean"/>
</target>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/rebus"/>
<classpathentry kind="lib" path="lib/luaj-jse-3.0.1.jar"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/nikhef-tools"/>
......
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
......@@ -60,7 +60,7 @@
<target name="compile" depends="rebus">
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}">
<javac srcdir="${src}" destdir="${build}" source="1.6" target="1.6" includeantruntime="no">
<classpath>
<pathelement location="${rebus_lib}/JavaFTD2XX-0.2.6.jar"/>
<pathelement location="${lib}/luaj-jse-3.0.1.jar"/>
......
package nl.nikhef.sfp.ddmi;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.xml.stream.XMLStreamException;
public class DDMI extends DDMIGroup {
private static final String DDMI_XML = "desc/sfpdd.xml";
......@@ -118,6 +116,11 @@ public class DDMI extends DDMIGroup {
}
}
public Collection<DataSource> getSources() {
return Collections.unmodifiableCollection(_dataSources.values());
}
......
......@@ -48,9 +48,9 @@ public class DDMIContext
switch (value.getType()) {
case INTEGER_TYPE:
case BITMAP_TYPE:
return LuaValue.valueOf(value.readInt(DDMIContext.this));
return LuaValue.valueOf(DDMIUtils.readInt(value, DDMIContext.this));
case TEXT_TYPE:
return LuaValue.valueOf(value.readString(DDMIContext.this));
return LuaValue.valueOf(DDMIUtils.readString(value, DDMIContext.this));
default:
break;
}
......
......@@ -122,7 +122,7 @@ public class DDMIMeta<T extends Object> {
public static class BitField {
private Map<Integer, BitFieldValue> _bitFieldValue = new TreeMap<>();
private Map<Integer, BitFieldValue> _bitFieldValue = new TreeMap<Integer, BitFieldValue>();
public void setBit(String name, int pos, boolean inverted)
{
......
package nl.nikhef.sfp.ddmi;
import nl.nikhef.sfp.ddmi.DDMIValue.DDMIType;
public final class DDMIUtils {
private DDMIUtils() {
}
// -------------------------------------------------------------------------------------------
// Raw read/write conversion functions
// -------------------------------------------------------------------------------------------
public static final int rawToInt(byte[] rawData, DDMIValue val)
{
if (val.getLength() > 4) throw new AccessException("Can't interpret as integer");
byte[] d = rawData;
if (d == null) return 0;
boolean signed;
if (val.getType() == DDMIType.INTEGER_TYPE ||
val.getType() == DDMIType.DECIMAL_TYPE_SIGNED ||
val.getType() == DDMIType.DECIMAL_TYPE_FLOAT) {
signed =true;
} else {
signed = false;
}
int v = signed ? d[0] : d[0] & 0xFF;
for (int i = 1; i < d.length; i++) {
v <<= 8;
v |= 0xFF & d[i];
}
return v;
}
public static final float rawToDecimal(DDMIValue val, byte[] rawData)
{
float baseValue = Float.NaN;
int intValue = rawToInt(rawData, val);
switch (val.getType()) {
case DECIMAL_TYPE_FLOAT:
baseValue = Float.intBitsToFloat(intValue);
break;
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
baseValue = intValue;
break;
default:
break;
}
if (DDMIMeta.CONV.partOf(val)) {
baseValue = DDMIMeta.CONV.of(val).apply(baseValue);
}
return baseValue;
}
public static final String rawToString(DDMIValue val, byte[] rawData)
{
return new String(rawData).trim();
}
public static final byte[] decimalToRaw(DDMIValue val, float value)
{
if (DDMIMeta.CONV.partOf(val)) {
value = DDMIMeta.CONV.of(val).revert(value);
}
int intValue = 0;
switch (val.getType()) {
case DECIMAL_TYPE_FLOAT:
intValue = Float.floatToIntBits(value);
break;
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
intValue = Math.round(value);
break;
default:
break;
}
return intToRaw(val, intValue);
}
public static final byte[] intToRaw(DDMIValue val, int v)
{
if (val.getLength() > 4) throw new AccessException("Can't interpret as integer");
byte[] b = new byte[val.getLength()];
for (int i = val.getLength() - 1; i >= 0; --i) {
b[i] = (byte)(v & 0xFF);
v >>= 8;
}
return b;
}
public static byte[] stringToRaw(DDMIValue val, String str) {
byte[] newRaw = new byte[val.getLength()];
byte[] strBytes = str.getBytes();
for (int i = 0; i < newRaw.length; i++) {
if (i < strBytes.length) {
newRaw[i] = strBytes[i];
} else {
newRaw[i] = (byte)' ';
}
}
return newRaw;
}
// -------------------------------------------------------------------------------------------
// Read functions
// -------------------------------------------------------------------------------------------
public static final String readString(DDMIValue val, DDMIContext ctx)
{
return rawToString(val, val.readRaw(ctx));
}
public static final int readInt(DDMIValue val, DDMIContext ctx)
{
return rawToInt(val.readRaw(ctx), val);
}
public static final float readDecimal(DDMIValue val, DDMIContext ctx) {
return rawToDecimal(val, val.readRaw(ctx));
}
public static final String getValueAsSting(DDMIValue val, DDMIContext ctx) {
switch (val.getType()) {
case INTEGER_TYPE:
int v = readInt(val, ctx);
if (DDMIMeta.LOOKUP.partOf(val)) {
DDMIMeta.LookupTable lut = DDMIMeta.LOOKUP.of(val);
return String.format("%s (%02d)", lut.get(v), v);
} else {
return String.format("%d", v);
}
case TEXT_TYPE:
return readString(val, ctx);
case DECIMAL_TYPE_FLOAT:
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
return String.format("%.3f", readDecimal(val, ctx));
default:
StringBuilder sb = new StringBuilder();
for (byte b : val.readRaw(ctx))
{
sb.append(String.format("%02x ", 0xFF & b));
}
return sb.toString();
}
}
public static final void writeInt(DDMIValue val, DDMIContext ctx, int v)
{
val.writeRaw(ctx, intToRaw(val, v));
}
}
......@@ -153,35 +153,6 @@ public class DDMIValue extends DDMIElement {
acc.write(ctx, _offset, dta);
}
public String readString(DDMIContext ctx) {
return new String(readRaw(ctx));
}
public int readInt(DDMIContext ctx) {
if (_length > 4) throw new AccessException("Can't interpret as integer");
byte[] d = readRaw(ctx);
if (d == null) return 0;
int v = d[0];
for (int i = 1; i < d.length; i++) {
v <<= 8;
v |= 0xFF & d[i];
}
return v;
}
public void writeInt(DDMIContext ctx, int v)
{
if (_length > 4) throw new AccessException("Can't interpret as integer");
byte[] b = new byte[_length];
for (int i = 0; i < _length; ++i) {
b[i] = (byte)(v & 0xFF);
v >>= 8;
}
writeRaw(ctx, b);
}
@Override
public String toString() {
......@@ -196,7 +167,7 @@ public class DDMIValue extends DDMIElement {
switch (_type) {
case INTEGER_TYPE:
int v = readInt(ctx);
int v = DDMIUtils.readInt(this, ctx);
if (DDMIMeta.LOOKUP.partOf(this)) {
DDMIMeta.LookupTable lut = DDMIMeta.LOOKUP.of(this);
sb.append(String.format("%s (%02d)\n", lut.get(v), v));
......@@ -206,7 +177,7 @@ public class DDMIValue extends DDMIElement {
break;
case TEXT_TYPE:
sb.append(readString(ctx));
sb.append(DDMIUtils.readString(this, ctx));
sb.append('\n');
break;
case BITMAP_TYPE:
......@@ -235,58 +206,7 @@ public class DDMIValue extends DDMIElement {
}
public float readDecimal(DDMIContext ctx) {
float baseValue = Float.NaN;
switch (_type) {
case DECIMAL_TYPE_FLOAT:
baseValue = Float.intBitsToFloat(readInt(ctx));
break;
case DECIMAL_TYPE_UNSIGNED:
baseValue = 0xFFFFFFFFL & readInt(ctx);
break;
case DECIMAL_TYPE_SIGNED:
baseValue = readInt(ctx);
break;
default:
break;
}
if (DDMIMeta.CONV.partOf(this)) {
baseValue = DDMIMeta.CONV.of(this).apply(baseValue);
}
return baseValue;
}
public String getValueAsSting(DDMIContext ctx) {
switch (_type) {
case INTEGER_TYPE:
int v = readInt(ctx);
if (DDMIMeta.LOOKUP.partOf(this)) {
DDMIMeta.LookupTable lut = DDMIMeta.LOOKUP.of(this);
return String.format("%s (%02d)", lut.get(v), v);
} else {
return String.format("%d", v);
}
case TEXT_TYPE:
return readString(ctx);
case DECIMAL_TYPE_FLOAT:
case DECIMAL_TYPE_UNSIGNED:
case DECIMAL_TYPE_SIGNED:
return String.format("%.3f", readDecimal(ctx));
default:
StringBuilder sb = new StringBuilder();
for (byte b : readRaw(ctx))
{
sb.append(String.format("%02x ", 0xFF & b));
}
return sb.toString();
}
}
}
......@@ -118,6 +118,10 @@ public abstract class DataSource {
}
}
public void clear(DDMIContext ctx) {
ctx.scratch.remove(key);
}
}
......@@ -268,4 +272,12 @@ public abstract class DataSource {
_caches.add(new Cache(start, end));
}
public void clearCache(DDMIContext ctx)
{
if (_caches == null) return;
for (Cache c : _caches) {
c.clear(ctx);
}
}
}
\ No newline at end of file
package nl.nikhef.sfp.ddmi;
import java.util.logging.Logger;
import nl.nikhef.sfp.SFPManager;
import nl.nikhef.tools.Utils;
public class PageDataSource extends DataSource {
private static final Logger LOG = Logger.getLogger(PageDataSource.class.getSimpleName());
private final DataSource _parent;
private final int _pageNo;
......@@ -22,12 +30,13 @@ public class PageDataSource extends DataSource {
private void selectPage(DDMIContext ctx)
{
LOG.info("Selecting page " + _pageNo);
if (_parent.getPageSelect() == -1)
throw new RuntimeException("Parent has no page select!");
byte[] pageData = new byte[] { (byte)_pageNo };
_parent.writeMedia(ctx, getPageSelect(), pageData);
_parent.writeMedia(ctx, _parent.getPageSelect(), pageData);
}
......@@ -35,13 +44,16 @@ public class PageDataSource extends DataSource {
byte[] readMedia(DDMIContext ctx, int off, int len)
{
selectPage(ctx);
return _parent.readMedia(ctx, off, len);
byte[] dta = _parent.readMedia(ctx, off, len);
// Utils.dumpHex("Page: " + _pageNo + ", Reading " + off + ":" + len, dta);
return dta;
}
@Override
void writeMedia(DDMIContext ctx, int off, byte[] data)
{
selectPage(ctx);
Utils.dumpHex("Page: " + _pageNo + ", Writign " + off + ":" + data.length, data);
_parent.writeMedia(ctx, off, data);
}
......
......@@ -262,22 +262,22 @@
</group>
<group label="Real-time diagnostics" name="rt_diag">
<signed label="Temperature" offset="96" length="2" monitor="true" name="temperature">
<convert scale="0.00390625" />
</signed>
<signed label="Vcc" offset="98" length="2" monitor="true" name="vcc">
<convert scale="0.00390625" />
</signed>
<signed label="TX Bias" offset="100" length="2" monitor="true" name="tx_bias">
<convert scale="0.00390625" />
</signed>
<signed label="TX Power" offset="102" length="2" monitor="true" name="tx_power">
<signed label="Temperature (&#176;C)" offset="96" length="2" monitor="true" name="temperature">
<convert scale="0.00390625" />
</signed>
<unsigned label="Vcc (V)" offset="98" length="2" monitor="true" name="vcc">
<convert scale="0.0001" />
</unsigned>
<unsigned label="TX Bias (mA)" offset="100" length="2" monitor="true" name="tx_bias">
<convert scale="0.002" />
</unsigned>
<unsigned label="TX Power (mW)" offset="102" length="2" monitor="true" name="tx_power">
<convert scale="0.001" />
</unsigned>
<signed label="RX Power" offset="104" length="2" monitor="true" name="rx_bias">
<convert scale="0.00390625" />
</signed>
<unsigned label="RX Power (mW)" offset="104" length="2" monitor="true" name="rx_bias">
<convert scale="0.001" />
</unsigned>
<!-- TODO BEGIN build visual conditional here -->
<signed label="Laser temperature" offset="106" length="2" monitor="true" name="laser_temp">
......@@ -290,8 +290,8 @@
<!-- TODO END build visual conditional here -->
<signed label="TEC current" offset="108" length="2" monitor="true" name="tec_current">
<convert scale="0.00390625" />
<signed label="TEC current (mA)" offset="108" length="2" monitor="true" name="tec_current">
<convert scale="0.1" />
</signed>
<!-- Oh dear, a monitoring, changeable value... -->
......
......@@ -4,27 +4,43 @@ import java.io.IOException;
import javax.xml.stream.XMLStreamException;
import com.ftdi.FTDevice;
import nl.nikhef.rebus.dev.PCA9848;
import nl.nikhef.rebus.ftdi.I2C;
import nl.nikhef.rebus.ftdi.JavaFTD2xxMPSSE;
import nl.nikhef.rebus.ftdi.MPSSE;
import nl.nikhef.sfp.ddmi.DDMI;
import nl.nikhef.sfp.ddmi.DDMIContext;
import nl.nikhef.sfp.ddmi.DDMILoader;
import nl.nikhef.sfp.i2c.I2CLink;
import nl.nikhef.sfp.i2c.SimI2CLink;
import nl.nikhef.tools.Utils;
public class Test2 {
public static void main(String[] args) throws XMLStreamException, IOException {
DDMILoader loader = new DDMILoader();
DDMI ddmi = loader.getDDMI();
I2CLink link = new SimI2CLink("Test");
MPSSE mpsse = new JavaFTD2xxMPSSE(FTDevice.getDevicesBySerialNumber("NK1BYBILA").get(0));
I2C i2c = new I2C(mpsse, 100000, false);
DDMIContext ctx = new DDMIContext(link, ddmi);
PCA9848 mux = new PCA9848(i2c, PCA9848.ADDRESS_HHH);
mux.setSingle(0);
i2c.write(0x50, new byte[] { 0 });
Utils.dumpHex("EEPROM", i2c.read(0x50, 128));
i2c.write(0x51, new byte[] { 127, 2 });
i2c.write(0x51, new byte[] { (byte)132 });
Utils.dumpHex("Page 2", i2c.read(0x51, 2));
mpsse.close();
//DDMIContext ctx = new DDMIContext(link, ddmi);
ddmi.prettyPrint(ctx);
//ddmi.prettyPrint(ctx);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=1.6
......@@ -28,7 +28,7 @@
<target name="compile">
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}" />
<javac srcdir="${src}" destdir="${build}" source="1.6" target="1.6" includeantruntime="no"/>
</target>
......
......@@ -116,10 +116,7 @@ public class SimpleObjectProxy<I> extends XOLProxyBase<I>
m.invoke(_instance, convObj);
return true;
} catch (SecurityException |
IllegalAccessException |
IllegalArgumentException |
InvocationTargetException e) {
} catch (Exception e) {
throw new RuntimeException("Attribute '" + name + "' can not be assigned", e);
}
}
......@@ -137,7 +134,7 @@ public class SimpleObjectProxy<I> extends XOLProxyBase<I>
if (!pType.isAssignableFrom(obj.getInstance().getClass())) return;
m.invoke(_instance, obj.getInstance());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
} catch (Exception e) {
throw new RuntimeException("Parent can not be assigned", e);
}
}
......@@ -170,7 +167,7 @@ public class SimpleObjectProxy<I> extends XOLProxyBase<I>
tmp =_addAllChildMethod;
_addAllChildMethod.invoke(_instance, val);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
} catch (Exception e) {
throw new RuntimeException(String.format("Can not add child to class '%s', using method %s", _clazz.getSimpleName(), tmp), e);
}
}
......@@ -187,7 +184,7 @@ public class SimpleObjectProxy<I> extends XOLProxyBase<I>
try {
m.invoke(_instance, data);
return true;
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
} catch (Exception e) {
throw new RuntimeException("CharacterData can not be assigned", e);
}
}
......
......@@ -9,16 +9,16 @@ package nl.nikhef.tools.xml;
*/
public class SimpleObjectProxyFactory<I> implements XOLProxyFactory<I> {
private Class<? extends I> _class;
private Class<I> _class;
public SimpleObjectProxyFactory(Class<? extends I> clazz)
public SimpleObjectProxyFactory(Class<I> clazz)
{
_class = clazz;
}
@Override
public XOLProxy<? extends I> newProxy() {
return new SimpleObjectProxy<>(_class);
public XOLProxy<I> newProxy() {
return new SimpleObjectProxy<I>(_class);
}
}
......@@ -20,7 +20,7 @@ public class SimpleProxyFactory<I> implements XOLProxyFactory<I> {
public XOLProxy<? extends I> newProxy() {
try {
return _class.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
} catch (Exception e) {
throw new RuntimeException("Failed to instantiate XOLProxy", e);
}
}
......
......@@ -7,9 +7,9 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class Feather {
private final Map<Key, Provider<?>> providers = new ConcurrentHashMap<>();
private final Map<Key, Object> singletons = new ConcurrentHashMap<>();
private final Map<Class, Object[][]> injectFields = new ConcurrentHashMap<>(0);
private final Map<Key, Provider<?>> providers = new ConcurrentHashMap<Key, Provider<?>>();
private final Map<Key, Object> singletons = new ConcurrentHashMap<Key, Object>();
private final Map<Class, Object[][]> injectFields = new ConcurrentHashMap<Class, Object[][]>(0);
/**
* Constructs Feather with configuration modules
......@@ -82,7 +82,7 @@ public class Feather {
Field field = (Field) f[0];
Key key = (Key) f[2];
try {
field.set(target, (boolean) f[1] ? provider(key) : instance(key));
field.set(target, (Boolean) f[1] ? provider(key) : instance(key));
} catch (Exception e) {
throw new FeatherException(String.format("Can't inject field %s in %s", field.getName(), target.getClass().getName()));
}
......@@ -202,7 +202,7 @@ public class Feather {
private static Set<Key> append(Set<Key> set, Key newKey) {
if (set != null && !set.isEmpty()) {
Set<Key> appended = new LinkedHashSet<>(set);
Set<Key> appended = new LinkedHashSet<Key>(set);
appended.add(newKey);
return appended;
} else {
......@@ -232,7 +232,7 @@ public class Feather {
private static Set<Field> fields(Class<?> type) {
Class<?> current = type;
Set<Field> fields = new HashSet<>();
Set<Field> fields = new HashSet<Field>();
while (!current.equals(Object.class)) {
for (Field field : current.getDeclaredFields()) {
if (field.isAnnotationPresent(Inject.class)) {
......@@ -278,7 +278,7 @@ public class Feather {
private static Set<Method> providers(Class<?> type) {
Class<?> current = type;
Set<Method> providers = new HashSet<>();
Set<Method> providers = new HashSet<Method>();
while (!current.equals(Object.class)) {
for (Method method : current.getDeclaredMethods()) {
if (method.isAnnotationPresent(Provides.class) && (type.equals(current) || !providerInSubClass(method, providers))) {
......
......@@ -18,21 +18,21 @@ public class Key<T> {
* @return Key for a given type
*/
public static <T> Key<T> of(Class<T> type) {
return new Key<>(type, null, null);
return new Key<T>(type, null, null);
}
/**
* @return Key for a given type and qualifier annotation type
*/
public static <T> Key<T> of(Class<T> type, Class<? extends Annotation> qualifier) {
return new Key<>(type, qualifier, null);
return new Key<T>(type, qualifier, null);
}
/**
* @return Key for a given type and name (@Named value)
*/
public static <T> Key<T> of(Class<T> type, String name) {
return new Key<>(type, Named.class, name);
return new Key<T>(type, Named.class, name);
}
static <X> Key<X> of(Class<X> type, Annotation qualifier) {
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="src" path="/nikhef-tools"/>
<classpathentry kind="lib" path="lib/jna-4.3.0.jar"/>
<classpathentry kind="output" path="bin"/>
......
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
......@@ -15,7 +15,6 @@
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="jar" value="rebus.jar"/>
<property name="lib" location="lib"/>
<target name="default" depends="jar" />
......@@ -23,12 +22,18 @@
<jar destfile="${jar}">
<fileset dir="${build}" />
<fileset dir="${src}" includes="natives/**/*"/>
</jar>
</target>
<target name="compile">
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}" classpath="${lib}/JavaFTD2XX-0.2.6.jar"/>
<javac srcdir="${src}" destdir="${build}" source="1.6" target="1.6" includeantruntime="no">
<classpath>
<pathelement location="../nikhef-tools/nikhef-tools.jar"/>
<pathelement location="lib/jna-4.3.0.jar"/>
</classpath>
</javac>
</target>
<target name="clean">
......
......@@ -110,7 +110,6 @@ public abstract class MPSSE {
protected void cmd(int cmd, int[] toSend, int[] toRecv) throws IOException
{
// System.out.printf("Command: %02X send=%d recv=%d\n", cmd, toSend == null ? 0 : toSend.length, toRecv == null ? 0 : toRecv.length);
try {
checkQueue();
if (toSend == null) toSend = new int[0];
......@@ -130,12 +129,6 @@ public abstract class MPSSE {
toRecv[i] = 0xFF & rx[i];
}
checkQueue();
} catch (Throwable t) {
//System.out.println(" -> Error:");
t.printStackTrace();
throw t;
}
// System.out.println(" -> Ok!");
}
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry combineaccessrules="false" kind="src" path="/rebus"/>
<classpathentry combineaccessrules="false" kind="src" path="/jsfp"/>
<classpathentry kind="lib" path="lib/miglayout-4.0-swing.jar">
......
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=1.6
......@@ -9,7 +9,7 @@
====================================================================== -->
<project name="safaripark" default="default">
<description>
Java Bus Emulator Interface
SaFariPark
</description>
<property name="src" location="src"/>
......@@ -19,7 +19,7 @@
<property name="jsfp" location="../jsfp/jsfp.jar" />
<property name="tools" location="../nikhef-tools/nikhef-tools.jar" />
<property name="lua" value="../jsfp/lib/luaj-jse-3.0.1.jar"/>
<property name="ftdi" value="../rebus/lib/JavaFTD2XX-0.2.6.jar"/>
<property name="jna" value="../rebus/lib/jna-4.3.0.jar"/>
<property name="mig" value="lib/miglayout-4.0-swing.jar"/>
......@@ -37,28 +37,36 @@
<ant dir="../jsfp" />
</target>
<target name="dist" depends="compile">
<mkdir dir="${dist}"/>
<jar destfile="${dist}/safaripark.jar">
<fileset dir="${build}" />
<fileset dir="${src}"
includes="**/*.png"
/>
</jar>
<copy file="${rebus}" todir="${dist}"/>
<copy file="${jsfp}" todir="${dist}"/>
<copy file="${tools}" todir="${dist}"/>
<copy file="${ftdi}" todir="${dist}"/>
<copy file="${jna}" todir="${dist}"/>
<copy file="${lua}" todir="${dist}"/>
<copy file="${mig}" todir="${dist}"/>
<copy todir="${dist}/overlays">
<fileset dir="overlays"/>
</copy>
<echo file="${dist}/safaripark.bat">@echo off
java -cp "rebus.jar;JavaFTD2XX-0.2.6.jar;nikhef-tools.jar;luaj-jse-3.0.1.jar;jsfp.jar;safaripark.jar" nl.nikhef.safaripark.SaFariPark
java -cp "rebus.jar;jna-4.3.0.jar;nikhef-tools.jar;luaj-jse-3.0.1.jar;jsfp.jar;safaripark.jar;miglayout-4.0-swing.jar" nl.nikhef.safaripark.SaFariPark
pause
</echo>
</target>
<target name="compile" depends="jsfp">
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}">
<javac srcdir="${src}" destdir="${build}" source="1.6" target="1.6" includeantruntime="no">
<classpath>
<pathelement location="${ftdi}"/>
<pathelement location="${jna}"/>
<pathelement location="${rebus}"/>
<pathelement location="${jsfp}"/>
<pathelement location="${tools}"/>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Adds support for the Maxim DS1856M -->
<overlay>
<group id="root">
<group label="Tunable SFP" source-id="diag_p2" showIf="isset(id.montype, 6)">
<bitmap label="Dithering" writable="false" offset="128" length="1" name="dithering"
level="debug">
<bool bit="0">Selection in 50PPM steps</bool>
<bool bit="1">Selection by channel number></bool>
<bool bit="2">TX Dither supported</bool>
</bitmap>
<group label="Laser capabilities">
<int label="First Frequency (THz)" writable="false" name="LFL1" offset="132" length="2" level="basic" />
<unsigned label="First Frequency (GHz)" writable="false" name="LFL2" offset="134" length="2" level="basic">
<convert scale="0.1"/>
</unsigned>
<int label="Last Frequency (THz)" writable="false" name="LFH1" offset="136" length="2" level="basic" />
<unsigned label="Last Frequency (GHz)" writable="false" name="LFH2" offset="138" length="2" level="basic">
<convert scale="0.1"/>
</unsigned>
<unsigned label="Minimum grid spacing (GHz)" writable="false" name="LGrid" offset="140" length="2" level="basic" >
<convert scale="0.1"/>
</unsigned>
</group>
<group label="Frequency and wavelength control">
<int label="Channel number set" writable="true" name="chno_set" offset="144" length="2" level="basic" />
<unsigned label="Wavelength set (nm)" writable="true" name="wl_set" offset="146" length="2" level="basic" >
<convert scale="0.05"/>
</unsigned>
<bitmap label="Other options" writable="true" name="tx_dither" offset="151" length="1" level="basic">
<bool bit="0">Disable dithering</bool>
</bitmap>
</group>
<group label="Status and Alarms">
<int label="Error frequency" writable="false" name="err_f" offset="152" length="2" level="basic" />
<int label="Error wavelength" writable="false" name="err_wl" offset="154" length="2" level="basic" />
<bitmap label="Current status" writable="false" name="current_status" offset="168" length="1" level="basic">
<bool bit="4">TX tune</bool>
<bool bit="5">Wavelength Unlocked</bool>
<bool bit="6">TEC Fault</bool>
</bitmap>
<bitmap label="Latched status" writable="false" name="latched_status" offset="172" length="1" level="basic">
<bool bit="2">Unsupported TX Dither</bool>
<bool bit="3">New Channel acquired</bool>
<bool bit="4">Bad Channel requested</bool>
<bool bit="5">Wavelength Unlocked</bool>
<bool bit="6">TEC Fault</bool>
</bitmap>
</group>
</group>
</group>
</overlay>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Adds support for the Maxim DS1856M -->
<overlay>
<source id="diag_p0">
<checksum offset="247" start="128" end="246"/>
<cache start="128" end="247"/>
</source>
<group id="root">
<group label="Loopback SFP" source-id="diag_p0" showIf="isset(id.montype, 6)">
<bitmap label="Magic Value" writable="true" offset="128" length="2" name="magic" level="basic" />
<int label="Version" writable="true" offset="130" length="1" name="version" level="basic" />
<bitmap label="Calibration Date" writable="true" offset="131" length="3" name="cal_date" level="basic" />
<bitmap label="OUI responsible" writable="true" offset="134" length="3" name="cal_oui" level="basic" />
<unsigned label="Tx-to-Rx Delay (ps)" writable="true" offset="140" length="4" name="tx2rx_dly" level="basic" >
<convert scale="0.0000152587890625"/>
</unsigned>
<unsigned label="Tx-to-Out Delay (ps)" writable="true" offset="144" length="4" name="tx2out_dly" level="basic" >
<convert scale="0.0000152587890625"/>
</unsigned>
<unsigned label="Rx-to-Out Delay (ps)" writable="true" offset="148" length="4" name="rx2out_dly" level="basic" >
<convert scale="0.0000152587890625"/>
</unsigned>
</group>
</group>
</overlay>
......@@ -22,7 +22,7 @@ public class ActiveLogArea extends TextArea {
gLogger.addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
public void publish(final LogRecord record) {
SwingUtilities.invokeLater(new Runnable() {
@Override
......
......@@ -10,11 +10,14 @@ import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.LogManager;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
......@@ -31,9 +34,13 @@ import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.xml.stream.XMLStreamException;
import org.codejargon.feather.Feather;
import org.codejargon.feather.Provides;
import nl.nikhef.safaripark.devmgr.BaySelectionListener;
import nl.nikhef.safaripark.devmgr.DeviceManager;
import nl.nikhef.safaripark.editpane.EditPane;
import nl.nikhef.safaripark.extra.GuiUtils;
import nl.nikhef.safaripark.monitor.Monitor;
import nl.nikhef.safaripark.res.Resources;
import nl.nikhef.sfp.SFPDevice;
......@@ -72,7 +79,8 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
public SaFariPark() throws IOException, XMLStreamException
@Inject
public SaFariPark(SFPManager sfpMgr, DDMILoader loader, OverlayManager ovlMgr) throws IOException, XMLStreamException
{
......@@ -82,13 +90,9 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
setIconImage(loadImage("res/appicon.png"));
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
_sfpManager = new SFPManager();
_loader = new DDMILoader();
_ovlMgr = new OverlayManager();
_ovlMgr.scanDirectory(new File("overlays"));
_loader.loadOverlays(_ovlMgr.getOverlays());
_sfpManager = sfpMgr;
_loader = loader;
_ovlMgr = ovlMgr;
_ctxCache = new ContextCache(_sfpManager, _loader);
_devMgr = new DeviceManager(_sfpManager);
......@@ -140,11 +144,44 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
{
JToolBar tb = new JToolBar();
tb.add(_selectOverlays);
GuiUtils.toolbarTextButtions(tb);
add(tb, BorderLayout.NORTH);
}
private static class SaFariParkModule
{
@Provides
@Singleton
OverlayManager ovlMgr() {
OverlayManager ovlMgr = new OverlayManager();
ovlMgr.scanDirectory(new File("overlays"));
return ovlMgr;
}
@Provides
@Singleton
DDMILoader ddmiLoader(OverlayManager ovl) throws IOException, XMLStreamException {
DDMILoader loader = new DDMILoader();
loader.loadOverlays(ovl.getOverlays());
return loader;
}
}
public static void main(String[] args)
{
System.out.printf("Starting SaFariPark on %s Java %s (%s bit) and %s (OS=%s, %s)\n",
System.getProperty("java.vendor"),
System.getProperty("java.version"),
System.getProperty("sun.arch.data.model") ,
System.getProperty("os.name"),
System.getProperty("os.version"),
System.getProperty("os.arch"));
Locale.setDefault(Locale.US);
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
......@@ -168,6 +205,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
}
}
/*
SaFariPark sfpE;
try {
sfpE = new SaFariPark();
......@@ -177,7 +215,12 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
e.printStackTrace();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}*/
Feather feather = Feather.with(new SaFariParkModule());
SaFariPark sfpE = feather.instance(SaFariPark.class);
sfpE.setVisible(true);
sfpE.init();
}
......
package nl.nikhef.safaripark.editpane;
import java.awt.BorderLayout;
import java.text.DecimalFormat;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.NumberFormatter;
import nl.nikhef.sfp.ddmi.DDMIValue;
......@@ -13,13 +16,16 @@ import nl.nikhef.sfp.ddmi.DDMIValue;
public class DecimalEditor extends ValueEditor implements DocumentListener {
private JTextField _tf;
private JFormattedTextField _tf;
private boolean _ignoreEvents = false;
public DecimalEditor(EditorContext ctx, DDMIValue value, JLabel label) {
super(ctx, value, label);
setLayout(new BorderLayout());
_tf = new JTextField();
DecimalFormat dec = new DecimalFormat();
dec.setMaximumFractionDigits(6);
dec.setGroupingUsed(false);
_tf = new JFormattedTextField(new NumberFormatter(dec));
add(_tf, BorderLayout.CENTER);
_tf.getDocument().addDocumentListener(this);
clearValue();
......@@ -31,8 +37,7 @@ public class DecimalEditor extends ValueEditor implements DocumentListener {
_tf.setEnabled(isValueValid());
_tf.setEditable(value.isWritable());
_ignoreEvents = true;
String text = String.format("%f", getAsDecimal());
_tf.setText(text);
_tf.setValue(getAsDecimal());
_ignoreEvents = false;
}
......@@ -49,9 +54,12 @@ public class DecimalEditor extends ValueEditor implements DocumentListener {
private void valueUpdated() {
if (_ignoreEvents) return;
float v = Number.class.cast(_tf.getValue()).floatValue();
setAsDecimal(v);
// setAsString(_tf.getText());
}
@Override
public void insertUpdate(DocumentEvent e) {
valueUpdated();
......
......@@ -18,6 +18,7 @@ import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import nl.nikhef.safaripark.ContextCache;
import nl.nikhef.safaripark.extra.GuiUtils;
import nl.nikhef.safaripark.res.Resources;
import nl.nikhef.sfp.SFPDevice;
import nl.nikhef.sfp.ddmi.DDMI;
......@@ -57,6 +58,15 @@ public class EditPane extends JPanel {
}
};
private Action _reload = new AbstractAction("Reload", Resources.getIcon("arrow-refresh")) {
@Override
public void actionPerformed(ActionEvent e) {
_ctx.reload();
}
};
public EditPane(ContextCache ctxCache) {
......@@ -66,27 +76,23 @@ public class EditPane extends JPanel {
_ctxCache = ctxCache;
_ctx = new EditorContext(_apply, _revert);
_ctx = new EditorContext(_apply, _revert, _reload);
_tbar = new JToolBar("Form Editor");
_apply.setEnabled(false);
_revert.setEnabled(false);
_reload.setEnabled(false);
//_tbar.set
List<JButton> buttons = new ArrayList<JButton>();
buttons.add(_tbar.add(_apply));
buttons.add(_tbar.add(_revert));
_tbar.add(_apply);
_tbar.add(_revert);
_tbar.add(_reload);
for (JButton but : buttons) {
but.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
but.setHideActionText(false);
but.setHorizontalTextPosition(SwingConstants.TRAILING);
but.setVerticalTextPosition(SwingConstants.CENTER);
}
GuiUtils.toolbarTextButtions(_tbar);
add(_tbar, BorderLayout.NORTH);
_tab = new JTabbedPane();
......@@ -110,7 +116,9 @@ public class EditPane extends JPanel {
{
_apply.setEnabled(false);
_revert.setEnabled(false);
// TODO Remove checksum test from this location. Should be generic
if (dev.isModulePresent(bay)) {
DDMIContext ctx = _ctxCache.getContextFor(dev, bay);
......@@ -125,8 +133,10 @@ public class EditPane extends JPanel {
_ctx.getContext().updateChecksums();
}
}
_reload.setEnabled(true);
} else {
_ctx.setContext(null);
_reload.setEnabled(false);
}
}
......
......@@ -8,6 +8,7 @@ import java.util.Set;
import javax.swing.Action;
import nl.nikhef.sfp.ddmi.DDMIContext;
import nl.nikhef.sfp.ddmi.DataSource;
/**
......@@ -25,10 +26,12 @@ public class EditorContext
private boolean _batchProc = false;
private Action _apply;
private Action _revert;
private Action _reload;
public EditorContext(Action apply, Action revert) {
public EditorContext(Action apply, Action revert, Action reload) {
_apply = apply;
_revert = revert;
_reload = reload;
}
void addEditor(ValueEditor editor)
......@@ -71,9 +74,15 @@ public class EditorContext
if (someAreDirty()) {
_apply.setEnabled(true);
_revert.setEnabled(true);
_reload.setEnabled(false);
} else {
_apply.setEnabled(false);
_revert.setEnabled(false);
if (_ctx != null) {
_reload.setEnabled(true);
} else {
_reload.setEnabled(false);
}
}
}
......@@ -104,6 +113,19 @@ public class EditorContext
updateButtons();
}
public void reload() {
if (_ctx == null) return;
for (DataSource ds : _ctx.getDDMI().getSources()) {
ds.clearCache(_ctx);
}
for (ValueEditor ve : _editor)
{
ve.updateEditor();
}
}
public DDMIContext getContext()
{
......@@ -111,6 +133,8 @@ public class EditorContext
}
public void changeDirtyState(ValueEditor valueEditor) {
if (_batchProc) return;
if (valueEditor.dirty)
......@@ -123,5 +147,6 @@ public class EditorContext
}
updateButtons();
}
}
......@@ -26,13 +26,22 @@ public class FormEditPane extends JPanel {
setLayout(new MigLayout("wrap 4", "[sizegroup l, grow 0.3][sizegroup v,grow 0.7][sizegroup l,grow 0.3][sizegroup v,grow 0.7]"));
int col = 0;
for (DDMIElement el : grp.getChildren())
{
if (el instanceof DDMIGroup) {
if (col % 2 == 1) {
add(new JPanel(), "span 2");
col += 1;
}
addGroup(ctx, DDMIGroup.class.cast(el), level);
} else if (el instanceof DDMIValue){
addField(ctx, DDMIValue.class.cast(el), level);
}
col += 1;
}
}
......@@ -49,6 +58,8 @@ public class FormEditPane extends JPanel {
add(titleBar, "span 4, growx");
add(new FormEditPane(ctx, grp, level + 1), "span 4, growx");
// Needed to align everything. Don't know why....
add(new JPanel(), "span 2");
}
private void addField(EditorContext ctx, DDMIValue val, int level) {
......
package nl.nikhef.safaripark.editpane;
import java.awt.BorderLayout;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import javax.swing.JFormattedTextField;
......@@ -20,7 +21,9 @@ public class IntegerEditor extends ValueEditor implements DocumentListener {
public IntegerEditor(EditorContext ctx, DDMIValue value, JLabel label) {
super(ctx, value, label);
setLayout(new BorderLayout());
_tf = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance()));
DecimalFormat dec = new DecimalFormat();
dec.setGroupingUsed(false);
_tf = new JFormattedTextField(new NumberFormatter(dec));
add(_tf, BorderLayout.CENTER);
_tf.getDocument().addDocumentListener(this);
clearValue();
......
......@@ -8,6 +8,7 @@ import javax.swing.JPanel;
import nl.nikhef.sfp.ddmi.AccessException;
import nl.nikhef.sfp.ddmi.DDMIMeta;
import nl.nikhef.sfp.ddmi.DDMIUtils;
import nl.nikhef.sfp.ddmi.DDMIValue;
import nl.nikhef.tools.Utils;
......@@ -104,95 +105,38 @@ public abstract class ValueEditor extends JPanel {
public String getAsString()
{
if (rawValue == null) return "";
return new String(rawValue).trim();
return DDMIUtils.rawToString(value, rawValue);
}
public void setAsString(String str)
{
byte[] newRaw = new byte[value.getLength()];
byte[] strBytes = str.getBytes();
for (int i = 0; i < newRaw.length; i++) {
if (i < strBytes.length) {
newRaw[i] = strBytes[i];
} else {
newRaw[i] = (byte)' ';
}
}
setRawValue(newRaw);
setRawValue(DDMIUtils.stringToRaw(value, str));
}
public int getAsInt()
{
if (rawValue == null) return 0;
if (rawValue.length > 4) throw new AccessException("Can't interpret as integer");
int v = rawValue[0];
for (int i = 1; i < rawValue.length; i++) {
v <<= 8;
v |= 0xFF & rawValue[i];
}
/*
int l = rawValue.length - 1;
int i = rawValue[l];
l--;
while (l >= 0 ) {
i = (i << 8) | (0xFF & rawValue[l]);
l--;
}
*/
return v;
return DDMIUtils.rawToInt(rawValue, value);
}
public void setAsInt(int v)
{
if (rawValue.length > 4) throw new AccessException("Can't interpret as integer");
byte[] b = new byte[rawValue.length];
for (int i = 0; i < b.length; ++i) {
b[i] = (byte)(v & 0xFF);
v >>= 8;
}
setRawValue(b);
setRawValue(DDMIUtils.intToRaw(value, v));
}
public void setAsDecimal(float v)
{
setRawValue(DDMIUtils.decimalToRaw(value, v));
}
public float getAsDecimal() {
float baseValue = Float.NaN;
switch (value.getType()) {
case DECIMAL_TYPE_FLOAT:
baseValue = Float.intBitsToFloat(getAsInt());
break;
case DECIMAL_TYPE_UNSIGNED:
baseValue = 0xFFFFFFFFL & getAsInt();
break;
case DECIMAL_TYPE_SIGNED:
baseValue = getAsInt();
break;
default:
break;
}
if (DDMIMeta.CONV.partOf(value)) {
Utils.dumpHex("Raw value", rawValue);
System.out.println("Converting: " + value.getLabel());
baseValue = DDMIMeta.CONV.of(value).apply(baseValue);
}
return baseValue;
return DDMIUtils.rawToDecimal(value, rawValue);
}
public void commit()
{
......
package nl.nikhef.safaripark.extra;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public final class GuiUtils {
private GuiUtils() {};
public static final void toolbarTextButton(JButton button)
{
button.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
button.setHideActionText(false);
button.setHorizontalTextPosition(SwingConstants.TRAILING);
button.setVerticalTextPosition(SwingConstants.CENTER);
}
public static final void toolbarTextButtions(JToolBar tb)
{
for (Component c: tb.getComponents())
{
if (c instanceof JButton) {
toolbarTextButton(JButton.class.cast(c));
}
}
}
}
......@@ -19,6 +19,7 @@ import nl.nikhef.sfp.SFPProviderListener;
import nl.nikhef.sfp.ddmi.DDMI;
import nl.nikhef.sfp.ddmi.DDMIContext;
import nl.nikhef.sfp.ddmi.DDMIFilter;
import nl.nikhef.sfp.ddmi.DDMIUtils;
import nl.nikhef.sfp.ddmi.DDMIValue;
@SuppressWarnings("serial")
......@@ -115,7 +116,7 @@ public class MonitorModel extends AbstractTableModel implements SFPDeviceListene
DDMIValue val = _columns.get(j);
if (val.isValid(dab.ctx)) {
try {
dab.data[j] = val.getValueAsSting(dab.ctx);
dab.data[j] = DDMIUtils.getValueAsSting(val, dab.ctx);
} catch (Exception e) {
dab.data[j] = "?";
}
......
......@@ -45,7 +45,7 @@ public class CheckBoxNodeEditor extends AbstractCellEditor implements TreeCellEd
return false;
}
public Component getTreeCellEditorComponent(JTree tree, Object value,
public Component getTreeCellEditorComponent(final JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row) {
Component editor = renderer.getTreeCellRendererComponent(tree, value,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment