Changeset 5258
- Timestamp:
- 08/25/08 10:51:54 (3 months ago)
- Location:
- incubator/widgets/coordinatelayout/src/com/itmill/toolkit
- Files:
-
- 3 modified
-
tests/tickets/Ticket1267.java (modified) (13 diffs)
-
ui/CoordinateLayout.java (modified) (27 diffs)
-
ui/gwt/client/ui/ICoordinateLayout.java (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/tests/tickets/Ticket1267.java
r5215 r5258 14 14 import com.itmill.toolkit.ui.GridLayout; 15 15 import com.itmill.toolkit.ui.Label; 16 import com.itmill.toolkit.ui.Layout; 16 17 import com.itmill.toolkit.ui.OrderedLayout; 17 18 import com.itmill.toolkit.ui.Panel; 19 import com.itmill.toolkit.ui.Select; 18 20 import com.itmill.toolkit.ui.Slider; 19 21 import com.itmill.toolkit.ui.Table; … … 23 25 public class Ticket1267 extends Application { 24 26 25 final CoordinateLayout layout = new CoordinateLayout();27 final CoordinateLayout coordinateLayout = new CoordinateLayout(); 26 28 27 29 public void init() { … … 32 34 // SplitPanel(SplitPanel.ORIENTATION_HORIZONTAL); 33 35 34 layout.setBorders(true); 36 coordinateLayout.setMargin(true); 37 coordinateLayout.setMargin(true, true, true, true); 35 38 36 39 // Setup table … … 60 63 } 61 64 62 layout.addComponent(table); 63 table.setSizeFull(); 64 layout.setCoordinates(table, new CoordinateLayout.Coordinates( 65 "0,0,0,0,-1,-1")); 65 coordinateLayout.addComponent(table); 66 coordinateLayout.setCoordinates(table, 67 new CoordinateLayout.Coordinates("0,0,-1,-1")); 66 68 67 69 CoordinateLayout.Coordinates xy = new CoordinateLayout.Coordinates(40, … … 69 71 xy.setUnitsPercent(true, true, true, true, false, false); 70 72 71 layout.addComponent(72 new TextField("Caption","TextField with a caption"), xy);73 coordinateLayout.addComponent(new TextField("Caption", 74 "TextField with a caption"), xy); 73 75 74 76 final DateField dateField = new DateField("Removal test"); 75 layout.addComponent(dateField);77 // coordinateLayout.addComponent(dateField); 76 78 77 79 final Panel panel = new Panel("TestPanel"); 78 layout.addComponent(panel, "-1,0,0%,-1,-1,-1%"); 80 // coordinateLayout.addComponent(panel, "0,-1,-1,-1,-1,0"); 81 82 final Layout ol = new OrderedLayout(); 83 ol.addComponent(new Select("Select inside layouts", table 84 .getContainerDataSource())); 85 ol.addComponent(new Select("Select inside layouts", table 86 .getContainerDataSource())); 87 ol.addComponent(new Select("Select inside layouts", table 88 .getContainerDataSource())); 89 90 // CoordinateLayout.Coordinates xy2 = new CoordinateLayout.Coordinates( 91 // "-1,-1,0,0,200,200"); 92 // coordinateLayout.addComponent(ol, xy2); 79 93 80 94 Button b1 = new Button("Add contents to panel"); … … 93 107 public void buttonClick(Button.ClickEvent e) { 94 108 if (bottom) { 95 layout.sendToTop(panel);109 coordinateLayout.sendToTop(panel); 96 110 bottom = false; 97 111 } else { 98 layout.sendToBottom(panel);112 coordinateLayout.sendToBottom(panel); 99 113 bottom = true; 100 114 } … … 105 119 b3.addListener(new Button.ClickListener() { 106 120 public void buttonClick(Button.ClickEvent e) { 107 layout.setBorders(!layout.hasBorders());121 coordinateLayout.setBorders(!coordinateLayout.hasBorders()); 108 122 } 109 123 }); … … 113 127 public void buttonClick(Button.ClickEvent e) { 114 128 e.getButton().setEnabled(false); 115 layout.removeComponent(dateField);129 coordinateLayout.removeComponent(dateField); 116 130 } 117 131 }); … … 120 134 b5.addListener(new Button.ClickListener() { 121 135 public void buttonClick(Button.ClickEvent e) { 122 layout.requestRepaint();123 } 124 }); 125 126 // Setup layout for splitpanel136 coordinateLayout.requestRepaint(); 137 } 138 }); 139 140 // Setup coordinateLayout for right 127 141 OrderedLayout right = new OrderedLayout(); 128 142 right.addComponent(getControlPanel(table)); … … 134 148 right.addComponent(b5); 135 149 136 // sPanel.addComponent( layout);150 // sPanel.addComponent(coordinateLayout); 137 151 // sPanel.addComponent(right); 138 152 // … … 143 157 ExpandLayout mainLayout = new ExpandLayout( 144 158 ExpandLayout.ORIENTATION_HORIZONTAL); 145 mainLayout.addComponent( layout);159 mainLayout.addComponent(coordinateLayout); 146 160 mainLayout.addComponent(right); 147 161 main.setLayout(mainLayout); … … 207 221 newCoord.setUnitsPercent(true, true, true, true, true, 208 222 true); 209 layout.setCoordinates(c, newCoord);223 coordinateLayout.setCoordinates(c, newCoord); 210 224 } 211 225 } … … 222 236 newCoord 223 237 .setUnitsPercent(true, true, true, true, true, true); 224 layout.setCoordinates(c, newCoord);238 coordinateLayout.setCoordinates(c, newCoord); 225 239 labelArray[j].setValue(new Integer(values[j])); 226 240 } -
incubator/widgets/coordinatelayout/src/com/itmill/toolkit/ui/CoordinateLayout.java
r5220 r5258 2 2 3 3 import java.util.ArrayList; 4 import java.util.Arrays; 4 5 import java.util.HashMap; 5 6 import java.util.Iterator; … … 12 13 /** 13 14 * 14 * A layout that enables absolute positioning for its children.15 * A coordinateLayout that enables absolute positioning for its children. 15 16 * 16 17 * … … 23 24 protected boolean hasBorders; 24 25 25 public static int TOP= 0;26 public static int RIGHT= 1;27 public static int BOTTOM= 2;28 public static int LEFT = 3;29 public static int WIDTH= 4;30 public static int HEIGHT= 5;31 32 /** 33 * Creates an empty coordinatelayout. 26 public static final int LEFT = 0; 27 public static final int TOP = 1; 28 public static final int WIDTH = 2; 29 public static final int HEIGHT = 3; 30 public static final int RIGHT = 4; 31 public static final int BOTTOM = 5; 32 33 /** 34 * Creates an empty coordinatelayout. The coordinateLayout is full size by default. 34 35 */ 35 36 public CoordinateLayout() { … … 44 45 /** 45 46 * 46 * Adds a component to the layout at the specified coordinates. Null 47 * arguments are not permitted and will throw an IllegalArgumentException. 47 * Adds a component to the coordinateLayout at the specified coordinates. The values 48 * are treated as pixel values by default and for example 49 * {@link com.itmill.toolkit.ui.CoordinateLayout.Coordinates#setUnitPercent(int, boolean)} 50 * can be used to set the values as percentage. 51 * 52 * The value should not be negative, except for -1 which is reserved for 53 * automatic value (terminal decides). Null argument is not permitted and 54 * will throw an IllegalArgumentException. 55 * 56 * Examples: 57 * 58 * <code>addComponent(c, 0, 0, -1, -1, -1, -1)</code> to attach to 59 * upper-left corner and let terminal decide size 60 * 61 * <code>Coordinates c = addComponent(c, 5, 5, 200, 200, -1, -1) 62 * c.setUnitPercent(CoordinateLayout.LEFT, true) 63 * c.setUnitPercent(CoordinateLayout.TOP, true) 64 * </code> to attach 5% from upper-left corner and define size to 200 x 200 65 * pixels 66 * 67 * <code>addComponent(c, 0, 0, -1, -1, 0, 0)</code> to stretch component to 68 * cover coordinateLayout area (attached to all four corners) 69 * 48 70 * 49 71 * @param c 50 72 * component to be added 73 * @param left 74 * distance of component left from coordinateLayout left 51 75 * @param top 52 * distance of component top from layout top 53 * @param right 54 * distance of component right from layout right 55 * @param bottom 56 * distance of component bottom from layout bottom 57 * @param left 58 * distance of component left from layout left 76 * distance of component top from coordinateLayout top 59 77 * @param width 60 78 * component width 61 79 * @param height 62 80 * component height 81 * @param right 82 * distance of component right from coordinateLayout right 83 * @param bottom 84 * distance of component bottom from coordinateLayout bottom 63 85 * @return the coordinates object for the component 64 86 * 65 87 * @throws IllegalArgumentException 66 88 */ 67 public Coordinates addComponent(Component c, int top, int right, 68 int bottom, int left, int width, int height) 69 throws IllegalArgumentException { 89 public Coordinates addComponent(Component c, int left, int top, int width, 90 int height, int right, int bottom) throws IllegalArgumentException { 70 91 if (c == null) { 71 92 throw new IllegalArgumentException(); 72 93 } 73 Coordinates newCoords = new Coordinates( top, right, bottom, left,74 width, height);94 Coordinates newCoords = new Coordinates(left, top, width, height, 95 right, bottom); 75 96 componentToCoord.put(c, newCoords); 76 97 addComponent(c); … … 80 101 /** 81 102 * Add a component to the specified coordinates. The string format is 82 * "top[%],right[%],bottom[%],left[%],width[%],height[%]". Null arguments 83 * will throw an IllegalArgumentException 103 * "left[%], top[%] [,width[%], height[%] [,right[%], bottom[%]]]". Null 104 * arguments will throw an IllegalArgumentException. 105 * 106 * Examples for string format: 107 * 108 * <code>addComponent(c, "0, 0")</code> to attach to upper-left corner and 109 * let terminal decide size 110 * 111 * <code>addComponent(c, "5%, 5%, 200, 200")</code> to attach 5% from 112 * upper-left corner and define size to 200 x 200 pixels 113 * 114 * <code>addComponent(c,"0, 0, , ,0, 0")</code> to stretch component to 115 * cover coordinateLayout area (attached to all four corners) 84 116 * 85 117 * @param c … … 87 119 * @param coordString 88 120 * coordinates in the specified string format 89 * @return the Coordinates object for the component121 * @return the created Coordinates object for the component 90 122 * 91 123 * @throws IllegalArgumentException … … 103 135 104 136 /** 105 * Adds a component to the layout at the specified coordinates. Null137 * Adds a component to the coordinateLayout at the specified coordinates. Null 106 138 * arguments are not permitted and will throw an IllegalArgumentException. 107 139 * … … 126 158 * permitted and will throw an IllegalArgumentException. In addition, the 127 159 * user of this method must make sure that the given component is a child of 128 * this layout.160 * this coordinateLayout. 129 161 * 130 162 * @param c … … 142 174 setCoordinates(c, new Coordinates(top, right, bottom, left, width, 143 175 height)); 144 updateContents();176 requestRepaint(); 145 177 } 146 178 … … 149 181 * permitted and will throw an IllegalArgumentException. In addition, the 150 182 * user of this method must make sure that the given component is a child of 151 * this layout.183 * this coordinateLayout. 152 184 * 153 185 * @param c … … 164 196 } 165 197 componentToCoord.put(c, coord); 166 updateContents();198 requestRepaint(); 167 199 } 168 200 169 201 public void setBorders(boolean bordersEnabled) { 170 202 hasBorders = bordersEnabled; 171 updateContents();203 requestRepaint(); 172 204 } 173 205 … … 181 213 componentList.add(c); 182 214 183 updateContents();215 requestRepaint(); 184 216 } 185 217 … … 193 225 componentList.add(0, c); 194 226 195 updateContents();196 }197 198 public void updateContents() {199 200 227 requestRepaint(); 201 228 } … … 203 230 /** 204 231 * If a component is added with this method the component is added to the 205 * top-left corner of the layout.232 * top-left corner of the coordinateLayout. 206 233 * 207 234 * @param c … … 224 251 } 225 252 super.addComponent(c); 226 updateContents();227 } 228 229 /** 230 * Removes the component from the layout. Method will throw253 requestRepaint(); 254 } 255 256 /** 257 * Removes the component from the coordinateLayout. Method will throw 231 258 * IllegalArgumentException if the given component is not a child of this 232 * layout.259 * coordinateLayout. 233 260 * 234 261 * @param c … … 246 273 componentToCoord.remove(c); 247 274 248 updateContents();275 requestRepaint(); 249 276 } 250 277 … … 252 279 * Replaces a child component with a new one. The new component uses the 253 280 * same coordinates as the previous component. If the arguments are null or 254 * the component is not a child of this layout IllegalArgumentException is281 * the component is not a child of this coordinateLayout IllegalArgumentException is 255 282 * thrown. 256 283 * … … 270 297 } 271 298 componentList.set(componentList.indexOf(c1), c2); 272 updateContents();273 } 274 275 /** 276 * Get the coordinates for a given component in this layout299 requestRepaint(); 300 } 301 302 /** 303 * Get the coordinates for a given component in this coordinateLayout 277 304 * 278 305 * @param c 279 306 * @return the Coordinates object for the given component 280 307 * @throws IllegalArgumentException 281 * thrown if component is not in this layout308 * thrown if component is not in this coordinateLayout 282 309 */ 283 310 public Coordinates getCoordinates(Component c) … … 303 330 /** 304 331 * Returns the iterator for the coordinates of the child components in this 305 * layout.332 * coordinateLayout. 306 333 * 307 334 * @return the iterator for the coordinate list … … 312 339 313 340 /** 314 * True if this layout has children341 * True if this coordinateLayout has children 315 342 * 316 343 * @return … … 376 403 377 404 target.startTag("component"); 378 379 target.startTag("coords"); 380 target.addAttribute("top", coords.getCoord(TOP)); 381 target.addAttribute("right", coords.getCoord(RIGHT)); 382 target.addAttribute("bottom", coords.getCoord(BOTTOM)); 383 target.addAttribute("left", coords.getCoord(LEFT)); 384 target.endTag("coords"); 385 386 target.startTag("dimensions"); 387 target.addAttribute("width", coords.getWidth()); 388 target.addAttribute("height", coords.getHeight()); 389 target.endTag("dimensions"); 390 391 target.startTag("isValuePercent"); 392 target.addAttribute("top", coords.isValuePercent(TOP)); 393 target.addAttribute("right", coords.isValuePercent(RIGHT)); 394 target.addAttribute("bottom", coords.isValuePercent(BOTTOM)); 395 target.addAttribute("left", coords.isValuePercent(LEFT)); 396 target.addAttribute("width", coords.isValuePercent(WIDTH)); 397 target.addAttribute("height", coords.isValuePercent(HEIGHT)); 398 target.endTag("isValuePercent"); 399 400 target.startTag("data"); 405 target.addAttribute("position", coords.toString()); 406 401 407 component.paint(target); 402 target.endTag("data");403 408 404 409 target.endTag("component"); … … 431 436 * 432 437 * @param top 433 * distance of component top from layout top438 * distance of component top from coordinateLayout top 434 439 * @param right 435 * distance of component right from layout right440 * distance of component right from coordinateLayout right 436 441 * @param bottom 437 * distance of component bottom from layout bottom442 * distance of component bottom from coordinateLayout bottom 438 443 * @param left 439 * distance of component left from layout left444 * distance of component left from coordinateLayout left 440 445 * @param width 441 446 * component width … … 447 452 */ 448 453 public Coordinates(int top, int right, int bottom, int left, int width, 449 int height) throws NumberFormatException { 454 int height) throws IllegalArgumentException { 455 450 456 properties = new int[6]; 451 452 457 isUnitPercent = new boolean[6]; 453 458 … … 460 465 properties[HEIGHT] = height; 461 466 462 java.util.Arrays.fill(isUnitPercent, false); 463 464 } 465 466 /** 467 * Create a new Coordinates object with a initialization string. The 468 * string format is 469 * "top[%],right[%],bottom[%],left[%],width[%],height[%]". 467 for (int i = 0; i < properties.length; i++) { 468 if (properties[i] < -1) { 469 throw new IllegalArgumentException( 470 "Illegal coordinate value " + properties[i]); 471 } 472 } 473 474 } 475 476 /** 470 477 * 471 478 * @param coordinateString 472 479 * @throws IllegalArgumentException 473 */ 474 public Coordinates(String coordinateString) // TODO test this 475 // properly 476 throws IllegalArgumentException { 480 * @see com.itmill.toolkit.ui.CoordinateLayout#addComponent(Component, 481 * String) 482 */ 483 public Coordinates(String coordinateString) 484 throws IllegalArgumentException {// TODO test this properly 485 477 486 properties = new int[6]; 478 479 487 isUnitPercent = new boolean[6]; 480 488 489 Arrays.fill(properties, -1); 490 481 491 String coordStringArray[] = coordinateString.split(","); 482 492 483 if (coordStringArray.length != 6) { 484 throw new IllegalArgumentException("Wrong number of arguments"); 493 if (coordStringArray.length > 6) { 494 throw new IllegalArgumentException( 495 "Incorrect string syntax: too many arguments"); 485 496 } 486 497 … … 489 500 Matcher matcher = null; 490 501 try { 491 for (int i = 0; i < 4; i++) {502 for (int i = 0; i < coordStringArray.length; i++) { 492 503 493 504 matcher = numberPattern.matcher(coordStringArray[i].trim()); 494 matcher.find(); 495 properties[i] = Integer.parseInt(matcher.group()); 496 497 isUnitPercent[i] = coordStringArray[i] 498 .matches(percentRegex); 505 if (matcher.find()) { 506 properties[i] = Integer.parseInt(matcher.group()); 507 508 isUnitPercent[i] = coordStringArray[i] 509 .matches(percentRegex); 510 } else { 511 properties[i] = -1; 512 } 499 513 } 500 514 501 matcher = numberPattern.matcher(coordStringArray[WIDTH].trim());502 matcher.find();503 properties[WIDTH] = Integer.parseInt(matcher.group());504 isUnitPercent[WIDTH] = coordStringArray[WIDTH]505 .matches(percentRegex);506 507 matcher = numberPattern508 .matcher(coordStringArray[HEIGHT].trim());509 matcher.find();510 properties[HEIGHT] = Integer.parseInt(matcher.group());511 isUnitPercent[HEIGHT] = coordStringArray[HEIGHT]512 .matches(percentRegex);513 514 515 } catch (IllegalStateException e) { 515 throw new IllegalArgumentException(e.toString()); 516 throw new IllegalArgumentException("Incorrect string syntax " 517 + e.toString()); 516 518 } 517 519 } … … 538 540 } 539 541 542 public void setUnitPercent(int valueId, boolean isPercent) { 543 isUnitPercent[valueId] = isPercent; 544 } 545 540 546 /** 541 547 * Set all the values to be treated as percentage. … … 660 666 returnString.append("%"); 661 667 } 662 returnString.append(", "); 668 if (i != properties.length - 1) { 669 returnString.append(","); 670 } 663 671 }
