JPopupMenuTable.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2020.
3
 * This program and the accompanying materials
4
 * are made available under no term at all, use it like
5
 * you want, but share and discuss about it
6
 * every time possible with every body.
7
 * 
8
 * Contributors:
9
 *      ron190 at ymail dot com - initial implementation
10
 ******************************************************************************/
11
package com.jsql.view.swing.popupmenu;
12
13
import com.jsql.util.I18nUtil;
14
import com.jsql.view.swing.menubar.JMenuItemWithMargin;
15
import com.jsql.view.swing.util.I18nViewUtil;
16
17
import javax.swing.*;
18
import javax.swing.event.PopupMenuEvent;
19
import javax.swing.event.PopupMenuListener;
20
import java.awt.*;
21
import java.awt.event.ActionEvent;
22
import java.awt.event.InputEvent;
23
import java.awt.event.KeyEvent;
24
25
/**
26
 * Default popup menu and shortcuts for a table.
27
 */
28
public class JPopupMenuTable extends JPopupMenu {
29
    
30
    /**
31
     * Table with new menu and shortcut.
32
     */
33
    private final JTable table;
34
35
    /**
36
     * Create popup menu for this table component.
37
     * @param table The table receiving the menu
38
     */
39
    public JPopupMenuTable(JTable table) {
40
        
41
        this.table = table;
42
43 1 1. <init> : removed call to javax/swing/JTable::setComponentPopupMenu → NO_COVERAGE
        table.setComponentPopupMenu(this);
44
45
        JMenuItem copyItem = new JMenuItemWithMargin(new ActionCopy());
46 1 1. <init> : removed call to javax/swing/JMenuItem::setText → NO_COVERAGE
        copyItem.setText(I18nUtil.valueByKey("CONTEXT_MENU_COPY"));
47 1 1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("CONTEXT_MENU_COPY", copyItem);
48 1 1. <init> : removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE
        copyItem.setMnemonic('C');
49 1 1. <init> : removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE
        copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
50
        
51
        this.add(copyItem);
52
53 1 1. <init> : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addSeparator → NO_COVERAGE
        this.addSeparator();
54
55
        JMenuItem selectAllItem = new JMenuItemWithMargin(new ActionSelectAll());
56 1 1. <init> : removed call to javax/swing/JMenuItem::setText → NO_COVERAGE
        selectAllItem.setText(I18nUtil.valueByKey("CONTEXT_MENU_SELECT_ALL"));
57 1 1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("CONTEXT_MENU_SELECT_ALL", selectAllItem);
58 1 1. <init> : removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE
        selectAllItem.setMnemonic('A');
59 1 1. <init> : removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE
        selectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK));
60
        
61
        this.add(selectAllItem);
62
63
        // Show menu next mouse pointer
64 1 1. <init> : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addPopupMenuListener → NO_COVERAGE
        this.addPopupMenuListener(new PopupMenuListener() {
65
            
66
            @Override
67
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
68
                // Fix #67773: NullPointerException on getLocation()
69 1 1. popupMenuWillBecomeVisible : negated conditional → NO_COVERAGE
                if (MouseInfo.getPointerInfo() != null) {
70 1 1. popupMenuWillBecomeVisible : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::setLocation → NO_COVERAGE
                    JPopupMenuTable.this.setLocation(MouseInfo.getPointerInfo().getLocation());
71
                }
72
            }
73
            
74
            @Override
75
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
76
                // Do nothing
77
            }
78
            
79
            @Override
80
            public void popupMenuCanceled(PopupMenuEvent e) {
81
                // Do nothing
82
            }
83
        });
84
    }
85
86
    public JPopupMenuTable(JTable tableValues, Action actionShowSearchTable) {
87
        
88
        this(tableValues);
89
        
90 1 1. <init> : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addSeparator → NO_COVERAGE
        this.addSeparator();
91
92
        JMenuItem search = new JMenuItemWithMargin();
93 1 1. <init> : removed call to javax/swing/JMenuItem::setAction → NO_COVERAGE
        search.setAction(actionShowSearchTable);
94 1 1. <init> : removed call to javax/swing/JMenuItem::setText → NO_COVERAGE
        search.setText("Search...");
95 1 1. <init> : removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE
        search.setMnemonic('S');
96 1 1. <init> : removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE
        search.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK));
97
        
98
        this.add(search);
99
    }
100
101
    /**
102
     * An action for Select All shortcut.
103
     */
104
    private class ActionSelectAll extends AbstractAction {
105
        @Override
106
        public void actionPerformed(ActionEvent e) {
107 1 1. actionPerformed : removed call to javax/swing/JTable::selectAll → NO_COVERAGE
            JPopupMenuTable.this.table.selectAll();
108
        }
109
    }
110
111
    /**
112
     * An action for Copy shortcut.
113
     */
114
    private class ActionCopy extends AbstractAction {
115
        @Override
116
        public void actionPerformed(ActionEvent e) {
117
            
118
            var copyEvent = new ActionEvent(
119
                JPopupMenuTable.this.table,
120
                ActionEvent.ACTION_PERFORMED,
121
                "copy"
122
            );
123
            
124 1 1. actionPerformed : removed call to javax/swing/Action::actionPerformed → NO_COVERAGE
            JPopupMenuTable.this.table.getActionMap().get(copyEvent.getActionCommand()).actionPerformed(copyEvent);
125
        }
126
    }
127
}

Mutations

43

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JTable::setComponentPopupMenu → NO_COVERAGE

46

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setText → NO_COVERAGE

47

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

48

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE

49

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE

53

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addSeparator → NO_COVERAGE

56

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setText → NO_COVERAGE

57

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE

58

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE

59

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE

64

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addPopupMenuListener → NO_COVERAGE

69

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

70

1.1
Location : popupMenuWillBecomeVisible
Killed by : none
removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::setLocation → NO_COVERAGE

90

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addSeparator → NO_COVERAGE

93

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setAction → NO_COVERAGE

94

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setText → NO_COVERAGE

95

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE

96

1.1
Location : <init>
Killed by : none
removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE

107

1.1
Location : actionPerformed
Killed by : none
removed call to javax/swing/JTable::selectAll → NO_COVERAGE

124

1.1
Location : actionPerformed
Killed by : none
removed call to javax/swing/Action::actionPerformed → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1