android: AndrOBD library vendored (no submodule, no git link)

This commit is contained in:
“Naeel”
2026-05-25 09:36:38 +04:00
parent 361fe8803d
commit b3b044572c
193 changed files with 61446 additions and 8 deletions
+275
View File
@@ -0,0 +1,275 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.ProcessVar;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
/**
* @author esh
*/
class ProcessVarBeanInfo extends SimpleBeanInfo
{
// Bean descriptor//GEN-FIRST:BeanDescriptor
/*lazy BeanDescriptor*/
private static BeanDescriptor getBdescriptor()
{
// Here you can add code for customizing the BeanDescriptor.
return new BeanDescriptor(ProcessVar.class, PvDetailPanel.class);
}//GEN-LAST:BeanDescriptor
// Property identifiers//GEN-FIRST:Properties
private static final int PROPERTY_empty = 0;
private static final int PROPERTY_keyAttribute = 1;
private static final int PROPERTY_keyValue = 2;
private static final int PROPERTY_valueMap = 3;
// Property array
/*lazy PropertyDescriptor*/
private static PropertyDescriptor[] getPdescriptor()
{
PropertyDescriptor[] properties = new PropertyDescriptor[4];
try
{
properties[PROPERTY_empty] = new PropertyDescriptor("empty", ProcessVar.class, "isEmpty", null);
properties[PROPERTY_keyAttribute] = new PropertyDescriptor("keyAttribute", ProcessVar.class, "getKeyAttribute", "setKeyAttribute");
properties[PROPERTY_keyValue] = new PropertyDescriptor("keyValue", ProcessVar.class, "getKeyValue", "setKeyValue");
properties[PROPERTY_valueMap] = new PropertyDescriptor("valueMap", ProcessVar.class, "getValueMap", "setValueMap");
properties[PROPERTY_valueMap].setPropertyEditorClass(PvDetailPanel.class);
} catch (IntrospectionException ignored)
{
}//GEN-HEADEREND:Properties
// Here you can add code for customizing the properties array.
return properties;
}//GEN-LAST:Properties
// EventSet identifiers//GEN-FIRST:Events
private static final int EVENT_pvChangeListener = 0;
// EventSet array
/*lazy EventSetDescriptor*/
private static EventSetDescriptor[] getEdescriptor()
{
EventSetDescriptor[] eventSets = new EventSetDescriptor[1];
try
{
eventSets[EVENT_pvChangeListener] = new EventSetDescriptor(com.fr3ts0n.pvs.ProcessVar.class, "pvChangeListener", com.fr3ts0n.pvs.PvChangeListener.class, new String[]{"pvChanged"}, "addPvChangeListener", "removePvChangeListener");
} catch (IntrospectionException ignored)
{
}//GEN-HEADEREND:Events
// Here you can add code for customizing the event sets array.
return eventSets;
}//GEN-LAST:Events
// Method identifiers//GEN-FIRST:Methods
private static final int METHOD_addPvChangeListener0 = 0;
private static final int METHOD_clear1 = 1;
private static final int METHOD_clone2 = 2;
private static final int METHOD_containsKey3 = 3;
private static final int METHOD_containsValue4 = 4;
private static final int METHOD_entrySet5 = 5;
private static final int METHOD_equals6 = 6;
private static final int METHOD_get7 = 7;
private static final int METHOD_hashCode8 = 8;
private static final int METHOD_keySet9 = 9;
private static final int METHOD_put10 = 10;
private static final int METHOD_putAll11 = 11;
private static final int METHOD_pvChanged12 = 12;
private static final int METHOD_remove13 = 13;
private static final int METHOD_size14 = 14;
private static final int METHOD_toString15 = 15;
private static final int METHOD_values16 = 16;
// Method array
/*lazy MethodDescriptor*/
private static MethodDescriptor[] getMdescriptor()
{
MethodDescriptor[] methods = new MethodDescriptor[17];
try
{
methods[METHOD_addPvChangeListener0] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("addPvChangeListener",
com.fr3ts0n.pvs.PvChangeListener.class, Integer.TYPE));
methods[METHOD_addPvChangeListener0].setDisplayName("");
methods[METHOD_clear1] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("clear"));
methods[METHOD_clear1].setDisplayName("");
methods[METHOD_clone2] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("clone"));
methods[METHOD_clone2].setDisplayName("");
methods[METHOD_containsKey3] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("containsKey",
Object.class));
methods[METHOD_containsKey3].setDisplayName("");
methods[METHOD_containsValue4] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("containsValue",
Object.class));
methods[METHOD_containsValue4].setDisplayName("");
methods[METHOD_entrySet5] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("entrySet"));
methods[METHOD_entrySet5].setDisplayName("");
methods[METHOD_equals6] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("equals",
Object.class));
methods[METHOD_equals6].setDisplayName("");
methods[METHOD_get7] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("get",
Object.class));
methods[METHOD_get7].setDisplayName("");
methods[METHOD_hashCode8] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("hashCode"));
methods[METHOD_hashCode8].setDisplayName("");
methods[METHOD_keySet9] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("keySet"));
methods[METHOD_keySet9].setDisplayName("");
methods[METHOD_put10] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("put",
Object.class, Object.class, Integer.TYPE));
methods[METHOD_put10].setDisplayName("");
methods[METHOD_putAll11] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("putAll",
java.util.Map.class, Integer.TYPE, Boolean.TYPE));
methods[METHOD_putAll11].setDisplayName("");
methods[METHOD_pvChanged12] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("pvChanged",
com.fr3ts0n.pvs.PvChangeEvent.class));
methods[METHOD_pvChanged12].setDisplayName("");
methods[METHOD_remove13] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("remove",
Object.class));
methods[METHOD_remove13].setDisplayName("");
methods[METHOD_size14] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("size"));
methods[METHOD_size14].setDisplayName("");
methods[METHOD_toString15] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("toString"));
methods[METHOD_toString15].setDisplayName("");
methods[METHOD_values16] = new MethodDescriptor(com.fr3ts0n.pvs.ProcessVar.class.getMethod("values"));
methods[METHOD_values16].setDisplayName("");
} catch (Exception ignored)
{
}//GEN-HEADEREND:Methods
// Here you can add code for customizing the methods array.
return methods;
}//GEN-LAST:Methods
private static final int defaultPropertyIndex = -1;//GEN-BEGIN:Idx
private static final int defaultEventIndex = -1;//GEN-END:Idx
@SuppressWarnings("rawtypes")
public BeanInfo[] getAdditionalBeanInfo()
{//GEN-FIRST:Superclass
Class superclass = ProcessVar.class.getSuperclass();
BeanInfo sbi = null;
try
{
sbi = Introspector.getBeanInfo(superclass);//GEN-HEADEREND:Superclass
// Here you can add code for customizing the Superclass BeanInfo.
} catch (IntrospectionException ignored)
{
}
return new BeanInfo[]{sbi};
}//GEN-LAST:Superclass
/**
* Gets the bean's <code>BeanDescriptor</code>s.
*
* @return BeanDescriptor describing the editable
* properties of this bean. May return null if the
* information should be obtained by automatic analysis.
*/
public BeanDescriptor getBeanDescriptor()
{
return getBdescriptor();
}
/**
* Gets the bean's <code>PropertyDescriptor</code>s.
*
* @return An array of PropertyDescriptors describing the editable
* properties supported by this bean. May return null if the
* information should be obtained by automatic analysis.
* If a property is indexed, then its entry in the result array will
* belong to the IndexedPropertyDescriptor subclass of PropertyDescriptor.
* A client of getPropertyDescriptors can use "instanceof" to check
* if a given PropertyDescriptor is an IndexedPropertyDescriptor.
*/
public PropertyDescriptor[] getPropertyDescriptors()
{
return getPdescriptor();
}
/**
* Gets the bean's <code>EventSetDescriptor</code>s.
*
* @return An array of EventSetDescriptors describing the kinds of
* events fired by this bean. May return null if the information
* should be obtained by automatic analysis.
*/
public EventSetDescriptor[] getEventSetDescriptors()
{
return getEdescriptor();
}
/**
* Gets the bean's <code>MethodDescriptor</code>s.
*
* @return An array of MethodDescriptors describing the methods
* implemented by this bean. May return null if the information
* should be obtained by automatic analysis.
*/
public MethodDescriptor[] getMethodDescriptors()
{
return getMdescriptor();
}
/**
* A bean may have a "default" property that is the property that will
* mostly commonly be initially chosen for update by human's who are
* customizing the bean.
*
* @return Index of default property in the PropertyDescriptor array
* returned by getPropertyDescriptors.
* <P> Returns -1 if there is no default property.
*/
public int getDefaultPropertyIndex()
{
return defaultPropertyIndex;
}
/**
* A bean may have a "default" event that is the event that will
* mostly commonly be used by human's when using the bean.
*
* @return Index of default event in the EventSetDescriptor array
* returned by getEventSetDescriptors.
* <P> Returns -1 if there is no default event.
*/
public int getDefaultEventIndex()
{
return defaultEventIndex;
}
}
@@ -0,0 +1,32 @@
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.ProcessVar;
import java.awt.datatransfer.DataFlavor;
class PvDataFlavor extends DataFlavor
{
private static final String PV_MIME_TYPE = "application/processvar";
public PvDataFlavor()
{
super(ProcessVar.class, PV_MIME_TYPE);
}
public PvDataFlavor(String arg0) throws ClassNotFoundException
{
super(arg0);
}
public PvDataFlavor(String arg0, String arg1)
{
super(arg0, arg1);
}
public PvDataFlavor(String arg0, String arg1, ClassLoader arg2)
throws ClassNotFoundException
{
super(arg0, arg1, arg2);
}
}
+255
View File
@@ -0,0 +1,255 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.ProcessVar;
import com.fr3ts0n.pvs.PvChangeEvent;
import com.fr3ts0n.pvs.PvChangeListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.Customizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import javax.swing.text.JTextComponent;
/**
* panel class to display / edit a parocess variable and all it's attributes
*
* @author $Author: erwin $
*/
public class PvDetailPanel extends JPanel
implements ActionListener, PvChangeListener, Customizer
{
/**
*
*/
private static final long serialVersionUID = 740664204205911504L;
// field background colors
private static final Color unchangedColor = Color.white;
private static final Color changedColor = Color.lightGray;
private static final Color labelColor = Color.lightGray;
private static final LineBorder lineBorder = new LineBorder(Color.BLACK);
private final HashMap<Object, JComponent> fields = new HashMap<Object, JComponent>();
private ProcessVar dataSource = null;
private boolean editable = false;
public PvDetailPanel()
{
setLayout(new GridBagLayout());
setBackground(labelColor);
setBorder(lineBorder);
}
/**
* create a panel of detailed information on current process variable
*/
public PvDetailPanel(ProcessVar data)
{
this();
setProcessVar(data);
}
/**
* create a panel of detailed information on current process variable
*/
public PvDetailPanel(ProcessVar data, boolean allowEdit)
{
this();
setEditable(allowEdit);
setProcessVar(data);
}
/**
* set the process var which is assigned to this editor panel
* this creates all corresponding data fields
*/
@SuppressWarnings({"unchecked", "rawtypes"})
private void setProcessVar(ProcessVar data)
{
if (dataSource == null || !dataSource.equals(data))
{
// remove all child components, if they have been set already
if (dataSource != null && !dataSource.equals(data))
{
dataSource.removePvChangeListener(this);
fields.clear();
removeAll();
}
// update data source variable
dataSource = data;
// if data source is anything real ...
if (data != null)
{
Object currKey;
Object currVal;
JLabel hdrCmp;
JComponent dataCmp;
GridBagConstraints attr = new GridBagConstraints();
// ... fill content panel with data
ArrayList keys = new ArrayList(data.keySet());
// sort list alphabetically
Collections.sort(keys);
Iterator it = keys.iterator();
// loop through all attributes
while (it.hasNext())
{
/* set default attributes */
attr.gridwidth = 1;
attr.gridheight = 1;
attr.weightx = 0.0;
attr.fill = GridBagConstraints.BOTH;
if ((currKey = it.next()) != null)
{
hdrCmp = new JLabel(currKey.toString());
hdrCmp.setBackground(labelColor);
hdrCmp.setBorder(lineBorder);
// setup data component based on it's value
if ((currVal = data.get(currKey)) == null)
{
dataCmp = new JLabel();
} else
{
if (currVal instanceof ProcessVar)
{
dataCmp = new PvDetailPanel((ProcessVar) currVal, editable);
} else
{
dataCmp = new JTextField(data.get(currKey).toString());
((JTextField) dataCmp).setEditable(editable);
((JTextField) dataCmp).addActionListener(this);
}
}
dataCmp.setName(currKey.toString());
// add the components
add(hdrCmp, attr);
attr.gridwidth = GridBagConstraints.REMAINDER;
attr.weightx = 1.0;
add(dataCmp, attr);
// add data component to Hashmap of fields
fields.put(currKey, dataCmp);
}
}
// add 'this' panel as PvChangeListener to Process variable
data.addPvChangeListener(this, PvChangeEvent.PV_ADDED | PvChangeEvent.PV_MODIFIED);
}
validate();
}
}
/** Implementation of Customizer interface */
public void setObject(Object bean)
{
setEditable(true);
setProcessVar((ProcessVar) bean);
}
/** return the process var which is assigned to this editor panel */
public ProcessVar getProcessVar()
{
return (dataSource);
}
/** return if the process this editor panel is editable */
public boolean getEditable()
{
return (editable);
}
/** set this editor panel to be non-/editable */
private void setEditable(boolean newEditable)
{
editable = newEditable;
}
/**
* action handler for edit fields within panel
* this handler also temporarily changes the color of the edit field to
* visibly indicate the update action.
*/
public void actionPerformed(ActionEvent e)
{
// find out which field sends the event
JTextField edit = (JTextField) e.getSource();
// update the corresponding process var
dataSource.put(edit.getName(), edit.getText(), PvChangeEvent.PV_MANUAL_MOD);
// indicate change by changing field's background color
edit.setBackground(changedColor);
Toolkit.getDefaultToolkit().beep();
}
protected void finalize() throws Throwable
{
dataSource.removePvChangeListener(this);
fields.clear();
removeAll();
super.finalize();
}
/**
* handler for process variable changes
* update dialog element from process variable
*/
public void pvChanged(PvChangeEvent event)
{
// only update panel if it is displayable
if (isDisplayable())
{
Component edit = fields.get(event.getKey());
Object value = event.getValue();
// if we have found the corresponding editor field ...
if (edit != null)
{
// set the value and background for it
edit.setBackground(event.getType() == PvChangeEvent.PV_MANUAL_MOD ? changedColor : unchangedColor);
if (edit instanceof JTextComponent)
{
((JTextComponent) edit).setText(value != null ? value.toString() : "");
} else if (edit instanceof JLabel)
{
((JLabel) edit).setText(value != null ? value.toString() : "");
} else if (edit instanceof PvDetailPanel)
{
((PvDetailPanel) edit).setProcessVar((ProcessVar) value);
}
}
}
}
}
+143
View File
@@ -0,0 +1,143 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.ProcessVar;
import com.fr3ts0n.pvs.PvList;
import java.awt.Dimension;
import java.awt.ScrollPane;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.DropMode;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
public class PvExplorer extends JSplitPane implements TreeSelectionListener
{
/** unique serial version ID */
private static final long serialVersionUID = 182596839340890403L;
/** root process variable for tree and initial table display */
ProcessVar pvRoot;
/** PV tree display */
private final JTree pvTree;
/** PV table display */
private final PvTable pvTable;
/** PV List as container for single process variables to be displayed in table */
private final PvList tblList = new PvList();
/** PV transfer handler to handle data transfers within explorer */
private final PvTransferHandler xferHdlr = new PvTransferHandler();
public PvExplorer(ProcessVar pv)
{
setDividerSize(2);
setPreferredSize(new Dimension(640, 480));
pvTree = new JTree(new PvTreeNode(pv));
pvTree.getSelectionModel().addTreeSelectionListener(this);
pvTree.setDragEnabled(true);
pvTree.setDropMode(DropMode.ON_OR_INSERT);
pvTree.setTransferHandler(xferHdlr);
pvTable = new PvTable(pv);
pvTable.setDragEnabled(true);
pvTable.setDropMode(DropMode.ON_OR_INSERT);
pvTable.addMouseListener(tblMouseLstnr);
pvTable.setTransferHandler(xferHdlr);
JScrollPane spPvTree = new JScrollPane(pvTree);
add(spPvTree, JSplitPane.LEFT);
JScrollPane spPvTable = new JScrollPane(pvTable);
add(spPvTable, JSplitPane.RIGHT);
}
@Override
public void valueChanged(TreeSelectionEvent e)
{
TreePath selPath = e.getNewLeadSelectionPath();
if (selPath == null)
return;
ProcessVar pv = PvTreeNode.getPvFromTreePath(selPath);
if (pv instanceof PvList)
{
// if process var is a PV list itself then show it in table
pvTable.setProcessVar(pv);
} else
{
// ... otherwise create a list with PV as contained element
tblList.clear();
tblList.put(pv.getKeyValue(), pv);
pvTable.setProcessVar(tblList);
}
}
/**
* Listener for mouse events on table side
*/
private final MouseListener tblMouseLstnr = new MouseListener()
{
@Override
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() > 1)
{
// find the process var to selected row ...
ProcessVar pv = pvTable.getPvModel().getElementAt(pvTable.getSelectedRow());
// and show a detail panel about it ...
if (pv != null)
{
PvDetailPanel panDetail = new PvDetailPanel(pv, true);
ScrollPane panScr = new ScrollPane();
panScr.setPreferredSize(new Dimension(640, 480));
panScr.add(panDetail);
JOptionPane.showMessageDialog(null, panScr);
}
}
}
@Override
public void mouseEntered(MouseEvent e)
{
}
@Override
public void mouseExited(MouseEvent e)
{
}
@Override
public void mousePressed(MouseEvent e)
{
}
@Override
public void mouseReleased(MouseEvent e)
{
}
};
}
+89
View File
@@ -0,0 +1,89 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.ProcessVar;
import javax.swing.JTable;
/**
* Table GUI object for process variables
*
* @author erwin
*/
public class PvTable extends JTable
{
/**
*
*/
private static final long serialVersionUID = 6339359674123198139L;
private ProcessVar pv;
private PvTableModel pvModel = new PvTableModel();
private final PvTableCellRenderer renderer = new PvTableCellRenderer();
/** Creates a new instance of PvTable */
public PvTable()
{
setRowSelectionAllowed(true);
setDefaultRenderer(Object.class, renderer);
setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}},
new String[]{
"Title 1", "Title 2", "Title 3", "Title 4"
}));
}
/**
* Creates a new instance of PvTable
*
* @param list The process var to display in table
*/
public PvTable(ProcessVar list)
{
setProcessVar(list);
setRowSelectionAllowed(true);
}
/**
* set the process var
*
* @param list The process var to display in table
*/
public void setProcessVar(ProcessVar list)
{
pv = list;
pvModel.setProcessVar(pv);
setModel(pvModel);
}
public PvTableModel getPvModel()
{
return pvModel;
}
public void setPvModel(PvTableModel pvModel)
{
this.pvModel = pvModel;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,65 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableCellRenderer;
/**
* Cell Renderer for PvTable component
*
* @author erwin
*/
public class PvTableCellRenderer extends JLabel
implements TableCellRenderer
{
/**
*
*/
private static final long serialVersionUID = -7686049090382566048L;
private static final EmptyBorder brdr = new EmptyBorder(0, 5, 0, 5);
/** Creates a new instance of PvTableCellRenderer */
public PvTableCellRenderer()
{
setOpaque(true);
setBorder(brdr);
}
/** render a single pv attribute based on location within table */
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
setFont(table.getFont());
setHorizontalAlignment(value instanceof Number ? RIGHT : LEFT);
setText(String.valueOf(value));
setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
return (this);
}
}
+218
View File
@@ -0,0 +1,218 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.IndexedProcessVar;
import com.fr3ts0n.pvs.ProcessVar;
import com.fr3ts0n.pvs.PvChangeEvent;
import com.fr3ts0n.pvs.PvChangeListener;
import java.util.Arrays;
import javax.swing.table.AbstractTableModel;
/**
* Data Model to represent a ProcessVar within a Table object
*
* @author erwin
*/
public class PvTableModel extends AbstractTableModel
implements PvChangeListener
{
/**
*
*/
private static final long serialVersionUID = -6777148395276846388L;
protected ProcessVar pv;
protected IndexedProcessVar currRow;
protected Object[] keys;
private String[] colHeaders = {};
/** Creates a new instance of PvTableModel */
public PvTableModel()
{
}
/**
* Creates a new instance of PvTableModel
*
* @param pVar the process variable to represent
*/
public PvTableModel(ProcessVar pVar)
{
setProcessVar(pVar);
}
/**
* update th list of key items for correct location of coordinates
*
* @param pv Process variable
*/
private void updateKeys(ProcessVar pv)
{
keys = pv.keySet().toArray();
Arrays.sort(keys);
}
/**
* set the process variable to be represented
*
* @param pVar the process variable to represent
*/
public synchronized void setProcessVar(ProcessVar pVar)
{
// set the pv
pv = pVar;
updateKeys(pVar);
if (keys.length > 0)
{
currRow = (IndexedProcessVar) pv.get(keys[0]);
colHeaders = currRow.getFields();
fireTableStructureChanged();
}
pv.addPvChangeListener(this, PvChangeEvent.PV_ALLEVENTS);
}
/**
* get number of table rows
*
* @return number of rows to show
*/
public int getRowCount()
{
return (keys != null ? keys.length : 0);
}
/**
* return number of columns
*
* @return number of columns
*/
public int getColumnCount()
{
return (colHeaders.length);
}
/**
* get process var for row
* @param rowIndex row index
* @return process var
*/
public IndexedProcessVar getElementAt(int rowIndex)
{
if (rowIndex < getRowCount())
currRow = (IndexedProcessVar) pv.get(keys[rowIndex]);
return currRow;
}
/**
* get the value for table location (x,y)
*
* @param rowIndex row number
* @param columnIndex column number
* @return value for table location
*/
public Object getValueAt(int rowIndex, int columnIndex)
{
Object result = null;
// if the pv is set ...
if (pv != null)
{
// get the column value
if((currRow = getElementAt(rowIndex)) != null)
{
result = currRow.get(columnIndex);
}
}
return (result);
}
/**
* handle a process variable change
*
* @param event the change event to be handled
*/
public synchronized void pvChanged(PvChangeEvent event)
{
Object key;
int rowId;
try
{
if(event.isChildEvent())
{
key = String.valueOf(event.getValue());
}
else
{
key = event.getKey();
}
rowId = key != null ? Arrays.binarySearch(keys, key) : 0;
switch (event.getType())
{
case PvChangeEvent.PV_CONFIRMED:
case PvChangeEvent.PV_MODIFIED:
case PvChangeEvent.PV_MANUAL_MOD:
fireTableRowsUpdated(rowId, rowId);
break;
case PvChangeEvent.PV_ADDED:
if (pv.size() == 1)
{
setProcessVar(pv);
} else
{
updateKeys(pv);
fireTableRowsInserted(rowId, rowId);
}
break;
case PvChangeEvent.PV_DELETED:
updateKeys(pv);
fireTableRowsDeleted(rowId, rowId);
break;
case PvChangeEvent.PV_CLEARED:
if (keys.length > 0)
{
updateKeys(pv);
}
// w/o data there are NO columns available -> structure change
fireTableStructureChanged();
break;
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
/**
* return column name of PID field
*
* @param column specified column number to get name for ...
*/
@Override
public String getColumnName(int column)
{
return (colHeaders[column]);
}
}
+157
View File
@@ -0,0 +1,157 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.ProcessVar;
import com.fr3ts0n.pvs.PvChangeEvent;
import java.awt.Point;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import javax.swing.JComponent;
import javax.swing.JTree;
import javax.swing.TransferHandler;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
/**
* @author se82wi
*/
public class PvTransferHandler extends TransferHandler
{
/** Serial Version ID */
private static final long serialVersionUID = -3156199604384589468L;
private static final PvDataFlavor processVarFlavor = new PvDataFlavor();
public PvTransferHandler()
{
super("userObject");
}
/* (non-Javadoc)
* @see javax.swing.TransferHandler#getSourceActions(JComponent c)
*/
@Override
public int getSourceActions(JComponent c)
{
return COPY_OR_MOVE;
}
/* (non-Javadoc)
* @see javax.swing.TransferHandler#createTransferable(javax.swing.JComponent)
*/
@Override
protected Transferable createTransferable(JComponent c)
{
if (c instanceof JTree)
{
try
{
JTree tree = (JTree) c;
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getSelectionPath().getLastPathComponent();
ProcessVar pv = (ProcessVar) node.getUserObject();
return (Transferable) pv;
} catch (ClassCastException ex)
{
ProcessVar.log.severe(this.toString() + ":" + ex.getMessage());
}
} else if (c instanceof PvTable)
{
PvTable tab = (PvTable) c;
ProcessVar pv = tab.getPvModel().getElementAt(tab.getSelectedRow());
return (Transferable) pv;
}
// anything else is handled by superclass
return super.createTransferable(c);
}
/* (non-Javadoc)
* @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
*/
@Override
protected void exportDone(JComponent c, Transferable t, int action)
{
try
{
if (action == MOVE)
{
ProcessVar pv = (ProcessVar) t.getTransferData(processVarFlavor);
pv.firePvChanged(new PvChangeEvent(pv, pv.getKeyAttribute(), pv, PvChangeEvent.PV_ELIMINATED));
}
} catch (UnsupportedFlavorException e)
{
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
} catch (IOException e)
{
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
}
}
/* (non-Javadoc)
* @see javax.swing.TransferHandler#importData(javax.swing.TransferHandler.TransferSupport)
*/
@Override
public boolean importData(TransferSupport support)
{
try
{
if (support.getComponent() instanceof JTree)
{
JTree tree = (JTree) support.getComponent();
Point dropPoint = support.getDropLocation().getDropPoint();
TreePath path = tree.getPathForLocation(dropPoint.x, dropPoint.y);
Object node = path.getLastPathComponent();
if (support.isDataFlavorSupported(processVarFlavor))
{
ProcessVar tVar = (ProcessVar) ((PvTreeNode) node).getUserObject();
ProcessVar chldPv = (ProcessVar) support.getTransferable().getTransferData(processVarFlavor);
Object chldKey = chldPv.getKeyValue();
tVar.put(chldKey, chldPv, PvChangeEvent.PV_ADDED);
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
model.nodeStructureChanged((TreeNode) model.getRoot());
return true;
}
}
} catch (UnsupportedFlavorException e)
{
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
} catch (IOException e)
{
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
}
// anything else is handled by superclass
return super.importData(support);
}
/* (non-Javadoc)
* @see javax.swing.TransferHandler#canImport(javax.swing.TransferHandler.TransferSupport)
*/
@Override
public boolean canImport(TransferSupport support)
{
return support != null
&& support.isDataFlavorSupported(processVarFlavor);
}
}
+152
View File
@@ -0,0 +1,152 @@
/*
* (C) Copyright 2015 by fr3ts0n <erwin.scheuch-heilig@gmx.at>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
package com.fr3ts0n.pvs.gui;
import com.fr3ts0n.pvs.ProcessVar;
import com.fr3ts0n.pvs.PvChangeEvent;
import com.fr3ts0n.pvs.PvChangeListener;
import java.util.Iterator;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
/**
* @author se82wi
* Tree node from a process variable
*/
public class PvTreeNode extends DefaultMutableTreeNode
implements PvChangeListener
{
/**
* ProcessVar tree node Renderer
*/
private static final long serialVersionUID = 8478304706986978587L;
public PvTreeNode()
{
super();
}
public PvTreeNode(Object userObject)
{
super(userObject);
setUserObject(userObject);
}
/*
* (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);
}
}
/**
* get process variable from tree node
*
* @param path tree path to find object for
* @return process variable, or null if no process variable found
*/
public static ProcessVar getPvFromTreePath(TreePath path)
{
PvTreeNode selNode = (PvTreeNode) path.getLastPathComponent();
if (selNode == null)
return null;
Object pvObj = selNode.getUserObject();
if (!(pvObj instanceof ProcessVar))
return null;
return (ProcessVar) pvObj;
}
/**
* Find child node containing matching user Object
*
* @param userObject user object to match
* @return matching child node, or
* <pre>null</pre> if nothing has been found
*/
private PvTreeNode findChild(Object userObject)
{
PvTreeNode currNode;
// search through children for matching user object
@SuppressWarnings("unchecked")
Iterator<PvTreeNode> it = children.iterator();
while (it.hasNext())
{
currNode = it.next();
if (userObject == currNode.userObject)
return currNode;
}
// haven't found it -> return NULL
return null;
}
/**
* Handler for PvChangeEvents
*/
@Override
public synchronized void pvChanged(PvChangeEvent pvchangeevent)
{
Object currVal = pvchangeevent.getValue();
if (!(currVal instanceof ProcessVar))
return;
switch (pvchangeevent.getType())
{
case PvChangeEvent.PV_ADDED:
add(new PvTreeNode(currVal));
break;
case PvChangeEvent.PV_CLEARED:
removeAllChildren();
break;
case PvChangeEvent.PV_DELETED:
PvTreeNode pvNode = findChild(currVal);
if (pvNode != null)
pvNode.removeFromParent();
}
}
}
+6
View File
@@ -0,0 +1,6 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
Process variable visualization classes
</body>
</html>