Skip to content

Commit

Permalink
Set TaskBar icon is available
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Apr 21, 2021
1 parent 4c04b91 commit b455522
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ lib/**/*.dylib
lib/**/*.so
trufflesqueak*.zip
trufflesqueak*.jar
/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/trufflesqueak-icon.png
2 changes: 2 additions & 0 deletions mx.trufflesqueak/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"version": "21.1.0",
"trufflesqueak:dependencyMap": {
"graalvm": "21.0.0",
"icon": "trufflesqueak-icon.png",
"icon_tag": "21.0.0.1",
"image": "TruffleSqueakImage-21.1.0-dev.zip",
"image_tag": "21.0.0.1",
"jdk8": "282",
Expand Down
13 changes: 13 additions & 0 deletions mx.trufflesqueak/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ download-asset() {
"https://github.com/${GITHUB_SLUG}/releases/download/${git_tag}/${filename}"
}

download-trufflesqueak-icon() {
local target="${BASE_DIRECTORY}/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/trufflesqueak-icon.png"

if ls -1 ${target} 2>/dev/null; then
echo "[TruffleSqueak icon already downloaded]"
return
fi

download-asset "${DEP_ICON}" "${DEP_ICON_TAG}" "${target}"
echo "[TruffleSqueak icon downloaded successfully]"
}

download-trufflesqueak-image() {
local target_dir="${BASE_DIRECTORY}/src/resources"

Expand Down Expand Up @@ -203,6 +215,7 @@ set-up-dependencies() {
shallow-clone-graalvm-project https://github.com/graalvm/graaljs.git
download-trufflesqueak-image
download-trufflesqueak-test-image
download-trufflesqueak-icon

if [[ "${java_version}" == "java8" ]]; then
set-up-openjdk8-jvmci "${HOME}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
Expand All @@ -29,6 +30,8 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayDeque;
import java.util.List;

Expand Down Expand Up @@ -56,6 +59,7 @@ public final class SqueakDisplay implements SqueakDisplayInterface {
private static final String DEFAULT_WINDOW_TITLE = "TruffleSqueak";
private static final Dimension MINIMUM_WINDOW_SIZE = new Dimension(200, 150);
private static final Toolkit TOOLKIT = Toolkit.getDefaultToolkit();
private static final URL ICON_URL = SqueakDisplay.class.getResource("trufflesqueak-icon.png");
@CompilationFinal(dimensions = 1) private static final int[] CURSOR_COLORS = new int[]{0x00000000, 0xFF0000FF, 0xFFFFFFFF, 0xFF000000};

public final SqueakImageContext image;
Expand All @@ -72,6 +76,10 @@ public final class SqueakDisplay implements SqueakDisplayInterface {
private Point rememberedWindowLocation;
private boolean deferUpdates;

static {
tryToSetTaskbarIcon();
}

public SqueakDisplay(final SqueakImageContext image) {
this.image = image;
frame.add(canvas);
Expand All @@ -83,6 +91,21 @@ public SqueakDisplay(final SqueakImageContext image) {
installEventListeners();
}

@TruffleBoundary
private static void tryToSetTaskbarIcon() {
// java.awt.Taskbar introduced in JDK 9, call it reflectively.
try {
final Image icon = TOOLKIT.getImage(ICON_URL);
final Class<?> tbClass = Class.forName("java.awt.Taskbar");
final Method getter = tbClass.getMethod("getTaskbar");
final Object tb = getter.invoke(getter);
final Method setter = tb.getClass().getMethod("setIconImage", Image.class);
setter.invoke(tb, icon);
} catch (final Exception e) {
// Ignore
}
}

@SuppressWarnings("unused")
private void installEventListeners() {
canvas.addMouseListener(mouse);
Expand Down

0 comments on commit b455522

Please sign in to comment.