diff options
author | Simon Rettberg | 2015-07-08 19:39:35 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-08 19:39:35 +0200 |
commit | 8d6cd17c330388aa13fd7c39802c7400d85f972c (patch) | |
tree | 5f2c5856f58b1454e24dc16fad10751dfe9d087b /dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java | |
parent | oops (diff) | |
download | tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.tar.gz tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.tar.xz tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.zip |
[client] Redo package structure, add comments/TODOs, rename GUI classes
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java new file mode 100644 index 00000000..224ad865 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/OpenLinks.java @@ -0,0 +1,82 @@ +package org.openslx.dozmod.util; + +import java.awt.Desktop; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import javax.swing.JOptionPane; + +import org.apache.log4j.Logger; + +public class OpenLinks { + + /** + * Logger instance for this class + */ + private final static Logger LOGGER = Logger.getLogger(OpenLinks.class); + + /** + * Map containing the links + */ + @SuppressWarnings("serial") + private static Map<String, String> links = Collections.unmodifiableMap(new HashMap<String, String>(){{ + put("faq", "http://bwlehrpool.hs-offenburg.de"); + put("otrs", "http://bwlehrpool.hs-offenburg.de"); + put("vmware", "https://my.vmware.com/de/web/vmware/free#desktop_end_user_computing/vmware_player/6_0"); + put("intro", "http://www.hs-offenburg.de/fileadmin/Einrichtungen/hrz/Projekte/bwLehrpool/3_bwLehrpool_-_Image_einbinden_und_starten.pdf"); + // TODO use enum not map + }}); + + /** + * Static URIs + */ + + private static Map<String, URI> uris; + static { + // temp map + Map<String, URI> tmpUris = new HashMap<String, URI>(); + for (String key : links.keySet()) { + URI tmp; + try { + tmp = new URI(links.get(key)); + } catch (URISyntaxException e) { + // should never happen! + LOGGER.error("Bad URI syntax of '" + key + "', see trace: ", e); + tmp = null; + } + tmpUris.put(key, tmp); + } + // check sizes of maps to be equal + if (links.size() != tmpUris.size()) { + LOGGER.error("Links and URIs have different sizes, this should not happen. Contact a developper."); + } + + // all good, save it to the actual 'uris' map + uris = Collections.unmodifiableMap(tmpUris); + } + + + public static void openWebpage(String key) { + // first check if we have the link for the request key + if (!uris.containsKey(key)) { + LOGGER.error("OpenLinks has to link to '" + key + "'. Check if the given key actually exists."); + return; + } + Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() + : null; + if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { + try { + desktop.browse(uris.get(key)); + } catch (Exception e) { + e.printStackTrace(); + JOptionPane.showMessageDialog(null, + e.getCause() + "\n" + e.getStackTrace(), + "Debug-Message", JOptionPane.ERROR_MESSAGE); + } + } + }// end openWebpage + +} |