Skip to content

Commit 2536d3d

Browse files
Use built-in constants for colors
See JetBrains/intellij-community@b71c278
1 parent d44a9f5 commit 2536d3d

File tree

8 files changed

+33
-61
lines changed

8 files changed

+33
-61
lines changed

.github/workflows/build.yml

-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ jobs:
4747
- name: Fetch Sources
4848
uses: actions/checkout@v4
4949

50-
# Validate wrapper
51-
- name: Gradle Wrapper Validation
52-
uses: gradle/actions/wrapper-validation@v4
53-
5450
# Set up Java environment for the next steps
5551
- name: Setup Java
5652
uses: actions/setup-java@v4

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Use color constants
10+
711
## [0.0.7] - 2024-09-23
812

913
### Added

build.gradle.kts

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ version = providers.gradleProperty("pluginVersion").get()
1616

1717
// Set the JVM language level used to build the project.
1818
kotlin {
19-
jvmToolchain(17)
19+
jvmToolchain(21)
2020
}
2121

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

47-
instrumentationTools()
48-
pluginVerifier()
49-
zipSigner()
5047
testFramework(TestFrameworkType.Platform)
5148
}
5249
}

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ pluginRepositoryUrl = https://github.com/strangelookingnerd/pedro-progress-bar-p
77
pluginVersion = 0.0.8
88

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

1313
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
1414
platformType = IC
15-
platformVersion = 2023.3.8
15+
platformVersion = 251.14649.49
1616

1717
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1818
# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP

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

+22-47
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
package com.github.strangelookingnerd;
2626

2727
import com.intellij.openapi.progress.util.ColorProgressBar;
28-
import com.intellij.ui.Gray;
29-
import com.intellij.ui.JBColor;
3028
import com.intellij.ui.scale.JBUIScale;
3129
import com.intellij.util.ui.JBInsets;
30+
import com.intellij.util.ui.JBUI;
3231
import com.intellij.util.ui.UIUtilities;
3332

3433
import javax.swing.ImageIcon;
@@ -57,28 +56,6 @@
5756
*/
5857
public class PedroProgressBarUI extends BasicProgressBarUI {
5958

60-
private static final Color TRACK_COLOR = JBColor.namedColor("ProgressBar.trackColor",
61-
new JBColor(Gray.xC4, Gray.x55));
62-
private static final Color PROGRESS_COLOR = JBColor.namedColor("ProgressBar.progressColor",
63-
new JBColor(Gray.x80, Gray.xA0));
64-
private static final Color INDETERMINATE_START_COLOR = JBColor.namedColor("ProgressBar.indeterminateStartColor",
65-
new JBColor(Gray.xC4, Gray.x69));
66-
private static final Color INDETERMINATE_END_COLOR = JBColor.namedColor("ProgressBar.indeterminateEndColor",
67-
new JBColor(Gray.x80, Gray.x83));
68-
69-
private static final Color FAILED_COLOR = JBColor.namedColor("ProgressBar.failedColor",
70-
new JBColor(0xd64f4f, 0xe74848));
71-
private static final Color FAILED_END_COLOR = JBColor.namedColor("ProgressBar.failedEndColor",
72-
new JBColor(0xfb8f89, 0xf4a2a0));
73-
private static final Color PASSED_COLOR = JBColor.namedColor("ProgressBar.passedColor",
74-
new JBColor(0x34b171, 0x008f50));
75-
private static final Color PASSED_END_COLOR = JBColor.namedColor("ProgressBar.passedEndColor",
76-
new JBColor(0x7ee8a5, 0x5dc48f));
77-
private static final Color WARNING_COLOR = JBColor.namedColor("ProgressBar.warningColor",
78-
new JBColor(0xF0A732, 0xD9A343));
79-
private static final Color WARNING_END_COLOR = JBColor.namedColor("ProgressBar.warningEndColor",
80-
new JBColor(0xEAD2A1, 0xEAD2A1));
81-
8259
private static final int CYCLE_TIME_DEFAULT = 800;
8360
private static final int REPAINT_INTERVAL_DEFAULT = 50;
8461

@@ -114,25 +91,24 @@ protected void paintIndeterminate(Graphics graphics, JComponent component) {
11491
JBInsets.removeFrom(r, i);
11592
int orientation = progressBar.getOrientation();
11693

117-
// Use foreground color as a reference, don't use it directly. This is done for compatibility reason.
118-
// Colors are hardcoded in UI delegates by design. If more colors are needed contact designers.
11994
Color startColor;
12095
Color endColor;
12196
Color foreground = progressBar.getForeground();
122-
if (foreground == ColorProgressBar.RED) {
123-
startColor = FAILED_COLOR;
124-
endColor = FAILED_END_COLOR;
125-
} else if (foreground == ColorProgressBar.GREEN) {
126-
startColor = PASSED_COLOR;
127-
endColor = PASSED_END_COLOR;
128-
} else if (foreground == ColorProgressBar.YELLOW) {
129-
startColor = WARNING_COLOR;
130-
endColor = WARNING_END_COLOR;
97+
Object statusProperty = progressBar.getClientProperty(JBUI.CurrentTheme.ProgressBar.statusKey());
98+
if (JBUI.CurrentTheme.ProgressBar.failedStatusValue().equals(statusProperty) || foreground == ColorProgressBar.RED) {
99+
startColor = JBUI.CurrentTheme.ProgressBar.FAILED;
100+
endColor = JBUI.CurrentTheme.ProgressBar.FAILED_END;
101+
} else if (JBUI.CurrentTheme.ProgressBar.passedStatusValue().equals(statusProperty) || foreground == ColorProgressBar.GREEN) {
102+
startColor = JBUI.CurrentTheme.ProgressBar.PASSED;
103+
endColor = JBUI.CurrentTheme.ProgressBar.PASSED_END;
104+
} else if (JBUI.CurrentTheme.ProgressBar.warningStatusValue().equals(statusProperty) || foreground == ColorProgressBar.YELLOW) {
105+
startColor = JBUI.CurrentTheme.ProgressBar.WARNING;
106+
endColor = JBUI.CurrentTheme.ProgressBar.WARNING_END;
131107
} else {
132108
startColor = progressBar.getClientProperty("ProgressBar.indeterminateStartColor") instanceof Color color ?
133-
color : INDETERMINATE_START_COLOR;
109+
color : JBUI.CurrentTheme.ProgressBar.INDETERMINATE_START;
134110
endColor = progressBar.getClientProperty("ProgressBar.indeterminateEndColor") instanceof Color color ?
135-
color : INDETERMINATE_END_COLOR;
111+
color : JBUI.CurrentTheme.ProgressBar.INDETERMINATE_END;
136112
}
137113

138114
Shape shape;
@@ -207,20 +183,19 @@ protected void paintDeterminate(Graphics graphics, JComponent component) {
207183
fullShape = getShapedRect(xOffset, r.y, pWidth, r.height, pWidth);
208184
coloredShape = getShapedRect(xOffset, r.y, pWidth, amountFull, pWidth);
209185
}
210-
graphics2D.setColor(TRACK_COLOR);
186+
graphics2D.setColor(JBUI.CurrentTheme.ProgressBar.TRACK);
211187
graphics2D.fill(fullShape);
212188

213-
// Use foreground color as a reference, don't use it directly. This is done for compatibility reason.
214-
// Colors are hardcoded in UI delegates by design. If more colors are needed contact designers.
215189
Color foreground = progressBar.getForeground();
216-
if (foreground == ColorProgressBar.RED) {
217-
graphics2D.setColor(FAILED_COLOR);
218-
} else if (foreground == ColorProgressBar.GREEN) {
219-
graphics2D.setColor(PASSED_COLOR);
220-
} else if (foreground == ColorProgressBar.YELLOW) {
221-
graphics2D.setColor(WARNING_COLOR);
190+
Object statusProperty = progressBar.getClientProperty(JBUI.CurrentTheme.ProgressBar.statusKey());
191+
if (JBUI.CurrentTheme.ProgressBar.failedStatusValue().equals(statusProperty) || foreground == ColorProgressBar.RED) {
192+
graphics.setColor(JBUI.CurrentTheme.ProgressBar.FAILED);
193+
} else if (JBUI.CurrentTheme.ProgressBar.passedStatusValue().equals(statusProperty) || foreground == ColorProgressBar.GREEN) {
194+
graphics.setColor(JBUI.CurrentTheme.ProgressBar.PASSED);
195+
} else if (JBUI.CurrentTheme.ProgressBar.warningStatusValue().equals(statusProperty) || foreground == ColorProgressBar.YELLOW) {
196+
graphics.setColor(JBUI.CurrentTheme.ProgressBar.WARNING);
222197
} else {
223-
graphics2D.setColor(PROGRESS_COLOR);
198+
graphics2D.setColor(JBUI.CurrentTheme.ProgressBar.PROGRESS);
224199
}
225200
graphics2D.fill(coloredShape);
226201

src/test/java/com/github/strangelookingnerd/PedroIconsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PedroIconsTest {
4343

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

4949
ImageIcon icon = PedroIcons.getScaledIcon();

src/test/java/com/github/strangelookingnerd/PedroProgressBarListenerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
class PedroProgressBarListenerTest {
4848

4949
@Test
50-
void testUpdateProgressBar() {
50+
void updateProgressBar() {
5151
// defaults
5252
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
5353
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));

src/test/java/com/github/strangelookingnerd/PedroProgressBarUITest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
class PedroProgressBarUITest {
3535

3636
@Test
37-
void testCreateUI() {
37+
void createUI() {
3838
ComponentUI ui = PedroProgressBarUI.createUI(null);
3939
assertInstanceOf(PedroProgressBarUI.class, ui);
4040
}
4141

4242
@Test
43-
void testGetBoxLength() {
43+
void getBoxLength() {
4444
PedroProgressBarUI progressBar = new PedroProgressBarUI();
4545
assertEquals(0, progressBar.getBoxLength(0, 100));
4646
}

0 commit comments

Comments
 (0)