PanelNode.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.tree;
12
13
import com.jsql.util.I18nUtil;
14
import com.jsql.view.swing.tree.model.AbstractNodeModel;
15
import com.jsql.view.swing.util.UiStringUtil;
16
import com.jsql.view.swing.util.UiUtil;
17
18
import javax.swing.*;
19
import javax.swing.tree.DefaultMutableTreeNode;
20
import java.awt.*;
21
import java.awt.event.FocusAdapter;
22
import java.awt.event.FocusEvent;
23
import java.awt.event.KeyAdapter;
24
import java.awt.event.KeyEvent;
25
import java.nio.charset.StandardCharsets;
26
import java.util.stream.Stream;
27
28
/**
29
 * A tree Node composed of an icon, a GIF loader, a progress bar, a label.
30
 */
31
public class PanelNode extends JPanel {
32
    
33
    /**
34
     * Default icon of the node (database or table).
35
     */
36
    private final JLabel iconNode = new JLabel();
37
38
    /**
39
     * A GIF loader, displayed if progress track is unknown (like columns).
40
     */
41
    private final JLabel loaderWait = new JLabel();
42
43
    /**
44
     * Progress bar displayed during injection, with pause icon displayed if user paused the process.
45
     */
46
    private final ProgressBarPausable progressBar = new ProgressBarPausable();
47
48
    /**
49
     * Text of the node.
50
     */
51
    private final JLabel nodeLabel = new JLabel();
52
    private final JTextField textFieldEditable = new JTextField(15);
53
    
54
    /**
55
     * Create Panel for tree nodes.
56
     * @param tree JTree to populate
57
     * @param currentNode Node to draw in the tree
58
     */
59
    public PanelNode(final JTree tree, final DefaultMutableTreeNode currentNode) {
60 1 1. <init> : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE
        this.loaderWait.setIcon(UiUtil.HOURGLASS.getIcon());
61 1 1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE
        this.loaderWait.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
62
63 1 1. <init> : removed call to com/jsql/view/swing/tree/ProgressBarPausable::setPreferredSize → NO_COVERAGE
        this.progressBar.setPreferredSize(new Dimension(20, 20));
64 1 1. <init> : removed call to com/jsql/view/swing/tree/ProgressBarPausable::setBorder → NO_COVERAGE
        this.progressBar.setBorder(BorderFactory.createEmptyBorder(4, 3, 4, 3));
65
66 1 1. <init> : removed call to javax/swing/JLabel::setOpaque → NO_COVERAGE
        this.nodeLabel.setOpaque(true);
67
68 1 1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE
        this.iconNode.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
69
        
70 1 1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::setLayout → NO_COVERAGE
        this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
71
        
72
        Stream.of(
73
            this.iconNode,
74
            this.loaderWait,
75
            this.progressBar,
76
            this.nodeLabel,
77
            this.textFieldEditable
78
        )
79 1 1. <init> : removed call to java/util/stream/Stream::forEach → NO_COVERAGE
        .forEach(component -> {
80
            this.add(component);
81 1 1. lambda$new$0 : removed call to javax/swing/JComponent::setVisible → NO_COVERAGE
            component.setVisible(false);
82
        });
83
        
84 1 1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::setComponentOrientation → NO_COVERAGE
        this.setComponentOrientation(ComponentOrientation.getOrientation(I18nUtil.getCurrentLocale()));
85
        
86 1 1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::initTextFieldEditable → NO_COVERAGE
        this.initTextFieldEditable(tree, currentNode);
87
    }
88
89
    private void initTextFieldEditable(final JTree tree, final DefaultMutableTreeNode currentNode) {
90 1 1. initTextFieldEditable : removed call to javax/swing/JTextField::addActionListener → NO_COVERAGE
        this.textFieldEditable.addActionListener(e -> {
91
            AbstractNodeModel nodeModel = (AbstractNodeModel) currentNode.getUserObject();
92 1 1. lambda$initTextFieldEditable$1 : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE
            nodeModel.setIsEdited(false);
93
            
94 1 1. lambda$initTextFieldEditable$1 : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
            this.nodeLabel.setVisible(true);
95 1 1. lambda$initTextFieldEditable$1 : removed call to javax/swing/JTextField::setVisible → NO_COVERAGE
            this.textFieldEditable.setVisible(false);
96
            tree.requestFocusInWindow();
97
98 1 1. lambda$initTextFieldEditable$1 : removed call to com/jsql/model/bean/database/AbstractElementDatabase::setElementValue → NO_COVERAGE
            nodeModel.getElementDatabase().setElementValue(new String(
99
                this.textFieldEditable.getText().getBytes(StandardCharsets.UTF_8),
100
                StandardCharsets.UTF_8
101
            ));
102 1 1. lambda$initTextFieldEditable$1 : removed call to javax/swing/JLabel::setText → NO_COVERAGE
            this.nodeLabel.setText(UiStringUtil.detectUtf8Html(nodeModel.getElementDatabase().getLabelWithCount()));
103
            
104 1 1. lambda$initTextFieldEditable$1 : removed call to javax/swing/JTree::revalidate → NO_COVERAGE
            tree.revalidate();
105 1 1. lambda$initTextFieldEditable$1 : removed call to javax/swing/JTree::repaint → NO_COVERAGE
            tree.repaint();
106
        });
107
        
108 1 1. initTextFieldEditable : removed call to javax/swing/JTextField::addFocusListener → NO_COVERAGE
        this.textFieldEditable.addFocusListener(new FocusAdapter() {
109
            @Override
110
            public void focusLost(FocusEvent e) {
111
                AbstractNodeModel nodeModel = (AbstractNodeModel) currentNode.getUserObject();
112 1 1. focusLost : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE
                nodeModel.setIsEdited(false);
113 1 1. focusLost : removed call to javax/swing/JTree::revalidate → NO_COVERAGE
                tree.revalidate();
114 1 1. focusLost : removed call to javax/swing/JTree::repaint → NO_COVERAGE
                tree.repaint();
115
            }
116
        });
117
        
118
        KeyAdapter keyAdapterF2 = new KeyAdapter() {
119
            @Override
120
            public void keyPressed(KeyEvent e) {
121
                AbstractNodeModel nodeModel = (AbstractNodeModel) currentNode.getUserObject();
122
                
123 2 1. keyPressed : negated conditional → NO_COVERAGE
2. keyPressed : negated conditional → NO_COVERAGE
                if (e.getKeyCode() == KeyEvent.VK_F2 && !nodeModel.isRunning()) {
124 1 1. keyPressed : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE
                    nodeModel.setIsEdited(true);
125
                    
126 1 1. keyPressed : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
                    PanelNode.this.nodeLabel.setVisible(false);
127 1 1. keyPressed : removed call to javax/swing/JTextField::setVisible → NO_COVERAGE
                    PanelNode.this.textFieldEditable.setVisible(true);
128
                    PanelNode.this.textFieldEditable.requestFocusInWindow();
129
                    
130 1 1. keyPressed : removed call to javax/swing/JTree::revalidate → NO_COVERAGE
                    tree.revalidate();
131 1 1. keyPressed : removed call to javax/swing/JTree::repaint → NO_COVERAGE
                    tree.repaint();
132
                }
133
            }
134
        };
135
        
136 1 1. initTextFieldEditable : removed call to com/jsql/view/swing/tree/PanelNode::addKeyListener → NO_COVERAGE
        this.addKeyListener(keyAdapterF2);
137 1 1. initTextFieldEditable : removed call to javax/swing/JTextField::addKeyListener → NO_COVERAGE
        this.textFieldEditable.addKeyListener(keyAdapterF2);
138
    }
139
140
    /**
141
     * Change the text icon.
142
     * @param newIcon An icon to display next to the text.
143
     */
144
    public void setIconNode(Icon newIcon) {
145 1 1. setIconNode : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE
        this.iconNode.setIcon(newIcon);
146
    }
147
    
148
    /**
149
     * Display text icon to the left.
150
     */
151
    public void showIcon() {
152 1 1. showIcon : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
        this.iconNode.setVisible(true);
153
    }
154
    
155
    /**
156
     * Mask the node icon for example when the loader component is displayed.
157
     */
158
    public void hideIcon() {
159 1 1. hideIcon : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
        this.iconNode.setVisible(false);
160
    }
161
    
162
    /**
163
     * Change the loader icon.
164
     * @param newIcon An icon to display for the loader.
165
     */
166
    public void setLoaderIcon(Icon newIcon) {
167 1 1. setLoaderIcon : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE
        this.loaderWait.setIcon(newIcon);
168
    }
169
170
    /**
171
     * Display the animated gif loader.
172
     */
173
    public void showLoader() {
174 1 1. showLoader : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE
        this.loaderWait.setVisible(true);
175
    }
176
    
177
    
178
    // Getter and setter
179
180
    public ProgressBarPausable getProgressBar() {
181 1 1. getProgressBar : replaced return value with null for com/jsql/view/swing/tree/PanelNode::getProgressBar → NO_COVERAGE
        return this.progressBar;
182
    }
183
184
    public JLabel getNodeLabel() {
185 1 1. getNodeLabel : replaced return value with null for com/jsql/view/swing/tree/PanelNode::getNodeLabel → NO_COVERAGE
        return this.nodeLabel;
186
    }
187
188
    public JTextField getTextFieldEditable() {
189 1 1. getTextFieldEditable : replaced return value with null for com/jsql/view/swing/tree/PanelNode::getTextFieldEditable → NO_COVERAGE
        return this.textFieldEditable;
190
    }
191
}

Mutations

60

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

61

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

63

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/tree/ProgressBarPausable::setPreferredSize → NO_COVERAGE

64

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/tree/ProgressBarPausable::setBorder → NO_COVERAGE

66

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

68

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

70

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/tree/PanelNode::setLayout → NO_COVERAGE

79

1.1
Location : <init>
Killed by : none
removed call to java/util/stream/Stream::forEach → NO_COVERAGE

81

1.1
Location : lambda$new$0
Killed by : none
removed call to javax/swing/JComponent::setVisible → NO_COVERAGE

84

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/tree/PanelNode::setComponentOrientation → NO_COVERAGE

86

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/tree/PanelNode::initTextFieldEditable → NO_COVERAGE

90

1.1
Location : initTextFieldEditable
Killed by : none
removed call to javax/swing/JTextField::addActionListener → NO_COVERAGE

92

1.1
Location : lambda$initTextFieldEditable$1
Killed by : none
removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE

94

1.1
Location : lambda$initTextFieldEditable$1
Killed by : none
removed call to javax/swing/JLabel::setVisible → NO_COVERAGE

95

1.1
Location : lambda$initTextFieldEditable$1
Killed by : none
removed call to javax/swing/JTextField::setVisible → NO_COVERAGE

98

1.1
Location : lambda$initTextFieldEditable$1
Killed by : none
removed call to com/jsql/model/bean/database/AbstractElementDatabase::setElementValue → NO_COVERAGE

102

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

104

1.1
Location : lambda$initTextFieldEditable$1
Killed by : none
removed call to javax/swing/JTree::revalidate → NO_COVERAGE

105

1.1
Location : lambda$initTextFieldEditable$1
Killed by : none
removed call to javax/swing/JTree::repaint → NO_COVERAGE

108

1.1
Location : initTextFieldEditable
Killed by : none
removed call to javax/swing/JTextField::addFocusListener → NO_COVERAGE

112

1.1
Location : focusLost
Killed by : none
removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE

113

1.1
Location : focusLost
Killed by : none
removed call to javax/swing/JTree::revalidate → NO_COVERAGE

114

1.1
Location : focusLost
Killed by : none
removed call to javax/swing/JTree::repaint → NO_COVERAGE

123

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

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

124

1.1
Location : keyPressed
Killed by : none
removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE

126

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

127

1.1
Location : keyPressed
Killed by : none
removed call to javax/swing/JTextField::setVisible → NO_COVERAGE

130

1.1
Location : keyPressed
Killed by : none
removed call to javax/swing/JTree::revalidate → NO_COVERAGE

131

1.1
Location : keyPressed
Killed by : none
removed call to javax/swing/JTree::repaint → NO_COVERAGE

136

1.1
Location : initTextFieldEditable
Killed by : none
removed call to com/jsql/view/swing/tree/PanelNode::addKeyListener → NO_COVERAGE

137

1.1
Location : initTextFieldEditable
Killed by : none
removed call to javax/swing/JTextField::addKeyListener → NO_COVERAGE

145

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

152

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

159

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

167

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

174

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

181

1.1
Location : getProgressBar
Killed by : none
replaced return value with null for com/jsql/view/swing/tree/PanelNode::getProgressBar → NO_COVERAGE

185

1.1
Location : getNodeLabel
Killed by : none
replaced return value with null for com/jsql/view/swing/tree/PanelNode::getNodeLabel → NO_COVERAGE

189

1.1
Location : getTextFieldEditable
Killed by : none
replaced return value with null for com/jsql/view/swing/tree/PanelNode::getTextFieldEditable → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1