-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
23 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/com/devoxx/genie/ui/component/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.devoxx.genie.ui.component; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.border.AbstractBorder; | ||
import java.awt.*; | ||
import java.awt.geom.Area; | ||
import java.awt.geom.RoundRectangle2D; | ||
|
||
public class GlowingBorder extends AbstractBorder { | ||
private final Color glowColor; | ||
private final int glowWidth = 4; | ||
|
||
@Getter | ||
@Setter | ||
private float alpha = 0.5f; | ||
|
||
public GlowingBorder(Color glowColor) { | ||
this.glowColor = glowColor; | ||
} | ||
|
||
@Override | ||
public void paintBorder(Component c, @NotNull Graphics g, int x, int y, int width, int height) { | ||
Graphics2D g2 = (Graphics2D) g.create(); | ||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | ||
|
||
int arcWidth = 15; | ||
int arcHeight = 15; | ||
RoundRectangle2D.Float outer = new RoundRectangle2D.Float(x, y, width - 1, height - 1, arcWidth, arcHeight); | ||
RoundRectangle2D.Float inner = new RoundRectangle2D.Float(x + glowWidth, y + glowWidth, width - glowWidth * 2 - 1, height - glowWidth * 2 - 1, arcWidth, arcHeight); | ||
|
||
Area area = new Area(outer); | ||
area.subtract(new Area(inner)); | ||
|
||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); | ||
g2.setColor(glowColor); | ||
g2.fill(area); | ||
|
||
g2.dispose(); | ||
} | ||
|
||
@Override | ||
public Insets getBorderInsets(Component c) { | ||
return new Insets(glowWidth, glowWidth, glowWidth, glowWidth); | ||
} | ||
|
||
} |
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 Jul 02 13:43:13 CEST 2024 | ||
version=0.2.0 | ||
#Tue Jul 02 18:49:47 CEST 2024 | ||
version=0.2.1 |