]> source.dussan.org Git - vaadin-framework.git/commitdiff
Sampler theme location guessing made better.
authorMarc Englund <marc.englund@itmill.com>
Thu, 16 Oct 2008 13:58:34 +0000 (13:58 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 16 Oct 2008 13:58:34 +0000 (13:58 +0000)
svn changeset:5652/svn branch:trunk

src/com/itmill/toolkit/demo/sampler/Feature.java
src/com/itmill/toolkit/demo/sampler/SamplerApplication.java

index d78b7afd8b68382bf64316abb5b6ae9947d52115..7690f8cde5365deaf4295cba2ee48bde871a8884 100644 (file)
@@ -6,17 +6,25 @@ import java.io.InputStreamReader;
 
 import com.itmill.toolkit.ui.Component;
 
+/**
+ * Represents one feature or sample, with associated example.
+ * <p>
+ * 
+ * </p>
+ * 
+ */
 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() {
index a02c144835164174361af68a1ea9189e76c5b5bb..4622ec1743ba42fd6d9664b87ec21513f3716ca9 100644 (file)
@@ -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();