codeEditor.setText("");
codeEditorLines.clear();
codeEditor.setEditable(false);
Highlighter hl = codeEditor.getHighlighter();
Object o = null;
try {
o = hl.addHighlight(0, 0, CURRENT_LINE_MARKER);
} catch (BadLocationException e1) {
}
currentLineTag = o;
o = null;
try {
o = hl.addHighlight(0, 0, SELECTED_LINE_MARKER);
} catch (BadLocationException e1) {
}
selectedLineTag = o;
codeEditor.getComponentPopupMenu().addPopupMenuListener(new PopupMenuListener() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
/* Disable breakpoint actions */
actionAddBreakpoint.setEnabled(false);
actionRemoveBreakpoint.setEnabled(false);
int line = getCodeEditorMouseLine();
if (line < 1) {
return;
}
/* Configure breakpoint menu options */
/* XXX TODO We should ask for the file specified in the firmware, not
* the actual file on disk. */
int address =
CodeUI.this.mote.getExecutableAddressOf(displayedFile, line);
if (address < 0) {
return;
}
final int start = codeEditorLines.get(line);
int end = codeEditorLines.get(line+1);
Highlighter hl = codeEditor.getHighlighter();
try {
hl.changeHighlight(selectedLineTag, start, end);
} catch (BadLocationException e1) {
}
boolean hasBreakpoint =
CodeUI.this.mote.breakpointExists(address);
if (!hasBreakpoint) {
actionAddBreakpoint.setEnabled(true);
actionAddBreakpoint.putValue("WatchpointMote", CodeUI.this.mote);
actionAddBreakpoint.putValue("WatchpointFile", displayedFile);
actionAddBreakpoint.putValue("WatchpointLine", new Integer(line));
actionAddBreakpoint.putValue("WatchpointAddress", new Integer(address));
} else {
actionRemoveBreakpoint.setEnabled(true);
actionRemoveBreakpoint.putValue("WatchpointMote", CodeUI.this.mote);
actionRemoveBreakpoint.putValue("WatchpointFile", displayedFile);
actionRemoveBreakpoint.putValue("WatchpointLine", new Integer(line));
actionRemoveBreakpoint.putValue("WatchpointAddress", new Integer(address));
}
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
Highlighter hl = codeEditor.getHighlighter();
try {
hl.changeHighlight(selectedLineTag, 0, 0);
} catch (BadLocationException e1) {
}
}
public void popupMenuCanceled(PopupMenuEvent e) {
}