|
27 | 27 | import javax.swing.event.MouseInputListener;
|
28 | 28 | import java.awt.*;
|
29 | 29 | import java.awt.event.KeyEvent;
|
30 |
| -import java.awt.event.KeyListener; |
31 | 30 | import java.awt.event.MouseEvent;
|
32 | 31 |
|
33 | 32 | import static processing.app.I18n.tr;
|
|
36 | 35 | /**
|
37 | 36 | * run/stop/etc buttons for the ide
|
38 | 37 | */
|
39 |
| -public class EditorToolbar extends JComponent implements MouseInputListener, KeyListener { |
| 38 | +public class EditorToolbar extends JComponent implements MouseInputListener, KeyEventDispatcher { |
40 | 39 |
|
41 | 40 | /**
|
42 | 41 | * Rollover titles for each button.
|
@@ -136,6 +135,7 @@ public EditorToolbar(Editor editor, JMenu menu) {
|
136 | 135 |
|
137 | 136 | addMouseListener(this);
|
138 | 137 | addMouseMotionListener(this);
|
| 138 | + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this); |
139 | 139 | }
|
140 | 140 |
|
141 | 141 | private void loadButtons() {
|
@@ -440,24 +440,12 @@ public Dimension getMaximumSize() {
|
440 | 440 | return new Dimension(3000, BUTTON_HEIGHT);
|
441 | 441 | }
|
442 | 442 |
|
443 |
| - |
444 |
| - public void keyPressed(KeyEvent e) { |
445 |
| - if (e.getKeyCode() == KeyEvent.VK_SHIFT) { |
446 |
| - shiftPressed = true; |
447 |
| - repaint(); |
448 |
| - } |
449 |
| - } |
450 |
| - |
451 |
| - |
452 |
| - public void keyReleased(KeyEvent e) { |
453 |
| - if (e.getKeyCode() == KeyEvent.VK_SHIFT) { |
454 |
| - shiftPressed = false; |
| 443 | + public boolean dispatchKeyEvent(final KeyEvent e) { |
| 444 | + if (shiftPressed != e.isShiftDown()) { |
| 445 | + shiftPressed = !shiftPressed; |
455 | 446 | repaint();
|
456 | 447 | }
|
| 448 | + // Return false to continue processing this keyEvent |
| 449 | + return false; |
457 | 450 | }
|
458 |
| - |
459 |
| - |
460 |
| - public void keyTyped(KeyEvent e) { |
461 |
| - } |
462 |
| - |
463 | 451 | }
|
0 commit comments