implement breakpoint diamond and step arrow (fixes #3307)

This commit is contained in:
Ben Fry
2015-09-24 05:51:14 -04:00
parent 209ea9000a
commit 48d013becf
5 changed files with 73 additions and 36 deletions

View File

@@ -50,8 +50,9 @@ public class JavaEditor extends Editor {
// Runner associated with this editor window
private Runner runtime;
// Need to sort through the rest of these additions...
// Need to sort through the rest of these additions [fry]
// TODO these are all null, need to remove color support
protected Color breakpointColor;
protected Color currentLineColor;
protected Color breakpointMarkerColor;
@@ -122,11 +123,11 @@ public class JavaEditor extends Editor {
Toolkit.setMenuMnemonics(textarea.getRightClickPopup());
// load settings from theme.txt
breakpointColor = mode.getColor("breakpoint.bgcolor");
breakpointMarkerColor = mode.getColor("breakpoint.marker.color");
currentLineColor = mode.getColor("currentline.bgcolor");
currentLineMarkerColor = mode.getColor("currentline.marker.color");
// // load settings from theme.txt
// breakpointColor = mode.getColor("breakpoint.bgcolor");
// breakpointMarkerColor = mode.getColor("breakpoint.marker.color");
// currentLineColor = mode.getColor("currentline.bgcolor");
// currentLineMarkerColor = mode.getColor("currentline.marker.color");
// set breakpoints from marker comments
for (LineID lineID : stripBreakpointComments()) {
@@ -2189,7 +2190,7 @@ public class JavaEditor extends Editor {
cursorToLineStart(line.lineIdx());
// highlight line
currentLine = new LineHighlight(line.lineIdx(), currentLineColor, this);
currentLine.setMarker(getJavaTextArea().currentLineMarker, currentLineMarkerColor);
currentLine.setMarker(JavaTextArea.STEP_MARKER, currentLineMarkerColor);
currentLine.setPriority(10); // fixes current line being hidden by the breakpoint when moved down
}
@@ -2218,7 +2219,7 @@ public class JavaEditor extends Editor {
*/
public void addBreakpointedLine(LineID lineID) {
LineHighlight hl = new LineHighlight(lineID, breakpointColor, this);
hl.setMarker(getJavaTextArea().breakpointMarker, breakpointMarkerColor);
hl.setMarker(JavaTextArea.BREAK_MARKER, breakpointMarkerColor);
breakpointedLines.add(hl);
// repaint current line if it's on this line
if (currentLine != null && currentLine.getLineID().equals(lineID)) {

View File

@@ -72,9 +72,9 @@ public class JavaTextArea extends JEditTextArea {
protected Color gutterLineColor; // = new Color(233, 233, 233); // color of vertical separation line
/// the text marker for highlighting breakpoints in the gutter
public String breakpointMarker = "<>";
static public final String BREAK_MARKER = "<>";
/// the text marker for highlighting the current line in the gutter
public String currentLineMarker = "->";
static public final String STEP_MARKER = "->";
/// maps line index to gutter text
protected Map<Integer, String> gutterText = new HashMap<Integer, String>();
@@ -129,9 +129,9 @@ public class JavaTextArea extends JEditTextArea {
gutterBgColor = mode.getColor("editor.gutter.bgcolor"); //, gutterBgColor);
gutterLineColor = mode.getColor("editor.gutter.linecolor"); //, gutterLineColor);
gutterPadding = mode.getInteger("editor.gutter.padding");
breakpointMarker = mode.getString("editor.gutter.breakpoint.marker"); //, breakpointMarker);
// breakpointMarker = mode.getString("editor.gutter.breakpoint.marker"); //, breakpointMarker);
// breakpointMarker = "\u2666";
currentLineMarker = mode.getString("editor.gutter.currentline.marker"); //, currentLineMarker);
// currentLineMarker = mode.getString("editor.gutter.currentline.marker"); //, currentLineMarker);
// TweakMode code
prevCompListeners = painter.getComponentListeners();

View File

@@ -38,6 +38,7 @@ import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.util.List;
@@ -268,24 +269,56 @@ public class JavaTextAreaPainter extends TextAreaPainter
if (getJavaEditor().isDebuggerEnabled()) {
text = getTextArea().getGutterText(line);
}
// if no special text for a breakpoint, just show the line number
if (text == null) {
gfx.setColor(gutterTextColor);
int textRight = Editor.LEFT_GUTTER - Editor.GUTTER_MARGIN;
int textBaseline = textArea.lineToY(line) + fm.getHeight();
if (text != null) {
if (text.equals(JavaTextArea.BREAK_MARKER)) {
drawDiamond(gfx, textRight - 8, textBaseline - 8, 8, 8);
} else if (text.equals(JavaTextArea.STEP_MARKER)) {
//drawRightArrow(gfx, textRight - 7, textBaseline - 7, 7, 6);
drawRightArrow(gfx, textRight - 7, textBaseline - 7.5f, 7, 7);
}
} else {
// if no special text for a breakpoint, just show the line number
text = String.valueOf(line + 1);
//text = makeOSF(String.valueOf(line + 1));
}
char[] txt = text.toCharArray();
//gfx.setFont(getFont());
gfx.setFont(gutterTextFont);
// Right-align the text
int tx = Editor.LEFT_GUTTER - Editor.GUTTER_MARGIN -
gfx.getFontMetrics().charsWidth(txt, 0, txt.length);
gfx.setColor(gutterTextColor);
// Using 'fm' here because it's relative to the editor text size,
// not the numbers in the gutter
int ty = textArea.lineToY(line) + fm.getHeight();
Utilities.drawTabbedText(new Segment(txt, 0, text.length()),
tx, ty, gfx, this, 0);
gfx.setFont(gutterTextFont);
// Right-align the text
char[] txt = text.toCharArray();
int tx = textRight - gfx.getFontMetrics().charsWidth(txt, 0, txt.length);
// Using 'fm' here because it's relative to the editor text size,
// not the numbers in the gutter
Utilities.drawTabbedText(new Segment(txt, 0, text.length()),
tx, textBaseline, gfx, this, 0);
}
}
private void drawDiamond(Graphics g, float x, float y, float w, float h) {
Graphics2D g2 = (Graphics2D) g;
GeneralPath path = new GeneralPath();
path.moveTo(x + w/2, y);
path.lineTo(x + w, y + h/2);
path.lineTo(x + w/2, y + h);
path.lineTo(x, y + h/2);
path.closePath();
g2.fill(path);
}
private void drawRightArrow(Graphics g, float x, float y, float w, float h) {
Graphics2D g2 = (Graphics2D) g;
GeneralPath path = new GeneralPath();
path.moveTo(x, y);
path.lineTo(x + w, y + h/2);
path.lineTo(x, y + h);
path.closePath();
g2.fill(path);
}