From 25f4c7753a2a08b0baef6271898d6cbee99eba35 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Thu, 16 Oct 2008 13:58:34 +0000 Subject: [PATCH] Sampler theme location guessing made better. svn changeset:5652/svn branch:trunk --- .../itmill/toolkit/demo/sampler/Feature.java | 17 +++++++--- .../demo/sampler/SamplerApplication.java | 33 +++++++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/com/itmill/toolkit/demo/sampler/Feature.java b/src/com/itmill/toolkit/demo/sampler/Feature.java index d78b7afd8b..7690f8cde5 100644 --- a/src/com/itmill/toolkit/demo/sampler/Feature.java +++ b/src/com/itmill/toolkit/demo/sampler/Feature.java @@ -6,17 +6,25 @@ import java.io.InputStreamReader; import com.itmill.toolkit.ui.Component; +/** + * Represents one feature or sample, with associated example. + *

+ * + *

+ * + */ abstract public class Feature { public static final Object PROPERTY_ICON = "Icon"; public static final Object PROPERTY_NAME = "Name"; public static final Object PROPERTY_DESCRIPTION = "Description"; + private static final Object MUTEX = new Object(); private String javaSource = null; /** * Gets the name of this feature. Defaults to class simplename, override if - * needed. + * needed. Try not to exceed 25 characters too much. * * @return */ @@ -26,7 +34,8 @@ abstract public class Feature { /** * Gets the description for this feature. Should describe what the example - * intends to showcase. May contain HTML. + * intends to showcase. May contain HTML. 100 words should be enough, and + * about 7 rows... * * @return the description */ @@ -116,7 +125,7 @@ abstract public class Feature { public String getSource() { // TODO get's .txt for now, change to .java! - synchronized (this) { + synchronized (MUTEX) { if (javaSource == null) { StringBuffer src = new StringBuffer(); try { @@ -161,7 +170,7 @@ abstract public class Feature { * @return */ protected static final String getThemeBase() { - return SamplerApplication.THEME_BASE; + return SamplerApplication.getThemeBase(); } public String toString() { diff --git a/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java b/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java index a02c144835..4622ec1743 100644 --- a/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java +++ b/src/com/itmill/toolkit/demo/sampler/SamplerApplication.java @@ -1,5 +1,6 @@ package com.itmill.toolkit.demo.sampler; +import java.net.URI; import java.net.URL; import java.util.Collection; import java.util.Collections; @@ -35,8 +36,6 @@ import com.itmill.toolkit.ui.Button.ClickEvent; import com.itmill.toolkit.ui.Button.ClickListener; public class SamplerApplication extends Application { - public static final String THEME_BASE = "/ITMILL/themes/sampler/"; - // Main structure, root is always a FeatureSet that is not shown private static final FeatureSet features = new FeatureSet("All", new Feature[] { @@ -91,9 +90,33 @@ public class SamplerApplication extends Application { private static final HierarchicalContainer allFeatures = features .getContainer(true); + // init() inits + private static final String THEME_NAME = "sampler"; + + // used when trying to guess theme location + private static String APP_URL = null; + public void init() { setTheme("sampler"); setMainWindow(new SamplerWindow()); + if (APP_URL == null) { + APP_URL = getURL().toString(); + } + } + + /** + * Tries to guess theme location. + * + * @return + */ + public static String getThemeBase() { + try { + URI uri = new URI(APP_URL + "../ITMILL/themes/" + THEME_NAME + "/"); + return uri.normalize().toString(); + } catch (Exception e) { + System.err.println("Theme location could not be resolved:" + e); + } + return "/ITMILL/themes/" + THEME_NAME + "/"; } // Supports multiple browser windows @@ -135,6 +158,12 @@ public class SamplerApplication extends Application { return null; } + /** + * Gets the instance for the given Feature class, e.g DummyFeature.class. + * + * @param clazz + * @return + */ public static Feature getFeatureFor(Class clazz) { for (Iterator it = allFeatures.getItemIds().iterator(); it.hasNext();) { Feature f = (Feature) it.next(); -- 2.39.5