]> source.dussan.org Git - vaadin-framework.git/commitdiff
-Layouts no longer implement Sizeable (except SplitPanel and ExpandLayout). Sizeable...
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Tue, 6 Nov 2007 07:14:26 +0000 (07:14 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Tue, 6 Nov 2007 07:14:26 +0000 (07:14 +0000)
-Changed ReservationApplication to conform to new setStyleName. Removed deprecated style constant usages also. Some margins enabled to layouts.
-IOrderedLayout vertical reverted back to DIV implementation.
-Margins added to demo layouts where needed.

svn changeset:2714/svn branch:trunk

14 files changed:
src/com/itmill/toolkit/demo/reservation/ReservationApplication.java
src/com/itmill/toolkit/demo/reservation/ResourceSelectorPanel.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
src/com/itmill/toolkit/tests/TestForBasicApplicationLayout.java
src/com/itmill/toolkit/tests/featurebrowser/PropertyPanel.java
src/com/itmill/toolkit/ui/AbstractComponentContainer.java
src/com/itmill/toolkit/ui/AbstractLayout.java
src/com/itmill/toolkit/ui/ExpandLayout.java
src/com/itmill/toolkit/ui/GridLayout.java
src/com/itmill/toolkit/ui/Layout.java
src/com/itmill/toolkit/ui/OrderedLayout.java
src/com/itmill/toolkit/ui/Panel.java
src/com/itmill/toolkit/ui/SplitPanel.java
src/com/itmill/toolkit/ui/TabSheet.java

index 273ff1cfca069f50650b015d50a4bb29b9e175e7..0f3297461ceab5cc0d0d0a5b199cea35a286aa6e 100644 (file)
@@ -68,7 +68,6 @@ public class ReservationApplication extends Application {
                setTheme("reservr");\r
 \r
                TabSheet mainTabs = new TabSheet();\r
-               mainTabs.addStyleName(TabSheet.STYLE_NO_PADDING);\r
                mainWindow.addComponent(mainTabs);\r
 \r
                OrderedLayout reservationTab = new OrderedLayout();\r
@@ -83,7 +82,8 @@ public class ReservationApplication extends Application {
 \r
                Panel reservationPanel = new Panel("Reservation", new OrderedLayout(\r
                                OrderedLayout.ORIENTATION_HORIZONTAL));\r
-               reservationPanel.setStyle("light");\r
+               reservationPanel.addStyleName(Panel.STYLE_LIGHT);\r
+               reservationPanel.getLayout().setMargin(true);\r
                reservationTab.addComponent(reservationPanel);\r
 \r
                OrderedLayout infoLayout = new OrderedLayout();\r
@@ -125,7 +125,7 @@ public class ReservationApplication extends Application {
 \r
                Label arrowLabel = new Label("&raquo;");\r
                arrowLabel.setContentMode(Label.CONTENT_XHTML);\r
-               arrowLabel.setStyle("arrow");\r
+               arrowLabel.setStyleName("arrow");\r
                reservationPanel.addComponent(arrowLabel);\r
 \r
                Calendar to = Calendar.getInstance();\r
@@ -178,6 +178,7 @@ public class ReservationApplication extends Application {
                Panel allLayout = new Panel(new OrderedLayout(\r
                                OrderedLayout.ORIENTATION_HORIZONTAL));\r
                allLayout.addStyleName(Panel.STYLE_LIGHT);\r
+               allLayout.getLayout().setMargin(true);\r
                allCalendar = new CalendarField();\r
                initCalendarFieldPropertyIds(allCalendar);\r
                allLayout.addComponent(allCalendar);\r
index 69da622ef4983055586332d2fe5664b652c5374d..d28313cc62adcb0d9b7dd1280a9e2f7221f3a431 100644 (file)
@@ -22,7 +22,7 @@ public class ResourceSelectorPanel extends Panel implements
 \r
        public ResourceSelectorPanel(String caption) {\r
                super(caption, new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL));\r
-               setStyle("light");\r
+               addStyleName(Panel.STYLE_LIGHT);\r
        }\r
 \r
        public void setResourceContainer(Container resources) {\r
@@ -41,7 +41,7 @@ public class ResourceSelectorPanel extends Panel implements
                                String description = (String) resource.getItemProperty(\r
                                                SampleDB.Resource.PROPERTY_ID_DESCRIPTION).getValue();\r
                                Button rButton = new Button(name, this);\r
-                               rButton.setStyle("link");\r
+                               rButton.setStyleName("link");\r
                                rButton.setDescription(description);\r
                                rButton.setData(resource);\r
                                Layout resourceLayout = (Layout) categoryLayouts.get(category);\r
@@ -49,12 +49,13 @@ public class ResourceSelectorPanel extends Panel implements
                                                .get(category);\r
                                if (resourceLayout == null) {\r
                                        resourceLayout = new OrderedLayout();\r
+                                       resourceLayout.setMargin(true);\r
                                        this.addComponent(resourceLayout);\r
                                        categoryLayouts.put(category, resourceLayout);\r
                                        resourceList = new LinkedList();\r
                                        categoryResources.put(category, resourceList);\r
                                        Button cButton = new Button(category + " (any)", this);\r
-                                       cButton.setStyle("important-link");\r
+                                       cButton.setStyleName("important-link");\r
                                        cButton.setData(category);\r
                                        resourceLayout.addComponent(cButton);\r
                                }\r
@@ -89,7 +90,7 @@ public class ResourceSelectorPanel extends Panel implements
                                                .get(category);\r
                                setSelectedResources(resources);\r
                        }\r
-                       ((Button) source).setStyle("selected-link");\r
+                       ((Button) source).setStyleName("selected-link");\r
                }\r
 \r
        }\r
@@ -100,9 +101,9 @@ public class ResourceSelectorPanel extends Panel implements
                        for (Iterator bit = lo.getComponentIterator(); bit.hasNext();) {\r
                                Button b = (Button) bit.next();\r
                                if (b.getData() instanceof Item) {\r
-                                       b.setStyle("link");\r
+                                       b.setStyleName("link");\r
                                } else {\r
-                                       b.setStyle("important-link");\r
+                                       b.setStyleName("important-link");\r
                                }\r
                        }\r
                }\r
index 59cf73d7de08b9fe7a4b1a472e56693a29e80553..fdf50c4d436424207dc8521d77e8bcd517ca4058 100644 (file)
@@ -33,8 +33,8 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
        public static final int ALIGNMENT_RIGHT = 2;
        public static final int ALIGNMENT_TOP = 4;
        public static final int ALIGNMENT_BOTTOM = 8;
-       public static final int HORIZONTAL_ALIGNMENT_CENTER = 16;
-       public static final int VERTICAL_ALIGNMENT_CENTER = 32;
+       public static final int ALIGNMENT_HORIZONTAL_CENTER = 16;
+       public static final int ALIGNMENT_VERTICAL_CENTER = 32;
 
        int orientationMode = ORIENTATION_VERTICAL;
 
@@ -49,7 +49,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
        protected Element childContainer;
        
        /*
-        * Margin element that provides marginals.
+        * Element that provides margins.
         */
        private Element margin;
 
@@ -60,18 +60,25 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
        }
 
        protected void constructDOM() {
-               margin = DOM.createDiv();
-               Element table = DOM.createTable();
-               Element tBody = DOM.createTBody();
-               childContainer = orientationMode == ORIENTATION_HORIZONTAL ? DOM
-                               .createTR() : tBody;
-               DOM.appendChild(table, tBody);
-               if (orientationMode == ORIENTATION_HORIZONTAL)
+               switch (orientationMode) {
+               case ORIENTATION_HORIZONTAL:
+                       Element table = DOM.createTable();
+                       Element tBody = DOM.createTBody();
+                       childContainer = DOM.createTR();
+                       DOM.appendChild(table, tBody);
                        DOM.appendChild(tBody, childContainer);
-               setElement(table);
-               // prevent unwanted spacing
-               DOM.setElementAttribute(table, "cellSpacing", "0");
-               DOM.setElementAttribute(table, "cellPadding", "0");
+                       setElement(table);
+                       // prevent unwanted spacing
+                       DOM.setElementAttribute(table, "cellSpacing", "0");
+                       DOM.setElementAttribute(table, "cellPadding", "0");
+                       margin = table;
+                       break;
+               default:
+                       childContainer = DOM.createDiv();
+                       setElement(childContainer);
+                       margin = childContainer;
+                       break;
+               }
        }
 
        public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
@@ -163,7 +170,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                                vAlign = "top";
                        else if ((alignment & ALIGNMENT_BOTTOM) == ALIGNMENT_BOTTOM)
                                vAlign = "bottom";
-                       else if ((alignment & VERTICAL_ALIGNMENT_CENTER) == VERTICAL_ALIGNMENT_CENTER)
+                       else if ((alignment & ALIGNMENT_VERTICAL_CENTER) == ALIGNMENT_VERTICAL_CENTER)
                                vAlign = "middle";
                        // Horizontal alignment
                        String hAlign = "";
@@ -171,7 +178,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                                hAlign = "left";
                        else if ((alignment & ALIGNMENT_RIGHT) == ALIGNMENT_RIGHT)
                                hAlign = "right";
-                       else if ((alignment & HORIZONTAL_ALIGNMENT_CENTER) == HORIZONTAL_ALIGNMENT_CENTER)
+                       else if ((alignment & ALIGNMENT_HORIZONTAL_CENTER) == ALIGNMENT_HORIZONTAL_CENTER)
                                hAlign = "center";
 
                        Element td = DOM.getParent(((Widget) it.next()).getElement());
@@ -182,23 +189,19 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                // Modify layout marginals
                String marginClasses = "";
                if (uidl.hasAttribute("marginTop"))
-                       marginClasses = StyleConstants.LAYOUT_MARGIN_TOP;
+                       marginClasses += " " + StyleConstants.LAYOUT_MARGIN_TOP;
                if (uidl.hasAttribute("marginRight"))
-                       marginClasses = StyleConstants.LAYOUT_MARGIN_RIGHT;
+                       marginClasses += " " + StyleConstants.LAYOUT_MARGIN_RIGHT;
                if (uidl.hasAttribute("marginBottom"))
-                       marginClasses = StyleConstants.LAYOUT_MARGIN_BOTTOM;
+                       marginClasses += " " + StyleConstants.LAYOUT_MARGIN_BOTTOM;
                if (uidl.hasAttribute("marginLeft"))
-                       marginClasses = StyleConstants.LAYOUT_MARGIN_LEFT;
+                       marginClasses += " " + StyleConstants.LAYOUT_MARGIN_LEFT;
                
-               DOM.setElementProperty(margin, "className", marginClasses);
-               
-               // Adjust size
-               if(uidl.hasAttribute("width"))
-                       setWidth(uidl.getStringAttribute("width"));
-               else setWidth("100%");
-               if(uidl.hasAttribute("height"))
-                       setHeight(uidl.getStringAttribute("height"));
-               else setHeight("");
+               if(marginClasses.equals(""))
+                       DOM.setElementProperty(margin, "className", CLASSNAME);
+               else
+                       DOM.setElementProperty(margin, "className", CLASSNAME + marginClasses);
+
        }
 
        /**
@@ -268,11 +271,10 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                } else {
                        Element container = createWidgetWrappper();
                        DOM.insertChild(childContainer, container, beforeIndex);
-                       insert(w, orientationMode == ORIENTATION_HORIZONTAL ? container
-                                       : DOM.getFirstChild(container), beforeIndex, false);
+                       insert(w, container, beforeIndex, false);
                }
        }
-
+       
        /**
         * creates an Element which will contain child widget
         */
@@ -281,9 +283,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                case ORIENTATION_HORIZONTAL:
                        return DOM.createTD();
                default:
-                       Element tr = DOM.createTR();
-                       DOM.appendChild(tr, DOM.createTD());
-                       return tr;
+                       return DOM.createDiv();
                }
        }
 
@@ -322,8 +322,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
        public void add(Widget w) {
                Element wrapper = createWidgetWrappper();
                DOM.appendChild(childContainer, wrapper);
-               super.add(w, orientationMode == ORIENTATION_HORIZONTAL ? wrapper : DOM
-                               .getFirstChild(wrapper));
+               super.add(w, wrapper);
        }
 
        public boolean remove(int index) {
@@ -335,9 +334,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                boolean removed = super.remove(w);
                if (removed) {
                        if (!(w instanceof Caption)) {
-                               DOM.removeChild(childContainer,
-                                               orientationMode == ORIENTATION_HORIZONTAL ? wrapper
-                                                               : DOM.getParent(wrapper));
+                               DOM.removeChild(childContainer, wrapper);
                        }
                        return true;
                }
index f7a058cbd2350519748b5fee1e2198a166a7f9e2..e7712ecaaae4e1c1acfcbb4ebf510db0080e8c61 100644 (file)
@@ -56,10 +56,10 @@ public class TestForBasicApplicationLayout extends CustomComponent {
                tab.setWidthUnits(Sizeable.UNITS_PERCENTAGE);\r
                tab.setHeight(740);\r
                tab.setHeightUnits(Sizeable.UNITS_PIXELS);\r
-               tab.addStyleName(TabSheet.STYLE_NO_PADDING);\r
 \r
                Panel report = new Panel("Monthly Program Runs", new ExpandLayout());\r
                OrderedLayout controls = new OrderedLayout();\r
+               controls.setMargin(true);\r
                controls.addComponent(new Label("Report tab"));\r
                controls.addComponent(click);\r
                controls.addComponent(click2);\r
index ad8382a632c64dc19cc3ae7fff61117369f87287..a16f42ce1330fc1a89a25216547a18438bc736c3 100644 (file)
@@ -67,6 +67,7 @@ public class PropertyPanel extends Panel implements Button.ClickListener,
        /** Contruct new property panel for configuring given object. */
        public PropertyPanel(Object objectToConfigure) {
                super();
+               getLayout().setMargin(false);
 
                // Layout
                setCaption("Properties");
@@ -84,6 +85,7 @@ public class PropertyPanel extends Panel implements Button.ClickListener,
                // Control buttons
                OrderedLayout buttons = new OrderedLayout(
                                OrderedLayout.ORIENTATION_HORIZONTAL);
+               buttons.setMargin(false, true, true, true);
                buttons.addComponent(setButton);
                buttons.addComponent(discardButton);
                addComponent(buttons);
index 659a81098732340d425580970cbdfbb28114559a..6c2e45d562ed5d1181507ab1f68707af68569f36 100644 (file)
@@ -32,8 +32,6 @@ import java.lang.reflect.Method;
 import java.util.Iterator;
 import java.util.LinkedList;
 
-import com.itmill.toolkit.terminal.Sizeable;
-
 /**
  * Extension to {@link AbstractComponent} that defines the default
  * implementation for the methods in {@link ComponentContainer}. Basic UI
@@ -46,8 +44,8 @@ import com.itmill.toolkit.terminal.Sizeable;
  * @since 3.0
  */
 public abstract class AbstractComponentContainer extends AbstractComponent
-               implements ComponentContainer, Sizeable {
-       
+               implements ComponentContainer {
+
        /**
         * Constructs a new component container.
         */
@@ -207,5 +205,5 @@ public abstract class AbstractComponentContainer extends AbstractComponent
                        fireComponentDetachEvent(c);
                }
        }
-       
+
 }
index 06d0d1899de713bf61200b2926ba9e14b5bafe1f..10dc8694ba20f6477f497028efc084bb71346bc0 100644 (file)
@@ -21,30 +21,6 @@ public abstract class AbstractLayout extends AbstractComponentContainer
         * space at that edge.
         */
        protected boolean[] margins;
-       
-       /**
-        * Height of the layout. Set to -1 for undefined height.
-        */
-       private int height = -1;
-
-       /**
-        * Height unit.
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
-        */
-       private int heightUnit = UNITS_PIXELS;
-
-       /**
-        * Width of the layout. Set to -1 for undefined width.
-        */
-       private int width = -1;
-
-       /**
-        * Width unit.
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
-        */
-       private int widthUnit = UNITS_PIXELS;
 
        /*
         * (non-Javadoc)
@@ -73,108 +49,6 @@ public abstract class AbstractLayout extends AbstractComponentContainer
                margins = new boolean[] { topEnabled, rightEnabled, bottomEnabled,
                                leftEnabled };
        }
-       
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
-        */
-       public int getHeight() {
-               return height;
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
-        */
-       public int getHeightUnits() {
-               return heightUnit;
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#getWidth()
-        */
-       public int getWidth() {
-               return width;
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
-        */
-       public int getWidthUnits() {
-               return widthUnit;
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#setHeight(int)
-        */
-       public void setHeight(int height) {
-               this.height = height;
-               requestRepaint();
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
-        */
-       public void setHeightUnits(int units) {
-               this.heightUnit = units;
-               requestRepaint();
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#setSizeFull()
-        */
-       public void setSizeFull() {
-               height = 100;
-               width = 100;
-               heightUnit = UNITS_PERCENTAGE;
-               widthUnit = UNITS_PERCENTAGE;
-               requestRepaint();
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined()
-        */
-       public void setSizeUndefined() {
-               height = -1;
-               width = -1;
-               heightUnit = UNITS_PIXELS;
-               widthUnit = UNITS_PIXELS;
-               requestRepaint();
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#setWidth(int)
-        */
-       public void setWidth(int width) {
-               this.width = width;
-               requestRepaint();
-       }
-
-       /*
-        * (non-Javadoc)
-        * 
-        * @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int)
-        */
-       public void setWidthUnits(int units) {
-               this.widthUnit = units;
-               requestRepaint();
-       }
 
        /*
         * (non-Javadoc)
@@ -194,14 +68,6 @@ public abstract class AbstractLayout extends AbstractComponentContainer
                        target.addAttribute("marginBottom", margins[2]);
                if (margins[3])
                        target.addAttribute("marginLeft", margins[3]);
-
-               // Add size info
-               if (getHeight() > -1)
-                       target.addAttribute("height", getHeight()
-                                       + UNIT_SYMBOLS[getHeightUnits()]);
-               if (getWidth() > -1)
-                       target.addAttribute("width", getWidth()
-                                       + UNIT_SYMBOLS[getWidthUnits()]);
        }
 
 }
index 497035f8f8e7cd634437a116eaf78090d654c76b..c8bc8b23a00f750cfb4b0ffd3a4495829ce621e5 100644 (file)
@@ -25,6 +25,30 @@ public class ExpandLayout extends OrderedLayout implements Sizeable {
 
        private Component expanded;
 
+       /**
+        * Height of the layout. Set to -1 for undefined height.
+        */
+       private int height = -1;
+
+       /**
+        * Height unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int heightUnit = UNITS_PIXELS;
+
+       /**
+        * Width of the layout. Set to -1 for undefined width.
+        */
+       private int width = -1;
+
+       /**
+        * Width unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int widthUnit = UNITS_PIXELS;
+
        public ExpandLayout() {
                setSizeFull();
        }
@@ -48,6 +72,9 @@ public class ExpandLayout extends OrderedLayout implements Sizeable {
        }
 
        public void paintContent(PaintTarget target) throws PaintException {
+
+               //TODO should we add margins?
+               
                // Size
                if (getHeight() >= 0)
                        target.addAttribute("height", "" + getHeight()
@@ -109,4 +136,106 @@ public class ExpandLayout extends OrderedLayout implements Sizeable {
                        expanded = newComponent;
        }
 
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
+        */
+       public int getHeight() {
+               return height;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
+        */
+       public int getHeightUnits() {
+               return heightUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidth()
+        */
+       public int getWidth() {
+               return width;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
+        */
+       public int getWidthUnits() {
+               return widthUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeight(int)
+        */
+       public void setHeight(int height) {
+               this.height = height;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
+        */
+       public void setHeightUnits(int units) {
+               this.heightUnit = units;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeFull()
+        */
+       public void setSizeFull() {
+               height = 100;
+               width = 100;
+               heightUnit = UNITS_PERCENTAGE;
+               widthUnit = UNITS_PERCENTAGE;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined()
+        */
+       public void setSizeUndefined() {
+               height = -1;
+               width = -1;
+               heightUnit = UNITS_PIXELS;
+               widthUnit = UNITS_PIXELS;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidth(int)
+        */
+       public void setWidth(int width) {
+               this.width = width;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int)
+        */
+       public void setWidthUnits(int units) {
+               this.widthUnit = units;
+               requestRepaint();
+       }
+
 }
index f9ecdbe3b5b8fee49f8ef91474f735e70d2c0b07..867e75b11a2fa8d513ecf39f3cbc5cf19c4df639 100644 (file)
@@ -101,33 +101,33 @@ public class GridLayout extends AbstractLayout {
        /**
         * Contained component should be aligned horizontally to the left.
         */
-       private int ALIGNMENT_LEFT = 1;
+       public static final int ALIGNMENT_LEFT = 1;
 
        /**
         * Contained component should be aligned horizontally to the right.
         */
-       private int ALIGNMENT_RIGHT = 2;
+       public static final int ALIGNMENT_RIGHT = 2;
 
        /**
         * Contained component should be aligned vertically to the top.
         */
-       private int ALIGNMENT_TOP = 4;
+       public static final int ALIGNMENT_TOP = 4;
 
        /**
         * Contained component should be aligned vertically to the bottom.
         */
-       private int ALIGNMENT_BOTTOM = 8;
+       public static final int ALIGNMENT_BOTTOM = 8;
 
        /**
         * Contained component should be horizontally aligned to center.
         */
-       private int HORIZONTAL_ALIGNMENT_CENTER = 16;
-       
+       public static final int HORIZONTAL_ALIGNMENT_CENTER = 16;
+
        /**
         * Contained component should be vertically aligned to center.
         */
-       private int VERTICAL_ALIGNMENT_CENTER = 32;
-       
+       public static final int VERTICAL_ALIGNMENT_CENTER = 32;
+
        /**
         * Is spacing between contained components enabled. Defaults to false.
         */
@@ -353,7 +353,7 @@ public class GridLayout extends AbstractLayout {
                components.remove(component);
                if (area != null)
                        areas.remove(area);
-               
+
                componentToAlignment.remove(component);
 
                requestRepaint();
@@ -404,7 +404,7 @@ public class GridLayout extends AbstractLayout {
                // TODO refactor attribute names in future release.
                target.addAttribute("h", rows);
                target.addAttribute("w", cols);
-               
+
                if (this.spacing)
                        target.addAttribute("spacing", this.spacing);
 
@@ -825,7 +825,7 @@ public class GridLayout extends AbstractLayout {
         * </p>
         */
        public void setWidth(int width) {
-               super.setWidth(width);
+               // super.setWidth(width);
        }
 
        /**
@@ -839,7 +839,8 @@ public class GridLayout extends AbstractLayout {
         * </p>
         */
        public int getWidth() {
-               return super.getWidth();
+               // return super.getWidth();
+               return -1;
        }
 
        /**
@@ -893,7 +894,7 @@ public class GridLayout extends AbstractLayout {
         * </p>
         */
        public void setHeight(int height) {
-               super.setHeight(height);
+               // super.setHeight(height);
        }
 
        /**
@@ -907,7 +908,8 @@ public class GridLayout extends AbstractLayout {
         * </p>
         */
        public int getHeight() {
-               return super.getHeight();
+               // return super.getHeight();
+               return -1;
        }
 
        /**
index 53c4ed791d7c2e0ec0ef192e1ad3c378a47d4aaa..245675f90bdb502938db4d647255ecc6ba17f9c7 100644 (file)
@@ -42,7 +42,7 @@ import com.itmill.toolkit.terminal.Sizeable;
  * @VERSION@
  * @since 3.0
  */
-public interface Layout extends ComponentContainer, Sizeable {
+public interface Layout extends ComponentContainer {
 
        /**
         * Enable layout margins. Affects all four sides of the layout. This will
index 0b7cc04a0900da18744669ef0fffbf5b141daf37..a19c501b507fb9b5d3d25c4ffb1b0154ed2ac1c6 100644 (file)
@@ -66,6 +66,8 @@ public class OrderedLayout extends AbstractLayout {
         */
        private LinkedList components = new LinkedList();
 
+       /* Child component alignments ************************************** */
+
        /**
         * Mapping from components to alignments (horizontal + vertical).
         */
@@ -94,12 +96,12 @@ public class OrderedLayout extends AbstractLayout {
        /**
         * Contained component should be horizontally aligned to center.
         */
-       public static final int HORIZONTAL_ALIGNMENT_CENTER = 16;
+       public static final int ALIGNMENT_HORIZONTAL_CENTER = 16;
 
        /**
         * Contained component should be vertically aligned to center.
         */
-       public static final int VERTICAL_ALIGNMENT_CENTER = 32;
+       public static final int ALIGNMENT_VERTICAL_CENTER = 32;
 
        /**
         * Orientation of the layout.
@@ -219,6 +221,7 @@ public class OrderedLayout extends AbstractLayout {
                if (orientation == ORIENTATION_HORIZONTAL)
                        target.addAttribute("orientation", "horizontal");
 
+               // Add spacing attribute (omitted if false)
                if (this.spacing)
                        target.addAttribute("spacing", this.spacing);
 
index 151c968b3845e5b52605b4b973c886c4150a4f23..9e8e686e6402dda4d4c18be98011340a646c4756 100644 (file)
@@ -39,6 +39,7 @@ import com.itmill.toolkit.terminal.KeyMapper;
 import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
 import com.itmill.toolkit.terminal.Scrollable;
+import com.itmill.toolkit.terminal.Sizeable;
 
 /**
  * Panel - a simple single component container.
@@ -48,13 +49,37 @@ import com.itmill.toolkit.terminal.Scrollable;
  * @VERSION@
  * @since 3.0
  */
-public class Panel extends AbstractLayout implements Scrollable,
+public class Panel extends AbstractLayout implements Sizeable, Scrollable,
                ComponentContainer.ComponentAttachListener,
                ComponentContainer.ComponentDetachListener, Action.Container {
 
        public static final String STYLE_LIGHT = "light";
 
        public static final String STYLE_EMPHASIZE = "emphasize";
+       
+       /**
+        * Height of the layout. Set to -1 for undefined height.
+        */
+       private int height = -1;
+
+       /**
+        * Height unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int heightUnit = UNITS_PIXELS;
+
+       /**
+        * Width of the layout. Set to -1 for undefined width.
+        */
+       private int width = -1;
+
+       /**
+        * Width unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int widthUnit = UNITS_PIXELS;
 
        /**
         * Layout of the panel.
@@ -86,7 +111,7 @@ public class Panel extends AbstractLayout implements Scrollable,
         * Creates a new empty panel. Ordered layout is used.
         */
        public Panel() {
-               this(new OrderedLayout());
+               setLayout(null);
        }
 
        /**
@@ -185,20 +210,7 @@ public class Panel extends AbstractLayout implements Scrollable,
        public void paintContent(PaintTarget target) throws PaintException {
                layout.paint(target);
 
-               // We need to add these attributes here (and not in super.paintContent),
-               // because Panel needs to have size information as variables.
-
-               // Add margin info
-               if (margins == null)
-                       setMargin(false);
-               if (margins[0])
-                       target.addAttribute("marginTop", margins[0]);
-               if (margins[1])
-                       target.addAttribute("marginRight", margins[1]);
-               if (margins[2])
-                       target.addAttribute("marginBottom", margins[2]);
-               if (margins[3])
-                       target.addAttribute("marginLeft", margins[3]);
+               super.paintContent(target);
 
                // Add size info as variables
                if (getHeight() > -1)
@@ -479,5 +491,107 @@ public class Panel extends AbstractLayout implements Scrollable,
                        requestRepaint();
                }
        }
+       
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
+        */
+       public int getHeight() {
+               return height;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
+        */
+       public int getHeightUnits() {
+               return heightUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidth()
+        */
+       public int getWidth() {
+               return width;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
+        */
+       public int getWidthUnits() {
+               return widthUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeight(int)
+        */
+       public void setHeight(int height) {
+               this.height = height;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
+        */
+       public void setHeightUnits(int units) {
+               this.heightUnit = units;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeFull()
+        */
+       public void setSizeFull() {
+               height = 100;
+               width = 100;
+               heightUnit = UNITS_PERCENTAGE;
+               widthUnit = UNITS_PERCENTAGE;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined()
+        */
+       public void setSizeUndefined() {
+               height = -1;
+               width = -1;
+               heightUnit = UNITS_PIXELS;
+               widthUnit = UNITS_PIXELS;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidth(int)
+        */
+       public void setWidth(int width) {
+               this.width = width;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int)
+        */
+       public void setWidthUnits(int units) {
+               this.widthUnit = units;
+               requestRepaint();
+       }
 
 }
index cb9adc5eefaad2d19870dde90045b2183a0959f4..3ae1a90c73b659d7e0a5ae261069fe21f259c165 100644 (file)
@@ -45,7 +45,7 @@ import com.itmill.toolkit.terminal.Sizeable;
  * @VERSION@
  * @since 5.0
  */
-public class SplitPanel extends AbstractLayout {
+public class SplitPanel extends AbstractLayout implements Sizeable {
 
        /* Predefined orientations ***************************************** */
 
@@ -72,6 +72,30 @@ public class SplitPanel extends AbstractLayout {
 
        private int posUnit = UNITS_PERCENTAGE;
 
+       /**
+        * Height of the layout. Set to -1 for undefined height.
+        */
+       private int height = -1;
+
+       /**
+        * Height unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int heightUnit = UNITS_PIXELS;
+
+       /**
+        * Width of the layout. Set to -1 for undefined width.
+        */
+       private int width = -1;
+
+       /**
+        * Width unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int widthUnit = UNITS_PIXELS;
+
        /**
         * Creates a new split panel. The orientation of the panels is
         * <code>ORIENTATION_VERTICAL</code>.
@@ -210,13 +234,20 @@ public class SplitPanel extends AbstractLayout {
         *             if the paint operation failed.
         */
        public void paintContent(PaintTarget target) throws PaintException {
-               
                super.paintContent(target);
 
                String position = pos + UNIT_SYMBOLS[posUnit];
 
                target.addAttribute("position", position);
 
+               // Add size info
+               if (getHeight() > -1)
+                       target.addAttribute("height", getHeight()
+                                       + UNIT_SYMBOLS[getHeightUnits()]);
+               if (getWidth() > -1)
+                       target.addAttribute("width", getWidth()
+                                       + UNIT_SYMBOLS[getWidthUnits()]);
+
                if (firstComponent != null)
                        firstComponent.paint(target);
                else
@@ -278,11 +309,114 @@ public class SplitPanel extends AbstractLayout {
         * 
         * @param pos
         *            size of the first region
-        * @param unit the unit (from {@link Sizeable}) in which the size is given.
+        * @param unit
+        *            the unit (from {@link Sizeable}) in which the size is given.
         */
        public void setSplitPosition(int pos, int unit) {
                this.pos = pos;
                this.posUnit = unit;
        }
 
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
+        */
+       public int getHeight() {
+               return height;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
+        */
+       public int getHeightUnits() {
+               return heightUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidth()
+        */
+       public int getWidth() {
+               return width;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
+        */
+       public int getWidthUnits() {
+               return widthUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeight(int)
+        */
+       public void setHeight(int height) {
+               this.height = height;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
+        */
+       public void setHeightUnits(int units) {
+               this.heightUnit = units;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeFull()
+        */
+       public void setSizeFull() {
+               height = 100;
+               width = 100;
+               heightUnit = UNITS_PERCENTAGE;
+               widthUnit = UNITS_PERCENTAGE;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined()
+        */
+       public void setSizeUndefined() {
+               height = -1;
+               width = -1;
+               heightUnit = UNITS_PIXELS;
+               widthUnit = UNITS_PIXELS;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidth(int)
+        */
+       public void setWidth(int width) {
+               this.width = width;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int)
+        */
+       public void setWidthUnits(int units) {
+               this.widthUnit = units;
+               requestRepaint();
+       }
+
 }
index aacdfb43d60f94991a2dcc6527368f4f627db0c6..494310aa57867cb6ed6fd4e89028800a14ad49a9 100644 (file)
@@ -30,11 +30,15 @@ package com.itmill.toolkit.ui;
 
 import java.lang.reflect.Method;
 import java.util.Hashtable;
-import java.util.LinkedList;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.Map;
 
-import com.itmill.toolkit.terminal.*;
+import com.itmill.toolkit.terminal.KeyMapper;
+import com.itmill.toolkit.terminal.PaintException;
+import com.itmill.toolkit.terminal.PaintTarget;
+import com.itmill.toolkit.terminal.Resource;
+import com.itmill.toolkit.terminal.Sizeable;
 
 /**
  * Tabsheet component.
@@ -44,14 +48,7 @@ import com.itmill.toolkit.terminal.*;
  * @VERSION@
  * @since 3.0
  */
-public class TabSheet extends AbstractLayout {
-
-       /**
-        * Use this stylename with {@link #addStyleName(String)} to remove padding
-        * between TabSheet borders and content. The actual client-side
-        * implementation will determine which stylenames it implements.
-        */
-       public static final String STYLE_NO_PADDING = "nopad";
+public class TabSheet extends AbstractLayout implements Sizeable {
 
        /**
         * Linked list of component tabs.
@@ -80,6 +77,30 @@ public class TabSheet extends AbstractLayout {
         */
        private boolean tabsHidden;
 
+       /**
+        * Height of the layout. Set to -1 for undefined height.
+        */
+       private int height = -1;
+
+       /**
+        * Height unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int heightUnit = UNITS_PIXELS;
+
+       /**
+        * Width of the layout. Set to -1 for undefined width.
+        */
+       private int width = -1;
+
+       /**
+        * Width unit.
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable.UNIT_SYMBOLS;
+        */
+       private int widthUnit = UNITS_PIXELS;
+
        /**
         * Constructs a new Tabsheet. Tabsheet is immediate by default.
         */
@@ -199,7 +220,15 @@ public class TabSheet extends AbstractLayout {
         */
        public void paintContent(PaintTarget target) throws PaintException {
                super.paintContent(target);
-               
+
+               // Add size info
+               if (getHeight() > -1)
+                       target.addAttribute("height", getHeight()
+                                       + UNIT_SYMBOLS[getHeightUnits()]);
+               if (getWidth() > -1)
+                       target.addAttribute("width", getWidth()
+                                       + UNIT_SYMBOLS[getWidthUnits()]);
+
                if (areTabsHidden())
                        target.addAttribute("hidetabs", true);
 
@@ -492,4 +521,106 @@ public class TabSheet extends AbstractLayout {
                fireEvent(new SelectedTabChangeEvent(this));
        }
 
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeight()
+        */
+       public int getHeight() {
+               return height;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getHeightUnits()
+        */
+       public int getHeightUnits() {
+               return heightUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidth()
+        */
+       public int getWidth() {
+               return width;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#getWidthUnits()
+        */
+       public int getWidthUnits() {
+               return widthUnit;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeight(int)
+        */
+       public void setHeight(int height) {
+               this.height = height;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setHeightUnits(int)
+        */
+       public void setHeightUnits(int units) {
+               this.heightUnit = units;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeFull()
+        */
+       public void setSizeFull() {
+               height = 100;
+               width = 100;
+               heightUnit = UNITS_PERCENTAGE;
+               widthUnit = UNITS_PERCENTAGE;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setSizeUndefined()
+        */
+       public void setSizeUndefined() {
+               height = -1;
+               width = -1;
+               heightUnit = UNITS_PIXELS;
+               widthUnit = UNITS_PIXELS;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidth(int)
+        */
+       public void setWidth(int width) {
+               this.width = width;
+               requestRepaint();
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see com.itmill.toolkit.terminal.Sizeable#setWidthUnits(int)
+        */
+       public void setWidthUnits(int units) {
+               this.widthUnit = units;
+               requestRepaint();
+       }
+
 }