\n");
ps.println("Parent Directory
\n");
String[] list = dir.list();
@@ -522,51 +504,51 @@ outerloop:
}
ps.println("
KeyEvent class, without
+ * the VK_ prefix.
+ * @param keyStroke A string description of the key stroke
+ */
+ static public KeyStroke parseKeyStroke(String keyStroke) {
+ if (keyStroke == null) {
+ return null;
+ }
+ int modifiers = 0;
+ int index = keyStroke.indexOf('+');
+ if (index != -1) {
+ for (int i = 0; i < index; i++) {
+ switch (Character.toUpperCase(keyStroke.charAt(i))) {
+ case 'A':
+ modifiers |= InputEvent.ALT_MASK;
+ break;
+ case 'C':
+ modifiers |= InputEvent.CTRL_MASK;
+ break;
+ case 'M':
+ modifiers |= InputEvent.META_MASK;
+ break;
+ case 'S':
+ modifiers |= InputEvent.SHIFT_MASK;
+ break;
}
+ }
+ }
+ String key = keyStroke.substring(index + 1);
+ if (key.length() == 1) {
+ char ch = Character.toUpperCase(key.charAt(0));
+ if (modifiers == 0) {
+ return KeyStroke.getKeyStroke(ch);
+ } else {
+ return KeyStroke.getKeyStroke(ch,modifiers);
+ }
- /**
- * Removes all key bindings from this input handler.
- */
- public void removeAllKeyBindings()
- {
- bindings.clear();
- }
+ } else if (key.length() == 0) {
+ System.err.println("Invalid key stroke: " + keyStroke);
+ return null;
- /**
- * Returns a copy of this input handler that shares the same
- * key bindings. Setting key bindings in the copy will also
- * set them in the original.
- */
- public InputHandler copy()
- {
- return new DefaultInputHandler(this);
- }
+ } else {
+ int ch;
- /**
- * Handle a key pressed event. This will look up the binding for
- * the key stroke and execute it.
- */
- public void keyPressed(KeyEvent evt)
- {
- int keyCode = evt.getKeyCode();
- int modifiers = evt.getModifiers();
+ try {
+ ch = KeyEvent.class.getField("VK_".concat(key)).getInt(null);
+ } catch (Exception e) {
+ System.err.println("Invalid key stroke: " + keyStroke);
+ return null;
+ }
+ return KeyStroke.getKeyStroke(ch,modifiers);
+ }
+ }
- // moved this earlier so it doesn't get random meta clicks
- if (keyCode == KeyEvent.VK_CONTROL ||
- keyCode == KeyEvent.VK_SHIFT ||
- keyCode == KeyEvent.VK_ALT ||
- keyCode == KeyEvent.VK_META) {
- return;
- }
- // don't get command-s or other menu key equivs on mac
- // unless it's something that's specifically bound (cmd-left or right)
- //if ((modifiers & KeyEvent.META_MASK) != 0) return;
- if ((modifiers & InputEvent.META_MASK) != 0) {
- KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, modifiers);
- if (currentBindings.get(keyStroke) == null) {
- return;
- }
- }
-
- /*
- char keyChar = evt.getKeyChar();
- System.out.println("code=" + keyCode + " char=" + keyChar +
- " charint=" + ((int)keyChar));
- System.out.println("other codes " + KeyEvent.VK_ALT + " " +
- KeyEvent.VK_META);
- */
-
- if((modifiers & ~InputEvent.SHIFT_MASK) != 0
- || evt.isActionKey()
- || keyCode == KeyEvent.VK_BACK_SPACE
- || keyCode == KeyEvent.VK_DELETE
- || keyCode == KeyEvent.VK_ENTER
- || keyCode == KeyEvent.VK_TAB
- || keyCode == KeyEvent.VK_ESCAPE)
- {
- if(grabAction != null)
- {
- handleGrabAction(evt);
- return;
- }
-
- KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode,
- modifiers);
- Object o = currentBindings.get(keyStroke);
- if(o == null)
- {
- // Don't beep if the user presses some
- // key we don't know about unless a
- // prefix is active. Otherwise it will
- // beep when caps lock is pressed, etc.
- if(currentBindings != bindings)
- {
- Toolkit.getDefaultToolkit().beep();
- // F10 should be passed on, but C+e F10
- // shouldn't
- repeatCount = 0;
- repeat = false;
- evt.consume();
- }
- currentBindings = bindings;
- return;
- }
- else if(o instanceof ActionListener)
- {
- currentBindings = bindings;
-
- executeAction(((ActionListener)o),
- evt.getSource(),null);
-
- evt.consume();
- return;
- }
- else if(o instanceof Map)
- {
- currentBindings = (Map)o;
- evt.consume();
- return;
- }
- }
- }
-
- /**
- * Handle a key typed event. This inserts the key into the text area.
- */
- public void keyTyped(KeyEvent evt)
- {
- int modifiers = evt.getModifiers();
- char c = evt.getKeyChar();
-
- // this is the apple/cmd key on macosx.. so menu commands
- // were being passed through as legit keys.. added this line
- // in an attempt to prevent.
- if ((modifiers & InputEvent.META_MASK) != 0) return;
-
- // Prevent CTRL-/ from going through as a typed '/' character
- // http://code.google.com/p/processing/issues/detail?id=596
- if ((modifiers & InputEvent.CTRL_MASK) != 0 && c == '/') return;
-
- if (c != KeyEvent.CHAR_UNDEFINED) // &&
- // (modifiers & KeyEvent.ALT_MASK) == 0)
- {
- if(c >= 0x20 && c != 0x7f)
- {
- KeyStroke keyStroke = KeyStroke.getKeyStroke(
- Character.toUpperCase(c));
- Object o = currentBindings.get(keyStroke);
-
- if(o instanceof Map)
- {
- currentBindings = (Map)o;
- return;
- }
- else if(o instanceof ActionListener)
- {
- currentBindings = bindings;
- executeAction((ActionListener)o,
- evt.getSource(),
- String.valueOf(c));
- return;
- }
-
- currentBindings = bindings;
-
- if(grabAction != null)
- {
- handleGrabAction(evt);
- return;
- }
-
- // 0-9 adds another 'digit' to the repeat number
- if(repeat && Character.isDigit(c))
- {
- repeatCount *= 10;
- repeatCount += (c - '0');
- return;
- }
-
- executeAction(INSERT_CHAR,evt.getSource(),
- String.valueOf(evt.getKeyChar()));
-
- repeatCount = 0;
- repeat = false;
- }
- }
- }
-
- /**
- * Converts a string to a keystroke. The string should be of the
- * form modifiers+shortcut where modifiers
- * is any combination of A for Alt, C for Control, S for Shift
- * or M for Meta, and shortcut is either a single character,
- * or a keycode name from the KeyEvent class, without
- * the VK_ prefix.
- * @param keyStroke A string description of the key stroke
- */
- public static KeyStroke parseKeyStroke(String keyStroke)
- {
- if(keyStroke == null)
- return null;
- int modifiers = 0;
- int index = keyStroke.indexOf('+');
- if(index != -1)
- {
- for(int i = 0; i < index; i++)
- {
- switch(Character.toUpperCase(keyStroke
- .charAt(i)))
- {
- case 'A':
- modifiers |= InputEvent.ALT_MASK;
- break;
- case 'C':
- modifiers |= InputEvent.CTRL_MASK;
- break;
- case 'M':
- modifiers |= InputEvent.META_MASK;
- break;
- case 'S':
- modifiers |= InputEvent.SHIFT_MASK;
- break;
- }
- }
- }
- String key = keyStroke.substring(index + 1);
- if(key.length() == 1)
- {
- char ch = Character.toUpperCase(key.charAt(0));
- if(modifiers == 0)
- return KeyStroke.getKeyStroke(ch);
- else
- return KeyStroke.getKeyStroke(ch,modifiers);
- }
- else if(key.length() == 0)
- {
- System.err.println("Invalid key stroke: " + keyStroke);
- return null;
- }
- else
- {
- int ch;
-
- try
- {
- ch = KeyEvent.class.getField("VK_".concat(key))
- .getInt(null);
- }
- catch(Exception e)
- {
- System.err.println("Invalid key stroke: "
- + keyStroke);
- return null;
- }
-
- return KeyStroke.getKeyStroke(ch,modifiers);
- }
- }
-
- // private members
- private Map bindings;
- private Map currentBindings;
-
- private DefaultInputHandler(DefaultInputHandler copy)
- {
- bindings = currentBindings = copy.bindings;
- }
+ private DefaultInputHandler(DefaultInputHandler copy) {
+ bindings = copy.bindings;
+ }
}
diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java
index 8554078f4..dbe954f8d 100644
--- a/app/src/processing/app/syntax/JEditTextArea.java
+++ b/app/src/processing/app/syntax/JEditTextArea.java
@@ -80,9 +80,9 @@ public class JEditTextArea extends JComponent
private InputMethodSupport inputMethodSupport;
- private TextAreaDefaults defaults;
+ private final TextAreaDefaults defaults;
- private Brackets bracketHelper = new Brackets();
+ private final Brackets bracketHelper = new Brackets();
private FontMetrics cachedPartialPixelWidthFont;
private float partialPixelWidth;
@@ -102,11 +102,9 @@ public class JEditTextArea extends JComponent
enableEvents(AWTEvent.KEY_EVENT_MASK);
if (!DISABLE_CARET) {
- caretTimer = new Timer(500, new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (hasFocus()) {
- blinkCaret();
- }
+ caretTimer = new Timer(500, e -> {
+ if (hasFocus()) {
+ blinkCaret();
}
});
caretTimer.setInitialDelay(500);
@@ -152,13 +150,10 @@ public class JEditTextArea extends JComponent
// We don't seem to get the initial focus event?
// focusedComponent = this;
- addMouseWheelListener(new MouseWheelListener() {
-
- @Override
- public void mouseWheelMoved(MouseWheelEvent e) {
- if (scrollBarsInitialized) {
- if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
- int scrollAmount = e.getUnitsToScroll();
+ addMouseWheelListener(e -> {
+ if (scrollBarsInitialized) {
+ if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
+ int scrollAmount = e.getUnitsToScroll();
// System.out.println("rot/amt = " + e.getWheelRotation() + " " + amt);
// int max = vertical.getMaximum();
// System.out.println("UNIT SCROLL of " + amt + " at value " + vertical.getValue() + " and max " + max);
@@ -174,14 +169,13 @@ public class JEditTextArea extends JComponent
// }
// System.out.println(" " + e);
- // inertia scrolling on OS X will fire several shift-wheel events
- // that are negative values.. this makes the scrolling area jump.
- boolean isHorizontal = Platform.isMacOS() && e.isShiftDown();
- if (isHorizontal) {
- horizontal.setValue(horizontal.getValue() + scrollAmount);
- }else{
- vertical.setValue(vertical.getValue() + scrollAmount);
- }
+ // inertia scrolling on OS X will fire several shift-wheel events
+ // that are negative values.. this makes the scrolling area jump.
+ boolean isHorizontal = Platform.isMacOS() && e.isShiftDown();
+ if (isHorizontal) {
+ horizontal.setValue(horizontal.getValue() + scrollAmount);
+ }else{
+ vertical.setValue(vertical.getValue() + scrollAmount);
}
}
}
@@ -191,7 +185,6 @@ public class JEditTextArea extends JComponent
/**
* Override this to provide your own painter for this {@link JEditTextArea}.
- * @param defaults
* @return a newly constructed {@link TextAreaPainter}.
*/
protected TextAreaPainter createPainter(final TextAreaDefaults defaults) {
@@ -922,9 +915,11 @@ public class JEditTextArea extends JComponent
int length = getLineLength(line);
String str = getText(offset, length);
- for(int i = 0; i < str.length(); i++) {
- if(!Character.isWhitespace(str.charAt(i))) {
- return offset + i;
+ if (str != null) {
+ for (int i = 0; i < str.length(); i++) {
+ if (!Character.isWhitespace(str.charAt(i))) {
+ return offset + i;
+ }
}
}
return offset + length;
@@ -948,9 +943,11 @@ public class JEditTextArea extends JComponent
int length = getLineLength(line);
String str = getText(offset - length - 1, length);
- for (int i = 0; i < length; i++) {
- if(!Character.isWhitespace(str.charAt(length - i - 1))) {
- return offset - i;
+ if (str != null) {
+ for (int i = 0; i < length; i++) {
+ if (!Character.isWhitespace(str.charAt(length - i - 1))) {
+ return offset - i;
+ }
}
}
return offset - length;
@@ -1654,11 +1651,7 @@ public class JEditTextArea extends JComponent
String selection = getSelectedText();
if (selection != null) {
int repeatCount = inputHandler.getRepeatCount();
- StringBuilder sb = new StringBuilder();
- for(int i = 0; i < repeatCount; i++)
- sb.append(selection);
-
- clipboard.setContents(new StringSelection(sb.toString()), null);
+ clipboard.setContents(new StringSelection(selection.repeat(Math.max(0, repeatCount))), null);
}
}
}
@@ -1689,10 +1682,8 @@ public class JEditTextArea extends JComponent
+ getTextAsHtml(null) + "\n