ProgressBarPausable.java

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.tree;
12
13
import com.jsql.util.LogLevelUtil;
14
import com.jsql.view.swing.util.UiUtil;
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
18
import javax.imageio.ImageIO;
19
import javax.swing.*;
20
import java.awt.*;
21
import java.awt.image.BufferedImage;
22
import java.io.IOException;
23
import java.util.Objects;
24
25
/**
26
 * A progress bar with a Pause icon over it.
27
 */
28
public class ProgressBarPausable extends JProgressBar {
29
    
30
    /**
31
     * Log4j logger sent to view.
32
     */
33
    private static final Logger LOGGER = LogManager.getRootLogger();
34
35
    /**
36
     * True if icon should be displayed, false otherwise.
37
     */
38
    private boolean isIconDisplayed = false;
39
40
    @Override
41
    public void paint(Graphics graphics) {
42
        
43
        // Fix #42285: InternalError on paint()
44
        try {
45 1 1. paint : removed call to javax/swing/JProgressBar::paint → NO_COVERAGE
            super.paint(graphics);
46
        } catch (InternalError e) {
47
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
48
        }
49
50 1 1. paint : negated conditional → NO_COVERAGE
        if (this.isIconDisplayed) {
51
            try {
52
                BufferedImage bufferedImage = ImageIO.read(
53
                    Objects.requireNonNull(ProgressBarPausable.class.getClassLoader().getResource(UiUtil.PATH_PAUSE))
54
                );
55
                graphics.drawImage(
56
                    bufferedImage,
57 2 1. paint : Replaced integer division with multiplication → NO_COVERAGE
2. paint : Replaced integer subtraction with addition → NO_COVERAGE
                    (this.getWidth() - bufferedImage.getWidth()) / 2,
58 2 1. paint : Replaced integer division with multiplication → NO_COVERAGE
2. paint : Replaced integer subtraction with addition → NO_COVERAGE
                    (this.getHeight() - bufferedImage.getHeight()) / 2,
59
                    null
60
                );
61
            } catch (IOException e) {
62
                LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
63
            }
64
        }
65
    }
66
67
    /**
68
     * Activate pause state, hence display pause icon.
69
     */
70
    public void pause() {
71
        this.isIconDisplayed = true;
72
    }
73
}

Mutations

45

1.1
Location : paint
Killed by : none
removed call to javax/swing/JProgressBar::paint → NO_COVERAGE

50

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

57

1.1
Location : paint
Killed by : none
Replaced integer division with multiplication → NO_COVERAGE

2.2
Location : paint
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

58

1.1
Location : paint
Killed by : none
Replaced integer division with multiplication → NO_COVERAGE

2.2
Location : paint
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1