JPopupMenuTable.java

1
/*******************************************************************************
2
 * Copyhacked (H) 2012-2025.
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 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.util.I18nViewUtil;
15
16
import javax.swing.*;
17
import javax.swing.event.PopupMenuEvent;
18
import javax.swing.event.PopupMenuListener;
19
import java.awt.*;
20
import java.awt.event.ActionEvent;
21
import java.awt.event.InputEvent;
22
import java.awt.event.KeyEvent;
23
24
/**
25
 * Default popup menu and shortcuts for a table.
26
 */
27
public class JPopupMenuTable extends JPopupMenu {
28
    
29
    /**
30
     * Table with new menu and shortcut.
31
     */
32
    private final JTable table;
33
34
    /**
35
     * Create popup menu for this table component.
36
     * @param table The table receiving the menu
37
     */
38
    public JPopupMenuTable(JTable table) {
39
        this.table = table;
40 1 1. <init> : removed call to javax/swing/JTable::setComponentPopupMenu → NO_COVERAGE
        table.setComponentPopupMenu(this);
41
42
        JMenuItem copyItem = new JMenuItem(new ActionCopy());
43 1 1. <init> : removed call to javax/swing/JMenuItem::setText → NO_COVERAGE
        copyItem.setText(I18nUtil.valueByKey("CONTEXT_MENU_COPY"));
44 1 1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("CONTEXT_MENU_COPY", copyItem);
45 1 1. <init> : removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE
        copyItem.setMnemonic('C');
46 1 1. <init> : removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE
        copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
47
48
        JMenuItem selectAllItem = new JMenuItem(new ActionSelectAll());
49 1 1. <init> : removed call to javax/swing/JMenuItem::setText → NO_COVERAGE
        selectAllItem.setText(I18nUtil.valueByKey("CONTEXT_MENU_SELECT_ALL"));
50 1 1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("CONTEXT_MENU_SELECT_ALL", selectAllItem);
51 1 1. <init> : removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE
        selectAllItem.setMnemonic('A');
52 1 1. <init> : removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE
        selectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK));
53
54
        this.add(copyItem);
55 1 1. <init> : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addSeparator → NO_COVERAGE
        this.addSeparator();
56
        this.add(selectAllItem);
57
58
        // Show menu next mouse pointer
59 1 1. <init> : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addPopupMenuListener → NO_COVERAGE
        this.addPopupMenuListener(new PopupMenuListener() {
60
            @Override
61
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
62
                // Fix #67773: NullPointerException on getLocation()
63 1 1. popupMenuWillBecomeVisible : negated conditional → NO_COVERAGE
                if (MouseInfo.getPointerInfo() != null) {
64 1 1. popupMenuWillBecomeVisible : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::setLocation → NO_COVERAGE
                    JPopupMenuTable.this.setLocation(MouseInfo.getPointerInfo().getLocation());
65
                }
66
            }
67
            @Override
68
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
69
                // Do nothing
70
            }
71
            @Override
72
            public void popupMenuCanceled(PopupMenuEvent e) {
73
                // Do nothing
74
            }
75
        });
76
    }
77
78
    public JPopupMenuTable(JTable tableValues, Action actionShowSearchTable) {
79
        this(tableValues);
80
81
        JMenuItem search = new JMenuItem();
82 1 1. <init> : removed call to javax/swing/JMenuItem::setAction → NO_COVERAGE
        search.setAction(actionShowSearchTable);
83 1 1. <init> : removed call to javax/swing/JMenuItem::setText → NO_COVERAGE
        search.setText("Search...");
84 1 1. <init> : removed call to javax/swing/JMenuItem::setMnemonic → NO_COVERAGE
        search.setMnemonic('S');
85 1 1. <init> : removed call to javax/swing/JMenuItem::setAccelerator → NO_COVERAGE
        search.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK));
86 1 1. <init> : removed call to com/jsql/view/swing/popupmenu/JPopupMenuTable::addSeparator → NO_COVERAGE
        this.addSeparator();
87
        this.add(search);
88
    }
89
90
    /**
91
     * An action for Select All shortcut.
92
     */
93
    private class ActionSelectAll extends AbstractAction {
94
        @Override
95
        public void actionPerformed(ActionEvent e) {
96 1 1. actionPerformed : removed call to javax/swing/JTable::selectAll → NO_COVERAGE
            JPopupMenuTable.this.table.selectAll();
97
        }
98
    }
99
100
    /**
101
     * An action for Copy shortcut.
102
     */
103
    private class ActionCopy extends AbstractAction {
104
        @Override
105
        public void actionPerformed(ActionEvent e) {
106
            var copyEvent = new ActionEvent(JPopupMenuTable.this.table, ActionEvent.ACTION_PERFORMED, "copy");
107 1 1. actionPerformed : removed call to javax/swing/Action::actionPerformed → NO_COVERAGE
            JPopupMenuTable.this.table.getActionMap().get(copyEvent.getActionCommand()).actionPerformed(copyEvent);
108
        }
109
    }
110
}

Mutations

40

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

43

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

44

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

45

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

46

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

49

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

50

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

51

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

52

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

55

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

59

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

63

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

64

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

82

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

83

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

84

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

85

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

86

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

96

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

107

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.18.2