Changeset 5264
- Timestamp:
- 08/26/08 06:42:31 (3 months ago)
- Location:
- incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui
- Files:
-
- 3 modified
-
CoordinateLayout.java (modified) (6 diffs)
-
gwt/client/CoordinateLayoutWidgetSet.java (modified) (2 diffs)
-
gwt/client/ui/ICoordinateLayout.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/CoordinateLayout.java
r5258 r5264 32 32 33 33 /** 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. 35 36 */ 36 37 public CoordinateLayout() { … … 45 46 /** 46 47 * 47 * Adds a component to the coordinateLayout at the specified coordinates. The values48 * are treated as pixel values by default and for example48 * Adds a component to the coordinateLayout at the specified coordinates. 49 * The values are treated as pixel values by default and for example 49 50 * {@link com.itmill.toolkit.ui.CoordinateLayout.Coordinates#setUnitPercent(int, boolean)} 50 51 * can be used to set the values as percentage. … … 135 136 136 137 /** 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. 139 141 * 140 142 * @param c … … 279 281 * Replaces a child component with a new one. The new component uses the 280 282 * same coordinates as the previous component. If the arguments are null or 281 * the component is not a child of this coordinateLayout IllegalArgumentException is282 * thrown.283 * the component is not a child of this coordinateLayout 284 * IllegalArgumentException is thrown. 283 285 * 284 286 * @param c1 … … 451 453 * @throws NumberFormatException 452 454 */ 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 { 455 457 456 458 properties = new int[6]; 457 459 isUnitPercent = new boolean[6]; 458 460 461 properties[LEFT] = left; 459 462 properties[TOP] = top; 463 properties[WIDTH] = width; 464 properties[HEIGHT] = height; 460 465 properties[RIGHT] = right; 461 466 properties[BOTTOM] = bottom; 462 properties[LEFT] = left;463 464 properties[WIDTH] = width;465 properties[HEIGHT] = height;466 467 467 468 for (int i = 0; i < properties.length; i++) { … … 530 531 * @param height 531 532 */ 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) { 534 535 isUnitPercent[TOP] = top; 535 isUnitPercent[RIGHT] = right;536 isUnitPercent[BOTTOM] = bottom;537 536 isUnitPercent[LEFT] = left; 538 537 isUnitPercent[WIDTH] = width; 539 538 isUnitPercent[HEIGHT] = height; 539 isUnitPercent[RIGHT] = right; 540 isUnitPercent[BOTTOM] = bottom; 540 541 } 541 542 -
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/gwt/client/CoordinateLayoutWidgetSet.java
r4867 r5264 1 1 package com.itmill.toolkit.ui.gwt.client; 2 2 3 import com.google.gwt.user.client.ui.Widget;4 3 import com.itmill.toolkit.terminal.gwt.client.DefaultWidgetSet; 4 import com.itmill.toolkit.terminal.gwt.client.Paintable; 5 5 import com.itmill.toolkit.terminal.gwt.client.UIDL; 6 6 import com.itmill.toolkit.ui.gwt.client.ui.ICoordinateLayout; … … 9 9 10 10 /** Creates a widget according to its class name. */ 11 public WidgetcreateWidget(UIDL uidl) {11 public Paintable createWidget(UIDL uidl) { 12 12 final String className = resolveWidgetTypeName(uidl); 13 13 if ("com.itmill.toolkit.ui.gwt.client.ui.ICoordinateLayout" -
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/gwt/client/ui/ICoordinateLayout.java
r5258 r5264 211 211 212 212 Widget componentWidget = (Widget) componentIterator.next(); 213 Caption componentCaption = (Caption) componentToCaption 214 .get((Paintable) componentWidget); 213 215 214 216 // Reset position info … … 223 225 // (sides with a determined position) 224 226 boolean[] sidesToAttach = new boolean[6]; 227 int numberOfSides = 0; 225 228 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; 227 238 } 228 239 … … 327 338 328 339 // 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); 333 342 334 343 } … … 354 363 Element widgetElement = w.getElement(); 355 364 Element areaElement; 356 365 Caption componentCaption = (Caption) componentToCaption 366 .get((Paintable) w); 357 367 // Set widget element attributes 358 368 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"); 360 376 } 361 377 if (sidesToAttach[RIGHT] || sidesToAttach[WIDTH]) { … … 441 457 442 458 int[] captionPosition = new int[6]; 443 int parentTop, parentBottom, parentLeft, parentHeight; 459 int parentTop, parentRight, parentBottom, parentLeft, parentHeight, parentWidth; 460 String value; 444 461 445 462 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(); 463 464 Element areaElement = (Element) componentToArea.get(parent); 464 465 … … 469 470 } 470 471 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"); 483 520 484 521 // force z update on caption … … 495 532 496 533 // Set caption z-index (same as parent components z) 497 if (componentToCaption.get( component) != null) {534 if (componentToCaption.get((Paintable) component) != null) { 498 535 Caption c = (Caption) componentToCaption.get((Paintable) component); 499 536 DOM.setStyleAttribute(c.getElement(), "zIndex", "" + zIndex); … … 645 682 } 646 683 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 647 694 protected int calculateAbsoluteLeft(int width, int left, int right) { 648 695 … … 725 772 public void replaceChildComponent(Widget from, Widget to) { 726 773 client.unregisterPaintable((Paintable) from); 727 final Caption c = (Caption) componentToCaption.get( from);774 final Caption c = (Caption) componentToCaption.get((Paintable) from); 728 775 if (c == null) { 729 776 remove(from);
