diff --git a/CHANGELOG.md b/CHANGELOG.md index 22223e1..f13cfa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ # Pedro Progress Bar Changelog ## [Unreleased] +### Added +- Do not use deprecated `UIUtil.isUnderWin10LookAndFeel()` +- Plugin description cleanup - Various dependency updates ## [0.0.2] diff --git a/src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java b/src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java index ae290d5..236c7e6 100644 --- a/src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java +++ b/src/main/java/com/github/strangelookingnerd/PedroProgressBarUI.java @@ -29,7 +29,6 @@ import com.intellij.ui.JBColor; import com.intellij.ui.scale.JBUIScale; import com.intellij.util.ui.JBInsets; -import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.UIUtilities; import javax.swing.ImageIcon; @@ -260,9 +259,9 @@ protected int getBoxLength(int availableLength, int otherDimension) { } private Shape getShapedRect(float x, float y, float w, float h, float ar) { - boolean flatEnds = UIUtil.isUnderWin10LookAndFeel() || progressBar.getClientProperty( - "ProgressBar.flatEnds") == Boolean.TRUE; - return flatEnds ? new Rectangle2D.Float(x, y, w, h) : new RoundRectangle2D.Float(x, y, w, h, ar, ar); + return progressBar.getClientProperty("ProgressBar.flatEnds") == Boolean.TRUE + ? new Rectangle2D.Float(x, y, w, h) + : new RoundRectangle2D.Float(x, y, w, h, ar, ar); } private int getStripeWidth() { diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index d96fd37..cdf24c5 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,8 +1,8 @@ - + com.github.strangelookingnerd.pedro-progress-bar Pedro Progress Bar - strangelookingnerd + strangelookingnerd User Interface com.intellij.modules.platform diff --git a/src/test/java/com/github/strangelookingnerd/PedroProgressBarListenerTest.java b/src/test/java/com/github/strangelookingnerd/PedroProgressBarListenerTest.java new file mode 100644 index 0000000..f1e64b8 --- /dev/null +++ b/src/test/java/com/github/strangelookingnerd/PedroProgressBarListenerTest.java @@ -0,0 +1,113 @@ +/* + * The MIT License + * + * Copyright (c) 2024 strangelookingnerd + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.github.strangelookingnerd; + +import com.intellij.ide.ui.laf.LafManagerImpl; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.IdeFrame; +import com.intellij.openapi.wm.StatusBar; +import com.intellij.ui.BalloonLayout; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.Test; + +import javax.swing.JComponent; +import javax.swing.UIManager; +import javax.swing.plaf.metal.MetalProgressBarUI; +import java.awt.Rectangle; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +class PedroProgressBarListenerTest { + + @Test + void testUpdateProgressBar() { + // defaults + assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI")); + assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName())); + + // ctor. + PedroProgressBarListener listener = new PedroProgressBarListener(); + assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI")); + assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName())); + + // reset + UIManager.put("ProgressBarUI", null); + UIManager.getDefaults().remove(PedroProgressBarUI.class.getName()); + assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI")); + assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName())); + + // applicationActivated + listener.applicationActivated(new TestFrame()); + assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI")); + assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName())); + + // reset + UIManager.put("ProgressBarUI", null); + UIManager.getDefaults().remove(PedroProgressBarUI.class.getName()); + assertEquals(MetalProgressBarUI.class.getName(), UIManager.get("ProgressBarUI")); + assertNull(UIManager.getDefaults().get(PedroProgressBarUI.class.getName())); + + // lookAndFeelChanged + listener.lookAndFeelChanged(new LafManagerImpl()); + assertEquals(PedroProgressBarUI.class.getName(), UIManager.get("ProgressBarUI")); + assertEquals(PedroProgressBarUI.class, UIManager.getDefaults().get(PedroProgressBarUI.class.getName())); + } + + private static class TestFrame implements IdeFrame { + + @Override + public @Nullable StatusBar getStatusBar() { + return null; + } + + @Override + public @NotNull Rectangle suggestChildFrameBounds() { + return new Rectangle(0, 0, 100, 100); + } + + @Override + public @Nullable Project getProject() { + return null; + } + + @Override + public void setFrameTitle(String title) { + // NOP + } + + @Override + public JComponent getComponent() { + return null; + } + + @Override + public @Nullable BalloonLayout getBalloonLayout() { + return null; + } + } + +} \ No newline at end of file diff --git a/src/test/java/com/github/strangelookingnerd/PedroProgressBarUITest.java b/src/test/java/com/github/strangelookingnerd/PedroProgressBarUITest.java new file mode 100644 index 0000000..5cae417 --- /dev/null +++ b/src/test/java/com/github/strangelookingnerd/PedroProgressBarUITest.java @@ -0,0 +1,48 @@ +/* + * The MIT License + * + * Copyright (c) 2024 strangelookingnerd + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.github.strangelookingnerd; + +import org.junit.jupiter.api.Test; + +import javax.swing.plaf.ComponentUI; + +import static com.intellij.testFramework.UsefulTestCase.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PedroProgressBarUITest { + + @Test + void testCreateUI() { + ComponentUI ui = PedroProgressBarUI.createUI(null); + assertInstanceOf(ui, PedroProgressBarUI.class); + } + + @Test + void testGetBoxLength() { + PedroProgressBarUI progressBar = new PedroProgressBarUI(); + assertEquals(0, progressBar.getBoxLength(0, 100)); + } + +} \ No newline at end of file