]> source.dussan.org Git - vaadin-framework.git/commitdiff
-CustomLayout now supports sizeable.
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Fri, 16 Nov 2007 14:39:30 +0000 (14:39 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Fri, 16 Nov 2007 14:39:30 +0000 (14:39 +0000)
-Small fixes to IPanel.
-GridLayout and OrderedLayout now fetch alignment constants from client side package.

svn changeset:2858/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java
src/com/itmill/toolkit/terminal/gwt/public/default/panel/panel.css
src/com/itmill/toolkit/ui/CustomLayout.java
src/com/itmill/toolkit/ui/GridLayout.java
src/com/itmill/toolkit/ui/OrderedLayout.java

index 3924f1ba5e9aa1c19bac6c2ee7672bc300c412e6..7b8264b8ebd856625ae6d4a846c6605859917fad 100644 (file)
@@ -23,406 +23,425 @@ import com.itmill.toolkit.terminal.gwt.client.Util;
  * 
  */
 public class ICustomLayout extends ComplexPanel implements Paintable,
-        Container, ContainerResizedListener {
-
-    /** Location-name to containing element in DOM map */
-    private HashMap locationToElement = new HashMap();
-
-    /** Location-name to contained widget map */
-    private HashMap locationToWidget = new HashMap();
-
-    /** Widget to captionwrapper map */
-    private HashMap widgetToCaptionWrapper = new HashMap();
-
-    /** Currently rendered style */
-    String currentTemplate;
-
-    /** Unexecuted scripts loaded from the template */
-    private String scripts = "";
-
-    /** Paintable ID of this paintable */
-    private String pid;
-
-    private ApplicationConnection client;
-
-    public ICustomLayout() {
-        setElement(DOM.createDiv());
-        DOM.setStyleAttribute(getElement(), "height", "100%");
-    }
-
-    /**
-     * Sets widget to given location.
-     * 
-     * If location already contains a widget it will be removed.
-     * 
-     * @param widget
-     *                Widget to be set into location.
-     * @param location
-     *                location name where widget will be added
-     * 
-     * @throws IllegalArgumentException
-     *                 if no such location is found in the layout.
-     */
-    public void setWidget(Widget widget, String location) {
-
-        if (widget == null) {
-            return;
-        }
-
-        // If no given location is found in the layout, and exception is throws
-        Element elem = (Element) locationToElement.get(location);
-        if (elem == null && hasTemplate()) {
-            throw new IllegalArgumentException("No location " + location
-                    + " found");
-        }
-
-        // Get previous widget
-        Widget previous = (Widget) locationToWidget.get(location);
-        // NOP if given widget already exists in this location
-        if (previous == widget) {
-            return;
-        }
-        remove(previous);
-
-        // if template is missing add element in order
-        if (!hasTemplate()) {
-            elem = getElement();
-        }
-
-        // Add widget to location
-        super.add(widget, elem);
-        locationToWidget.put(location, widget);
-    }
-
-    /** Update the layout from UIDL */
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        this.client = client;
-        // Client manages general cases
-        if (client.updateComponent(this, uidl, false)) {
-            return;
-        }
-
-        // Update PID
-        pid = uidl.getId();
-        if (!hasTemplate()) {
-            // Update HTML template only once
-            initializeHTML(uidl, client);
-        }
-
-        // Evaluate scripts
-        eval(scripts);
-        scripts = null;
-
-        // For all contained widgets
-        for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
-            UIDL uidlForChild = (UIDL) i.next();
-            if (uidlForChild.getTag().equals("location")) {
-                String location = uidlForChild.getStringAttribute("name");
-                Widget child = client.getWidget(uidlForChild.getChildUIDL(0));
-                try {
-                    setWidget(child, location);
-                    ((Paintable) child).updateFromUIDL(uidlForChild
-                            .getChildUIDL(0), client);
-                } catch (IllegalArgumentException e) {
-                    // If no location is found, this component is not visible
-                }
-            }
-        }
-
-        iLayout();
-    }
-
-    /** Initialize HTML-layout. */
-    private void initializeHTML(UIDL uidl, ApplicationConnection client) {
-
-        String newTemplate = uidl.getStringAttribute("template");
-
-        // Get the HTML-template from client
-        String template = client
-                .getResource("layouts/" + newTemplate + ".html");
-        if (template == null) {
-            template = "<em>Layout file layouts/"
-                    + newTemplate
-                    + ".html is missing. Components will be drawn for debug purposes.</em>";
-        } else {
-            currentTemplate = newTemplate;
-        }
-
-        // Connect body of the template to DOM
-        template = extractBodyAndScriptsFromTemplate(template);
-        DOM.setInnerHTML(getElement(), template);
-
-        // Remap locations to elements
-        locationToElement.clear();
-        scanForLocations(getElement());
-
-        // Remap image srcs in layout
-        Widget parent = getParent();
-        while (parent != null && !(parent instanceof IView)) {
-            parent = parent.getParent();
-        }
-        if (parent != null && ((IView) parent).getTheme() != null) {
-            String prefix;
-            if (uriEndsWithSlash()) {
-                prefix = "../ITMILL/themes/";
-            } else {
-                prefix = "ITMILL/themes/";
-            }
-            prefixImgSrcs(getElement(), prefix + ((IView) parent).getTheme()
-                    + "/layouts/");
-        } else {
-            throw (new IllegalStateException(
-                    "Could not find IView; maybe updateFromUIDL() was called before attaching the widget?"));
-        }
-
-        publishResizedFunction(DOM.getFirstChild(getElement()));
-
-    }
-
-    private native boolean uriEndsWithSlash() /*-{
-       var path =  $wnd.location.pathname;
-       if(path.charAt(path.length - 1) == "/")
-               return true;
-       return false;
-    }-*/;
-
-    private boolean hasTemplate() {
-        if (currentTemplate == null) {
-            return false;
-        } else {
-            return true;
-        }
-    }
-
-    /** Collect locations from template */
-    private void scanForLocations(Element elem) {
-
-        String location = getLocation(elem);
-        if (location != null) {
-            locationToElement.put(location, elem);
-            DOM.setInnerHTML(elem, "");
-        } else {
-            int len = DOM.getChildCount(elem);
-            for (int i = 0; i < len; i++) {
-                scanForLocations(DOM.getChild(elem, i));
-            }
-        }
-    }
-
-    /** Get the location attribute for given element */
-    private static native String getLocation(Element elem) /*-{
-     return elem.getAttribute("location");
-     }-*/;
-
-    /** Evaluate given script in browser document */
-    private static native void eval(String script) /*-{
-     try {
-        if (script != null) 
-     eval("{ var document = $doc; var window = $wnd; "+ script + "}");
-     } catch (e) {
-     }
-     }-*/;
-
-    /** Prefix all img tag srcs with given prefix. */
-    private static native void prefixImgSrcs(Element e, String srcPrefix) /*-{
-     try {
-     var divs = e.getElementsByTagName("img"); 
-     var base = "" + $doc.location;
-     var l = base.length-1;
-     while (l >= 0 && base.charAt(l) != "/") l--;
-     base = base.substring(0,l+1);
-     for (var i = 0; i < divs.length; i++) {
-     var div = divs[i];
-     var src = div.getAttribute("src");
-     if (src.indexOf(base) == 0) div.setAttribute("src",base + srcPrefix + src.substring(base.length));
-     else if (src.indexOf("http") != 0) div.setAttribute("src",srcPrefix + src);
-     }                 
-     } catch (e) { alert(e + " " + srcPrefix);}
-     }-*/;
-
-    /**
-     * Extract body part and script tags from raw html-template.
-     * 
-     * Saves contents of all script-tags to private property: scripts. Returns
-     * contents of the body part for the html without script-tags. Also replaces
-     * all _UID_ tags with an unique id-string.
-     * 
-     * @param html
-     *                Original HTML-template received from server
-     * @return html that is used to create the HTMLPanel.
-     */
-    private String extractBodyAndScriptsFromTemplate(String html) {
-
-        // Replace UID:s
-        html = html.replaceAll("_UID_", pid + "__");
-
-        // Exctract script-tags
-        scripts = "";
-        int endOfPrevScript = 0;
-        int nextPosToCheck = 0;
-        String lc = html.toLowerCase();
-        String res = "";
-        int scriptStart = lc.indexOf("<script", nextPosToCheck);
-        while (scriptStart > 0) {
-            res += html.substring(endOfPrevScript, scriptStart);
-            scriptStart = lc.indexOf(">", scriptStart);
-            int j = lc.indexOf("</script>", scriptStart);
-            scripts += html.substring(scriptStart + 1, j) + ";";
-            nextPosToCheck = endOfPrevScript = j + "</script>".length();
-            scriptStart = lc.indexOf("<script", nextPosToCheck);
-        }
-        res += html.substring(endOfPrevScript);
-
-        // Extract body
-        html = res;
-        lc = html.toLowerCase();
-        int startOfBody = lc.indexOf("<body");
-        if (startOfBody < 0) {
-            res = html;
-        } else {
-            res = "";
-            startOfBody = lc.indexOf(">", startOfBody) + 1;
-            int endOfBody = lc.indexOf("</body>", startOfBody);
-            if (endOfBody > startOfBody) {
-                res = html.substring(startOfBody, endOfBody);
-            } else {
-                res = html.substring(startOfBody);
-            }
-        }
-
-        return res;
-    }
-
-    /** Replace child components */
-    public void replaceChildComponent(Widget from, Widget to) {
-        String location = getLocation(from);
-        if (location == null) {
-            throw new IllegalArgumentException();
-        }
-        setWidget(to, location);
-    }
-
-    /** Does this layout contain given child */
-    public boolean hasChildComponent(Widget component) {
-        return locationToWidget.containsValue(component);
-    }
-
-    /** Update caption for given widget */
-    public void updateCaption(Paintable component, UIDL uidl) {
-        CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper
-                .get(component);
-        if (Caption.isNeeded(uidl)) {
-            if (wrapper == null) {
-                String loc = getLocation((Widget) component);
-                super.remove((Widget) component);
-                wrapper = new CaptionWrapper(component, client);
-                super.add(wrapper, (Element) locationToElement.get(loc));
-                widgetToCaptionWrapper.put(component, wrapper);
-            }
-            wrapper.updateCaption(uidl);
-        } else {
-            if (wrapper != null) {
-                String loc = getLocation((Widget) component);
-                super.remove(wrapper);
-                super.add((Widget) wrapper.getPaintable(),
-                        (Element) locationToElement.get(loc));
-                widgetToCaptionWrapper.remove(component);
-            }
-        }
-    }
-
-    /** Get the location of an widget */
-    public String getLocation(Widget w) {
-        for (Iterator i = locationToWidget.keySet().iterator(); i.hasNext();) {
-            String location = (String) i.next();
-            if (locationToWidget.get(location) == w) {
-                return location;
-            }
-        }
-        return null;
-    }
-
-    /** Removes given widget from the layout */
-    public boolean remove(Widget w) {
-        client.unregisterPaintable((Paintable) w);
-        String location = getLocation(w);
-        if (location != null) {
-            locationToWidget.remove(location);
-        }
-        CaptionWrapper cw = (CaptionWrapper) widgetToCaptionWrapper.get(w);
-        if (cw != null) {
-            widgetToCaptionWrapper.remove(w);
-            return super.remove(cw);
-        } else if (w != null) {
-            return super.remove(w);
-        }
-        return false;
-    }
-
-    /** Adding widget without specifying location is not supported */
-    public void add(Widget w) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** Clear all widgets from the layout */
-    public void clear() {
-        super.clear();
-        locationToWidget.clear();
-        widgetToCaptionWrapper.clear();
-    }
-
-    public void iLayout() {
-        if (!iLayoutJS(DOM.getFirstChild(getElement()))) {
-            Util.runDescendentsLayout(this);
-        }
-    }
-
-    /**
-     * This method is published to JS side with the same name into first DOM
-     * node of custom layout. This way if one implements some resizeable
-     * containers in custom layout he/she can notify children after resize.
-     */
-    public void notifyChildrenOfSizeChange() {
-        Util.runDescendentsLayout(this);
-    }
-
-    public void onDetach() {
-        detachResizedFunction(DOM.getFirstChild(getElement()));
-    }
-
-    private native void detachResizedFunction(Element element)
-    /*-{
-       element.notifyChildrenOfSizeChange = null;
-    }-*/;
-
-    private native void publishResizedFunction(Element element)
-    /*-{
-       var self = this;
-       element.notifyChildrenOfSizeChange = function() {
-               self.@com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout::notifyChildrenOfSizeChange()();
-       };
-    }-*/;
-
-    /**
-     * In custom layout one may want to run layout functions made with
-     * JavaScript. This function tests if one exists (with name "iLayoutJS" in
-     * layouts first DOM node) and runs if it. Return value is used to determine
-     * is children needs to be notified of size changes.
-     * 
-     * @param el
-     * @return true if layout function was run and it returned true.
-     */
-    private native boolean iLayoutJS(Element el)
-    /*-{
-       if(el && el.iLayoutJS) {
-               try {
-                       el.iLayoutJS();
-                       return true;
-               } catch (e) {
-                       return false;
-               }
-       } else {
-               return false;
-       }
-    }-*/;
+               Container, ContainerResizedListener {
+
+       public static final String CLASSNAME = "i-customlayout";
+
+       /** Location-name to containing element in DOM map */
+       private HashMap locationToElement = new HashMap();
+
+       /** Location-name to contained widget map */
+       private HashMap locationToWidget = new HashMap();
+
+       /** Widget to captionwrapper map */
+       private HashMap widgetToCaptionWrapper = new HashMap();
+
+       /** Currently rendered style */
+       String currentTemplate;
+
+       /** Unexecuted scripts loaded from the template */
+       private String scripts = "";
+
+       /** Paintable ID of this paintable */
+       private String pid;
+
+       private ApplicationConnection client;
+
+       public ICustomLayout() {
+               setElement(DOM.createDiv());
+               // Clear any unwanted styling
+               DOM.setStyleAttribute(getElement(), "border", "none");
+               DOM.setStyleAttribute(getElement(), "margin", "0");
+               DOM.setStyleAttribute(getElement(), "padding", "0");
+               DOM.setStyleAttribute(getElement(), "overflow", "hidden");
+               setStyleName(CLASSNAME);
+       }
+
+       /**
+        * Sets widget to given location.
+        * 
+        * If location already contains a widget it will be removed.
+        * 
+        * @param widget
+        *            Widget to be set into location.
+        * @param location
+        *            location name where widget will be added
+        * 
+        * @throws IllegalArgumentException
+        *             if no such location is found in the layout.
+        */
+       public void setWidget(Widget widget, String location) {
+
+               if (widget == null) {
+                       return;
+               }
+
+               // If no given location is found in the layout, and exception is throws
+               Element elem = (Element) locationToElement.get(location);
+               if (elem == null && hasTemplate()) {
+                       throw new IllegalArgumentException("No location " + location
+                                       + " found");
+               }
+
+               // Get previous widget
+               Widget previous = (Widget) locationToWidget.get(location);
+               // NOP if given widget already exists in this location
+               if (previous == widget) {
+                       return;
+               }
+               remove(previous);
+
+               // if template is missing add element in order
+               if (!hasTemplate()) {
+                       elem = getElement();
+               }
+
+               // Add widget to location
+               super.add(widget, elem);
+               locationToWidget.put(location, widget);
+       }
+
+       /** Update the layout from UIDL */
+       public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+               this.client = client;
+               // Client manages general cases
+               if (client.updateComponent(this, uidl, false)) {
+                       return;
+               }
+
+               // Update PID
+               pid = uidl.getId();
+               if (!hasTemplate()) {
+                       // Update HTML template only once
+                       initializeHTML(uidl, client);
+               }
+
+               // Set size
+               if (uidl.hasAttribute("width")) {
+                       setWidth(uidl.getStringAttribute("width"));
+               } else {
+                       setWidth("100%");
+               }
+               if (uidl.hasAttribute("height")) {
+                       setHeight(uidl.getStringAttribute("height"));
+               } else {
+                       setHeight("100%");
+               }
+
+               // Evaluate scripts
+               eval(scripts);
+               scripts = null;
+
+               // For all contained widgets
+               for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
+                       UIDL uidlForChild = (UIDL) i.next();
+                       if (uidlForChild.getTag().equals("location")) {
+                               String location = uidlForChild.getStringAttribute("name");
+                               Widget child = client.getWidget(uidlForChild.getChildUIDL(0));
+                               try {
+                                       setWidget(child, location);
+                                       ((Paintable) child).updateFromUIDL(uidlForChild
+                                                       .getChildUIDL(0), client);
+                               } catch (IllegalArgumentException e) {
+                                       // If no location is found, this component is not visible
+                               }
+                       }
+               }
+
+               iLayout();
+       }
+
+       /** Initialize HTML-layout. */
+       private void initializeHTML(UIDL uidl, ApplicationConnection client) {
+
+               String newTemplate = uidl.getStringAttribute("template");
+
+               // Get the HTML-template from client
+               String template = client
+                               .getResource("layouts/" + newTemplate + ".html");
+               if (template == null) {
+                       template = "<em>Layout file layouts/"
+                                       + newTemplate
+                                       + ".html is missing. Components will be drawn for debug purposes.</em>";
+               } else {
+                       currentTemplate = newTemplate;
+               }
+
+               // Connect body of the template to DOM
+               template = extractBodyAndScriptsFromTemplate(template);
+               DOM.setInnerHTML(getElement(), template);
+
+               // Remap locations to elements
+               locationToElement.clear();
+               scanForLocations(getElement());
+
+               // Remap image srcs in layout
+               Widget parent = getParent();
+               while (parent != null && !(parent instanceof IView)) {
+                       parent = parent.getParent();
+               }
+               if (parent != null && ((IView) parent).getTheme() != null) {
+                       String prefix;
+                       if (uriEndsWithSlash()) {
+                               prefix = "../ITMILL/themes/";
+                       } else {
+                               prefix = "ITMILL/themes/";
+                       }
+                       prefixImgSrcs(getElement(), prefix + ((IView) parent).getTheme()
+                                       + "/layouts/");
+               } else {
+                       throw (new IllegalStateException(
+                                       "Could not find IView; maybe updateFromUIDL() was called before attaching the widget?"));
+               }
+
+               publishResizedFunction(DOM.getFirstChild(getElement()));
+
+       }
+
+       private native boolean uriEndsWithSlash() /*-{
+               var path =  $wnd.location.pathname;
+               if(path.charAt(path.length - 1) == "/")
+                       return true;
+               return false;
+          }-*/;
+
+       private boolean hasTemplate() {
+               if (currentTemplate == null) {
+                       return false;
+               } else {
+                       return true;
+               }
+       }
+
+       /** Collect locations from template */
+       private void scanForLocations(Element elem) {
+
+               String location = getLocation(elem);
+               if (location != null) {
+                       locationToElement.put(location, elem);
+                       DOM.setInnerHTML(elem, "");
+               } else {
+                       int len = DOM.getChildCount(elem);
+                       for (int i = 0; i < len; i++) {
+                               scanForLocations(DOM.getChild(elem, i));
+                       }
+               }
+       }
+
+       /** Get the location attribute for given element */
+       private static native String getLocation(Element elem) /*-{
+           return elem.getAttribute("location");
+           }-*/;
+
+       /** Evaluate given script in browser document */
+       private static native void eval(String script) /*-{
+           try {
+                if (script != null) 
+           eval("{ var document = $doc; var window = $wnd; "+ script + "}");
+           } catch (e) {
+           }
+           }-*/;
+
+       /** Prefix all img tag srcs with given prefix. */
+       private static native void prefixImgSrcs(Element e, String srcPrefix) /*-{
+           try {
+           var divs = e.getElementsByTagName("img"); 
+           var base = "" + $doc.location;
+           var l = base.length-1;
+           while (l >= 0 && base.charAt(l) != "/") l--;
+           base = base.substring(0,l+1);
+           for (var i = 0; i < divs.length; i++) {
+           var div = divs[i];
+           var src = div.getAttribute("src");
+           if (src.indexOf(base) == 0) div.setAttribute("src",base + srcPrefix + src.substring(base.length));
+           else if (src.indexOf("http") != 0) div.setAttribute("src",srcPrefix + src);
+           }                   
+           } catch (e) { alert(e + " " + srcPrefix);}
+           }-*/;
+
+       /**
+        * Extract body part and script tags from raw html-template.
+        * 
+        * Saves contents of all script-tags to private property: scripts. Returns
+        * contents of the body part for the html without script-tags. Also replaces
+        * all _UID_ tags with an unique id-string.
+        * 
+        * @param html
+        *            Original HTML-template received from server
+        * @return html that is used to create the HTMLPanel.
+        */
+       private String extractBodyAndScriptsFromTemplate(String html) {
+
+               // Replace UID:s
+               html = html.replaceAll("_UID_", pid + "__");
+
+               // Exctract script-tags
+               scripts = "";
+               int endOfPrevScript = 0;
+               int nextPosToCheck = 0;
+               String lc = html.toLowerCase();
+               String res = "";
+               int scriptStart = lc.indexOf("<script", nextPosToCheck);
+               while (scriptStart > 0) {
+                       res += html.substring(endOfPrevScript, scriptStart);
+                       scriptStart = lc.indexOf(">", scriptStart);
+                       int j = lc.indexOf("</script>", scriptStart);
+                       scripts += html.substring(scriptStart + 1, j) + ";";
+                       nextPosToCheck = endOfPrevScript = j + "</script>".length();
+                       scriptStart = lc.indexOf("<script", nextPosToCheck);
+               }
+               res += html.substring(endOfPrevScript);
+
+               // Extract body
+               html = res;
+               lc = html.toLowerCase();
+               int startOfBody = lc.indexOf("<body");
+               if (startOfBody < 0) {
+                       res = html;
+               } else {
+                       res = "";
+                       startOfBody = lc.indexOf(">", startOfBody) + 1;
+                       int endOfBody = lc.indexOf("</body>", startOfBody);
+                       if (endOfBody > startOfBody) {
+                               res = html.substring(startOfBody, endOfBody);
+                       } else {
+                               res = html.substring(startOfBody);
+                       }
+               }
+
+               return res;
+       }
+
+       /** Replace child components */
+       public void replaceChildComponent(Widget from, Widget to) {
+               String location = getLocation(from);
+               if (location == null) {
+                       throw new IllegalArgumentException();
+               }
+               setWidget(to, location);
+       }
+
+       /** Does this layout contain given child */
+       public boolean hasChildComponent(Widget component) {
+               return locationToWidget.containsValue(component);
+       }
+
+       /** Update caption for given widget */
+       public void updateCaption(Paintable component, UIDL uidl) {
+               CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper
+                               .get(component);
+               if (Caption.isNeeded(uidl)) {
+                       if (wrapper == null) {
+                               String loc = getLocation((Widget) component);
+                               super.remove((Widget) component);
+                               wrapper = new CaptionWrapper(component, client);
+                               super.add(wrapper, (Element) locationToElement.get(loc));
+                               widgetToCaptionWrapper.put(component, wrapper);
+                       }
+                       wrapper.updateCaption(uidl);
+               } else {
+                       if (wrapper != null) {
+                               String loc = getLocation((Widget) component);
+                               super.remove(wrapper);
+                               super.add((Widget) wrapper.getPaintable(),
+                                               (Element) locationToElement.get(loc));
+                               widgetToCaptionWrapper.remove(component);
+                       }
+               }
+       }
+
+       /** Get the location of an widget */
+       public String getLocation(Widget w) {
+               for (Iterator i = locationToWidget.keySet().iterator(); i.hasNext();) {
+                       String location = (String) i.next();
+                       if (locationToWidget.get(location) == w) {
+                               return location;
+                       }
+               }
+               return null;
+       }
+
+       /** Removes given widget from the layout */
+       public boolean remove(Widget w) {
+               client.unregisterPaintable((Paintable) w);
+               String location = getLocation(w);
+               if (location != null) {
+                       locationToWidget.remove(location);
+               }
+               CaptionWrapper cw = (CaptionWrapper) widgetToCaptionWrapper.get(w);
+               if (cw != null) {
+                       widgetToCaptionWrapper.remove(w);
+                       return super.remove(cw);
+               } else if (w != null) {
+                       return super.remove(w);
+               }
+               return false;
+       }
+
+       /** Adding widget without specifying location is not supported */
+       public void add(Widget w) {
+               throw new UnsupportedOperationException();
+       }
+
+       /** Clear all widgets from the layout */
+       public void clear() {
+               super.clear();
+               locationToWidget.clear();
+               widgetToCaptionWrapper.clear();
+       }
+
+       public void iLayout() {
+               if (!iLayoutJS(DOM.getFirstChild(getElement()))) {
+                       Util.runDescendentsLayout(this);
+               }
+       }
+
+       /**
+        * This method is published to JS side with the same name into first DOM
+        * node of custom layout. This way if one implements some resizeable
+        * containers in custom layout he/she can notify children after resize.
+        */
+       public void notifyChildrenOfSizeChange() {
+               Util.runDescendentsLayout(this);
+       }
+
+       public void onDetach() {
+               detachResizedFunction(DOM.getFirstChild(getElement()));
+       }
+
+       private native void detachResizedFunction(Element element)
+       /*-{
+               element.notifyChildrenOfSizeChange = null;
+       }-*/;
+
+       private native void publishResizedFunction(Element element)
+       /*-{
+               var self = this;
+               element.notifyChildrenOfSizeChange = function() {
+                       self.@com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout::notifyChildrenOfSizeChange()();
+               };
+       }-*/;
+
+       /**
+        * In custom layout one may want to run layout functions made with
+        * JavaScript. This function tests if one exists (with name "iLayoutJS" in
+        * layouts first DOM node) and runs if it. Return value is used to determine
+        * is children needs to be notified of size changes.
+        * 
+        * @param el
+        * @return true if layout function was run and it returned true.
+        */
+       private native boolean iLayoutJS(Element el)
+       /*-{
+               if(el && el.iLayoutJS) {
+                       try {
+                               el.iLayoutJS();
+                               return true;
+                       } catch (e) {
+                               return false;
+                       }
+               } else {
+                       return false;
+               }
+       }-*/;
 }
index 57dccd6b98f7affe4a1f9b2ec84130f9a14eee0a..31c2586aa0b268314c964484d0e9c01fe7726485 100644 (file)
@@ -134,7 +134,7 @@ public class IPanel extends SimplePanel implements Paintable,
                        "offsetTop") - DOM.getElementPropertyInt(getElement(), "offsetTop") + DOM.getElementPropertyInt(bottomDecoration,
                        "offsetHeight");
 
-                       int contentH = availableH - usedH - 1;
+                       int contentH = availableH - usedH;
                        if (contentH < 0)
                                contentH = 0;
                        DOM.setStyleAttribute(contentNode, "height", contentH + "px");
index cd26ace64c32eb7597d5a574593ba0048adb9a45..25660f894943ca2d33eb8e6c1a972fc065006c15 100644 (file)
        background: #fff;
 }
 
+.i-panel-light-caption {
+       overflow: hidden;
+}
+
 .i-panel-nocaption {
        height: 9px;
 }
index 55930cce7e90522ba53a60fe2395d990751e9eb7..6eb165cb4c860d6985f785f5dec8e76114cbf31c 100644 (file)
 
 package com.itmill.toolkit.ui;
 
+import java.util.HashMap;
+import java.util.Iterator;
+
 import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
 
-import java.util.Iterator;
-import java.util.HashMap;
-
 /**
  * <p>
  * A container component with freely designed layout and style. The container
@@ -248,4 +248,29 @@ public class CustomLayout extends AbstractLayout {
                requestRepaint();
        }
 
+       /**
+        * Although most layouts support margins, CustomLayout does not. The
+        * behaviour of this layout is determined almost completely by the actual
+        * template.
+        * 
+        * @throws UnsupportedOperationException
+        */
+       public void setMargin(boolean enabled) {
+               throw new UnsupportedOperationException(
+                               "CustomLayout does not support margins.");
+       }
+
+       /**
+        * Although most layouts support margins, CustomLayout does not. The
+        * behaviour of this layout is determined almost completely by the actual
+        * template.
+        * 
+        * @throws UnsupportedOperationException
+        */
+       public void setMargin(boolean topEnabled, boolean rightEnabled,
+                       boolean bottomEnabled, boolean leftEnabled) {
+               throw new UnsupportedOperationException(
+                               "CustomLayout does not support margins.");
+       }
+
 }
index e5a38efbef446a0d31a8e6e3be110f1fb909ad29..901842bed76cb0f7b22c97dcb43264e56995ed44 100644 (file)
@@ -37,6 +37,7 @@ import java.util.Map;
 import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
 import com.itmill.toolkit.terminal.Sizeable;
+import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo;
 
 /**
  * <p>
@@ -101,32 +102,32 @@ public class GridLayout extends AbstractLayout {
        /**
         * Contained component should be aligned horizontally to the left.
         */
-       public static final int ALIGNMENT_LEFT = 1;
+       public static final int ALIGNMENT_LEFT = AlignmentInfo.ALIGNMENT_LEFT;
 
        /**
         * Contained component should be aligned horizontally to the right.
         */
-       public static final int ALIGNMENT_RIGHT = 2;
+       public static final int ALIGNMENT_RIGHT = AlignmentInfo.ALIGNMENT_RIGHT;
 
        /**
         * Contained component should be aligned vertically to the top.
         */
-       public static final int ALIGNMENT_TOP = 4;
+       public static final int ALIGNMENT_TOP = AlignmentInfo.ALIGNMENT_TOP;
 
        /**
         * Contained component should be aligned vertically to the bottom.
         */
-       public static final int ALIGNMENT_BOTTOM = 8;
+       public static final int ALIGNMENT_BOTTOM = AlignmentInfo.ALIGNMENT_BOTTOM;
 
        /**
         * Contained component should be horizontally aligned to center.
         */
-       public static final int HORIZONTAL_ALIGNMENT_CENTER = 16;
+       public static final int ALIGNMENT_HORIZONTAL_CENTER = AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER;
 
        /**
         * Contained component should be vertically aligned to center.
         */
-       public static final int VERTICAL_ALIGNMENT_CENTER = 32;
+       public static final int ALIGNMENT_VERTICAL_CENTER = AlignmentInfo.ALIGNMENT_VERTICAL_CENTER;
 
        /**
         * Is spacing between contained components enabled. Defaults to false.
index b489312bcac885b8b2c5436546663f055da6c154..72e98a7c2d0f0ce7c26ab9659338b20e9650af85 100644 (file)
@@ -35,6 +35,7 @@ import java.util.Map;
 
 import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
+import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo;
 
 /**
  * Ordered layout.
@@ -76,32 +77,32 @@ public class OrderedLayout extends AbstractLayout {
        /**
         * Contained component should be aligned horizontally to the left.
         */
-       public static final int ALIGNMENT_LEFT = 1;
+       public static final int ALIGNMENT_LEFT = AlignmentInfo.ALIGNMENT_LEFT;
 
        /**
         * Contained component should be aligned horizontally to the right.
         */
-       public static final int ALIGNMENT_RIGHT = 2;
+       public static final int ALIGNMENT_RIGHT = AlignmentInfo.ALIGNMENT_RIGHT;
 
        /**
         * Contained component should be aligned vertically to the top.
         */
-       public static final int ALIGNMENT_TOP = 4;
+       public static final int ALIGNMENT_TOP = AlignmentInfo.ALIGNMENT_TOP;
 
        /**
         * Contained component should be aligned vertically to the bottom.
         */
-       public static final int ALIGNMENT_BOTTOM = 8;
+       public static final int ALIGNMENT_BOTTOM = AlignmentInfo.ALIGNMENT_BOTTOM;
 
        /**
         * Contained component should be horizontally aligned to center.
         */
-       public static final int ALIGNMENT_HORIZONTAL_CENTER = 16;
+       public static final int ALIGNMENT_HORIZONTAL_CENTER = AlignmentInfo.ALIGNMENT_HORIZONTAL_CENTER;
 
        /**
         * Contained component should be vertically aligned to center.
         */
-       public static final int ALIGNMENT_VERTICAL_CENTER = 32;
+       public static final int ALIGNMENT_VERTICAL_CENTER = AlignmentInfo.ALIGNMENT_VERTICAL_CENTER;
 
        private static final int ALIGNMENT_DEFAULT = ALIGNMENT_TOP + ALIGNMENT_LEFT;