Changeset 5215

Show
Ignore:
Timestamp:
08/19/08 12:13:04 (5 months ago)
Author:
risto.yrjana@…
Message:

Fixed width and height with borders

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

Legend:

Unmodified
Added
Removed
  • incubator/widgets/coordinatelayout/src/com/itmill/toolkit/tests/tickets/Ticket1267.java

    r5208 r5215  
    1111import com.itmill.toolkit.ui.CoordinateLayout; 
    1212import com.itmill.toolkit.ui.DateField; 
     13import com.itmill.toolkit.ui.ExpandLayout; 
    1314import com.itmill.toolkit.ui.GridLayout; 
    1415import com.itmill.toolkit.ui.Label; 
     
    1617import com.itmill.toolkit.ui.Panel; 
    1718import com.itmill.toolkit.ui.Slider; 
    18 import com.itmill.toolkit.ui.SplitPanel; 
    1919import com.itmill.toolkit.ui.Table; 
    2020import com.itmill.toolkit.ui.TextField; 
     
    2929        final Window main = new Window("Coordinatelayout demo"); 
    3030 
    31         SplitPanel sPanel = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); 
     31        // SplitPanel sPanel = new 
     32        // SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); 
    3233 
    3334        layout.setBorders(true); 
     
    6263        table.setSizeFull(); 
    6364        layout.setCoordinates(table, new CoordinateLayout.Coordinates( 
    64                 "0,0,-1,-1,30%,50%")); 
     65                "0,0,0,0,-1,-1")); 
    6566 
    6667        CoordinateLayout.Coordinates xy = new CoordinateLayout.Coordinates(40, 
     
    7576 
    7677        final Panel panel = new Panel("TestPanel"); 
    77         layout.addComponent(panel, "15%,-1,-1,0,-1,-1%"); 
     78        layout.addComponent(panel, "-1,0,0%,-1,-1,-1%"); 
    7879 
    7980        Button b1 = new Button("Add contents to panel"); 
     
    133134        right.addComponent(b5); 
    134135 
    135         sPanel.addComponent(layout); 
    136         sPanel.addComponent(right); 
    137  
    138         sPanel.setSplitPosition(75); 
    139  
    140         main.setLayout(sPanel); 
    141  
    142         // ExpandLayout mainLayout = new ExpandLayout( 
    143         // ExpandLayout.ORIENTATION_HORIZONTAL); 
    144         // mainLayout.addComponent(layout); 
    145         // mainLayout.addComponent(right); 
    146         // main.setLayout(mainLayout); 
     136        // sPanel.addComponent(layout); 
     137        // sPanel.addComponent(right); 
     138        // 
     139        // sPanel.setSplitPosition(75); 
     140        // 
     141        // main.setLayout(sPanel); 
     142 
     143        ExpandLayout mainLayout = new ExpandLayout( 
     144                ExpandLayout.ORIENTATION_HORIZONTAL); 
     145        mainLayout.addComponent(layout); 
     146        mainLayout.addComponent(right); 
     147        main.setLayout(mainLayout); 
    147148 
    148149        setMainWindow(main); 
  • incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/gwt/client/ui/ICoordinateLayout.java

    r5208 r5215  
    213213                            .getPaintable(componentDataUIDL); 
    214214                    Widget componentWidget = (Widget) componentDataPaintable; 
     215                    Element componentElement = componentWidget.getElement(); 
     216                    int[] absolute = new int[6]; 
    215217 
    216218                    // Reset position info 
    217                     removePositionAttributes(componentWidget.getElement()); 
    218                     DOM.setStyleAttribute(componentWidget.getElement(), 
    219                             "position", "absolute"); 
    220  
    221                     // Here we real calculate values from (possibly) percentage 
     219                    removePositionAttributes(componentElement); 
     220                    DOM.setStyleAttribute(componentElement, "position", 
     221                            "absolute"); 
     222 
     223                    // Calculate real pixel values from (possibly) percentage 
    222224                    // values 
    223225                    int top = calculateRealCoord("top", coords, isValuePercent); 
     
    229231                            isValuePercent); 
    230232 
    231                     // If we are not given a width and height we should first 
    232                     // try to 
    233                     // calculate them from the coordinates. If that fails, we 
    234                     // should 
    235                     // query the widget. In the simplest case they are given in 
    236                     // from 
    237                     // the 
    238                     // server. 
    239  
    240                     int width = -1; 
    241                     int height = -1; 
     233                    // Try to calculate width and height from the given 
     234                    // values and ask the component only if necessary 
     235 
     236                    absolute[WIDTH] = -1; 
     237                    absolute[HEIGHT] = -1; 
    242238 
    243239                    if (dimensions.getIntAttribute("width") == -1) { 
    244240                        if (left != -1 & right != -1) { 
    245                             width = layout[RIGHT] - left - right; 
     241                            absolute[WIDTH] = layout[RIGHT] - left - right; 
    246242                        } else { 
    247  
    248                             width = componentWidget.getOffsetWidth(); 
     243                            absolute[WIDTH] = componentWidget.getOffsetWidth(); 
    249244                        } 
    250245                    } else { 
    251                         width = dimensions.getIntAttribute("width"); 
     246                        absolute[WIDTH] = dimensions.getIntAttribute("width"); 
    252247                        if (isValuePercent.getBooleanAttribute("width")) { 
    253                             float multiplier = (float) width / 100; 
    254                             width = (int) (multiplier * this.getOffsetWidth()); 
     248                            float multiplier = (float) absolute[WIDTH] / 100; 
     249                            absolute[WIDTH] = (int) (multiplier * this 
     250                                    .getOffsetWidth()); 
    255251                        } 
    256252                    } 
     
    258254                    if (dimensions.getIntAttribute("height") == -1) { 
    259255                        if (top != -1 & bottom != -1) { 
    260                             height = layout[BOTTOM] - top - bottom; 
    261  
     256                            absolute[HEIGHT] = layout[BOTTOM] - top - bottom; 
    262257                        } else { 
    263  
    264                             height = componentWidget.getOffsetHeight(); 
     258                            absolute[HEIGHT] = componentWidget 
     259                                    .getOffsetHeight(); 
    265260 
    266261                        } 
    267262                    } else { 
    268                         height = dimensions.getIntAttribute("height"); 
     263                        absolute[HEIGHT] = dimensions.getIntAttribute("height"); 
    269264                        if (isValuePercent.getBooleanAttribute("height")) { 
    270                             float multiplier = (float) height / 100; 
    271                             height = (int) (multiplier * this.getOffsetHeight()); 
     265                            float multiplier = (float) absolute[HEIGHT] / 100; 
     266                            absolute[HEIGHT] = (int) (multiplier * this 
     267                                    .getOffsetHeight()); 
    272268                        } 
    273269 
    274270                    } 
    275271 
    276                     // Next we calculate the coordinates for the component 
     272                    // Calculate the coordinates for the component 
    277273                    // Each coordinate needs component size and two related 
    278274                    // coordinates 
    279                     int absoluteTop = calculateAbsoluteTop(height, top, bottom); 
    280                     int absoluteRight = calculateAbsoluteRight(width, right, 
    281                             left); 
    282                     int absoluteBottom = calculateAbsoluteBottom(height, 
    283                             bottom, top); 
    284                     int absoluteLeft = calculateAbsoluteLeft(width, left, right); 
     275 
     276                    absolute[TOP] = calculateAbsoluteTop(absolute[HEIGHT], top, 
     277                            bottom); 
     278                    absolute[RIGHT] = calculateAbsoluteRight(absolute[WIDTH], 
     279                            right, left); 
     280                    absolute[BOTTOM] = calculateAbsoluteBottom( 
     281                            absolute[HEIGHT], bottom, top); 
     282                    absolute[LEFT] = calculateAbsoluteLeft(absolute[WIDTH], 
     283                            left, right); 
    285284 
    286285                    // Sanity checks 
    287                     // height 
    288                     if ((absoluteTop + absoluteBottom) > getOffsetHeight()) { 
    289                         if (absoluteTop > absoluteBottom) { 
    290                             absoluteTop -= absoluteTop - absoluteBottom; 
     286                    // negative values 
     287                    for (int i = 0; i < absolute.length; i++) { 
     288                        if (absolute[i] < 0) { 
     289                            absolute[i] = 0; 
     290                        } 
     291                    } 
     292 
     293                    // height overflows 
     294                    if ((absolute[TOP] + absolute[BOTTOM]) > getOffsetHeight()) { 
     295                        if (absolute[TOP] > absolute[BOTTOM]) { 
     296                            absolute[TOP] -= absolute[TOP] - absolute[BOTTOM]; 
    291297                        } else { 
    292                             absoluteBottom -= absoluteBottom - absoluteTop; 
     298                            absolute[BOTTOM] -= absolute[BOTTOM] 
     299                                    - absolute[TOP]; 
    293300                        } 
    294301                    } 
    295302 
    296                     if (height > getOffsetHeight()) { 
    297                         height = getOffsetHeight(); 
    298                     } else if (height < 0) { 
    299                         height = 0; 
    300                     } 
    301  
    302                     // width 
    303                     if (absoluteRight + absoluteLeft > getOffsetWidth()) { 
    304                         if (absoluteRight > absoluteLeft) { 
    305                             absoluteRight -= absoluteRight - absoluteLeft; 
     303                    if (absolute[HEIGHT] > getOffsetHeight()) { 
     304                        absolute[HEIGHT] = getOffsetHeight(); 
     305                    } 
     306 
     307                    // width overflows 
     308                    if (absolute[RIGHT] + absolute[LEFT] > getOffsetWidth()) { 
     309                        if (absolute[RIGHT] > absolute[LEFT]) { 
     310                            absolute[RIGHT] -= absolute[RIGHT] - absolute[LEFT]; 
    306311                        } else { 
    307                             absoluteLeft -= absoluteLeft - absoluteRight; 
     312                            absolute[LEFT] -= absolute[LEFT] - absolute[RIGHT]; 
    308313                        } 
    309314                    } 
    310315 
    311                     if (width > getOffsetWidth()) { 
    312                         width = getOffsetWidth(); 
    313                     } else if (width < 0) { 
    314                         width = 0; 
    315                     } 
     316                    if (absolute[WIDTH] > getOffsetWidth()) { 
     317                        absolute[WIDTH] = getOffsetWidth(); 
     318                    } 
     319 
     320                    // this is a fix for borders 
     321                    // TODO there might be a better way to do this 
     322                    int border = (DOM.getElementPropertyInt(componentElement, 
     323                            "offsetWidth") - DOM.getElementPropertyInt( 
     324                            componentElement, "clientWidth")); 
     325 
     326                    absolute[WIDTH] -= border; 
     327                    absolute[HEIGHT] -= border; 
    316328 
    317329                    System.err.print("For component " 
     
    322334                    System.err.print(coords.getIntAttribute("left") + ","); 
    323335                    System.err.print(dimensions.getIntAttribute("width") + ","); 
    324                     System.err.print(dimensions.getIntAttribute("height") 
     336                    System.err.print(dimensions 
     337                            .getIntAttribute("absolute[HEIGHT]") 
    325338                            + "), "); 
    326339 
    327340                    System.err.print("calculated (" + top + "," + right + "," 
    328341                            + bottom + "," + left + "), "); 
    329                     System.err 
    330                             .print("absolute (" + absoluteTop + "," 
    331                                     + absoluteRight + "," + absoluteBottom 
    332                                     + "," + absoluteLeft + "," + width + "," 
    333                                     + height + ")\n"); 
     342                    System.err.print("absolute (" + absolute[TOP] + "," 
     343                            + absolute[RIGHT] + "," + absolute[BOTTOM] + "," 
     344                            + absolute[LEFT] + "," + absolute[WIDTH] + "," 
     345                            + absolute[HEIGHT] + ")\n"); 
    334346 
    335347                    // this call puts the component to the componentToCoords map 
    336348                    // and sets the style attributes 
    337                     setWidgetPosition(componentWidget, absoluteTop, 
    338                             absoluteRight, absoluteBottom, absoluteLeft, width, 
    339                             height); 
     349                    setWidgetPosition(componentWidget, absolute[TOP], 
     350                            absolute[RIGHT], absolute[BOTTOM], absolute[LEFT], 
     351                            absolute[WIDTH], absolute[HEIGHT]); 
    340352 
    341353                    // Update caption position