Skip to content

Commit da57dbf

Browse files
feat: Add an icon for the GUI application (#1179)
* Test run of application icons. These icons are not final, but meant as a test of the packaging platform. * Try adding an in-app icon. * Actually add the image. * Add defensive null check. * Update Mac OS icon. * Add the application icon SVG source. * Add a helper script for Mac icon creation. * Update Windows icon + add conversion script. * Update Mac OS icon. * Update core icon with better background transparency. * Update Windows icon, including more intermediate resolutions in the ico file. * Support different resolution icons within the app JFrame. * Support JFrame app icon in multiple resolutions. * Fix typo. * Add README and script updates. * Java format. * Add the --win-console option back in. Co-authored-by: Brian Ferris <[email protected]>
1 parent cec914e commit da57dbf

File tree

12 files changed

+229
-2
lines changed

12 files changed

+229
-2
lines changed

app/gui/src/main/java/org/mobilitydata/gtfsvalidator/app/gui/GtfsValidatorApp.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
import java.awt.Font;
2424
import java.awt.GridBagConstraints;
2525
import java.awt.GridBagLayout;
26+
import java.awt.Image;
27+
import java.awt.Toolkit;
2628
import java.awt.event.MouseAdapter;
2729
import java.awt.event.MouseEvent;
2830
import java.io.File;
2931
import java.net.URI;
3032
import java.net.URISyntaxException;
33+
import java.net.URL;
3134
import java.nio.file.Path;
3235
import java.util.ArrayList;
36+
import java.util.Arrays;
3337
import java.util.List;
3438
import java.util.ResourceBundle;
3539
import javax.swing.BorderFactory;
@@ -134,6 +138,7 @@ public void showNewVersionAvailable() {
134138

135139
void constructUI() {
136140
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
141+
setApplicationIcon();
137142

138143
JPanel panel = new JPanel();
139144
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
@@ -155,6 +160,25 @@ void constructUI() {
155160
}
156161
}
157162

163+
private void setApplicationIcon() {
164+
Toolkit toolkit = Toolkit.getDefaultToolkit();
165+
List<String> iconFileNames =
166+
Arrays.asList("icon_16x16.png", "icon_32x32.png", "icon_48x48.png");
167+
List<Image> iconImages = new ArrayList<>();
168+
for (String iconFileName : iconFileNames) {
169+
URL resource = getClass().getResource(iconFileName);
170+
if (resource != null) {
171+
Image image = toolkit.createImage(resource);
172+
iconImages.add(image);
173+
} else {
174+
logger.atWarning().log("Icon image not found: %s", iconFileName);
175+
}
176+
}
177+
if (!iconImages.isEmpty()) {
178+
setIconImages(iconImages);
179+
}
180+
}
181+
158182
private void constructGtfsInputSection(JPanel parent) {
159183
// GTFS Input Section
160184
parent.add(createLabelWithFont(bundle.getString("gtfs_input"), BOLD_FONT));
980 Bytes
Loading
1.51 KB
Loading
2.61 KB
Loading

app/pkg/build.gradle

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import org.gradle.internal.os.OperatingSystem
18+
1719
plugins {
1820
id 'java'
1921
id "de.jjohannes.extra-java-module-info" version "0.11"
@@ -96,9 +98,16 @@ jlink {
9698
// Some platforms (e.g. Mac OS) need a pure x.y.z version number.
9799
// So strip any -SNAPSHOT suffix if present.
98100
appVersion = project.version.toString().replace('-SNAPSHOT', '')
99-
if (org.gradle.internal.os.OperatingSystem.current().windows) {
101+
if (OperatingSystem.current().isWindows()) {
100102
installerOptions += ['--win-per-user-install', '--win-dir-chooser', '--win-menu', '--win-shortcut']
101-
imageOptions += ['--win-console']
103+
imageOptions = [
104+
'--icon', "${projectDir}/src/main/icons/Icon.ico", '--win-console'
105+
]
106+
}
107+
if (OperatingSystem.current().isMacOsX()) {
108+
imageOptions = [
109+
'--icon', "${projectDir}/src/main/icons/Icon.icns"
110+
]
102111
}
103112
}
104113
}

app/pkg/src/main/icons/Icon.icns

223 KB
Binary file not shown.

app/pkg/src/main/icons/Icon.ico

112 KB
Binary file not shown.

app/pkg/src/main/icons/Icon.svg

Lines changed: 81 additions & 0 deletions
Loading

app/pkg/src/main/icons/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Updating Application Icons
2+
3+
The source file for all application icons is `Icon.svg`. This is used to create three
4+
platform-specific application icons:
5+
6+
* Windows: `Icon.ico`
7+
* Mac OS: `Icon.icns`
8+
* Java In-App
9+
10+
When updating the source icon, you can run the following three scripts to regenerate the
11+
relevant icon files from the SVG source:
12+
13+
* `svg2ico.sh`
14+
* `svg2icsn.sh`
15+
* `svg2jframe_icons.sh`

app/pkg/src/main/icons/svg2icns.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
#
3+
# Helper script for constructing a Mac OS icns icon bundle,
4+
# from an intermediate iconset file bundle. Requires install
5+
# of ImageMagik for `convert` command.
6+
7+
set -e
8+
9+
BASEDIR=$(dirname "$0")
10+
SVG=$BASEDIR/Icon.svg
11+
ICONSET_DIR=$BASEDIR/Icon.iconset
12+
13+
CONFIGS="
14+
icon_16x16.png,16x16
15+
16+
icon_32x32.png,32x32
17+
18+
icon_128x128.png,128x128
19+
20+
icon_256x256.png,256x256
21+
22+
icon_512x512.png,512x512
23+
24+
"
25+
26+
if [ -e $ICONSET_DIR ]; then
27+
rm -rf "$ICONSET_DIR"
28+
fi
29+
mkdir $ICONSET_DIR
30+
31+
for CONFIG in $CONFIGS; do
32+
FILENAME=$(echo $CONFIG | cut -d, -f1)
33+
SIZE=$(echo $CONFIG | cut -d, -f2)
34+
echo $FILENAME
35+
convert -density 1200 -background none -resize $SIZE $SVG $ICONSET_DIR/$FILENAME
36+
done
37+
38+
iconutil -c icns $ICONSET_DIR
39+
rm -rf "$ICONSET_DIR"

0 commit comments

Comments
 (0)