BreakPoints UI enhancements - line icons

Breakpoints handling fixes
This commit is contained in:
Jindra Petřík
2015-11-21 23:32:02 +01:00
parent 0dc971b2e1
commit 1884320315
11 changed files with 217 additions and 63 deletions
@@ -111,6 +111,18 @@ public class DebugPanel extends JPanel {
}
});
Main.getDebugHandler().addConnectionListener(new DebuggerHandler.ConnectionListener() {
@Override
public void connected() {
}
@Override
public void disconnected() {
refresh();
}
});
Main.getDebugHandler().addBreakListener(listener = new DebuggerHandler.BreakListener() {
@Override
@@ -92,6 +92,10 @@ public class DebuggerHandler implements DebugConnectionListener {
public synchronized void removeBreakPoint(String scriptName, int line) {
if (isBreakpointInvalid(scriptName, line)) {
invalidBreakPointMap.get(scriptName).remove(line);
if (invalidBreakPointMap.get(scriptName).isEmpty()) {
invalidBreakPointMap.remove(scriptName);
}
return;
}
if (isBreakpointToAdd(scriptName, line)) {
@@ -160,7 +164,7 @@ public class DebuggerHandler implements DebugConnectionListener {
public boolean addBreakPoint(String scriptName, int line) {
synchronized (this) {
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.INFO, "adding bp " + scriptName + ":" + line);
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.FINE, "adding bp " + scriptName + ":" + line);
if (isBreakpointToRemove(scriptName, line)) {
toRemoveBPointMap.get(scriptName).remove(line);
if (toRemoveBPointMap.get(scriptName).isEmpty()) {
@@ -169,18 +173,18 @@ public class DebuggerHandler implements DebugConnectionListener {
}
if (isBreakpointConfirmed(scriptName, line)) {
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.INFO, "bp " + scriptName + ":" + line + " already confirmed");
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.FINE, "bp " + scriptName + ":" + line + " already confirmed");
return true;
}
if (isBreakpointInvalid(scriptName, line)) {
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.INFO, "bp " + scriptName + ":" + line + " already invalid");
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.FINE, "bp " + scriptName + ":" + line + " already invalid");
return false;
}
if (!toAddBPointMap.containsKey(scriptName)) {
toAddBPointMap.put(scriptName, new TreeSet<>());
}
toAddBPointMap.get(scriptName).add(line);
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.INFO, "bp " + scriptName + ":" + line + " added to todo");
Logger.getLogger(DebuggerHandler.class.getName()).log(Level.FINE, "bp " + scriptName + ":" + line + " added to todo");
}
try {
sendBreakPoints(false);
@@ -328,6 +332,15 @@ public class DebuggerHandler implements DebugConnectionListener {
commands.disconnect();
}
commands = null;
synchronized (this) {
for (String scriptName : confirmedPointMap.keySet()) {
if (!toAddBPointMap.containsKey(scriptName)) {
toAddBPointMap.put(scriptName, new TreeSet<>());
}
toAddBPointMap.get(scriptName).addAll(confirmedPointMap.get(scriptName));
}
confirmedPointMap.clear();
}
for (ConnectionListener l : clisteners) {
l.disconnected();
}
+1 -1
View File
@@ -426,7 +426,7 @@ public class Main {
}
public synchronized static boolean toggleBreakPoint(String scriptName, int line) {
if (getDebugHandler().isBreakpointToAdd(scriptName, line) || getDebugHandler().isBreakpointConfirmed(scriptName, line)) {
if (getDebugHandler().isBreakpointToAdd(scriptName, line) || getDebugHandler().isBreakpointConfirmed(scriptName, line) || getDebugHandler().isBreakpointInvalid(scriptName, line)) {
getDebugHandler().removeBreakPoint(scriptName, line);
return false;
} else {
@@ -2838,10 +2838,10 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
public void clearDebuggerColors() {
if (abcPanel != null) {
abcPanel.decompiledTextArea.removeColorMarkerOnAllLines(DecompiledEditorPane.FG_IP_COLOR, DecompiledEditorPane.BG_IP_COLOR, DecompiledEditorPane.PRIORITY_IP);
abcPanel.decompiledTextArea.removeColorMarkerOnAllLines(DecompiledEditorPane.IP_MARKER);
}
if (actionPanel != null) {
actionPanel.decompiledEditor.removeColorMarkerOnAllLines(DecompiledEditorPane.FG_IP_COLOR, DecompiledEditorPane.BG_IP_COLOR, DecompiledEditorPane.PRIORITY_IP);
actionPanel.decompiledEditor.removeColorMarkerOnAllLines(DecompiledEditorPane.IP_MARKER);
}
}
@@ -45,15 +45,6 @@ import com.jpexs.decompiler.flash.gui.SearchPanel;
import com.jpexs.decompiler.flash.gui.TagEditorPanel;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.decompiler.flash.gui.DebugPanel;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.BG_BREAKPOINT_COLOR;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.BG_INVALID_BREAKPOINT_COLOR;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.BG_IP_COLOR;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.FG_BREAKPOINT_COLOR;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.FG_INVALID_BREAKPOINT_COLOR;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.FG_IP_COLOR;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.PRIORITY_BREAKPOINT;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.PRIORITY_INVALID_BREAKPOINT;
import static com.jpexs.decompiler.flash.gui.abc.DecompiledEditorPane.PRIORITY_IP;
import com.jpexs.decompiler.flash.gui.controls.JPersistentSplitPane;
import com.jpexs.decompiler.flash.gui.controls.NoneSelectedButtonGroup;
import com.jpexs.decompiler.flash.gui.editor.DebuggableEditorPane;
@@ -17,29 +17,44 @@
package com.jpexs.decompiler.flash.gui.editor;
import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.decompiler.flash.gui.View;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.Set;
import jsyntaxpane.components.BreakPointListener;
import jsyntaxpane.components.LineMarkerPainter;
import jsyntaxpane.components.LineNumbersBreakpointsRuler;
/**
*
* @author JPEXS
*/
public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakPointListener {
public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakPointListener, LineMarkerPainter {
public static final Color BG_BREAKPOINT_COLOR = new Color(0xfc, 0x9d, 0x9f);
public static final Color FG_BREAKPOINT_COLOR = null;
public static final int PRIORITY_BREAKPOINT = 20;
private static final Color BG_CURRENT_COLOR = new Color(0xd6, 0xe8, 0xe2);
private static final Color BG_RULER_COLOR = new Color(0xe9, 0xe8, 0xe2);
public static final Color BG_IP_COLOR = new Color(0xbd, 0xe6, 0xaa);
public static final Color FG_IP_COLOR = null;
public static final int PRIORITY_IP = 0;
private static final Color BG_BREAKPOINT_COLOR = new Color(0xfc, 0x9d, 0x9f);
private static final Color FG_BREAKPOINT_COLOR = null;
private static final int PRIORITY_BREAKPOINT = 20;
public static final Color BG_INVALID_BREAKPOINT_COLOR = new Color(0xdc, 0xdc, 0xd8);
public static final Color FG_INVALID_BREAKPOINT_COLOR = null;
public static final int PRIORITY_INVALID_BREAKPOINT = 10;
private static final Color BG_IP_COLOR = new Color(0xbd, 0xe6, 0xaa);
private static final Color FG_IP_COLOR = null;
private static final int PRIORITY_IP = 0;
private static final Color BG_INVALID_BREAKPOINT_COLOR = new Color(0xdc, 0xdc, 0xd8);
private static final Color FG_INVALID_BREAKPOINT_COLOR = null;
private static final int PRIORITY_INVALID_BREAKPOINT = 10;
public static final LineMarker BREAKPOINT_MARKER = new LineMarker(FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT);
public static final LineMarker IP_MARKER = new LineMarker(FG_IP_COLOR, BG_IP_COLOR, PRIORITY_IP);
public static final LineMarker INVALID_BREAKPOINT_MARKER = new LineMarker(FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT);
protected String scriptName = null;
private LineNumbersBreakpointsRuler ruler;
public synchronized void setScriptName(String scriptName) {
this.scriptName = scriptName;
@@ -51,23 +66,23 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
return;
}
boolean on = Main.toggleBreakPoint(scriptName, line);
removeColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT);
removeColorMarker(line, INVALID_BREAKPOINT_MARKER);
if (on) {
if (Main.isBreakPointValid(scriptName, line)) {
addColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT);
addColorMarker(line, BREAKPOINT_MARKER);
} else {
addColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT);
addColorMarker(line, INVALID_BREAKPOINT_MARKER);
}
} else {
removeColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT);
removeColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT);
removeColorMarker(line, BREAKPOINT_MARKER);
removeColorMarker(line, INVALID_BREAKPOINT_MARKER);
}
}
public synchronized void refreshMarkers() {
removeColorMarkerOnAllLines(FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT);
removeColorMarkerOnAllLines(FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT);
removeColorMarkerOnAllLines(FG_IP_COLOR, BG_IP_COLOR, PRIORITY_IP);
removeColorMarkerOnAllLines(BREAKPOINT_MARKER);
removeColorMarkerOnAllLines(INVALID_BREAKPOINT_MARKER);
removeColorMarkerOnAllLines(IP_MARKER);
if (scriptName == null) {
return;
@@ -77,15 +92,15 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
for (int line : bkptLines) {
if (Main.isBreakPointValid(scriptName, line)) {
addColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT);
addColorMarker(line, BREAKPOINT_MARKER);
} else {
addColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT);
addColorMarker(line, INVALID_BREAKPOINT_MARKER);
}
}
int ip = Main.getIp(scriptName);
String ipPath = Main.getIpClass();
if (ip > 0 && ipPath != null && ipPath.equals(scriptName)) {
addColorMarker(ip, FG_IP_COLOR, BG_IP_COLOR, PRIORITY_IP);
addColorMarker(ip, IP_MARKER);
}
}
@@ -99,4 +114,71 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
return scriptName;
}
@Override
public void paintLineMarker(Graphics g, int line, int x, int lineY, int textY, int lineHeight, boolean currentLine, int maxLines) {
if (currentLine) {
g.setColor(BG_CURRENT_COLOR);
} else {
g.setColor(View.getDefaultBackgroundColor());
}
int h = lineHeight;
if (line == 1) {
h += lineY;
}
if (line == maxLines) {
h = getHeight() - lineY;
}
g.fillRect(0, line == 1 ? 0 : lineY, getWidth(), h);
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
((Graphics2D) g).setStroke(new BasicStroke(0.5f));
boolean drawText = true;
if (hasColorMarker(line, INVALID_BREAKPOINT_MARKER)) {
g.setColor(BG_INVALID_BREAKPOINT_COLOR);
g.fillOval(x + 5, textY - 10, 10, 10);
g.setColor(Color.black);
g.drawOval(x + 5, textY - 10, 10, 10);
drawText = false;
} else if (hasColorMarker(line, BREAKPOINT_MARKER)) {
g.setColor(BG_BREAKPOINT_COLOR);
g.fillOval(x + 5, textY - 10, 10, 10);
g.setColor(Color.black);
g.drawOval(x + 5, textY - 10, 10, 10);
drawText = false;
}
if (hasColorMarker(line, IP_MARKER)) {
int mx = x + 10;
g.setColor(BG_IP_COLOR);
g.fillPolygon(new int[]{mx, mx + 10, mx}, new int[]{textY - 10, textY - 5, textY}, 3);
g.setColor(Color.black);
g.drawPolygon(new int[]{mx, mx + 10, mx}, new int[]{textY - 10, textY - 5, textY}, 3);
drawText = false;
}
if (drawText) {
g.setColor(getForeground());
g.drawString("" + line, x, textY);
}
}
@Override
public void installLineMarker(LineNumbersBreakpointsRuler ruler) {
this.ruler = ruler;
}
@Override
public void addColorMarker(int line, LineMarker lm) {
super.addColorMarker(line, lm);
ruler.repaint();
}
@Override
public void removeColorMarker(int line, LineMarker lm) {
super.removeColorMarker(line, lm);
ruler.repaint();
}
}
@@ -82,7 +82,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
private Color bgColor;
private Color color;
private FgPainter fgPainter;
private int line;
//private int line;
private int priority;
public FgPainter getForegroundPainter() {
@@ -91,11 +91,10 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
@Override
public String toString() {
return bgColor.toString() + " line " + line + " priority:" + priority;
return bgColor.toString() + " priority:" + priority;
}
public LineMarker(int line, Color color, Color bgColor, int priority) {
this.line = line;
public LineMarker(Color color, Color bgColor, int priority) {
this.bgColor = bgColor;
this.color = color;
this.priority = priority;
@@ -109,7 +108,6 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
int hash = 5;
hash = 17 * hash + Objects.hashCode(this.bgColor);
hash = 17 * hash + Objects.hashCode(this.color);
hash = 17 * hash + this.line;
return hash;
}
@@ -125,10 +123,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
if (!Objects.equals(this.bgColor, other.bgColor)) {
return false;
}
if (!Objects.equals(this.color, other.color)) {
return false;
}
return this.line == other.line;
return (Objects.equals(this.color, other.color));
}
public Color getBgColor() {
@@ -156,41 +151,45 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
repaint();
}
public void removeColorMarker(int line, Color color, Color bgColor, int priority) {
public boolean hasColorMarker(int line, LineMarker lm) {
if (lineMarkers.containsKey(line)) {
return lineMarkers.get(line).contains(lm);
}
return false;
}
public void removeColorMarker(int line, LineMarker lm) {
if (lineMarkers.containsKey(line)) {
LineMarker lm = new LineMarker(line, color, bgColor, priority);
lineMarkers.get(line).remove(lm);
}
repaint();
getParent().repaint();
}
public void removeColorMarkerOnAllLines(Color color, Color bgColor, int priority) {
public void removeColorMarkerOnAllLines(LineMarker lm) {
for (int line : lineMarkers.keySet()) {
removeColorMarker(line, color, bgColor, priority);
removeColorMarker(line, lm);
}
}
public void toggleColorMarker(int line, Color color, Color bgColor, int priority) {
public void toggleColorMarker(int line, LineMarker lm) {
if (!lineMarkers.containsKey(line)) {
addColorMarker(line, color, bgColor, priority);
addColorMarker(line, lm);
} else {
LineMarker m = new LineMarker(line, color, bgColor, priority);
if (lineMarkers.get(line).contains(m)) {
removeColorMarker(line, color, bgColor, priority);
if (lineMarkers.get(line).contains(lm)) {
removeColorMarker(line, lm);
} else {
addColorMarker(line, color, bgColor, priority);
addColorMarker(line, lm);
}
}
repaint();
getParent().repaint();
}
public void addColorMarker(int line, Color color, Color bgColor, int priority) {
public void addColorMarker(int line, LineMarker lm) {
if (!lineMarkers.containsKey(line)) {
lineMarkers.put(line, Collections.synchronizedSortedSet(new TreeSet<>()));
}
LineMarker marker = new LineMarker(line, color, bgColor, priority);
lineMarkers.get(line).add(marker);
repaint();
lineMarkers.get(line).add(lm);
getParent().repaint();
}
public int getLine() {