Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use color constants #75

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ jobs:
- name: Fetch Sources
uses: actions/checkout@v4

# Validate wrapper
- name: Gradle Wrapper Validation
uses: gradle/actions/wrapper-validation@v4

# Set up Java environment for the next steps
- name: Setup Java
uses: actions/setup-java@v4
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased]

### Added

- Use built-in constants for colors

## [0.0.7] - 2024-09-23

### Added
Expand Down
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ version = providers.gradleProperty("pluginVersion").get()

// Set the JVM language level used to build the project.
kotlin {
jvmToolchain(17)
jvmToolchain(21)
}

// Configure project's dependencies
Expand Down Expand Up @@ -45,9 +45,6 @@ dependencies {
// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file for plugin from JetBrains Marketplace.
plugins(providers.gradleProperty("platformPlugins").map { it.split(',') })

instrumentationTools()
pluginVerifier()
zipSigner()
testFramework(TestFrameworkType.Platform)
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pluginRepositoryUrl = https://github.com/strangelookingnerd/pedro-progress-bar-p
pluginVersion = 0.0.8

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 233
pluginSinceBuild = 251
pluginUntilBuild =

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2023.3.8
platformVersion = 251.23536.34

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP
Expand Down
71 changes: 23 additions & 48 deletions src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@

package com.github.strangelookingnerd;

import com.intellij.openapi.progress.util.ColorProgressBar;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.openapi.progress.util.ProgressBarUtil;
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtilities;

import javax.swing.ImageIcon;
Expand Down Expand Up @@ -57,28 +56,6 @@
*/
public class PedroProgressBarUI extends BasicProgressBarUI {

private static final Color TRACK_COLOR = JBColor.namedColor("ProgressBar.trackColor",
new JBColor(Gray.xC4, Gray.x55));
private static final Color PROGRESS_COLOR = JBColor.namedColor("ProgressBar.progressColor",
new JBColor(Gray.x80, Gray.xA0));
private static final Color INDETERMINATE_START_COLOR = JBColor.namedColor("ProgressBar.indeterminateStartColor",
new JBColor(Gray.xC4, Gray.x69));
private static final Color INDETERMINATE_END_COLOR = JBColor.namedColor("ProgressBar.indeterminateEndColor",
new JBColor(Gray.x80, Gray.x83));

private static final Color FAILED_COLOR = JBColor.namedColor("ProgressBar.failedColor",
new JBColor(0xd64f4f, 0xe74848));
private static final Color FAILED_END_COLOR = JBColor.namedColor("ProgressBar.failedEndColor",
new JBColor(0xfb8f89, 0xf4a2a0));
private static final Color PASSED_COLOR = JBColor.namedColor("ProgressBar.passedColor",
new JBColor(0x34b171, 0x008f50));
private static final Color PASSED_END_COLOR = JBColor.namedColor("ProgressBar.passedEndColor",
new JBColor(0x7ee8a5, 0x5dc48f));
private static final Color WARNING_COLOR = JBColor.namedColor("ProgressBar.warningColor",
new JBColor(0xF0A732, 0xD9A343));
private static final Color WARNING_END_COLOR = JBColor.namedColor("ProgressBar.warningEndColor",
new JBColor(0xEAD2A1, 0xEAD2A1));

private static final int CYCLE_TIME_DEFAULT = 800;
private static final int REPAINT_INTERVAL_DEFAULT = 50;

Expand Down Expand Up @@ -114,25 +91,24 @@
JBInsets.removeFrom(r, i);
int orientation = progressBar.getOrientation();

// Use foreground color as a reference, don't use it directly. This is done for compatibility reason.
// Colors are hardcoded in UI delegates by design. If more colors are needed contact designers.
Color startColor;
Color endColor;
Color foreground = progressBar.getForeground();
if (foreground == ColorProgressBar.RED) {
startColor = FAILED_COLOR;
endColor = FAILED_END_COLOR;
} else if (foreground == ColorProgressBar.GREEN) {
startColor = PASSED_COLOR;
endColor = PASSED_END_COLOR;
} else if (foreground == ColorProgressBar.YELLOW) {
startColor = WARNING_COLOR;
endColor = WARNING_END_COLOR;
Object statusProperty = progressBar.getClientProperty(ProgressBarUtil.STATUS_KEY);

Check warning on line 97 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L97

Added line #L97 was not covered by tests
if (ProgressBarUtil.FAILED_VALUE.equals(statusProperty) || foreground == JBUI.CurrentTheme.ProgressBar.FAILED) {
startColor = JBUI.CurrentTheme.ProgressBar.FAILED;
endColor = JBUI.CurrentTheme.ProgressBar.FAILED_END;

Check warning on line 100 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L99-L100

Added lines #L99 - L100 were not covered by tests
} else if (ProgressBarUtil.PASSED_VALUE.equals(statusProperty) || foreground == JBUI.CurrentTheme.ProgressBar.PASSED) {
startColor = JBUI.CurrentTheme.ProgressBar.PASSED;
endColor = JBUI.CurrentTheme.ProgressBar.PASSED_END;

Check warning on line 103 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L102-L103

Added lines #L102 - L103 were not covered by tests
} else if (ProgressBarUtil.WARNING_VALUE.equals(statusProperty) || foreground == JBUI.CurrentTheme.ProgressBar.WARNING) {
startColor = JBUI.CurrentTheme.ProgressBar.WARNING;
endColor = JBUI.CurrentTheme.ProgressBar.WARNING_END;

Check warning on line 106 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L105-L106

Added lines #L105 - L106 were not covered by tests
} else {
startColor = progressBar.getClientProperty("ProgressBar.indeterminateStartColor") instanceof Color color ?
color : INDETERMINATE_START_COLOR;
color : JBUI.CurrentTheme.ProgressBar.INDETERMINATE_START;

Check warning on line 109 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L109

Added line #L109 was not covered by tests
endColor = progressBar.getClientProperty("ProgressBar.indeterminateEndColor") instanceof Color color ?
color : INDETERMINATE_END_COLOR;
color : JBUI.CurrentTheme.ProgressBar.INDETERMINATE_END;

Check warning on line 111 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L111

Added line #L111 was not covered by tests
}

Shape shape;
Expand Down Expand Up @@ -207,20 +183,19 @@
fullShape = getShapedRect(xOffset, r.y, pWidth, r.height, pWidth);
coloredShape = getShapedRect(xOffset, r.y, pWidth, amountFull, pWidth);
}
graphics2D.setColor(TRACK_COLOR);
graphics2D.setColor(JBUI.CurrentTheme.ProgressBar.TRACK);

Check warning on line 186 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L186

Added line #L186 was not covered by tests
graphics2D.fill(fullShape);

// Use foreground color as a reference, don't use it directly. This is done for compatibility reason.
// Colors are hardcoded in UI delegates by design. If more colors are needed contact designers.
Color foreground = progressBar.getForeground();
if (foreground == ColorProgressBar.RED) {
graphics2D.setColor(FAILED_COLOR);
} else if (foreground == ColorProgressBar.GREEN) {
graphics2D.setColor(PASSED_COLOR);
} else if (foreground == ColorProgressBar.YELLOW) {
graphics2D.setColor(WARNING_COLOR);
Object statusProperty = progressBar.getClientProperty(ProgressBarUtil.STATUS_KEY);

Check warning on line 190 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L190

Added line #L190 was not covered by tests
if (ProgressBarUtil.FAILED_VALUE.equals(statusProperty) || foreground == JBUI.CurrentTheme.ProgressBar.FAILED) {
graphics.setColor(JBUI.CurrentTheme.ProgressBar.FAILED);

Check warning on line 192 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L192

Added line #L192 was not covered by tests
} else if (ProgressBarUtil.PASSED_VALUE.equals(statusProperty) || foreground == JBUI.CurrentTheme.ProgressBar.PASSED) {
graphics.setColor(JBUI.CurrentTheme.ProgressBar.PASSED);

Check warning on line 194 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L194

Added line #L194 was not covered by tests
} else if (ProgressBarUtil.WARNING_VALUE.equals(statusProperty) || foreground == JBUI.CurrentTheme.ProgressBar.WARNING) {
graphics.setColor(JBUI.CurrentTheme.ProgressBar.WARNING);

Check warning on line 196 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L196

Added line #L196 was not covered by tests
} else {
graphics2D.setColor(PROGRESS_COLOR);
graphics2D.setColor(JBUI.CurrentTheme.ProgressBar.PROGRESS);

Check warning on line 198 in src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java#L198

Added line #L198 was not covered by tests
}
graphics2D.fill(coloredShape);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PedroIconsTest {

@ParameterizedTest
@ValueSource(floats = {0.75F, 1F, 1.1F, 1.25F, 1.5F, 1.75F, 2F, 3F})
void testScaling(float scaleFactor) {
void scaling(float scaleFactor) {
JBUIScale.setUserScaleFactorForTest(scaleFactor);

ImageIcon icon = PedroIcons.getScaledIcon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
class PedroProgressBarListenerTest {

@Test
void testUpdateProgressBar() {
void updateProgressBar() {
// defaults
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
class PedroProgressBarUITest {

@Test
void testCreateUI() {
void createUI() {
ComponentUI ui = PedroProgressBarUI.createUI(null);
assertInstanceOf(PedroProgressBarUI.class, ui);
}

@Test
void testGetBoxLength() {
void getBoxLength() {
PedroProgressBarUI progressBar = new PedroProgressBarUI();
assertEquals(0, progressBar.getBoxLength(0, 100));
}
Expand Down
Loading