TabHeader.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.tab;
12
13
import com.jsql.view.swing.action.ActionCloseTabResult;
14
import com.jsql.view.swing.util.MediatorHelper;
15
import com.jsql.view.swing.util.UiUtil;
16
import org.apache.commons.lang3.StringUtils;
17
18
import javax.swing.*;
19
import java.awt.*;
20
import java.awt.event.MouseEvent;
21
import java.awt.event.MouseListener;
22
23
/**
24
 * Panel displayed as a header for tabs.
25
 */
26
public class TabHeader extends JPanel implements MouseListener {
27
    
28
    private transient Cleanable cleanableTab;
29
    
30
    public interface Cleanable {
31
        void clean();
32
    }
33
    
34
    private final JLabel tabTitleLabel = new JLabel() {
35
        
36
        @Override
37
        public void setText(String text) {
38
            
39 1 1. setText : removed call to javax/swing/JLabel::setText → NO_COVERAGE
            super.setText(text + StringUtils.SPACE);
40
        }
41
    };
42
    
43
    /**
44
     * Tab header with default tab icon.
45
     */
46
    public TabHeader() {
47
        this(UiUtil.ICON_TABLE);
48
    }
49
50
    /**
51
     * Tab header with a custom icon.
52
     */
53
    public TabHeader(Icon imageIcon) {
54
        
55
        super(new FlowLayout(FlowLayout.LEFT, 0, 0));
56
57 1 1. <init> : removed call to com/jsql/view/swing/tab/TabHeader::setOpaque → NO_COVERAGE
        this.setOpaque(false);
58
59
        // Set the text of tab
60 1 1. <init> : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE
        this.getTabTitleLabel().setIcon(imageIcon);
61
        this.add(this.getTabTitleLabel());
62
63
        JButton tabCloseButton = new ButtonClose();
64 1 1. <init> : removed call to javax/swing/JButton::addMouseListener → NO_COVERAGE
        tabCloseButton.addMouseListener(this);
65
66
        this.add(tabCloseButton);
67
    }
68
69
    public TabHeader(String label, Icon imageIcon) {
70
        
71
        this(imageIcon);
72
        
73 1 1. <init> : removed call to javax/swing/JLabel::setText → NO_COVERAGE
        this.getTabTitleLabel().setText(label);
74 1 1. <init> : removed call to javax/swing/JLabel::setName → NO_COVERAGE
        tabTitleLabel.setName(label.trim());
75
    }
76
77
    public TabHeader(String label, Icon imageIcon, Cleanable cleanableTab) {
78
        
79
        this(imageIcon);
80
        
81 1 1. <init> : removed call to javax/swing/JLabel::setText → NO_COVERAGE
        this.getTabTitleLabel().setText(label);
82 1 1. <init> : removed call to javax/swing/JLabel::setName → NO_COVERAGE
        tabTitleLabel.setName(label.trim());
83
        
84
        this.cleanableTab = cleanableTab;
85
    }
86
    
87
    public TabHeader(String label) {
88
        
89
        this();
90
        
91 1 1. <init> : removed call to javax/swing/JLabel::setText → NO_COVERAGE
        this.getTabTitleLabel().setText(label);
92 1 1. <init> : removed call to javax/swing/JLabel::setName → NO_COVERAGE
        tabTitleLabel.setName(label.trim());
93
    }
94
95
    /**
96
     * Action for close button: remove tab.
97
     */
98
    @Override
99
    public void mouseClicked(MouseEvent e) {
100
        
101 1 1. mouseClicked : negated conditional → NO_COVERAGE
        if (SwingUtilities.isRightMouseButton(e)) {
102
            return;
103
        }
104
        
105
        int closeTabNumber = MediatorHelper.tabResults().indexOfTabComponent(TabHeader.this);
106
        
107 1 1. mouseClicked : negated conditional → NO_COVERAGE
        if (this.getCleanableTab() != null) {
108 1 1. mouseClicked : removed call to com/jsql/view/swing/tab/TabHeader$Cleanable::clean → NO_COVERAGE
            this.getCleanableTab().clean();
109
        }
110
        
111 1 1. mouseClicked : removed call to com/jsql/view/swing/action/ActionCloseTabResult::perform → NO_COVERAGE
        ActionCloseTabResult.perform(closeTabNumber);
112
    }
113
114
    @Override
115
    public void mouseEntered(MouseEvent e) {
116
        // Do nothing
117
    }
118
    
119
    @Override
120
    public void mouseExited(MouseEvent e) {
121
        // Do nothing
122
    }
123
    
124
    @Override
125
    public void mousePressed(MouseEvent e) {
126
        // Do nothing
127
    }
128
    
129
    @Override
130
    public void mouseReleased(MouseEvent e) {
131
        // Do nothing
132
    }
133
134
    public JLabel getTabTitleLabel() {
135 1 1. getTabTitleLabel : replaced return value with null for com/jsql/view/swing/tab/TabHeader::getTabTitleLabel → NO_COVERAGE
        return this.tabTitleLabel;
136
    }
137
138
    public Cleanable getCleanableTab() {
139 1 1. getCleanableTab : replaced return value with null for com/jsql/view/swing/tab/TabHeader::getCleanableTab → NO_COVERAGE
        return this.cleanableTab;
140
    }
141
}

Mutations

39

1.1
Location : setText
Killed by : none
removed call to javax/swing/JLabel::setText → NO_COVERAGE

57

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/tab/TabHeader::setOpaque → NO_COVERAGE

60

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

64

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

73

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

74

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

81

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

82

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

91

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

92

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

101

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

107

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

108

1.1
Location : mouseClicked
Killed by : none
removed call to com/jsql/view/swing/tab/TabHeader$Cleanable::clean → NO_COVERAGE

111

1.1
Location : mouseClicked
Killed by : none
removed call to com/jsql/view/swing/action/ActionCloseTabResult::perform → NO_COVERAGE

135

1.1
Location : getTabTitleLabel
Killed by : none
replaced return value with null for com/jsql/view/swing/tab/TabHeader::getTabTitleLabel → NO_COVERAGE

139

1.1
Location : getCleanableTab
Killed by : none
replaced return value with null for com/jsql/view/swing/tab/TabHeader::getCleanableTab → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1