+ shortcut for registering identical breakpoints for all motes of a particular mote type (currently only in popup menu)
This commit is contained in:
parent
4fecf3fe1e
commit
e8ca6d4a4e
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: BreakpointsUI.java,v 1.3 2009/06/11 10:06:47 fros4943 Exp $
|
||||
* $Id: BreakpointsUI.java,v 1.4 2009/06/15 09:45:46 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.mspmote.plugins;
|
||||
|
@ -37,10 +37,22 @@ import java.awt.event.ActionListener;
|
|||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import se.sics.cooja.GUI;
|
||||
import se.sics.cooja.Mote;
|
||||
import se.sics.cooja.MoteType;
|
||||
import se.sics.cooja.Simulation;
|
||||
import se.sics.cooja.Watchpoint;
|
||||
import se.sics.cooja.WatchpointMote;
|
||||
import se.sics.cooja.dialogs.MessageList;
|
||||
import se.sics.cooja.mspmote.MspMote;
|
||||
import se.sics.cooja.mspmote.MspMoteType;
|
||||
|
||||
/**
|
||||
* Displays a set of breakpoints.
|
||||
*
|
||||
|
@ -52,6 +64,8 @@ public class BreakpointsUI extends JPanel {
|
|||
private MspBreakpointContainer breakpoints = null;
|
||||
private JTable table = null;
|
||||
|
||||
private MspBreakpoint popupBreakpoint = null;
|
||||
|
||||
public BreakpointsUI(MspBreakpointContainer breakpoints, final MspCodeWatcher codeWatcher) {
|
||||
this.breakpoints = breakpoints;
|
||||
|
||||
|
@ -88,16 +102,20 @@ public class BreakpointsUI extends JPanel {
|
|||
table.getColumnModel().getColumn(3).setPreferredWidth(60);
|
||||
table.getColumnModel().getColumn(3).setMaxWidth(60);
|
||||
|
||||
/* Popup menu: register on all motes */
|
||||
final JPopupMenu popupMenu = new JPopupMenu();
|
||||
popupMenu.add(new JMenuItem(addToMoteTypeAction));
|
||||
popupMenu.add(new JMenuItem(delFromMoteTypeAction));
|
||||
|
||||
/* Show source file on breakpoint mouse click */
|
||||
table.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
java.awt.Point p = e.getPoint();
|
||||
int rowIndex = table.rowAtPoint(p);
|
||||
int colIndex = table.columnAtPoint(p);
|
||||
int realColumnIndex = table.convertColumnIndexToModel(colIndex);
|
||||
|
||||
if (realColumnIndex != 1 && realColumnIndex != 2) {
|
||||
if (realColumnIndex != 0 && realColumnIndex != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -105,6 +123,13 @@ public class BreakpointsUI extends JPanel {
|
|||
if (rowIndex < 0 || rowIndex >= allBreakpoints.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e)) {
|
||||
popupBreakpoint = allBreakpoints[rowIndex];
|
||||
popupMenu.show(table, e.getX(), e.getY());
|
||||
return;
|
||||
}
|
||||
|
||||
File file = allBreakpoints[rowIndex].getCodeFile();
|
||||
int line = allBreakpoints[rowIndex].getLineNumber();
|
||||
if (file == null) {
|
||||
|
@ -115,7 +140,7 @@ public class BreakpointsUI extends JPanel {
|
|||
codeWatcher.displaySourceFile(file, line);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/* Update when breakpoints are triggered/added/removed */
|
||||
breakpoints.addWatchpointListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
@ -220,4 +245,94 @@ public class BreakpointsUI extends JPanel {
|
|||
return getValueAt(0, c).getClass();
|
||||
}
|
||||
};
|
||||
|
||||
private Action addToMoteTypeAction = new AbstractAction("Register on all motes (mote type)") {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (popupBreakpoint == null) {
|
||||
logger.fatal("No breakpoint to add");
|
||||
}
|
||||
|
||||
/* Extract all motes of the same mote type */
|
||||
Simulation sim = popupBreakpoint.getMote().getSimulation();
|
||||
MoteType type = popupBreakpoint.getMote().getType();
|
||||
ArrayList<MspMote> motes = new ArrayList<MspMote>();
|
||||
for (Mote m: sim.getMotes()) {
|
||||
if (m.getType() == type) {
|
||||
if (!(m instanceof MspMote)) {
|
||||
logger.fatal("At least one mote was not a MSP mote: " + m);
|
||||
return;
|
||||
}
|
||||
|
||||
motes.add((MspMote)m);
|
||||
}
|
||||
}
|
||||
|
||||
/* Register breakpoints */
|
||||
int reregistered = 0;
|
||||
for (MspMote m: motes) {
|
||||
/* Avoid duplicates (match executable addresses) */
|
||||
MspBreakpointContainer container = m.getBreakpointsContainer();
|
||||
MspBreakpoint[] breakpoints = container.getBreakpoints();
|
||||
for (MspBreakpoint w: breakpoints) {
|
||||
if (popupBreakpoint.getExecutableAddress().intValue() ==
|
||||
w.getExecutableAddress().intValue()) {
|
||||
logger.info("Reregistering breakpoint at mote: " + m);
|
||||
container.removeBreakpoint(w.getExecutableAddress());
|
||||
reregistered++;
|
||||
}
|
||||
}
|
||||
|
||||
MspBreakpoint newBreakpoint = container.addBreakpoint(
|
||||
popupBreakpoint.getCodeFile(),
|
||||
popupBreakpoint.getLineNumber(),
|
||||
popupBreakpoint.getExecutableAddress());
|
||||
newBreakpoint.setStopsSimulation(popupBreakpoint.stopsSimulation());
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||
"Registered " + motes.size() + " breakpoints (" + reregistered + " re-registered)",
|
||||
"Breakpoints added", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
};
|
||||
private Action delFromMoteTypeAction = new AbstractAction("Delete from all motes (mote type)") {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (popupBreakpoint == null) {
|
||||
logger.fatal("No breakpoint to delete");
|
||||
}
|
||||
|
||||
/* Extract all motes of the same mote type */
|
||||
Simulation sim = popupBreakpoint.getMote().getSimulation();
|
||||
MoteType type = popupBreakpoint.getMote().getType();
|
||||
ArrayList<MspMote> motes = new ArrayList<MspMote>();
|
||||
for (Mote m: sim.getMotes()) {
|
||||
if (m.getType() == type) {
|
||||
if (!(m instanceof MspMote)) {
|
||||
logger.fatal("At least one mote was not a MSP mote: " + m);
|
||||
return;
|
||||
}
|
||||
|
||||
motes.add((MspMote)m);
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete breakpoints */
|
||||
int deleted = 0;
|
||||
for (MspMote m: motes) {
|
||||
/* Avoid duplicates (match executable addresses) */
|
||||
MspBreakpointContainer container = m.getBreakpointsContainer();
|
||||
MspBreakpoint[] breakpoints = container.getBreakpoints();
|
||||
for (MspBreakpoint w: breakpoints) {
|
||||
if (popupBreakpoint.getExecutableAddress().intValue() ==
|
||||
w.getExecutableAddress().intValue()) {
|
||||
container.removeBreakpoint(w.getExecutableAddress());
|
||||
deleted++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||
"Deleted " + deleted + " breakpoints",
|
||||
"Breakpoints deleted", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue