mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
and more cleanups...
This commit is contained in:
@@ -1,28 +1,25 @@
|
||||
/* -*- 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
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
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 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.
|
||||
*/
|
||||
|
||||
package processing.mode.java.debug;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.logE;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.CardLayout;
|
||||
import java.awt.Color;
|
||||
@@ -81,13 +78,12 @@ import processing.app.syntax.JEditTextArea;
|
||||
import processing.app.syntax.PdeTextAreaDefaults;
|
||||
import processing.core.PApplet;
|
||||
import processing.mode.java.JavaEditor;
|
||||
import processing.mode.java.JavaInputHandler;
|
||||
import processing.mode.java.pdex.ErrorBar;
|
||||
import processing.mode.java.pdex.ErrorCheckerService;
|
||||
import processing.mode.java.pdex.ErrorMessageSimplifier;
|
||||
import processing.mode.java.pdex.ExperimentalMode;
|
||||
import processing.mode.java.pdex.Problem;
|
||||
import processing.mode.java.pdex.TextArea;
|
||||
import processing.mode.java.pdex.JavaTextArea;
|
||||
import processing.mode.java.pdex.XQConsoleToggle;
|
||||
import processing.mode.java.pdex.XQErrorTable;
|
||||
import processing.mode.java.tweak.ColorControlBox;
|
||||
@@ -110,138 +106,87 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
//private JMenu fileMenu;
|
||||
//protected EditorToolbar toolbar;
|
||||
|
||||
// highlighting
|
||||
protected Color breakpointColor = new Color(240, 240, 240); // the background color for highlighting lines
|
||||
protected Color currentLineColor = new Color(255, 255, 150); // the background color for highlighting lines
|
||||
protected Color breakpointMarkerColor = new Color(74, 84, 94); // the color of breakpoint gutter markers
|
||||
protected Color currentLineMarkerColor = new Color(226, 117, 0); // the color of current line gutter markers
|
||||
protected List<LineHighlight> breakpointedLines = new ArrayList<LineHighlight>(); // breakpointed lines
|
||||
protected LineHighlight currentLine; // line the debugger is currently suspended at
|
||||
protected final String breakpointMarkerComment = " //<>//"; // breakpoint marker comment
|
||||
// menus
|
||||
protected JMenu debugMenu; // the debug menu
|
||||
// debugger control
|
||||
protected JMenuItem debugMenuItem;
|
||||
protected JMenuItem continueMenuItem;
|
||||
protected JMenuItem stopMenuItem;
|
||||
// breakpoints
|
||||
protected JMenuItem toggleBreakpointMenuItem;
|
||||
protected JMenuItem listBreakpointsMenuItem;
|
||||
// stepping
|
||||
protected JMenuItem stepOverMenuItem;
|
||||
protected JMenuItem stepIntoMenuItem;
|
||||
protected JMenuItem stepOutMenuItem;
|
||||
// info
|
||||
protected JMenuItem printStackTraceMenuItem;
|
||||
protected JMenuItem printLocalsMenuItem;
|
||||
protected JMenuItem printThisMenuItem;
|
||||
protected JMenuItem printSourceMenuItem;
|
||||
protected JMenuItem printThreads;
|
||||
// variable inspector
|
||||
protected JMenuItem toggleVariableInspectorMenuItem;
|
||||
// references
|
||||
public ExperimentalMode dmode; // the mode
|
||||
protected Debugger dbg; // the debugger
|
||||
protected VariableInspector vi; // the variable inspector frame
|
||||
|
||||
public TextArea ta; // the text area
|
||||
public ErrorBar errorBar;
|
||||
|
||||
/**
|
||||
* Show Console button
|
||||
*/
|
||||
protected XQConsoleToggle btnShowConsole;
|
||||
protected Color breakpointColor; // = new Color(240, 240, 240); // the background color for highlighting lines
|
||||
protected Color currentLineColor; // = new Color(255, 255, 150); // the background color for highlighting lines
|
||||
protected Color breakpointMarkerColor; // = new Color(74, 84, 94); // the color of breakpoint gutter markers
|
||||
protected Color currentLineMarkerColor; // = new Color(226, 117, 0); // the color of current line gutter markers
|
||||
protected List<LineHighlight> breakpointedLines = new ArrayList<LineHighlight>(); // breakpointed lines
|
||||
protected LineHighlight currentLine; // line the debugger is currently suspended at
|
||||
protected final String breakpointMarkerComment = " //<>//"; // breakpoint marker comment
|
||||
|
||||
/**
|
||||
* Show Problems button
|
||||
*/
|
||||
protected XQConsoleToggle btnShowErrors;
|
||||
protected JMenu debugMenu; // the debug menu
|
||||
|
||||
/**
|
||||
* Scroll pane for Error Table
|
||||
*/
|
||||
protected JScrollPane errorTableScrollPane;
|
||||
protected JMenuItem debugMenuItem;
|
||||
protected JMenuItem continueMenuItem;
|
||||
protected JMenuItem stopMenuItem;
|
||||
|
||||
/**
|
||||
* Panel with card layout which contains the p5 console and Error Table
|
||||
* panes
|
||||
*/
|
||||
protected JPanel consoleProblemsPane;
|
||||
protected JMenuItem toggleBreakpointMenuItem;
|
||||
protected JMenuItem listBreakpointsMenuItem;
|
||||
|
||||
protected JMenuItem stepOverMenuItem;
|
||||
protected JMenuItem stepIntoMenuItem;
|
||||
protected JMenuItem stepOutMenuItem;
|
||||
|
||||
protected JMenuItem printStackTraceMenuItem;
|
||||
protected JMenuItem printLocalsMenuItem;
|
||||
protected JMenuItem printThisMenuItem;
|
||||
protected JMenuItem printSourceMenuItem;
|
||||
protected JMenuItem printThreads;
|
||||
|
||||
protected JMenuItem toggleVariableInspectorMenuItem;
|
||||
|
||||
public ExperimentalMode dmode; // the mode
|
||||
protected Debugger dbg; // the debugger
|
||||
protected VariableInspector vi; // the variable inspector frame
|
||||
|
||||
public JavaTextArea ta; // the text area
|
||||
public ErrorBar errorBar;
|
||||
|
||||
protected XQErrorTable errorTable;
|
||||
protected XQConsoleToggle btnShowConsole;
|
||||
protected XQConsoleToggle btnShowErrors;
|
||||
protected JScrollPane errorTableScrollPane;
|
||||
protected JPanel consoleProblemsPane;
|
||||
protected XQErrorTable errorTable;
|
||||
|
||||
/**
|
||||
* Enable/Disable compilation checking
|
||||
*/
|
||||
public boolean compilationCheckEnabled = true;
|
||||
public boolean compilationCheckEnabled = true;
|
||||
|
||||
protected JCheckBoxMenuItem showWarnings;
|
||||
public JCheckBoxMenuItem problemWindowMenuCB;
|
||||
protected JCheckBoxMenuItem debugMessagesEnabled;
|
||||
protected JMenuItem showOutline, showTabOutline;
|
||||
protected JCheckBoxMenuItem writeErrorLog;
|
||||
protected JCheckBoxMenuItem completionsEnabled;
|
||||
|
||||
/**
|
||||
* Show warnings menu item
|
||||
*/
|
||||
protected JCheckBoxMenuItem showWarnings;
|
||||
|
||||
/**
|
||||
* Check box menu item for show/hide Problem Window
|
||||
*/
|
||||
public JCheckBoxMenuItem problemWindowMenuCB;
|
||||
|
||||
/**
|
||||
* Enable/Disable debug ouput
|
||||
*/
|
||||
protected JCheckBoxMenuItem debugMessagesEnabled;
|
||||
|
||||
/**
|
||||
* Show outline view
|
||||
*/
|
||||
protected JMenuItem showOutline, showTabOutline;
|
||||
|
||||
/**
|
||||
* Enable/Disable error logging
|
||||
*/
|
||||
protected JCheckBoxMenuItem writeErrorLog;
|
||||
|
||||
/**
|
||||
* Enable/Disable code completion
|
||||
*/
|
||||
protected JCheckBoxMenuItem completionsEnabled;
|
||||
|
||||
/**
|
||||
* If sketch contains java tabs, some editor features are disabled
|
||||
*/
|
||||
public boolean hasJavaTabs;
|
||||
// TODO no way should this be public; make an accessor or protected
|
||||
public boolean hasJavaTabs;
|
||||
|
||||
|
||||
public DebugEditor(Base base, String path, EditorState state, Mode mode) {
|
||||
super(base, path, state, mode);
|
||||
super(base, path, state, mode);
|
||||
|
||||
// get mode
|
||||
dmode = (ExperimentalMode) mode;
|
||||
dmode = (ExperimentalMode) mode;
|
||||
dbg = new Debugger(this);
|
||||
vi = new VariableInspector(this);
|
||||
|
||||
// init controller class
|
||||
dbg = new Debugger(this);
|
||||
// access to customized (i.e. subclassed) text area
|
||||
ta = (JavaTextArea) textarea;
|
||||
|
||||
// variable inspector window
|
||||
vi = new VariableInspector(this);
|
||||
// Add show usage option
|
||||
JMenuItem showUsageItem = new JMenuItem("Show Usage...");
|
||||
showUsageItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleShowUsage();
|
||||
}
|
||||
});
|
||||
ta.getRightClickPopup().add(showUsageItem);
|
||||
|
||||
// access to customized (i.e. subclassed) text area
|
||||
ta = (TextArea) textarea;
|
||||
|
||||
// Add show usage option
|
||||
JMenuItem showUsageItem = new JMenuItem("Show Usage..");
|
||||
showUsageItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleShowUsage();
|
||||
}
|
||||
});
|
||||
ta.getRightClickPopup().add(showUsageItem);
|
||||
|
||||
// add refactor option
|
||||
JMenuItem renameItem = new JMenuItem("Rename..");
|
||||
renameItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleRefactor();
|
||||
}
|
||||
});
|
||||
// add refactor option
|
||||
JMenuItem renameItem = new JMenuItem("Rename...");
|
||||
renameItem.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleRefactor();
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: Add support for word select on right click and rename.
|
||||
// ta.customPainter.addMouseListener(new MouseAdapter() {
|
||||
@@ -249,7 +194,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// System.out.println(evt);
|
||||
// }
|
||||
// });
|
||||
ta.getRightClickPopup().add(renameItem);
|
||||
ta.getRightClickPopup().add(renameItem);
|
||||
// set action on frame close
|
||||
// addWindowListener(new WindowAdapter() {
|
||||
// @Override
|
||||
@@ -258,27 +203,28 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// }
|
||||
// });
|
||||
|
||||
Toolkit.setMenuMnemonics(ta.getRightClickPopup());
|
||||
Toolkit.setMenuMnemonics(ta.getRightClickPopup());
|
||||
|
||||
// load settings from theme.txt
|
||||
ExperimentalMode theme = dmode;
|
||||
breakpointColor = theme.getThemeColor("breakpoint.bgcolor", breakpointColor);
|
||||
breakpointMarkerColor = theme.getThemeColor("breakpoint.marker.color", breakpointMarkerColor);
|
||||
currentLineColor = theme.getThemeColor("currentline.bgcolor", currentLineColor);
|
||||
currentLineMarkerColor = theme.getThemeColor("currentline.marker.color", currentLineMarkerColor);
|
||||
// load settings from theme.txt
|
||||
breakpointColor = mode.getColor("breakpoint.bgcolor"); //, breakpointColor);
|
||||
breakpointMarkerColor = mode.getColor("breakpoint.marker.color"); //, breakpointMarkerColor);
|
||||
currentLineColor = mode.getColor("currentline.bgcolor"); //, currentLineColor);
|
||||
currentLineMarkerColor = mode.getColor("currentline.marker.color"); //, currentLineMarkerColor);
|
||||
|
||||
// set breakpoints from marker comments
|
||||
for (LineID lineID : stripBreakpointComments()) {
|
||||
//System.out.println("setting: " + lineID);
|
||||
dbg.setBreakpoint(lineID);
|
||||
}
|
||||
getSketch().setModified(false); // setting breakpoints will flag sketch as modified, so override this here
|
||||
// set breakpoints from marker comments
|
||||
for (LineID lineID : stripBreakpointComments()) {
|
||||
//System.out.println("setting: " + lineID);
|
||||
dbg.setBreakpoint(lineID);
|
||||
}
|
||||
getSketch().setModified(false); // setting breakpoints will flag sketch as modified, so override this here
|
||||
|
||||
checkForJavaTabs();
|
||||
initializeErrorChecker();
|
||||
ta.setECSandThemeforTextArea(errorCheckerService, dmode);
|
||||
addXQModeUI();
|
||||
debugToolbarEnabled = new AtomicBoolean(false);
|
||||
checkForJavaTabs();
|
||||
initializeErrorChecker();
|
||||
|
||||
ta.setECSandThemeforTextArea(errorCheckerService, dmode);
|
||||
|
||||
addXQModeUI();
|
||||
debugToolbarEnabled = new AtomicBoolean(false);
|
||||
//log("Sketch Path: " + path);
|
||||
}
|
||||
|
||||
@@ -426,43 +372,13 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides sketch menu creation to change keyboard shortcuts from "Run".
|
||||
*
|
||||
* @return the sketch menu
|
||||
*/
|
||||
/*@Override
|
||||
public JMenu buildSketchMenu() {
|
||||
JMenuItem runItem = Toolkit.newJMenuItemShift(DebugToolbar.getTitle(DebugToolbar.RUN, false), KeyEvent.VK_R);
|
||||
runItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleRun();
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem presentItem = new JMenuItem(DebugToolbar.getTitle(DebugToolbar.RUN, true));
|
||||
presentItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handlePresent();
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem stopItem = new JMenuItem(DebugToolbar.getTitle(DebugToolbar.STOP, false));
|
||||
stopItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleStop();
|
||||
}
|
||||
});
|
||||
return buildSketchMenu(new JMenuItem[]{runItem, presentItem, stopItem});
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Whether debug toolbar is enabled
|
||||
*/
|
||||
public AtomicBoolean debugToolbarEnabled;
|
||||
private AtomicBoolean debugToolbarEnabled;
|
||||
|
||||
public boolean isDebugToolbarEnabled() {
|
||||
return debugToolbarEnabled != null && debugToolbarEnabled.get();
|
||||
}
|
||||
|
||||
|
||||
protected EditorToolbar javaToolbar, debugToolbar;
|
||||
|
||||
@@ -477,7 +393,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
javaToolbar = createToolbar();
|
||||
nextToolbar = javaToolbar;
|
||||
debugToolbarEnabled.set(false);
|
||||
log("Switching to Java Mode Toolbar");
|
||||
Base.log("Switching to Java Mode Toolbar");
|
||||
}
|
||||
else{
|
||||
// switch to debug
|
||||
@@ -485,7 +401,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
debugToolbar = new DebugToolbar(this, getBase());
|
||||
nextToolbar = debugToolbar;
|
||||
debugToolbarEnabled.set(true);
|
||||
log("Switching to Debugger Toolbar");
|
||||
Base.log("Switching to Debugger Toolbar");
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@@ -790,11 +706,11 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
Logger.getLogger(DebugEditor.class.getName()).log(Level.INFO, "Invoked 'Toggle Variable Inspector' menu item");
|
||||
toggleVariableInspector();
|
||||
} else if (source.equals(showOutline)){
|
||||
log("Show Sketch Outline:");
|
||||
Base.log("Show Sketch Outline:");
|
||||
errorCheckerService.getASTGenerator().showSketchOutline();
|
||||
}
|
||||
else if (source.equals(showTabOutline)){
|
||||
log("Show Tab Outline:");
|
||||
Base.log("Show Tab Outline:");
|
||||
errorCheckerService.getASTGenerator().showTabOutline();
|
||||
}
|
||||
}
|
||||
@@ -896,7 +812,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// this method gets called twice when saving sketch for the first time
|
||||
// once with new name and another with old(causing NPE). Keep an eye out
|
||||
// for potential issues. See #2675. TODO:
|
||||
logE("Illegal tab name to addBreakpointComments() " + tabFilename);
|
||||
Base.loge("Illegal tab name to addBreakpointComments() " + tabFilename);
|
||||
return;
|
||||
}
|
||||
List<LineBreakpoint> bps = dbg.getBreakpoints(tab.getFileName());
|
||||
@@ -1127,7 +1043,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
*
|
||||
* @return the text area object
|
||||
*/
|
||||
public TextArea textArea() {
|
||||
public JavaTextArea textArea() {
|
||||
return ta;
|
||||
}
|
||||
|
||||
@@ -1303,7 +1219,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// return new TextArea(new PdeTextAreaDefaults(mode), this);
|
||||
// }
|
||||
protected JEditTextArea createTextArea() {
|
||||
return new TextArea(new PdeTextAreaDefaults(mode), new JavaInputHandler(this), this);
|
||||
return new JavaTextArea(new PdeTextAreaDefaults(mode), this);
|
||||
//return new JavaTextArea(new PdeTextAreaDefaults(mode), new JavaInputHandler(this), this);
|
||||
/*
|
||||
return new TextArea(new PdeTextAreaDefaults(mode), new PdeInputHandler(), this) {
|
||||
// Forwards key events directly to the input handler. This is slightly
|
||||
@@ -1347,36 +1264,36 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* @param line the line to highlight as current suspended line
|
||||
*/
|
||||
public void setCurrentLine(LineID line) {
|
||||
clearCurrentLine();
|
||||
if (line == null) {
|
||||
return; // safety, e.g. when no line mapping is found and the null line is used.
|
||||
}
|
||||
switchToTab(line.fileName());
|
||||
// scroll to line, by setting the cursor
|
||||
cursorToLineStart(line.lineIdx());
|
||||
// highlight line
|
||||
currentLine = new LineHighlight(line.lineIdx(), currentLineColor, this);
|
||||
currentLine.setMarker(ta.currentLineMarker, currentLineMarkerColor);
|
||||
currentLine.setPriority(10); // fixes current line being hidden by the breakpoint when moved down
|
||||
clearCurrentLine();
|
||||
if (line == null) {
|
||||
return; // safety, e.g. when no line mapping is found and the null line is used.
|
||||
}
|
||||
switchToTab(line.fileName());
|
||||
// scroll to line, by setting the cursor
|
||||
cursorToLineStart(line.lineIdx());
|
||||
// highlight line
|
||||
currentLine = new LineHighlight(line.lineIdx(), currentLineColor, this);
|
||||
currentLine.setMarker(ta.currentLineMarker, currentLineMarkerColor);
|
||||
currentLine.setPriority(10); // fixes current line being hidden by the breakpoint when moved down
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the highlight for the debuggers current line.
|
||||
*/
|
||||
public void clearCurrentLine() {
|
||||
if (currentLine != null) {
|
||||
currentLine.clear();
|
||||
currentLine.dispose();
|
||||
if (currentLine != null) {
|
||||
currentLine.clear();
|
||||
currentLine.dispose();
|
||||
|
||||
// revert to breakpoint color if any is set on this line
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
if (hl.lineID().equals(currentLine.lineID())) {
|
||||
hl.paint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
currentLine = null;
|
||||
// revert to breakpoint color if any is set on this line
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
if (hl.lineID().equals(currentLine.lineID())) {
|
||||
hl.paint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
currentLine = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1385,13 +1302,13 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* @param lineID the line id to highlight as breakpointed
|
||||
*/
|
||||
public void addBreakpointedLine(LineID lineID) {
|
||||
LineHighlight hl = new LineHighlight(lineID, breakpointColor, this);
|
||||
hl.setMarker(ta.breakpointMarker, breakpointMarkerColor);
|
||||
breakpointedLines.add(hl);
|
||||
// repaint current line if it's on this line
|
||||
if (currentLine != null && currentLine.lineID().equals(lineID)) {
|
||||
currentLine.paint();
|
||||
}
|
||||
LineHighlight hl = new LineHighlight(lineID, breakpointColor, this);
|
||||
hl.setMarker(ta.breakpointMarker, breakpointMarkerColor);
|
||||
breakpointedLines.add(hl);
|
||||
// repaint current line if it's on this line
|
||||
if (currentLine != null && currentLine.lineID().equals(lineID)) {
|
||||
currentLine.paint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1402,7 +1319,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
*/
|
||||
//TODO: remove and replace by {@link #addBreakpointedLine(LineID lineID)}
|
||||
public void addBreakpointedLine(int lineIdx) {
|
||||
addBreakpointedLine(getLineIDInCurrentTab(lineIdx));
|
||||
addBreakpointedLine(getLineIDInCurrentTab(lineIdx));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1413,43 +1330,43 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* highlight from
|
||||
*/
|
||||
public void removeBreakpointedLine(int lineIdx) {
|
||||
LineID line = getLineIDInCurrentTab(lineIdx);
|
||||
//System.out.println("line id: " + line.fileName() + " " + line.lineIdx());
|
||||
LineHighlight foundLine = null;
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
if (hl.lineID.equals(line)) {
|
||||
foundLine = hl;
|
||||
break;
|
||||
}
|
||||
LineID line = getLineIDInCurrentTab(lineIdx);
|
||||
//System.out.println("line id: " + line.fileName() + " " + line.lineIdx());
|
||||
LineHighlight foundLine = null;
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
if (hl.lineID.equals(line)) {
|
||||
foundLine = hl;
|
||||
break;
|
||||
}
|
||||
if (foundLine != null) {
|
||||
foundLine.clear();
|
||||
breakpointedLines.remove(foundLine);
|
||||
foundLine.dispose();
|
||||
// repaint current line if it's on this line
|
||||
if (currentLine != null && currentLine.lineID().equals(line)) {
|
||||
currentLine.paint();
|
||||
}
|
||||
}
|
||||
if (foundLine != null) {
|
||||
foundLine.clear();
|
||||
breakpointedLines.remove(foundLine);
|
||||
foundLine.dispose();
|
||||
// repaint current line if it's on this line
|
||||
if (currentLine != null && currentLine.lineID().equals(line)) {
|
||||
currentLine.paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all highlights for breakpointed lines.
|
||||
*/
|
||||
public void clearBreakpointedLines() {
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
hl.clear();
|
||||
hl.dispose();
|
||||
}
|
||||
breakpointedLines.clear(); // remove all breakpoints
|
||||
// fix highlights not being removed when tab names have changed due to opening a new sketch in same editor
|
||||
ta.clearLineBgColors(); // force clear all highlights
|
||||
ta.clearGutterText();
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
hl.clear();
|
||||
hl.dispose();
|
||||
}
|
||||
breakpointedLines.clear(); // remove all breakpoints
|
||||
// fix highlights not being removed when tab names have changed due to opening a new sketch in same editor
|
||||
ta.clearLineBgColors(); // force clear all highlights
|
||||
ta.clearGutterText();
|
||||
|
||||
// repaint current line
|
||||
if (currentLine != null) {
|
||||
currentLine.paint();
|
||||
}
|
||||
// repaint current line
|
||||
if (currentLine != null) {
|
||||
currentLine.paint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1460,7 +1377,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* current tab
|
||||
*/
|
||||
public LineID getLineIDInCurrentTab(int lineIdx) {
|
||||
return new LineID(getSketch().getCurrentCode().getFileName(), lineIdx);
|
||||
return new LineID(getSketch().getCurrentCode().getFileName(), lineIdx);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1469,9 +1386,9 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* @return the current {@link LineID}
|
||||
*/
|
||||
protected LineID getCurrentLineID() {
|
||||
String tab = getSketch().getCurrentCode().getFileName();
|
||||
int lineNo = getTextArea().getCaretLine();
|
||||
return new LineID(tab, lineNo);
|
||||
String tab = getSketch().getCurrentCode().getFileName();
|
||||
int lineNo = getTextArea().getCaretLine();
|
||||
return new LineID(tab, lineNo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1481,7 +1398,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* @return true, if the {@link LineID} is on the current tab.
|
||||
*/
|
||||
public boolean isInCurrentTab(LineID line) {
|
||||
return line.fileName().equals(getSketch().getCurrentCode().getFileName());
|
||||
return line.fileName().equals(getSketch().getCurrentCode().getFileName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1492,32 +1409,32 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
*/
|
||||
@Override
|
||||
protected void setCode(SketchCode code) {
|
||||
//System.out.println("tab switch: " + code.getFileName());
|
||||
super.setCode(code); // set the new document in the textarea, etc. need to do this first
|
||||
//System.out.println("tab switch: " + code.getFileName());
|
||||
super.setCode(code); // set the new document in the textarea, etc. need to do this first
|
||||
|
||||
// set line background colors for tab
|
||||
if (ta != null) { // can be null when setCode is called the first time (in constructor)
|
||||
// clear all line backgrounds
|
||||
ta.clearLineBgColors();
|
||||
// clear all gutter text
|
||||
ta.clearGutterText();
|
||||
// load appropriate line backgrounds for tab
|
||||
// first paint breakpoints
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
if (isInCurrentTab(hl.lineID())) {
|
||||
hl.paint();
|
||||
}
|
||||
}
|
||||
// now paint current line (if any)
|
||||
if (currentLine != null) {
|
||||
if (isInCurrentTab(currentLine.lineID())) {
|
||||
currentLine.paint();
|
||||
}
|
||||
}
|
||||
// set line background colors for tab
|
||||
if (ta != null) { // can be null when setCode is called the first time (in constructor)
|
||||
// clear all line backgrounds
|
||||
ta.clearLineBgColors();
|
||||
// clear all gutter text
|
||||
ta.clearGutterText();
|
||||
// load appropriate line backgrounds for tab
|
||||
// first paint breakpoints
|
||||
for (LineHighlight hl : breakpointedLines) {
|
||||
if (isInCurrentTab(hl.lineID())) {
|
||||
hl.paint();
|
||||
}
|
||||
}
|
||||
if (dbg() != null && dbg().isStarted()) {
|
||||
dbg().startTrackingLineChanges();
|
||||
// now paint current line (if any)
|
||||
if (currentLine != null) {
|
||||
if (isInCurrentTab(currentLine.lineID())) {
|
||||
currentLine.paint();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dbg() != null && dbg().isStarted()) {
|
||||
dbg().startTrackingLineChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1528,13 +1445,13 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* not found
|
||||
*/
|
||||
public SketchCode getTab(String fileName) {
|
||||
Sketch s = getSketch();
|
||||
for (SketchCode c : s.getCode()) {
|
||||
if (c.getFileName().equals(fileName)) {
|
||||
return c;
|
||||
}
|
||||
Sketch s = getSketch();
|
||||
for (SketchCode c : s.getCode()) {
|
||||
if (c.getFileName().equals(fileName)) {
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1543,7 +1460,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* @return the {@link SketchCode} representing the current tab
|
||||
*/
|
||||
public SketchCode getCurrentTab() {
|
||||
return getSketch().getCurrentCode();
|
||||
return getSketch().getCurrentCode();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1552,8 +1469,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* @return the document object
|
||||
*/
|
||||
public Document currentDocument() {
|
||||
//return ta.getDocument();
|
||||
return getCurrentTab().getDocument();
|
||||
//return ta.getDocument();
|
||||
return getCurrentTab().getDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1573,19 +1490,19 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* @param lineIdx the line (0-based) that was double clicked
|
||||
*/
|
||||
public void gutterDblClicked(int lineIdx) {
|
||||
if (dbg != null) {
|
||||
dbg.toggleBreakpoint(lineIdx);
|
||||
}
|
||||
if (dbg != null) {
|
||||
dbg.toggleBreakpoint(lineIdx);
|
||||
}
|
||||
}
|
||||
|
||||
public void statusBusy() {
|
||||
statusNotice("Debugger busy...");
|
||||
statusNotice("Debugger busy...");
|
||||
}
|
||||
|
||||
public void statusHalted() {
|
||||
statusNotice("Debugger halted.");
|
||||
statusNotice("Debugger halted.");
|
||||
}
|
||||
|
||||
|
||||
public static final int STATUS_EMPTY = 100, STATUS_COMPILER_ERR = 200,
|
||||
STATUS_WARNING = 300, STATUS_INFO = 400, STATUS_ERR = 500;
|
||||
public int statusMessageType = STATUS_EMPTY;
|
||||
@@ -1611,7 +1528,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
}
|
||||
// Don't need to clear compiler error messages
|
||||
if(type == STATUS_COMPILER_ERR) return;
|
||||
|
||||
|
||||
// Clear the message after a delay
|
||||
SwingWorker<Object, Object> s = new SwingWorker<Object, Object>() {
|
||||
@Override
|
||||
@@ -1627,15 +1544,15 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
};
|
||||
s.execute();
|
||||
}
|
||||
|
||||
|
||||
public void statusEmpty(){
|
||||
statusMessage = null;
|
||||
statusMessageType = STATUS_EMPTY;
|
||||
super.statusEmpty();
|
||||
}
|
||||
|
||||
|
||||
public ErrorCheckerService errorCheckerService;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes and starts Error Checker Service
|
||||
*/
|
||||
@@ -1650,20 +1567,20 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
} catch (Exception e) {
|
||||
System.err
|
||||
.println("Error Checker Service not initialized [XQEditor]: "
|
||||
+ e);
|
||||
+ e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
// System.out.println("Error Checker Service initialized.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the error bar
|
||||
* @param problems
|
||||
*/
|
||||
public void updateErrorBar(ArrayList<Problem> problems) {
|
||||
errorBar.updateErrorPoints(problems);
|
||||
errorBar.updateErrorPoints(problems);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1676,7 +1593,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
CardLayout cl = (CardLayout) consoleProblemsPane.getLayout();
|
||||
cl.show(consoleProblemsPane, buttonName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the error table
|
||||
* @param tableModel
|
||||
@@ -1685,34 +1602,32 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
synchronized public boolean updateTable(final TableModel tableModel) {
|
||||
return errorTable.updateTable(tableModel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle whether the tiny red error indicator is shown near the error button
|
||||
* at the bottom of the PDE
|
||||
*/
|
||||
public void updateErrorToggle(){
|
||||
btnShowErrors.updateMarker(ExperimentalMode.errorCheckEnabled
|
||||
&& errorCheckerService.hasErrors(), errorBar.errorColor);
|
||||
btnShowErrors.updateMarker(ExperimentalMode.errorCheckEnabled
|
||||
&& errorCheckerService.hasErrors(), errorBar.errorColor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle refactor operation
|
||||
*/
|
||||
private void handleRefactor() {
|
||||
log("Caret at:");
|
||||
log(ta.getLineText(ta.getCaretLine()));
|
||||
Base.log("Caret at:" + ta.getLineText(ta.getCaretLine()));
|
||||
errorCheckerService.getASTGenerator().handleRefactor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle show usage operation
|
||||
*/
|
||||
private void handleShowUsage() {
|
||||
log("Caret at:");
|
||||
log(ta.getLineText(ta.getCaretLine()));
|
||||
Base.log("Caret at:" + ta.getLineText(ta.getCaretLine()));
|
||||
errorCheckerService.getASTGenerator().handleShowUsage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the sketch contains java tabs. If it does, the editor ain't built
|
||||
* for it, yet. Also, user should really start looking at more powerful IDEs
|
||||
@@ -1725,8 +1640,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
compilationCheckEnabled = false;
|
||||
hasJavaTabs = true;
|
||||
JOptionPane.showMessageDialog(new Frame(), this
|
||||
.getSketch().getName()
|
||||
+ " contains .java tabs. Some editor features are not supported " +
|
||||
.getSketch().getName()
|
||||
+ " contains .java tabs. Some editor features are not supported " +
|
||||
"for .java tabs and will be disabled.");
|
||||
break;
|
||||
}
|
||||
@@ -1737,7 +1652,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
super.applyPreferences();
|
||||
if (dmode != null) {
|
||||
dmode.loadPreferences();
|
||||
log("Applying prefs");
|
||||
Base.log("Applying prefs");
|
||||
// trigger it once to refresh UI
|
||||
errorCheckerService.runManualErrorCheck();
|
||||
}
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/* -*- 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
|
||||
|
||||
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.
|
||||
|
||||
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.debug;
|
||||
|
||||
import com.sun.jdi.VirtualMachine;
|
||||
import processing.app.RunnerListener;
|
||||
import processing.app.SketchException;
|
||||
import processing.app.exec.StreamRedirectThread;
|
||||
import processing.mode.java.JavaBuild;
|
||||
import processing.mode.java.runner.MessageSiphon;
|
||||
|
||||
/**
|
||||
* Runs a {@link JavaBuild}. Launches the build in a new debuggee VM.
|
||||
*
|
||||
* @author Martin Leopold <m@martinleopold.com>
|
||||
*/
|
||||
public class DebugRunner extends processing.mode.java.runner.Runner {
|
||||
|
||||
// important inherited fields
|
||||
// protected VirtualMachine vm;
|
||||
public DebugRunner(JavaBuild build, RunnerListener listener) throws SketchException {
|
||||
super(build, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the virtual machine. Simple non-blocking launch. VM starts
|
||||
* suspended.
|
||||
*
|
||||
* @return debuggee VM or null on failure
|
||||
*/
|
||||
public VirtualMachine launch() {
|
||||
// String[] machineParamList = getMachineParams();
|
||||
// String[] sketchParamList = getSketchParams(false);
|
||||
// /*
|
||||
// * System.out.println("vm launch sketch params:"); for (int i=0;
|
||||
// * i<sketchParamList.length; i++) {
|
||||
// * System.out.println(sketchParamList[i]); } System.out.println("vm
|
||||
// * launch machine params:"); for (int i=0; i<machineParamList.length;
|
||||
// * i++) { System.out.println(machineParamList[i]); }
|
||||
// *
|
||||
// */
|
||||
// vm = launchVirtualMachine(machineParamList, sketchParamList); // will return null on failure
|
||||
if (launchVirtualMachine(false)) { // will return null on failure
|
||||
redirectStreams(vm);
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect a VMs output and error streams to System.out and System.err
|
||||
*
|
||||
* @param vm the VM
|
||||
*/
|
||||
protected void redirectStreams(VirtualMachine vm) {
|
||||
MessageSiphon ms = new MessageSiphon(process.getErrorStream(), this);
|
||||
errThread = ms.getThread();
|
||||
outThread = new StreamRedirectThread("VM output reader", process.getInputStream(), System.out);
|
||||
errThread.start();
|
||||
outThread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional access to the virtual machine. TODO: may not be needed
|
||||
*
|
||||
* @return debugge VM or null if not running
|
||||
*/
|
||||
public VirtualMachine vm() {
|
||||
return vm;
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,7 @@ import processing.app.SketchCode;
|
||||
import processing.mode.java.JavaBuild;
|
||||
import processing.mode.java.pdex.VMEventListener;
|
||||
import processing.mode.java.pdex.VMEventReader;
|
||||
import processing.mode.java.runner.Runner;
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ import processing.mode.java.pdex.VMEventReader;
|
||||
public class Debugger implements VMEventListener {
|
||||
|
||||
protected DebugEditor editor; // editor window, acting as main view
|
||||
protected DebugRunner runtime; // the runtime, contains debuggee VM
|
||||
protected Runner runtime; // the runtime, contains debuggee VM
|
||||
protected boolean started = false; // debuggee vm has started, VMStartEvent received, main class loaded
|
||||
protected boolean paused = false; // currently paused at breakpoint or step
|
||||
protected ThreadReference currentThread; // thread the last breakpoint or step occured in
|
||||
@@ -202,8 +203,8 @@ public class Debugger implements VMEventListener {
|
||||
//lineMap = LineMapping.generateMapping(srcPath + File.separator + mainClassName + ".java");
|
||||
|
||||
Logger.getLogger(Debugger.class.getName()).log(Level.INFO, "launching debuggee runtime");
|
||||
runtime = new DebugRunner(build, editor);
|
||||
VirtualMachine vm = runtime.launch(); // non-blocking
|
||||
runtime = new Runner(build, editor);
|
||||
VirtualMachine vm = runtime.launchDebug(); // non-blocking
|
||||
if (vm == null) {
|
||||
Logger.getLogger(Debugger.class.getName()).log(Level.SEVERE, "error 37: launch failed");
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.debug;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import processing.app.Base;
|
||||
|
||||
import com.sun.jdi.AbsentInformationException;
|
||||
import com.sun.jdi.Location;
|
||||
import com.sun.jdi.ReferenceType;
|
||||
@@ -219,13 +219,13 @@ public class LineBreakpoint implements ClassLoadListener {
|
||||
@Override
|
||||
public void classLoaded(ReferenceType theClass) {
|
||||
// check if our class is being loaded
|
||||
log("Class Loaded: " + theClass.name());
|
||||
Base.log("Class Loaded: " + theClass.name());
|
||||
if (theClass.name().equals(className())) {
|
||||
this.theClass = theClass;
|
||||
attach();
|
||||
}
|
||||
for (ReferenceType ct : theClass.nestedTypes()) {
|
||||
log("Nested " + ct.name());
|
||||
Base.log("Nested " + ct.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.logE;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
@@ -288,7 +285,7 @@ public class ASTGenerator {
|
||||
.types().get(0)));
|
||||
//log("Total CU " + compilationUnit.types().size());
|
||||
if(compilationUnit.types() == null || compilationUnit.types().isEmpty()){
|
||||
logE("No CU found!");
|
||||
Base.loge("No CU found!");
|
||||
}
|
||||
visitRecur((ASTNode) compilationUnit.types().get(0), codeTree);
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
@@ -330,7 +327,7 @@ public class ASTGenerator {
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
// logE("++>" + System.getProperty("java.class.path"));
|
||||
// Base.loge("++>" + System.getProperty("java.class.path"));
|
||||
// log(System.getProperty("java.class.path"));
|
||||
// log("-------------------------------");
|
||||
return codeTree;
|
||||
@@ -907,9 +904,9 @@ public class ASTGenerator {
|
||||
parser.setKind(ASTParser.K_EXPRESSION);
|
||||
parser.setSource(word2.toCharArray());
|
||||
ASTNode testnode = parser.createAST(null);
|
||||
//logE("PREDICTION PARSER PROBLEMS: " + parser);
|
||||
//Base.loge("PREDICTION PARSER PROBLEMS: " + parser);
|
||||
// Find closest ASTNode of the document to this word
|
||||
logE("Typed: " + word2 + "|" + " temp Node type: " + testnode.getClass().getSimpleName());
|
||||
Base.loge("Typed: " + word2 + "|" + " temp Node type: " + testnode.getClass().getSimpleName());
|
||||
if(testnode instanceof MethodInvocation){
|
||||
MethodInvocation mi = (MethodInvocation)testnode;
|
||||
log(mi.getName() + "," + mi.getExpression() + "," + mi.typeArguments().size());
|
||||
@@ -922,7 +919,7 @@ public class ASTGenerator {
|
||||
// Make sure nearestNode is not NULL if couldn't find a closeset node
|
||||
nearestNode = (ASTNode) errorCheckerService.getLastCorrectCU().types().get(0);
|
||||
}
|
||||
logE(lineNumber + " Nearest ASTNode to PRED "
|
||||
Base.loge(lineNumber + " Nearest ASTNode to PRED "
|
||||
+ getNodeAsString(nearestNode));
|
||||
|
||||
candidates = new ArrayList<CompletionCandidate>();
|
||||
@@ -930,7 +927,7 @@ public class ASTGenerator {
|
||||
// Determine the expression typed
|
||||
|
||||
if (testnode instanceof SimpleName && !noCompare) {
|
||||
logE("One word expression " + getNodeAsString(testnode));
|
||||
Base.loge("One word expression " + getNodeAsString(testnode));
|
||||
//==> Simple one word exprssion - so is just an identifier
|
||||
|
||||
// Bottom up traversal of the AST to look for possible definitions at
|
||||
@@ -1022,7 +1019,7 @@ public class ASTGenerator {
|
||||
|
||||
// ==> Complex expression of type blah.blah2().doIt,etc
|
||||
// Have to resolve it by carefully traversing AST of testNode
|
||||
logE("Complex expression " + getNodeAsString(testnode));
|
||||
Base.loge("Complex expression " + getNodeAsString(testnode));
|
||||
log("candidates empty");
|
||||
ASTNode childExpr = getChildExpression(testnode);
|
||||
log("Parent expression : " + getParentExpression(testnode));
|
||||
@@ -1282,7 +1279,7 @@ public class ASTGenerator {
|
||||
- lineElement.getStartOffset());
|
||||
return javaLine;
|
||||
} catch (BadLocationException e) {
|
||||
logE(e + " in getJavaSourceCodeline() for jinenum: " + javaLineNumber);
|
||||
Base.loge(e + " in getJavaSourceCodeline() for jinenum: " + javaLineNumber);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1309,7 +1306,7 @@ public class ASTGenerator {
|
||||
// - lineElement.getStartOffset());
|
||||
return lineElement;
|
||||
} catch (BadLocationException e) {
|
||||
logE(e + " in getJavaSourceCodeline() for jinenum: " + javaLineNumber);
|
||||
Base.loge(e + " in getJavaSourceCodeline() for jinenum: " + javaLineNumber);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1516,7 +1513,7 @@ public class ASTGenerator {
|
||||
protected static ASTNode findClosestParentNode(int lineNumber, ASTNode node) {
|
||||
Iterator<StructuralPropertyDescriptor> it = node
|
||||
.structuralPropertiesForType().iterator();
|
||||
// logE("Props of " + node.getClass().getName());
|
||||
// Base.loge("Props of " + node.getClass().getName());
|
||||
while (it.hasNext()) {
|
||||
StructuralPropertyDescriptor prop = it.next();
|
||||
|
||||
@@ -1745,12 +1742,12 @@ public class ASTGenerator {
|
||||
// log(getNodeAsString(simpName));
|
||||
decl = findDeclaration((SimpleName) simpName);
|
||||
if (decl != null) {
|
||||
// logE("DECLA: " + decl.getClass().getName());
|
||||
// Base.loge("DECLA: " + decl.getClass().getName());
|
||||
nodeLabel = getLabelIfType(new ASTNodeWrapper(decl),
|
||||
(SimpleName) simpName);
|
||||
//retLabelString = getNodeAsString(decl);
|
||||
} else {
|
||||
// logE("null");
|
||||
// Base.loge("null");
|
||||
if (scrollOnly) {
|
||||
editor.statusMessage(simpName + " is not defined in this sketch",
|
||||
DebugEditor.STATUS_ERR);
|
||||
@@ -1784,13 +1781,13 @@ public class ASTGenerator {
|
||||
* since it contains all the properties.
|
||||
*/
|
||||
ASTNode simpName2 = getNodeName(decl, nameOfNode);
|
||||
// logE("FINAL String decl: " + getNodeAsString(decl));
|
||||
// logE("FINAL String label: " + getNodeAsString(simpName2));
|
||||
// Base.loge("FINAL String decl: " + getNodeAsString(decl));
|
||||
// Base.loge("FINAL String label: " + getNodeAsString(simpName2));
|
||||
//errorCheckerService.highlightNode(simpName2);
|
||||
ASTNodeWrapper declWrap = new ASTNodeWrapper(simpName2, nodeLabel);
|
||||
//errorCheckerService.highlightNode(declWrap);
|
||||
if (!declWrap.highlightNode(this)) {
|
||||
logE("Highlighting failed.");
|
||||
Base.loge("Highlighting failed.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1872,11 +1869,10 @@ public class ASTGenerator {
|
||||
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
|
||||
log(CompilationUnit.propertyDescriptors(AST.JLS4).size());
|
||||
|
||||
DefaultMutableTreeNode astTree = new DefaultMutableTreeNode(
|
||||
"CompilationUnit");
|
||||
logE("Errors: " + cu.getProblems().length);
|
||||
DefaultMutableTreeNode astTree = new DefaultMutableTreeNode("CompilationUnit");
|
||||
Base.loge("Errors: " + cu.getProblems().length);
|
||||
visitRecur(cu, astTree);
|
||||
log(astTree.getChildCount());
|
||||
Base.log("" + astTree.getChildCount());
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
@@ -1894,10 +1890,11 @@ public class ASTGenerator {
|
||||
|
||||
ASTNode found = NodeFinder.perform(cu, 468, 5);
|
||||
if (found != null) {
|
||||
log(found);
|
||||
Base.log(found.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final ASTGenerator thisASTGenerator = this;
|
||||
|
||||
protected void addListeners(){
|
||||
@@ -1905,7 +1902,7 @@ public class ASTGenerator {
|
||||
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
log(e);
|
||||
Base.log(e.toString());
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
|
||||
@Override
|
||||
@@ -2093,7 +2090,7 @@ public class ASTGenerator {
|
||||
lineOffsetDisplacement.put(awrap.getLineNumber(),
|
||||
lineOffsetDisplacementConst);
|
||||
}
|
||||
// logE(getNodeAsString(awrap.getNode()) + ", T:" + pdeOffsets[i][0]
|
||||
// Base.loge(getNodeAsString(awrap.getNode()) + ", T:" + pdeOffsets[i][0]
|
||||
// + ", L:" + pdeOffsets[i][1] + ", O:" + pdeOffsets[i][2]);
|
||||
highlightPDECode(pdeOffsets[i][0],
|
||||
pdeOffsets[i][1], pdeOffsets[i][2]
|
||||
@@ -2204,7 +2201,7 @@ public class ASTGenerator {
|
||||
if(wnode.getNode() == null){
|
||||
return null;
|
||||
}
|
||||
logE("Gonna find all occurrences of "
|
||||
Base.loge("Gonna find all occurrences of "
|
||||
+ getNodeAsString(wnode.getNode()));
|
||||
|
||||
//If wnode is a constructor, find the TD instead.
|
||||
@@ -2221,7 +2218,7 @@ public class ASTGenerator {
|
||||
if(node != null && node instanceof TypeDeclaration){
|
||||
TypeDeclaration td = (TypeDeclaration) node;
|
||||
if(td.getName().toString().equals(md.getName().toString())){
|
||||
logE("Renaming constructor of " + getNodeAsString(td));
|
||||
Base.loge("Renaming constructor of " + getNodeAsString(td));
|
||||
wnode = new ASTNodeWrapper(td);
|
||||
}
|
||||
}
|
||||
@@ -2257,7 +2254,7 @@ public class ASTGenerator {
|
||||
public static void visitRecur(ASTNode node, DefaultMutableTreeNode tnode) {
|
||||
Iterator<StructuralPropertyDescriptor> it =
|
||||
node.structuralPropertiesForType().iterator();
|
||||
//logE("Props of " + node.getClass().getName());
|
||||
//Base.loge("Props of " + node.getClass().getName());
|
||||
DefaultMutableTreeNode ctnode = null;
|
||||
while (it.hasNext()) {
|
||||
StructuralPropertyDescriptor prop = it.next();
|
||||
@@ -2461,7 +2458,7 @@ public class ASTGenerator {
|
||||
}
|
||||
log("Visiting: " + getNodeAsString(node));
|
||||
ASTNode decl2 = findDeclaration(sn);
|
||||
logE("It's decl: " + getNodeAsString(decl2));
|
||||
Base.loge("It's decl: " + getNodeAsString(decl2));
|
||||
log("But we need: "+getNodeAsString(decl));
|
||||
for (ASTNode astNode : nodesToBeMatched) {
|
||||
if(astNode.equals(decl2)){
|
||||
@@ -2525,7 +2522,7 @@ public class ASTGenerator {
|
||||
public static void printRecur(ASTNode node) {
|
||||
Iterator<StructuralPropertyDescriptor> it = node
|
||||
.structuralPropertiesForType().iterator();
|
||||
//logE("Props of " + node.getClass().getName());
|
||||
//Base.loge("Props of " + node.getClass().getName());
|
||||
while (it.hasNext()) {
|
||||
StructuralPropertyDescriptor prop = it.next();
|
||||
|
||||
@@ -2559,12 +2556,12 @@ public class ASTGenerator {
|
||||
CompilationUnit root = (CompilationUnit) node.getRoot();
|
||||
// log("Inside "+getNodeAsString(node) + " | " + root.getLineNumber(node.getStartPosition()));
|
||||
if (root.getLineNumber(node.getStartPosition()) == lineNumber) {
|
||||
// logE(3 + getNodeAsString(node) + " len " + node.getLength());
|
||||
// Base.loge(3 + getNodeAsString(node) + " len " + node.getLength());
|
||||
return node;
|
||||
// if (offset < node.getLength())
|
||||
// return node;
|
||||
// else {
|
||||
// logE(-11);
|
||||
// Base.loge(-11);
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
@@ -2577,7 +2574,7 @@ public class ASTGenerator {
|
||||
.getStructuralProperty(prop),
|
||||
lineNumber, offset, name);
|
||||
if (retNode != null) {
|
||||
// logE(11 + getNodeAsString(retNode));
|
||||
// Base.loge(11 + getNodeAsString(retNode));
|
||||
return retNode;
|
||||
}
|
||||
}
|
||||
@@ -2589,13 +2586,13 @@ public class ASTGenerator {
|
||||
|
||||
ASTNode rr = findLineOfNode(retNode, lineNumber, offset, name);
|
||||
if (rr != null) {
|
||||
// logE(12 + getNodeAsString(rr));
|
||||
// Base.loge(12 + getNodeAsString(rr));
|
||||
return rr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// logE("-1");
|
||||
// Base.loge("-1");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2638,7 +2635,7 @@ public class ASTGenerator {
|
||||
.getStructuralProperty(prop),
|
||||
offset, lineStartOffset, name);
|
||||
if (retNode != null) {
|
||||
// logE(11 + getNodeAsString(retNode));
|
||||
// Base.loge(11 + getNodeAsString(retNode));
|
||||
return retNode;
|
||||
}
|
||||
}
|
||||
@@ -2650,13 +2647,13 @@ public class ASTGenerator {
|
||||
|
||||
ASTNode rr = pinpointOnLine(retNode, offset, lineStartOffset, name);
|
||||
if (rr != null) {
|
||||
// logE(12 + getNodeAsString(rr));
|
||||
// Base.loge(12 + getNodeAsString(rr));
|
||||
return rr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// logE("-1");
|
||||
// Base.loge("-1");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3267,7 +3264,7 @@ public class ASTGenerator {
|
||||
switch (node.getNodeType()) {
|
||||
|
||||
case ASTNode.TYPE_DECLARATION:
|
||||
//logE(getNodeAsString(node));
|
||||
//Base.loge(getNodeAsString(node));
|
||||
TypeDeclaration td = (TypeDeclaration) node;
|
||||
if (td.getName().toString().equals(name)) {
|
||||
if (constrains.contains(ASTNode.CLASS_INSTANCE_CREATION)) {
|
||||
@@ -3306,25 +3303,25 @@ public class ASTGenerator {
|
||||
}
|
||||
break;
|
||||
case ASTNode.METHOD_DECLARATION:
|
||||
//logE(getNodeAsString(node));
|
||||
//Base.loge(getNodeAsString(node));
|
||||
if (((MethodDeclaration) node).getName().toString().equalsIgnoreCase(name))
|
||||
return node;
|
||||
break;
|
||||
case ASTNode.SINGLE_VARIABLE_DECLARATION:
|
||||
//logE(getNodeAsString(node));
|
||||
//Base.loge(getNodeAsString(node));
|
||||
if (((SingleVariableDeclaration) node).getName().toString().equalsIgnoreCase(name))
|
||||
return node;
|
||||
break;
|
||||
case ASTNode.FIELD_DECLARATION:
|
||||
//logE("FD" + node);
|
||||
//Base.loge("FD" + node);
|
||||
vdfList = ((FieldDeclaration) node).fragments();
|
||||
break;
|
||||
case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
|
||||
//logE("VDE" + node);
|
||||
//Base.loge("VDE" + node);
|
||||
vdfList = ((VariableDeclarationExpression) node).fragments();
|
||||
break;
|
||||
case ASTNode.VARIABLE_DECLARATION_STATEMENT:
|
||||
//logE("VDS" + node);
|
||||
//Base.loge("VDS" + node);
|
||||
vdfList = ((VariableDeclarationStatement) node).fragments();
|
||||
break;
|
||||
|
||||
@@ -3764,4 +3761,8 @@ public class ASTGenerator {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
static private void log(Object object) {
|
||||
Base.log(object == null ? "null" : object.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,6 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log2;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.logE;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
@@ -48,6 +44,8 @@ import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
|
||||
import org.eclipse.jdt.core.dom.Type;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
|
||||
import processing.app.Base;
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper class for ASTNode objects
|
||||
@@ -108,7 +106,7 @@ public class ASTNodeWrapper {
|
||||
public int[] getJavaCodeOffsets(ErrorCheckerService ecs) {
|
||||
int nodeOffset = Node.getStartPosition(), nodeLength = Node
|
||||
.getLength();
|
||||
log("0.nodeOffset " + nodeOffset);
|
||||
Base.log("0.nodeOffset " + nodeOffset);
|
||||
ASTNode thisNode = Node;
|
||||
while (thisNode.getParent() != null) {
|
||||
if (getLineNumber(thisNode.getParent()) == lineNumber) {
|
||||
@@ -129,7 +127,7 @@ public class ASTNodeWrapper {
|
||||
*/
|
||||
|
||||
int altStartPos = thisNode.getStartPosition();
|
||||
log("1.Altspos " + altStartPos);
|
||||
Base.log("1.Altspos " + altStartPos);
|
||||
thisNode = thisNode.getParent();
|
||||
Javadoc jd = null;
|
||||
|
||||
@@ -144,21 +142,21 @@ public class ASTNodeWrapper {
|
||||
if (thisNode instanceof TypeDeclaration) {
|
||||
jd = ((TypeDeclaration) thisNode).getJavadoc();
|
||||
altStartPos = getJavadocOffset((TypeDeclaration) thisNode);
|
||||
log("Has t jdoc " + ((TypeDeclaration) thisNode).getJavadoc());
|
||||
Base.log("Has t jdoc " + ((TypeDeclaration) thisNode).getJavadoc());
|
||||
} else if (thisNode instanceof MethodDeclaration) {
|
||||
altStartPos = getJavadocOffset((MethodDeclaration) thisNode);
|
||||
jd = ((MethodDeclaration) thisNode).getJavadoc();
|
||||
log("Has m jdoc " + jd);
|
||||
Base.log("Has m jdoc " + jd);
|
||||
} else if (thisNode instanceof FieldDeclaration) {
|
||||
FieldDeclaration fd = ((FieldDeclaration) thisNode);
|
||||
jd = fd.getJavadoc();
|
||||
log("Has f jdoc " + fd.getJavadoc());
|
||||
Base.log("Has f jdoc " + fd.getJavadoc());
|
||||
altStartPos = getJavadocOffset(fd);
|
||||
//nodeOffset = ((VariableDeclarationFragment)(fd.fragments().get(0))).getName().getStartPosition();
|
||||
}
|
||||
|
||||
if (jd == null) {
|
||||
log("Visiting children of node " + getNodeAsString(thisNode));
|
||||
Base.log("Visiting children of node " + getNodeAsString(thisNode));
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterator<StructuralPropertyDescriptor> it =
|
||||
thisNode.structuralPropertiesForType().iterator();
|
||||
@@ -169,9 +167,9 @@ public class ASTNodeWrapper {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ASTNode> nodelist = (List<ASTNode>)
|
||||
thisNode.getStructuralProperty(prop);
|
||||
log("prop " + prop);
|
||||
Base.log("prop " + prop);
|
||||
for (ASTNode cnode : nodelist) {
|
||||
log("Visiting node " + getNodeAsString(cnode));
|
||||
Base.log("Visiting node " + getNodeAsString(cnode));
|
||||
if (getLineNumber(cnode) == lineNumber) {
|
||||
if (flag) {
|
||||
altStartPos = cnode.getStartPosition();
|
||||
@@ -193,7 +191,7 @@ public class ASTNodeWrapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
log("Altspos " + altStartPos);
|
||||
Base.log("Altspos " + altStartPos);
|
||||
}
|
||||
|
||||
int pdeoffsets[] = getPDECodeOffsets(ecs);
|
||||
@@ -203,7 +201,7 @@ public class ASTNodeWrapper {
|
||||
return new int[] {
|
||||
lineNumber, nodeOffset + vals[0] - altStartPos, vals[1] };
|
||||
else {// no offset mapping needed
|
||||
log("joff[1] = " + (nodeOffset - altStartPos));
|
||||
Base.log("joff[1] = " + (nodeOffset - altStartPos));
|
||||
return new int[] { lineNumber, nodeOffset - altStartPos, nodeLength };
|
||||
}
|
||||
}
|
||||
@@ -223,23 +221,19 @@ public class ASTNodeWrapper {
|
||||
|
||||
Type tp = fd.getType();
|
||||
int lineNum = getLineNumber(sn);
|
||||
log("SN "+sn + ", " + lineNum);
|
||||
Base.log("SN "+sn + ", " + lineNum);
|
||||
for (ASTNode astNode : list) {
|
||||
if(getLineNumber(astNode) == lineNum)
|
||||
{
|
||||
log("first node in that line " + astNode);
|
||||
log("diff " + (sn.getStartPosition() - astNode.getStartPosition()));
|
||||
if(getLineNumber(astNode) == lineNum) {
|
||||
Base.log("first node in that line " + astNode);
|
||||
Base.log("diff " + (sn.getStartPosition() - astNode.getStartPosition()));
|
||||
return (astNode.getStartPosition());
|
||||
}
|
||||
}
|
||||
if(getLineNumber(fd.getType()) == lineNum)
|
||||
{
|
||||
log("first node in that line " + tp);
|
||||
log("diff " + (sn.getStartPosition() - tp.getStartPosition()));
|
||||
if(getLineNumber(fd.getType()) == lineNum) {
|
||||
Base.log("first node in that line " + tp);
|
||||
Base.log("diff " + (sn.getStartPosition() - tp.getStartPosition()));
|
||||
return (tp.getStartPosition());
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -256,12 +250,12 @@ public class ASTNodeWrapper {
|
||||
List<ASTNode> list = md.modifiers();
|
||||
SimpleName sn = (SimpleName) getNode();
|
||||
int lineNum = getLineNumber(sn);
|
||||
log("SN " + sn + ", " + lineNum);
|
||||
Base.log("SN " + sn + ", " + lineNum);
|
||||
|
||||
for (ASTNode astNode : list) {
|
||||
if (getLineNumber(astNode) == lineNum) {
|
||||
log("first node in that line " + astNode);
|
||||
log("diff " + (sn.getStartPosition() - astNode.getStartPosition()));
|
||||
Base.log("first node in that line " + astNode);
|
||||
Base.log("diff " + (sn.getStartPosition() - astNode.getStartPosition()));
|
||||
return (astNode.getStartPosition());
|
||||
}
|
||||
}
|
||||
@@ -269,8 +263,8 @@ public class ASTNodeWrapper {
|
||||
if (!md.isConstructor()) {
|
||||
Type tp = md.getReturnType2();
|
||||
if (getLineNumber(tp) == lineNum) {
|
||||
log("first node in that line " + tp);
|
||||
log("diff " + (sn.getStartPosition() - tp.getStartPosition()));
|
||||
Base.log("first node in that line " + tp);
|
||||
Base.log("diff " + (sn.getStartPosition() - tp.getStartPosition()));
|
||||
return (tp.getStartPosition());
|
||||
}
|
||||
}
|
||||
@@ -293,22 +287,21 @@ public class ASTNodeWrapper {
|
||||
SimpleName sn = (SimpleName) getNode();
|
||||
|
||||
int lineNum = getLineNumber(sn);
|
||||
log("SN "+sn + ", " + lineNum);
|
||||
Base.log("SN "+sn + ", " + lineNum);
|
||||
for (ASTNode astNode : list) {
|
||||
if(getLineNumber(astNode) == lineNum)
|
||||
{
|
||||
log("first node in that line " + astNode);
|
||||
log("diff " + (sn.getStartPosition() - astNode.getStartPosition()));
|
||||
if (getLineNumber(astNode) == lineNum) {
|
||||
Base.log("first node in that line " + astNode);
|
||||
Base.log("diff " + (sn.getStartPosition() - astNode.getStartPosition()));
|
||||
return (astNode.getStartPosition());
|
||||
}
|
||||
}
|
||||
|
||||
if(td.getJavadoc() != null){
|
||||
log("diff "
|
||||
if (td.getJavadoc() != null){
|
||||
Base.log("diff "
|
||||
+ (td.getJavadoc().getStartPosition() + td.getJavadoc().getLength() + 1));
|
||||
return (td.getJavadoc().getStartPosition() + td.getJavadoc().getLength() + 1);
|
||||
}
|
||||
log("getJavadocOffset(TypeDeclaration td) "+sn + ", found nothing. Meh.");
|
||||
Base.log("getJavadocOffset(TypeDeclaration td) "+sn + ", found nothing. Meh.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -342,7 +335,7 @@ public class ASTNodeWrapper {
|
||||
pi++;
|
||||
int startoffDif = pi - pj;
|
||||
int stopindex = javaCodeMap[pj + nodeLen - 1];
|
||||
log(startIndex + "SI,St" + stopindex + "sod " + startoffDif);
|
||||
Base.log(startIndex + "SI,St" + stopindex + "sod " + startoffDif);
|
||||
|
||||
// count till stopindex
|
||||
while (pdeCodeMap[pi] < stopindex && pi < pdeCodeMap.length) {
|
||||
@@ -352,7 +345,7 @@ public class ASTNodeWrapper {
|
||||
|
||||
// log("PDE maps from " + pdeeCodeMap[pi]);
|
||||
|
||||
log("pde len " + count);
|
||||
Base.log("pde len " + count);
|
||||
return new int[] { startoffDif, count };
|
||||
}
|
||||
|
||||
@@ -392,7 +385,7 @@ public class ASTNodeWrapper {
|
||||
* TODO: This is a work in progress. There may be more bugs here in hiding.
|
||||
*/
|
||||
|
||||
log("Src:" + source);
|
||||
Base.log("Src:" + source);
|
||||
// Instead of converting pde into java, how can I simply extract the same source
|
||||
// from the java code? Think. TODO
|
||||
String sourceAlt = new String(source);
|
||||
@@ -446,7 +439,7 @@ public class ASTNodeWrapper {
|
||||
|
||||
}
|
||||
if(offsetmap.isEmpty()){
|
||||
log("No offset matching needed.");
|
||||
Base.log("No offset matching needed.");
|
||||
return null;
|
||||
}
|
||||
// replace with 0xff[webcolor] and others
|
||||
@@ -462,9 +455,9 @@ public class ASTNodeWrapper {
|
||||
colorMatcher = colorPattern.matcher(sourceAlt);
|
||||
sourceAlt = colorMatcher.replaceAll("int");
|
||||
|
||||
log("From direct source: ");
|
||||
Base.log("From direct source: ");
|
||||
// sourceAlt = sourceJava;
|
||||
log(sourceAlt);
|
||||
Base.log(sourceAlt);
|
||||
|
||||
|
||||
// Create code map. Beware! Dark magic ahead.
|
||||
@@ -480,7 +473,7 @@ public class ASTNodeWrapper {
|
||||
pdeCodeMap[pj] = pdeCodeMap[pj - 1] + 1;
|
||||
}
|
||||
|
||||
log(key + ":" + offsetmap.get(key));
|
||||
Base.log(key + ":" + offsetmap.get(key));
|
||||
|
||||
int kval = offsetmap.get(key);
|
||||
if (kval > 0) {
|
||||
@@ -522,23 +515,25 @@ public class ASTNodeWrapper {
|
||||
pj++;
|
||||
}
|
||||
|
||||
// debug o/p
|
||||
for (int i = 0; i < pdeCodeMap.length; i++) {
|
||||
if (pdeCodeMap[i] > 0 || javaCodeMap[i] > 0 || i == 0) {
|
||||
if (i < source.length())
|
||||
log2(source.charAt(i));
|
||||
log2(pdeCodeMap[i] + " - " + javaCodeMap[i]);
|
||||
if (i < sourceAlt.length())
|
||||
log2(sourceAlt.charAt(i));
|
||||
log2(" <-[" + i + "]");
|
||||
log("");
|
||||
if (Base.DEBUG) {
|
||||
// debug o/p
|
||||
for (int i = 0; i < pdeCodeMap.length; i++) {
|
||||
if (pdeCodeMap[i] > 0 || javaCodeMap[i] > 0 || i == 0) {
|
||||
if (i < source.length())
|
||||
System.out.print(source.charAt(i));
|
||||
System.out.print(pdeCodeMap[i] + " - " + javaCodeMap[i]);
|
||||
if (i < sourceAlt.length())
|
||||
System.out.print(sourceAlt.charAt(i));
|
||||
System.out.print(" <-[" + i + "]");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
log("");
|
||||
|
||||
return new int[][]{javaCodeMap,pdeCodeMap};
|
||||
return new int[][] { javaCodeMap, pdeCodeMap };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Highlight the ASTNode in the editor, if it's of type
|
||||
* SimpleName
|
||||
@@ -546,7 +541,7 @@ public class ASTNodeWrapper {
|
||||
* @return - true if highlighting was successful
|
||||
*/
|
||||
public boolean highlightNode(ASTGenerator astGenerator){
|
||||
if(!(Node instanceof SimpleName)){
|
||||
if (!(Node instanceof SimpleName)) {
|
||||
return false;
|
||||
}
|
||||
SimpleName nodeName = (SimpleName) Node;
|
||||
@@ -560,7 +555,7 @@ public class ASTNodeWrapper {
|
||||
Element lineElement = javaSource.getDefaultRootElement()
|
||||
.getElement(javaLineNumber-1);
|
||||
if(lineElement == null) {
|
||||
log(lineNumber + " line element null while highlighting " + nodeName);
|
||||
Base.log(lineNumber + " line element null while highlighting " + nodeName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -570,12 +565,12 @@ public class ASTNodeWrapper {
|
||||
astGenerator.editor.getSketch().setCurrentCode(pdeOffs[0]);
|
||||
String pdeLine = astGenerator.editor.getLineText(pdeOffs[1]);
|
||||
String lookingFor = nodeName.toString();
|
||||
log(lookingFor + ", " + nodeName.getStartPosition());
|
||||
log(javaLineNumber +" JL " + javaLine + " LSO " + lineElement.getStartOffset() + ","
|
||||
Base.log(lookingFor + ", " + nodeName.getStartPosition());
|
||||
Base.log(javaLineNumber +" JL " + javaLine + " LSO " + lineElement.getStartOffset() + ","
|
||||
+ lineElement.getEndOffset());
|
||||
log(pdeOffs[1] + " PL " + pdeLine);
|
||||
Base.log(pdeOffs[1] + " PL " + pdeLine);
|
||||
if (!javaLine.contains(lookingFor) || !pdeLine.contains(lookingFor)) {
|
||||
logE("Logical error in highLightNode(). Please file a bug report.");
|
||||
Base.loge("Logical error in highLightNode(). Please file a bug report.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -584,7 +579,7 @@ public class ASTNodeWrapper {
|
||||
- lineElement.getStartOffset(),
|
||||
nodeName.getLength());
|
||||
if (highlightStart == -1) {
|
||||
logE("Logical error in highLightNode() during offset matching. " +
|
||||
Base.loge("Logical error in highLightNode() during offset matching. " +
|
||||
"Please file a bug report.");
|
||||
return false;
|
||||
}
|
||||
@@ -623,8 +618,9 @@ public class ASTNodeWrapper {
|
||||
+ index);
|
||||
*/
|
||||
return true;
|
||||
|
||||
} catch (BadLocationException e) {
|
||||
logE("BLE in highLightNode() for " + nodeName);
|
||||
Base.loge("BLE in highLightNode() for " + nodeName);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@@ -658,12 +654,9 @@ public class ASTNodeWrapper {
|
||||
public int getPDECodeOffsetForSN(ASTGenerator astGen){
|
||||
if (Node instanceof SimpleName) {
|
||||
Element lineElement = astGen.getJavaSourceCodeElement(lineNumber);
|
||||
log("Line element off " + lineElement.getStartOffset());
|
||||
OffsetMatcher ofm = new OffsetMatcher(
|
||||
astGen
|
||||
.getPDESourceCodeLine(lineNumber),
|
||||
astGen
|
||||
.getJavaSourceCodeLine(lineNumber));
|
||||
Base.log("Line element off " + lineElement.getStartOffset());
|
||||
OffsetMatcher ofm = new OffsetMatcher(astGen.getPDESourceCodeLine(lineNumber),
|
||||
astGen.getJavaSourceCodeLine(lineNumber));
|
||||
//log("");
|
||||
int pdeOffset = ofm.getPdeOffForJavaOff(Node.getStartPosition()
|
||||
- lineElement.getStartOffset(), Node.toString().length());
|
||||
@@ -699,7 +692,7 @@ public class ASTNodeWrapper {
|
||||
* @return
|
||||
*/
|
||||
public static String getJavaCode(String source){
|
||||
log("Src:" + source);
|
||||
Base.log("Src:" + source);
|
||||
String sourceAlt = new String(source);
|
||||
|
||||
// Find all #[web color]
|
||||
@@ -754,7 +747,7 @@ public class ASTNodeWrapper {
|
||||
colorMatcher = colorPattern.matcher(sourceAlt);
|
||||
sourceAlt = colorMatcher.replaceAll("int");
|
||||
|
||||
log("Converted:"+sourceAlt);
|
||||
Base.log("Converted:"+sourceAlt);
|
||||
return sourceAlt;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,6 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log2;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.logE;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
@@ -53,6 +49,7 @@ import javax.swing.plaf.InsetsUIResource;
|
||||
import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
|
||||
@@ -83,7 +80,7 @@ public class CompletionPanel {
|
||||
*/
|
||||
private int insertionPosition;
|
||||
|
||||
private TextArea textarea;
|
||||
private JavaTextArea textarea;
|
||||
|
||||
/**
|
||||
* Scroll pane in which the completion list is displayed
|
||||
@@ -105,7 +102,7 @@ public class CompletionPanel {
|
||||
*/
|
||||
public CompletionPanel(final JEditTextArea textarea, int position, String subWord,
|
||||
DefaultListModel<CompletionCandidate> items, final Point location, DebugEditor dedit) {
|
||||
this.textarea = (TextArea) textarea;
|
||||
this.textarea = (JavaTextArea) textarea;
|
||||
editor = dedit;
|
||||
this.insertionPosition = position;
|
||||
if (subWord.indexOf('.') != -1)
|
||||
@@ -338,7 +335,7 @@ public class CompletionPanel {
|
||||
}
|
||||
}
|
||||
|
||||
logE(subWord + " <= subword, Inserting suggestion=> "
|
||||
Base.loge(subWord + " <= subword, Inserting suggestion=> "
|
||||
+ selectedSuggestion + " Current sub: " + currentSubword);
|
||||
if (currentSubword.length() > 0) {
|
||||
textarea.getDocument().remove(insertionPosition - currentSubwordLen,
|
||||
@@ -359,7 +356,7 @@ public class CompletionPanel {
|
||||
}
|
||||
}
|
||||
|
||||
log("Suggestion inserted: " + System.currentTimeMillis());
|
||||
Base.log("Suggestion inserted: " + System.currentTimeMillis());
|
||||
if (completionList.getSelectedValue().getLabel().contains("...")) {
|
||||
// log("No hide");
|
||||
// Why not hide it? Coz this is the case of
|
||||
@@ -392,7 +389,7 @@ public class CompletionPanel {
|
||||
|
||||
private String fetchCurrentSubword() {
|
||||
//log("Entering fetchCurrentSubword");
|
||||
TextArea ta = editor.ta;
|
||||
JavaTextArea ta = editor.ta;
|
||||
int off = ta.getCaretPosition();
|
||||
//log2("off " + off);
|
||||
if (off < 0)
|
||||
@@ -405,9 +402,9 @@ public class CompletionPanel {
|
||||
//log2(s + " len " + s.length());
|
||||
|
||||
int x = ta.getCaretPosition() - ta.getLineStartOffset(line) - 1, x1 = x - 1;
|
||||
if(x >= s.length() || x < 0)
|
||||
if (x >= s.length() || x < 0)
|
||||
return null; //TODO: Does this check cause problems? Verify.
|
||||
log2(" x char: " + s.charAt(x));
|
||||
if (Base.DEBUG) System.out.print(" x char: " + s.charAt(x));
|
||||
//int xLS = off - getLineStartNonWhiteSpaceOffset(line);
|
||||
|
||||
String word = (x < s.length() ? s.charAt(x) : "") + "";
|
||||
@@ -564,16 +561,13 @@ public class CompletionPanel {
|
||||
break;
|
||||
|
||||
default:
|
||||
log("(CustomListRenderer)Unknown CompletionCandidate type " + cc.getType());
|
||||
Base.log("(CustomListRenderer)Unknown CompletionCandidate type " + cc.getType());
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
Base.log("(CustomListRenderer)Unknown CompletionCandidate object " + value);
|
||||
}
|
||||
else
|
||||
log("(CustomListRenderer)Unknown CompletionCandidate object " + value);
|
||||
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
@@ -69,17 +69,17 @@ public class ErrorBar extends JPanel {
|
||||
/**
|
||||
* Color of Error Marker
|
||||
*/
|
||||
public Color errorColor = new Color(0xED2630);
|
||||
public Color errorColor; // = new Color(0xED2630);
|
||||
|
||||
/**
|
||||
* Color of Warning Marker
|
||||
*/
|
||||
public Color warningColor = new Color(0xFFC30E);
|
||||
public Color warningColor; // = new Color(0xFFC30E);
|
||||
|
||||
/**
|
||||
* Background color of the component
|
||||
*/
|
||||
public Color backgroundColor = new Color(0x2C343D);
|
||||
public Color backgroundColor; // = new Color(0x2C343D);
|
||||
|
||||
/**
|
||||
* DebugEditor instance
|
||||
@@ -118,23 +118,26 @@ public class ErrorBar extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(preferredWidth, preferredHeight);
|
||||
}
|
||||
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
|
||||
public ErrorBar(DebugEditor editor, int height, ExperimentalMode mode) {
|
||||
this.editor = editor;
|
||||
this.preferredHeight = height;
|
||||
this.errorCheckerService = editor.errorCheckerService;
|
||||
errorColor = mode.getThemeColor("errorbar.errorcolor", errorColor);
|
||||
warningColor = mode
|
||||
.getThemeColor("errorbar.warningcolor", warningColor);
|
||||
backgroundColor = mode.getThemeColor("errorbar.backgroundcolor",
|
||||
backgroundColor);
|
||||
|
||||
errorColor = mode.getColor("errorbar.errorcolor"); //, errorColor);
|
||||
warningColor = mode.getColor("errorbar.warningcolor"); //, warningColor);
|
||||
backgroundColor = mode.getColor("errorbar.backgroundcolor"); //, backgroundColor);
|
||||
|
||||
addListeners();
|
||||
}
|
||||
|
||||
@@ -238,7 +241,7 @@ public class ErrorBar extends JPanel {
|
||||
*/
|
||||
protected void addListeners() {
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
addMouseListener(new MouseAdapter() {
|
||||
|
||||
// Find out which error/warning the user has clicked
|
||||
// and then scroll to that
|
||||
@@ -272,20 +275,16 @@ public class ErrorBar extends JPanel {
|
||||
});
|
||||
|
||||
// Tooltip on hover
|
||||
this.addMouseMotionListener(new MouseMotionListener() {
|
||||
|
||||
@Override
|
||||
addMouseMotionListener(new MouseMotionAdapter() {
|
||||
public void mouseMoved(final MouseEvent evt) {
|
||||
// System.out.println(e);
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
|
||||
protected Object doInBackground() throws Exception {
|
||||
for (ErrorMarker eMarker : errorPoints) {
|
||||
if (evt.getY() >= eMarker.getY() - 2
|
||||
&& evt.getY() <= eMarker.getY() + 2 + errorMarkerHeight) {
|
||||
if (evt.getY() >= eMarker.getY() - 2 &&
|
||||
evt.getY() <= eMarker.getY() + 2 + errorMarkerHeight) {
|
||||
Problem p = eMarker.getProblem();
|
||||
String msg = (p.isError() ? "Error: " : "Warning: ")
|
||||
+ p.getMessage();
|
||||
String msg = (p.isError() ? "Error: " : "Warning: ") + p.getMessage();
|
||||
setToolTipText(msg);
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
break;
|
||||
@@ -294,7 +293,7 @@ public class ErrorBar extends JPanel {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
worker.execute();
|
||||
} catch (Exception exp) {
|
||||
@@ -304,13 +303,6 @@ public class ErrorBar extends JPanel {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent arg0) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.logE;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
@@ -346,10 +343,10 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
else {
|
||||
noSleep = false;
|
||||
log("Didn't sleep!");
|
||||
Base.log("Didn't sleep!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log("Oops! [ErrorCheckerThreaded]: " + e);
|
||||
Base.log("Oops! [ErrorCheckerThreaded]: " + e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -363,7 +360,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
// Check if a certain interval has passed after the call. Only then
|
||||
// begin error check. Helps prevent unnecessary flickering. See #2677
|
||||
if (System.currentTimeMillis() - lastErrorCheckCall > errorCheckInterval) {
|
||||
log("Interval passed, starting error check");
|
||||
Base.log("Interval passed, starting error check");
|
||||
checkCode();
|
||||
checkForMissingImports();
|
||||
}
|
||||
@@ -374,7 +371,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
checkerClass = null;
|
||||
classLoader = null;
|
||||
System.gc();
|
||||
logE("Thread stopped: " + editor.getSketch().getName());
|
||||
Base.loge("Thread stopped: " + editor.getSketch().getName());
|
||||
System.gc();
|
||||
}
|
||||
|
||||
@@ -404,7 +401,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
log("Will suggest for type:" + missingClass);
|
||||
Base.log("Will suggest for type:" + missingClass);
|
||||
//astGenerator.suggestImports(missingClass);
|
||||
}
|
||||
}
|
||||
@@ -417,6 +414,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
return astGenerator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This thing acts as an event queue counter of sort.
|
||||
* Since error checking happens on demand, anytime this counter
|
||||
@@ -425,11 +423,13 @@ public class ErrorCheckerService implements Runnable {
|
||||
*/
|
||||
protected AtomicInteger textModified = new AtomicInteger();
|
||||
|
||||
|
||||
/**
|
||||
* Time stamp of last runManualErrorCheck() call.
|
||||
*/
|
||||
private volatile long lastErrorCheckCall = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Triggers error check
|
||||
*/
|
||||
@@ -439,12 +439,13 @@ public class ErrorCheckerService implements Runnable {
|
||||
lastErrorCheckCall = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
// TODO: Experimental, lookout for threading related issues
|
||||
public void quickErrorCheck() {
|
||||
//TODO: Experimental, lookout for threading related issues
|
||||
noSleep = true;
|
||||
log("quickErrorCheck()");
|
||||
}
|
||||
|
||||
|
||||
protected SketchChangedListener sketchChangedListener;
|
||||
protected class SketchChangedListener implements DocumentListener{
|
||||
|
||||
@@ -516,7 +517,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
astGenerator.buildAST(cu);
|
||||
if(!ExperimentalMode.errorCheckEnabled){
|
||||
problemsList.clear();
|
||||
log("Error Check disabled, so not updating UI.");
|
||||
Base.log("Error Check disabled, so not updating UI.");
|
||||
}
|
||||
calcPDEOffsetsForProbList();
|
||||
updateErrorTable();
|
||||
@@ -540,7 +541,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
return true;
|
||||
|
||||
} catch (Exception e) {
|
||||
log("Oops! [ErrorCheckerService.checkCode]: " + e);
|
||||
Base.log("Oops! [ErrorCheckerService.checkCode]: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@@ -770,7 +771,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
Element lineElement = javaSource.getDefaultRootElement()
|
||||
.getElement(javaLineNumber);
|
||||
if (lineElement == null) {
|
||||
log("calcPDEOffsetsForProbList(): Couldn't fetch javalinenum "
|
||||
Base.log("calcPDEOffsetsForProbList(): Couldn't fetch javalinenum "
|
||||
+ javaLineNumber + "\nProblem: " + p);
|
||||
p.setPDEOffsets(-1,-1);
|
||||
continue;
|
||||
@@ -782,7 +783,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
Element pdeLineElement = pdeTabs[p.getTabIndex()]
|
||||
.getDefaultRootElement().getElement(p.getLineNumber());
|
||||
if (pdeLineElement == null) {
|
||||
log("calcPDEOffsetsForProbList(): Couldn't fetch pdelinenum "
|
||||
Base.log("calcPDEOffsetsForProbList(): Couldn't fetch pdelinenum "
|
||||
+ javaLineNumber + "\nProblem: " + p);
|
||||
p.setPDEOffsets(-1,-1);
|
||||
continue;
|
||||
@@ -1056,7 +1057,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}*/
|
||||
|
||||
} catch (Exception e) {
|
||||
log("Exception at updateErrorTable() " + e);
|
||||
Base.log("Exception at updateErrorTable() " + e);
|
||||
e.printStackTrace();
|
||||
pauseThread();
|
||||
}
|
||||
@@ -1361,7 +1362,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log("Exception in preprocessCode()");
|
||||
Base.log("Exception in preprocessCode()");
|
||||
}
|
||||
String sourceAlt = rawCode.toString();
|
||||
// Replace comments with whitespaces
|
||||
@@ -1460,11 +1461,11 @@ public class ErrorCheckerService implements Runnable {
|
||||
* @return true - if highlighting happened correctly.
|
||||
*/
|
||||
private boolean highlightNode(ASTNodeWrapper awrap){
|
||||
log("Highlighting: " + awrap);
|
||||
Base.log("Highlighting: " + awrap);
|
||||
try {
|
||||
int pdeoffsets[] = awrap.getPDECodeOffsets(this);
|
||||
int javaoffsets[] = awrap.getJavaCodeOffsets(this);
|
||||
log("offsets: " +pdeoffsets[0] + "," +
|
||||
Base.log("offsets: " +pdeoffsets[0] + "," +
|
||||
pdeoffsets[1]+ "," +javaoffsets[1]+ "," +
|
||||
javaoffsets[2]);
|
||||
scrollToErrorLine(editor, pdeoffsets[0],
|
||||
@@ -1472,7 +1473,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
javaoffsets[2]);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logE("Scrolling failed for " + awrap);
|
||||
Base.loge("Scrolling failed for " + awrap);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@@ -1532,7 +1533,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
editor.repaint();
|
||||
} catch (Exception e) {
|
||||
logE(e
|
||||
Base.loge(e
|
||||
+ " : Error while selecting text in scrollToErrorLine(), for problem: " + p);
|
||||
}
|
||||
// log("---");
|
||||
@@ -1564,7 +1565,8 @@ public class ErrorCheckerService implements Runnable {
|
||||
edt.setSelection(lsno, lsno + length);
|
||||
edt.getTextArea().scrollTo(lineNoInTab - 1, 0);
|
||||
edt.repaint();
|
||||
log(lineStartOffset + " LSO,len " + length);
|
||||
Base.log(lineStartOffset + " LSO,len " + length);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println(e
|
||||
+ " : Error while selecting text in static scrollToErrorLine()");
|
||||
@@ -1708,7 +1710,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
if (!ExperimentalMode.errorCheckEnabled) {
|
||||
// unticked Menu Item
|
||||
// pauseThread();
|
||||
log(editor.getSketch().getName()
|
||||
Base.log(editor.getSketch().getName()
|
||||
+ " - Error Checker paused.");
|
||||
editor.errorBar.errorPoints.clear();
|
||||
problemsList.clear();
|
||||
@@ -1718,7 +1720,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
editor.errorBar.repaint();
|
||||
} else {
|
||||
//resumeThread();
|
||||
log(editor.getSketch().getName()
|
||||
Base.log(editor.getSketch().getName()
|
||||
+ " - Error Checker resumed.");
|
||||
runManualErrorCheck();
|
||||
}
|
||||
@@ -1728,7 +1730,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
* Stops the Error Checker Service thread
|
||||
*/
|
||||
public void stopThread() {
|
||||
logE("Stopping thread: " + editor.getSketch().getName());
|
||||
Base.loge("Stopping thread: " + editor.getSketch().getName());
|
||||
stopThread.set(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ package processing.mode.java.pdex;
|
||||
|
||||
import processing.mode.java.tweak.SketchParser;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
@@ -46,7 +45,7 @@ public class ExperimentalMode extends JavaMode {
|
||||
public static final boolean VERBOSE_LOGGING = true;
|
||||
//public static final boolean VERBOSE_LOGGING = false;
|
||||
public static final int LOG_SIZE = 512 * 1024; // max log file size (in bytes)
|
||||
public static boolean DEBUG = !true;
|
||||
// public static boolean DEBUG = !true;
|
||||
|
||||
|
||||
public ExperimentalMode(Base base, File folder) {
|
||||
@@ -160,12 +159,12 @@ public class ExperimentalMode extends JavaMode {
|
||||
|
||||
|
||||
public void loadPreferences() {
|
||||
log("Load PDEX prefs");
|
||||
Base.log("Load PDEX prefs");
|
||||
ensurePrefsExist();
|
||||
errorCheckEnabled = Preferences.getBoolean(prefErrorCheck);
|
||||
warningsEnabled = Preferences.getBoolean(prefWarnings);
|
||||
codeCompletionsEnabled = Preferences.getBoolean(prefCodeCompletionEnabled);
|
||||
DEBUG = Preferences.getBoolean(prefDebugOP);
|
||||
// DEBUG = Preferences.getBoolean(prefDebugOP);
|
||||
errorLogsEnabled = Preferences.getBoolean(prefErrorLogs);
|
||||
autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval);
|
||||
// untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave);
|
||||
@@ -178,11 +177,11 @@ public class ExperimentalMode extends JavaMode {
|
||||
|
||||
|
||||
public void savePreferences() {
|
||||
log("Saving PDEX prefs");
|
||||
Base.log("Saving PDEX prefs");
|
||||
Preferences.setBoolean(prefErrorCheck, errorCheckEnabled);
|
||||
Preferences.setBoolean(prefWarnings, warningsEnabled);
|
||||
Preferences.setBoolean(prefCodeCompletionEnabled, codeCompletionsEnabled);
|
||||
Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
// Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
|
||||
Preferences.setInteger(prefAutoSaveInterval, autoSaveInterval);
|
||||
// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled);
|
||||
@@ -203,7 +202,7 @@ public class ExperimentalMode extends JavaMode {
|
||||
if (Preferences.get(prefCodeCompletionEnabled) == null)
|
||||
Preferences.setBoolean(prefCodeCompletionEnabled, codeCompletionsEnabled);
|
||||
if (Preferences.get(prefDebugOP) == null)
|
||||
Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
// Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
if (Preferences.get(prefErrorLogs) == null)
|
||||
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
|
||||
if (Preferences.get(prefAutoSaveInterval) == null)
|
||||
@@ -232,41 +231,41 @@ public class ExperimentalMode extends JavaMode {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a String value from theme.txt
|
||||
*
|
||||
* @param attribute the attribute key to load
|
||||
* @param defaultValue the default value
|
||||
* @return the attributes value, or the default value if the attribute
|
||||
* couldn't be loaded
|
||||
*/
|
||||
public String loadThemeString(String attribute, String defaultValue) {
|
||||
String newString = theme.get(attribute);
|
||||
if (newString != null) {
|
||||
return newString;
|
||||
}
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error loading String: {0}", attribute);
|
||||
return defaultValue;
|
||||
}
|
||||
// /**
|
||||
// * Load a String value from theme.txt
|
||||
// *
|
||||
// * @param attribute the attribute key to load
|
||||
// * @param defaultValue the default value
|
||||
// * @return the attributes value, or the default value if the attribute
|
||||
// * couldn't be loaded
|
||||
// */
|
||||
// public String loadThemeString(String attribute, String defaultValue) {
|
||||
// String newString = theme.get(attribute);
|
||||
// if (newString != null) {
|
||||
// return newString;
|
||||
// }
|
||||
// Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error loading String: {0}", attribute);
|
||||
// return defaultValue;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Load a Color value from theme.txt
|
||||
*
|
||||
* @param attribute the attribute key to load
|
||||
* @param defaultValue the default value
|
||||
* @return the attributes value, or the default value if the attribute
|
||||
* couldn't be loaded
|
||||
*/
|
||||
public Color getThemeColor(String attribute, Color defaultValue) {
|
||||
Color newColor = theme.getColor(attribute);
|
||||
if (newColor != null) {
|
||||
return newColor;
|
||||
}
|
||||
log("error loading color: " + attribute);
|
||||
Logger.getLogger(ExperimentalMode.class.getName()).log(Level.WARNING, "Error loading Color: {0}", attribute);
|
||||
return defaultValue;
|
||||
}
|
||||
// /**
|
||||
// * Load a Color value from theme.txt
|
||||
// *
|
||||
// * @param attribute the attribute key to load
|
||||
// * @param defaultValue the default value
|
||||
// * @return the attributes value, or the default value if the attribute
|
||||
// * couldn't be loaded
|
||||
// */
|
||||
// public Color getThemeColor(String attribute, Color defaultValue) {
|
||||
// Color newColor = theme.getColor(attribute);
|
||||
// if (newColor != null) {
|
||||
// return newColor;
|
||||
// }
|
||||
// log("error loading color: " + attribute);
|
||||
// Logger.getLogger(ExperimentalMode.class.getName()).log(Level.WARNING, "Error loading Color: {0}", attribute);
|
||||
// return defaultValue;
|
||||
// }
|
||||
|
||||
|
||||
protected ImageIcon classIcon, fieldIcon, methodIcon, localVarIcon;
|
||||
@@ -298,31 +297,31 @@ public class ExperimentalMode extends JavaMode {
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* System.out.println()
|
||||
*/
|
||||
public static final void log(Object message){
|
||||
if(ExperimentalMode.DEBUG)
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* System.err.println()
|
||||
*/
|
||||
public static final void logE(Object message){
|
||||
if(ExperimentalMode.DEBUG)
|
||||
System.err.println(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* System.out.print
|
||||
*/
|
||||
public static final void log2(Object message){
|
||||
if(ExperimentalMode.DEBUG)
|
||||
System.out.print(message);
|
||||
}
|
||||
// /**
|
||||
// * System.out.println()
|
||||
// */
|
||||
// public static final void log(Object message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// System.out.println(message);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * System.err.println()
|
||||
// */
|
||||
// public static final void logE(Object message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// System.err.println(message);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * System.out.print
|
||||
// */
|
||||
// public static final void log2(Object message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// System.out.print(message);
|
||||
// }
|
||||
|
||||
|
||||
public String[] getIgnorable() {
|
||||
|
||||
@@ -20,8 +20,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log2;
|
||||
import processing.mode.java.JavaInputHandler;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.tweak.ColorControlBox;
|
||||
import processing.mode.java.tweak.Handle;
|
||||
@@ -44,67 +43,79 @@ import javax.swing.DefaultListModel;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.syntax.InputHandler;
|
||||
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 TextArea extends JEditTextArea {
|
||||
public class JavaTextArea extends JEditTextArea {
|
||||
protected PdeTextAreaDefaults defaults;
|
||||
protected DebugEditor editor;
|
||||
|
||||
protected MouseListener[] mouseListeners; // cached mouselisteners, these are wrapped by MouseHandler
|
||||
|
||||
protected DebugEditor editor; // the editor
|
||||
// contains line background colors
|
||||
protected Map<Integer, Color> lineColors = new HashMap<Integer, Color>();
|
||||
|
||||
// line properties
|
||||
protected Map<Integer, Color> lineColors = new HashMap<Integer, Color>(); // contains line background colors
|
||||
// [px] space added to the left and right of gutter chars
|
||||
protected int gutterPadding; // = 3;
|
||||
protected Color gutterBgColor; // = new Color(252, 252, 252); // gutter background color
|
||||
protected Color gutterLineColor; // = new Color(233, 233, 233); // color of vertical separation line
|
||||
|
||||
// left-hand gutter properties
|
||||
protected int gutterPadding = 3; // [px] space added to the left and right of gutter chars
|
||||
/// the text marker for highlighting breakpoints in the gutter
|
||||
public String breakpointMarker = "<>";
|
||||
/// the text marker for highlighting the current line in the gutter
|
||||
public String currentLineMarker = "->";
|
||||
|
||||
protected Color gutterBgColor = new Color(252, 252, 252); // gutter background color
|
||||
/// maps line index to gutter text
|
||||
protected Map<Integer, String> gutterText = new HashMap<Integer, String>();
|
||||
|
||||
protected Color gutterLineColor = new Color(233, 233, 233); // color of vertical separation line
|
||||
|
||||
public String breakpointMarker = "<>"; // the text marker for highlighting breakpoints in the gutter
|
||||
|
||||
public String currentLineMarker = "->"; // the text marker for highlighting the current line in the gutter
|
||||
|
||||
protected Map<Integer, String> gutterText = new HashMap<Integer, String>(); // maps line index to gutter text
|
||||
|
||||
protected Map<Integer, Color> gutterTextColors = new HashMap<Integer, Color>(); // maps line index to gutter text color
|
||||
|
||||
protected TextAreaPainter customPainter;
|
||||
/// maps line index to gutter text color
|
||||
protected Map<Integer, Color> gutterTextColors = new HashMap<Integer, Color>();
|
||||
|
||||
protected ErrorCheckerService errorCheckerService;
|
||||
|
||||
|
||||
|
||||
public TextArea(TextAreaDefaults defaults, InputHandler inputHandler, DebugEditor editor) {
|
||||
super(defaults, inputHandler);
|
||||
protected JavaTextAreaPainter getCustomPainter() {
|
||||
return (JavaTextAreaPainter) painter;
|
||||
}
|
||||
|
||||
|
||||
//public JavaTextArea(TextAreaDefaults defaults, InputHandler inputHandler, DebugEditor editor) {
|
||||
//public JavaTextArea(DebugEditor editor) {
|
||||
public JavaTextArea(TextAreaDefaults defaults, DebugEditor editor) {
|
||||
super(defaults, new JavaInputHandler(editor));
|
||||
//super(defaults, inputHandler);
|
||||
this.editor = editor;
|
||||
|
||||
// replace the painter:
|
||||
// first save listeners, these are package-private in JEditTextArea, so not accessible
|
||||
ComponentListener[] componentListeners = painter.getComponentListeners();
|
||||
// removed all this since we have the createPainter() method and we
|
||||
// won't have to remove/re-add the custom painter object [fry 150122]
|
||||
// // replace the painter:
|
||||
// // first save listeners, these are package-private in JEditTextArea, so not accessible
|
||||
// ComponentListener[] componentListeners = painter.getComponentListeners();
|
||||
mouseListeners = painter.getMouseListeners();
|
||||
MouseMotionListener[] mouseMotionListeners = painter.getMouseMotionListeners();
|
||||
|
||||
remove(painter);
|
||||
|
||||
// set new painter
|
||||
customPainter = new TextAreaPainter(this, defaults);
|
||||
painter = customPainter;
|
||||
|
||||
// set listeners
|
||||
for (ComponentListener cl : componentListeners) {
|
||||
painter.addComponentListener(cl);
|
||||
}
|
||||
|
||||
for (MouseMotionListener mml : mouseMotionListeners) {
|
||||
painter.addMouseMotionListener(mml);
|
||||
}
|
||||
// MouseMotionListener[] mouseMotionListeners = painter.getMouseMotionListeners();
|
||||
//
|
||||
// remove(painter);
|
||||
// // set new painter
|
||||
// customPainter = new TextAreaPainter(this, defaults);
|
||||
// painter = customPainter;
|
||||
//
|
||||
// // set listeners
|
||||
// for (ComponentListener cl : componentListeners) {
|
||||
// painter.addComponentListener(cl);
|
||||
// }
|
||||
//
|
||||
// for (MouseMotionListener mml : mouseMotionListeners) {
|
||||
// painter.addMouseMotionListener(mml);
|
||||
// }
|
||||
|
||||
// use a custom mouse handler instead of directly using mouseListeners
|
||||
MouseHandler mouseHandler = new MouseHandler();
|
||||
@@ -114,27 +125,28 @@ public class TextArea extends JEditTextArea {
|
||||
add(CENTER, painter);
|
||||
|
||||
// load settings from theme.txt
|
||||
ExperimentalMode theme = (ExperimentalMode) editor.getMode();
|
||||
gutterBgColor = theme.getThemeColor("gutter.bgcolor", gutterBgColor);
|
||||
gutterLineColor = theme.getThemeColor("gutter.linecolor", gutterLineColor);
|
||||
gutterPadding = theme.getInteger("gutter.padding");
|
||||
breakpointMarker = theme.loadThemeString("breakpoint.marker", breakpointMarker);
|
||||
currentLineMarker = theme.loadThemeString("currentline.marker", currentLineMarker);
|
||||
Mode mode = editor.getMode();
|
||||
gutterBgColor = mode.getColor("gutter.bgcolor"); //, gutterBgColor);
|
||||
gutterLineColor = mode.getColor("gutter.linecolor"); //, gutterLineColor);
|
||||
gutterPadding = mode.getInteger("gutter.padding");
|
||||
breakpointMarker = mode.getString("breakpoint.marker"); //, breakpointMarker);
|
||||
currentLineMarker = mode.getString("currentline.marker"); //, currentLineMarker);
|
||||
|
||||
// TweakMode code
|
||||
prevCompListeners = painter.getComponentListeners();
|
||||
prevMouseListeners = painter.getMouseListeners();
|
||||
prevMMotionListeners = painter.getMouseMotionListeners();
|
||||
prevKeyListeners = editor.getKeyListeners();
|
||||
|
||||
prevCompListeners = painter
|
||||
.getComponentListeners();
|
||||
prevMouseListeners = painter.getMouseListeners();
|
||||
prevMMotionListeners = painter
|
||||
.getMouseMotionListeners();
|
||||
prevKeyListeners = editor.getKeyListeners();
|
||||
|
||||
|
||||
interactiveMode = false;
|
||||
addPrevListeners();
|
||||
|
||||
interactiveMode = false;
|
||||
addPrevListeners();
|
||||
}
|
||||
|
||||
|
||||
protected JavaTextAreaPainter createPainter(final TextAreaDefaults defaults) {
|
||||
return new JavaTextAreaPainter(this, defaults);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets ErrorCheckerService and loads theme for TextArea(XQMode)
|
||||
@@ -145,9 +157,10 @@ public class TextArea extends JEditTextArea {
|
||||
public void setECSandThemeforTextArea(ErrorCheckerService ecs,
|
||||
ExperimentalMode mode) {
|
||||
errorCheckerService = ecs;
|
||||
customPainter.setECSandTheme(ecs, mode);
|
||||
getCustomPainter().setECSandTheme(ecs, mode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles KeyEvents for TextArea
|
||||
* Code completion begins from here.
|
||||
@@ -157,7 +170,7 @@ public class TextArea extends JEditTextArea {
|
||||
if(evt.getKeyCode() == KeyEvent.VK_ESCAPE){
|
||||
if(suggestion != null){
|
||||
if(suggestion.isVisible()){
|
||||
log("esc key");
|
||||
Base.log("esc key");
|
||||
hideSuggestion();
|
||||
evt.consume();
|
||||
return;
|
||||
@@ -199,12 +212,12 @@ public class TextArea extends JEditTextArea {
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_BACK_SPACE:
|
||||
log("BK Key");
|
||||
Base.log("BK Key");
|
||||
break;
|
||||
case KeyEvent.VK_SPACE:
|
||||
if (suggestion != null)
|
||||
if (suggestion.isVisible()) {
|
||||
log("Space bar, hide completion list");
|
||||
Base.log("Space bar, hide completion list");
|
||||
suggestion.hide();
|
||||
}
|
||||
break;
|
||||
@@ -233,8 +246,8 @@ public class TextArea extends JEditTextArea {
|
||||
|
||||
if (keyChar == '.') {
|
||||
if (ExperimentalMode.codeCompletionsEnabled) {
|
||||
log("[KeyEvent]" + KeyEvent.getKeyText(evt2.getKeyCode()) + " |Prediction started");
|
||||
log("Typing: " + fetchPhrase(evt2));
|
||||
Base.log("[KeyEvent]" + KeyEvent.getKeyText(evt2.getKeyCode()) + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt2));
|
||||
}
|
||||
} else if (keyChar == ' ') { // Trigger on Ctrl-Space
|
||||
if (!Base.isMacOS() && ExperimentalMode.codeCompletionsEnabled &&
|
||||
@@ -244,8 +257,8 @@ public class TextArea extends JEditTextArea {
|
||||
// Provide completions only if it's enabled
|
||||
if (ExperimentalMode.codeCompletionsEnabled) {
|
||||
getDocument().remove(getCaretPosition() - 1, 1); // Remove the typed space
|
||||
log("[KeyEvent]" + evt2.getKeyChar() + " |Prediction started");
|
||||
log("Typing: " + fetchPhrase(evt2));
|
||||
Base.log("[KeyEvent]" + evt2.getKeyChar() + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt2));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -268,8 +281,8 @@ public class TextArea extends JEditTextArea {
|
||||
protected Object doInBackground() throws Exception {
|
||||
// Provide completions only if it's enabled
|
||||
if (ExperimentalMode.codeCompletionsEnabled) {
|
||||
log("[KeyEvent]" + KeyEvent.getKeyText(evt2.getKeyCode()) + " |Prediction started");
|
||||
log("Typing: " + fetchPhrase(evt2));
|
||||
Base.log("[KeyEvent]" + KeyEvent.getKeyText(evt2.getKeyCode()) + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt2));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -288,8 +301,8 @@ public class TextArea extends JEditTextArea {
|
||||
// Provide completions only if it's enabled
|
||||
if (ExperimentalMode.codeCompletionsEnabled
|
||||
&& (ExperimentalMode.ccTriggerEnabled || suggestion.isVisible())) {
|
||||
log("[KeyEvent]" + evt.getKeyChar() + " |Prediction started");
|
||||
log("Typing: " + fetchPhrase(evt));
|
||||
Base.log("[KeyEvent]" + evt.getKeyChar() + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -303,7 +316,7 @@ public class TextArea extends JEditTextArea {
|
||||
* @return
|
||||
*/
|
||||
private String fetchPhrase(MouseEvent evt) {
|
||||
log("--handle Mouse Right Click--");
|
||||
Base.log("--handle Mouse Right Click--");
|
||||
int off = xyToOffset(evt.getX(), evt.getY());
|
||||
if (off < 0)
|
||||
return null;
|
||||
@@ -318,7 +331,7 @@ public class TextArea extends JEditTextArea {
|
||||
else {
|
||||
int x = xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
|
||||
int xLS = off - getLineStartNonWhiteSpaceOffset(line);
|
||||
log("x=" + x);
|
||||
Base.log("x=" + x);
|
||||
if (x < 0 || x >= s.length())
|
||||
return null;
|
||||
String word = s.charAt(x) + "";
|
||||
@@ -357,7 +370,7 @@ public class TextArea extends JEditTextArea {
|
||||
}
|
||||
if (Character.isDigit(word.charAt(0)))
|
||||
return null;
|
||||
log("Mouse click, word: " + word.trim());
|
||||
Base.log("Mouse click, word: " + word.trim());
|
||||
errorCheckerService.getASTGenerator().setLastClickedWord(line, word, xLS);
|
||||
return word.trim();
|
||||
}
|
||||
@@ -373,14 +386,14 @@ public class TextArea extends JEditTextArea {
|
||||
public String fetchPhrase(KeyEvent evt) {
|
||||
|
||||
int off = getCaretPosition();
|
||||
log2("off " + off);
|
||||
Base.log("off " + off);
|
||||
if (off < 0)
|
||||
return null;
|
||||
int line = getCaretLine();
|
||||
if (line < 0)
|
||||
return null;
|
||||
String s = getLineText(line);
|
||||
log2("lin " + line);
|
||||
Base.log(" line " + line);
|
||||
|
||||
//log2(s + " len " + s.length());
|
||||
|
||||
@@ -391,7 +404,7 @@ public class TextArea extends JEditTextArea {
|
||||
return null; //TODO: Does this check cause problems? Verify.
|
||||
}
|
||||
|
||||
log2(" x char: " + s.charAt(x));
|
||||
Base.log(" x char: " + s.charAt(x));
|
||||
|
||||
if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_'
|
||||
|| s.charAt(x) == '(' || s.charAt(x) == '.')) {
|
||||
@@ -497,9 +510,10 @@ public class TextArea extends JEditTextArea {
|
||||
* @return gutter width in pixels
|
||||
*/
|
||||
protected int getGutterWidth() {
|
||||
if (editor.debugToolbarEnabled == null || !editor.debugToolbarEnabled.get()){
|
||||
if (!editor.isDebugToolbarEnabled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FontMetrics fm = painter.getFontMetrics();
|
||||
// log("fm: " + (fm == null));
|
||||
// log("editor: " + (editor == null));
|
||||
@@ -510,6 +524,7 @@ public class TextArea extends JEditTextArea {
|
||||
return textWidth + 2 * gutterPadding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the width of margins applied to the left and right of the gutter
|
||||
* text.
|
||||
@@ -517,12 +532,13 @@ public class TextArea extends JEditTextArea {
|
||||
* @return margins in pixels
|
||||
*/
|
||||
protected int getGutterMargins() {
|
||||
if (editor.debugToolbarEnabled == null || !editor.debugToolbarEnabled.get()){
|
||||
if (!editor.isDebugToolbarEnabled()) {
|
||||
return 0;
|
||||
}
|
||||
return gutterPadding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the gutter text of a specific line.
|
||||
*
|
||||
@@ -536,6 +552,7 @@ public class TextArea extends JEditTextArea {
|
||||
painter.invalidateLine(lineIdx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the gutter text and color of a specific line.
|
||||
*
|
||||
@@ -550,6 +567,7 @@ public class TextArea extends JEditTextArea {
|
||||
gutterTextColors.put(lineIdx, textColor);
|
||||
setGutterText(lineIdx, text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the gutter text of a specific line.
|
||||
@@ -562,6 +580,7 @@ public class TextArea extends JEditTextArea {
|
||||
painter.invalidateLine(lineIdx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear all gutter text.
|
||||
*/
|
||||
@@ -583,6 +602,7 @@ public class TextArea extends JEditTextArea {
|
||||
return gutterText.get(lineIdx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the gutter text color for a specific line.
|
||||
*
|
||||
@@ -594,6 +614,7 @@ public class TextArea extends JEditTextArea {
|
||||
return gutterTextColors.get(lineIdx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the background color of a line.
|
||||
*
|
||||
@@ -618,6 +639,7 @@ public class TextArea extends JEditTextArea {
|
||||
painter.invalidateLine(lineIdx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear all line background colors.
|
||||
*/
|
||||
@@ -628,6 +650,7 @@ public class TextArea extends JEditTextArea {
|
||||
lineColors.clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a lines background color.
|
||||
*
|
||||
@@ -639,6 +662,7 @@ public class TextArea extends JEditTextArea {
|
||||
return lineColors.get(lineIdx);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a character offset to a horizontal pixel position inside the text
|
||||
* area. Overridden to take gutter width into account.
|
||||
@@ -654,6 +678,7 @@ public class TextArea extends JEditTextArea {
|
||||
return super._offsetToX(line, offset) + getGutterWidth();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a horizontal pixel position to a character offset. Overridden to
|
||||
* take gutter width into account.
|
||||
@@ -669,6 +694,7 @@ public class TextArea extends JEditTextArea {
|
||||
return super.xToOffset(line, x - getGutterWidth());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Custom mouse handler. Implements double clicking in the gutter area to
|
||||
* toggle breakpoints, sets default cursor (instead of text cursor) in the
|
||||
@@ -761,41 +787,6 @@ public class TextArea extends JEditTextArea {
|
||||
|
||||
private CompletionPanel suggestion;
|
||||
|
||||
//JEditTextArea textarea;
|
||||
|
||||
/* No longer used
|
||||
private void addCompletionPopupListner() {
|
||||
this.addKeyListener(new KeyListener() {
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (Character.isLetterOrDigit(e.getKeyChar())
|
||||
|| e.getKeyChar() == KeyEvent.VK_BACK_SPACE
|
||||
|| e.getKeyChar() == KeyEvent.VK_DELETE) {
|
||||
// SwingUtilities.invokeLater(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// showSuggestion();
|
||||
// }
|
||||
//
|
||||
// });
|
||||
} else if (Character.isWhitespace(e.getKeyChar())
|
||||
|| e.getKeyChar() == KeyEvent.VK_ESCAPE) {
|
||||
hideSuggestion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
}*/
|
||||
|
||||
|
||||
// appears unused, removed when looking to change completion trigger [fry 140801]
|
||||
/*
|
||||
@@ -810,53 +801,44 @@ public class TextArea extends JEditTextArea {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Calculates location of caret and displays the suggestion popup at the location.
|
||||
*
|
||||
* @param defListModel
|
||||
* @param listModel
|
||||
* @param subWord
|
||||
*/
|
||||
protected void showSuggestion(DefaultListModel<CompletionCandidate> defListModel,String subWord) {
|
||||
protected void showSuggestion(DefaultListModel<CompletionCandidate> listModel, String subWord) {
|
||||
hideSuggestion();
|
||||
if (defListModel.size() == 0) {
|
||||
log("TextArea: No suggestions to show.");
|
||||
return;
|
||||
}
|
||||
int position = getCaretPosition();
|
||||
Point location = new Point();
|
||||
try {
|
||||
location.x = offsetToX(getCaretLine(), position
|
||||
- getLineStartOffset(getCaretLine()));
|
||||
location.y = lineToY(getCaretLine())
|
||||
+ getPainter().getFontMetrics().getHeight() + getPainter().getFontMetrics().getDescent();
|
||||
//log("TA position: " + location);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (listModel.size() == 0) {
|
||||
Base.log("TextArea: No suggestions to show.");
|
||||
|
||||
if (subWord.length() < 2) {
|
||||
return;
|
||||
} else {
|
||||
int position = getCaretPosition();
|
||||
Point location = new Point();
|
||||
try {
|
||||
location.x = offsetToX(getCaretLine(), position
|
||||
- getLineStartOffset(getCaretLine()));
|
||||
location.y = lineToY(getCaretLine())
|
||||
+ getPainter().getFontMetrics().getHeight() + getPainter().getFontMetrics().getDescent();
|
||||
//log("TA position: " + location);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (subWord.length() < 2) {
|
||||
return;
|
||||
}
|
||||
suggestion = new CompletionPanel(this, position, subWord,
|
||||
listModel, location, editor);
|
||||
requestFocusInWindow();
|
||||
}
|
||||
//if (suggestion == null)
|
||||
suggestion = new CompletionPanel(this, position, subWord, defListModel,
|
||||
location,editor);
|
||||
// else
|
||||
// suggestion.updateList(defListModel, subWord, location, position);
|
||||
//
|
||||
// suggestion.setVisible(true);
|
||||
requestFocusInWindow();
|
||||
// SwingUtilities.invokeLater(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// requestFocusInWindow();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides suggestion popup
|
||||
*/
|
||||
|
||||
/** Hides suggestion popup */
|
||||
public void hideSuggestion() {
|
||||
if (suggestion != null) {
|
||||
suggestion.hide();
|
||||
@@ -908,10 +890,11 @@ public class TextArea extends JEditTextArea {
|
||||
removeAllListeners();
|
||||
|
||||
// add our private interaction listeners
|
||||
customPainter.addMouseListener(customPainter);
|
||||
customPainter.addMouseMotionListener(customPainter);
|
||||
customPainter.startInterativeMode();
|
||||
customPainter.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
getCustomPainter().startInterativeMode();
|
||||
// customPainter.addMouseListener(customPainter);
|
||||
// customPainter.addMouseMotionListener(customPainter);
|
||||
// customPainter.startInterativeMode();
|
||||
// customPainter.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
this.editable = false;
|
||||
this.caretBlinks = false;
|
||||
this.setCaretVisible(false);
|
||||
@@ -927,8 +910,8 @@ public class TextArea extends JEditTextArea {
|
||||
removeAllListeners();
|
||||
addPrevListeners();
|
||||
|
||||
customPainter.stopInteractiveMode();
|
||||
customPainter.setCursor(new Cursor(Cursor.TEXT_CURSOR));
|
||||
getCustomPainter().stopInteractiveMode();
|
||||
// customPainter.setCursor(new Cursor(Cursor.TEXT_CURSOR));
|
||||
this.editable = true;
|
||||
this.caretBlinks = true;
|
||||
this.setCaretVisible(true);
|
||||
@@ -945,13 +928,13 @@ public class TextArea extends JEditTextArea {
|
||||
{
|
||||
// add the original text-edit listeners
|
||||
for (ComponentListener cl : prevCompListeners) {
|
||||
customPainter.addComponentListener(cl);
|
||||
painter.addComponentListener(cl);
|
||||
}
|
||||
for (MouseListener ml : prevMouseListeners) {
|
||||
customPainter.addMouseListener(ml);
|
||||
painter.addMouseListener(ml);
|
||||
}
|
||||
for (MouseMotionListener mml : prevMMotionListeners) {
|
||||
customPainter.addMouseMotionListener(mml);
|
||||
painter.addMouseMotionListener(mml);
|
||||
}
|
||||
for (KeyListener kl : prevKeyListeners) {
|
||||
editor.addKeyListener(kl);
|
||||
@@ -960,7 +943,6 @@ public class TextArea extends JEditTextArea {
|
||||
|
||||
//public void updateInterface(ArrayList<Handle> handles[], ArrayList<ColorControlBox> colorBoxes[]) {
|
||||
public void updateInterface(List<List<Handle>> handles, List<List<ColorControlBox>> colorBoxes) {
|
||||
customPainter.updateInterface(handles, colorBoxes);
|
||||
getCustomPainter().updateInterface(handles, colorBoxes);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,10 +20,9 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.tweak.*;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Graphics;
|
||||
@@ -39,98 +38,84 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
//import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Segment;
|
||||
import javax.swing.text.Utilities;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.syntax.SyntaxDocument;
|
||||
import processing.app.syntax.TextAreaDefaults;
|
||||
import processing.app.syntax.TextAreaPainter;
|
||||
import processing.app.syntax.TokenMarker;
|
||||
|
||||
|
||||
/**
|
||||
* Customized line painter. Adds support for background colors, left hand gutter
|
||||
* area with background color and text.
|
||||
*
|
||||
* @author Martin Leopold <m@martinleopold.com>
|
||||
*/
|
||||
public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
public class JavaTextAreaPainter extends TextAreaPainter
|
||||
implements MouseListener, MouseMotionListener {
|
||||
|
||||
protected TextArea ta; // we need the subclassed textarea
|
||||
|
||||
// protected JavaTextArea ta; // we need the subclassed textarea
|
||||
protected ErrorCheckerService errorCheckerService;
|
||||
|
||||
/**
|
||||
* Error line underline color
|
||||
*/
|
||||
public Color errorColor = new Color(0xED2630);
|
||||
|
||||
/**
|
||||
* Warning line underline color
|
||||
*/
|
||||
|
||||
public Color warningColor = new Color(0xFFC30E);
|
||||
|
||||
/**
|
||||
* Color of Error Marker
|
||||
*/
|
||||
public Color errorMarkerColor = new Color(0xED2630);
|
||||
|
||||
/**
|
||||
* Color of Warning Marker
|
||||
*/
|
||||
public Color warningMarkerColor = new Color(0xFFC30E);
|
||||
public Color errorColor; // = new Color(0xED2630);
|
||||
public Color warningColor; // = new Color(0xFFC30E);
|
||||
public Color errorMarkerColor; // = new Color(0xED2630);
|
||||
public Color warningMarkerColor; // = new Color(0xFFC30E);
|
||||
|
||||
static int ctrlMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
|
||||
|
||||
public TextAreaPainter(TextArea textArea, TextAreaDefaults defaults) {
|
||||
|
||||
public JavaTextAreaPainter(JavaTextArea textArea, TextAreaDefaults defaults) {
|
||||
super(textArea, defaults);
|
||||
ta = textArea;
|
||||
// ta = textArea;
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if(ta.editor.hasJavaTabs) return; // Ctrl + Click disabled for java tabs
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
if (evt.isControlDown() || evt.isMetaDown())
|
||||
handleCtrlClick(evt);
|
||||
if (!hasJavaTabs()) { // Ctrl + Click disabled for java tabs
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
if (evt.isControlDown() || evt.isMetaDown()) {
|
||||
handleCtrlClick(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// TweakMode code
|
||||
interactiveMode = false;
|
||||
cursorType = Cursor.DEFAULT_CURSOR;
|
||||
interactiveMode = false;
|
||||
cursorType = Cursor.DEFAULT_CURSOR;
|
||||
}
|
||||
|
||||
// public void processKeyEvent(KeyEvent evt) {
|
||||
// log(evt);
|
||||
// }
|
||||
|
||||
|
||||
void handleCtrlClick(MouseEvent evt) {
|
||||
log("--handleCtrlClick--");
|
||||
int off = ta.xyToOffset(evt.getX(), evt.getY());
|
||||
Base.log("--handleCtrlClick--");
|
||||
int off = textArea.xyToOffset(evt.getX(), evt.getY());
|
||||
if (off < 0)
|
||||
return;
|
||||
int line = ta.getLineOfOffset(off);
|
||||
int line = textArea.getLineOfOffset(off);
|
||||
if (line < 0)
|
||||
return;
|
||||
String s = ta.getLineText(line);
|
||||
String s = textArea.getLineText(line);
|
||||
if (s == null)
|
||||
return;
|
||||
else if (s.length() == 0)
|
||||
return;
|
||||
else {
|
||||
int x = ta.xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
|
||||
log("x="+x);
|
||||
int xLS = off - ta.getLineStartNonWhiteSpaceOffset(line);
|
||||
int x = textArea.xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
|
||||
Base.log("x="+x);
|
||||
int xLS = off - textArea.getLineStartNonWhiteSpaceOffset(line);
|
||||
if (x < 0 || x >= s.length())
|
||||
return;
|
||||
String word = s.charAt(x) + "";
|
||||
if (s.charAt(x) == ' ')
|
||||
return;
|
||||
if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_' || s
|
||||
.charAt(x) == '$'))
|
||||
if (!(Character.isLetterOrDigit(s.charAt(x)) || s.charAt(x) == '_' || s.charAt(x) == '$'))
|
||||
return;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
@@ -164,22 +149,20 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
if (Character.isDigit(word.charAt(0)))
|
||||
return;
|
||||
|
||||
log(errorCheckerService.mainClassOffset + line +
|
||||
"|" + line + "| offset " + xLS + word + " <= \n");
|
||||
errorCheckerService.getASTGenerator()
|
||||
.scrollToDeclaration(line, word, xLS);
|
||||
Base.log(errorCheckerService.mainClassOffset + line + "|" + line + "| offset " + xLS + word + " <= \n");
|
||||
errorCheckerService.getASTGenerator().scrollToDeclaration(line, word, xLS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void loadTheme(ExperimentalMode mode) {
|
||||
errorColor = mode.getThemeColor("editor.errorcolor", errorColor);
|
||||
warningColor = mode.getThemeColor("editor.warningcolor", warningColor);
|
||||
errorMarkerColor = mode.getThemeColor("editor.errormarkercolor",
|
||||
errorMarkerColor);
|
||||
warningMarkerColor = mode.getThemeColor("editor.warningmarkercolor",
|
||||
warningMarkerColor);
|
||||
}
|
||||
// private void loadTheme(ExperimentalMode mode) {
|
||||
// errorColor = mode.getThemeColor("editor.errorcolor", errorColor);
|
||||
// warningColor = mode.getThemeColor("editor.warningcolor", warningColor);
|
||||
// errorMarkerColor = mode.getThemeColor("editor.errormarkercolor", errorMarkerColor);
|
||||
// warningMarkerColor = mode.getThemeColor("editor.warningmarkercolor", warningMarkerColor);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Paint a line. Paints the gutter (with background color and text) then the
|
||||
* line (background color and text).
|
||||
@@ -198,24 +181,19 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
try {
|
||||
// TODO This line is causing NPE's randomly ever since I added the
|
||||
// toggle for Java Mode/Debugger toolbar. [Manindra]
|
||||
super.paintLine(gfx, line, x + ta.getGutterWidth(), tokenMarker);
|
||||
super.paintLine(gfx, line, x + getGutterWidth(), tokenMarker);
|
||||
|
||||
} catch (Exception e) {
|
||||
log(e.getMessage());
|
||||
Base.log(e.getMessage());
|
||||
}
|
||||
if (ta.editor.debugToolbarEnabled != null &&
|
||||
ta.editor.debugToolbarEnabled.get()) {
|
||||
// paint gutter
|
||||
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);
|
||||
|
||||
// paint gutter symbol
|
||||
paintGutterText(gfx, line, x);
|
||||
|
||||
}
|
||||
paintErrorLine(gfx, line, x);
|
||||
}
|
||||
@@ -232,9 +210,9 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
* horizontal position
|
||||
*/
|
||||
protected void paintGutterBg(Graphics gfx, int line, int x) {
|
||||
gfx.setColor(ta.gutterBgColor);
|
||||
int y = ta.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
|
||||
gfx.fillRect(0, y, ta.getGutterWidth(), fm.getHeight());
|
||||
gfx.setColor(getTextArea().gutterBgColor);
|
||||
int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
|
||||
gfx.fillRect(0, y, getGutterWidth(), fm.getHeight());
|
||||
}
|
||||
|
||||
|
||||
@@ -249,10 +227,10 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
* horizontal position
|
||||
*/
|
||||
protected void paintGutterLine(Graphics gfx, int line, int x) {
|
||||
int y = ta.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
|
||||
gfx.setColor(ta.gutterLineColor);
|
||||
gfx.drawLine(ta.getGutterWidth(), y, ta.getGutterWidth(),
|
||||
y + fm.getHeight());
|
||||
int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
|
||||
gfx.setColor(getTextArea().gutterLineColor);
|
||||
gfx.drawLine(getGutterWidth(), y,
|
||||
getGutterWidth(), y + fm.getHeight());
|
||||
}
|
||||
|
||||
|
||||
@@ -267,30 +245,30 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
* horizontal position
|
||||
*/
|
||||
protected void paintGutterText(Graphics gfx, int line, int x) {
|
||||
String text = ta.getGutterText(line);
|
||||
String text = getTextArea().getGutterText(line);
|
||||
if (text == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
gfx.setFont(getFont());
|
||||
Color textColor = ta.getGutterTextColor(line);
|
||||
Color textColor = getTextArea().getGutterTextColor(line);
|
||||
if (textColor == null) {
|
||||
gfx.setColor(getForeground());
|
||||
} else {
|
||||
gfx.setColor(textColor);
|
||||
}
|
||||
int y = ta.lineToY(line) + fm.getHeight();
|
||||
int y = textArea.lineToY(line) + fm.getHeight();
|
||||
|
||||
// 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()),
|
||||
ta.getGutterMargins(), y, gfx, this, 0);
|
||||
getGutterMargins(), y, gfx, this, 0);
|
||||
Utilities.drawTabbedText(new Segment(text.toCharArray(), 0, text.length()),
|
||||
ta.getGutterMargins() + 1, y, gfx, this, 0);
|
||||
getGutterMargins() + 1, y, gfx, this, 0);
|
||||
Utilities.drawTabbedText(new Segment(text.toCharArray(), 0, text.length()),
|
||||
ta.getGutterMargins(), y + 1, gfx, this, 0);
|
||||
getGutterMargins(), y + 1, gfx, this, 0);
|
||||
Utilities.drawTabbedText(new Segment(text.toCharArray(), 0, text.length()),
|
||||
ta.getGutterMargins() + 1, y + 1, gfx, this, 0);
|
||||
getGutterMargins() + 1, y + 1, gfx, this, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -304,12 +282,12 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
* @param x
|
||||
*/
|
||||
protected void paintLineBgColor(Graphics gfx, int line, int x) {
|
||||
int y = ta.lineToY(line);
|
||||
int y = textArea.lineToY(line);
|
||||
y += fm.getLeading() + fm.getMaxDescent();
|
||||
int height = fm.getHeight();
|
||||
|
||||
// get the color
|
||||
Color col = ta.getLineBgColor(line);
|
||||
Color col = getTextArea().getLineBgColor(line);
|
||||
//System.out.print("bg line " + line + ": ");
|
||||
// no need to paint anything
|
||||
if (col == null) {
|
||||
@@ -366,20 +344,19 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
// Determine co-ordinates
|
||||
// log("Hoff " + ta.getHorizontalOffset() + ", " +
|
||||
// horizontalAdjustment);
|
||||
int y = ta.lineToY(line);
|
||||
int y = textArea.lineToY(line);
|
||||
y += fm.getLeading() + fm.getMaxDescent();
|
||||
// int height = fm.getHeight();
|
||||
int start = ta.getLineStartOffset(line) + problem.getPDELineStartOffset();
|
||||
int pLength = problem.getPDELineStopOffset() + 1
|
||||
- problem.getPDELineStartOffset();
|
||||
int start = textArea.getLineStartOffset(line) + problem.getPDELineStartOffset();
|
||||
int pLength = problem.getPDELineStopOffset() + 1 - problem.getPDELineStartOffset();
|
||||
|
||||
try {
|
||||
String badCode = null;
|
||||
String goodCode = null;
|
||||
try {
|
||||
badCode = ta.getDocument().getText(start, pLength);
|
||||
goodCode = ta.getDocument().getText(ta.getLineStartOffset(line),
|
||||
problem.getPDELineStartOffset());
|
||||
SyntaxDocument doc = textArea.getDocument();
|
||||
badCode = doc.getText(start, pLength);
|
||||
goodCode = doc.getText(textArea.getLineStartOffset(line), problem.getPDELineStartOffset());
|
||||
//log("paintErrorLine() LineText GC: " + goodCode);
|
||||
//log("paintErrorLine() LineText BC: " + badCode);
|
||||
} catch (BadLocationException bl) {
|
||||
@@ -391,15 +368,15 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
}
|
||||
|
||||
// Take care of offsets
|
||||
int aw = fm.stringWidth(trimRight(badCode)) + ta.getHorizontalOffset(); // apparent width. Whitespaces
|
||||
int aw = fm.stringWidth(trimRight(badCode)) + textArea.getHorizontalOffset(); // apparent width. Whitespaces
|
||||
// to the left of line + text
|
||||
// width
|
||||
int rw = fm.stringWidth(badCode.trim()); // real width
|
||||
int x1 = fm.stringWidth(goodCode) + (aw - rw), y1 = y + fm.getHeight()
|
||||
- 2, x2 = x1 + rw;
|
||||
// Adding offsets for the gutter
|
||||
x1 += ta.getGutterWidth();
|
||||
x2 += ta.getGutterWidth();
|
||||
x1 += getGutterWidth();
|
||||
x2 += getGutterWidth();
|
||||
|
||||
// gfx.fillRect(x1, y, rw, height);
|
||||
|
||||
@@ -465,34 +442,39 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
*/
|
||||
public void setECSandTheme(ErrorCheckerService ecs, ExperimentalMode mode) {
|
||||
this.errorCheckerService = ecs;
|
||||
loadTheme(mode);
|
||||
//loadTheme(mode);
|
||||
|
||||
errorColor = mode.getColor("editor.errorcolor"); //, errorColor);
|
||||
warningColor = mode.getColor("editor.warningcolor"); //, warningColor);
|
||||
errorMarkerColor = mode.getColor("editor.errormarkercolor"); //, errorMarkerColor);
|
||||
warningMarkerColor = mode.getColor("editor.warningmarkercolor"); //, warningMarkerColor);
|
||||
}
|
||||
|
||||
|
||||
public String getToolTipText(java.awt.event.MouseEvent evt) {
|
||||
if (ta.editor.hasJavaTabs) { // disabled for java tabs
|
||||
if (hasJavaTabs()) { // disabled for java tabs
|
||||
setToolTipText(null);
|
||||
return super.getToolTipText(evt);
|
||||
}
|
||||
int off = ta.xyToOffset(evt.getX(), evt.getY());
|
||||
int off = textArea.xyToOffset(evt.getX(), evt.getY());
|
||||
if (off < 0) {
|
||||
setToolTipText(null);
|
||||
return super.getToolTipText(evt);
|
||||
}
|
||||
int line = ta.getLineOfOffset(off);
|
||||
int line = textArea.getLineOfOffset(off);
|
||||
if (line < 0) {
|
||||
setToolTipText(null);
|
||||
return super.getToolTipText(evt);
|
||||
}
|
||||
String s = ta.getLineText(line);
|
||||
String s = textArea.getLineText(line);
|
||||
if (s == "")
|
||||
return evt.toString();
|
||||
else if (s.length() == 0) {
|
||||
setToolTipText(null);
|
||||
return super.getToolTipText(evt);
|
||||
} else {
|
||||
int x = ta.xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
|
||||
int xLS = off - ta.getLineStartNonWhiteSpaceOffset(line);
|
||||
int x = textArea.xToOffset(line, evt.getX()), x2 = x + 1, x1 = x - 1;
|
||||
int xLS = off - textArea.getLineStartNonWhiteSpaceOffset(line);
|
||||
if (x < 0 || x >= s.length()) {
|
||||
setToolTipText(null);
|
||||
return super.getToolTipText(evt);
|
||||
@@ -552,6 +534,7 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
return super.getToolTipText(evt);
|
||||
}
|
||||
|
||||
|
||||
// TweakMode code
|
||||
protected int horizontalAdjustment = 0;
|
||||
|
||||
@@ -572,18 +555,12 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
cursorImg, new Point(0, 0), "blank cursor");
|
||||
|
||||
|
||||
/**
|
||||
* Repaints the text.
|
||||
* @param gfx The graphics context
|
||||
*/
|
||||
@Override
|
||||
public synchronized void paint(Graphics gfx)
|
||||
{
|
||||
synchronized public void paint(Graphics gfx) {
|
||||
super.paint(gfx);
|
||||
|
||||
if (interactiveMode && handles!=null)
|
||||
{
|
||||
int currentTab = ta.editor.getSketch().getCurrentCodeIndex();
|
||||
if (interactiveMode && handles != null) {
|
||||
int currentTab = getCurrentCodeIndex();
|
||||
// enable anti-aliasing
|
||||
Graphics2D g2d = (Graphics2D)gfx;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
@@ -591,10 +568,10 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
|
||||
for (Handle n : handles.get(currentTab)) {
|
||||
// update n position and width, and draw it
|
||||
int lineStartChar = ta.getLineStartOffset(n.line);
|
||||
int x = ta.offsetToX(n.line, n.newStartChar - lineStartChar);
|
||||
int y = ta.lineToY(n.line) + fm.getHeight() + 1;
|
||||
int end = ta.offsetToX(n.line, n.newEndChar - lineStartChar);
|
||||
int lineStartChar = textArea.getLineStartOffset(n.line);
|
||||
int x = textArea.offsetToX(n.line, n.newStartChar - lineStartChar);
|
||||
int y = textArea.lineToY(n.line) + fm.getHeight() + 1;
|
||||
int end = textArea.offsetToX(n.line, n.newEndChar - lineStartChar);
|
||||
n.setPos(x, y);
|
||||
n.setWidth(end - x);
|
||||
n.draw(g2d, n==mouseHandle);
|
||||
@@ -602,23 +579,26 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
|
||||
// draw color boxes
|
||||
for (ColorControlBox cBox: colorBoxes.get(currentTab)) {
|
||||
int lineStartChar = ta.getLineStartOffset(cBox.getLine());
|
||||
int x = ta.offsetToX(cBox.getLine(), cBox.getCharIndex() - lineStartChar);
|
||||
int y = ta.lineToY(cBox.getLine()) + fm.getDescent();
|
||||
int lineStartChar = textArea.getLineStartOffset(cBox.getLine());
|
||||
int x = textArea.offsetToX(cBox.getLine(), cBox.getCharIndex() - lineStartChar);
|
||||
int y = textArea.lineToY(cBox.getLine()) + fm.getDescent();
|
||||
cBox.setPos(x, y+1);
|
||||
cBox.draw(g2d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startInterativeMode()
|
||||
{
|
||||
interactiveMode = true;
|
||||
|
||||
public void startInterativeMode() {
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
interactiveMode = true;
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void stopInteractiveMode()
|
||||
{
|
||||
|
||||
public void stopInteractiveMode() {
|
||||
interactiveMode = false;
|
||||
|
||||
if (colorSelector != null) {
|
||||
@@ -627,9 +607,11 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
colorSelector.frame.dispatchEvent(new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
|
||||
setCursor(new Cursor(Cursor.TEXT_CURSOR));
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
// Update the interface
|
||||
//public void updateInterface(ArrayList<Handle> handles[], ArrayList<ColorControlBox> colorBoxes[]) {
|
||||
public void updateInterface(List<List<Handle>> handles, List<List<ColorControlBox>> colorBoxes) {
|
||||
@@ -646,44 +628,44 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
* (don't paint while we make changes to the text of the editor)
|
||||
*/
|
||||
public synchronized void initInterfacePositions() {
|
||||
SketchCode[] code = ta.editor.getSketch().getCode();
|
||||
int prevScroll = ta.getVerticalScrollPosition();
|
||||
String prevText = ta.getText();
|
||||
SketchCode[] code = getEditor().getSketch().getCode();
|
||||
int prevScroll = textArea.getVerticalScrollPosition();
|
||||
String prevText = textArea.getText();
|
||||
|
||||
for (int tab=0; tab<code.length; tab++) {
|
||||
String tabCode = ta.editor.baseCode[tab];
|
||||
ta.setText(tabCode);
|
||||
String tabCode = getEditor().baseCode[tab];
|
||||
textArea.setText(tabCode);
|
||||
for (Handle n : handles.get(tab)) {
|
||||
int lineStartChar = ta.getLineStartOffset(n.line);
|
||||
int x = ta.offsetToX(n.line, n.newStartChar - lineStartChar);
|
||||
int end = ta.offsetToX(n.line, n.newEndChar - lineStartChar);
|
||||
int y = ta.lineToY(n.line) + fm.getHeight() + 1;
|
||||
int lineStartChar = textArea.getLineStartOffset(n.line);
|
||||
int x = textArea.offsetToX(n.line, n.newStartChar - lineStartChar);
|
||||
int end = textArea.offsetToX(n.line, n.newEndChar - lineStartChar);
|
||||
int y = textArea.lineToY(n.line) + fm.getHeight() + 1;
|
||||
n.initInterface(x, y, end-x, fm.getHeight());
|
||||
}
|
||||
|
||||
for (ColorControlBox cBox : colorBoxes.get(tab)) {
|
||||
int lineStartChar = ta.getLineStartOffset(cBox.getLine());
|
||||
int x = ta.offsetToX(cBox.getLine(), cBox.getCharIndex() - lineStartChar);
|
||||
int y = ta.lineToY(cBox.getLine()) + fm.getDescent();
|
||||
int lineStartChar = textArea.getLineStartOffset(cBox.getLine());
|
||||
int x = textArea.offsetToX(cBox.getLine(), cBox.getCharIndex() - lineStartChar);
|
||||
int y = textArea.lineToY(cBox.getLine()) + fm.getDescent();
|
||||
cBox.initInterface(this, x, y+1, fm.getHeight()-2, fm.getHeight()-2);
|
||||
}
|
||||
}
|
||||
|
||||
ta.setText(prevText);
|
||||
ta.scrollTo(prevScroll, 0);
|
||||
textArea.setText(prevText);
|
||||
textArea.scrollTo(prevScroll, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Take the saved code of the current tab and replace
|
||||
* all numbers with their current values.
|
||||
* Update TextArea with the new code.
|
||||
*/
|
||||
public void updateCodeText()
|
||||
{
|
||||
public void updateCodeText() {
|
||||
int charInc = 0;
|
||||
int currentTab = ta.editor.getSketch().getCurrentCodeIndex();
|
||||
SketchCode sc = ta.editor.getSketch().getCode(currentTab);
|
||||
String code = ta.editor.baseCode[currentTab];
|
||||
int currentTab = getCurrentCodeIndex();
|
||||
SketchCode sc = getEditor().getSketch().getCode(currentTab);
|
||||
String code = getEditor().baseCode[currentTab];
|
||||
|
||||
for (Handle n : handles.get(currentTab)) {
|
||||
int s = n.startChar + charInc;
|
||||
@@ -699,28 +681,27 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
sc.setProgram(code);
|
||||
}
|
||||
|
||||
private synchronized void replaceTextAreaCode(String code)
|
||||
{
|
||||
// don't paint while we do the stuff below
|
||||
/* by default setText will scroll all the way to the end
|
||||
* remember current scroll position */
|
||||
int scrollLine = ta.getVerticalScrollPosition();
|
||||
int scrollHor = ta.getHorizontalScroll();
|
||||
ta.setText(code);
|
||||
ta.setOrigin(scrollLine, -scrollHor);
|
||||
|
||||
// don't paint while we do the stuff below
|
||||
private synchronized void replaceTextAreaCode(String code) {
|
||||
// by default setText will scroll all the way to the end
|
||||
// remember current scroll position
|
||||
int scrollLine = textArea.getVerticalScrollPosition();
|
||||
int scrollHor = textArea.getHorizontalScrollPosition();
|
||||
textArea.setText(code);
|
||||
textArea.setOrigin(scrollLine, -scrollHor);
|
||||
}
|
||||
|
||||
public String replaceString(String str, int start, int end, String put)
|
||||
{
|
||||
|
||||
public String replaceString(String str, int start, int end, String put) {
|
||||
return str.substring(0, start) + put + str.substring(end, str.length());
|
||||
}
|
||||
|
||||
public void updateCursor(int mouseX, int mouseY)
|
||||
{
|
||||
int currentTab = ta.editor.getSketch().getCurrentCodeIndex();
|
||||
|
||||
public void updateCursor(int mouseX, int mouseY) {
|
||||
int currentTab = getCurrentCodeIndex();
|
||||
for (Handle n : handles.get(currentTab)) {
|
||||
if (n.pick(mouseX, mouseY))
|
||||
{
|
||||
if (n.pick(mouseX, mouseY)) {
|
||||
cursorType = Cursor.W_RESIZE_CURSOR;
|
||||
setCursor(new Cursor(cursorType));
|
||||
return;
|
||||
@@ -728,8 +709,7 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
}
|
||||
|
||||
for (ColorControlBox colorBox : colorBoxes.get(currentTab)) {
|
||||
if (colorBox.pick(mouseX, mouseY))
|
||||
{
|
||||
if (colorBox.pick(mouseX, mouseY)) {
|
||||
cursorType = Cursor.HAND_CURSOR;
|
||||
setCursor(new Cursor(cursorType));
|
||||
return;
|
||||
@@ -737,21 +717,18 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
}
|
||||
|
||||
if (cursorType == Cursor.W_RESIZE_CURSOR ||
|
||||
cursorType == Cursor.HAND_CURSOR ||
|
||||
cursorType == -1) {
|
||||
cursorType = Cursor.DEFAULT_CURSOR;
|
||||
cursorType == Cursor.HAND_CURSOR ||
|
||||
cursorType == -1) {
|
||||
cursorType = Cursor.DEFAULT_CURSOR;
|
||||
setCursor(new Cursor(cursorType));
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle color boxes show/hide
|
||||
*
|
||||
* display the box if the mouse if in the same line.
|
||||
* always keep the color box of the color selector.
|
||||
*/
|
||||
private void showHideColorBoxes(int y)
|
||||
{
|
||||
int currentTab = ta.editor.getSketch().getCurrentCodeIndex();
|
||||
|
||||
|
||||
private void showHideColorBoxes(int y) {
|
||||
// display the box if the mouse if in the same line.
|
||||
// always keep the color box of the color selector.
|
||||
int currentTab = getCurrentCodeIndex();
|
||||
|
||||
boolean change = false;
|
||||
for (ColorControlBox box : colorBoxes.get(currentTab)) {
|
||||
@@ -786,13 +763,15 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
int currentTab = ta.editor.getSketch().getCurrentCodeIndex();
|
||||
int currentTab = getCurrentCodeIndex();
|
||||
// check for clicks on number handles
|
||||
for (Handle n : handles.get(currentTab)) {
|
||||
if (n.pick(e.getX(), e.getY())) {
|
||||
@@ -807,12 +786,10 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
|
||||
// check for clicks on color boxes
|
||||
for (ColorControlBox box : colorBoxes.get(currentTab)) {
|
||||
if (box.pick(e.getX(), e.getY()))
|
||||
{
|
||||
if (box.pick(e.getX(), e.getY())) {
|
||||
if (colorSelector != null) {
|
||||
// we already show a color selector, close it
|
||||
colorSelector.frame.dispatchEvent(
|
||||
new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING));
|
||||
colorSelector.frame.dispatchEvent(new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
|
||||
colorSelector = new ColorSelector(box);
|
||||
@@ -828,6 +805,7 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (mouseHandle != null) {
|
||||
@@ -839,6 +817,7 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
updateCursor(e.getX(), e.getY());
|
||||
@@ -848,16 +827,59 @@ public class TextAreaPainter extends processing.app.syntax.TextAreaPainter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
private DebugEditor getEditor() {
|
||||
return ((JavaTextArea) textArea).editor;
|
||||
}
|
||||
|
||||
|
||||
private int getCurrentCodeIndex() {
|
||||
return getEditor().getSketch().getCurrentCodeIndex();
|
||||
}
|
||||
|
||||
|
||||
private int getGutterMargins() {
|
||||
return ((JavaTextArea) textArea).getGutterMargins();
|
||||
}
|
||||
|
||||
|
||||
private int getGutterWidth() {
|
||||
return ((JavaTextArea) textArea).getGutterWidth();
|
||||
}
|
||||
|
||||
|
||||
private JavaTextArea getTextArea() {
|
||||
return (JavaTextArea) textArea;
|
||||
}
|
||||
|
||||
|
||||
// private Color getGutterBgColor() {
|
||||
// return ((JavaTextArea) textArea).gutterBgColor;
|
||||
// }
|
||||
|
||||
|
||||
// private boolean isDebugToolbarEnabled() {
|
||||
// AtomicBoolean enabled = getEditor().debugToolbarEnabled;
|
||||
// return (enabled != null && enabled.get());
|
||||
// }
|
||||
|
||||
|
||||
private boolean hasJavaTabs() {
|
||||
return getEditor().hasJavaTabs;
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,6 @@ package processing.mode.java.pdex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
|
||||
|
||||
/**
|
||||
* Performs offset matching between PDE and Java code (one line of code only)
|
||||
@@ -258,7 +256,6 @@ public class OffsetMatcher {
|
||||
// a.getJavaOffForPdeOff(20,4);
|
||||
a = new OffsetMatcher("}", "\n");
|
||||
a.getPdeOffForJavaOff(0,1);
|
||||
log("--");
|
||||
a = new OffsetMatcher("color abc = #qwerty;", "int abc = 0xffqwerty;");
|
||||
a.getPdeOffForJavaOff(4, 3);
|
||||
// a.getJavaOffForPdeOff(6, 3);
|
||||
|
||||
@@ -21,119 +21,71 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowFocusListener;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.ToolTipManager;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.table.JTableHeader;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Language;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import static processing.mode.java.pdex.ExperimentalMode.log;
|
||||
|
||||
|
||||
/**
|
||||
* Custom JTable implementation for XQMode. Minor tweaks and addtions.
|
||||
*
|
||||
* @author Manindra Moharana <me@mkmoharana.com>
|
||||
*
|
||||
*/
|
||||
public class XQErrorTable extends JTable {
|
||||
|
||||
/**
|
||||
* Column Names of JTable
|
||||
*/
|
||||
public static final String[] columnNames = { Language.text("editor.footer.errors.problem"), Language.text("editor.footer.errors.tab"), Language.text("editor.footer.errors.line") };
|
||||
/** Column Names of JTable */
|
||||
public static final String[] columnNames = {
|
||||
Language.text("editor.footer.errors.problem"),
|
||||
Language.text("editor.footer.errors.tab"),
|
||||
Language.text("editor.footer.errors.line")
|
||||
};
|
||||
|
||||
/**
|
||||
* Column Widths of JTable.
|
||||
*/
|
||||
/** Column Widths of JTable. */
|
||||
public int[] columnWidths = { 600, 100, 50 }; // Default Values
|
||||
|
||||
/**
|
||||
* Is the column being resized?
|
||||
*/
|
||||
/** Is the column being resized? */
|
||||
private boolean columnResizing = false;
|
||||
|
||||
/**
|
||||
* ErrorCheckerService instance
|
||||
*/
|
||||
/** ErrorCheckerService instance */
|
||||
protected ErrorCheckerService errorCheckerService;
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int colIndex) {
|
||||
return false; // Disallow the editing of any cell
|
||||
}
|
||||
|
||||
|
||||
public XQErrorTable(final ErrorCheckerService errorCheckerService) {
|
||||
this.errorCheckerService = errorCheckerService;
|
||||
for (int i = 0; i < this.getColumnModel().getColumnCount(); i++) {
|
||||
this.getColumnModel().getColumn(i)
|
||||
.setPreferredWidth(columnWidths[i]);
|
||||
getColumnModel().getColumn(i).setPreferredWidth(columnWidths[i]);
|
||||
}
|
||||
|
||||
this.getTableHeader().setReorderingAllowed(false);
|
||||
getTableHeader().setReorderingAllowed(false);
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
synchronized public void mouseClicked(MouseEvent e) {
|
||||
try {
|
||||
errorCheckerService.scrollToErrorLine(((XQErrorTable) e
|
||||
.getSource()).getSelectedRow());
|
||||
// System.out.print("Row clicked: "
|
||||
// + ((XQErrorTable) e.getSource()).getSelectedRow());
|
||||
int row = ((XQErrorTable) e.getSource()).getSelectedRow();
|
||||
errorCheckerService.scrollToErrorLine(row);
|
||||
} catch (Exception e1) {
|
||||
System.out.println("Exception XQErrorTable mouseReleased "
|
||||
+ e);
|
||||
Base.log("Exception XQErrorTable mouseReleased " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// public void mouseMoved(MouseEvent evt) {
|
||||
// log(evt);
|
||||
//// String tip = null;
|
||||
//// java.awt.Point p = evt.getPoint();
|
||||
// int rowIndex = rowAtPoint(evt.getPoint());
|
||||
// int colIndex = columnAtPoint(evt.getPoint());
|
||||
// synchronized (errorCheckerService.problemsList) {
|
||||
// if (rowIndex < errorCheckerService.problemsList.size()) {
|
||||
// Problem p = errorCheckerService.problemsList.get(rowIndex);
|
||||
// if (p.getImportSuggestions() != null
|
||||
// && p.getImportSuggestions().length > 0) {
|
||||
// log("Import Suggestions available");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//// return super.getToolTipText(evt);
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
final XQErrorTable thisTable = this;
|
||||
|
||||
this.addMouseMotionListener(new MouseMotionListener() {
|
||||
this.addMouseMotionListener(new MouseMotionAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent evt) {
|
||||
// log(evt);
|
||||
// String tip = null;
|
||||
// java.awt.Point p = evt.getPoint();
|
||||
int rowIndex = rowAtPoint(evt.getPoint());
|
||||
// int colIndex = columnAtPoint(evt.getPoint());
|
||||
synchronized (errorCheckerService.problemsList) {
|
||||
if (rowIndex < errorCheckerService.problemsList.size()) {
|
||||
|
||||
@@ -141,27 +93,22 @@ public class XQErrorTable extends JTable {
|
||||
if (p.getImportSuggestions() != null
|
||||
&& p.getImportSuggestions().length > 0) {
|
||||
String t = p.getMessage() + "(Import Suggestions available)";
|
||||
int x1 = thisTable.getFontMetrics(thisTable.getFont())
|
||||
.stringWidth(p.getMessage()), x2 = thisTable
|
||||
.getFontMetrics(thisTable.getFont()).stringWidth(t);
|
||||
if(evt.getX() < x1 || evt.getX() > x2) return;
|
||||
String[] list = p.getImportSuggestions();
|
||||
String className = list[0].substring(list[0].lastIndexOf('.') + 1);
|
||||
String[] temp = new String[list.length];
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
temp[i] = "<html>Import '" + className + "' <font color=#777777>(" + list[i] + ")</font></html>";
|
||||
FontMetrics fm = thisTable.getFontMetrics(thisTable.getFont());
|
||||
int x1 = fm.stringWidth(p.getMessage());
|
||||
int x2 = fm.stringWidth(t);
|
||||
if (evt.getX() > x1 && evt.getX() < x2) {
|
||||
String[] list = p.getImportSuggestions();
|
||||
String className = list[0].substring(list[0].lastIndexOf('.') + 1);
|
||||
String[] temp = new String[list.length];
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
temp[i] = "<html>Import '" + className + "' <font color=#777777>(" + list[i] + ")</font></html>";
|
||||
}
|
||||
showImportSuggestion(temp, evt.getXOnScreen(), evt.getYOnScreen() - 3 * thisTable.getFont().getSize());
|
||||
}
|
||||
showImportSuggestion(temp, evt.getXOnScreen(), evt.getYOnScreen() - 3 * thisTable.getFont().getSize());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Handles the resizing of columns. When mouse press is detected on
|
||||
@@ -178,10 +125,8 @@ public class XQErrorTable extends JTable {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
columnResizing = false;
|
||||
for (int i = 0; i < ((JTableHeader) e.getSource())
|
||||
.getColumnModel().getColumnCount(); i++) {
|
||||
columnWidths[i] = ((JTableHeader) e.getSource())
|
||||
.getColumnModel().getColumn(i).getWidth();
|
||||
for (int i = 0; i < ((JTableHeader) e.getSource()).getColumnModel().getColumnCount(); i++) {
|
||||
columnWidths[i] = ((JTableHeader) e.getSource()).getColumnModel().getColumn(i).getWidth();
|
||||
// System.out.println("nw " + columnWidths[i]);
|
||||
}
|
||||
}
|
||||
@@ -190,6 +135,13 @@ public class XQErrorTable extends JTable {
|
||||
ToolTipManager.sharedInstance().registerComponent(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int rowIndex, int colIndex) {
|
||||
return false; // Disallow the editing of any cell
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates table contents with new data
|
||||
* @param tableModel - TableModel
|
||||
@@ -209,7 +161,6 @@ public class XQErrorTable extends JTable {
|
||||
}
|
||||
|
||||
protected void done() {
|
||||
|
||||
try {
|
||||
setModel(tableModel);
|
||||
|
||||
@@ -239,9 +190,12 @@ public class XQErrorTable extends JTable {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
JFrame frmImportSuggest;
|
||||
|
||||
private void showImportSuggestion(String list[], int x, int y){
|
||||
if(frmImportSuggest != null) {
|
||||
if (frmImportSuggest != null) {
|
||||
// frmImportSuggest.setVisible(false);
|
||||
// frmImportSuggest = null;
|
||||
return;
|
||||
@@ -267,13 +221,11 @@ public class XQErrorTable extends JTable {
|
||||
|
||||
final DebugEditor editor = errorCheckerService.getEditor();
|
||||
classList.addListSelectionListener(new ListSelectionListener() {
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if (classList.getSelectedValue() != null) {
|
||||
try {
|
||||
String t = classList.getSelectedValue().trim();
|
||||
log(t);
|
||||
Base.log(t);
|
||||
int x = t.indexOf('(');
|
||||
String impString = "import " + t.substring(x + 1, t.indexOf(')')) + ";\n";
|
||||
int ct = editor.getSketch().getCurrentCodeIndex();
|
||||
@@ -281,7 +233,7 @@ public class XQErrorTable extends JTable {
|
||||
editor.textArea().getDocument().insertString(0, impString, null);
|
||||
editor.getSketch().setCurrentCode(ct);
|
||||
} catch (BadLocationException ble) {
|
||||
log("Failed to insert import");
|
||||
Base.log("Failed to insert import");
|
||||
ble.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -311,7 +263,5 @@ public class XQErrorTable extends JTable {
|
||||
frmImportSuggest.setBounds(x, y, 250, 100);
|
||||
frmImportSuggest.pack();
|
||||
frmImportSuggest.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -116,6 +116,39 @@ public class Runner implements MessageConsumer {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simple non-blocking launch of the virtual machine. VM starts suspended.
|
||||
* @return debuggee VM or null on failure
|
||||
*/
|
||||
public VirtualMachine launchDebug() {
|
||||
if (launchVirtualMachine(false)) { // will return null on failure
|
||||
redirectStreams(vm);
|
||||
}
|
||||
return vm;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Redirect a VMs output and error streams to System.out and System.err
|
||||
*/
|
||||
protected void redirectStreams(VirtualMachine vm) {
|
||||
MessageSiphon ms = new MessageSiphon(process.getErrorStream(), this);
|
||||
errThread = ms.getThread();
|
||||
outThread = new StreamRedirectThread("VM output reader", process.getInputStream(), System.out);
|
||||
errThread.start();
|
||||
outThread.start();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Additional access to the virtual machine. TODO: may not be needed
|
||||
* @return debugge VM or null if not running
|
||||
*/
|
||||
public VirtualMachine vm() {
|
||||
return vm;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean launchVirtualMachine(boolean presenting) {
|
||||
String[] vmParams = getMachineParams();
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.awt.Graphics2D;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import processing.mode.java.pdex.TextAreaPainter;
|
||||
import processing.mode.java.pdex.JavaTextAreaPainter;
|
||||
|
||||
|
||||
public class ColorControlBox {
|
||||
@@ -44,7 +44,7 @@ public class ColorControlBox {
|
||||
|
||||
// interface
|
||||
int x, y, width, height;
|
||||
TextAreaPainter painter;
|
||||
JavaTextAreaPainter painter;
|
||||
|
||||
|
||||
public ColorControlBox(String context, ColorMode mode, ArrayList<Handle> handles) {
|
||||
@@ -65,7 +65,7 @@ public class ColorControlBox {
|
||||
}
|
||||
|
||||
|
||||
public void initInterface(TextAreaPainter textAreaPainter, int x, int y, int w, int h)
|
||||
public void initInterface(JavaTextAreaPainter textAreaPainter, int x, int y, int w, int h)
|
||||
{
|
||||
this.painter = textAreaPainter;
|
||||
this.x = x;
|
||||
|
||||
Reference in New Issue
Block a user