Changeset 5264

Show
Ignore:
Timestamp:
08/26/08 06:42:31 (3 months ago)
Author:
risto.yrjana@…
Message:

Updated coordinate ordering, fixed captions

Location:
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/CoordinateLayout.java

    r5258 r5264  
    3232 
    3333    /** 
    34      * Creates an empty coordinatelayout. The coordinateLayout is full size by default. 
     34     * Creates an empty coordinatelayout. The coordinateLayout is full size by 
     35     * default. 
    3536     */ 
    3637    public CoordinateLayout() { 
     
    4546    /** 
    4647     *  
    47      * Adds a component to the coordinateLayout at the specified coordinates. The values 
    48      * are treated as pixel values by default and for example 
     48     * Adds a component to the coordinateLayout at the specified coordinates. 
     49     * The values are treated as pixel values by default and for example 
    4950     * {@link com.itmill.toolkit.ui.CoordinateLayout.Coordinates#setUnitPercent(int, boolean)} 
    5051     * can be used to set the values as percentage. 
     
    135136 
    136137    /** 
    137      * Adds a component to the coordinateLayout at the specified coordinates. Null 
    138      * arguments are not permitted and will throw an IllegalArgumentException. 
     138     * Adds a component to the coordinateLayout at the specified coordinates. 
     139     * Null arguments are not permitted and will throw an 
     140     * IllegalArgumentException. 
    139141     *  
    140142     * @param c 
     
    279281     * Replaces a child component with a new one. The new component uses the 
    280282     * same coordinates as the previous component. If the arguments are null or 
    281      * the component is not a child of this coordinateLayout IllegalArgumentException is 
    282      * thrown. 
     283     * the component is not a child of this coordinateLayout 
     284     * IllegalArgumentException is thrown. 
    283285     *  
    284286     * @param c1 
     
    451453         * @throws NumberFormatException 
    452454         */ 
    453         public Coordinates(int top, int right, int bottom, int left, int width, 
    454                 int height) throws IllegalArgumentException { 
     455        public Coordinates(int left, int top, int width, int height, int right, 
     456                int bottom) throws IllegalArgumentException { 
    455457 
    456458            properties = new int[6]; 
    457459            isUnitPercent = new boolean[6]; 
    458460 
     461            properties[LEFT] = left; 
    459462            properties[TOP] = top; 
     463            properties[WIDTH] = width; 
     464            properties[HEIGHT] = height; 
    460465            properties[RIGHT] = right; 
    461466            properties[BOTTOM] = bottom; 
    462             properties[LEFT] = left; 
    463  
    464             properties[WIDTH] = width; 
    465             properties[HEIGHT] = height; 
    466467 
    467468            for (int i = 0; i < properties.length; i++) { 
     
    530531         * @param height 
    531532         */ 
    532         public void setUnitsPercent(boolean top, boolean right, boolean bottom, 
    533                 boolean left, boolean width, boolean height) { 
     533        public void setUnitsPercent(boolean left, boolean top, boolean width, 
     534                boolean height, boolean right, boolean bottom) { 
    534535            isUnitPercent[TOP] = top; 
    535             isUnitPercent[RIGHT] = right; 
    536             isUnitPercent[BOTTOM] = bottom; 
    537536            isUnitPercent[LEFT] = left; 
    538537            isUnitPercent[WIDTH] = width; 
    539538            isUnitPercent[HEIGHT] = height; 
     539            isUnitPercent[RIGHT] = right; 
     540            isUnitPercent[BOTTOM] = bottom; 
    540541        } 
    541542 
  • incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/gwt/client/CoordinateLayoutWidgetSet.java

    r4867 r5264  
    11package com.itmill.toolkit.ui.gwt.client; 
    22 
    3 import com.google.gwt.user.client.ui.Widget; 
    43import com.itmill.toolkit.terminal.gwt.client.DefaultWidgetSet; 
     4import com.itmill.toolkit.terminal.gwt.client.Paintable; 
    55import com.itmill.toolkit.terminal.gwt.client.UIDL; 
    66import com.itmill.toolkit.ui.gwt.client.ui.ICoordinateLayout; 
     
    99 
    1010    /** Creates a widget according to its class name. */ 
    11     public Widget createWidget(UIDL uidl) { 
     11    public Paintable createWidget(UIDL uidl) { 
    1212        final String className = resolveWidgetTypeName(uidl); 
    1313        if ("com.itmill.toolkit.ui.gwt.client.ui.ICoordinateLayout" 
  • incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/gwt/client/ui/ICoordinateLayout.java

    r5258 r5264  
    211211 
    212212                Widget componentWidget = (Widget) componentIterator.next(); 
     213                Caption componentCaption = (Caption) componentToCaption 
     214                        .get((Paintable) componentWidget); 
    213215 
    214216                // Reset position info 
     
    223225                // (sides with a determined position) 
    224226                boolean[] sidesToAttach = new boolean[6]; 
     227                int numberOfSides = 0; 
    225228                for (int i = 0; i < relative.length; i++) { 
    226                     sidesToAttach[i] = (relative[i] != -1); 
     229                    if (relative[i] != -1) { 
     230                        sidesToAttach[i] = true; 
     231                        ++numberOfSides; 
     232                    } 
     233                } 
     234                // At least one of (TOP, BOTTOM) must be attached to ensure the 
     235                // captions are displayed properly 
     236                if (!sidesToAttach[TOP] && !sidesToAttach[BOTTOM]) { 
     237                    sidesToAttach[TOP] = true; 
    227238                } 
    228239 
     
    327338 
    328339                // Update caption position 
    329                 Caption c = (Caption) componentToCaption 
    330                         .get((Paintable) componentWidget); 
    331                 if (c != null) { 
    332                     updateCaptionPosition(c, componentWidget); 
     340                if (componentCaption != null) { 
     341                    updateCaptionPosition(componentCaption, componentWidget); 
    333342 
    334343                } 
     
    354363        Element widgetElement = w.getElement(); 
    355364        Element areaElement; 
    356  
     365        Caption componentCaption = (Caption) componentToCaption 
     366                .get((Paintable) w); 
    357367        // Set widget element attributes 
    358368        if (sidesToAttach[TOP] || sidesToAttach[HEIGHT]) { 
    359             DOM.setStyleAttribute(widgetElement, "top", "0px"); 
     369            int margin = 0; 
     370            if (componentCaption != null) { 
     371                margin += componentCaption.getOffsetHeight(); 
     372            } 
     373            DOM.setStyleAttribute(widgetElement, "top", Integer 
     374                    .toString(margin) 
     375                    + "px"); 
    360376        } 
    361377        if (sidesToAttach[RIGHT] || sidesToAttach[WIDTH]) { 
     
    441457 
    442458        int[] captionPosition = new int[6]; 
    443         int parentTop, parentBottom, parentLeft, parentHeight; 
     459        int parentTop, parentRight, parentBottom, parentLeft, parentHeight, parentWidth; 
     460        String value; 
    444461 
    445462        Element captionElement = c.getElement(); 
    446  
    447         parentTop = parent.getAbsoluteTop(); 
    448         parentHeight = parent.getOffsetHeight(); 
    449         parentBottom = parentTop + parentHeight; 
    450         parentLeft = parent.getAbsoluteLeft(); 
    451  
    452         captionPosition[TOP] = parentTop - c.getOffsetHeight(); 
    453         captionPosition[RIGHT] = parentLeft + c.getOffsetWidth(); 
    454         captionPosition[BOTTOM] = parentBottom + parentHeight; 
    455         captionPosition[LEFT] = parentLeft; 
    456         captionPosition[WIDTH] = c.getOffsetWidth(); 
    457         captionPosition[HEIGHT] = c.getOffsetHeight(); 
    458  
    459         // setWidgetPosition(c, cTop, cRight, cBottom, cLeft, 
    460         // c.getOffsetWidth(), 
    461         // c.getOffsetHeight()); 
    462  
     463        Element parentElement = parent.getElement(); 
    463464        Element areaElement = (Element) componentToArea.get(parent); 
    464465 
     
    469470        } 
    470471 
    471         DOM.setStyleAttribute(captionElement, "top", captionPosition[TOP] 
    472                 + "px"); 
    473         DOM.setStyleAttribute(captionElement, "right", captionPosition[RIGHT] 
    474                 + "px"); 
    475         DOM.setStyleAttribute(captionElement, "bottom", captionPosition[BOTTOM] 
    476                 + "px"); 
    477         DOM.setStyleAttribute(captionElement, "left", captionPosition[LEFT] 
    478                 + "px"); 
    479         DOM.setStyleAttribute(captionElement, "width", captionPosition[WIDTH] 
    480                 + "px"); 
    481         DOM.setStyleAttribute(captionElement, "height", captionPosition[HEIGHT] 
    482                 + "px"); 
     472        resetPositionAttributes((Widget) c); 
     473 
     474        parentTop = getPositionValue(parentElement, "top"); 
     475        parentRight = getPositionValue(parentElement, "right"); 
     476        parentBottom = getPositionValue(parentElement, "bottom"); 
     477        parentLeft = getPositionValue(parentElement, "left"); 
     478 
     479        if (parentBottom == -1 || parentTop != -1) { 
     480            DOM.setStyleAttribute(captionElement, "top", "0px"); 
     481        } else { 
     482            int bottom = parent.getOffsetHeight(); 
     483            DOM.setStyleAttribute(captionElement, "bottom", bottom + "px"); 
     484        } 
     485 
     486        if (parentRight == -1 || parentLeft != -1) { 
     487            DOM.setStyleAttribute(captionElement, "left", "0px"); 
     488        } else { 
     489            int right = parent.getOffsetWidth() - c.getOffsetWidth(); 
     490            DOM.setStyleAttribute(captionElement, "right", right + "px"); 
     491        } 
     492 
     493        // parentHeight = parent.getOffsetHeight(); 
     494        // parentBottom = parentTop + parentHeight; 
     495        // parentLeft = parent.getAbsoluteLeft(); 
     496 
     497        // captionPosition[TOP] = parentTop; 
     498        // captionPosition[RIGHT] = parentLeft + c.getOffsetWidth(); 
     499        // captionPosition[BOTTOM] = parentBottom + parentHeight; 
     500        // captionPosition[LEFT] = parentLeft; 
     501        // captionPosition[WIDTH] = c.getOffsetWidth(); 
     502        // captionPosition[HEIGHT] = c.getOffsetHeight(); 
     503 
     504        // setWidgetPosition(c, cTop, cRight, cBottom, cLeft, 
     505        // c.getOffsetWidth(), 
     506        // c.getOffsetHeight()); 
     507 
     508        // DOM.setStyleAttribute(captionElement, "right", captionPosition[RIGHT] 
     509        // + "px"); 
     510        // DOM.setStyleAttribute(captionElement, "bottom", 
     511        // captionPosition[BOTTOM] 
     512        // + "px"); 
     513        // DOM.setStyleAttribute(captionElement, "left", captionPosition[LEFT] 
     514        // + "px"); 
     515        // DOM.setStyleAttribute(captionElement, "width", captionPosition[WIDTH] 
     516        // + "px"); 
     517        // DOM.setStyleAttribute(captionElement, "height", 
     518        // captionPosition[HEIGHT] 
     519        // + "px"); 
    483520 
    484521        // force z update on caption 
     
    495532 
    496533        // Set caption z-index (same as parent components z) 
    497         if (componentToCaption.get(component) != null) { 
     534        if (componentToCaption.get((Paintable) component) != null) { 
    498535            Caption c = (Caption) componentToCaption.get((Paintable) component); 
    499536            DOM.setStyleAttribute(c.getElement(), "zIndex", "" + zIndex); 
     
    645682    } 
    646683 
     684    protected int getPositionValue(Element e, String position) { 
     685        String value = DOM.getStyleAttribute(e, position); 
     686        int intvalue = DOM.getElementPropertyInt(e, position); 
     687        if (!"".equals(value)) { 
     688            return Integer.parseInt(value.substring(0, value.length() - 2)); 
     689        } else { 
     690            return -1; 
     691        } 
     692    } 
     693 
    647694    protected int calculateAbsoluteLeft(int width, int left, int right) { 
    648695 
     
    725772    public void replaceChildComponent(Widget from, Widget to) { 
    726773        client.unregisterPaintable((Paintable) from); 
    727         final Caption c = (Caption) componentToCaption.get(from); 
     774        final Caption c = (Caption) componentToCaption.get((Paintable) from); 
    728775        if (c == null) { 
    729776            remove(from);