removing more sketchy accessors, other cleanups

This commit is contained in:
Ben Fry
2015-01-25 11:03:07 -05:00
parent 342c6958ab
commit 5ad61b7fb4
11 changed files with 226 additions and 219 deletions

View File

@@ -226,24 +226,24 @@ public class DebugToolbar extends JavaToolbar {
deditor.handleRun();
} else {
Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Debug' toolbar button");
deditor.dbg.startDebug();
deditor.debugger.startDebug();
}
break;
case CONTINUE:
Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Continue' toolbar button");
deditor.dbg.continueDebug();
deditor.debugger.continueDebug();
break;
case TOGGLE_BREAKPOINT:
Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Toggle Breakpoint' toolbar button");
deditor.dbg.toggleBreakpoint();
deditor.debugger.toggleBreakpoint();
break;
case STEP:
if (shift) {
Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Step Into' toolbar button");
deditor.dbg.stepInto();
deditor.debugger.stepInto();
} else {
Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Step' toolbar button");
deditor.dbg.stepOver();
deditor.debugger.stepOver();
}
break;
// case STEP_INTO:

View File

@@ -50,16 +50,68 @@ public class JavaEditor extends Editor {
// Runner associated with this editor window
private Runner runtime;
// Need to sort through the rest of these additions...
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
protected JMenu debugMenu; // the debug menu
// protected JMenuItem debugMenuItem;
protected JMenuItem continueMenuItem;
protected JMenuItem stopMenuItem;
// 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;
protected Debugger debugger; // the debugger
protected DebugTray tray; // the variable inspector frame
// public JavaTextArea ta; // the text area
public ErrorBar errorBar;
protected XQConsoleToggle btnShowConsole;
protected XQConsoleToggle btnShowErrors;
protected JScrollPane errorTableScrollPane;
protected JPanel consoleProblemsPane;
protected XQErrorTable errorTable;
public boolean compilationCheckEnabled = true;
protected JCheckBoxMenuItem showWarnings;
public JCheckBoxMenuItem problemWindowMenuCB;
protected JCheckBoxMenuItem debugMessagesEnabled;
protected JMenuItem showOutline, showTabOutline;
protected JCheckBoxMenuItem writeErrorLog;
protected JCheckBoxMenuItem completionsEnabled;
// TODO no way should this be public; make an accessor or protected
public boolean hasJavaTabs;
protected JavaEditor(Base base, String path, EditorState state, Mode mode) {
super(base, path, state, mode);
jmode = (JavaMode) mode;
dbg = new Debugger(this);
vi = new DebugTray(this);
// access to customized (i.e. subclassed) text area
ta = (JavaTextArea) textarea;
debugger = new Debugger(this);
tray = new DebugTray(this);
// Add show usage option
JMenuItem showUsageItem = new JMenuItem("Show Usage...");
@@ -68,7 +120,7 @@ public class JavaEditor extends Editor {
handleShowUsage();
}
});
ta.getRightClickPopup().add(showUsageItem);
getTextArea().getRightClickPopup().add(showUsageItem);
// add refactor option
JMenuItem renameItem = new JMenuItem("Rename...");
@@ -84,7 +136,7 @@ public class JavaEditor extends Editor {
// System.out.println(evt);
// }
// });
ta.getRightClickPopup().add(renameItem);
textarea.getRightClickPopup().add(renameItem);
// set action on frame close
// addWindowListener(new WindowAdapter() {
// @Override
@@ -93,7 +145,7 @@ public class JavaEditor extends Editor {
// }
// });
Toolkit.setMenuMnemonics(ta.getRightClickPopup());
Toolkit.setMenuMnemonics(textarea.getRightClickPopup());
// load settings from theme.txt
breakpointColor = mode.getColor("breakpoint.bgcolor"); //, breakpointColor);
@@ -104,14 +156,14 @@ public class JavaEditor extends Editor {
// set breakpoints from marker comments
for (LineID lineID : stripBreakpointComments()) {
//System.out.println("setting: " + lineID);
dbg.setBreakpoint(lineID);
debugger.setBreakpoint(lineID);
}
getSketch().setModified(false); // setting breakpoints will flag sketch as modified, so override this here
checkForJavaTabs();
initializeErrorChecker();
ta.setECSandThemeforTextArea(errorCheckerService, jmode);
getJavaTextArea().setECSandThemeforTextArea(errorCheckerService, jmode);
addXQModeUI();
debugToolbarEnabled = new AtomicBoolean(false);
@@ -1011,8 +1063,8 @@ public class JavaEditor extends Editor {
* session or performs standard stop action if not currently debugging.
*/
public void handleStop() {
if (dbg.isStarted()) {
dbg.stopDebug();
if (debugger.isStarted()) {
debugger.stopDebug();
} else {
toolbar.activate(JavaToolbar.STOP);
@@ -1052,14 +1104,14 @@ public class JavaEditor extends Editor {
boolean saved = super.handleSaveAs();
if (saved) {
// re-set breakpoints in first tab (name has changed)
List<LineBreakpoint> bps = dbg.getBreakpoints(oldName);
dbg.clearBreakpoints(oldName);
List<LineBreakpoint> bps = debugger.getBreakpoints(oldName);
debugger.clearBreakpoints(oldName);
String newName = getSketch().getCode(0).getFileName();
//System.out.println("new name: " + newName);
for (LineBreakpoint bp : bps) {
LineID line = new LineID(newName, bp.lineID().lineIdx());
//System.out.println("setting: " + line);
dbg.setBreakpoint(line);
debugger.setBreakpoint(line);
}
// add breakpoint marker comments to source file
for (int i = 0; i < getSketch().getCodeCount(); i++) {
@@ -1067,7 +1119,7 @@ public class JavaEditor extends Editor {
}
// set new name of variable inspector
vi.setTitle(getSketch().getName());
tray.setTitle(getSketch().getName());
}
// if file location has changed, update autosaver
// autosaver.reloadAutosaveDir();
@@ -1160,61 +1212,8 @@ public class JavaEditor extends Editor {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
// Additions from PDE X, Debug Mode, Twerk Mode...
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
protected JMenu debugMenu; // the debug menu
protected JMenuItem debugMenuItem;
protected JMenuItem continueMenuItem;
protected JMenuItem stopMenuItem;
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;
protected Debugger dbg; // the debugger
protected DebugTray vi; // the variable inspector frame
public JavaTextArea ta; // the text area
public ErrorBar errorBar;
protected XQConsoleToggle btnShowConsole;
protected XQConsoleToggle btnShowErrors;
protected JScrollPane errorTableScrollPane;
protected JPanel consoleProblemsPane;
protected XQErrorTable errorTable;
public boolean compilationCheckEnabled = true;
protected JCheckBoxMenuItem showWarnings;
public JCheckBoxMenuItem problemWindowMenuCB;
protected JCheckBoxMenuItem debugMessagesEnabled;
protected JMenuItem showOutline, showTabOutline;
protected JCheckBoxMenuItem writeErrorLog;
protected JCheckBoxMenuItem completionsEnabled;
// TODO no way should this be public; make an accessor or protected
public boolean hasJavaTabs;
private void addXQModeUI(){
// Adding ErrorBar
@@ -1269,7 +1268,7 @@ public class JavaEditor extends Editor {
// ensure completion gets hidden on editor losing focus
addWindowFocusListener(new WindowFocusListener() {
public void windowLostFocus(WindowEvent e) {
ta.hideSuggestion();
getJavaTextArea().hideSuggestion();
}
public void windowGainedFocus(WindowEvent e) {
@@ -1298,9 +1297,9 @@ public class JavaEditor extends Editor {
public void dispose() {
//System.out.println("window dispose");
// quit running debug session
dbg.stopDebug();
debugger.stopDebug();
// remove var.inspector
vi.dispose();
tray.dispose();
errorCheckerService.stopThread();
// original dispose
super.dispose();
@@ -1401,7 +1400,7 @@ public class JavaEditor extends Editor {
break;
}
}
ta.repaint();
textarea.repaint();
}
});
}
@@ -1414,6 +1413,7 @@ public class JavaEditor extends Editor {
*/
protected JMenu buildDebugMenu() {
debugMenu = new JMenu(Language.text("menu.debug"));
JMenuItem item;
JCheckBoxMenuItem toggleDebugger =
new JCheckBoxMenuItem(Language.text("menu.debug.show_debug_toolbar"));
@@ -1425,20 +1425,20 @@ public class JavaEditor extends Editor {
});
debugMenu.add(toggleDebugger);
debugMenuItem = Toolkit.newJMenuItemAlt(Language.text("menu.debug.debug"), KeyEvent.VK_R);
debugMenuItem.addActionListener(new ActionListener() {
item = Toolkit.newJMenuItemAlt(Language.text("menu.debug.debug"), KeyEvent.VK_R);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Debug' menu item");
dbg.startDebug();
debugger.startDebug();
}
});
debugMenu.add(debugMenuItem);
debugMenu.add(item);
continueMenuItem = Toolkit.newJMenuItem(Language.text("menu.debug.continue"), KeyEvent.VK_U);
continueMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Continue' menu item");
dbg.continueDebug();
debugger.continueDebug();
}
});
debugMenu.add(continueMenuItem);
@@ -1447,27 +1447,28 @@ public class JavaEditor extends Editor {
stopMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Stop' menu item");
dbg.stopDebug();
debugger.stopDebug();
}
});
debugMenu.add(stopMenuItem);
debugMenu.addSeparator();
toggleBreakpointMenuItem =
item =
Toolkit.newJMenuItem(Language.text("menu.debug.toggle_breakpoint"), KeyEvent.VK_B);
toggleBreakpointMenuItem.addActionListener(new ActionListener() {
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Toggle Breakpoint' menu item");
dbg.toggleBreakpoint();
debugger.toggleBreakpoint();
}
});
debugMenu.add(toggleBreakpointMenuItem);
debugMenu.add(item);
listBreakpointsMenuItem = new JMenuItem(Language.text("menu.debug.list_breakpoints"));
listBreakpointsMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'List Breakpoints' menu item");
dbg.listBreakpoints();
debugger.listBreakpoints();
}
});
debugMenu.add(listBreakpointsMenuItem);
@@ -1478,7 +1479,7 @@ public class JavaEditor extends Editor {
stepOverMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Step Over' menu item");
dbg.stepOver();
debugger.stepOver();
}
});
debugMenu.add(stepOverMenuItem);
@@ -1487,7 +1488,7 @@ public class JavaEditor extends Editor {
stepIntoMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Step Into' menu item");
dbg.stepInto();
debugger.stepInto();
}
});
debugMenu.add(stepIntoMenuItem);
@@ -1496,7 +1497,7 @@ public class JavaEditor extends Editor {
stepOutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Step Out' menu item");
dbg.stepOut();
debugger.stepOut();
}
});
debugMenu.add(stepOutMenuItem);
@@ -1507,7 +1508,7 @@ public class JavaEditor extends Editor {
printStackTraceMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Print Stack Trace' menu item");
dbg.printStackTrace();
debugger.printStackTrace();
}
});
debugMenu.add(printStackTraceMenuItem);
@@ -1516,7 +1517,7 @@ public class JavaEditor extends Editor {
printLocalsMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Print Locals' menu item");
dbg.printLocals();
debugger.printLocals();
}
});
debugMenu.add(printLocalsMenuItem);
@@ -1525,7 +1526,7 @@ public class JavaEditor extends Editor {
printThisMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Print This' menu item");
dbg.printThis();
debugger.printThis();
}
});
debugMenu.add(printThisMenuItem);
@@ -1534,7 +1535,7 @@ public class JavaEditor extends Editor {
printSourceMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Print Source' menu item");
dbg.printSource();
debugger.printSource();
}
});
debugMenu.add(printSourceMenuItem);
@@ -1543,7 +1544,7 @@ public class JavaEditor extends Editor {
printThreads.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Print Threads' menu item");
dbg.printThreads();
debugger.printThreads();
}
});
debugMenu.add(printThreads);
@@ -1599,9 +1600,9 @@ public class JavaEditor extends Editor {
protected boolean handleOpenInternal(String path) {
// log("handleOpenInternal, path: " + path);
boolean didOpen = super.handleOpenInternal(path);
if (didOpen && dbg != null) {
if (didOpen && debugger != null) {
// should already been stopped (open calls handleStop)
dbg.clearBreakpoints();
debugger.clearBreakpoints();
clearBreakpointedLines(); // force clear breakpoint highlights
variableInspector().reset(); // clear contents of variable inspector
}
@@ -1673,7 +1674,7 @@ public class JavaEditor extends Editor {
Base.loge("Illegal tab name to addBreakpointComments() " + tabFilename);
return;
}
List<LineBreakpoint> bps = dbg.getBreakpoints(tab.getFileName());
List<LineBreakpoint> bps = debugger.getBreakpoints(tab.getFileName());
// load the source file
File sourceFile = new File(sketch.getFolder(), tab.getFileName());
@@ -1774,7 +1775,7 @@ public class JavaEditor extends Editor {
*/
protected void setTabContents(String tabFilename, String code) {
// remove all breakpoints of this tab
dbg.clearBreakpoints(tabFilename);
debugger.clearBreakpoints(tabFilename);
SketchCode currentTab = getCurrentTab();
@@ -1861,7 +1862,7 @@ public class JavaEditor extends Editor {
* @return the debugger controller object
*/
public Debugger getDebugger() {
return dbg;
return debugger;
}
@@ -1869,8 +1870,8 @@ public class JavaEditor extends Editor {
* Access the custom text area object.
* @return the text area object
*/
public JavaTextArea textArea() {
return ta;
public JavaTextArea getJavaTextArea() {
return (JavaTextArea) textarea;
}
@@ -1991,7 +1992,7 @@ public class JavaEditor extends Editor {
* @return the variable inspector object
*/
public DebugTray variableInspector() {
return vi;
return tray;
}
@@ -2006,7 +2007,7 @@ public class JavaEditor extends Editor {
* Show the variable inspector window.
*/
public void showVariableInspector() {
vi.setVisible(true);
tray.setVisible(true);
}
/**
@@ -2016,23 +2017,23 @@ public class JavaEditor extends Editor {
* invisible.
*/
public void showVariableInspector(boolean visible) {
vi.setVisible(visible);
tray.setVisible(visible);
}
/**
* Hide the variable inspector window.
*/
public void hideVariableInspector() {
vi.setVisible(true);
tray.setVisible(true);
}
/**
* Toggle visibility of the variable inspector window.
*/
public void toggleVariableInspector() {
vi.setFocusableWindowState(false); // to not get focus when set visible
vi.setVisible(!vi.isVisible());
vi.setFocusableWindowState(true); // allow to get focus again
tray.setFocusableWindowState(false); // to not get focus when set visible
tray.setVisible(!tray.isVisible());
tray.setFocusableWindowState(true); // allow to get focus again
}
@@ -2053,7 +2054,7 @@ public class JavaEditor extends Editor {
cursorToLineStart(line.lineIdx());
// highlight line
currentLine = new LineHighlight(line.lineIdx(), currentLineColor, this);
currentLine.setMarker(ta.currentLineMarker, currentLineMarkerColor);
currentLine.setMarker(getJavaTextArea().currentLineMarker, currentLineMarkerColor);
currentLine.setPriority(10); // fixes current line being hidden by the breakpoint when moved down
}
@@ -2083,7 +2084,7 @@ public class JavaEditor extends Editor {
*/
public void addBreakpointedLine(LineID lineID) {
LineHighlight hl = new LineHighlight(lineID, breakpointColor, this);
hl.setMarker(ta.breakpointMarker, breakpointMarkerColor);
hl.setMarker(getJavaTextArea().breakpointMarker, breakpointMarkerColor);
breakpointedLines.add(hl);
// repaint current line if it's on this line
if (currentLine != null && currentLine.getLineID().equals(lineID)) {
@@ -2140,8 +2141,8 @@ public class JavaEditor extends Editor {
}
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();
getJavaTextArea().clearLineBgColors(); // force clear all highlights
getJavaTextArea().clearGutterText();
// repaint current line
if (currentLine != null) {
@@ -2193,6 +2194,7 @@ public class JavaEditor extends Editor {
super.setCode(code); // set the new document in the textarea, etc. need to do this first
// set line background colors for tab
final JavaTextArea ta = getJavaTextArea();
if (ta != null) { // can be null when setCode is called the first time (in constructor)
// clear all line backgrounds
ta.clearLineBgColors();
@@ -2270,8 +2272,8 @@ public class JavaEditor extends Editor {
* @param lineIdx the line (0-based) that was double clicked
*/
public void gutterDblClicked(int lineIdx) {
if (dbg != null) {
dbg.toggleBreakpoint(lineIdx);
if (debugger != null) {
debugger.toggleBreakpoint(lineIdx);
}
}
@@ -2399,7 +2401,7 @@ public class JavaEditor extends Editor {
* Handle refactor operation
*/
private void handleRefactor() {
Base.log("Caret at:" + ta.getLineText(ta.getCaretLine()));
Base.log("Caret at:" + textarea.getLineText(textarea.getCaretLine()));
errorCheckerService.getASTGenerator().handleRefactor();
}
@@ -2408,7 +2410,7 @@ public class JavaEditor extends Editor {
* Handle show usage operation
*/
private void handleShowUsage() {
Base.log("Caret at:" + ta.getLineText(ta.getCaretLine()));
Base.log("Caret at:" + textarea.getLineText(textarea.getCaretLine()));
errorCheckerService.getASTGenerator().handleShowUsage();
}
@@ -2460,15 +2462,16 @@ public class JavaEditor extends Editor {
UDPTweakClient tweakClient;
public void startInteractiveMode()
{
ta.startInteractiveMode();
public void startInteractiveMode() {
getJavaTextArea().startInteractiveMode();
}
//public void stopInteractiveMode(ArrayList<Handle> handles[]) {
public void stopInteractiveMode(List<List<Handle>> handles) {
tweakClient.shutdown();
ta.stopInteractiveMode();
getJavaTextArea().stopInteractiveMode();
// remove space from the code (before and after)
removeSpacesFromCode();
@@ -2492,9 +2495,9 @@ public class JavaEditor extends Editor {
// NO! don't keep changes
loadSavedCode();
// update the painter to draw the saved (old) code
ta.invalidate();
}
else {
textarea.invalidate();
} else {
// YES! keep changes
// the new values are already present, just make sure the user can save the modified tabs
for (int i=0; i<sketch.getCodeCount(); i++) {
@@ -2526,30 +2529,23 @@ public class JavaEditor extends Editor {
// repaint the editor header (show the modified tabs)
header.repaint();
ta.invalidate();
textarea.invalidate();
}
}
else {
} else {
// number values were not modified but we need to load the saved code
// because of some formatting changes
loadSavedCode();
ta.invalidate();
textarea.invalidate();
}
}
public void updateInterface(List<List<Handle>> handles, List<List<ColorControlBox>> colorBoxes) {
// set OSC port of handles
// for (int i=0; i<handles.length; i++) {
// for (Handle h : handles[i]) {
// h.setOscPort(oscPort);
// }
// }
ta.updateInterface(handles, colorBoxes);
public void updateInterface(List<List<Handle>> handles,
List<List<ColorControlBox>> colorBoxes) {
getJavaTextArea().updateInterface(handles, colorBoxes);
}
//private boolean[] getModifiedTabs(ArrayList<Handle> handles[]) {
private boolean[] getModifiedTabs(List<List<Handle>> handles) {
boolean[] modifiedTabs = new boolean[handles.size()];

View File

@@ -158,8 +158,8 @@ public class LineHighlight implements LineListener {
public void lineChanged(LineID line, int oldLineIdx, int newLineIdx) {
// clear old line
if (editor.isInCurrentTab(new LineID(line.fileName(), oldLineIdx))) {
editor.textArea().clearLineBgColor(oldLineIdx);
editor.textArea().clearGutterText(oldLineIdx);
editor.getJavaTextArea().clearLineBgColor(oldLineIdx);
editor.getJavaTextArea().clearGutterText(oldLineIdx);
}
// paint new line
@@ -185,12 +185,12 @@ public class LineHighlight implements LineListener {
*/
public void paint() {
if (editor.isInCurrentTab(lineID)) {
editor.textArea().setLineBgColor(lineID.lineIdx(), bgColor);
editor.getJavaTextArea().setLineBgColor(lineID.lineIdx(), bgColor);
if (marker != null) {
if (markerColor != null) {
editor.textArea().setGutterText(lineID.lineIdx(), marker, markerColor);
editor.getJavaTextArea().setGutterText(lineID.lineIdx(), marker, markerColor);
} else {
editor.textArea().setGutterText(lineID.lineIdx(), marker);
editor.getJavaTextArea().setGutterText(lineID.lineIdx(), marker);
}
}
}
@@ -201,8 +201,8 @@ public class LineHighlight implements LineListener {
*/
public void clear() {
if (editor.isInCurrentTab(lineID)) {
editor.textArea().clearLineBgColor(lineID.lineIdx());
editor.textArea().clearGutterText(lineID.lineIdx());
editor.getJavaTextArea().clearLineBgColor(lineID.lineIdx());
editor.getJavaTextArea().clearGutterText(lineID.lineIdx());
}
}
}

View File

@@ -111,6 +111,7 @@ import processing.app.Base;
import processing.app.Library;
import processing.app.SketchCode;
import processing.app.Toolkit;
import processing.app.syntax.JEditTextArea;
import processing.mode.java.JavaEditor;
import processing.mode.java.JavaMode;
import processing.mode.java.preproc.PdePreprocessor;
@@ -1077,8 +1078,7 @@ public class ASTGenerator {
// tableAuto.validate();
// tableAuto.repaint();
// }
errorCheckerService.getEditor().textArea()
.showSuggestion(defListModel, word);
errorCheckerService.getEditor().getJavaTextArea().showSuggestion(defListModel, word);
}
private DefaultListModel<CompletionCandidate> filterPredictions(){
@@ -2030,7 +2030,7 @@ public class ASTGenerator {
protected void refactorIt(){
String newName = txtRenameField.getText().trim();
String selText = lastClickedWord == null ? editor.ta.getSelectedText()
String selText = lastClickedWord == null ? getSelectedText()
: lastClickedWord;
// Find all occurrences of last clicked word
DefaultMutableTreeNode defCU = findAllOccurrences(); //TODO: Repetition here
@@ -2098,7 +2098,7 @@ public class ASTGenerator {
+ off, awrap.getNode()
.toString().length());
//int k = JOptionPane.showConfirmDialog(new JFrame(), "Rename?","", JOptionPane.INFORMATION_MESSAGE);
editor.ta.setSelectedText(newName);
editor.getTextArea().setSelectedText(newName);
}
editor.stopCompoundEdit();
errorCheckerService.resumeThread();
@@ -2123,14 +2123,15 @@ public class ASTGenerator {
// + lineStartWSOffset + ",Len: " + length);
editor.toFront();
editor.getSketch().setCurrentCode(tab);
lineStartWSOffset += editor.ta.getLineStartOffset(lineNumber);
editor.ta.select(lineStartWSOffset, lineStartWSOffset + length);
lineStartWSOffset += editor.getTextArea().getLineStartOffset(lineNumber);
editor.getTextArea().select(lineStartWSOffset, lineStartWSOffset + length);
}
public void handleShowUsage(){
if(editor.hasJavaTabs) return; // show usage disabled if java tabs
log("Last clicked word:" + lastClickedWord);
if(lastClickedWord == null && editor.ta.getSelectedText() == null){
if (lastClickedWord == null &&
getSelectedText() == null) {
editor.statusMessage("Highlight the class/function/variable name first"
, JavaEditor.STATUS_INFO);
return;
@@ -2142,9 +2143,9 @@ public class ASTGenerator {
return;
}
DefaultMutableTreeNode defCU = findAllOccurrences();
String selText = lastClickedWord == null ? editor.ta.getSelectedText()
: lastClickedWord;
if(defCU == null){
String selText = lastClickedWord == null ?
getSelectedText() : lastClickedWord;
if (defCU == null) {
editor.statusMessage("Can't locate definition of " + selText,
JavaEditor.STATUS_ERR);
return;
@@ -2176,25 +2177,24 @@ public class ASTGenerator {
}
protected DefaultMutableTreeNode findAllOccurrences(){
final JEditTextArea ta = editor.getTextArea();
log("Last clicked word:" + lastClickedWord);
String selText = lastClickedWord == null ? editor.ta.getSelectedText()
: lastClickedWord;
int line = editor.ta.getSelectionStartLine();
String selText = lastClickedWord == null ? ta.getSelectedText() :
lastClickedWord;
int line = ta.getSelectionStartLine();
log(selText
+ "<- offsets "
+ (line)
+ ", "
+ (editor.ta.getSelectionStart() - editor.ta
.getLineStartOffset(line))
+ (ta.getSelectionStart() - ta.getLineStartOffset(line))
+ ", "
+ (editor.ta.getSelectionStop() - editor.ta
.getLineStartOffset(line)));
int offwhitespace = editor.ta
.getLineStartNonWhiteSpaceOffset(line);
+ (ta.getSelectionStop() - ta.getLineStartOffset(line)));
int offwhitespace = ta.getLineStartNonWhiteSpaceOffset(line);
ASTNodeWrapper wnode;
if (lastClickedWord == null || lastClickedWordNode.getNode() == null) {
wnode = getASTNodeAt(line + errorCheckerService.mainClassOffset, selText,
editor.ta.getSelectionStart() - offwhitespace, false);
ta.getSelectionStart() - offwhitespace, false);
}
else{
wnode = lastClickedWordNode;
@@ -2471,26 +2471,26 @@ public class ASTGenerator {
return false;
}
public void handleRefactor(){
public void handleRefactor() {
if(editor.hasJavaTabs) return; // refactoring disabled if java tabs
log("Last clicked word:" + lastClickedWord);
if(lastClickedWord == null && editor.ta.getSelectedText() == null){
if (lastClickedWord == null &&
getSelectedText() == null) {
editor.statusMessage("Highlight the class/function/variable name first",
JavaEditor.STATUS_INFO);
return;
}
if(errorCheckerService.hasSyntaxErrors()){
editor
.statusMessage("Can't perform action until syntax errors are fixed :(",
JavaEditor.STATUS_WARNING);
if (errorCheckerService.hasSyntaxErrors()) {
editor.statusMessage("Can't perform action until syntax errors are fixed :(",
JavaEditor.STATUS_WARNING);
return;
}
DefaultMutableTreeNode defCU = findAllOccurrences();
String selText = lastClickedWord == null ? editor.ta.getSelectedText()
: lastClickedWord;
if(defCU == null){
String selText = lastClickedWord == null ?
getSelectedText() : lastClickedWord;
if (defCU == null) {
editor.statusMessage(selText + " isn't defined in this sketch, so it can't" +
" be renamed", JavaEditor.STATUS_ERR);
return;
@@ -2505,7 +2505,7 @@ public class ASTGenerator {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String selText = lastClickedWord == null ? editor.ta.getSelectedText()
String selText = lastClickedWord == null ? getSelectedText()
: lastClickedWord;
frmOccurenceList.setTitle("All occurrences of "
+ selText);
@@ -3057,22 +3057,19 @@ public class ASTGenerator {
return commentList;
}
protected boolean caretWithinLineComment(){
String pdeLine = editor.getLineText(editor.textArea().getCaretLine()).trim();
int caretPos = editor.textArea().getCaretPosition()
- editor.textArea()
.getLineStartNonWhiteSpaceOffset(editor.textArea().getCaretLine());
protected boolean caretWithinLineComment() {
final JEditTextArea ta = editor.getTextArea();
String pdeLine = editor.getLineText(ta.getCaretLine()).trim();
int caretPos = ta.getCaretPosition() - ta.getLineStartNonWhiteSpaceOffset(ta.getCaretLine());
int x = pdeLine.indexOf("//");
// log(x + " , " + caretPos + ", Checking line for comment " + pdeLine);
//lineStartOffset = editor.textArea().
if (x >= 0 && caretPos > x) {
// log("INSIDE a comment");
return true;
}
// log("not within comment");
return false;
}
/**
* A wrapper for java.lang.reflect types.
@@ -3480,7 +3477,7 @@ public class ASTGenerator {
+ ";\n";
int ct = editor.getSketch().getCurrentCodeIndex();
editor.getSketch().setCurrentCode(0);
editor.textArea().getDocument().insertString(0, impString, null);
editor.getTextArea().getDocument().insertString(0, impString, null);
editor.getSketch().setCurrentCode(ct);
errorCheckerService.runManualErrorCheck();
frmImportSuggest.setVisible(false);
@@ -3539,7 +3536,7 @@ public class ASTGenerator {
editor.getY()
+ (editor.getHeight() - frmImportSuggest.getHeight())
/ 2);
editor.ta.hideSuggestion();
hideSuggestion();
classList.setSelectedIndex(0);
frmImportSuggest.setVisible(true);
}
@@ -3766,4 +3763,14 @@ public class ASTGenerator {
static private void log(Object object) {
Base.log(object == null ? "null" : object.toString());
}
private String getSelectedText() {
return editor.getTextArea().getSelectedText();
}
private void hideSuggestion() {
((JavaTextArea) editor.getTextArea()).hideSuggestion();
}
}

View File

@@ -583,7 +583,7 @@ public class ASTNodeWrapper {
"Please file a bug report.");
return false;
}
int lso = astGenerator.editor.ta.getLineStartOffset(pdeOffs[1]);
int lso = astGenerator.editor.getTextArea().getLineStartOffset(pdeOffs[1]);
highlightStart += lso;
astGenerator.editor.setSelection(highlightStart, highlightStart
+ nodeName.getLength());

View File

@@ -380,7 +380,7 @@ public class CompletionPanel {
// See #2755
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
protected Object doInBackground() throws Exception {
editor.ta.fetchPhrase(null);
((JavaTextArea) editor.getTextArea()).fetchPhrase(null);
return null;
}
};
@@ -400,7 +400,7 @@ public class CompletionPanel {
private String fetchCurrentSubword() {
//log("Entering fetchCurrentSubword");
JavaTextArea ta = editor.ta;
JEditTextArea ta = editor.getTextArea();
int off = ta.getCaretPosition();
//log2("off " + off);
if (off < 0)

View File

@@ -36,6 +36,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.PlainDocument;
@@ -1210,7 +1211,7 @@ public class ErrorCheckerService implements Runnable {
public String getPDECodeAtLine(int tab, int linenumber){
if(linenumber < 0) return null;
editor.getSketch().setCurrentCode(tab);
return editor.ta.getLineText(linenumber);
return editor.getTextArea().getLineText(linenumber);
}
/**
@@ -1526,15 +1527,15 @@ public class ErrorCheckerService implements Runnable {
// It's also a bit silly that if parameters to scrollTo() are out of range,
// a BadLocation Exception is thrown internally and caught in JTextArea AND
// even the stack trace gets printed! W/o letting me catch it later! SMH
if (p.getLineNumber() < Base.countLines(editor.textArea().getDocument()
.getText(0, editor.textArea().getDocument().getLength()))
&& p.getLineNumber() >= 0) {
final Document doc = editor.getTextArea().getDocument();
final int lineCount = Base.countLines(doc.getText(0, doc.getLength()));
if (p.getLineNumber() < lineCount && p.getLineNumber() >= 0) {
editor.getTextArea().scrollTo(p.getLineNumber(), 0);
}
editor.repaint();
} catch (Exception e) {
Base.loge(e
+ " : Error while selecting text in scrollToErrorLine(), for problem: " + p);
Base.loge("Error while selecting text in scrollToErrorLine(), for problem: " + p, e);
}
// log("---");
}

View File

@@ -95,7 +95,7 @@ public class SketchOutline {
frmOutlineView = new JFrame();
frmOutlineView.setAlwaysOnTop(true);
frmOutlineView.setUndecorated(true);
Point tp = errorCheckerService.getEditor().ta.getLocationOnScreen();
Point tp = errorCheckerService.getEditor().getTextArea().getLocationOnScreen();
int minWidth = (int) (editor.getMinimumSize().width * 0.7f);
int maxWidth = (int) (editor.getMinimumSize().width * 0.9f);
@@ -122,19 +122,19 @@ public class SketchOutline {
jsp.setViewportView(soTree);
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jsp.setMinimumSize(new Dimension(minWidth, editor.ta.getHeight() - 10));
jsp.setMaximumSize(new Dimension(maxWidth, editor.ta.getHeight() - 10));
jsp.setMinimumSize(new Dimension(minWidth, editor.getTextArea().getHeight() - 10));
jsp.setMaximumSize(new Dimension(maxWidth, editor.getTextArea().getHeight() - 10));
panelBottom.add(jsp);
frmOutlineView.add(panelTop);
frmOutlineView.add(panelBottom);
frmOutlineView.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frmOutlineView.pack();
frmOutlineView.setBounds(tp.x + errorCheckerService.getEditor().ta.getWidth() - minWidth, tp.y, minWidth,
Math.min(editor.ta.getHeight(), frmOutlineView.getHeight()));
frmOutlineView.setMinimumSize(new Dimension(minWidth, Math.min(errorCheckerService.getEditor().ta.getHeight(), frmOutlineView.getHeight())));
frmOutlineView.setLocation(tp.x + errorCheckerService.getEditor().ta.getWidth()/2 - frmOutlineView.getWidth()/2,
frmOutlineView.getY() + (editor.ta.getHeight() - frmOutlineView.getHeight()) / 2);
frmOutlineView.setBounds(tp.x + errorCheckerService.getEditor().getTextArea().getWidth() - minWidth, tp.y, minWidth,
Math.min(editor.getTextArea().getHeight(), frmOutlineView.getHeight()));
frmOutlineView.setMinimumSize(new Dimension(minWidth, Math.min(errorCheckerService.getEditor().getTextArea().getHeight(), frmOutlineView.getHeight())));
frmOutlineView.setLocation(tp.x + errorCheckerService.getEditor().getTextArea().getWidth()/2 - frmOutlineView.getWidth()/2,
frmOutlineView.getY() + (editor.getTextArea().getHeight() - frmOutlineView.getHeight()) / 2);
addListeners();
}

View File

@@ -83,7 +83,7 @@ public class TabOutline {
frmOutlineView = new JFrame();
frmOutlineView.setAlwaysOnTop(true);
frmOutlineView.setUndecorated(true);
Point tp = errorCheckerService.getEditor().ta.getLocationOnScreen();
Point tp = errorCheckerService.getEditor().getTextArea().getLocationOnScreen();
lblCaption = new JLabel("Tabs List (type to filter)");
int minWidth = estimateFrameWidth();
int maxWidth = (int) (editor.getMinimumSize().width * 0.9f);
@@ -104,8 +104,8 @@ public class TabOutline {
jsp.setViewportView(tabTree);
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jsp.setMinimumSize(new Dimension(minWidth, editor.ta.getHeight() - 10));
jsp.setMaximumSize(new Dimension(maxWidth, editor.ta.getHeight() - 10));
jsp.setMinimumSize(new Dimension(minWidth, editor.getTextArea().getHeight() - 10));
jsp.setMaximumSize(new Dimension(maxWidth, editor.getTextArea().getHeight() - 10));
panelBottom.add(jsp);
frmOutlineView.add(panelTop);
@@ -113,20 +113,18 @@ public class TabOutline {
frmOutlineView.add(panelBottom);
frmOutlineView.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frmOutlineView.pack();
frmOutlineView.setBounds(tp.x
+ errorCheckerService.getEditor().ta
.getWidth() - minWidth,
frmOutlineView.setBounds(tp.x + errorCheckerService.getEditor().getTextArea().getWidth() - minWidth,
tp.y,
minWidth,
estimateFrameHeight());
frmOutlineView.setMinimumSize(new Dimension(minWidth, Math
.min(errorCheckerService.getEditor().ta.getHeight(),
.min(errorCheckerService.getEditor().getTextArea().getHeight(),
frmOutlineView.getHeight())));
frmOutlineView.setLocation(tp.x
+ errorCheckerService.getEditor().ta
+ errorCheckerService.getEditor().getTextArea()
.getWidth()/2 - frmOutlineView.getWidth()/2,
frmOutlineView.getY()
+ (editor.ta.getHeight() - frmOutlineView
+ (editor.getTextArea().getHeight() - frmOutlineView
.getHeight()) / 2);
DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tabTree.getCellRenderer();
renderer.setLeafIcon(null);
@@ -330,11 +328,10 @@ public class TabOutline {
}
private int estimateFrameWidth() {
FontMetrics fm = editor.ta.getGraphics().getFontMetrics();
FontMetrics fm = editor.getTextArea().getGraphics().getFontMetrics();
int w = fm.stringWidth(lblCaption.getText()) + 10;
for (int i = 0; i < editor.getSketch().getCodeCount(); i++) {
w = Math.max(w, fm.stringWidth(editor.getSketch().getCode(i)
.getPrettyName()) + 10);
w = Math.max(w, fm.stringWidth(editor.getSketch().getCode(i).getPrettyName()) + 10);
}
return w;
}

View File

@@ -230,7 +230,7 @@ public class XQErrorTable extends JTable {
String impString = "import " + t.substring(x + 1, t.indexOf(')')) + ";\n";
int ct = editor.getSketch().getCurrentCodeIndex();
editor.getSketch().setCurrentCode(0);
editor.textArea().getDocument().insertString(0, impString, null);
editor.getTextArea().getDocument().insertString(0, impString, null);
editor.getSketch().setCurrentCode(ct);
} catch (BadLocationException ble) {
Base.log("Failed to insert import");