Changeset 5245

Show
Ignore:
Timestamp:
08/22/08 09:57:20 (3 months ago)
Author:
joonas.lehtinen@…
Message:

Fixed #1904 : IOrderedLayout spacing and margincs should be specifiable in CSS

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/WebContent/ITMILL/themes/default/orderedlayout/orderedlayout.css

    r5063 r5245  
    1 . 
    2 /* Ordered layout spacing and margins are currently fixed. 
    3    This is considered to be a bug. For more info, see 
    4    http://dev.itmill.com/ticket/1904 
    5  
    6 i-orderedlayout-margin-top { 
     1.i-orderedlayout-margin-top { 
    72        padding-top: 15px; 
    83} 
     
    2419} 
    2520 
    26 */ 
    27  
    2821/* Placing error indicator right after the widget with empty caption */ 
    2922.i-orderedlayout-c * { float:left; display: block;} 
  • trunk/WebContent/ITMILL/themes/default/styles.css

    r5240 r5245  
    784784        white-space: nowrap; 
    785785} 
    786 . 
    787 /* Ordered layout spacing and margins are currently fixed. 
    788    This is considered to be a bug. For more info, see 
    789    http://dev.itmill.com/ticket/1904 
    790  
    791 i-orderedlayout-margin-top { 
     786.i-orderedlayout-margin-top { 
    792787        padding-top: 15px; 
    793788} 
     
    808803        padding-left: 8px; 
    809804} 
    810  
    811 */ 
    812805 
    813806/* Placing error indicator right after the widget with empty caption */ 
  • trunk/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java

    r5236 r5245  
    55package com.itmill.toolkit.terminal.gwt.client.ui; 
    66 
     7import java.util.HashMap; 
    78import java.util.Iterator; 
    89import java.util.Vector; 
     
    3839    public static final int ORIENTATION_HORIZONTAL = 1; 
    3940 
    40     private int hSpacing = -1; 
    41     private int vSpacing = -1; 
    42     private int marginTop = -1; 
    43     private int marginBottom = -1; 
    44     private int marginLeft = -1; 
    45     private int marginRight = -1; 
     41    /** 
     42     * If margin and spacing values has been calculated, this holds the values 
     43     * for the given UIDL style attribute . 
     44     */ 
     45    private static HashMap measuredMargins = new HashMap(); 
     46 
     47    /** 
     48     * Spacing. Correct values will be set in 
     49     * updateMarginAndSpacingFromCSS(UIDL) 
     50     */ 
     51    private int hSpacing, vSpacing; 
     52 
     53    /** 
     54     * Margin. Correct values will be set in updateMarginAndSpacingFromCSS(UIDL) 
     55     */ 
     56    private int marginTop, marginBottom, marginLeft, marginRight; 
    4657 
    4758    int orientationMode = ORIENTATION_VERTICAL; 
     
    319330 
    320331    private void updateMarginAndSpacingSizesFromCSS(UIDL uidl) { 
    321         // TODO Read spacing and margins from CSS as documented in #1904. 
    322         // Somehow refresh after updates 
    323  
    324         hSpacing = 8; 
    325         vSpacing = 8; 
    326         marginTop = 15; 
    327         marginBottom = 15; 
    328         marginLeft = 18; 
    329         marginRight = 18; 
     332 
     333        // Style for this layout 
     334        String style = uidl.getStringAttribute("style"); 
     335        if (style == null) { 
     336            style = ""; 
     337        } 
     338 
     339        // Try to find measured from cache 
     340        int[] r = (int[]) measuredMargins.get(style); 
     341 
     342        // Measure from DOM 
     343        if (r == null) { 
     344            r = new int[] { 0, 0, 0, 0, 0, 0 }; 
     345 
     346            // Construct DOM for measurements 
     347            Element e1 = DOM.createTable(); 
     348            DOM.setStyleAttribute(e1, "position", "absolute"); 
     349            DOM.setElementProperty(e1, "cellSpacing", "0"); 
     350            DOM.setElementProperty(e1, "cellPadding", "0"); 
     351            Element e11 = DOM.createTBody(); 
     352            Element e12 = DOM.createTR(); 
     353            Element e13 = DOM.createTD(); 
     354            Element e2 = DOM.createDiv(); 
     355            Element e3 = DOM.createDiv(); 
     356            DOM.setStyleAttribute(e3, "width", "100px"); 
     357            DOM.setStyleAttribute(e3, "height", "100px"); 
     358            DOM.appendChild(getElement(), e1); 
     359            DOM.appendChild(e1, e11); 
     360            DOM.appendChild(e11, e12); 
     361            DOM.appendChild(e12, e13); 
     362            DOM.appendChild(e13, e2); 
     363            DOM.appendChild(e2, e3); 
     364            DOM.setInnerText(e3, "."); 
     365 
     366            // Measure different properties 
     367            final String[] classes = { "margin-top", "margin-right", 
     368                    "margin-bottom", "margin-left", "vspacing", "hspacing" }; 
     369            for (int c = 0; c < 6; c++) { 
     370                StringBuffer styleBuf = new StringBuffer(); 
     371                final String primaryName = getStylePrimaryName(); 
     372                styleBuf.append(primaryName + "-" + classes[c]); 
     373                if (style.length() > 0) { 
     374                    final String[] styles = style.split(" "); 
     375                    for (int i = 0; i < styles.length; i++) { 
     376                        styleBuf.append(" "); 
     377                        styleBuf.append(primaryName); 
     378                        styleBuf.append("-"); 
     379                        styleBuf.append(styles[i]); 
     380                        styleBuf.append("-"); 
     381                        styleBuf.append(classes[c]); 
     382                    } 
     383                } 
     384                DOM.setElementProperty(e2, "className", styleBuf.toString()); 
     385 
     386                // Measure 
     387                r[c] = DOM.getElementPropertyInt(e1, 
     388                        (c % 2) == 1 ? "offsetWidth" : "offsetHeight") - 100; 
     389            } 
     390 
     391            // Clean-up 
     392            DOM.removeChild(getElement(), e1); 
     393 
     394            // Cache for further use 
     395            measuredMargins.put(style, r); 
     396        } 
     397 
     398        // Set the properties 
     399        marginTop = r[0]; 
     400        marginRight = r[1]; 
     401        marginBottom = r[2]; 
     402        marginLeft = r[3]; 
     403        vSpacing = r[4]; 
     404        hSpacing = r[5]; 
    330405    } 
    331406