summaryrefslogtreecommitdiff
path: root/BKUApplet/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-11-05 19:05:14 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2009-11-05 19:05:14 +0000
commit83e8c95ea7d257166d350a59bfd81e9833ec14fd (patch)
tree1d989268e21e0ea2de24be718f40e5e86df74bbd /BKUApplet/src/main/java/at/gv/egiz
parent9f66f6cc09fd4d010b270d8a83b204728b9336e1 (diff)
downloadmocca-83e8c95ea7d257166d350a59bfd81e9833ec14fd.tar.gz
mocca-83e8c95ea7d257166d350a59bfd81e9833ec14fd.tar.bz2
mocca-83e8c95ea7d257166d350a59bfd81e9833ec14fd.zip
[#484] European Language support
git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@535 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'BKUApplet/src/main/java/at/gv/egiz')
-rw-r--r--BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java572
-rw-r--r--BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java82
2 files changed, 369 insertions, 285 deletions
diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java
index 6346b7f4..7a15f7a5 100644
--- a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java
+++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/BKUApplet.java
@@ -16,6 +16,7 @@
*/
package at.gv.egiz.bku.online.applet;
+import at.gv.egiz.bku.online.applet.viewer.URLFontLoader;
import at.gv.egiz.bku.gui.BKUGUIFacade.Style;
import at.gv.egiz.bku.gui.DefaultHelpListener;
import at.gv.egiz.bku.gui.AbstractHelpListener;
@@ -25,6 +26,8 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.net.ssl.HttpsURLConnection;
import javax.swing.JApplet;
import javax.swing.JPanel;
@@ -34,6 +37,7 @@ import org.apache.commons.logging.LogFactory;
import at.gv.egiz.bku.gui.BKUGUIFacade;
import at.gv.egiz.bku.gui.BKUGUIImpl;
+import at.gv.egiz.bku.gui.viewer.FontProvider;
import at.gv.egiz.stal.service.STALPortType;
import at.gv.egiz.stal.service.STALService;
import java.applet.AppletContext;
@@ -46,289 +50,287 @@ import javax.xml.namespace.QName;
* Note: all swing code is executed by the event dispatch thread (see
* BKUGUIFacade)
*/
-public class BKUApplet extends JApplet {
-
- private static final long serialVersionUID = 1L;
-
- private static Log log = LogFactory.getLog(BKUApplet.class);
- /**
- * Applet parameter keys
- */
- public static final String GUI_STYLE = "GuiStyle";
- public final static String LOCALE = "Locale";
- public final static String WSDL_URL = "WSDL_URL";
- public static final String HASHDATA_DISPLAY = "HashDataDisplay";
- public final static String HASHDATA_URL = "HashDataURL";
- public final static String HELP_URL = "HelpURL";
- public final static String SESSION_ID = "SessionID";
- public static final String BACKGROUND_IMG = "Background";
- public static final String BACKGROUND_COLOR = "BackgroundColor";
- public static final String REDIRECT_URL = "RedirectURL";
- public static final String REDIRECT_TARGET = "RedirectTarget";
- public static final String HASHDATA_DISPLAY_FRAME = "frame";
- /**
- * STAL WSDL namespace and service name
- */
- public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal";
- public static final String STAL_SERVICE = "STALService";
- /**
- * Dummy session id, used if no sessionId parameter is provided
- */
- protected static final String TEST_SESSION_ID = "TestSession";
-
- static {
- if (log.isTraceEnabled()) {
- log.trace("enabling webservice communication dump");
- System
- .setProperty(
- "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump",
- "true");
- }
- }
-
- /**
- * STAL
- */
- protected AppletBKUWorker worker;
- protected Thread workerThread;
-
- /*
- * (non-Javadoc)
- *
- * @see java.applet.Applet#getParameterInfo()
- */
- @Override
- public String[][] getParameterInfo() {
- return new String[][] {
- { WSDL_URL, "url",
- "URL of the WSDL of the MOCCA server side STAL" },
- { REDIRECT_URL, "url",
- "URL to redirect the browser to when finished" },
- { REDIRECT_TARGET, "frame target",
- "name of the target frame for redirection when finished" },
- { LOCALE, "locale",
- "locale for UI localization (optional, default: system default)" },
- { GUI_STYLE, "simple, advanced, tiny",
- "GUI style (optional, default: simple)" },
- { BACKGROUND_COLOR, "#hhhhhh",
- "background color, e.g. '#333333' (optional, default: look and feel dependend)" },
- { BACKGROUND_IMG, "url",
- "URL of a background image for the GUI (optional, default: no image)" },
- { HELP_URL, "url",
- "URL for locating help files, e.g. '../help/' (no help provided if missing)" } };
- }
-
- /**
- * Factory method to create and wire HelpListener, GUI and BKUWorker.
- * (Config via applet parameters, see BKUApplet.* constants)
- */
- @Override
- public void init() {
- log.info("Welcome to MOCCA");
- log.trace("Called init()");
-
- HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory
- .getInstance());
-
- String locale = getParameter(LOCALE);
- if (locale != null) {
- this.setLocale(new Locale(locale));
- }
- log.trace("default locale: " + Locale.getDefault());
- log.debug("setting locale: " + getLocale());
-
- BKUGUIFacade.Style guiStyle;
- String guiStyleParam = getParameter(GUI_STYLE);
- if ("advanced".equals(guiStyleParam)) {
- guiStyle = BKUGUIFacade.Style.advanced;
- } else if ("tiny".equals(guiStyleParam)) {
- guiStyle = BKUGUIFacade.Style.tiny;
- } else {
- guiStyle = BKUGUIFacade.Style.simple;
- }
- log.debug("setting gui-style: " + guiStyle);
-
- URL backgroundImgURL = null;
- try {
- backgroundImgURL = getURLParameter(BACKGROUND_IMG, null);
- log.debug("setting background: " + backgroundImgURL);
- } catch (MalformedURLException ex) {
- log.warn("cannot load applet background image: " + ex.getMessage());
- }
-
- AbstractHelpListener helpListener = null;
- try {
- helpListener = new DefaultHelpListener(getAppletContext(),
- getURLParameter(HELP_URL, null), getLocale());
- if (log.isDebugEnabled()) {
- log
- .debug("setting helpURL: "
- + getURLParameter(HELP_URL, null));
- }
- } catch (MalformedURLException ex) {
- log.warn("failed to load help URL: " + ex.getMessage()
- + ", disabling help");
- }
-
- SwitchFocusListener switchFocusListener = new SwitchFocusListener(
- getAppletContext(), "focusToBrowser()");
-
- // Note: We need a panel in order to be able to set the background
- // properly.
- // Setting the background without a panel has side effects with the
- // different java plugins.
- JPanel contentPanel = new JPanel();
- getContentPane().add(contentPanel);
-
- String backgroundColor = getParameter(BACKGROUND_COLOR);
- if (backgroundColor != null && backgroundColor.startsWith("#")) {
- try {
- Color color = new Color(Integer.parseInt(backgroundColor
- .substring(1), 16));
- log.debug("setting background color to " + color);
- contentPanel.setBackground(color);
- } catch (NumberFormatException e) {
- log.debug("failed to set background color '" + backgroundColor
- + "'");
- }
- }
-
- BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle,
- backgroundImgURL, helpListener, switchFocusListener);
-
- worker = createBKUWorker(this, gui);
- }
-
- @Override
- public void start() {
- log.trace("Called start()");
- workerThread = new Thread(worker);
- workerThread.start();
- }
-
- @Override
- public void stop() {
- log.trace("Called stop()");
- if ((workerThread != null) && (workerThread.isAlive())) {
- workerThread.interrupt();
- }
- }
-
- @Override
- public void destroy() {
- log.trace("Called destroy()");
- }
-
- // ///////////////////////////////////////////////////////////////////////////
- // factory methods for subclasses to inject different components
- // ///////////////////////////////////////////////////////////////////////////
-
- protected BKUGUIFacade createGUI(Container contentPane, Locale locale,
- Style guiStyle, URL backgroundImgURL,
- AbstractHelpListener helpListener,
- SwitchFocusListener switchFocusListener) {
- return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL,
- helpListener, switchFocusListener);
- }
-
- protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) {
- return new AppletBKUWorker(applet, gui);
- }
-
- // ///////////////////////////////////////////////////////////////////////////
- // callback for BKUWorker to allow extension
- // ///////////////////////////////////////////////////////////////////////////
-
- /**
- * Callback for BKUWorker to allow extension
- *
- * @return
- * @throws java.net.MalformedURLException
- */
- public STALPortType getSTALPort() throws MalformedURLException {
- URL wsdlURL = getURLParameter(WSDL_URL, null);
- log.debug("setting STAL WSDL: " + wsdlURL);
- QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE);
- STALService stal = new STALService(wsdlURL, endpointName);
- return stal.getSTALPort();
- }
-
- /**
- * Callback for BKUWorker to allow extension (TODO STALPort could know its
- * STALTranslator)
- *
- * @return
- * @throws java.net.MalformedURLException
- */
- public STALTranslator getSTALTranslator() {
- return new STALTranslator();
- }
-
- /**
- * Callback for BKUWorker to keep applet context out of BKUWorker
- *
- * @return
- * @throws java.net.MalformedURLException
- */
- protected void sendRedirect(String sessionId) {
- try {
- AppletContext ctx = getAppletContext();
- if (ctx == null) {
- log
- .error("no applet context (applet might already have been destroyed)");
- return;
- }
- URL redirectURL = getURLParameter(REDIRECT_URL, sessionId);
- String redirectTarget = getParameter(REDIRECT_TARGET);
- if (redirectTarget == null) {
- log.info("Done. Redirecting to " + redirectURL + " ...");
- ctx.showDocument(redirectURL);
- } else {
- log.info("Done. Redirecting to " + redirectURL + " (target="
- + redirectTarget + ") ...");
- ctx.showDocument(redirectURL, redirectTarget);
- }
- } catch (MalformedURLException ex) {
- log.warn("Failed to redirect: " + ex.getMessage(), ex);
- // gui.showErrorDialog(errorMsg, okListener, actionCommand)
- }
- }
-
- public void getFocusFromBrowser() {
-
- worker.getFocusFromBrowser();
- }
-
- // ///////////////////////////////////////////////////////////////////////////
- // utility methods
- // ///////////////////////////////////////////////////////////////////////////
-
- protected URL getURLParameter(String paramKey, String sessionId)
- throws MalformedURLException {
- String urlParam = getParameter(paramKey);
- if (urlParam != null && !"".equals(urlParam)) {
- URL codebase = getCodeBase();
- try {
- URL url;
- if (codebase.getProtocol().equalsIgnoreCase("file")) {
- // for debugging in appletrunner
- url = new URL(urlParam);
- } else {
- if (sessionId != null) {
- urlParam = urlParam + ";jsessionid=" + sessionId;
- }
- url = new URL(codebase, urlParam);
- }
- return url;
- } catch (MalformedURLException ex) {
- log.error("applet paremeter " + urlParam
- + " is not a valid URL: " + ex.getMessage());
- throw ex;
- }
- } else {
- log.error("applet paremeter " + paramKey + " not set");
- throw new MalformedURLException(paramKey + " not set");
- }
- }
-
+public class BKUApplet extends JApplet {
+
+ private static final long serialVersionUID = 1L;
+ private static Log log = LogFactory.getLog(BKUApplet.class);
+ /**
+ * Applet parameter keys
+ */
+ public static final String GUI_STYLE = "GuiStyle";
+ public final static String LOCALE = "Locale";
+ public final static String WSDL_URL = "WSDL_URL";
+ public static final String HASHDATA_DISPLAY = "HashDataDisplay";
+ public final static String HASHDATA_URL = "HashDataURL";
+ public final static String HELP_URL = "HelpURL";
+ public final static String SESSION_ID = "SessionID";
+ public static final String BACKGROUND_IMG = "Background";
+ public static final String BACKGROUND_COLOR = "BackgroundColor";
+ public static final String REDIRECT_URL = "RedirectURL";
+ public static final String REDIRECT_TARGET = "RedirectTarget";
+ public static final String HASHDATA_DISPLAY_FRAME = "frame";
+ /**
+ * STAL WSDL namespace and service name
+ */
+ public static final String STAL_WSDL_NS = "http://www.egiz.gv.at/wsdl/stal";
+ public static final String STAL_SERVICE = "STALService";
+ /**
+ * Dummy session id, used if no sessionId parameter is provided
+ */
+ protected static final String TEST_SESSION_ID = "TestSession";
+
+ static {
+ if (log.isTraceEnabled()) {
+ log.trace("enabling webservice communication dump");
+ System.setProperty(
+ "com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump",
+ "true");
+ }
+ }
+ /**
+ * STAL
+ */
+ protected AppletBKUWorker worker;
+ protected Thread workerThread;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.applet.Applet#getParameterInfo()
+ */
+ @Override
+ public String[][] getParameterInfo() {
+ return new String[][]{
+ {WSDL_URL, "url",
+ "URL of the WSDL of the MOCCA server side STAL"},
+ {REDIRECT_URL, "url",
+ "URL to redirect the browser to when finished"},
+ {REDIRECT_TARGET, "frame target",
+ "name of the target frame for redirection when finished"},
+ {LOCALE, "locale",
+ "locale for UI localization (optional, default: system default)"},
+ {GUI_STYLE, "simple, advanced, tiny",
+ "GUI style (optional, default: simple)"},
+ {BACKGROUND_COLOR, "#hhhhhh",
+ "background color, e.g. '#333333' (optional, default: look and feel dependend)"},
+ {BACKGROUND_IMG, "url",
+ "URL of a background image for the GUI (optional, default: no image)"},
+ {HELP_URL, "url",
+ "URL for locating help files, e.g. '../help/' (no help provided if missing)"}};
+ }
+
+ /**
+ * Factory method to create and wire HelpListener, GUI and BKUWorker.
+ * (Config via applet parameters, see BKUApplet.* constants)
+ */
+ @Override
+ public void init() {
+ log.info("Welcome to MOCCA");
+ log.trace("Called init()");
+ showStatus("Initializing MOCCA applet");
+
+ HttpsURLConnection.setDefaultSSLSocketFactory(InternalSSLSocketFactory.getInstance());
+
+ String locale = getParameter(LOCALE);
+ if (locale != null) {
+ this.setLocale(new Locale(locale));
+ }
+ log.trace("default locale: " + Locale.getDefault());
+ log.debug("setting locale: " + getLocale());
+
+ BKUGUIFacade.Style guiStyle;
+ String guiStyleParam = getParameter(GUI_STYLE);
+ if ("advanced".equals(guiStyleParam)) {
+ guiStyle = BKUGUIFacade.Style.advanced;
+ } else if ("tiny".equals(guiStyleParam)) {
+ guiStyle = BKUGUIFacade.Style.tiny;
+ } else {
+ guiStyle = BKUGUIFacade.Style.simple;
+ }
+ log.debug("setting gui-style: " + guiStyle);
+
+ URL backgroundImgURL = null;
+ try {
+ backgroundImgURL = getURLParameter(BACKGROUND_IMG, null);
+ log.debug("setting background: " + backgroundImgURL);
+ } catch (MalformedURLException ex) {
+ log.warn("cannot load applet background image: " + ex.getMessage());
+ }
+
+ AbstractHelpListener helpListener = null;
+ try {
+ helpListener = new DefaultHelpListener(getAppletContext(),
+ getURLParameter(HELP_URL, null), getLocale());
+ if (log.isDebugEnabled()) {
+ log.debug("setting helpURL: " + getURLParameter(HELP_URL, null));
+ }
+ } catch (MalformedURLException ex) {
+ log.warn("failed to load help URL: " + ex.getMessage() + ", disabling help");
+ }
+
+ SwitchFocusListener switchFocusListener = new SwitchFocusListener(
+ getAppletContext(), "focusToBrowser()");
+
+ // Note: We need a panel in order to be able to set the background
+ // properly.
+ // Setting the background without a panel has side effects with the
+ // different java plugins.
+ JPanel contentPanel = new JPanel();
+ getContentPane().add(contentPanel);
+
+ String backgroundColor = getParameter(BACKGROUND_COLOR);
+ if (backgroundColor != null && backgroundColor.startsWith("#")) {
+ try {
+ Color color = new Color(Integer.parseInt(backgroundColor.substring(1), 16));
+ log.debug("setting background color to " + color);
+ contentPanel.setBackground(color);
+ } catch (NumberFormatException e) {
+ log.debug("failed to set background color '" + backgroundColor + "'");
+ }
+ }
+
+ try {
+ URLFontLoader fontProvider = new URLFontLoader(getCodeBase());
+ fontProvider.loadInBackground();
+ BKUGUIFacade gui = createGUI(contentPanel, getLocale(), guiStyle,
+ backgroundImgURL, fontProvider, helpListener, switchFocusListener);
+
+ worker = createBKUWorker(this, gui);
+ } catch (MalformedURLException ex) {
+ log.fatal("failed to load font provider URL", ex);
+ System.err.println("invalid font provider URL " + ex.getMessage());
+ }
+ }
+
+ @Override
+ public void start() {
+ log.trace("Called start()");
+ if (worker != null) {
+ showStatus("Starting MOCCA applet");
+ workerThread = new Thread(worker);
+ workerThread.start();
+ } else {
+ log.debug("cannot start uninitialzed MOCCA applet");
+ }
+ }
+
+ @Override
+ public void stop() {
+ log.trace("Called stop()");
+ showStatus("Stopping MOCCA applet");
+ if ((workerThread != null) && (workerThread.isAlive())) {
+ workerThread.interrupt();
+ }
+ }
+
+ @Override
+ public void destroy() {
+ log.trace("Called destroy()");
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // factory methods for subclasses to inject different components
+ // ///////////////////////////////////////////////////////////////////////////
+ protected BKUGUIFacade createGUI(Container contentPane, Locale locale,
+ Style guiStyle, URL backgroundImgURL,
+ FontProvider fontProvider, AbstractHelpListener helpListener,
+ SwitchFocusListener switchFocusListener) {
+ return new BKUGUIImpl(contentPane, locale, guiStyle, backgroundImgURL,
+ fontProvider, helpListener, switchFocusListener);
+ }
+
+ protected AppletBKUWorker createBKUWorker(BKUApplet applet, BKUGUIFacade gui) {
+ return new AppletBKUWorker(applet, gui);
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // callback for BKUWorker to allow extension
+ // ///////////////////////////////////////////////////////////////////////////
+ /**
+ * Callback for BKUWorker to allow extension
+ *
+ * @return
+ * @throws java.net.MalformedURLException
+ */
+ public STALPortType getSTALPort() throws MalformedURLException {
+ URL wsdlURL = getURLParameter(WSDL_URL, null);
+ log.debug("setting STAL WSDL: " + wsdlURL);
+ QName endpointName = new QName(STAL_WSDL_NS, STAL_SERVICE);
+ STALService stal = new STALService(wsdlURL, endpointName);
+ return stal.getSTALPort();
+ }
+
+ /**
+ * Callback for BKUWorker to allow extension (TODO STALPort could know its
+ * STALTranslator)
+ *
+ * @return
+ * @throws java.net.MalformedURLException
+ */
+ public STALTranslator getSTALTranslator() {
+ return new STALTranslator();
+ }
+
+ /**
+ * Callback for BKUWorker to keep applet context out of BKUWorker
+ *
+ * @return
+ * @throws java.net.MalformedURLException
+ */
+ protected void sendRedirect(String sessionId) {
+ try {
+ AppletContext ctx = getAppletContext();
+ if (ctx == null) {
+ log.error("no applet context (applet might already have been destroyed)");
+ return;
+ }
+ URL redirectURL = getURLParameter(REDIRECT_URL, sessionId);
+ String redirectTarget = getParameter(REDIRECT_TARGET);
+ if (redirectTarget == null) {
+ log.info("Done. Redirecting to " + redirectURL + " ...");
+ ctx.showDocument(redirectURL);
+ } else {
+ log.info("Done. Redirecting to " + redirectURL + " (target=" + redirectTarget + ") ...");
+ ctx.showDocument(redirectURL, redirectTarget);
+ }
+ } catch (MalformedURLException ex) {
+ log.warn("Failed to redirect: " + ex.getMessage(), ex);
+ // gui.showErrorDialog(errorMsg, okListener, actionCommand)
+ }
+ }
+
+ public void getFocusFromBrowser() {
+
+ worker.getFocusFromBrowser();
+ }
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // utility methods
+ // ///////////////////////////////////////////////////////////////////////////
+ protected URL getURLParameter(String paramKey, String sessionId)
+ throws MalformedURLException {
+ String urlParam = getParameter(paramKey);
+ if (urlParam != null && !"".equals(urlParam)) {
+ URL codebase = getCodeBase();
+ try {
+ URL url;
+ if (codebase.getProtocol().equalsIgnoreCase("file")) {
+ // for debugging in appletrunner
+ url = new URL(urlParam);
+ } else {
+ if (sessionId != null) {
+ urlParam = urlParam + ";jsessionid=" + sessionId;
+ }
+ url = new URL(codebase, urlParam);
+ }
+ return url;
+ } catch (MalformedURLException ex) {
+ log.error("applet paremeter " + urlParam + " is not a valid URL: " + ex.getMessage());
+ throw ex;
+ }
+ } else {
+ log.error("applet paremeter " + paramKey + " not set");
+ throw new MalformedURLException(paramKey + " not set");
+ }
+ }
}
diff --git a/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java
new file mode 100644
index 00000000..f914aed7
--- /dev/null
+++ b/BKUApplet/src/main/java/at/gv/egiz/bku/online/applet/viewer/URLFontLoader.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2008 Federal Chancellery Austria and
+ * Graz University of Technology
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package at.gv.egiz.bku.online.applet.viewer;
+
+import at.gv.egiz.bku.gui.viewer.FontProviderException;
+import at.gv.egiz.bku.gui.viewer.FontProvider;
+import java.awt.Font;
+import java.awt.FontFormatException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.concurrent.ExecutionException;
+import javax.swing.SwingWorker;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public class URLFontLoader extends SwingWorker<Font, Object> implements FontProvider {
+
+ protected static final Log log = LogFactory.getLog(URLFontLoader.class);
+ protected URL fontURL;
+ protected Font font;
+
+ public URLFontLoader(URL codebase) throws MalformedURLException {
+ this.fontURL = new URL(codebase, SANSMONO_FONT_RESOURCE);
+ if (log.isDebugEnabled()) {
+ log.debug(Thread.currentThread() + " setting font load URL: " + fontURL);
+ }
+ }
+
+ public void loadInBackground() {
+ if (log.isDebugEnabled()) {
+ log.debug(Thread.currentThread() + " scheduling font loading in background: " + fontURL);
+ }
+ this.execute();
+ }
+
+ @Override
+ protected Font doInBackground() throws MalformedURLException, FontFormatException, IOException {
+ if (log.isDebugEnabled()) {
+ log.debug(Thread.currentThread() + " loading font in background...");
+ }
+ return Font.createFont(Font.TRUETYPE_FONT, fontURL.openStream());
+ }
+
+ /**
+ * waits for loadInBackground to finish
+ * @return the font loaded in loadInbackground
+ * @throws Exception
+ */
+ @Override
+ public Font getFont() throws FontProviderException {
+ log.debug(Thread.currentThread() + " get font");
+ try {
+ return get();
+ } catch (InterruptedException ex) {
+ log.error("font loader interrupted");
+// Thread.currentThread().interrupt();
+ throw new FontProviderException("font loader interrupted", ex);
+ } catch (ExecutionException ex) {
+ log.error("failed to load font", ex.getCause());
+ throw new FontProviderException("failed to load font", ex.getCause());
+ }
+ }
+}