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.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.plaf.basic.BasicProgressBarUI; | |
20 | import javax.swing.tree.DefaultMutableTreeNode; | |
21 | import java.awt.*; | |
22 | import java.awt.event.*; | |
23 | import java.nio.charset.StandardCharsets; | |
24 | import java.util.Objects; | |
25 | import java.util.stream.Stream; | |
26 | ||
27 | /** | |
28 | * A tree Node composed of an icon, a GIF loader, a progress bar, a label. | |
29 | */ | |
30 | public class PanelNode extends JPanel { | |
31 | | |
32 | /** | |
33 | * Default icon of the node (database or table). | |
34 | */ | |
35 | private final JLabel icon = new JLabel(); | |
36 | ||
37 | /** | |
38 | * A GIF loader, displayed if progress track is unknown (like columns). | |
39 | */ | |
40 | private final JLabel loader = new JLabel(); | |
41 | ||
42 | /** | |
43 | * Progress bar displayed during injection, with pause icon displayed if user paused the process. | |
44 | */ | |
45 | private final ProgressBarPausable progressBar = new ProgressBarPausable(); | |
46 | ||
47 | /** | |
48 | * Text of the node. | |
49 | */ | |
50 | private final JLabel label = new JLabel(); | |
51 | private final JTextField textFieldEditable = new JTextField(15); | |
52 | | |
53 | /** | |
54 | * Create Panel for tree nodes. | |
55 | * @param tree JTree to populate | |
56 | * @param currentNode Node to draw in the tree | |
57 | */ | |
58 | public PanelNode(final JTree tree, final DefaultMutableTreeNode currentNode) { | |
59 | | |
60 | var animatedGIF = new ImageIcon(Objects.requireNonNull(PanelNode.class.getClassLoader().getResource(UiUtil.PATH_PROGRESSBAR))); | |
61 |
1
1. <init> : removed call to javax/swing/ImageIcon::setImageObserver → NO_COVERAGE |
animatedGIF.setImageObserver(new ImageObserverAnimated(tree, currentNode)); |
62 | | |
63 |
1
1. <init> : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE |
this.loader.setIcon(animatedGIF); |
64 |
1
1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
this.loader.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
65 | ||
66 |
1
1. <init> : removed call to com/jsql/view/swing/tree/ProgressBarPausable::setPreferredSize → NO_COVERAGE |
this.progressBar.setPreferredSize(new Dimension(20, 20)); |
67 |
1
1. <init> : removed call to com/jsql/view/swing/tree/ProgressBarPausable::setUI → NO_COVERAGE |
this.progressBar.setUI(new BasicProgressBarUI()); |
68 |
1
1. <init> : removed call to com/jsql/view/swing/tree/ProgressBarPausable::setBorder → NO_COVERAGE |
this.progressBar.setBorder(BorderFactory.createCompoundBorder( |
69 | BorderFactory.createEmptyBorder(4, 3, 4, 3), | |
70 | BorderFactory.createCompoundBorder( | |
71 | BorderFactory.createLineBorder(Color.GRAY), | |
72 | BorderFactory.createLineBorder(Color.WHITE) | |
73 | ) | |
74 | )); | |
75 | | |
76 |
1
1. <init> : removed call to javax/swing/JLabel::setOpaque → NO_COVERAGE |
this.label.setOpaque(true); |
77 |
1
1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
this.label.setBorder(UiUtil.BORDER_FOCUS_GAINED); |
78 | ||
79 |
1
1. <init> : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
this.icon.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
80 | | |
81 |
1
1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::setBackground → NO_COVERAGE |
this.setBackground(Color.WHITE); |
82 |
1
1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::setLayout → NO_COVERAGE |
this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); |
83 | | |
84 | Stream.of( | |
85 | this.icon, | |
86 | this.loader, | |
87 | this.progressBar, | |
88 | this.label, | |
89 | this.textFieldEditable | |
90 | ) | |
91 |
1
1. <init> : removed call to java/util/stream/Stream::forEach → NO_COVERAGE |
.forEach(component -> { |
92 | | |
93 | this.add(component); | |
94 |
1
1. lambda$new$0 : removed call to javax/swing/JComponent::setVisible → NO_COVERAGE |
component.setVisible(false); |
95 | }); | |
96 | | |
97 |
1
1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::setComponentOrientation → NO_COVERAGE |
this.setComponentOrientation(ComponentOrientation.getOrientation(I18nUtil.getLocaleDefault())); |
98 | | |
99 |
1
1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::initializeTextFieldEditable → NO_COVERAGE |
this.initializeTextFieldEditable(tree, currentNode); |
100 | ||
101 |
1
1. <init> : removed call to com/jsql/view/swing/tree/PanelNode::addFocusListener → NO_COVERAGE |
this.addFocusListener(new FocusListener() { |
102 | | |
103 | @Override | |
104 | public void focusLost(FocusEvent e) { | |
105 | | |
106 |
1
1. focusLost : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
PanelNode.this.label.setBackground(UiUtil.COLOR_FOCUS_LOST); |
107 |
1
1. focusLost : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
PanelNode.this.label.setBorder(UiUtil.BORDER_FOCUS_LOST); |
108 | } | |
109 | | |
110 | @Override | |
111 | public void focusGained(FocusEvent e) { | |
112 | | |
113 |
1
1. focusGained : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
PanelNode.this.label.setBackground(UiUtil.COLOR_FOCUS_GAINED); |
114 |
1
1. focusGained : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
PanelNode.this.label.setBorder(UiUtil.BORDER_FOCUS_GAINED); |
115 | } | |
116 | }); | |
117 | } | |
118 | ||
119 | private void initializeTextFieldEditable(final JTree tree, final DefaultMutableTreeNode currentNode) { | |
120 | | |
121 |
1
1. initializeTextFieldEditable : removed call to javax/swing/JTextField::setFont → NO_COVERAGE |
this.textFieldEditable.setFont(UiUtil.FONT_NON_MONO); |
122 |
1
1. initializeTextFieldEditable : removed call to javax/swing/JTextField::setBorder → NO_COVERAGE |
this.textFieldEditable.setBorder(BorderFactory.createLineBorder(UiUtil.COLOR_FOCUS_GAINED, 1, false)); |
123 | | |
124 |
1
1. initializeTextFieldEditable : removed call to javax/swing/JTextField::addActionListener → NO_COVERAGE |
this.textFieldEditable.addActionListener(e -> { |
125 | | |
126 | AbstractNodeModel nodeModel = (AbstractNodeModel) currentNode.getUserObject(); | |
127 |
1
1. lambda$initializeTextFieldEditable$1 : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE |
nodeModel.setIsEdited(false); |
128 | | |
129 |
1
1. lambda$initializeTextFieldEditable$1 : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE |
this.label.setVisible(true); |
130 |
1
1. lambda$initializeTextFieldEditable$1 : removed call to javax/swing/JTextField::setVisible → NO_COVERAGE |
this.textFieldEditable.setVisible(false); |
131 | tree.requestFocusInWindow(); | |
132 | ||
133 |
1
1. lambda$initializeTextFieldEditable$1 : removed call to com/jsql/model/bean/database/AbstractElementDatabase::setElementValue → NO_COVERAGE |
nodeModel.getElementDatabase().setElementValue(new String( |
134 | this.textFieldEditable.getText().getBytes(StandardCharsets.UTF_8), | |
135 | StandardCharsets.UTF_8 | |
136 | )); | |
137 |
1
1. lambda$initializeTextFieldEditable$1 : removed call to javax/swing/JLabel::setText → NO_COVERAGE |
this.label.setText(UiStringUtil.detectUtf8Html(nodeModel.getElementDatabase().getLabelCount())); |
138 | | |
139 |
1
1. lambda$initializeTextFieldEditable$1 : removed call to javax/swing/JTree::revalidate → NO_COVERAGE |
tree.revalidate(); |
140 |
1
1. lambda$initializeTextFieldEditable$1 : removed call to javax/swing/JTree::repaint → NO_COVERAGE |
tree.repaint(); |
141 | }); | |
142 | | |
143 |
1
1. initializeTextFieldEditable : removed call to javax/swing/JTextField::addFocusListener → NO_COVERAGE |
this.textFieldEditable.addFocusListener(new FocusAdapter() { |
144 | | |
145 | @Override | |
146 | public void focusLost(FocusEvent e) { | |
147 | | |
148 | AbstractNodeModel nodeModel = (AbstractNodeModel) currentNode.getUserObject(); | |
149 |
1
1. focusLost : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE |
nodeModel.setIsEdited(false); |
150 |
1
1. focusLost : removed call to javax/swing/JTree::revalidate → NO_COVERAGE |
tree.revalidate(); |
151 |
1
1. focusLost : removed call to javax/swing/JTree::repaint → NO_COVERAGE |
tree.repaint(); |
152 | } | |
153 | }); | |
154 | | |
155 | KeyAdapter keyAdapterF2 = new KeyAdapter() { | |
156 | | |
157 | @Override | |
158 | public void keyPressed(KeyEvent e) { | |
159 | | |
160 | AbstractNodeModel nodeModel = (AbstractNodeModel) currentNode.getUserObject(); | |
161 | | |
162 |
2
1. keyPressed : negated conditional → NO_COVERAGE 2. keyPressed : negated conditional → NO_COVERAGE |
if (e.getKeyCode() == KeyEvent.VK_F2 && !nodeModel.isRunning()) { |
163 | | |
164 |
1
1. keyPressed : removed call to com/jsql/view/swing/tree/model/AbstractNodeModel::setIsEdited → NO_COVERAGE |
nodeModel.setIsEdited(true); |
165 | | |
166 |
1
1. keyPressed : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE |
PanelNode.this.label.setVisible(false); |
167 |
1
1. keyPressed : removed call to javax/swing/JTextField::setVisible → NO_COVERAGE |
PanelNode.this.textFieldEditable.setVisible(true); |
168 | PanelNode.this.textFieldEditable.requestFocusInWindow(); | |
169 | | |
170 |
1
1. keyPressed : removed call to javax/swing/JTree::revalidate → NO_COVERAGE |
tree.revalidate(); |
171 |
1
1. keyPressed : removed call to javax/swing/JTree::repaint → NO_COVERAGE |
tree.repaint(); |
172 | } | |
173 | } | |
174 | }; | |
175 | | |
176 |
1
1. initializeTextFieldEditable : removed call to com/jsql/view/swing/tree/PanelNode::addKeyListener → NO_COVERAGE |
this.addKeyListener(keyAdapterF2); |
177 |
1
1. initializeTextFieldEditable : removed call to javax/swing/JTextField::addKeyListener → NO_COVERAGE |
this.textFieldEditable.addKeyListener(keyAdapterF2); |
178 | } | |
179 | ||
180 | /** | |
181 | * Change the text icon. | |
182 | * @param newIcon An icon to display next to the text. | |
183 | */ | |
184 | public void setIcon(Icon newIcon) { | |
185 |
1
1. setIcon : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE |
this.icon.setIcon(newIcon); |
186 | } | |
187 | | |
188 | /** | |
189 | * Display the normal text icon to the left. | |
190 | */ | |
191 | public void showIcon() { | |
192 |
1
1. showIcon : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE |
this.icon.setVisible(true); |
193 | } | |
194 | | |
195 | /** | |
196 | * Mask the node icon for example when the loader component is displayed. | |
197 | */ | |
198 | public void hideIcon() { | |
199 |
1
1. hideIcon : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE |
this.icon.setVisible(false); |
200 | } | |
201 | | |
202 | /** | |
203 | * Change the loader icon. | |
204 | * @param newIcon An icon to display for the loader. | |
205 | */ | |
206 | public void setLoaderIcon(Icon newIcon) { | |
207 |
1
1. setLoaderIcon : removed call to javax/swing/JLabel::setIcon → NO_COVERAGE |
this.loader.setIcon(newIcon); |
208 | } | |
209 | ||
210 | /** | |
211 | * Display the animated gif loader. | |
212 | */ | |
213 | public void showLoader() { | |
214 |
1
1. showLoader : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE |
this.loader.setVisible(true); |
215 | } | |
216 | | |
217 | | |
218 | // Getter and setter | |
219 | ||
220 | public ProgressBarPausable getProgressBar() { | |
221 |
1
1. getProgressBar : replaced return value with null for com/jsql/view/swing/tree/PanelNode::getProgressBar → NO_COVERAGE |
return this.progressBar; |
222 | } | |
223 | ||
224 | public JLabel getLabel() { | |
225 |
1
1. getLabel : replaced return value with null for com/jsql/view/swing/tree/PanelNode::getLabel → NO_COVERAGE |
return this.label; |
226 | } | |
227 | ||
228 | public JTextField getEditable() { | |
229 |
1
1. getEditable : replaced return value with null for com/jsql/view/swing/tree/PanelNode::getEditable → NO_COVERAGE |
return this.textFieldEditable; |
230 | } | |
231 | } | |
Mutations | ||
61 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
79 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
91 |
1.1 |
|
94 |
1.1 |
|
97 |
1.1 |
|
99 |
1.1 |
|
101 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
113 |
1.1 |
|
114 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
124 |
1.1 |
|
127 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
133 |
1.1 |
|
137 |
1.1 |
|
139 |
1.1 |
|
140 |
1.1 |
|
143 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
162 |
1.1 2.2 |
|
164 |
1.1 |
|
166 |
1.1 |
|
167 |
1.1 |
|
170 |
1.1 |
|
171 |
1.1 |
|
176 |
1.1 |
|
177 |
1.1 |
|
185 |
1.1 |
|
192 |
1.1 |
|
199 |
1.1 |
|
207 |
1.1 |
|
214 |
1.1 |
|
221 |
1.1 |
|
225 |
1.1 |
|
229 |
1.1 |