| 1 | package com.jsql.view.swing.action; | |
| 2 | ||
| 3 | import com.jsql.view.swing.util.MediatorHelper; | |
| 4 | ||
| 5 | import javax.swing.*; | |
| 6 | import java.awt.*; | |
| 7 | import java.awt.event.InputEvent; | |
| 8 | import java.awt.event.KeyEvent; | |
| 9 | ||
| 10 | public class AltKeyEventDispatcher implements KeyEventDispatcher { | |
| 11 | ||
| 12 | private boolean wasAltDPressed = false; | |
| 13 | private boolean wasAltPressed = false; | |
| 14 | private boolean wasAltGraphPressed = false; | |
| 15 | | |
| 16 | @Override | |
| 17 | public boolean dispatchKeyEvent(KeyEvent keyEvent) { | |
| 18 | var shouldNotTakeFurtherAction = false; | |
| 19 | | |
| 20 | // Alt key press/release generates 2 events | |
| 21 | // AltGr key press/release generates 4 events including an Alt press/release | |
| 22 | // => AltGr:press Alt:press AltGr:release Alt:release | |
| 23 | // AltGr keycode is the same as Ctrl | |
| 24 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
if (keyEvent.getKeyCode() == KeyEvent.VK_CONTROL) { |
| 25 | this.wasAltGraphPressed = true; | |
| 26 | } | |
| 27 | | |
| 28 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
boolean isAltDPressed = keyEvent.isAltDown() |
| 29 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
&& keyEvent.getKeyCode() == (KeyEvent.VK_ALT & KeyEvent.VK_D); |
| 30 | | |
| 31 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
boolean isAltReleased = keyEvent.getKeyCode() == KeyEvent.VK_ALT |
| 32 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
&& keyEvent.getModifiersEx() == (InputEvent.ALT_DOWN_MASK & KeyEvent.KEY_RELEASED); |
| 33 | | |
| 34 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
boolean isAltPressed = keyEvent.isAltDown() |
| 35 |
2
1. dispatchKeyEvent : negated conditional → NO_COVERAGE 2. dispatchKeyEvent : negated conditional → NO_COVERAGE |
&& keyEvent.getKeyCode() == KeyEvent.VK_ALT |
| 36 | && !this.wasAltGraphPressed; | |
| 37 | | |
| 38 |
3
1. dispatchKeyEvent : negated conditional → NO_COVERAGE 2. dispatchKeyEvent : negated conditional → NO_COVERAGE 3. dispatchKeyEvent : negated conditional → NO_COVERAGE |
boolean wasAltPressedAlready = !this.wasAltDPressed |
| 39 | && !this.wasAltPressed | |
| 40 | && !this.wasAltGraphPressed; | |
| 41 | | |
| 42 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
if (isAltDPressed) { |
| 43 |
1
1. dispatchKeyEvent : removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::selectAddressBar → NO_COVERAGE |
this.selectAddressBar(); |
| 44 | shouldNotTakeFurtherAction = true; | |
| 45 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
} else if (isAltReleased) { |
| 46 |
1
1. dispatchKeyEvent : removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::showMenuBar → NO_COVERAGE |
this.showMenuBar(wasAltPressedAlready); |
| 47 | shouldNotTakeFurtherAction = true; | |
| 48 |
1
1. dispatchKeyEvent : negated conditional → NO_COVERAGE |
} else if (isAltPressed) { |
| 49 |
1
1. dispatchKeyEvent : removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::hideMenuBar → NO_COVERAGE |
this.hideMenuBar(); |
| 50 | shouldNotTakeFurtherAction = true; | |
| 51 | } | |
| 52 | | |
| 53 |
2
1. dispatchKeyEvent : replaced boolean return with true for com/jsql/view/swing/action/AltKeyEventDispatcher::dispatchKeyEvent → NO_COVERAGE 2. dispatchKeyEvent : replaced boolean return with false for com/jsql/view/swing/action/AltKeyEventDispatcher::dispatchKeyEvent → NO_COVERAGE |
return shouldNotTakeFurtherAction; |
| 54 | } | |
| 55 | ||
| 56 | private void selectAddressBar() { | |
| 57 | MediatorHelper.panelAddressBar().getTextFieldAddress().requestFocusInWindow(); | |
| 58 |
1
1. selectAddressBar : removed call to javax/swing/JTextField::selectAll → NO_COVERAGE |
MediatorHelper.panelAddressBar().getTextFieldAddress().selectAll(); |
| 59 | this.wasAltDPressed = true; | |
| 60 | } | |
| 61 | ||
| 62 | private void showMenuBar(boolean wasAltPressedAlready) { // Avoid flickering and AltGr pollution | |
| 63 |
1
1. showMenuBar : negated conditional → NO_COVERAGE |
if (wasAltPressedAlready) { |
| 64 |
2
1. showMenuBar : changed conditional boundary → NO_COVERAGE 2. showMenuBar : negated conditional → NO_COVERAGE |
if (MenuSelectionManager.defaultManager().getSelectedPath().length > 0) { |
| 65 |
1
1. showMenuBar : removed call to javax/swing/MenuSelectionManager::clearSelectedPath → NO_COVERAGE |
MenuSelectionManager.defaultManager().clearSelectedPath(); |
| 66 |
1
1. showMenuBar : negated conditional → NO_COVERAGE |
} else if (MediatorHelper.panelAddressBar().isAdvanceActivated()) { |
| 67 |
2
1. showMenuBar : negated conditional → NO_COVERAGE 2. showMenuBar : removed call to com/jsql/view/swing/menubar/AppMenubar::setVisible → NO_COVERAGE |
MediatorHelper.menubar().setVisible(!MediatorHelper.menubar().isVisible()); |
| 68 | this.wasAltGraphPressed = false; | |
| 69 | } | |
| 70 | } else { | |
| 71 | this.wasAltDPressed = false; | |
| 72 | this.wasAltPressed = false; | |
| 73 | this.wasAltGraphPressed = false; | |
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | private void hideMenuBar() { // Avoid flickering and AltGr pollution | |
| 78 | if ( | |
| 79 |
1
1. hideMenuBar : negated conditional → NO_COVERAGE |
MediatorHelper.panelAddressBar().isAdvanceActivated() |
| 80 |
1
1. hideMenuBar : negated conditional → NO_COVERAGE |
&& MediatorHelper.menubar().isVisible() |
| 81 | ) { | |
| 82 |
1
1. hideMenuBar : removed call to javax/swing/MenuSelectionManager::clearSelectedPath → NO_COVERAGE |
MenuSelectionManager.defaultManager().clearSelectedPath(); |
| 83 |
1
1. hideMenuBar : removed call to com/jsql/view/swing/menubar/AppMenubar::setVisible → NO_COVERAGE |
MediatorHelper.menubar().setVisible(false); |
| 84 | this.wasAltPressed = true; | |
| 85 | this.wasAltGraphPressed = false; | |
| 86 | } | |
| 87 | } | |
| 88 | } | |
Mutations | ||
| 24 |
1.1 |
|
| 28 |
1.1 |
|
| 29 |
1.1 |
|
| 31 |
1.1 |
|
| 32 |
1.1 |
|
| 34 |
1.1 |
|
| 35 |
1.1 2.2 |
|
| 38 |
1.1 2.2 3.3 |
|
| 42 |
1.1 |
|
| 43 |
1.1 |
|
| 45 |
1.1 |
|
| 46 |
1.1 |
|
| 48 |
1.1 |
|
| 49 |
1.1 |
|
| 53 |
1.1 2.2 |
|
| 58 |
1.1 |
|
| 63 |
1.1 |
|
| 64 |
1.1 2.2 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 67 |
1.1 2.2 |
|
| 79 |
1.1 |
|
| 80 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |