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

Mutations

63

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

65

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

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

66

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

80

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

81

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

82

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

83

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

84

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

87

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

95

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

96

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

97

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

98

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

101

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

104

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

105

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

106

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

107

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

113

1.1
Location : getTopPanel
Killed by : none
removed call to javax/swing/JPanel::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
replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getTopPanel → NO_COVERAGE

135

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

136

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

138

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

140

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

141

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

142

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

145

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

146

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

147

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

149

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

152

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

156

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

158

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

160

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

161

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

162

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

173

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

174

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

175

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

176

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

179

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

180

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

181

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

182

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

185

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

186

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

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::setLocation → NO_COVERAGE

190

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

197

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

201

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

205

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