-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from devoxx/feature-panel-glowing
Panel glowing
- Loading branch information
Showing
7 changed files
with
116 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/com/devoxx/genie/ui/component/border/AnimatedGlowingBorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.devoxx.genie.ui.component.border; | ||
|
||
import com.intellij.ui.JBColor; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.Border; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
|
||
public class AnimatedGlowingBorder implements Border { | ||
private final Timer glowTimer; | ||
private final GlowingBorder glowingBorder; | ||
private boolean isGlowing = false; | ||
private final JComponent component; | ||
private final Border defaultBorder; | ||
|
||
public AnimatedGlowingBorder(@NotNull JComponent component) { | ||
this.component = component; | ||
this.defaultBorder = BorderFactory.createEmptyBorder(4, 4, 4, 4); | ||
this.glowingBorder = new GlowingBorder(new JBColor(new Color(0, 120, 215), | ||
new Color(0, 120, 213))); | ||
this.glowTimer = createGlowTimer(); | ||
} | ||
|
||
private Timer createGlowTimer() { | ||
return new Timer(50, new ActionListener() { | ||
private float direction = 0.05f; | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
float alpha = glowingBorder.getAlpha(); | ||
alpha += direction; | ||
if (alpha > 1.0f) { | ||
alpha = 1.0f; | ||
direction = -0.05f; | ||
} else if (alpha < 0.3f) { | ||
alpha = 0.3f; | ||
direction = 0.05f; | ||
} | ||
glowingBorder.setAlpha(alpha); | ||
component.repaint(); | ||
} | ||
}); | ||
} | ||
|
||
public void startGlowing() { | ||
if (!isGlowing) { | ||
isGlowing = true; | ||
component.setBorder(glowingBorder); | ||
glowTimer.start(); | ||
} | ||
} | ||
|
||
public void stopGlowing() { | ||
if (isGlowing) { | ||
isGlowing = false; | ||
glowTimer.stop(); | ||
component.setBorder(defaultBorder); | ||
component.repaint(); | ||
} | ||
} | ||
|
||
@Override | ||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { | ||
if (isGlowing) { | ||
glowingBorder.paintBorder(c, g, x, y, width, height); | ||
} else { | ||
defaultBorder.paintBorder(c, g, x, y, width, height); | ||
} | ||
} | ||
|
||
@Override | ||
public Insets getBorderInsets(Component c) { | ||
return isGlowing ? glowingBorder.getBorderInsets(c) : defaultBorder.getBorderInsets(c); | ||
} | ||
|
||
@Override | ||
public boolean isBorderOpaque() { | ||
return false; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...oxx/genie/ui/component/GlowingBorder.java → ...ie/ui/component/border/GlowingBorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#Tue Dec 10 11:05:00 CET 2024 | ||
#Tue Dec 10 15:40:30 CET 2024 | ||
version=0.4.1 |