Changeset 5215
- Timestamp:
- 08/19/08 12:13:04 (5 months ago)
- Location:
- incubator/widgets/coordinatelayout/src/com/itmill/toolkit
- Files:
-
- 2 modified
-
tests/tickets/Ticket1267.java (modified) (6 diffs)
-
ui/gwt/client/ui/ICoordinateLayout.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/tests/tickets/Ticket1267.java
r5208 r5215 11 11 import com.itmill.toolkit.ui.CoordinateLayout; 12 12 import com.itmill.toolkit.ui.DateField; 13 import com.itmill.toolkit.ui.ExpandLayout; 13 14 import com.itmill.toolkit.ui.GridLayout; 14 15 import com.itmill.toolkit.ui.Label; … … 16 17 import com.itmill.toolkit.ui.Panel; 17 18 import com.itmill.toolkit.ui.Slider; 18 import com.itmill.toolkit.ui.SplitPanel;19 19 import com.itmill.toolkit.ui.Table; 20 20 import com.itmill.toolkit.ui.TextField; … … 29 29 final Window main = new Window("Coordinatelayout demo"); 30 30 31 SplitPanel sPanel = new SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); 31 // SplitPanel sPanel = new 32 // SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); 32 33 33 34 layout.setBorders(true); … … 62 63 table.setSizeFull(); 63 64 layout.setCoordinates(table, new CoordinateLayout.Coordinates( 64 "0,0, -1,-1,30%,50%"));65 "0,0,0,0,-1,-1")); 65 66 66 67 CoordinateLayout.Coordinates xy = new CoordinateLayout.Coordinates(40, … … 75 76 76 77 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%"); 78 79 79 80 Button b1 = new Button("Add contents to panel"); … … 133 134 right.addComponent(b5); 134 135 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); 147 148 148 149 setMainWindow(main); -
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/gwt/client/ui/ICoordinateLayout.java
r5208 r5215 213 213 .getPaintable(componentDataUIDL); 214 214 Widget componentWidget = (Widget) componentDataPaintable; 215 Element componentElement = componentWidget.getElement(); 216 int[] absolute = new int[6]; 215 217 216 218 // Reset position info 217 removePositionAttributes(component Widget.getElement());218 DOM.setStyleAttribute(component Widget.getElement(),219 " position", "absolute");220 221 // Here we real calculatevalues from (possibly) percentage219 removePositionAttributes(componentElement); 220 DOM.setStyleAttribute(componentElement, "position", 221 "absolute"); 222 223 // Calculate real pixel values from (possibly) percentage 222 224 // values 223 225 int top = calculateRealCoord("top", coords, isValuePercent); … … 229 231 isValuePercent); 230 232 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; 242 238 243 239 if (dimensions.getIntAttribute("width") == -1) { 244 240 if (left != -1 & right != -1) { 245 width= layout[RIGHT] - left - right;241 absolute[WIDTH] = layout[RIGHT] - left - right; 246 242 } else { 247 248 width = componentWidget.getOffsetWidth(); 243 absolute[WIDTH] = componentWidget.getOffsetWidth(); 249 244 } 250 245 } else { 251 width= dimensions.getIntAttribute("width");246 absolute[WIDTH] = dimensions.getIntAttribute("width"); 252 247 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()); 255 251 } 256 252 } … … 258 254 if (dimensions.getIntAttribute("height") == -1) { 259 255 if (top != -1 & bottom != -1) { 260 height = layout[BOTTOM] - top - bottom; 261 256 absolute[HEIGHT] = layout[BOTTOM] - top - bottom; 262 257 } else { 263 264 height = componentWidget.getOffsetHeight();258 absolute[HEIGHT] = componentWidget 259 .getOffsetHeight(); 265 260 266 261 } 267 262 } else { 268 height= dimensions.getIntAttribute("height");263 absolute[HEIGHT] = dimensions.getIntAttribute("height"); 269 264 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()); 272 268 } 273 269 274 270 } 275 271 276 // Next we calculate the coordinates for the component272 // Calculate the coordinates for the component 277 273 // Each coordinate needs component size and two related 278 274 // 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); 285 284 286 285 // 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]; 291 297 } else { 292 absoluteBottom -= absoluteBottom - absoluteTop; 298 absolute[BOTTOM] -= absolute[BOTTOM] 299 - absolute[TOP]; 293 300 } 294 301 } 295 302 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]; 306 311 } else { 307 absolute Left -= absoluteLeft - absoluteRight;312 absolute[LEFT] -= absolute[LEFT] - absolute[RIGHT]; 308 313 } 309 314 } 310 315 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; 316 328 317 329 System.err.print("For component " … … 322 334 System.err.print(coords.getIntAttribute("left") + ","); 323 335 System.err.print(dimensions.getIntAttribute("width") + ","); 324 System.err.print(dimensions.getIntAttribute("height") 336 System.err.print(dimensions 337 .getIntAttribute("absolute[HEIGHT]") 325 338 + "), "); 326 339 327 340 System.err.print("calculated (" + top + "," + right + "," 328 341 + 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"); 334 346 335 347 // this call puts the component to the componentToCoords map 336 348 // and sets the style attributes 337 setWidgetPosition(componentWidget, absolute Top,338 absolute Right, absoluteBottom, absoluteLeft, width,339 height);349 setWidgetPosition(componentWidget, absolute[TOP], 350 absolute[RIGHT], absolute[BOTTOM], absolute[LEFT], 351 absolute[WIDTH], absolute[HEIGHT]); 340 352 341 353 // Update caption position
