461 * @see #changedUpdate 462 */ 463 protected void updateLayout(DocumentEvent.ElementChange ec, 464 DocumentEvent e, Shape a) { 465 if (ec != null) { 466 // the newly inserted children don't have a valid 467 // offset so the child locator needs to be messaged 468 // that the child prior to the new children has 469 // changed size. 470 int index = Math.max(ec.getIndex() - 1, 0); 471 ChildState cs = getChildState(index); 472 locator.childChanged(cs); 473 } 474 } 475 476 // --- View methods ------------------------------------ 477 478 /** 479 * Sets the parent of the view. 480 * This is reimplemented to provide the superclass 481 * behavior as well as calling the <code>loadChildren</code> 482 * method if this view does not already have children. 483 * The children should not be loaded in the 484 * constructor because the act of setting the parent 485 * may cause them to try to search up the hierarchy 486 * (to get the hosting Container for example). 487 * If this view has children (the view is being moved 488 * from one place in the view hierarchy to another), 489 * the <code>loadChildren</code> method will not be called. 490 * 491 * @param parent the parent of the view, null if none 492 */ 493 public void setParent(View parent) { 494 super.setParent(parent); 495 if ((parent != null) && (getViewCount() == 0)) { 496 ViewFactory f = getViewFactory(); 497 loadChildren(f); 498 } 499 } 500 501 /** 502 * Child views can call this on the parent to indicate that 503 * the preference has changed and should be reconsidered 504 * for layout. This is reimplemented to queue new work 505 * on the layout thread. This method gets messaged from 506 * multiple threads via the children. 507 * 508 * @param child the child view 509 * @param width true if the width preference has changed 537 * Sets the size of the view. This should cause 538 * layout of the view if the view caches any layout 539 * information. 540 * <p> 541 * Since the major axis is updated asynchronously and should be 542 * the sum of the tiled children the call is ignored for the major 543 * axis. Since the minor axis is flexible, work is queued to resize 544 * the children if the minor span changes. 545 * 546 * @param width the width >= 0 547 * @param height the height >= 0 548 */ 549 public void setSize(float width, float height) { 550 setSpanOnAxis(X_AXIS, width); 551 setSpanOnAxis(Y_AXIS, height); 552 } 553 554 /** 555 * Retrieves the size of the view along an axis. 556 * 557 * @param axis may be either <code>View.X_AXIS</code> or 558 * <code>View.Y_AXIS</code> 559 * @return the current span of the view along the given axis, >= 0 560 */ 561 float getSpanOnAxis(int axis) { 562 if (axis == getMajorAxis()) { 563 return majorSpan; 564 } 565 return minorSpan; 566 } 567 568 /** 569 * Sets the size of the view along an axis. Since the major 570 * axis is updated asynchronously and should be the sum of the 571 * tiled children the call is ignored for the major axis. Since 572 * the minor axis is flexible, work is queued to resize the 573 * children if the minor span changes. 574 * 575 * @param axis may be either <code>View.X_AXIS</code> or 576 * <code>View.Y_AXIS</code> 577 * @param span the span to layout to >= 0 578 */ 579 void setSpanOnAxis(int axis, float span) { 580 float margin = getInsetSpan(axis); 581 if (axis == getMinorAxis()) { 582 float targetSpan = span - margin; 583 if (targetSpan != minorSpan) { 584 minorSpan = targetSpan; 585 586 // mark all of the ChildState instances as needing to 587 // resize the child, and queue up work to fix them. 588 int n = getViewCount(); 589 if (n != 0) { 590 LayoutQueue q = getLayoutQueue(); 591 for (int i = 0; i < n; i++) { 592 ChildState cs = getChildState(i); 593 cs.childSizeValid = false; 594 q.addTask(cs); 595 } 596 q.addTask(flushTask); 839 } 840 return pos; 841 } 842 843 /** 844 * Provides a way to determine the next visually represented model 845 * location that one might place a caret. Some views may not be visible, 846 * they might not be in the same order found in the model, or they just 847 * might not allow access to some of the locations in the model. 848 * This method enables specifying a position to convert 849 * within the range of >=0. If the value is -1, a position 850 * will be calculated automatically. If the value < -1, 851 * the {@code BadLocationException} will be thrown. 852 * 853 * @param pos the position to convert 854 * @param a the allocated region to render into 855 * @param direction the direction from the current position that can 856 * be thought of as the arrow keys typically found on a keyboard; 857 * this may be one of the following: 858 * <ul style="list-style-type:none"> 859 * <li><code>SwingConstants.WEST</code></li> 860 * <li><code>SwingConstants.EAST</code></li> 861 * <li><code>SwingConstants.NORTH</code></li> 862 * <li><code>SwingConstants.SOUTH</code></li> 863 * </ul> 864 * @param biasRet an array contain the bias that was checked 865 * @return the location within the model that best represents the next 866 * location visual position 867 * @exception BadLocationException the given position is not a valid 868 * position within the document 869 * @exception IllegalArgumentException if <code>direction</code> is invalid 870 */ 871 public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, 872 int direction, 873 Position.Bias[] biasRet) 874 throws BadLocationException { 875 if (pos < -1 || pos > getDocument().getLength()) { 876 throw new BadLocationException("invalid position", pos); 877 } 878 return Utilities.getNextVisualPositionFrom( 879 this, pos, b, a, direction, biasRet); 880 } 881 882 // --- variables ----------------------------------------- 883 884 /** 885 * The major axis against which the children are 886 * tiled. 887 */ 888 int axis; 889 | 461 * @see #changedUpdate 462 */ 463 protected void updateLayout(DocumentEvent.ElementChange ec, 464 DocumentEvent e, Shape a) { 465 if (ec != null) { 466 // the newly inserted children don't have a valid 467 // offset so the child locator needs to be messaged 468 // that the child prior to the new children has 469 // changed size. 470 int index = Math.max(ec.getIndex() - 1, 0); 471 ChildState cs = getChildState(index); 472 locator.childChanged(cs); 473 } 474 } 475 476 // --- View methods ------------------------------------ 477 478 /** 479 * Sets the parent of the view. 480 * This is reimplemented to provide the superclass 481 * behavior as well as calling the {@code loadChildren} 482 * method if this view does not already have children. 483 * The children should not be loaded in the 484 * constructor because the act of setting the parent 485 * may cause them to try to search up the hierarchy 486 * (to get the hosting Container for example). 487 * If this view has children (the view is being moved 488 * from one place in the view hierarchy to another), 489 * the {@code loadChildren} method will not be called. 490 * 491 * @param parent the parent of the view, null if none 492 */ 493 public void setParent(View parent) { 494 super.setParent(parent); 495 if ((parent != null) && (getViewCount() == 0)) { 496 ViewFactory f = getViewFactory(); 497 loadChildren(f); 498 } 499 } 500 501 /** 502 * Child views can call this on the parent to indicate that 503 * the preference has changed and should be reconsidered 504 * for layout. This is reimplemented to queue new work 505 * on the layout thread. This method gets messaged from 506 * multiple threads via the children. 507 * 508 * @param child the child view 509 * @param width true if the width preference has changed 537 * Sets the size of the view. This should cause 538 * layout of the view if the view caches any layout 539 * information. 540 * <p> 541 * Since the major axis is updated asynchronously and should be 542 * the sum of the tiled children the call is ignored for the major 543 * axis. Since the minor axis is flexible, work is queued to resize 544 * the children if the minor span changes. 545 * 546 * @param width the width >= 0 547 * @param height the height >= 0 548 */ 549 public void setSize(float width, float height) { 550 setSpanOnAxis(X_AXIS, width); 551 setSpanOnAxis(Y_AXIS, height); 552 } 553 554 /** 555 * Retrieves the size of the view along an axis. 556 * 557 * @param axis may be either {@code View.X_AXIS} or 558 * {@code View.Y_AXIS} 559 * @return the current span of the view along the given axis, >= 0 560 */ 561 float getSpanOnAxis(int axis) { 562 if (axis == getMajorAxis()) { 563 return majorSpan; 564 } 565 return minorSpan; 566 } 567 568 /** 569 * Sets the size of the view along an axis. Since the major 570 * axis is updated asynchronously and should be the sum of the 571 * tiled children the call is ignored for the major axis. Since 572 * the minor axis is flexible, work is queued to resize the 573 * children if the minor span changes. 574 * 575 * @param axis may be either {@code View.X_AXIS} or 576 * {@code View.Y_AXIS} 577 * @param span the span to layout to >= 0 578 */ 579 void setSpanOnAxis(int axis, float span) { 580 float margin = getInsetSpan(axis); 581 if (axis == getMinorAxis()) { 582 float targetSpan = span - margin; 583 if (targetSpan != minorSpan) { 584 minorSpan = targetSpan; 585 586 // mark all of the ChildState instances as needing to 587 // resize the child, and queue up work to fix them. 588 int n = getViewCount(); 589 if (n != 0) { 590 LayoutQueue q = getLayoutQueue(); 591 for (int i = 0; i < n; i++) { 592 ChildState cs = getChildState(i); 593 cs.childSizeValid = false; 594 q.addTask(cs); 595 } 596 q.addTask(flushTask); 839 } 840 return pos; 841 } 842 843 /** 844 * Provides a way to determine the next visually represented model 845 * location that one might place a caret. Some views may not be visible, 846 * they might not be in the same order found in the model, or they just 847 * might not allow access to some of the locations in the model. 848 * This method enables specifying a position to convert 849 * within the range of >=0. If the value is -1, a position 850 * will be calculated automatically. If the value < -1, 851 * the {@code BadLocationException} will be thrown. 852 * 853 * @param pos the position to convert 854 * @param a the allocated region to render into 855 * @param direction the direction from the current position that can 856 * be thought of as the arrow keys typically found on a keyboard; 857 * this may be one of the following: 858 * <ul style="list-style-type:none"> 859 * <li>{@code SwingConstants.WEST}</li> 860 * <li>{@code SwingConstants.EAST}</li> 861 * <li>{@code SwingConstants.NORTH}</li> 862 * <li>{@code SwingConstants.SOUTH}</li> 863 * </ul> 864 * @param biasRet an array contain the bias that was checked 865 * @return the location within the model that best represents the next 866 * location visual position 867 * @exception BadLocationException the given position is not a valid 868 * position within the document 869 * @exception IllegalArgumentException if {@code direction} is invalid 870 */ 871 public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, 872 int direction, 873 Position.Bias[] biasRet) 874 throws BadLocationException { 875 if (pos < -1 || pos > getDocument().getLength()) { 876 throw new BadLocationException("invalid position", pos); 877 } 878 return Utilities.getNextVisualPositionFrom( 879 this, pos, b, a, direction, biasRet); 880 } 881 882 // --- variables ----------------------------------------- 883 884 /** 885 * The major axis against which the children are 886 * tiled. 887 */ 888 int axis; 889 |