diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 2067629b5..3d5f2b2e7 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -304,7 +304,7 @@ public abstract class Editor extends JFrame implements RunnerListener { * solution where the listeners are handled properly. */ protected JEditTextArea createTextArea() { - return new JEditTextArea(new PdeTextAreaDefaults(mode)) { + return new JEditTextArea(new PdeTextAreaDefaults(mode), new PdeInputHandler()) { // this is a kludge that needs to be removed [fry 150120] public void processKeyEvent(KeyEvent evt) { // this had to be added in Processing 007X, because the menu key diff --git a/app/src/processing/app/Settings.java b/app/src/processing/app/Settings.java index eea88204b..58d66ac5b 100644 --- a/app/src/processing/app/Settings.java +++ b/app/src/processing/app/Settings.java @@ -39,7 +39,7 @@ public class Settings { /** * Copy of the defaults in case the user mangles a preference. * It's necessary to keep a copy of the defaults around, because the user may - * have mangled a setting on their own. In the past, we used to load the + * have replaced a setting on their own. In the past, we used to load the * defaults, then replace those with what was in the user's preferences file. * Problem is, if something like a font entry in the user's file no longer * parses properly, we need to be able to get back to a clean version of that diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index e44759b47..88ce30ce9 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -86,7 +86,7 @@ public class JEditTextArea extends JComponent * Creates a new JEditTextArea with the specified settings. * @param defaults The default settings */ - public JEditTextArea(TextAreaDefaults defaults) { + public JEditTextArea(TextAreaDefaults defaults, InputHandler inputHandler) { // Enable the necessary events enableEvents(AWTEvent.KEY_EVENT_MASK); @@ -129,7 +129,7 @@ public class JEditTextArea extends JComponent setFocusTraversalKeysEnabled(false); // Load the defaults - setInputHandler(defaults.inputHandler); + setInputHandler(inputHandler); setDocument(defaults.document); // editable = defaults.editable; caretVisible = defaults.caretVisible; @@ -1963,6 +1963,27 @@ public class JEditTextArea extends JComponent } } */ + + + public void processKeyEvent(KeyEvent event) { + // this had to be added in Processing 007X, because the menu key + // events weren't making it up to the frame. + super.processKeyEvent(event); + + if (inputHandler != null) { + switch (event.getID()) { + case KeyEvent.KEY_TYPED: + inputHandler.keyTyped(event); + break; + case KeyEvent.KEY_PRESSED: + inputHandler.keyPressed(event); + break; + case KeyEvent.KEY_RELEASED: + inputHandler.keyReleased(event); + break; + } + } + } // protected members diff --git a/app/src/processing/app/syntax/PdeInputHandler.java b/app/src/processing/app/syntax/PdeInputHandler.java new file mode 100644 index 000000000..3ac62c0b3 --- /dev/null +++ b/app/src/processing/app/syntax/PdeInputHandler.java @@ -0,0 +1,184 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + PdeInputHandler - PDE-specific handling of keys + Part of the Processing project - http://processing.org + + Copyright (c) 2012-14 The Processing Foundation + Copyright (c) 2004-12 Ben Fry and Casey Reas + Copyright (c) 2001-03 Massachusetts Institute of Technology + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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.app.syntax; + +import processing.app.Base; +import processing.app.Preferences; + + +/** + * Sets key bindings used by the PDE, except for those that are Mode-specific. + */ +public class PdeInputHandler extends DefaultInputHandler { + + public PdeInputHandler() { + // Use option on mac for text edit controls that are ctrl on Windows/Linux. + // (i.e. ctrl-left/right is option-left/right on OS X) + String mod = Base.isMacOS() ? "A" : "C"; + + // right now, ctrl-up/down is select up/down, but mod should be + // used instead, because the mac expects it to be option(alt) + + addKeyBinding("BACK_SPACE", InputHandler.BACKSPACE); + // for 0122, shift-backspace is delete, for 0176, it's now a preference, + // to prevent holy warriors from attacking me for it. + if (Preferences.getBoolean("editor.keys.shift_backspace_is_delete")) { + addKeyBinding("S+BACK_SPACE", InputHandler.DELETE); + } else { + // Made the default for 0215, deemed better for our audience. + addKeyBinding("S+BACK_SPACE", InputHandler.BACKSPACE); + } + + addKeyBinding("DELETE", InputHandler.DELETE); + addKeyBinding("S+DELETE", InputHandler.DELETE); + + // the following two were changed for 0122 for better mac/pc compatability + addKeyBinding(mod + "+BACK_SPACE", InputHandler.BACKSPACE_WORD); // 0122 + addKeyBinding(mod + "S+BACK_SPACE", InputHandler.BACKSPACE_WORD); // 0215 + addKeyBinding(mod + "+DELETE", InputHandler.DELETE_WORD); // 0122 + addKeyBinding(mod + "S+DELETE", InputHandler.DELETE_WORD); // 0215 + + // handled by listener, don't bother here + //addKeyBinding("ENTER", InputHandler.INSERT_BREAK); + //addKeyBinding("TAB", InputHandler.INSERT_TAB); + + addKeyBinding("INSERT", InputHandler.OVERWRITE); + + // http://dev.processing.org/bugs/show_bug.cgi?id=162 + // added for 0176, though the bindings do not appear relevant for osx + if (Preferences.getBoolean("editor.keys.alternative_cut_copy_paste")) { + addKeyBinding("C+INSERT", InputHandler.CLIPBOARD_COPY); + addKeyBinding("S+INSERT", InputHandler.CLIPBOARD_PASTE); + addKeyBinding("S+DELETE", InputHandler.CLIPBOARD_CUT); + } + + // disabling for 0122, not sure what this does + //addKeyBinding("C+\\", InputHandler.TOGGLE_RECT); + + // for 0122, these have been changed for better compatibility + // HOME and END now mean the beginning/end of the document + // for 0176 changed this to a preference so that the Mac OS X people + // can get the "normal" behavior as well if they prefer. + if (Preferences.getBoolean("editor.keys.home_and_end_travel_far")) { + addKeyBinding("HOME", InputHandler.DOCUMENT_HOME); + addKeyBinding("END", InputHandler.DOCUMENT_END); + addKeyBinding("S+HOME", InputHandler.SELECT_DOC_HOME); + addKeyBinding("S+END", InputHandler.SELECT_DOC_END); + } else { + // for 0123 added the proper windows defaults + addKeyBinding("HOME", InputHandler.HOME); + addKeyBinding("END", InputHandler.END); + addKeyBinding("S+HOME", InputHandler.SELECT_HOME); + addKeyBinding("S+END", InputHandler.SELECT_END); + addKeyBinding("C+HOME", InputHandler.DOCUMENT_HOME); + addKeyBinding("C+END", InputHandler.DOCUMENT_END); + addKeyBinding("CS+HOME", InputHandler.SELECT_DOC_HOME); + addKeyBinding("CS+END", InputHandler.SELECT_DOC_END); + } + + if (Base.isMacOS()) { + // Additional OS X key bindings added for 0215. + // Also note that two more are added above and marked 0215. + // http://code.google.com/p/processing/issues/detail?id=1354 + // Could not find a proper Apple guide, but a partial reference is here: + // http://guides.macrumors.com/Keyboard_shortcuts§ion=10#Text_Shortcuts + + // control-A move to start of current paragraph + addKeyBinding("C+A", InputHandler.HOME); + addKeyBinding("CS+A", InputHandler.SELECT_HOME); + // control-E move to end of current paragraph + addKeyBinding("C+E", InputHandler.END); + addKeyBinding("CS+E", InputHandler.SELECT_END); + + // control-D forward delete + addKeyBinding("C+D", InputHandler.DELETE); + + // control-B move left one character + addKeyBinding("C+B", InputHandler.PREV_CHAR); + addKeyBinding("CS+B", InputHandler.SELECT_PREV_CHAR); + // control-F move right one character + addKeyBinding("C+F", InputHandler.NEXT_CHAR); + addKeyBinding("CS+F", InputHandler.SELECT_NEXT_CHAR); + + // control-H delete (just ASCII for backspace) + addKeyBinding("C+H", InputHandler.BACKSPACE); + + // control-N move down one line + addKeyBinding("C+N", InputHandler.NEXT_LINE); + addKeyBinding("CS+N", InputHandler.SELECT_NEXT_LINE); + // control-P move up one line + addKeyBinding("C+P", InputHandler.PREV_LINE); + addKeyBinding("CS+P", InputHandler.SELECT_PREV_LINE); + + // might be nice, but no handlers currently available + // control-O insert new line after cursor + // control-T transpose (swap) two surrounding character + // control-V move to end, then left one character + // control-K delete remainder of current paragraph + // control-Y paste text previously deleted with control-K + } + + if (Base.isMacOS()) { + addKeyBinding("M+LEFT", InputHandler.HOME); + addKeyBinding("M+RIGHT", InputHandler.END); + addKeyBinding("MS+LEFT", InputHandler.SELECT_HOME); // 0122 + addKeyBinding("MS+RIGHT", InputHandler.SELECT_END); // 0122 + } else { + addKeyBinding("C+LEFT", InputHandler.HOME); // 0122 + addKeyBinding("C+RIGHT", InputHandler.END); // 0122 + addKeyBinding("CS+HOME", InputHandler.SELECT_HOME); // 0122 + addKeyBinding("CS+END", InputHandler.SELECT_END); // 0122 + } + + addKeyBinding("PAGE_UP", InputHandler.PREV_PAGE); + addKeyBinding("PAGE_DOWN", InputHandler.NEXT_PAGE); + addKeyBinding("S+PAGE_UP", InputHandler.SELECT_PREV_PAGE); + addKeyBinding("S+PAGE_DOWN", InputHandler.SELECT_NEXT_PAGE); + + addKeyBinding("LEFT", InputHandler.PREV_CHAR); + addKeyBinding("S+LEFT", InputHandler.SELECT_PREV_CHAR); + addKeyBinding(mod + "+LEFT", InputHandler.PREV_WORD); + addKeyBinding(mod + "S+LEFT", InputHandler.SELECT_PREV_WORD); + addKeyBinding("RIGHT", InputHandler.NEXT_CHAR); + addKeyBinding("S+RIGHT", InputHandler.SELECT_NEXT_CHAR); + addKeyBinding(mod + "+RIGHT", InputHandler.NEXT_WORD); + addKeyBinding(mod + "S+RIGHT", InputHandler.SELECT_NEXT_WORD); + + addKeyBinding("UP", InputHandler.PREV_LINE); + addKeyBinding(mod + "+UP", InputHandler.PREV_LINE); // p5 + addKeyBinding("S+UP", InputHandler.SELECT_PREV_LINE); + addKeyBinding("DOWN", InputHandler.NEXT_LINE); + addKeyBinding(mod + "+DOWN", InputHandler.NEXT_LINE); // p5 + addKeyBinding("S+DOWN", InputHandler.SELECT_NEXT_LINE); + + addKeyBinding("MS+UP", InputHandler.SELECT_DOC_HOME); + addKeyBinding("CS+UP", InputHandler.SELECT_DOC_HOME); + addKeyBinding("MS+DOWN", InputHandler.SELECT_DOC_END); + addKeyBinding("CS+DOWN", InputHandler.SELECT_DOC_END); + + addKeyBinding(mod + "+ENTER", InputHandler.REPEAT); + } +} \ No newline at end of file diff --git a/app/src/processing/app/syntax/PdeTextAreaDefaults.java b/app/src/processing/app/syntax/PdeTextAreaDefaults.java index e375881ed..1546d5375 100644 --- a/app/src/processing/app/syntax/PdeTextAreaDefaults.java +++ b/app/src/processing/app/syntax/PdeTextAreaDefaults.java @@ -4,7 +4,8 @@ PdeTextAreaDefaults - grabs font/color settings for the editor Part of the Processing project - http://processing.org - Copyright (c) 2004-06 Ben Fry and Casey Reas + Copyright (c) 2012-14 The Processing Foundation + Copyright (c) 2004-12 Ben Fry and Casey Reas Copyright (c) 2001-03 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify @@ -15,11 +16,11 @@ 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. + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + 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.app.syntax; @@ -30,6 +31,7 @@ import processing.app.*; public class PdeTextAreaDefaults extends TextAreaDefaults { public PdeTextAreaDefaults(Mode mode) { + /* inputHandler = new DefaultInputHandler(); //inputHandler.addDefaultKeyBindings(); // 0122 @@ -178,6 +180,7 @@ public class PdeTextAreaDefaults extends TextAreaDefaults { inputHandler.addKeyBinding("CS+DOWN", InputHandler.SELECT_DOC_END); inputHandler.addKeyBinding(mod + "+ENTER", InputHandler.REPEAT); + */ document = new SyntaxDocument(); // editable = true; diff --git a/app/src/processing/app/syntax/TextAreaDefaults.java b/app/src/processing/app/syntax/TextAreaDefaults.java index 1c9edb7cd..7133db3df 100644 --- a/app/src/processing/app/syntax/TextAreaDefaults.java +++ b/app/src/processing/app/syntax/TextAreaDefaults.java @@ -18,7 +18,7 @@ import java.awt.*; * creating the text area is that this method is faster. */ public class TextAreaDefaults { - public InputHandler inputHandler; + //public InputHandler inputHandler; public SyntaxDocument document; // public boolean editable; diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 1dce85a34..dc1492396 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -42,7 +42,9 @@ public class JavaEditor extends Editor { protected JEditTextArea createTextArea() { - return new JEditTextArea(new PdeTextAreaDefaults(mode)) { + return new JEditTextArea(new PdeTextAreaDefaults(mode), new PdeKeyListener(this)); + /* + return new JEditTextArea(new PdeTextAreaDefaults(mode), new PdeInputHandler()) { // Forwards key events directly to the input handler. This is slightly // faster than using a KeyListener because some Swing overhead is avoided. PdeKeyListener editorListener = new PdeKeyListener(JavaEditor.this, this); @@ -72,6 +74,7 @@ public class JavaEditor extends Editor { } } }; + */ } diff --git a/java/src/processing/mode/java/PdeKeyListener.java b/java/src/processing/mode/java/PdeKeyListener.java index 56662225a..25f49b804 100644 --- a/java/src/processing/mode/java/PdeKeyListener.java +++ b/java/src/processing/mode/java/PdeKeyListener.java @@ -3,7 +3,8 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-10 Ben Fry and Casey Reas + Copyright (c) 2012-15 The Processing Foundation + Copyright (c) 2004-12 Ben Fry and Casey Reas Copyright (c) 2001-04 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify @@ -34,21 +35,11 @@ import java.util.Arrays; /** - * Filters key events for tab expansion/indent/etc. - *

- * For version 0099, some changes have been made to make the indents - * smarter. There are still issues though: - *

- * Solving these issues, however, would probably best be done by a - * smarter parser/formatter, rather than continuing to hack this class. + * Filters key events for tab expansion/indent/etc. This is very old code + * that we'd love to replace with a smarter parser/formatter, rather than + * continuing to hack this class. */ -public class PdeKeyListener { +public class PdeKeyListener extends PdeInputHandler { private Editor editor; private JEditTextArea textarea; @@ -57,13 +48,26 @@ public class PdeKeyListener { Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); - public PdeKeyListener(Editor editor, JEditTextArea textarea) { - this.editor = editor; - this.textarea = textarea; - -// // let him know that i'm leechin' -// textarea.editorListener = this; + public PdeKeyListener(Editor editor) { + this.editor = editor; } + + + public void keyPressed(KeyEvent event) { + if (!pressed(event)) { + super.keyPressed(event); + } + } + + + public void keyTyped(KeyEvent event) { + if (!typed(event)) { + super.keyTyped(event); + } + } + + + // we don't need keyReleased(), so that's passed through automatically /** @@ -74,36 +78,25 @@ public class PdeKeyListener { * keyTyped(). * @return true if the event has been handled (to remove it from the queue) */ - public boolean keyPressed(KeyEvent event) { + protected boolean pressed(KeyEvent event) { + if (textarea == null) { + textarea = editor.getTextArea(); + } + char c = event.getKeyChar(); int code = event.getKeyCode(); Sketch sketch = editor.getSketch(); - /* - if ((event.getModifiers() & CTRL_ALT) == CTRL_ALT) { - if (code == KeyEvent.VK_LEFT) { - sketch.handlePrevCode(); - return true; - } else if (code == KeyEvent.VK_RIGHT) { - sketch.handleNextCode(); - return true; - } - } - */ - if ((event.getModifiers() & InputEvent.META_MASK) != 0) { //event.consume(); // does nothing return false; } - // TODO i don't like these accessors. clean em up later. -// if (!editor.getSketch().isModified()) { if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_TAB) || (code == KeyEvent.VK_ENTER) || ((c >= 32) && (c < 128))) { sketch.setModified(true); } -// } if ((code == KeyEvent.VK_UP) && ((event.getModifiers() & InputEvent.CTRL_MASK) != 0)) { @@ -140,7 +133,7 @@ public class PdeKeyListener { textarea.setCaretPosition(index); } event.consume(); - return true; +// return true; } else if ((code == KeyEvent.VK_DOWN) && ((event.getModifiers() & InputEvent.CTRL_MASK) != 0)) { @@ -164,11 +157,7 @@ public class PdeKeyListener { } index++; } - // if the first char, index will be -2 - //if (index < 0) index = 0; - //textarea.setSelectionStart(index); - //textarea.setSelectionEnd(index); if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) { textarea.setSelectionStart(caretIndex); textarea.setSelectionEnd(index); @@ -176,13 +165,9 @@ public class PdeKeyListener { textarea.setCaretPosition(index); } event.consume(); - return true; - } +// return true; - - switch (c) { - - case 9: // TAB + } else if (c == 9) { if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) { // if shift is down, the user always expects an outdent // http://code.google.com/p/processing/issues/detail?id=458 @@ -195,15 +180,13 @@ public class PdeKeyListener { int tabSize = Preferences.getInteger("editor.tabs.size"); textarea.setSelectedText(spaces(tabSize)); event.consume(); - return true; + } else if (!Preferences.getBoolean("editor.tabs.expand")) { textarea.setSelectedText("\t"); event.consume(); } - break; - case 10: // auto-indent - case 13: + } else if (c == 10 || c == 13) { // auto-indent if (Preferences.getBoolean("editor.indent")) { char contents[] = textarea.getText().toCharArray(); int tabSize = Preferences.getInteger("editor.tabs.size"); @@ -213,26 +196,6 @@ public class PdeKeyListener { // just before where the newline will be inserted) int origIndex = textarea.getCaretPosition() - 1; - // NOTE all this cursing about CRLF stuff is probably moot - // NOTE since the switch to JEditTextArea, which seems to use - // NOTE only LFs internally (thank god). disabling for 0099. - // walk through the array to the current caret position, - // and count how many weirdo windows line endings there are, - // which would be throwing off the caret position number - /* - int offset = 0; - int realIndex = origIndex; - for (int i = 0; i < realIndex-1; i++) { - if ((contents[i] == 13) && (contents[i+1] == 10)) { - offset++; - realIndex++; - } - } - // back up until \r \r\n or \n.. @#($* cross platform - //System.out.println(origIndex + " offset = " + offset); - origIndex += offset; // ARGH!#(* WINDOWS#@($* - */ - // if the previous thing is a brace (whether prev line or // up farther) then the correct indent is the number of spaces // on that line + 'indent'. @@ -244,10 +207,9 @@ public class PdeKeyListener { int spaceCount = calcSpaceCount(origIndex, contents); // If the last character was a left curly brace, then indent. - // For 0122, walk backwards a bit to make sure that the there - // isn't a curly brace several spaces (or lines) back. Also - // moved this before calculating extraCount, since it'll affect - // that as well. + // For 0122, walk backwards a bit to make sure that the there isn't a + // curly brace several spaces (or lines) back. Also moved this before + // calculating extraCount, since it'll affect that as well. int index2 = origIndex; while ((index2 >= 0) && Character.isWhitespace(contents[index2])) { @@ -262,7 +224,6 @@ public class PdeKeyListener { spaceCount += tabSize; } } - //System.out.println("spaceCount should be " + spaceCount); // now before inserting this many spaces, walk forward from // the caret position and count the number of spaces, @@ -283,23 +244,10 @@ public class PdeKeyListener { index++; } - // hitting return on a line with spaces *after* the caret - // can cause trouble. for 0099, was ignoring the case, but this is + // Hitting return on a line with spaces *after* the caret + // can cause trouble. For 0099, was ignoring the case, but this is // annoying, so in 0122 we're trying to fix that. - /* - if (spaceCount - extraCount > 0) { - spaceCount -= extraCount; - } - */ spaceCount -= extraCount; - //if (spaceCount < 0) spaceCount = 0; - //System.out.println("extraCount is " + extraCount); - - // now, check to see if the current line contains a } and if so, - // outdent again by indent - //if (braceCount > 0) { - //spaceCount -= 2; - //} if (spaceCount < 0) { // for rev 0122, actually delete extra space @@ -337,9 +285,9 @@ public class PdeKeyListener { } // mark this event as already handled (all but ignored) event.consume(); - return true; +// return true; - case '}': + } else if (c == '}') { if (Preferences.getBoolean("editor.indent")) { // first remove anything that was there (in case this multiple // characters are selected, so that it's not in the way of the @@ -383,13 +331,12 @@ public class PdeKeyListener { event.consume(); return true; } - break; } return false; } - public boolean keyTyped(KeyEvent event) { + protected boolean typed(KeyEvent event) { char c = event.getKeyChar(); if ((event.getModifiers() & InputEvent.CTRL_MASK) != 0) { @@ -447,7 +394,7 @@ public class PdeKeyListener { * the beginning of the current block, and return the number of * spaces found on that line. */ - protected int calcBraceIndent(int index, char contents[]) { + protected int calcBraceIndent(int index, char[] contents) { // now that we know things are ok to be indented, walk // backwards to the last { to see how far its line is indented. // this isn't perfect cuz it'll pick up commented areas, @@ -479,44 +426,11 @@ public class PdeKeyListener { // check how many spaces on the line with the matching open brace //int pairedSpaceCount = calcSpaceCount(index, contents); - //System.out.println(pairedSpaceCount); return calcSpaceCount(index, contents); } -// /** -// * Get the character array and blank out the commented areas. -// * This hasn't yet been tested, the plan was to make auto-indent -// * less gullible (it gets fooled by braces that are commented out). -// */ -// protected char[] getCleanedContents() { -// char c[] = textarea.getText().toCharArray(); -// -// int index = 0; -// while (index < c.length - 1) { -// if ((c[index] == '/') && (c[index+1] == '*')) { -// c[index++] = 0; -// c[index++] = 0; -// while ((index < c.length - 1) && -// !((c[index] == '*') && (c[index+1] == '/'))) { -// c[index++] = 0; -// } -// -// } else if ((c[index] == '/') && (c[index+1] == '/')) { -// // clear out until the end of the line -// while ((index < c.length) && (c[index] != 10)) { -// c[index++] = 0; -// } -// if (index != c.length) { -// index++; // skip over the newline -// } -// } -// } -// return c; -// } - - - static String spaces(int count) { + static private String spaces(int count) { char[] c = new char[count]; Arrays.fill(c, ' '); return new String(c); diff --git a/java/src/processing/mode/java/debug/DebugEditor.java b/java/src/processing/mode/java/debug/DebugEditor.java index 02ac8c4d8..14a503cf5 100644 --- a/java/src/processing/mode/java/debug/DebugEditor.java +++ b/java/src/processing/mode/java/debug/DebugEditor.java @@ -1303,7 +1303,9 @@ public class DebugEditor extends JavaEditor implements ActionListener { // return new TextArea(new PdeTextAreaDefaults(mode), this); // } protected JEditTextArea createTextArea() { - return new TextArea(new PdeTextAreaDefaults(mode), this) { + return new TextArea(new PdeTextAreaDefaults(mode), new PdeKeyListener(this), this); + /* + return new TextArea(new PdeTextAreaDefaults(mode), new PdeInputHandler(), this) { // Forwards key events directly to the input handler. This is slightly // faster than using a KeyListener because some Swing overhead is avoided. PdeKeyListener editorListener = new PdeKeyListener(DebugEditor.this, this); @@ -1333,6 +1335,7 @@ public class DebugEditor extends JavaEditor implements ActionListener { } } }; + */ } diff --git a/java/src/processing/mode/java/debug/FieldNode.java b/java/src/processing/mode/java/debug/FieldNode.java index 85f21d3b3..76b4bc2ad 100644 --- a/java/src/processing/mode/java/debug/FieldNode.java +++ b/java/src/processing/mode/java/debug/FieldNode.java @@ -1,21 +1,21 @@ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* -Part of the Processing project - http://processing.org -Copyright (c) 2012-15 The Processing Foundation + Part of the Processing project - http://processing.org + Copyright (c) 2012-15 The Processing Foundation -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License version 2 -as published by the Free Software Foundation. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 + as published by the Free Software Foundation. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software Foundation, Inc. -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package processing.mode.java.debug; @@ -28,6 +28,7 @@ import com.sun.jdi.Value; import java.util.logging.Level; import java.util.logging.Logger; + /** * Specialized {@link VariableNode} for representing fields. Overrides * {@link #setValue} to properly change the value of the encapsulated field. @@ -35,10 +36,10 @@ import java.util.logging.Logger; * @author Martin Leopold */ public class FieldNode extends VariableNode { - protected Field field; protected ObjectReference obj; + /** * Construct a {@link FieldNode}. * @@ -54,6 +55,7 @@ public class FieldNode extends VariableNode { this.obj = obj; } + @Override public void setValue(Value value) { try { diff --git a/java/src/processing/mode/java/debug/VariableInspector.java b/java/src/processing/mode/java/debug/VariableInspector.java index 32a97f6a4..cba1772df 100644 --- a/java/src/processing/mode/java/debug/VariableInspector.java +++ b/java/src/processing/mode/java/debug/VariableInspector.java @@ -37,6 +37,7 @@ import javax.swing.DefaultCellEditor; import javax.swing.GrayFilter; import javax.swing.Icon; import javax.swing.ImageIcon; +import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.UIDefaults; @@ -68,7 +69,7 @@ import processing.mode.java.pdex.ExperimentalMode; * * @author Martin Leopold */ -public class VariableInspector extends javax.swing.JFrame { +public class VariableInspector extends JFrame { protected DefaultMutableTreeNode rootNode; // the root node (invisible) protected DefaultMutableTreeNode builtins; // node for Processing built-in variables diff --git a/java/src/processing/mode/java/pdex/ExperimentalMode.java b/java/src/processing/mode/java/pdex/ExperimentalMode.java index 13b13e49f..b83eaae9d 100644 --- a/java/src/processing/mode/java/pdex/ExperimentalMode.java +++ b/java/src/processing/mode/java/pdex/ExperimentalMode.java @@ -32,17 +32,8 @@ import java.util.logging.Logger; import javax.swing.ImageIcon; -import processing.app.Base; -import processing.app.Editor; -import processing.app.EditorState; -import processing.app.Mode; -import processing.app.Preferences; -import processing.app.RunnerListener; -import processing.app.Sketch; -import processing.app.SketchCode; -import processing.app.SketchException; -import processing.mode.java.JavaBuild; -import processing.mode.java.JavaMode; +import processing.app.*; +import processing.mode.java.*; import processing.mode.java.debug.DebugEditor; import processing.mode.java.runner.Runner; @@ -281,9 +272,7 @@ public class ExperimentalMode extends JavaMode { protected ImageIcon classIcon, fieldIcon, methodIcon, localVarIcon; protected void loadIcons(){ - String iconPath = getContentFile("data") - .getAbsolutePath() - + File.separator + "icons"; + String iconPath = getContentFile("data").getAbsolutePath() + File.separator + "icons"; classIcon = new ImageIcon(iconPath + File.separator + "class_obj.png"); methodIcon = new ImageIcon(iconPath + File.separator + "methpub_obj.png"); @@ -295,6 +284,7 @@ public class ExperimentalMode extends JavaMode { } + /* public ClassLoader getJavaModeClassLoader() { for (Mode m : base.getModeList()) { if (m.getClass() == JavaMode.class) { @@ -305,6 +295,7 @@ public class ExperimentalMode extends JavaMode { // badness return null; } + */ /** diff --git a/java/src/processing/mode/java/pdex/TextArea.java b/java/src/processing/mode/java/pdex/TextArea.java index 481cd8845..7e66931c5 100644 --- a/java/src/processing/mode/java/pdex/TextArea.java +++ b/java/src/processing/mode/java/pdex/TextArea.java @@ -22,7 +22,6 @@ 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.debug.DebugEditor; import processing.mode.java.tweak.ColorControlBox; import processing.mode.java.tweak.Handle; @@ -45,6 +44,7 @@ import javax.swing.DefaultListModel; import javax.swing.SwingWorker; import processing.app.Base; +import processing.app.syntax.InputHandler; import processing.app.syntax.JEditTextArea; import processing.app.syntax.TextAreaDefaults; @@ -81,16 +81,15 @@ public class TextArea extends JEditTextArea { protected ErrorCheckerService errorCheckerService; - public TextArea(TextAreaDefaults defaults, DebugEditor editor) { - super(defaults); + public TextArea(TextAreaDefaults defaults, InputHandler inputHandler, DebugEditor 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(); mouseListeners = painter.getMouseListeners(); - MouseMotionListener[] mouseMotionListeners = painter - .getMouseMotionListeners(); + MouseMotionListener[] mouseMotionListeners = painter.getMouseMotionListeners(); remove(painter); @@ -119,10 +118,8 @@ public class TextArea extends JEditTextArea { 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); + breakpointMarker = theme.loadThemeString("breakpoint.marker", breakpointMarker); + currentLineMarker = theme.loadThemeString("currentline.marker", currentLineMarker); // TweakMode code diff --git a/todo.txt b/todo.txt index d2b2f5cb7..131734781 100644 --- a/todo.txt +++ b/todo.txt @@ -147,14 +147,10 @@ _ https://github.com/processing/processing/pull/2833 help me -_ IllegalArgumentException when clicking between editor windows -_ https://github.com/processing/processing/issues/2530 _ "String index out of range" error _ https://github.com/processing/processing/issues/1940 _ closing the color selector makes things freeze (only Linux and Windows?) _ https://github.com/processing/processing/issues/2381 -_ incorporate new preproc -_ https://github.com/fjenett/processing-preprocessor-antlr4 _ SOCKS proxy not working: _ https://github.com/processing/processing/issues/2643 _ the current code that gets/sets the pref is in Preferences @@ -422,8 +418,14 @@ _ http://www.javalobby.org/java/forums/t19012.html PDE / Compiler & Preprocessor medium (bugs/features) +_ incorporate new preproc +_ https://github.com/fjenett/processing-preprocessor-antlr4 +_ https://github.com/processing/processing/issues/3055 +_ update grammar for ANTLR +_ https://github.com/processing/processing/issues/3054 _ modify build to insert these after antlr run: _ @SuppressWarnings({"unused", "cast"}) +_ or get the updated ANTLR, which likely would support it _ omitting a semicolon shows the error on the line after it _ npe if library is removed before compile _ always check library folders to make sure they're still valid @@ -461,7 +463,9 @@ _ http://code.google.com/p/processing/issues/detail?id=494 PDE / Editor -_ Undo does not move to the correct location in the editor window +_ [help] IllegalArgumentException when clicking between editor windows +_ https://github.com/processing/processing/issues/2530 +_ [help] Undo does not move to the correct location in the editor window _ https://github.com/processing/processing/issues/707 _ clean up /tmp folders used during build _ https://github.com/processing/processing/issues/1896