Changeset 5077

Show
Ignore:
Timestamp:
07/10/08 12:20:23 (6 months ago)
Author:
matti.tahvonen@…
Message:

partial fix for #1902. FF seems to bug some pixels still (too narrow).

Location:
trunk/src/com/itmill/toolkit
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/com/itmill/toolkit/terminal/gwt/client/ui/ITextField.java

    r4777 r5077  
    1313import com.google.gwt.user.client.ui.Widget; 
    1414import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; 
     15import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener; 
    1516import com.itmill.toolkit.terminal.gwt.client.Paintable; 
    1617import com.itmill.toolkit.terminal.gwt.client.Tooltip; 
    1718import com.itmill.toolkit.terminal.gwt.client.UIDL; 
     19import com.itmill.toolkit.terminal.gwt.client.Util; 
    1820 
    1921/** 
     
    2426 */ 
    2527public class ITextField extends TextBoxBase implements Paintable, Field, 
    26         ChangeListener, FocusListener { 
     28        ChangeListener, FocusListener, ContainerResizedListener { 
    2729 
    2830    /** 
     
    4042 
    4143    private boolean immediate = false; 
     44    private float proportionalHeight = -1; 
     45    private float proportionalWidth = -1; 
     46    private int extraHorizontalPixels = -1; 
     47    private int extraVerticalPixels = -1; 
    4248 
    4349    public ITextField() { 
     
    119125    }-*/; 
    120126 
     127    public void setHeight(String height) { 
     128        if (height != null && height.indexOf("%") > 0) { 
     129            // special handling for proportional height 
     130            proportionalHeight = Float.parseFloat(height.substring(0, height 
     131                    .indexOf("%"))) / 100; 
     132            iLayout(); 
     133        } else { 
     134            super.setHeight(height); 
     135            proportionalHeight = -1; 
     136        } 
     137    } 
     138 
     139    public void setWidth(String width) { 
     140        if (width != null && width.indexOf("%") > 0) { 
     141            // special handling for proportional w 
     142            proportionalWidth = Float.parseFloat(width.substring(0, width 
     143                    .indexOf("%"))) / 100; 
     144            iLayout(); 
     145        } else { 
     146            super.setHeight(width); 
     147            proportionalWidth = -1; 
     148        } 
     149    } 
     150 
     151    public void iLayout() { 
     152        if (proportionalWidth >= 0) { 
     153            int availPixels = (int) (DOM.getElementPropertyInt(DOM 
     154                    .getParent(getElement()), "clientWidth") * proportionalWidth); 
     155            availPixels -= getExtraHorizontalPixels(); 
     156            super.setWidth(availPixels + "px"); 
     157        } 
     158        if (proportionalHeight >= 0) { 
     159            int availPixels = (int) (DOM.getElementPropertyInt(DOM 
     160                    .getParent(getElement()), "clientHeight") * proportionalHeight); 
     161            availPixels -= getExtraVerticalPixels(); 
     162            super.setHeight(availPixels + "px"); 
     163        } 
     164    } 
     165 
     166    /** 
     167     * @return space used by components paddings and borders 
     168     */ 
     169    private int getExtraHorizontalPixels() { 
     170        if (extraHorizontalPixels < 0) { 
     171            detectExtraSizes(); 
     172        } 
     173        return extraHorizontalPixels; 
     174    } 
     175 
     176    /** 
     177     * @return space used by components paddings and borders 
     178     */ 
     179    private int getExtraVerticalPixels() { 
     180        if (extraVerticalPixels < 0) { 
     181            detectExtraSizes(); 
     182        } 
     183        return extraVerticalPixels; 
     184    } 
     185 
     186    /** 
     187     * Detects space used by components paddings and borders. Used when 
     188     * relational size are used. 
     189     */ 
     190    private void detectExtraSizes() { 
     191        Element clone = Util.cloneNode(getElement(), false); 
     192        DOM.setElementAttribute(clone, "id", ""); 
     193        DOM.setStyleAttribute(clone, "visibility", "hidden"); 
     194        DOM.setStyleAttribute(clone, "position", "absolute"); 
     195        DOM.setStyleAttribute(clone, "width", "0"); 
     196        DOM.setStyleAttribute(clone, "height", "0"); 
     197        DOM.appendChild(DOM.getParent(getElement()), clone); 
     198        extraHorizontalPixels = DOM.getElementPropertyInt(clone, "offsetWidth"); 
     199        extraVerticalPixels = DOM.getElementPropertyInt(clone, "offsetHeight"); 
     200        DOM.removeChild(DOM.getParent(getElement()), clone); 
     201    } 
     202 
    121203} 
  • trunk/src/com/itmill/toolkit/tests/tickets/Ticket1902.java

    r5045 r5077  
    3636 
    3737        // 100% wide component 
    38         Button b2 = new Button("100% wide button"); 
     38        TextField b2 = new TextField("100% wide field"); 
    3939        mainLayout.addComponent(b2); 
    4040        b2.setWidth("100%"); 
     
    5858        lo2.setStyleName("red-background"); 
    5959        mainLayout.addComponent(lo2); 
    60         lo2.setWidth(400); 
     60        lo2.setWidth("50%"); 
    6161        lo2.setHeight(200); 
    6262 
     
    6868        lo2.addComponent(tf2); 
    6969        tf2.setWidth("100%"); 
     70        // tf2 = new TextField("50% wide, 100% height textfield"); // does not 
     71        // work with caption (10.7.2008 mac hosted mode) due layouts are broken 
     72        // in trunk 
     73        tf2 = new TextField(); 
     74        tf2.setRows(2); // trigger textArea impl. 
     75        tf2.setHeight("100%"); 
     76        tf2.setWidth("50%"); 
     77        lo2.addComponent(tf2); 
    7078    } 
    7179}