Search in sources :

Example 1 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class PvTransferHandler method importData.

/* (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);
}
Also used : JTree(javax.swing.JTree) ProcessVar(com.fr3ts0n.pvs.ProcessVar) TreePath(javax.swing.tree.TreePath) Point(java.awt.Point) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 2 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class PvExplorer method valueChanged.

@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);
    }
}
Also used : PvList(com.fr3ts0n.pvs.PvList) ProcessVar(com.fr3ts0n.pvs.ProcessVar) TreePath(javax.swing.tree.TreePath)

Example 3 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class PvDetailPanel method setProcessVar.

/**
 * set the process var which is assigned to this editor panel
 * this creates all corresponding data fields
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public 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 = null;
            Object currVal = null;
            JLabel hdrCmp = null;
            JComponent dataCmp = null;
            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();
    }
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) ProcessVar(com.fr3ts0n.pvs.ProcessVar) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 4 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class PvTransferHandler method exportDone.

/* (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());
    }
}
Also used : ProcessVar(com.fr3ts0n.pvs.ProcessVar) PvChangeEvent(com.fr3ts0n.pvs.PvChangeEvent) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 5 with ProcessVar

use of com.fr3ts0n.pvs.ProcessVar in project AndrOBD by fr3ts0n.

the class PvTransferHandler method createTransferable.

/* (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 = (ProcessVar) tab.getPvModel().getElementAt(tab.getSelectedRow());
        return (Transferable) pv;
    }
    // anything else is handled by superclass
    return super.createTransferable(c);
}
Also used : JTree(javax.swing.JTree) ProcessVar(com.fr3ts0n.pvs.ProcessVar) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Transferable(java.awt.datatransfer.Transferable)

Aggregations

ProcessVar (com.fr3ts0n.pvs.ProcessVar)9 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 JTree (javax.swing.JTree)2 TreePath (javax.swing.tree.TreePath)2 EcuDataPv (com.fr3ts0n.ecu.EcuDataPv)1 PvChangeEvent (com.fr3ts0n.pvs.PvChangeEvent)1 PvList (com.fr3ts0n.pvs.PvList)1 GridBagConstraints (java.awt.GridBagConstraints)1 Point (java.awt.Point)1 Transferable (java.awt.datatransfer.Transferable)1 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 CategorySeries (org.achartengine.model.CategorySeries)1 Second (org.jfree.data.time.Second)1 TimeSeries (org.jfree.data.time.TimeSeries)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1