TabMouseAdapter.java

1
package com.jsql.view.swing.tab;
2
3
import com.jsql.util.I18nUtil;
4
import com.jsql.util.LogLevelUtil;
5
import com.jsql.view.swing.util.MediatorHelper;
6
import org.apache.commons.lang3.SerializationException;
7
import org.apache.commons.lang3.SerializationUtils;
8
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.Logger;
10
11
import javax.swing.*;
12
import java.awt.*;
13
import java.awt.event.MouseAdapter;
14
import java.awt.event.MouseEvent;
15
16
/**
17
 * Display popupmenu on right click.
18
 * Used on manager tabs.
19
 */
20
public class TabMouseAdapter extends MouseAdapter {
21
    
22
    /**
23
     * Log4j logger sent to view.
24
     */
25
    private static final Logger LOGGER = LogManager.getRootLogger();
26
    
27
    private final TabbedPaneWheeled tabbedPaneWheeled;
28
    
29
    public TabMouseAdapter(TabbedPaneWheeled tabbedPaneWheeled) {
30
        this.tabbedPaneWheeled = tabbedPaneWheeled;
31
    }
32
33
    @Override
34
    public void mouseClicked(MouseEvent event) {
35
        
36 1 1. mouseClicked : negated conditional → NO_COVERAGE
        if (!SwingUtilities.isRightMouseButton(event)) {
37
            return;
38
        }
39
            
40
        var componentSource = (Component) event.getSource();
41
        var menu = new JPopupMenu();
42
43
        // Copy menu items from menubar
44
        for (
45
            var position = 0
46 2 1. mouseClicked : negated conditional → NO_COVERAGE
2. mouseClicked : changed conditional boundary → NO_COVERAGE
            ; position < MediatorHelper.menubar().getMenuView().getMenuComponentCount()
47
            ; position++
48
        ) {
49
            
50
            // Fix #35348: SerializationException on clone()
51
            try {
52
                JMenuItem itemMenu = (JMenuItem) SerializationUtils.clone(MediatorHelper.menubar().getMenuView().getMenuComponent(position));
53
                menu.add(itemMenu);
54
                
55
                final int positionFinal = position;
56 2 1. mouseClicked : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE
2. lambda$mouseClicked$0 : removed call to com/jsql/view/swing/tab/TabbedPaneWheeled::setSelectedIndex → NO_COVERAGE
                itemMenu.addActionListener(actionEvent -> this.tabbedPaneWheeled.setSelectedIndex(positionFinal));
57
                
58
            } catch (SerializationException e) {
59
                LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
60
            }
61
        }
62
63 1 1. mouseClicked : removed call to javax/swing/JPopupMenu::show → NO_COVERAGE
        menu.show(componentSource, event.getX(), event.getY());
64
        
65 1 1. mouseClicked : removed call to javax/swing/JPopupMenu::setLocation → NO_COVERAGE
        menu.setLocation(
66 1 1. mouseClicked : negated conditional → NO_COVERAGE
            ComponentOrientation.RIGHT_TO_LEFT.equals(ComponentOrientation.getOrientation(I18nUtil.getLocaleDefault()))
67 1 1. mouseClicked : Replaced integer subtraction with addition → NO_COVERAGE
            ? event.getXOnScreen() - menu.getWidth()
68
            : event.getXOnScreen(),
69
            event.getYOnScreen()
70
        );
71
    }
72
}

Mutations

36

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

46

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

2.2
Location : mouseClicked
Killed by : none
changed conditional boundary → NO_COVERAGE

56

1.1
Location : mouseClicked
Killed by : none
removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE

2.2
Location : lambda$mouseClicked$0
Killed by : none
removed call to com/jsql/view/swing/tab/TabbedPaneWheeled::setSelectedIndex → NO_COVERAGE

63

1.1
Location : mouseClicked
Killed by : none
removed call to javax/swing/JPopupMenu::show → NO_COVERAGE

65

1.1
Location : mouseClicked
Killed by : none
removed call to javax/swing/JPopupMenu::setLocation → NO_COVERAGE

66

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

67

1.1
Location : mouseClicked
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1