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

Mutations

68

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

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

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

69

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

82

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

83

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

84

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

85

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

86

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

89

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

97

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

98

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

99

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

100

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

103

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

106

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

107

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

108

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

109

1.1
Location : <init>
Killed by : none
removed call to com/jsql/view/swing/manager/ManagerCoder::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
removed call to javax/swing/JPanel::add → NO_COVERAGE

117

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

137

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

138

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

140

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

142

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

143

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

144

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

147

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

148

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

149

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

151

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

154

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

158

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

160

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

162

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

163

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

164

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

175

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

176

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

177

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

178

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

181

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

182

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

183

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

184

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

187

1.1
Location : mousePressed
Killed by : none
removed call to javax/swing/JPopupMenu::updateUI → 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::show → NO_COVERAGE

189

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

192

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

199

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

203

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

207

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.1