use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class PvTreeNode method setUserObject.
/*
* (non-Javadoc)
*
* @see
* javax.swing.tree.DefaultMutableTreeNode#setUserObject(java.lang.Object)
*/
@SuppressWarnings("unchecked")
@Override
public void setUserObject(Object userObject) {
super.setUserObject(userObject);
if (userObject instanceof ProcessVar) {
Object currVal;
ProcessVar pv = (ProcessVar) userObject;
// loop through attributes
Iterator<Object> it = pv.values().iterator();
while (it.hasNext()) {
currVal = it.next();
// if there is a child PV, then add it as a tree node
if (currVal instanceof ProcessVar)
add(new PvTreeNode(currVal));
}
pv.addPvChangeListener(this, PvChangeEvent.PV_ADDED | PvChangeEvent.PV_DELETED | PvChangeEvent.PV_CLEARED | PvChangeEvent.PV_ELIMINATED);
}
}
use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class PvXMLWriter method writePv.
/**
* write a process variable as XML to an output stream
*
* @param pv processVar to write
* @param recursiveDepth Depth of recursive PV writing
* @param completeDoc if TRUE, XML document will be initialized before,
* and finalized after writing this PV
*/
@SuppressWarnings("rawtypes")
public void writePv(ProcessVar pv, int recursiveDepth, boolean completeDoc) {
Object currKey;
Object currVal;
// Initialize XML-Document
if (completeDoc || !documentStarted) {
startDocument();
}
try {
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("", ATTR_TYPE, ATTR_TYPE, "CDATA", pv.getClass().getName());
attrs.addAttribute("", ATTR_KEY, ATTR_KEY, "CDATA", String.valueOf(pv.getKeyValue()));
handler.startElement("", TAG_PROCESSVAR, TAG_PROCESSVAR, attrs);
if (// Loop through all PV-Attributes
recursiveDepth > 0) {
Iterator it = pv.keySet().iterator();
while (it.hasNext()) {
currKey = it.next();
currVal = pv.get(currKey);
attrs.clear();
attrs.addAttribute("", ATTR_NAME, ATTR_NAME, "CDADTA", currKey.toString());
handler.startElement("", TAG_PVATTRIBUTE, TAG_PVATTRIBUTE, attrs);
if (currVal != null) {
// If current value is a PV itself ...
if (currVal instanceof ProcessVar) {
// write recursively
writePv((ProcessVar) currVal, recursiveDepth - 1, false);
} else {
// Otherwise write PV-Data as attribute
String currStr = currVal.toString();
handler.characters(currStr.toCharArray(), 0, currStr.length());
}
}
// finish attribute XML-element
handler.endElement("", TAG_PVATTRIBUTE, TAG_PVATTRIBUTE);
}
}
// finish PV XNL-element
handler.endElement("", TAG_PROCESSVAR, TAG_PROCESSVAR);
} catch (Throwable e) {
e.printStackTrace();
}
// Finalize XML document
if (completeDoc) {
endDocument();
}
}
use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class ObdGaugeAdapter method pvChanged.
@Override
public void pvChanged(PvChangeEvent event) {
ProcessVar currPv = (ProcessVar) event.getSource();
CategorySeries series = (CategorySeries) currPv.get(FID_GAUGE_SERIES);
series.set(0, String.valueOf(currPv.get(EcuDataPv.FID_UNITS)), ((Number) event.getValue()).doubleValue());
}
use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.
the class ObdDataPanel method pvChanged.
/**
* handle changes in the process var(s)
*
* @param event Process var event to be handled
*/
public void pvChanged(PvChangeEvent event) {
TimeSeries ts;
EcuDataPv pv;
switch(event.getType()) {
case PvChangeEvent.PV_MODIFIED:
pv = (EcuDataPv) event.getValue();
if ((ts = selPids.get(getPvId(pv))) != null)
try {
ts.addOrUpdate(new Second(), ((Number) pv.get(EcuDataPv.FID_VALUE)).floatValue());
} catch (Exception e) {
ProcessVar.log.log(Level.SEVERE, "", e);
}
break;
case PvChangeEvent.PV_DELETED:
// remove from selectable PIDs
pv = (EcuDataPv) event.getValue();
selPids.remove(pv);
break;
case PvChangeEvent.PV_CLEARED:
// remove all from selectable PIDs
selPids.clear();
break;
case PvChangeEvent.PV_ADDED:
if ((event.getValue() instanceof EcuDataPv)) {
pv = (EcuDataPv) event.getValue();
addDataSeries(pv);
} else if ((event.getValue() instanceof Object[])) {
for (Object currPv : (Object[]) event.getValue()) {
addDataSeries((ProcessVar) currPv);
}
}
break;
}
// update table column widths
updateColumnWidths();
}
Aggregations