working on new toolbars for the editor and the debugger

This commit is contained in:
Ben Fry
2015-01-27 09:17:00 -05:00
parent 7dbb5e605e
commit 14307703d8
11 changed files with 1326 additions and 391 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,21 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package processing.mode.java;
@@ -189,10 +189,9 @@ public class Debugger implements VMEventListener {
// load edits into sketch obj, etc...
editor.prepareRun();
if (editor.toolbar() != null) {
// after prepareRun, since this removes highlights
editor.toolbar().activate(DebugToolbar.DEBUG);
}
// after prepareRun, since this removes highlights
editor.activateDebug();
try {
Sketch sketch = editor.getSketch();
@@ -251,19 +250,18 @@ public class Debugger implements VMEventListener {
}
stopTrackingLineChanges();
started = false;
if (editor.toolbar() != null){
editor.toolbar().deactivate(DebugToolbar.DEBUG);
editor.toolbar().deactivate(DebugToolbar.CONTINUE);
editor.toolbar().deactivate(DebugToolbar.STEP);
}
editor.deactivateDebug();
editor.deactivateContinue();
editor.deactivateStep();
editor.statusEmpty();
}
/** Resume paused debugging session. Resumes VM. */
public synchronized void continueDebug() {
if(editor.toolbar() != null)
editor.toolbar().activate(DebugToolbar.CONTINUE);
editor.activateContinue();
editor.variableInspector().lock();
//editor.clearSelection();
//clearHighlight();
@@ -288,8 +286,7 @@ public class Debugger implements VMEventListener {
startDebug();
} else if (isPaused()) {
editor.variableInspector().lock();
if(editor.toolbar() != null)
editor.toolbar().activate(DebugToolbar.STEP);
editor.activateStep();
// use global to mark that there is a step request pending
requestedStep = runtime.vm().eventRequestManager().createStepRequest(currentThread, StepRequest.STEP_LINE, stepDepth);
@@ -619,10 +616,8 @@ public class Debugger implements VMEventListener {
@Override
public void run() {
editor.setCurrentLine(newCurrentLine);
if(editor.toolbar() != null){
editor.toolbar().deactivate(DebugToolbar.STEP);
editor.toolbar().deactivate(DebugToolbar.CONTINUE);
}
editor.deactivateStep();
editor.deactivateContinue();
}
});
@@ -651,10 +646,8 @@ public class Debugger implements VMEventListener {
@Override
public void run() {
editor.setCurrentLine(newCurrentLine);
if(editor.toolbar() != null){
editor.toolbar().deactivate(DebugToolbar.STEP);
editor.toolbar().deactivate(DebugToolbar.CONTINUE);
}
editor.deactivateStep();
editor.deactivateContinue();
}
});
@@ -953,18 +946,13 @@ public class Debugger implements VMEventListener {
/**
* Get a string describing a location.
* Format: class.method:translated_line_number
* @param l a location
* @param loc a location
* @return descriptive string for the given location
*/
protected String locationToString(Location l) {
LineID line = locationToLineID(l);
int lineNumber;
if (line != null) {
lineNumber = line.lineIdx() + 1;
} else {
lineNumber = l.lineNumber();
}
return l.declaringType().name() + "." + l.method().name() + ":" + lineNumber;
protected String locationToString(Location loc) {
LineID line = locationToLineID(loc);
int lineNumber = (line != null) ? (line.lineIdx() + 1) : loc.lineNumber();
return loc.declaringType().name() + "." + loc.method().name() + ":" + lineNumber;
}

View File

@@ -8,7 +8,6 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -61,10 +60,14 @@ public class JavaEditor extends Editor {
protected final String breakpointMarkerComment = " //<>//"; // breakpoint marker comment
protected JMenu debugMenu;
JCheckBoxMenuItem toggleDebugger;
protected Debugger debugger;
protected DebugTray tray;
// private EditorToolbar javaToolbar;
private DebugToolbar debugToolbar;
private ErrorBar errorBar;
protected XQConsoleToggle btnShowConsole;
@@ -138,7 +141,7 @@ public class JavaEditor extends Editor {
getJavaTextArea().setECSandThemeforTextArea(errorCheckerService, jmode);
addXQModeUI();
debugToolbarEnabled = new AtomicBoolean(false);
// debugToolbarEnabled = new AtomicBoolean(false);
//log("Sketch Path: " + path);
}
@@ -1159,11 +1162,11 @@ public class JavaEditor extends Editor {
* To initiate a "stop" action, call handleStop() instead.
*/
public void deactivateRun() {
if (toolbar instanceof DebugToolbar){
toolbar.deactivate(DebugToolbar.RUN);
} else {
toolbar.deactivate(JavaToolbar.RUN);
}
// if (toolbar instanceof DebugToolbar){
// toolbar.deactivate(DebugToolbar.RUN);
// } else {
toolbar.deactivate(JavaToolbar.RUN);
// }
}
@@ -1322,6 +1325,7 @@ public class JavaEditor extends Editor {
}
/*
private AtomicBoolean debugToolbarEnabled;
public boolean isDebugToolbarEnabled() {
@@ -1329,11 +1333,7 @@ public class JavaEditor extends Editor {
}
protected EditorToolbar javaToolbar, debugToolbar;
/**
* Toggles between java mode and debug mode toolbar
*/
/// Toggles between java mode and debug mode toolbar
protected void switchToolbars(){
final EditorToolbar nextToolbar;
if(debugToolbarEnabled.get()){
@@ -1376,6 +1376,7 @@ public class JavaEditor extends Editor {
}
});
}
*/
/**
* Creates the debug menu. Includes ActionListeners for the menu items.
@@ -1387,12 +1388,12 @@ public class JavaEditor extends Editor {
debugMenu = new JMenu(Language.text("menu.debug"));
JMenuItem item;
JCheckBoxMenuItem toggleDebugger =
new JCheckBoxMenuItem(Language.text("menu.debug.show_debug_toolbar"));
toggleDebugger = new JCheckBoxMenuItem("Use the Debugger");
//new JCheckBoxMenuItem(Language.text("menu.debug.show_debug_toolbar"));
toggleDebugger.setSelected(false);
toggleDebugger.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
switchToolbars();
//switchToolbars();
}
});
debugMenu.add(toggleDebugger);
@@ -1967,11 +1968,49 @@ public class JavaEditor extends Editor {
}
/*
public DebugToolbar toolbar() {
if (toolbar instanceof DebugToolbar)
return (DebugToolbar) toolbar;
return null;
}
*/
protected void activateRun() {
toolbar.activate(JavaToolbar.RUN);
}
protected void activateDebug() {
//debugToolbar.activate(DebugToolbar.DEBUG);
activateRun();
}
protected void deactivateDebug() {
deactivateRun();
}
protected void activateContinue() {
debugToolbar.activateContinue();
}
protected void deactivateContinue() {
debugToolbar.deactivateContinue();
}
protected void activateStep() {
debugToolbar.activateStep();
}
protected void deactivateStep() {
debugToolbar.deactivateStep();
}
/**

View File

@@ -26,16 +26,8 @@ import processing.mode.java.JavaEditor;
import processing.mode.java.tweak.ColorControlBox;
import processing.mode.java.tweak.Handle;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.FontMetrics;
import java.awt.Point;
import java.awt.event.ComponentListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.*;
import java.awt.event.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -48,17 +40,16 @@ import processing.app.Mode;
import processing.app.syntax.JEditTextArea;
import processing.app.syntax.PdeTextAreaDefaults;
import processing.app.syntax.TextAreaDefaults;
//import processing.app.syntax.TextAreaPainter;
/**
* Customized text area. Adds support for line background colors.
* @author Martin Leopold <m@martinleopold.com>
*/
public class JavaTextArea extends JEditTextArea {
protected PdeTextAreaDefaults defaults;
protected JavaEditor editor;
static final int LEFT_GUTTER = 59;
static final int RIGHT_GUTTER = 27;
static final int GUTTER_MARGIN = 3;
protected MouseListener[] mouseListeners; // cached mouselisteners, these are wrapped by MouseHandler
// contains line background colors
@@ -512,35 +503,34 @@ public class JavaTextArea extends JEditTextArea {
}
/**
* Retrieve the total width of the gutter area.
*
* @return gutter width in pixels
*/
protected int getGutterWidth() {
if (!editor.isDebugToolbarEnabled()) {
return 0;
}
FontMetrics fm = painter.getFontMetrics();
int textWidth = Math.max(fm.stringWidth(breakpointMarker),
fm.stringWidth(currentLineMarker));
return textWidth + 2 * gutterPadding;
}
/**
* Retrieve the width of margins applied to the left and right of the gutter
* text.
*
* @return margins in pixels
*/
protected int getGutterMargins() {
if (!editor.isDebugToolbarEnabled()) {
return 0;
}
return gutterPadding;
}
// /**
// * Retrieve the total width of the gutter area.
// * @return gutter width in pixels
// */
// protected int getGutterWidth() {
// if (!editor.isDebugToolbarEnabled()) {
// return 0;
// }
//
// FontMetrics fm = painter.getFontMetrics();
// int textWidth = Math.max(fm.stringWidth(breakpointMarker),
// fm.stringWidth(currentLineMarker));
// return textWidth + 2 * gutterPadding;
// }
//
//
// /**
// * Retrieve the width of margins applied to the left and right of the gutter
// * text.
// *
// * @return margins in pixels
// */
// protected int getGutterMargins() {
// if (!editor.isDebugToolbarEnabled()) {
// return 0;
// }
// return gutterPadding;
// }
/**
@@ -679,7 +669,7 @@ public class JavaTextArea extends JEditTextArea {
*/
@Override
public int _offsetToX(int line, int offset) {
return super._offsetToX(line, offset) + getGutterWidth();
return super._offsetToX(line, offset) + LEFT_GUTTER;
}
@@ -695,7 +685,7 @@ public class JavaTextArea extends JEditTextArea {
*/
@Override
public int xToOffset(int line, int x) {
return super.xToOffset(line, x - getGutterWidth());
return super.xToOffset(line, x - LEFT_GUTTER);
}
@@ -719,7 +709,7 @@ public class JavaTextArea extends JEditTextArea {
@Override
public void mousePressed(MouseEvent me) {
// check if this happened in the gutter area
if (me.getX() < getGutterWidth()) {
if (me.getX() < LEFT_GUTTER) {
if (me.getButton() == MouseEvent.BUTTON1 && me.getClickCount() == 2) {
int line = me.getY() / painter.getFontMetrics().getHeight()
+ firstLine;
@@ -776,12 +766,12 @@ public class JavaTextArea extends JEditTextArea {
@Override
public void mouseMoved(MouseEvent me) {
// No need to forward since the standard MouseMotionListeners are called anyway
if (me.getX() < getGutterWidth()) {
if (lastX >= getGutterWidth()) {
if (me.getX() < LEFT_GUTTER) {
if (lastX >= LEFT_GUTTER) {
painter.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
} else {
if (lastX < getGutterWidth()) {
if (lastX < LEFT_GUTTER) {
painter.setCursor(new Cursor(Cursor.TEXT_CURSOR));
}
}

View File

@@ -182,20 +182,17 @@ public class JavaTextAreaPainter extends TextAreaPainter
try {
// TODO This line is causing NPEs randomly ever since I added the
// toggle for Java Mode/Debugger toolbar. [Manindra]
super.paintLine(gfx, line, x + getGutterWidth(), tokenMarker);
super.paintLine(gfx, line, x + JavaTextArea.LEFT_GUTTER, tokenMarker);
} catch (Exception e) {
Base.log(e.getMessage());
}
if (getEditor().isDebugToolbarEnabled()) {
paintGutterBg(gfx, line, x);
// disabled line background after P5 2.1, since it adds highlight by default
//paintLineBgColor(gfx, line, x + ta.getGutterWidth());
paintGutterLine(gfx, line, x);
paintGutterText(gfx, line, x);
}
// formerly only when in debug mode
paintGutterBg(gfx, line, x);
paintGutterLine(gfx, line, x);
paintGutterText(gfx, line, x);
paintErrorLine(gfx, line, x);
}
@@ -213,7 +210,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
protected void paintGutterBg(Graphics gfx, int line, int x) {
gfx.setColor(getTextArea().gutterBgColor);
int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
gfx.fillRect(0, y, getGutterWidth(), fm.getHeight());
gfx.fillRect(0, y, JavaTextArea.LEFT_GUTTER, fm.getHeight());
}
@@ -230,8 +227,8 @@ public class JavaTextAreaPainter extends TextAreaPainter
protected void paintGutterLine(Graphics gfx, int line, int x) {
int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
gfx.setColor(getTextArea().gutterLineColor);
gfx.drawLine(getGutterWidth(), y,
getGutterWidth(), y + fm.getHeight());
gfx.drawLine(JavaTextArea.LEFT_GUTTER, y,
JavaTextArea.LEFT_GUTTER, y + fm.getHeight());
}
@@ -263,13 +260,13 @@ public class JavaTextAreaPainter extends TextAreaPainter
// draw 4 times to make it appear bold, displaced 1px to the right, to the bottom and bottom right.
//int len = text.length() > ta.gutterChars ? ta.gutterChars : text.length();
Utilities.drawTabbedText(new Segment(text.toCharArray(), 0, text.length()),
getGutterMargins(), y, gfx, this, 0);
JavaTextArea.GUTTER_MARGIN, y, gfx, this, 0);
Utilities.drawTabbedText(new Segment(text.toCharArray(), 0, text.length()),
getGutterMargins() + 1, y, gfx, this, 0);
JavaTextArea.GUTTER_MARGIN + 1, y, gfx, this, 0);
Utilities.drawTabbedText(new Segment(text.toCharArray(), 0, text.length()),
getGutterMargins(), y + 1, gfx, this, 0);
JavaTextArea.GUTTER_MARGIN, y + 1, gfx, this, 0);
Utilities.drawTabbedText(new Segment(text.toCharArray(), 0, text.length()),
getGutterMargins() + 1, y + 1, gfx, this, 0);
JavaTextArea.GUTTER_MARGIN + 1, y + 1, gfx, this, 0);
}
@@ -376,8 +373,8 @@ public class JavaTextAreaPainter extends TextAreaPainter
int x1 = fm.stringWidth(goodCode) + (aw - rw), y1 = y + fm.getHeight()
- 2, x2 = x1 + rw;
// Adding offsets for the gutter
x1 += getGutterWidth();
x2 += getGutterWidth();
x1 += JavaTextArea.LEFT_GUTTER;
x2 += JavaTextArea.LEFT_GUTTER;
// gfx.fillRect(x1, y, rw, height);
@@ -856,14 +853,14 @@ public class JavaTextAreaPainter extends TextAreaPainter
}
private int getGutterMargins() {
return ((JavaTextArea) textArea).getGutterMargins();
}
// private int getGutterMargins() {
// return ((JavaTextArea) textArea).getGutterMargins();
// }
private int getGutterWidth() {
return ((JavaTextArea) textArea).getGutterWidth();
}
// private int getGutterWidth() {
// return ((JavaTextArea) textArea).getGutterWidth();
// }
private JavaTextArea getTextArea() {