ManagerCoder.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.manager;
12
13
import com.jsql.util.I18nUtil;
14
import com.jsql.util.bruter.ActionCoder;
15
import com.jsql.util.bruter.Coder;
16
import com.jsql.view.swing.manager.util.CoderListener;
17
import com.jsql.view.swing.text.JPopupTextArea;
18
import com.jsql.view.swing.text.JTextAreaPlaceholder;
19
import com.jsql.view.swing.text.listener.DocumentListenerEditing;
20
import com.jsql.view.swing.util.I18nViewUtil;
21
import com.jsql.view.swing.util.JSplitPaneWithZeroSizeDivider;
22
import com.jsql.view.swing.util.UiUtil;
23
24
import javax.swing.*;
25
import javax.swing.event.ChangeEvent;
26
import javax.swing.event.ChangeListener;
27
import java.awt.*;
28
import java.awt.event.MouseAdapter;
29
import java.awt.event.MouseEvent;
30
import java.util.Arrays;
31
import java.util.LinkedHashMap;
32
import java.util.Map;
33
34
/**
35
 * Manager to code/decode string in various methods.
36
 */
37
public class ManagerCoder extends JPanel {
38
39
    /**
40
     * User input to encode.
41
     */
42
    private final JTextArea textInput;
43
44
    /**
45
     * JTextArea displaying result of encoding/decoding.
46
     */
47
    private final JTextArea result;
48
49
    /**
50
     * Encoding choice by user.
51
     */
52
    private JLabel menuMethod;
53
54
    private static final String ENCODE_TO = "Encode to ";
55
    private final transient CoderListener actionCoder = new CoderListener(this);
56
57
    private class ChangeMenuListener implements ChangeListener {
58
        private final String nameMethod;
59
        ChangeMenuListener(String nameMethod) {
60
            this.nameMethod = nameMethod;
61
        }
62
        @Override
63
        public void stateChanged(ChangeEvent e) {
64 1 1. stateChanged : negated conditional → NO_COVERAGE
            if (e.getSource() instanceof JMenuItem) {
65
                JMenuItem item = (JMenuItem) e.getSource();
66 2 1. stateChanged : negated conditional → NO_COVERAGE
2. stateChanged : negated conditional → NO_COVERAGE
                if (item.isSelected() || item.isArmed()) {
67 1 1. stateChanged : removed call to com/jsql/view/swing/manager/util/CoderListener::actionPerformed → NO_COVERAGE
                    ManagerCoder.this.actionCoder.actionPerformed(this.nameMethod);
68
                }
69
            }
70
        }
71
    }
72
73
    /**
74
     * Create a panel to encode a string.
75
     */
76
    public ManagerCoder() {
77
        super(new BorderLayout());
78
79
        var placeholderInput = new JTextAreaPlaceholder(I18nUtil.valueByKey("CODER_INPUT"));
80
        this.textInput = new JPopupTextArea(placeholderInput).getProxy();
81 1 1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("CODER_INPUT", placeholderInput);
82 1 1. <init> : removed call to javax/swing/text/Caret::setBlinkRate → NO_COVERAGE
        this.textInput.getCaret().setBlinkRate(500);
83 1 1. <init> : removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE
        this.textInput.setLineWrap(true);
84 1 1. <init> : removed call to javax/swing/JTextArea::setName → NO_COVERAGE
        this.textInput.setName("textInputManagerCoder");
85 1 1. <init> : removed call to javax/swing/text/Document::addDocumentListener → NO_COVERAGE
        this.textInput.getDocument().addDocumentListener(new DocumentListenerEditing() {
86
            @Override
87
            public void process() {
88 1 1. process : removed call to com/jsql/view/swing/manager/util/CoderListener::actionPerformed → NO_COVERAGE
                ManagerCoder.this.actionCoder.actionPerformed();
89
            }
90
        });
91
92
        JPanel topMixed = this.getTopPanel();
93
94
        var placeholderResult = new JTextAreaPlaceholder(I18nUtil.valueByKey("CODER_RESULT"));
95
        this.result = new JPopupTextArea(placeholderResult).getProxy();
96 1 1. <init> : removed call to com/jsql/view/swing/util/I18nViewUtil::addComponentForKey → NO_COVERAGE
        I18nViewUtil.addComponentForKey("CODER_RESULT", placeholderResult);
97 1 1. <init> : removed call to javax/swing/JTextArea::setName → NO_COVERAGE
        this.result.setName("resultManagerCoder");
98 1 1. <init> : removed call to javax/swing/JTextArea::setLineWrap → NO_COVERAGE
        this.result.setLineWrap(true);
99 1 1. <init> : removed call to javax/swing/JTextArea::setEditable → NO_COVERAGE
        this.result.setEditable(false);
100
101
        var bottom = new JPanel(new BorderLayout());
102 1 1. <init> : removed call to javax/swing/JPanel::add → NO_COVERAGE
        bottom.add(new JScrollPane(this.result), BorderLayout.CENTER);
103
104
        var divider = new JSplitPaneWithZeroSizeDivider(JSplitPane.VERTICAL_SPLIT);
105 1 1. <init> : removed call to com/jsql/view/swing/util/JSplitPaneWithZeroSizeDivider::setResizeWeight → NO_COVERAGE
        divider.setResizeWeight(0.5);
106 1 1. <init> : removed call to com/jsql/view/swing/util/JSplitPaneWithZeroSizeDivider::setTopComponent → NO_COVERAGE
        divider.setTopComponent(topMixed);
107 1 1. <init> : removed call to com/jsql/view/swing/util/JSplitPaneWithZeroSizeDivider::setBottomComponent → NO_COVERAGE
        divider.setBottomComponent(bottom);
108 1 1. <init> : removed call to com/jsql/view/swing/manager/ManagerCoder::add → NO_COVERAGE
        this.add(divider, BorderLayout.CENTER);
109
    }
110
111
    private JPanel getTopPanel() {
112
        var comboMenubar = this.getLabelMenu();
113
        var topMixed = new JPanel(new BorderLayout());
114 1 1. getTopPanel : removed call to javax/swing/JPanel::add → NO_COVERAGE
        topMixed.add(new JScrollPane(this.textInput), BorderLayout.CENTER);
115 1 1. getTopPanel : removed call to javax/swing/JPanel::add → NO_COVERAGE
        topMixed.add(comboMenubar, BorderLayout.SOUTH);
116 1 1. getTopPanel : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getTopPanel → NO_COVERAGE
        return topMixed;
117
    }
118
119
    private JLabel getLabelMenu() {
120
        Map<String, JMenu> mapMenus = new LinkedHashMap<>();
121
        
122
        mapMenus.put(Coder.BASE16.label, new JMenu());
123
        mapMenus.put(Coder.BASE32.label, new JMenu());
124
        mapMenus.put(Coder.BASE58.label, new JMenu());
125
        mapMenus.put(Coder.BASE64.label, new JMenu());
126
        mapMenus.put(Coder.HEX.label, new JMenu());
127
        mapMenus.put(Coder.URL.label, new JMenu());
128
        mapMenus.put(Coder.UNICODE.label, new JMenu());
129
        var menuHtml = new JMenu();
130
        mapMenus.put(Coder.HTML.label, menuHtml);
131
        mapMenus.put(Coder.BASE64_ZIP.label, new JMenu());
132
        mapMenus.put(Coder.HEX_ZIP.label, new JMenu());
133
134
        var menuEncodeHtmlDecimal = new JMenuItem(ManagerCoder.ENCODE_TO + Coder.HTML_DECIMAL.label);
135
        menuHtml.add(menuEncodeHtmlDecimal);
136 1 1. getLabelMenu : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE
        menuEncodeHtmlDecimal.addActionListener(this.actionCoder);
137 1 1. getLabelMenu : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE
        menuEncodeHtmlDecimal.addChangeListener(new ChangeMenuListener(ManagerCoder.ENCODE_TO + Coder.HTML_DECIMAL.label));
138
        
139 1 1. getLabelMenu : removed call to java/util/Map::forEach → NO_COVERAGE
        mapMenus.forEach((label, menu) -> {
140
            var menuEncode = new JMenuItem(ManagerCoder.ENCODE_TO + label);
141 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE
            menuEncode.addActionListener(this.actionCoder);
142 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE
            menuEncode.addChangeListener(new ChangeMenuListener(ManagerCoder.ENCODE_TO + label));
143 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenuItem::setName → NO_COVERAGE
            menuEncode.setName("encodeTo"+ label);
144
145
            var menuDecode = new JMenuItem("Decode from "+ label);
146 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE
            menuDecode.addActionListener(this.actionCoder);
147 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE
            menuDecode.addChangeListener(new ChangeMenuListener("Decode from "+ label));
148 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenuItem::setName → NO_COVERAGE
            menuDecode.setName("decodeFrom"+ label);
149
150 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenu::setText → NO_COVERAGE
            menu.setText(label);
151
            menu.add(menuEncode);
152
            menu.add(menuDecode);
153 1 1. lambda$getLabelMenu$0 : removed call to javax/swing/JMenu::setName → NO_COVERAGE
            menu.setName(label);
154
        });
155
156
        mapMenus.put("Hash", new JMenu("Hash"));
157 1 1. getLabelMenu : removed call to javax/swing/JMenu::setName → NO_COVERAGE
        mapMenus.get("Hash").setName("Hash");
158
159 1 1. getLabelMenu : removed call to java/util/List::forEach → NO_COVERAGE
        ActionCoder.getHashes().forEach(hash -> {
160
            var menuEncode = new JMenuItem("Hash to "+ hash);
161 1 1. lambda$getLabelMenu$1 : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE
            menuEncode.addActionListener(this.actionCoder);
162 1 1. lambda$getLabelMenu$1 : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE
            menuEncode.addChangeListener(new ChangeMenuListener("Hash to "+ hash));
163 1 1. lambda$getLabelMenu$1 : removed call to javax/swing/JMenuItem::setName → NO_COVERAGE
            menuEncode.setName("hashTo"+ hash);
164
            mapMenus.get("Hash").add(menuEncode);
165
        });
166
167
        JPopupMenu popupMenu = new JPopupMenu();
168
        for (JMenu menu: mapMenus.values()) {
169
            popupMenu.add(menu);
170
        }
171
172
        JLabel labelMenu = new JLabel(UiUtil.ARROW_DOWN.getIcon(), SwingConstants.LEFT);
173
        this.menuMethod = labelMenu;
174 1 1. getLabelMenu : removed call to javax/swing/JLabel::setText → NO_COVERAGE
        labelMenu.setText(ManagerCoder.ENCODE_TO + Coder.BASE64.label);
175 1 1. getLabelMenu : removed call to javax/swing/JLabel::setName → NO_COVERAGE
        labelMenu.setName("menuMethodManagerCoder");
176 1 1. getLabelMenu : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE
        labelMenu.setBorder(UiUtil.BORDER_5PX);
177 1 1. getLabelMenu : removed call to javax/swing/JLabel::addMouseListener → NO_COVERAGE
        labelMenu.addMouseListener(new MouseAdapter() {
178
            @Override
179
            public void mousePressed(MouseEvent e) {
180 1 1. mousePressed : removed call to java/util/stream/Stream::forEach → NO_COVERAGE
                Arrays.stream(popupMenu.getComponents()).map(JMenu.class::cast).forEach(menu -> {
181 1 1. lambda$mousePressed$0 : removed call to javax/swing/JMenu::updateUI → NO_COVERAGE
                    menu.updateUI();
182 2 1. lambda$mousePressed$0 : negated conditional → NO_COVERAGE
2. lambda$mousePressed$0 : changed conditional boundary → NO_COVERAGE
                    for (var i = 0 ; i < menu.getItemCount() ; i++) {
183 1 1. lambda$mousePressed$0 : removed call to javax/swing/JMenuItem::updateUI → NO_COVERAGE
                        menu.getItem(i).updateUI();
184
                    }
185
                });  // required: incorrect when dark/light mode switch
186 1 1. mousePressed : removed call to javax/swing/JPopupMenu::updateUI → NO_COVERAGE
                popupMenu.updateUI();  // required: incorrect when dark/light mode switch
187 2 1. mousePressed : Replaced integer addition with subtraction → NO_COVERAGE
2. mousePressed : removed call to javax/swing/JPopupMenu::show → NO_COVERAGE
                popupMenu.show(e.getComponent(), e.getComponent().getX(),e.getComponent().getY() + e.getComponent().getHeight());
188 2 1. mousePressed : Replaced integer addition with subtraction → NO_COVERAGE
2. mousePressed : removed call to javax/swing/JPopupMenu::setLocation → NO_COVERAGE
                popupMenu.setLocation(e.getComponent().getLocationOnScreen().x,e.getComponent().getLocationOnScreen().y + e.getComponent().getHeight());
189
            }
190
        });
191 1 1. getLabelMenu : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getLabelMenu → NO_COVERAGE
        return labelMenu;
192
    }
193
    
194
    
195
    // Getter and setter
196
197
    public JTextArea getTextInput() {
198 1 1. getTextInput : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getTextInput → NO_COVERAGE
        return this.textInput;
199
    }
200
201
    public JLabel getMenuMethod() {
202 1 1. getMenuMethod : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getMenuMethod → NO_COVERAGE
        return this.menuMethod;
203
    }
204
205
    public JTextArea getResult() {
206 1 1. getResult : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getResult → NO_COVERAGE
        return this.result;
207
    }
208
}

Mutations

64

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

66

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

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

67

1.1
Location : stateChanged
Killed by : none
removed call to com/jsql/view/swing/manager/util/CoderListener::actionPerformed → NO_COVERAGE

81

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

82

1.1
Location : <init>
Killed by : none
removed call to javax/swing/text/Caret::setBlinkRate → NO_COVERAGE

83

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

84

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

85

1.1
Location : <init>
Killed by : none
removed call to javax/swing/text/Document::addDocumentListener → NO_COVERAGE

88

1.1
Location : process
Killed by : none
removed call to com/jsql/view/swing/manager/util/CoderListener::actionPerformed → NO_COVERAGE

96

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

97

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

98

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

99

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

102

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

105

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

106

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

107

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

108

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerCoder::add → NO_COVERAGE

114

1.1
Location : getTopPanel
Killed by : none
removed call to javax/swing/JPanel::add → NO_COVERAGE

115

1.1
Location : getTopPanel
Killed by : none
removed call to javax/swing/JPanel::add → NO_COVERAGE

116

1.1
Location : getTopPanel
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getTopPanel → NO_COVERAGE

136

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

137

1.1
Location : getLabelMenu
Killed by : none
removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE

139

1.1
Location : getLabelMenu
Killed by : none
removed call to java/util/Map::forEach → NO_COVERAGE

141

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE

142

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE

143

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenuItem::setName → NO_COVERAGE

146

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE

147

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE

148

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenuItem::setName → NO_COVERAGE

150

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenu::setText → NO_COVERAGE

153

1.1
Location : lambda$getLabelMenu$0
Killed by : none
removed call to javax/swing/JMenu::setName → NO_COVERAGE

157

1.1
Location : getLabelMenu
Killed by : none
removed call to javax/swing/JMenu::setName → NO_COVERAGE

159

1.1
Location : getLabelMenu
Killed by : none
removed call to java/util/List::forEach → NO_COVERAGE

161

1.1
Location : lambda$getLabelMenu$1
Killed by : none
removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE

162

1.1
Location : lambda$getLabelMenu$1
Killed by : none
removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE

163

1.1
Location : lambda$getLabelMenu$1
Killed by : none
removed call to javax/swing/JMenuItem::setName → NO_COVERAGE

174

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

175

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

176

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

177

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

180

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

181

1.1
Location : lambda$mousePressed$0
Killed by : none
removed call to javax/swing/JMenu::updateUI → NO_COVERAGE

182

1.1
Location : lambda$mousePressed$0
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : lambda$mousePressed$0
Killed by : none
changed conditional boundary → NO_COVERAGE

183

1.1
Location : lambda$mousePressed$0
Killed by : none
removed call to javax/swing/JMenuItem::updateUI → NO_COVERAGE

186

1.1
Location : mousePressed
Killed by : none
removed call to javax/swing/JPopupMenu::updateUI → NO_COVERAGE

187

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

2.2
Location : mousePressed
Killed by : none
removed call to javax/swing/JPopupMenu::show → NO_COVERAGE

188

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

2.2
Location : mousePressed
Killed by : none
removed call to javax/swing/JPopupMenu::setLocation → NO_COVERAGE

191

1.1
Location : getLabelMenu
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getLabelMenu → NO_COVERAGE

198

1.1
Location : getTextInput
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getTextInput → NO_COVERAGE

202

1.1
Location : getMenuMethod
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getMenuMethod → NO_COVERAGE

206

1.1
Location : getResult
Killed by : none
replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getResult → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.22.0