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.manager; | |
12 | ||
13 | import com.jsql.view.swing.manager.util.CoderListener; | |
14 | import com.jsql.view.swing.manager.util.MenuBarCoder; | |
15 | import com.jsql.view.swing.panel.util.HTMLEditorKitTextPaneWrap; | |
16 | import com.jsql.view.swing.scrollpane.LightScrollPane; | |
17 | import com.jsql.view.swing.splitpane.JSplitPaneWithZeroSizeDivider; | |
18 | import com.jsql.view.swing.text.JPopupTextArea; | |
19 | import com.jsql.view.swing.text.JPopupTextPane; | |
20 | import com.jsql.view.swing.text.JTextAreaPlaceholder; | |
21 | import com.jsql.view.swing.text.listener.DocumentListenerEditing; | |
22 | ||
23 | import javax.swing.*; | |
24 | import javax.swing.event.ChangeEvent; | |
25 | import javax.swing.event.ChangeListener; | |
26 | import java.awt.*; | |
27 | import java.util.LinkedHashMap; | |
28 | import java.util.Map; | |
29 | import java.util.stream.Stream; | |
30 | ||
31 | /** | |
32 | * Manager to code/decode string in various methods. | |
33 | */ | |
34 | public class ManagerCoder extends JPanel implements Manager { | |
35 | | |
36 | /** | |
37 | * User input to encode. | |
38 | */ | |
39 | private final JTextArea textInput; | |
40 | ||
41 | /** | |
42 | * JTextArea displaying result of encoding/decoding. | |
43 | */ | |
44 | private final JTextPane result; | |
45 | ||
46 | /** | |
47 | * Encoding choice by user. | |
48 | */ | |
49 | private JMenuItem menuMethod; | |
50 | ||
51 | private final transient CoderListener actionCoder = new CoderListener(this); | |
52 | | |
53 | private class ChangeMenuListener implements ChangeListener { | |
54 | | |
55 | private final String nameMethod; | |
56 | | |
57 | ChangeMenuListener(String nameMethod) { | |
58 | this.nameMethod = nameMethod; | |
59 | } | |
60 | | |
61 | @Override | |
62 | public void stateChanged(ChangeEvent e) { | |
63 |
1
1. stateChanged : negated conditional → NO_COVERAGE |
if (e.getSource() instanceof JMenuItem) { |
64 | | |
65 | JMenuItem item = (JMenuItem) e.getSource(); | |
66 | | |
67 |
2
1. stateChanged : negated conditional → NO_COVERAGE 2. stateChanged : negated conditional → NO_COVERAGE |
if (item.isSelected() || item.isArmed()) { |
68 |
1
1. stateChanged : removed call to com/jsql/view/swing/manager/util/CoderListener::actionPerformed → NO_COVERAGE |
ManagerCoder.this.actionCoder.actionPerformed(this.nameMethod); |
69 | } | |
70 | } | |
71 | } | |
72 | } | |
73 | ||
74 | /** | |
75 | * Create a panel to encode a string. | |
76 | */ | |
77 | public ManagerCoder() { | |
78 | | |
79 | super(new BorderLayout()); | |
80 | ||
81 | this.textInput = new JPopupTextArea(new JTextAreaPlaceholder("Type a string to convert")).getProxy(); | |
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::setEditable → NO_COVERAGE |
this.textInput.setEditable(true); |
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("textInputManagerCoder"); |
86 | | |
87 |
1
1. <init> : removed call to javax/swing/text/Document::addDocumentListener → NO_COVERAGE |
this.textInput.getDocument().addDocumentListener(new DocumentListenerEditing() { |
88 | @Override | |
89 | public void process() { | |
90 |
1
1. process : removed call to com/jsql/view/swing/manager/util/CoderListener::actionPerformed → NO_COVERAGE |
ManagerCoder.this.actionCoder.actionPerformed(); |
91 | } | |
92 | }); | |
93 | ||
94 | JPanel topMixed = this.initializeTopPanel(); | |
95 | ||
96 | this.result = new JPopupTextPane("Result of conversion").getProxy(); | |
97 |
1
1. <init> : removed call to javax/swing/JTextPane::setContentType → NO_COVERAGE |
this.result.setContentType("text/html"); |
98 |
1
1. <init> : removed call to javax/swing/JTextPane::setEditorKit → NO_COVERAGE |
this.result.setEditorKit(new HTMLEditorKitTextPaneWrap()); |
99 |
1
1. <init> : removed call to javax/swing/JTextPane::setName → NO_COVERAGE |
this.result.setName("resultManagerCoder"); |
100 | | |
101 | var bottom = new JPanel(new BorderLayout()); | |
102 |
1
1. <init> : removed call to javax/swing/JPanel::add → NO_COVERAGE |
bottom.add(new LightScrollPane(0, 0, 0, 0, this.result), BorderLayout.CENTER); |
103 | ||
104 | var divider = new JSplitPaneWithZeroSizeDivider(JSplitPane.VERTICAL_SPLIT); | |
105 |
1
1. <init> : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::setBorder → NO_COVERAGE |
divider.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
106 |
1
1. <init> : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::setDividerSize → NO_COVERAGE |
divider.setDividerSize(0); |
107 |
1
1. <init> : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::setResizeWeight → NO_COVERAGE |
divider.setResizeWeight(0.5); |
108 | ||
109 |
1
1. <init> : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::setTopComponent → NO_COVERAGE |
divider.setTopComponent(topMixed); |
110 |
1
1. <init> : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::setBottomComponent → NO_COVERAGE |
divider.setBottomComponent(bottom); |
111 | ||
112 |
1
1. <init> : removed call to com/jsql/view/swing/manager/ManagerCoder::add → NO_COVERAGE |
this.add(divider, BorderLayout.CENTER); |
113 | } | |
114 | ||
115 | private JPanel initializeTopPanel() { | |
116 | | |
117 | var topMixed = new JPanel(new BorderLayout()); | |
118 | ||
119 | final var middleLine = new JPanel(); | |
120 |
1
1. initializeTopPanel : removed call to javax/swing/JPanel::setLayout → NO_COVERAGE |
middleLine.setLayout(new BorderLayout()); |
121 |
1
1. initializeTopPanel : removed call to javax/swing/JPanel::setBorder → NO_COVERAGE |
middleLine.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 1)); |
122 | ||
123 | var comboMenubar = this.initializeMenuBarCoder(); | |
124 | | |
125 |
1
1. initializeTopPanel : removed call to javax/swing/JMenuItem::setText → NO_COVERAGE |
this.menuMethod.setText("Encode to Base64"); |
126 | | |
127 | middleLine.add(comboMenubar); | |
128 | ||
129 |
1
1. initializeTopPanel : removed call to javax/swing/JPanel::add → NO_COVERAGE |
topMixed.add(new LightScrollPane(0, 0, 1, 0, this.textInput), BorderLayout.CENTER); |
130 |
1
1. initializeTopPanel : removed call to javax/swing/JPanel::add → NO_COVERAGE |
topMixed.add(middleLine, BorderLayout.SOUTH); |
131 | | |
132 |
1
1. initializeTopPanel : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::initializeTopPanel → NO_COVERAGE |
return topMixed; |
133 | } | |
134 | ||
135 | private MenuBarCoder initializeMenuBarCoder() { | |
136 | | |
137 | Map<String, JMenu> mapMenus = new LinkedHashMap<>(); | |
138 | | |
139 | mapMenus.put("Base16", new JMenu("Base16")); | |
140 | mapMenus.put("Base32", new JMenu("Base32")); | |
141 | mapMenus.put("Base58", new JMenu("Base58")); | |
142 | mapMenus.put("Base64", new JMenu("Base64")); | |
143 | mapMenus.put("Hex", new JMenu("Hex")); | |
144 | mapMenus.put("Url", new JMenu("Url")); | |
145 | mapMenus.put("Unicode", new JMenu("Unicode")); | |
146 | | |
147 | var menuHtml = new JMenu("Html"); | |
148 | mapMenus.put("Html", menuHtml); | |
149 | mapMenus.put("Base64(zipped)", new JMenu("Base64(zipped)")); | |
150 | mapMenus.put("Hex(zipped)", new JMenu("Hex(zipped)")); | |
151 | ||
152 | var menuEncodeHtmlDecimal = new JMenuItem("Encode to Html (decimal)"); | |
153 | menuHtml.add(menuEncodeHtmlDecimal); | |
154 |
1
1. initializeMenuBarCoder : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE |
menuEncodeHtmlDecimal.addActionListener(this.actionCoder); |
155 |
1
1. initializeMenuBarCoder : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE |
menuEncodeHtmlDecimal.addChangeListener(new ChangeMenuListener("Encode to Html (decimal)")); |
156 | | |
157 | mapMenus | |
158 |
1
1. initializeMenuBarCoder : removed call to java/util/Map::forEach → NO_COVERAGE |
.forEach((key, value) -> { |
159 | ||
160 | var menuEncode = new JMenuItem("Encode to " + key); | |
161 |
1
1. lambda$initializeMenuBarCoder$0 : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE |
menuEncode.addActionListener(this.actionCoder); |
162 |
1
1. lambda$initializeMenuBarCoder$0 : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE |
menuEncode.addChangeListener(new ChangeMenuListener("Encode to " + key)); |
163 |
1
1. lambda$initializeMenuBarCoder$0 : removed call to javax/swing/JMenuItem::setName → NO_COVERAGE |
menuEncode.setName("encodeTo" + key); |
164 | ||
165 | var menuDecode = new JMenuItem("Decode from " + key); | |
166 |
1
1. lambda$initializeMenuBarCoder$0 : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE |
menuDecode.addActionListener(this.actionCoder); |
167 |
1
1. lambda$initializeMenuBarCoder$0 : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE |
menuDecode.addChangeListener(new ChangeMenuListener("Decode from " + key)); |
168 |
1
1. lambda$initializeMenuBarCoder$0 : removed call to javax/swing/JMenuItem::setName → NO_COVERAGE |
menuDecode.setName("decodeFrom" + key); |
169 | ||
170 | value.add(menuEncode); | |
171 | value.add(menuDecode); | |
172 |
1
1. lambda$initializeMenuBarCoder$0 : removed call to javax/swing/JMenu::setName → NO_COVERAGE |
value.setName(key); |
173 | }); | |
174 | ||
175 | mapMenus.put("Hash", new JMenu("Hash")); | |
176 |
1
1. initializeMenuBarCoder : removed call to javax/swing/JMenu::setName → NO_COVERAGE |
mapMenus.get("Hash").setName("Hash"); |
177 | | |
178 | Stream.of("Adler32", "Crc16", "Crc32", "Crc64", "Md2", "Md4", "Md5", "Sha-1", "Sha-256", "Sha-384", "Sha-512", "Mysql") | |
179 |
1
1. initializeMenuBarCoder : removed call to java/util/stream/Stream::forEach → NO_COVERAGE |
.forEach(hash -> { |
180 | | |
181 | var menuEncode = new JMenuItem("Hash to "+ hash); | |
182 |
1
1. lambda$initializeMenuBarCoder$1 : removed call to javax/swing/JMenuItem::addActionListener → NO_COVERAGE |
menuEncode.addActionListener(this.actionCoder); |
183 |
1
1. lambda$initializeMenuBarCoder$1 : removed call to javax/swing/JMenuItem::addChangeListener → NO_COVERAGE |
menuEncode.addChangeListener(new ChangeMenuListener("Hash to "+ hash)); |
184 |
1
1. lambda$initializeMenuBarCoder$1 : removed call to javax/swing/JMenuItem::setName → NO_COVERAGE |
menuEncode.setName("hashTo"+ hash); |
185 | | |
186 | mapMenus.get("Hash").add(menuEncode); | |
187 | }); | |
188 | ||
189 | JMenu comboMenu = MenuBarCoder.createMenu("Choose method..."); | |
190 | this.menuMethod = comboMenu; | |
191 |
1
1. initializeMenuBarCoder : removed call to javax/swing/JMenuItem::setName → NO_COVERAGE |
this.menuMethod.setName("menuMethodManagerCoder"); |
192 | | |
193 | for (JMenu menu: mapMenus.values()) { | |
194 | comboMenu.add(menu); | |
195 | } | |
196 | ||
197 | var comboMenubar = new MenuBarCoder(comboMenu); | |
198 |
1
1. initializeMenuBarCoder : removed call to com/jsql/view/swing/manager/util/MenuBarCoder::setOpaque → NO_COVERAGE |
comboMenubar.setOpaque(false); |
199 |
1
1. initializeMenuBarCoder : removed call to com/jsql/view/swing/manager/util/MenuBarCoder::setBorder → NO_COVERAGE |
comboMenubar.setBorder(null); |
200 | | |
201 |
1
1. initializeMenuBarCoder : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::initializeMenuBarCoder → NO_COVERAGE |
return comboMenubar; |
202 | } | |
203 | | |
204 | | |
205 | // Getter and setter | |
206 | ||
207 | public JTextArea getTextInput() { | |
208 |
1
1. getTextInput : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getTextInput → NO_COVERAGE |
return this.textInput; |
209 | } | |
210 | ||
211 | public JMenuItem getMenuMethod() { | |
212 |
1
1. getMenuMethod : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getMenuMethod → NO_COVERAGE |
return this.menuMethod; |
213 | } | |
214 | ||
215 | public JTextPane getResult() { | |
216 |
1
1. getResult : replaced return value with null for com/jsql/view/swing/manager/ManagerCoder::getResult → NO_COVERAGE |
return this.result; |
217 | } | |
218 | } | |
Mutations | ||
63 |
1.1 |
|
67 |
1.1 2.2 |
|
68 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
87 |
1.1 |
|
90 |
1.1 |
|
97 |
1.1 |
|
98 |
1.1 |
|
99 |
1.1 |
|
102 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
112 |
1.1 |
|
120 |
1.1 |
|
121 |
1.1 |
|
125 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
132 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
158 |
1.1 |
|
161 |
1.1 |
|
162 |
1.1 |
|
163 |
1.1 |
|
166 |
1.1 |
|
167 |
1.1 |
|
168 |
1.1 |
|
172 |
1.1 |
|
176 |
1.1 |
|
179 |
1.1 |
|
182 |
1.1 |
|
183 |
1.1 |
|
184 |
1.1 |
|
191 |
1.1 |
|
198 |
1.1 |
|
199 |
1.1 |
|
201 |
1.1 |
|
208 |
1.1 |
|
212 |
1.1 |
|
216 |
1.1 |