return true;
}
protected Transferable createTransferable(JComponent c) {
if (c.getClass().equals(JTree.class)) {
JTree tree = (JTree) c;
TreePath[] selectedPaths = tree.getSelectionModel()
.getSelectionPaths();
SortedTreeNode[] nodes = getSelectedNodes(tree);
return new SortedTreeNodeTransferable(nodes);
}
return null;
}
public boolean importData(JComponent comp, Transferable t) {
try {
SortedTreeNode[] nodes = (SortedTreeNode[]) t
.getTransferData(myFlavor);
TableRow[] rows = getLeafValues(nodes);
long[] ids = getMoteIds(rows);
boolean[] grants = ReMote.this.getClientMoteAccess().getMoteControlPrivileges(ids,ReMote.this.session.getSessionId());
for (int i=0; i<grants.length;i++)
{
if (!grants[i]){
// FIXME: use a default mote identification string
JOptionPane.showMessageDialog(ReMote.this,"Unable to get control privilege for mote with ID "+ids[i]+".");
}
}
session.getMoteManager().requestMotes(ids);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
};
MoteControlTable table = new MoteControlTable(session
.getMoteManager().getMoteList());
final TableBasedTree treeModel = new TableBasedTree(
table,
"Control",
new TableRowOrdering[] { OrderingsControlledMotesView.BY_NET });
final JTree jTree = new JTree(treeModel);
jTree.setRootVisible(true);
jTree.setCellRenderer(new TableBasedTreeCellRenderer());
jTree.setTransferHandler(moteControlTransferHandler);
jTree.setDragEnabled(true);
jTree.setToggleClickCount(0);
ToolTipManager.sharedInstance().registerComponent(jTree);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
int i;
String cmd = e.getActionCommand();
SortedTreeNode[] nodes = getSelectedNodes(jTree);
TableRow[] rows = getLeafValues(nodes);
long[] motes = getMoteIds(rows);
SimpleMoteManager moteManager = (SimpleMoteManager) session
.getMoteManager();
if (cmd.equals("release")) {
moteManager.releaseMotes(motes);
} else if (cmd.equals("console")) {
for (i = 0; i < rows.length; i++) {
getMoteView((MoteControlRow) rows[i]);
}
} else if (cmd.equals("program")) {
java.util.Properties settings = getSettings();
try {
JFileChooser fc = new JFileChooser(settings
.getProperty("flashImagePath", "/"));
fc.setFileFilter(new FlashImageFilter());
int returnVal = fc
.showOpenDialog(getRootWindow());
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
FileInputStream fi = new FileInputStream(
file);
byte[] bytes = new byte[(int) file.length()];
fi.read(bytes);
moteManager.program(motes, bytes);
fi.close();
settings.setProperty("flashImagePath", file
.getParent());
saveSettings();
}
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (cmd.equals("start")) {
moteManager.start(motes);
} else if (cmd.equals("stop")) {
moteManager.stop(motes);
} else if (cmd.equals("reset")) {
moteManager.reset(motes);
}
}
};
MouseListener ml = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
TreePath selPath = jTree.getPathForLocation(e.getX(), e
.getY());
if (selPath != null && e.getClickCount() > 0) {
TableRow[] rows = getLeafValues(new SortedTreeNode[] { (SortedTreeNode) selPath
.getLastPathComponent() });
for (int i = 0; i < rows.length; i++) {
if (MoteControlRow.class
.isAssignableFrom(rows[i].getClass())) {
MoteControlRow row = (MoteControlRow) rows[i];
if (e.getClickCount() == 1) {
View moteView = (View) moteViews
.get(row);
if (moteView != null) {
moteView.requestFocusInWindow();
DockingWindow parent = moteView
.getWindowParent();
if (parent != null && TabWindow.class
.isAssignableFrom(parent
.getClass())) {
TabWindow tab = (TabWindow) parent;
tab
.setSelectedTab(tab
.getChildWindowIndex(moteView));
}
}
} else if (e.getClickCount() == 2) {
getMoteTabView().addTab(
getMoteView(row));
}
}
}
}
}
};
jTree.addMouseListener(ml);
TreeModelListener treeModelListener = new TreeModelListener() {
public void treeNodesChanged(TreeModelEvent e) {
// TODO Auto-generated method stub
}
public void treeNodesInserted(TreeModelEvent e) {
jTree.expandPath(e.getTreePath().getParentPath());
}
public void treeNodesRemoved(TreeModelEvent e) {
// TODO Auto-generated method stub