• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jiangxincode / ApkToolBoxGUI / #1295

15 Nov 2025 09:45AM UTC coverage: 2.849% (-0.002%) from 2.851%
#1295

push

jiangxincode
split color table and color converter

0 of 57 new or added lines in 3 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

248 of 8706 relevant lines covered (2.85%)

0.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/edu/jiangxin/apktoolbox/convert/color/ColorConvertPanel.java
1
package edu.jiangxin.apktoolbox.convert.color;
2

3
import edu.jiangxin.apktoolbox.convert.color.utils.ColorUtils;
4
import edu.jiangxin.apktoolbox.swing.extend.EasyPanel;
5
import edu.jiangxin.apktoolbox.utils.Constants;
6

7
import javax.swing.*;
8
import javax.swing.event.ChangeEvent;
9
import javax.swing.event.ChangeListener;
10
import javax.swing.event.DocumentEvent;
11
import javax.swing.event.DocumentListener;
12
import java.awt.*;
13
import java.io.Serial;
14

15
public class ColorConvertPanel extends EasyPanel {
16
    @Serial
17
    private static final long serialVersionUID = 1L;
18

19
    private Color color;
20

21
    private JSpinner redSpinner;
22

23
    private JSpinner greenInRgbSpinner;
24

25
    private JSpinner blueInRgbSpinner;
26

27
    private JTextField hexInRgbTextField;
28

29
    private JSpinner hueInHsbSpinner;
30

31
    private JSpinner saturationInHsbSpinner;
32

33
    private JSpinner brightnessInHsbSpinner;
34

35
    private JSpinner hueInHslSpinner;
36

37
    private JSpinner saturationInHslSpinner;
38

39
    private JSpinner lightnessInHslSpinner;
40

41
    private JSpinner cyanInCmykSpinner;
42

43
    private JSpinner magentaInCmykSpinner;
44

45
    private JSpinner yellowInCmykSpinner;
46

47
    private JSpinner blackInCmykSpinner;
48

49
    private JSpinner lInCielabSpinner;
50

51
    private JSpinner aInCielabSpinner;
52

53
    private JSpinner bInCielabSpinner;
54

55
    private JTextField colorBoxTextField;
56

UNCOV
57
    private boolean isChangedByUser = true;
×
58

59
    public ColorConvertPanel() throws HeadlessException {
60
        super();
×
61
    }
×
62

63
    @Override
64
    public void initUI() {
65
        BoxLayout boxLayout = new BoxLayout(this, BoxLayout.Y_AXIS);
×
66
        setLayout(boxLayout);
×
67

NEW
68
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
NEW
69
        createColorBoxPanel();
×
70

71
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
72
        createRgbPanel();
×
73

74
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
75
        createHsbPanel();
×
76

77
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
78
        createHslPanel();
×
79

80
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
81
        createCmykPanel();
×
82

83
        add(Box.createVerticalStrut(Constants.DEFAULT_Y_BORDER));
×
84
        createCielabPanel();
×
UNCOV
85
    }
×
86

87
    public void createColorBoxPanel() {
88
        JPanel colorBoxPanel = new JPanel();
×
89
        add(colorBoxPanel);
×
90
        colorBoxPanel.setLayout(new BorderLayout());
×
91
        colorBoxPanel.setBorder(BorderFactory.createTitledBorder("Color Box"));
×
92

93
        JPanel xPanel = new JPanel();
×
94
        colorBoxPanel.add(xPanel);
×
95
        xPanel.setLayout(new BoxLayout(xPanel, BoxLayout.X_AXIS));
×
96

97
        colorBoxTextField = new JTextField();
×
98
        colorBoxTextField.setEditable(false);
×
99
        colorBoxTextField.setOpaque(false);
×
100

101
        xPanel.add(colorBoxTextField);
×
102
    }
×
103

104
    private void createRgbPanel() {
105
        JPanel rgbPanel = new JPanel();
×
106
        add(rgbPanel);
×
107
        rgbPanel.setLayout(new BorderLayout());
×
108
        rgbPanel.setBorder(BorderFactory.createTitledBorder("RGB"));
×
109

110
        JPanel xPanel = new JPanel();
×
111
        rgbPanel.add(xPanel);
×
112
        xPanel.setLayout(new BoxLayout(xPanel, BoxLayout.X_AXIS));
×
113

114
        JLabel rebLabel = new JLabel("R(Red, [0-255])");
×
115
        redSpinner = new JSpinner();
×
116
        redSpinner.setModel(new SpinnerNumberModel(0, 0, 255, 1));
×
117
        redSpinner.addChangeListener(new RgbChangeListener());
×
118

119
        JLabel greenLabel = new JLabel("G(Green, [0-255])");
×
120
        greenInRgbSpinner = new JSpinner();
×
121
        greenInRgbSpinner.setModel(new SpinnerNumberModel(0, 0, 255, 1));
×
122
        greenInRgbSpinner.addChangeListener(new RgbChangeListener());
×
123

124
        JLabel blueLabel = new JLabel("B(Blue, [0-255])");
×
125
        blueInRgbSpinner = new JSpinner();
×
126
        blueInRgbSpinner.setModel(new SpinnerNumberModel(0, 0, 255, 1));
×
127
        blueInRgbSpinner.addChangeListener(new RgbChangeListener());
×
128

129
        JLabel hexLabel = new JLabel("Hex");
×
130
        hexInRgbTextField = new JTextField();
×
131
        hexInRgbTextField.setToolTipText("0xFFFFFF格式常用在通用语言中(Java/C++等), #FFFFFF格式常用在标记语言中(XML/HTML等)");
×
132
        hexInRgbTextField.setEditable(true);
×
133
        hexInRgbTextField.getDocument().addDocumentListener(new HexDocumentListener());
×
134

135
        xPanel.add(rebLabel);
×
136
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
137
        xPanel.add(redSpinner);
×
138
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
139
        xPanel.add(greenLabel);
×
140
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
141
        xPanel.add(greenInRgbSpinner);
×
142
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
143
        xPanel.add(blueLabel);
×
144
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
145
        xPanel.add(blueInRgbSpinner);
×
146
        xPanel.add(Box.createHorizontalStrut(3 * Constants.DEFAULT_X_BORDER));
×
147
        xPanel.add(hexLabel);
×
148
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
149
        xPanel.add(hexInRgbTextField);
×
150
    }
×
151

152
    private void createHsbPanel() {
153
        JPanel hsbPanel = new JPanel();
×
154
        add(hsbPanel);
×
155
        hsbPanel.setLayout(new BorderLayout());
×
156
        hsbPanel.setBorder(BorderFactory.createTitledBorder("HSB/HSV"));
×
157

158
        JPanel xPanel = new JPanel();
×
159
        hsbPanel.add(xPanel);
×
160
        xPanel.setLayout(new BoxLayout(xPanel, BoxLayout.X_AXIS));
×
161

162
        JLabel hueLabel = new JLabel("H(Hue, [0-360])");
×
163
        hueInHsbSpinner = new JSpinner();
×
164
        hueInHsbSpinner.setModel(new SpinnerNumberModel(0, 0, 360, 1));
×
165
        hueInHsbSpinner.addChangeListener(new HsbChangeListener());
×
166

167
        JLabel saturationLabel = new JLabel("S(Saturation, [0-100])");
×
168
        saturationInHsbSpinner = new JSpinner();
×
169
        saturationInHsbSpinner.setModel(new SpinnerNumberModel(100, 0, 100, 1));
×
170
        saturationInHsbSpinner.addChangeListener(new HsbChangeListener());
×
171

172

173
        JLabel brightnessLabel = new JLabel("B/V(Brightness/Value, [0-100])");
×
174
        brightnessInHsbSpinner = new JSpinner();
×
175
        brightnessInHsbSpinner.setModel(new SpinnerNumberModel(100, 0, 100, 1));
×
176
        brightnessInHsbSpinner.addChangeListener(new HsbChangeListener());
×
177

178
        xPanel.add(hueLabel);
×
179
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
180
        xPanel.add(hueInHsbSpinner);
×
181
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
182
        xPanel.add(saturationLabel);
×
183
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
184
        xPanel.add(saturationInHsbSpinner);
×
185
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
186
        xPanel.add(brightnessLabel);
×
187
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
188
        xPanel.add(brightnessInHsbSpinner);
×
189
    }
×
190

191
    private void createHslPanel() {
192
        JPanel hslPanel = new JPanel();
×
193
        add(hslPanel);
×
194
        hslPanel.setLayout(new BorderLayout());
×
195
        hslPanel.setBorder(BorderFactory.createTitledBorder("HSL"));
×
196

197
        JPanel xPanel = new JPanel();
×
198
        hslPanel.add(xPanel);
×
199
        xPanel.setLayout(new BoxLayout(xPanel, BoxLayout.X_AXIS));
×
200

201
        JLabel hueLabel = new JLabel("H(Hue, [0-360])");
×
202
        hueInHslSpinner = new JSpinner();
×
203
        hueInHslSpinner.setModel(new SpinnerNumberModel(0, 0, 360, 1));
×
204
        hueInHslSpinner.addChangeListener(new HslChangeListener());
×
205

206
        JLabel saturationLabel = new JLabel("S(Saturation, [0-100])");
×
207
        saturationInHslSpinner = new JSpinner();
×
208
        saturationInHslSpinner.setModel(new SpinnerNumberModel(100, 0, 100, 1));
×
209
        saturationInHslSpinner.addChangeListener(new HslChangeListener());
×
210

211

212
        JLabel lightnessLabel = new JLabel("L(Lightness, [0-100])");
×
213
        lightnessInHslSpinner = new JSpinner();
×
214
        lightnessInHslSpinner.setModel(new SpinnerNumberModel(50, 0, 100, 1));
×
215
        lightnessInHslSpinner.addChangeListener(new HslChangeListener());
×
216

217
        xPanel.add(hueLabel);
×
218
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
219
        xPanel.add(hueInHslSpinner);
×
220
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
221
        xPanel.add(saturationLabel);
×
222
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
223
        xPanel.add(saturationInHslSpinner);
×
224
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
225
        xPanel.add(lightnessLabel);
×
226
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
227
        xPanel.add(lightnessInHslSpinner);
×
228
    }
×
229

230
    private void createCmykPanel() {
231
        JPanel cmykPanel = new JPanel();
×
232
        add(cmykPanel);
×
233
        cmykPanel.setLayout(new BorderLayout());
×
234
        cmykPanel.setBorder(BorderFactory.createTitledBorder("CMYK"));
×
235

236
        JPanel xPanel = new JPanel();
×
237
        cmykPanel.add(xPanel);
×
238
        xPanel.setLayout(new BoxLayout(xPanel, BoxLayout.X_AXIS));
×
239

240
        JLabel cyanLabel = new JLabel("C(Cyan, [0-100])");
×
241
        cyanInCmykSpinner = new JSpinner();
×
242
        cyanInCmykSpinner.setModel(new SpinnerNumberModel(100, 0, 100, 1));
×
243
        cyanInCmykSpinner.addChangeListener(new CmykChangeListener());
×
244

245
        JLabel magentaLabel = new JLabel("M(Magenta, [0-100])");
×
246
        magentaInCmykSpinner = new JSpinner();
×
247
        magentaInCmykSpinner.setModel(new SpinnerNumberModel(100, 0, 100, 1));
×
248
        magentaInCmykSpinner.addChangeListener(new CmykChangeListener());
×
249

250

251
        JLabel yellowLabel = new JLabel("Y(Yellow, [0-100])");
×
252
        yellowInCmykSpinner = new JSpinner();
×
253
        yellowInCmykSpinner.setModel(new SpinnerNumberModel(100, 0, 100, 1));
×
254
        yellowInCmykSpinner.addChangeListener(new CmykChangeListener());
×
255

256
        JLabel blackLabel = new JLabel("K(Black, [0-100])");
×
257
        blackInCmykSpinner = new JSpinner();
×
258
        blackInCmykSpinner.setModel(new SpinnerNumberModel(0, 0, 100, 1));
×
259
        blackInCmykSpinner.addChangeListener(new CmykChangeListener());
×
260

261
        xPanel.add(cyanLabel);
×
262
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
263
        xPanel.add(cyanInCmykSpinner);
×
264
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
265
        xPanel.add(magentaLabel);
×
266
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
267
        xPanel.add(magentaInCmykSpinner);
×
268
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
269
        xPanel.add(yellowLabel);
×
270
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
271
        xPanel.add(yellowInCmykSpinner);
×
272
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
273
        xPanel.add(blackLabel);
×
274
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
275
        xPanel.add(blackInCmykSpinner);
×
276
    }
×
277

278
    private void createCielabPanel() {
279
        JPanel cielabPanel = new JPanel();
×
280
        add(cielabPanel);
×
281
        cielabPanel.setLayout(new BorderLayout());
×
282
        cielabPanel.setBorder(BorderFactory.createTitledBorder("CIELAB"));
×
283

284
        JPanel xPanel = new JPanel();
×
285
        cielabPanel.add(xPanel);
×
286
        xPanel.setLayout(new BoxLayout(xPanel, BoxLayout.X_AXIS));
×
287

288
        JLabel lLabel = new JLabel("L([0-100])");
×
289
        lInCielabSpinner = new JSpinner();
×
290
        lInCielabSpinner.setModel(new SpinnerNumberModel(50, 0, 100, 1));
×
291
        lInCielabSpinner.addChangeListener(new CielabChangeListener());
×
292

293
        JLabel magentaLabel = new JLabel("A([-128-127])");
×
294
        aInCielabSpinner = new JSpinner();
×
295
        aInCielabSpinner.setModel(new SpinnerNumberModel(0, -128, 127, 1));
×
296
        aInCielabSpinner.addChangeListener(new CielabChangeListener());
×
297

298

299
        JLabel yellowLabel = new JLabel("B([-128-127])");
×
300
        bInCielabSpinner = new JSpinner();
×
301
        bInCielabSpinner.setModel(new SpinnerNumberModel(0, -128, 127, 1));
×
302
        bInCielabSpinner.addChangeListener(new CielabChangeListener());
×
303

304
        xPanel.add(lLabel);
×
305
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
306
        xPanel.add(lInCielabSpinner);
×
307
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
308
        xPanel.add(magentaLabel);
×
309
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
310
        xPanel.add(aInCielabSpinner);
×
311
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
312
        xPanel.add(yellowLabel);
×
313
        xPanel.add(Box.createHorizontalStrut(Constants.DEFAULT_X_BORDER));
×
314
        xPanel.add(bInCielabSpinner);
×
315
    }
×
316

317
    private void syncToOthersFormat(String colorMode) {
318
        if (!colorMode.equalsIgnoreCase("RGB")) {
×
319
            redSpinner.setValue(color.getRed());
×
320
            greenInRgbSpinner.setValue(color.getGreen());
×
321
            blueInRgbSpinner.setValue(color.getBlue());
×
322
        }
323
        if (!colorMode.equalsIgnoreCase("HEX")) {
×
324
            hexInRgbTextField.setText(ColorUtils.color2Hex(color));
×
325
        }
326
        if (!colorMode.equalsIgnoreCase("HSB")) {
×
327
            int[] hsbArray = ColorUtils.color2Hsb(color);
×
328
            hueInHsbSpinner.setValue(hsbArray[0]);
×
329
            saturationInHsbSpinner.setValue(hsbArray[1]);
×
330
            brightnessInHsbSpinner.setValue(hsbArray[2]);
×
331
        }
332
        if (!colorMode.equalsIgnoreCase("HSL")) {
×
333
            int[] hsbArray = ColorUtils.color2Hsl(color);
×
334
            hueInHslSpinner.setValue(hsbArray[0]);
×
335
            saturationInHslSpinner.setValue(hsbArray[1]);
×
336
            lightnessInHslSpinner.setValue(hsbArray[2]);
×
337
        }
338
        if (!colorMode.equalsIgnoreCase("CMYK")) {
×
339
            int[] cmykArray = ColorUtils.color2Cmyk(color);
×
340
            cyanInCmykSpinner.setValue(cmykArray[0]);
×
341
            magentaInCmykSpinner.setValue(cmykArray[1]);
×
342
            yellowInCmykSpinner.setValue(cmykArray[2]);
×
343
            blackInCmykSpinner.setValue(cmykArray[3]);
×
344
        }
345
        if (!colorMode.equalsIgnoreCase("CIELAB")) {
×
346
            int[] cielabArray = ColorUtils.color2Cielab(color);
×
347
            lInCielabSpinner.setValue(cielabArray[0]);
×
348
            aInCielabSpinner.setValue(cielabArray[1]);
×
349
            bInCielabSpinner.setValue(cielabArray[2]);
×
350
        }
351
        colorBoxTextField.setBackground(color);
×
352
        //paint the color box with the converted output color
353
        colorBoxTextField.setOpaque(true);
×
354
    }
×
355

356
    class RgbChangeListener implements ChangeListener {
×
357
        @Override
358
        public void stateChanged(ChangeEvent e) {
359
            if (!isChangedByUser) {
×
360
                return;
×
361
            }
362
            isChangedByUser = false;
×
363
            int red = (Integer) redSpinner.getValue();
×
364
            int green = (Integer) greenInRgbSpinner.getValue();
×
365
            int blue = (Integer) blueInRgbSpinner.getValue();
×
366
            color = new Color(red, green, blue);
×
367
            syncToOthersFormat("RGB");
×
368
            isChangedByUser = true;
×
369
        }
×
370
    }
371

372
    class HsbChangeListener implements ChangeListener {
×
373
        @Override
374
        public void stateChanged(ChangeEvent e) {
375
            if (!isChangedByUser) {
×
376
                return;
×
377
            }
378
            isChangedByUser = false;
×
379
            int hue = (Integer) hueInHsbSpinner.getValue();
×
380
            int saturation = (Integer) saturationInHsbSpinner.getValue();
×
381
            int brightness = (Integer) brightnessInHsbSpinner.getValue();
×
382
            color = ColorUtils.hsb2Color(hue, saturation, brightness);
×
383
            syncToOthersFormat("HSB");
×
384
            isChangedByUser = true;
×
385
        }
×
386
    }
387

388
    class HslChangeListener implements ChangeListener {
×
389
        @Override
390
        public void stateChanged(ChangeEvent e) {
391
            if (!isChangedByUser) {
×
392
                return;
×
393
            }
394
            isChangedByUser = false;
×
395
            int hue = (Integer) hueInHslSpinner.getValue();
×
396
            int saturation = (Integer) saturationInHslSpinner.getValue();
×
397
            int lightness = (Integer) lightnessInHslSpinner.getValue();
×
398
            color = ColorUtils.hsl2Color(hue, saturation, lightness);
×
399
            syncToOthersFormat("HSL");
×
400
            isChangedByUser = true;
×
401
        }
×
402
    }
403

404
    class CmykChangeListener implements ChangeListener {
×
405
        @Override
406
        public void stateChanged(ChangeEvent e) {
407
            if (!isChangedByUser) {
×
408
                return;
×
409
            }
410
            isChangedByUser = false;
×
411
            int cyan = (Integer) cyanInCmykSpinner.getValue();
×
412
            int magenta = (Integer) magentaInCmykSpinner.getValue();
×
413
            int yellow = (Integer) yellowInCmykSpinner.getValue();
×
414
            int black = (Integer) blackInCmykSpinner.getValue();
×
415
            color = ColorUtils.cmyk2Color(cyan, magenta, yellow, black);
×
416
            syncToOthersFormat("CMYK");
×
417
            isChangedByUser = true;
×
418
        }
×
419
    }
420

421
    class CielabChangeListener implements ChangeListener {
×
422
        @Override
423
        public void stateChanged(ChangeEvent e) {
424
            if (!isChangedByUser) {
×
425
                return;
×
426
            }
427
            isChangedByUser = false;
×
428
            int l = (Integer) lInCielabSpinner.getValue();
×
429
            int a = (Integer) aInCielabSpinner.getValue();
×
430
            int b = (Integer) bInCielabSpinner.getValue();
×
431
            color = ColorUtils.cielab2Color(l, a, b);
×
432
            syncToOthersFormat("CIELAB");
×
433
            isChangedByUser = true;
×
434
        }
×
435
    }
436

437
    class HexDocumentListener implements DocumentListener {
×
438
        @Override
439
        public void insertUpdate(DocumentEvent e) {
440
            onValueUpdate();
×
441
        }
×
442

443
        @Override
444
        public void removeUpdate(DocumentEvent e) {
445
            onValueUpdate();
×
446
        }
×
447

448
        @Override
449
        public void changedUpdate(DocumentEvent e) {
450
            onValueUpdate();
×
451
        }
×
452

453
        private void onValueUpdate() {
454
            if (!isChangedByUser) {
×
455
                return;
×
456
            }
457
            isChangedByUser = false;
×
458
            String hex = hexInRgbTextField.getText();
×
459
            try {
460
                color = ColorUtils.hex2Color(hex);
×
461
                syncToOthersFormat("HEX");
×
462
            } catch (NumberFormatException e) {
×
463
                logger.error("Invalid hex value: {}", hex);
×
464
            }
×
465
            isChangedByUser = true;
×
466
        }
×
467
    }
468
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc