Skip to content

Commit 5df3b69

Browse files
Merge pull request #13 from strangelookingnerd/tests_and_cleanup
Tests and cleanup
2 parents 038d6d8 + 1a13231 commit 5df3b69

File tree

5 files changed

+169
-6
lines changed

5 files changed

+169
-6
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Pedro Progress Bar Changelog
33

44
## [Unreleased]
5+
### Added
6+
- Do not use deprecated `UIUtil.isUnderWin10LookAndFeel()`
7+
- Plugin description cleanup
58
- Various dependency updates
69

710
## [0.0.2]

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.intellij.ui.JBColor;
3030
import com.intellij.ui.scale.JBUIScale;
3131
import com.intellij.util.ui.JBInsets;
32-
import com.intellij.util.ui.UIUtil;
3332
import com.intellij.util.ui.UIUtilities;
3433

3534
import javax.swing.ImageIcon;
@@ -260,9 +259,9 @@ protected int getBoxLength(int availableLength, int otherDimension) {
260259
}
261260

262261
private Shape getShapedRect(float x, float y, float w, float h, float ar) {
263-
boolean flatEnds = UIUtil.isUnderWin10LookAndFeel() || progressBar.getClientProperty(
264-
"ProgressBar.flatEnds") == Boolean.TRUE;
265-
return flatEnds ? new Rectangle2D.Float(x, y, w, h) : new RoundRectangle2D.Float(x, y, w, h, ar, ar);
262+
return progressBar.getClientProperty("ProgressBar.flatEnds") == Boolean.TRUE
263+
? new Rectangle2D.Float(x, y, w, h)
264+
: new RoundRectangle2D.Float(x, y, w, h, ar, ar);
266265
}
267266

268267
private int getStripeWidth() {

src/main/resources/META-INF/plugin.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
2-
<idea-plugin>
2+
<idea-plugin url="https://github.com/strangelookingnerd/pedro-progress-bar-plugin">
33
<id>com.github.strangelookingnerd.pedro-progress-bar</id>
44
<name>Pedro Progress Bar</name>
5-
<vendor>strangelookingnerd</vendor>
5+
<vendor url="https://strangelookingnerd.github.io">strangelookingnerd</vendor>
66
<category>User Interface</category>
77

88
<depends>com.intellij.modules.platform</depends>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2024 strangelookingnerd
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package com.github.strangelookingnerd;
26+
27+
import com.intellij.ide.ui.laf.LafManagerImpl;
28+
import com.intellij.openapi.project.Project;
29+
import com.intellij.openapi.wm.IdeFrame;
30+
import com.intellij.openapi.wm.StatusBar;
31+
import com.intellij.ui.BalloonLayout;
32+
import org.jetbrains.annotations.NotNull;
33+
import org.jetbrains.annotations.Nullable;
34+
import org.junit.jupiter.api.Test;
35+
36+
import javax.swing.JComponent;
37+
import javax.swing.UIManager;
38+
import javax.swing.plaf.metal.MetalProgressBarUI;
39+
import java.awt.Rectangle;
40+
41+
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
import static org.junit.jupiter.api.Assertions.assertNull;
43+
44+
class PedroProgressBarListenerTest {
45+
46+
@Test
47+
void testUpdateProgressBar() {
48+
// defaults
49+
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
50+
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
51+
52+
// ctor.
53+
PedroProgressBarListener listener = new PedroProgressBarListener();
54+
assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
55+
assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
56+
57+
// reset
58+
UIManager.put("ProgressBarUI", null);
59+
UIManager.getDefaults().remove(PedroProgressBarUI.class.getName());
60+
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
61+
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
62+
63+
// applicationActivated
64+
listener.applicationActivated(new TestFrame());
65+
assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
66+
assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
67+
68+
// reset
69+
UIManager.put("ProgressBarUI", null);
70+
UIManager.getDefaults().remove(PedroProgressBarUI.class.getName());
71+
assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
72+
assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
73+
74+
// lookAndFeelChanged
75+
listener.lookAndFeelChanged(new LafManagerImpl());
76+
assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI"));
77+
assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName()));
78+
}
79+
80+
private static class TestFrame implements IdeFrame {
81+
82+
@Override
83+
public @Nullable StatusBar getStatusBar() {
84+
return null;
85+
}
86+
87+
@Override
88+
public @NotNull Rectangle suggestChildFrameBounds() {
89+
return new Rectangle(0, 0, 100, 100);
90+
}
91+
92+
@Override
93+
public @Nullable Project getProject() {
94+
return null;
95+
}
96+
97+
@Override
98+
public void setFrameTitle(String title) {
99+
// NOP
100+
}
101+
102+
@Override
103+
public JComponent getComponent() {
104+
return null;
105+
}
106+
107+
@Override
108+
public @Nullable BalloonLayout getBalloonLayout() {
109+
return null;
110+
}
111+
}
112+
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2024 strangelookingnerd
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package com.github.strangelookingnerd;
26+
27+
import org.junit.jupiter.api.Test;
28+
29+
import javax.swing.plaf.ComponentUI;
30+
31+
import static com.intellij.testFramework.UsefulTestCase.assertInstanceOf;
32+
import static org.junit.jupiter.api.Assertions.assertEquals;
33+
34+
class PedroProgressBarUITest {
35+
36+
@Test
37+
void testCreateUI() {
38+
ComponentUI ui = PedroProgressBarUI.createUI(null);
39+
assertInstanceOf(ui, PedroProgressBarUI.class);
40+
}
41+
42+
@Test
43+
void testGetBoxLength() {
44+
PedroProgressBarUI progressBar = new PedroProgressBarUI();
45+
assertEquals(0, progressBar.getBoxLength(0, 100));
46+
}
47+
48+
}

0 commit comments

Comments
 (0)