AltKeyEventDispatcher.java

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
        
19
        var shouldNotTakeFurtherAction = false;
20
        
21
        // Alt key press/release generates 2 events
22
        // AltGr key press/release generates 4 events including an Alt press/release
23
        // => AltGr:press Alt:press AltGr:release Alt:release
24
        // AltGr keycode is the same as Ctrl
25 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
        if (keyEvent.getKeyCode() == KeyEvent.VK_CONTROL) {
26
            this.wasAltGraphPressed = true;
27
        }
28
        
29 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
        boolean isAltDPressed = keyEvent.isAltDown()
30 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
            && keyEvent.getKeyCode() == (KeyEvent.VK_ALT & KeyEvent.VK_D);
31
        
32 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
        boolean isAltReleased = keyEvent.getKeyCode() == KeyEvent.VK_ALT
33 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
            && keyEvent.getModifiersEx() == (InputEvent.ALT_DOWN_MASK & KeyEvent.KEY_RELEASED);
34
        
35 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
        boolean isAltPressed = keyEvent.isAltDown()
36 2 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
2. dispatchKeyEvent : negated conditional → NO_COVERAGE
            && keyEvent.getKeyCode() == KeyEvent.VK_ALT
37
            && !this.wasAltGraphPressed;
38
        
39 3 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
2. dispatchKeyEvent : negated conditional → NO_COVERAGE
3. dispatchKeyEvent : negated conditional → NO_COVERAGE
        boolean wasAltPressedAlready = !this.wasAltDPressed
40
            && !this.wasAltPressed
41
            && !this.wasAltGraphPressed;
42
        
43 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
        if (isAltDPressed) {
44
            
45 1 1. dispatchKeyEvent : removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::selectAddressBar → NO_COVERAGE
            this.selectAddressBar();
46
            shouldNotTakeFurtherAction = true;
47
            
48 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
        } else if (isAltReleased) {
49
            
50 1 1. dispatchKeyEvent : removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::showMenuBar → NO_COVERAGE
            this.showMenuBar(wasAltPressedAlready);
51
            shouldNotTakeFurtherAction = true;
52
            
53 1 1. dispatchKeyEvent : negated conditional → NO_COVERAGE
        } else if (isAltPressed) {
54
            
55 1 1. dispatchKeyEvent : removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::hideMenuBar → NO_COVERAGE
            this.hideMenuBar();
56
            shouldNotTakeFurtherAction = true;
57
        }
58
        
59 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;
60
    }
61
62
    private void selectAddressBar() {
63
        
64
        MediatorHelper.panelAddressBar().getTextFieldAddress().requestFocusInWindow();
65 1 1. selectAddressBar : removed call to javax/swing/JTextField::selectAll → NO_COVERAGE
        MediatorHelper.panelAddressBar().getTextFieldAddress().selectAll();
66
        this.wasAltDPressed = true;
67
    }
68
69
    private void showMenuBar(boolean wasAltPressedAlready) {
70
        
71
        // Avoid flickering and AltGr pollution
72 1 1. showMenuBar : negated conditional → NO_COVERAGE
        if (wasAltPressedAlready) {
73 2 1. showMenuBar : changed conditional boundary → NO_COVERAGE
2. showMenuBar : negated conditional → NO_COVERAGE
            if (MenuSelectionManager.defaultManager().getSelectedPath().length > 0) {
74 1 1. showMenuBar : removed call to javax/swing/MenuSelectionManager::clearSelectedPath → NO_COVERAGE
                MenuSelectionManager.defaultManager().clearSelectedPath();
75 1 1. showMenuBar : negated conditional → NO_COVERAGE
            } else if (!MediatorHelper.panelAddressBar().isAdvanceActivated()) {
76
                
77 2 1. showMenuBar : negated conditional → NO_COVERAGE
2. showMenuBar : removed call to com/jsql/view/swing/menubar/Menubar::setVisible → NO_COVERAGE
                MediatorHelper.menubar().setVisible(!MediatorHelper.menubar().isVisible());
78
                this.wasAltGraphPressed = false;
79
            }
80
        } else {
81
            
82
            this.wasAltDPressed = false;
83
            this.wasAltPressed = false;
84
            this.wasAltGraphPressed = false;
85
        }
86
    }
87
88
    private void hideMenuBar() {
89
        
90
        // Avoid flickering and AltGr pollution
91
        if (
92 1 1. hideMenuBar : negated conditional → NO_COVERAGE
            !MediatorHelper.panelAddressBar().isAdvanceActivated()
93 1 1. hideMenuBar : negated conditional → NO_COVERAGE
            && MediatorHelper.menubar().isVisible()
94
        ) {
95
            
96 1 1. hideMenuBar : removed call to javax/swing/MenuSelectionManager::clearSelectedPath → NO_COVERAGE
            MenuSelectionManager.defaultManager().clearSelectedPath();
97 1 1. hideMenuBar : removed call to com/jsql/view/swing/menubar/Menubar::setVisible → NO_COVERAGE
            MediatorHelper.menubar().setVisible(false);
98
            this.wasAltPressed = true;
99
            this.wasAltGraphPressed = false;
100
        }
101
    }
102
}

Mutations

25

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

29

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

30

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

32

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

33

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

35

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

36

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

39

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

43

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

45

1.1
Location : dispatchKeyEvent
Killed by : none
removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::selectAddressBar → NO_COVERAGE

48

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

50

1.1
Location : dispatchKeyEvent
Killed by : none
removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::showMenuBar → NO_COVERAGE

53

1.1
Location : dispatchKeyEvent
Killed by : none
negated conditional → NO_COVERAGE

55

1.1
Location : dispatchKeyEvent
Killed by : none
removed call to com/jsql/view/swing/action/AltKeyEventDispatcher::hideMenuBar → NO_COVERAGE

59

1.1
Location : dispatchKeyEvent
Killed by : none
replaced boolean return with true for com/jsql/view/swing/action/AltKeyEventDispatcher::dispatchKeyEvent → NO_COVERAGE

2.2
Location : dispatchKeyEvent
Killed by : none
replaced boolean return with false for com/jsql/view/swing/action/AltKeyEventDispatcher::dispatchKeyEvent → NO_COVERAGE

65

1.1
Location : selectAddressBar
Killed by : none
removed call to javax/swing/JTextField::selectAll → NO_COVERAGE

72

1.1
Location : showMenuBar
Killed by : none
negated conditional → NO_COVERAGE

73

1.1
Location : showMenuBar
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : showMenuBar
Killed by : none
negated conditional → NO_COVERAGE

74

1.1
Location : showMenuBar
Killed by : none
removed call to javax/swing/MenuSelectionManager::clearSelectedPath → NO_COVERAGE

75

1.1
Location : showMenuBar
Killed by : none
negated conditional → NO_COVERAGE

77

1.1
Location : showMenuBar
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : showMenuBar
Killed by : none
removed call to com/jsql/view/swing/menubar/Menubar::setVisible → NO_COVERAGE

92

1.1
Location : hideMenuBar
Killed by : none
negated conditional → NO_COVERAGE

93

1.1
Location : hideMenuBar
Killed by : none
negated conditional → NO_COVERAGE

96

1.1
Location : hideMenuBar
Killed by : none
removed call to javax/swing/MenuSelectionManager::clearSelectedPath → NO_COVERAGE

97

1.1
Location : hideMenuBar
Killed by : none
removed call to com/jsql/view/swing/menubar/Menubar::setVisible → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1