added breakpoint colors and user defined messages
This commit is contained in:
parent
ebb47546a2
commit
752e80167b
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: BreakpointsUI.java,v 1.4 2009/06/15 09:45:46 fros4943 Exp $
|
* $Id: BreakpointsUI.java,v 1.5 2009/06/16 12:15:15 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote.plugins;
|
package se.sics.cooja.mspmote.plugins;
|
||||||
|
@ -41,17 +41,16 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
|
import javax.swing.table.TableCellEditor;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import se.sics.cooja.GUI;
|
import se.sics.cooja.GUI;
|
||||||
import se.sics.cooja.Mote;
|
import se.sics.cooja.Mote;
|
||||||
import se.sics.cooja.MoteType;
|
import se.sics.cooja.MoteType;
|
||||||
import se.sics.cooja.Simulation;
|
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.MspMote;
|
||||||
import se.sics.cooja.mspmote.MspMoteType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a set of breakpoints.
|
* Displays a set of breakpoints.
|
||||||
|
@ -61,6 +60,20 @@ import se.sics.cooja.mspmote.MspMoteType;
|
||||||
public class BreakpointsUI extends JPanel {
|
public class BreakpointsUI extends JPanel {
|
||||||
private static Logger logger = Logger.getLogger(BreakpointsUI.class);
|
private static Logger logger = Logger.getLogger(BreakpointsUI.class);
|
||||||
|
|
||||||
|
private static final int COLUMN_INFO = 0;
|
||||||
|
private static final int COLUMN_ADDRESS = 1;
|
||||||
|
private static final int COLUMN_FILELINE = 2;
|
||||||
|
private static final int COLUMN_STOP = 3;
|
||||||
|
private static final int COLUMN_REMOVE = 4;
|
||||||
|
|
||||||
|
private static final String[] COLUMN_NAMES = {
|
||||||
|
"Info",
|
||||||
|
"Address",
|
||||||
|
"File",
|
||||||
|
"Stop",
|
||||||
|
"Remove"
|
||||||
|
};
|
||||||
|
|
||||||
private MspBreakpointContainer breakpoints = null;
|
private MspBreakpointContainer breakpoints = null;
|
||||||
private JTable table = null;
|
private JTable table = null;
|
||||||
|
|
||||||
|
@ -79,28 +92,65 @@ public class BreakpointsUI extends JPanel {
|
||||||
int colIndex = table.columnAtPoint(p);
|
int colIndex = table.columnAtPoint(p);
|
||||||
int realColumnIndex = table.convertColumnIndexToModel(colIndex);
|
int realColumnIndex = table.convertColumnIndexToModel(colIndex);
|
||||||
|
|
||||||
if (realColumnIndex != 1) {
|
if (realColumnIndex == COLUMN_FILELINE) {
|
||||||
return null;
|
MspBreakpoint[] allBreakpoints = BreakpointsUI.this.breakpoints.getBreakpoints();
|
||||||
|
if (rowIndex < 0 || rowIndex >= allBreakpoints.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
File file = allBreakpoints[rowIndex].getCodeFile();
|
||||||
|
if (file == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return file.getPath() + ":" + allBreakpoints[rowIndex].getLineNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
MspBreakpoint[] allBreakpoints = BreakpointsUI.this.breakpoints.getBreakpoints();
|
if (realColumnIndex == COLUMN_INFO) {
|
||||||
if (rowIndex < 0 || rowIndex >= allBreakpoints.length) {
|
return "Optional watchpoint info: description and color";
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
File file = allBreakpoints[rowIndex].getCodeFile();
|
|
||||||
if (file == null) {
|
if (realColumnIndex == COLUMN_STOP) {
|
||||||
return null;
|
return "Indicates whether the watchpoint will stop the simulation when triggered";
|
||||||
}
|
}
|
||||||
return file.getPath();
|
|
||||||
|
if (realColumnIndex == COLUMN_REMOVE) {
|
||||||
|
return "Remove breakpoint from this mote only. (Right-click for more options)";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||||
table.getColumnModel().getColumn(0).setPreferredWidth(60); /* XXX */
|
table.getColumnModel().getColumn(COLUMN_ADDRESS).setPreferredWidth(60); /* XXX */
|
||||||
table.getColumnModel().getColumn(0).setMaxWidth(60);
|
table.getColumnModel().getColumn(COLUMN_ADDRESS).setMaxWidth(60);
|
||||||
table.getColumnModel().getColumn(2).setPreferredWidth(60);
|
table.getColumnModel().getColumn(COLUMN_INFO).setPreferredWidth(60);
|
||||||
table.getColumnModel().getColumn(2).setMaxWidth(60);
|
table.getColumnModel().getColumn(COLUMN_INFO).setMaxWidth(60);
|
||||||
table.getColumnModel().getColumn(3).setPreferredWidth(60);
|
table.getColumnModel().getColumn(COLUMN_INFO).setCellRenderer(
|
||||||
table.getColumnModel().getColumn(3).setMaxWidth(60);
|
new DefaultTableCellRenderer() {
|
||||||
|
public Component getTableCellRendererComponent(JTable table, Object value,
|
||||||
|
boolean isSelected, boolean hasFocus, int row, int column) {
|
||||||
|
Component c = super.getTableCellRendererComponent(
|
||||||
|
table, value, isSelected, hasFocus, row, column);
|
||||||
|
if (column != COLUMN_INFO) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
MspBreakpoint[] allBreakpoints = BreakpointsUI.this.breakpoints.getBreakpoints();
|
||||||
|
if (row < 0 || row >= allBreakpoints.length) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
MspBreakpoint breakpoint = allBreakpoints[row];
|
||||||
|
if (breakpoint.getColor() == null) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use watchpoint color */
|
||||||
|
c.setForeground(breakpoint.getColor());
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
table.getColumnModel().getColumn(COLUMN_STOP).setPreferredWidth(60);
|
||||||
|
table.getColumnModel().getColumn(COLUMN_STOP).setMaxWidth(60);
|
||||||
|
table.getColumnModel().getColumn(COLUMN_REMOVE).setPreferredWidth(60);
|
||||||
|
table.getColumnModel().getColumn(COLUMN_REMOVE).setMaxWidth(60);
|
||||||
|
|
||||||
/* Popup menu: register on all motes */
|
/* Popup menu: register on all motes */
|
||||||
final JPopupMenu popupMenu = new JPopupMenu();
|
final JPopupMenu popupMenu = new JPopupMenu();
|
||||||
|
@ -115,7 +165,10 @@ public class BreakpointsUI extends JPanel {
|
||||||
int colIndex = table.columnAtPoint(p);
|
int colIndex = table.columnAtPoint(p);
|
||||||
int realColumnIndex = table.convertColumnIndexToModel(colIndex);
|
int realColumnIndex = table.convertColumnIndexToModel(colIndex);
|
||||||
|
|
||||||
if (realColumnIndex != 0 && realColumnIndex != 1) {
|
if (realColumnIndex != COLUMN_ADDRESS
|
||||||
|
&& realColumnIndex != COLUMN_FILELINE
|
||||||
|
&& realColumnIndex != COLUMN_REMOVE
|
||||||
|
&& realColumnIndex != COLUMN_INFO) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,13 +176,33 @@ public class BreakpointsUI extends JPanel {
|
||||||
if (rowIndex < 0 || rowIndex >= allBreakpoints.length) {
|
if (rowIndex < 0 || rowIndex >= allBreakpoints.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
MspBreakpoint breakpoint = allBreakpoints[rowIndex];
|
||||||
|
|
||||||
if (e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e)) {
|
if (e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e)) {
|
||||||
popupBreakpoint = allBreakpoints[rowIndex];
|
popupBreakpoint = breakpoint;
|
||||||
popupMenu.show(table, e.getX(), e.getY());
|
popupMenu.show(table, e.getX(), e.getY());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (realColumnIndex == COLUMN_INFO) {
|
||||||
|
String msg = JOptionPane.showInputDialog(
|
||||||
|
GUI.getTopParentContainer(),
|
||||||
|
"Enter description",
|
||||||
|
"Watchpoint Description",
|
||||||
|
JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (msg != null) {
|
||||||
|
breakpoint.setUserMessage(msg);
|
||||||
|
}
|
||||||
|
Color newColor = JColorChooser.showDialog(
|
||||||
|
GUI.getTopParentContainer(),
|
||||||
|
"Watchpoint Color",
|
||||||
|
breakpoint.getColor());
|
||||||
|
if (newColor != null) {
|
||||||
|
breakpoint.setColor(newColor);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
File file = allBreakpoints[rowIndex].getCodeFile();
|
File file = allBreakpoints[rowIndex].getCodeFile();
|
||||||
int line = allBreakpoints[rowIndex].getLineNumber();
|
int line = allBreakpoints[rowIndex].getLineNumber();
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
|
@ -182,32 +255,26 @@ public class BreakpointsUI extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractTableModel tableModel = new AbstractTableModel() {
|
private AbstractTableModel tableModel = new AbstractTableModel() {
|
||||||
private final String[] tableColumnNames = {
|
|
||||||
"Address",
|
|
||||||
"File:Line",
|
|
||||||
"Breaks",
|
|
||||||
"Remove"
|
|
||||||
};
|
|
||||||
public String getColumnName(int col) {
|
public String getColumnName(int col) {
|
||||||
return tableColumnNames[col].toString();
|
return COLUMN_NAMES[col].toString();
|
||||||
}
|
}
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
return breakpoints.getBreakpointsCount();
|
return breakpoints.getBreakpointsCount();
|
||||||
}
|
}
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return tableColumnNames.length;
|
return COLUMN_NAMES.length;
|
||||||
}
|
}
|
||||||
public Object getValueAt(int row, int col) {
|
public Object getValueAt(int row, int col) {
|
||||||
MspBreakpoint breakpoint = breakpoints.getBreakpoints()[row];
|
MspBreakpoint breakpoint = breakpoints.getBreakpoints()[row];
|
||||||
|
|
||||||
/* Executable address in hexadecimal */
|
/* Executable address in hexadecimal */
|
||||||
if (col == 0) {
|
if (col == COLUMN_ADDRESS) {
|
||||||
Integer address = breakpoint.getExecutableAddress();
|
Integer address = breakpoint.getExecutableAddress();
|
||||||
return "0x" + Integer.toHexString(address.intValue());
|
return "0x" + Integer.toHexString(address.intValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Source file + line number */
|
/* Source file + line number */
|
||||||
if (col == 1) {
|
if (col == COLUMN_FILELINE) {
|
||||||
File file = breakpoint.getCodeFile();
|
File file = breakpoint.getCodeFile();
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -215,8 +282,15 @@ public class BreakpointsUI extends JPanel {
|
||||||
return file.getName() + ":" + breakpoint.getLineNumber();
|
return file.getName() + ":" + breakpoint.getLineNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (col == COLUMN_INFO) {
|
||||||
|
if (breakpoint.getUserMessage() != null) {
|
||||||
|
return breakpoint.getUserMessage();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/* Stops simulation */
|
/* Stops simulation */
|
||||||
if (col == 2) {
|
if (col == COLUMN_STOP) {
|
||||||
return breakpoint.stopsSimulation();
|
return breakpoint.stopsSimulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,18 +302,20 @@ public class BreakpointsUI extends JPanel {
|
||||||
public void setValueAt(Object value, int row, int col) {
|
public void setValueAt(Object value, int row, int col) {
|
||||||
MspBreakpoint breakpoint = breakpoints.getBreakpoints()[row];
|
MspBreakpoint breakpoint = breakpoints.getBreakpoints()[row];
|
||||||
|
|
||||||
if (col == 2) {
|
if (col == COLUMN_STOP) {
|
||||||
/* Toggle stop state */
|
/* Toggle stop state */
|
||||||
breakpoint.setStopsSimulation(!breakpoint.stopsSimulation());
|
breakpoint.setStopsSimulation(!breakpoint.stopsSimulation());
|
||||||
fireTableCellUpdated(row, col);
|
fireTableCellUpdated(row, col);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove breakpoint */
|
if (col == COLUMN_REMOVE) {
|
||||||
Integer address = breakpoint.getExecutableAddress();
|
/* Remove breakpoint */
|
||||||
breakpoints.removeBreakpoint(address);
|
Integer address = breakpoint.getExecutableAddress();
|
||||||
|
breakpoints.removeBreakpoint(address);
|
||||||
fireTableCellUpdated(row, col);
|
fireTableCellUpdated(row, col);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public Class<?> getColumnClass(int c) {
|
public Class<?> getColumnClass(int c) {
|
||||||
return getValueAt(0, c).getClass();
|
return getValueAt(0, c).getClass();
|
||||||
|
@ -286,6 +362,8 @@ public class BreakpointsUI extends JPanel {
|
||||||
popupBreakpoint.getCodeFile(),
|
popupBreakpoint.getCodeFile(),
|
||||||
popupBreakpoint.getLineNumber(),
|
popupBreakpoint.getLineNumber(),
|
||||||
popupBreakpoint.getExecutableAddress());
|
popupBreakpoint.getExecutableAddress());
|
||||||
|
newBreakpoint.setUserMessage(popupBreakpoint.getUserMessage());
|
||||||
|
newBreakpoint.setColor(popupBreakpoint.getColor());
|
||||||
newBreakpoint.setStopsSimulation(popupBreakpoint.stopsSimulation());
|
newBreakpoint.setStopsSimulation(popupBreakpoint.stopsSimulation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,12 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: MspBreakpoint.java,v 1.1 2009/06/11 10:05:28 fros4943 Exp $
|
* $Id: MspBreakpoint.java,v 1.2 2009/06/16 12:15:15 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote.plugins;
|
package se.sics.cooja.mspmote.plugins;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -61,10 +62,12 @@ public class MspBreakpoint implements Watchpoint {
|
||||||
private File codeFile = null; /* Source code, may be null*/
|
private File codeFile = null; /* Source code, may be null*/
|
||||||
private Integer lineNr = null; /* Source code line number, may be null */
|
private Integer lineNr = null; /* Source code line number, may be null */
|
||||||
|
|
||||||
|
private String msg = null;
|
||||||
|
private Color color = Color.BLACK;
|
||||||
|
|
||||||
public MspBreakpoint(MspBreakpointContainer breakpoints, MspMote mote) {
|
public MspBreakpoint(MspBreakpointContainer breakpoints, MspMote mote) {
|
||||||
this.breakpoints = breakpoints;
|
this.breakpoints = breakpoints;
|
||||||
this.mspMote = mote;
|
this.mspMote = mote;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MspBreakpoint(MspBreakpointContainer breakpoints, MspMote mote, Integer address) {
|
public MspBreakpoint(MspBreakpointContainer breakpoints, MspMote mote, Integer address) {
|
||||||
|
@ -154,6 +157,18 @@ public class MspBreakpoint implements Watchpoint {
|
||||||
config.add(element);
|
config.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg != null) {
|
||||||
|
element = new Element("msg");
|
||||||
|
element.setText(msg);
|
||||||
|
config.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (color != null) {
|
||||||
|
element = new Element("color");
|
||||||
|
element.setText("" + color.getRGB());
|
||||||
|
config.add(element);
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +192,10 @@ public class MspBreakpoint implements Watchpoint {
|
||||||
lineNr = Integer.parseInt(element.getText());
|
lineNr = Integer.parseInt(element.getText());
|
||||||
} else if (element.getName().equals("address")) {
|
} else if (element.getName().equals("address")) {
|
||||||
address = Integer.parseInt(element.getText());
|
address = Integer.parseInt(element.getText());
|
||||||
|
} else if (element.getName().equals("msg")) {
|
||||||
|
msg = element.getText();
|
||||||
|
} else if (element.getName().equals("color")) {
|
||||||
|
color = new Color(Integer.parseInt(element.getText()));
|
||||||
} else if (element.getName().equals("stops")) {
|
} else if (element.getName().equals("stops")) {
|
||||||
stopsSimulation = Boolean.parseBoolean(element.getText());
|
stopsSimulation = Boolean.parseBoolean(element.getText());
|
||||||
}
|
}
|
||||||
|
@ -190,11 +209,32 @@ public class MspBreakpoint implements Watchpoint {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUserMessage(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
public String getUserMessage() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
String desc = "";
|
||||||
if (codeFile != null) {
|
if (codeFile != null) {
|
||||||
return codeFile.getPath() + ":" + lineNr + " (0x" + Integer.toHexString(address.intValue()) + ")";
|
desc += codeFile.getPath() + ":" + lineNr + " (0x" + Integer.toHexString(address.intValue()) + ")";
|
||||||
|
} else {
|
||||||
|
desc += "0x" + Integer.toHexString(address.intValue());
|
||||||
}
|
}
|
||||||
return "0x" + Integer.toHexString(address.intValue());
|
if (msg != null) {
|
||||||
|
desc += "\n\n" + msg;
|
||||||
|
}
|
||||||
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,13 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: Watchpoint.java,v 1.1 2009/06/11 10:02:11 fros4943 Exp $
|
* $Id: Watchpoint.java,v 1.2 2009/06/16 12:15:27 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
|
@ -45,4 +47,9 @@ public interface Watchpoint {
|
||||||
* @return Mote
|
* @return Mote
|
||||||
*/
|
*/
|
||||||
public Mote getMote();
|
public Mote getMote();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Color
|
||||||
|
*/
|
||||||
|
public Color getColor();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue