Skip to content

Commit

Permalink
update avatar icon add icon arg
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ-Raven committed Dec 25, 2023
1 parent c5a4b3e commit 2d08f97
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/raven/swing/AvatarIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class AvatarIcon implements Icon {

private String filename;
private URL location;
private Icon icon;
private Image image;
private int round;
private int border;
Expand All @@ -39,6 +40,13 @@ public AvatarIcon(URL location, int width, int height, int round) {
this.round = round;
}

public AvatarIcon(Icon icon, int width, int height, int round) {
this.icon = icon;
this.width = width;
this.height = height;
this.round = round;
}

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
updateImage();
Expand All @@ -51,16 +59,18 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
}

private void updateImage() {
if ((filename != null || location != null) && (image == null || border != oldBorder)) {
if ((filename != null || location != null || icon != null) && (image == null || border != oldBorder)) {
imageWidth = UIScale.scale(width);
imageHeight = UIScale.scale(height);
oldBorder = border;
int b = UIScale.scale(border);
ImageIcon icon;
if (filename != null) {
icon = new ImageIcon(filename);
} else {
} else if (location != null) {
icon = new ImageIcon(location);
} else {
icon = (ImageIcon) this.icon;
}
image = resizeImage(icon.getImage(), imageWidth, imageHeight, b);
}
Expand Down

0 comments on commit 2d08f97

Please sign in to comment.