Include themes and fonts in OSX app package. Standardize loading

resource files
This commit is contained in:
bancika
2020-04-24 11:12:51 +02:00
parent bdf93b75e2
commit 49bc9cb8cc
9 changed files with 80 additions and 20 deletions
+1
View File
@@ -8,6 +8,7 @@
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/> <classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/> <classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/java-http-proxy.jar"/> <classpathentry kind="lib" path="lib/java-http-proxy.jar"/>
<classpathentry kind="lib" path="lib/AppleJavaExtensions.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
Binary file not shown.
@@ -3042,6 +3042,10 @@
<releaseDate>2020-04-20 00:00:00.000 CET</releaseDate> <releaseDate>2020-04-20 00:00:00.000 CET</releaseDate>
<name></name> <name></name>
<changes> <changes>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Include themes and fonts in OSX app package</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType> <changeType>BUG_FIX</changeType>
<description>Some boards (e.g. Breadboard) stop working at certain orientations</description> <description>Some boards (e.g. Breadboard) stop working at certain orientations</description>
@@ -0,0 +1,51 @@
/*
*
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
*
* This file is part of DIYLC.
*
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
package org.diylc.utils;
import java.io.File;
import org.apache.log4j.Logger;
public class ResourceLoader {
private static final Logger LOG = Logger.getLogger(ResourceLoader.class);
public static File[] getFiles(String relativePath) {
String bundlePath;
try {
bundlePath = com.apple.eio.FileManager.getPathToApplicationBundle();
LOG.debug("Detected OSX bundle path: " + bundlePath);
} catch (Exception e) {
bundlePath = null; // on non-OSX platforms
}
try {
String absolutePath;
if (bundlePath == null)
absolutePath = relativePath;
else
absolutePath = bundlePath + File.separator + "Contents" + File.separator + "Resources" + File.separator + relativePath;
LOG.debug("Looking for files in: " + absolutePath);
File absoluteFile = new File(absolutePath);
return absoluteFile.listFiles();
} catch (Exception e) {
LOG.error("Error while looking for files in: " + relativePath, e);
return null;
}
}
}
+3 -1
View File
@@ -125,6 +125,8 @@
</bundleapp> </bundleapp>
<zip destfile="${build.dir}/diylc-${diylc.version}-osx.zip"> <zip destfile="${build.dir}/diylc-${diylc.version}-osx.zip">
<zipfileset filemode="755" dir="${build.dir}/DIYLC.app" prefix="DIYLC.app" /> <zipfileset filemode="755" dir="${build.dir}/DIYLC.app" prefix="DIYLC.app" />
<zipfileset filemode="755" dir="${basedir}/themes" prefix="DIYLC.app/Contents/Resources/themes" />
<zipfileset filemode="755" dir="${basedir}/fonts" prefix="DIYLC.app/Contents/Resources/fonts" />
</zip> </zip>
</target> </target>
@@ -165,7 +167,7 @@
</zip> </zip>
</target> </target>
<target name="full" depends="win,mac,universal" /> <target name="full" depends="win,universal,mac" />
<target name="javadoc"> <target name="javadoc">
<javadoc access="public" author="true" classpathref="class.path" destdir="doc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" source="1.6" splitindex="true" use="true" version="true"> <javadoc access="public" author="true" classpathref="class.path" destdir="doc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" source="1.6" splitindex="true" use="true" version="true">
Binary file not shown.
Binary file not shown.
@@ -38,6 +38,7 @@ import org.diylc.presenter.Presenter;
import org.diylc.swing.gui.MainFrame; import org.diylc.swing.gui.MainFrame;
import org.diylc.swing.gui.TemplateDialog; import org.diylc.swing.gui.TemplateDialog;
import org.diylc.swingframework.FontChooserComboBox; import org.diylc.swingframework.FontChooserComboBox;
import org.diylc.utils.ResourceLoader;
/** /**
* Main class that runs DIYLC. * Main class that runs DIYLC.
@@ -98,22 +99,22 @@ public class DIYLCStarter {
public void run() { public void run() {
LOG.debug("Starting font pre-loading"); LOG.debug("Starting font pre-loading");
File dir = new File("fonts"); File[] fonts = ResourceLoader.getFiles("fonts");
File[] fonts = dir.listFiles();
for (int i = 0; i < fonts.length; i++) { if (fonts != null)
try { for (int i = 0; i < fonts.length; i++) {
LOG.info("Dynamically loading font: " + fonts[i].getName()); try {
Font customFont = Font.createFont(Font.TRUETYPE_FONT, new File(fonts[i].getAbsolutePath())).deriveFont(12f); LOG.info("Dynamically loading font: " + fonts[i].getName());
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font customFont = Font.createFont(Font.TRUETYPE_FONT, new File(fonts[i].getAbsolutePath())).deriveFont(12f);
// register the font GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(customFont); // register the font
} catch (IOException e) { ge.registerFont(customFont);
LOG.error("Could not load font", e); } catch (IOException e) {
} catch (FontFormatException e) { LOG.error("Could not load font", e);
LOG.error("Font format error", e); } catch (FontFormatException e) {
LOG.error("Font format error", e);
}
} }
}
FontChooserComboBox box = new FontChooserComboBox(); FontChooserComboBox box = new FontChooserComboBox();
box.getPreferredSize(); box.getPreferredSize();
@@ -31,6 +31,7 @@ import org.diylc.core.Theme;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.diylc.swing.ActionFactory; import org.diylc.swing.ActionFactory;
import org.diylc.swing.ISwingUI; import org.diylc.swing.ISwingUI;
import org.diylc.utils.ResourceLoader;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver; import com.thoughtworks.xstream.io.xml.DomDriver;
@@ -133,11 +134,11 @@ public class ConfigPlugin implements IPlugIn {
ActionFactory.getInstance() ActionFactory.getInstance()
.createConfigAction(plugInPort, "Sticky Points", IPlugInPort.STICKY_POINTS_KEY, true), CONFIG_MENU); .createConfigAction(plugInPort, "Sticky Points", IPlugInPort.STICKY_POINTS_KEY, true), CONFIG_MENU);
File themeDir = new File("themes"); File[] themeFiles = ResourceLoader.getFiles("themes");
if (themeDir.exists()) { if (themeFiles != null && themeFiles.length > 0) {
XStream xStream = new XStream(new DomDriver()); XStream xStream = new XStream(new DomDriver());
swingUI.injectSubmenu(THEME_MENU, IconLoader.Pens.getIcon(), CONFIG_MENU); swingUI.injectSubmenu(THEME_MENU, IconLoader.Pens.getIcon(), CONFIG_MENU);
for (File file : themeDir.listFiles()) { for (File file : themeFiles) {
if (file.getName().toLowerCase().endsWith(".xml")) { if (file.getName().toLowerCase().endsWith(".xml")) {
try { try {
InputStream in = new FileInputStream(file); InputStream in = new FileInputStream(file);