| 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.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 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 31 | ||
| 32 | /** | |
| 33 | * True if icon should be displayed, false otherwise. | |
| 34 | */ | |
| 35 | private boolean isIconDisplayed = false; | |
| 36 | ||
| 37 | @Override | |
| 38 | public void paint(Graphics graphics) { | |
| 39 | | |
| 40 | // Fix #42285: InternalError on paint() | |
| 41 | try { | |
| 42 |
1
1. paint : removed call to javax/swing/JProgressBar::paint → NO_COVERAGE |
super.paint(graphics); |
| 43 | } catch (InternalError e) { | |
| 44 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 45 | } | |
| 46 | ||
| 47 |
1
1. paint : negated conditional → NO_COVERAGE |
if (this.isIconDisplayed) { |
| 48 | try { | |
| 49 | BufferedImage bufferedImage = ImageIO.read( | |
| 50 | Objects.requireNonNull(ProgressBarPausable.class.getClassLoader().getResource(UiUtil.PATH_PAUSE)) | |
| 51 | ); | |
| 52 | graphics.drawImage( | |
| 53 | bufferedImage, | |
| 54 |
2
1. paint : Replaced integer division with multiplication → NO_COVERAGE 2. paint : Replaced integer subtraction with addition → NO_COVERAGE |
(this.getWidth() - bufferedImage.getWidth()) / 2, |
| 55 |
2
1. paint : Replaced integer division with multiplication → NO_COVERAGE 2. paint : Replaced integer subtraction with addition → NO_COVERAGE |
(this.getHeight() - bufferedImage.getHeight()) / 2, |
| 56 | null | |
| 57 | ); | |
| 58 | } catch (IOException e) { | |
| 59 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 60 | } | |
| 61 | } | |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Activate pause state, hence display pause icon. | |
| 66 | */ | |
| 67 | public void pause() { | |
| 68 | this.isIconDisplayed = true; | |
| 69 | } | |
| 70 | } | |
Mutations | ||
| 42 |
1.1 |
|
| 47 |
1.1 |
|
| 54 |
1.1 2.2 |
|
| 55 |
1.1 2.2 |