Feat: add link to discord and www on header

This commit is contained in:
Laurent Clouet
2025-08-21 11:59:50 +02:00
parent 65d290e2cd
commit 321af6ecb6
4 changed files with 59 additions and 7 deletions

View File

@@ -44,7 +44,11 @@ import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.GridBagLayout;
@@ -56,18 +60,23 @@ import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URL;
import java.util.Timer;
import java.util.TimerTask;
public class GuiSwing extends JFrame implements Gui {
public static final String type = "swing";
private static final String logoPath = "/sheepit-logo.png";
private static final String logoSheepItPath = "/sheepit-logo.png";
private static final String logoDiscordPath = "/discord-logo.png";
private static final String logoWebPath = "/web-logo.png";
public static final int WIDTH = 540;
public static void drawVersionStringOnImage(final BufferedImage image, String versionString) {
@@ -90,18 +99,20 @@ public class GuiSwing extends JFrame implements Gui {
}
@NotNull public static JLabel createLogoWithWatermark() {
final URL logoURL = GuiSwing.class.getResource(logoPath);
final URL logoSheepItURL = GuiSwing.class.getResource(logoSheepItPath);
final URL logoDiscordURL = GuiSwing.class.getResource(logoDiscordPath);
final URL logoWebURL = GuiSwing.class.getResource(logoWebPath);
// If logo cannot be found, return dummy image
if (logoURL == null) {
System.err.println("Error: Unable to find logo " + logoPath);
if (logoSheepItURL == null || logoDiscordURL == null || logoWebURL == null) {
System.err.println("Error: Unable to find logos");
return new JLabel();
}
JLabel labelImage;
try {
// Include the version of the app as a watermark in the SheepIt logo.
final BufferedImage watermark = ImageIO.read(logoURL);
final BufferedImage watermark = ImageIO.read(logoSheepItURL);
String versionString = "v" + Configuration.jarVersion;
drawVersionStringOnImage(watermark, versionString);
@@ -109,9 +120,50 @@ public class GuiSwing extends JFrame implements Gui {
}
catch (Exception e) {
// If something fails, we just show the SheepIt logo (without any watermark)
ImageIcon image = new ImageIcon(logoURL);
ImageIcon image = new ImageIcon(logoSheepItURL);
labelImage = new JLabel(image);
}
ImageIcon logoImageDiscord = new ImageIcon(logoDiscordURL);
ImageIcon logoImageWeb = new ImageIcon(logoWebURL);
labelImage.setLayout(new BorderLayout());
JPanel overlayPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 10));
overlayPanel.setOpaque(false);
JLabel logoLabelDiscord = new JLabel(logoImageDiscord);
logoLabelDiscord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
logoLabelDiscord.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
Desktop.getDesktop().browse(new URI("https://discord.gg/nZu9thzXfx"));
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
JLabel logoLabelWeb = new JLabel(logoImageWeb);
logoLabelWeb.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
logoLabelWeb.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
Desktop.getDesktop().browse(new URI("https://www.sheepit-renderfarm.com"));
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
overlayPanel.add(logoLabelWeb);
overlayPanel.add(logoLabelDiscord);
labelImage.add(overlayPanel, BorderLayout.SOUTH);
return labelImage;
}