Draw version string correctly on the watermark
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sheepit.client.standalone.swing.activity;
|
package com.sheepit.client.standalone.swing.activity;
|
||||||
|
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
@@ -138,11 +139,8 @@ public class Settings implements Activity {
|
|||||||
try {
|
try {
|
||||||
// Include the version of the app as a watermark in the SheepIt logo.
|
// Include the version of the app as a watermark in the SheepIt logo.
|
||||||
final BufferedImage watermark = ImageIO.read(getClass().getResource("/sheepit-logo.png"));
|
final BufferedImage watermark = ImageIO.read(getClass().getResource("/sheepit-logo.png"));
|
||||||
|
String versionString = "v" + Configuration.jarVersion;
|
||||||
Graphics gph = watermark.getGraphics();
|
drawVersionStringOnImage(watermark, versionString);
|
||||||
gph.setFont(gph.getFont().deriveFont(12f));
|
|
||||||
gph.drawString("v" + Configuration.jarVersion, 335, 120);
|
|
||||||
gph.dispose();
|
|
||||||
|
|
||||||
labelImage = new JLabel(new ImageIcon(watermark));
|
labelImage = new JLabel(new ImageIcon(watermark));
|
||||||
}
|
}
|
||||||
@@ -560,6 +558,23 @@ public class Settings implements Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawVersionStringOnImage(final BufferedImage image, String versionString) {
|
||||||
|
var watermarkWidth = image.getWidth();
|
||||||
|
var watermarkHeight = image.getHeight();
|
||||||
|
|
||||||
|
Graphics gph = image.getGraphics();
|
||||||
|
gph.setFont(gph.getFont().deriveFont(12f));
|
||||||
|
|
||||||
|
FontMetrics fontMetrics = gph.getFontMetrics();
|
||||||
|
// move text to the very right of the image respecting its length
|
||||||
|
int x = watermarkWidth - fontMetrics.stringWidth(versionString);
|
||||||
|
// the bottom of the image, but give enough headroom for descending letters like g
|
||||||
|
int y = watermarkHeight - fontMetrics.getMaxDescent();
|
||||||
|
|
||||||
|
gph.drawString(versionString, x, y);
|
||||||
|
gph.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
public void resizeWindow() {}
|
public void resizeWindow() {}
|
||||||
|
|
||||||
public boolean checkDisplaySaveButton() {
|
public boolean checkDisplaySaveButton() {
|
||||||
|
|||||||
Reference in New Issue
Block a user