2744 /** 2745 * Prompts the layout manager to lay out this component. This is 2746 * usually called when the component (more specifically, container) 2747 * is validated. 2748 * @see #validate 2749 * @see LayoutManager 2750 */ 2751 public void doLayout() { 2752 layout(); 2753 } 2754 2755 /** 2756 * @deprecated As of JDK version 1.1, 2757 * replaced by <code>doLayout()</code>. 2758 */ 2759 @Deprecated 2760 public void layout() { 2761 } 2762 2763 /** 2764 * Ensures that this component has a valid layout. This method is 2765 * primarily intended to operate on instances of <code>Container</code>. 2766 * @see #invalidate 2767 * @see #doLayout() 2768 * @see LayoutManager 2769 * @see Container#validate 2770 * @since JDK1.0 2771 */ 2772 public void validate() { 2773 synchronized (getTreeLock()) { 2774 ComponentPeer peer = this.peer; 2775 boolean wasValid = isValid(); 2776 if (!wasValid && peer != null) { 2777 Font newfont = getFont(); 2778 Font oldfont = peerFont; 2779 if (newfont != oldfont && (oldfont == null 2780 || !oldfont.equals(newfont))) { 2781 peer.setFont(newfont); 2782 peerFont = newfont; 2783 } 2784 peer.layout(); 2785 } 2786 valid = true; 2787 if (!wasValid) { 2788 mixOnValidating(); 2789 } 2790 } 2791 } 2792 2793 /** 2794 * Invalidates this component. This component and all parents 2795 * above it are marked as needing to be laid out. This method can 2796 * be called often, so it needs to execute quickly. 2797 * @see #validate 2798 * @see #doLayout 2799 * @see LayoutManager 2800 * @since JDK1.0 2801 */ 2802 public void invalidate() { 2803 synchronized (getTreeLock()) { 2804 /* Nullify cached layout and size information. 2805 * For efficiency, propagate invalidate() upwards only if 2806 * some other component hasn't already done so first. 2807 */ 2808 valid = false; 2809 if (!isPreferredSizeSet()) { 2810 prefSize = null; 2811 } 2812 if (!isMinimumSizeSet()) { 2813 minSize = null; 2814 } 2815 if (!isMaximumSizeSet()) { 2816 maxSize = null; 2817 } 2818 if (parent != null) { 2819 parent.invalidateIfValid(); 2820 } 2821 } 2822 } 2823 2824 /** Invalidates the component unless it is already invalid. 2825 */ 2826 final void invalidateIfValid() { 2827 if (isValid()) { 2828 invalidate(); 2829 } 2830 } 2831 2832 /** 2833 * Creates a graphics context for this component. This method will 2834 * return <code>null</code> if this component is currently not 2835 * displayable. 2836 * @return a graphics context for this component, or <code>null</code> 2837 * if it has none 2838 * @see #paint 2839 * @since JDK1.0 2840 */ 2841 public Graphics getGraphics() { 2842 if (peer instanceof LightweightPeer) { | 2744 /** 2745 * Prompts the layout manager to lay out this component. This is 2746 * usually called when the component (more specifically, container) 2747 * is validated. 2748 * @see #validate 2749 * @see LayoutManager 2750 */ 2751 public void doLayout() { 2752 layout(); 2753 } 2754 2755 /** 2756 * @deprecated As of JDK version 1.1, 2757 * replaced by <code>doLayout()</code>. 2758 */ 2759 @Deprecated 2760 public void layout() { 2761 } 2762 2763 /** 2764 * Validates this component. 2765 * <p> 2766 * The meaning of the term <i>validating</i> is defined by the ancestors of 2767 * this class. See {@link Container#validate} for more details. 2768 * 2769 * @see #invalidate 2770 * @see #doLayout() 2771 * @see LayoutManager 2772 * @see Container#validate 2773 * @since JDK1.0 2774 */ 2775 public void validate() { 2776 synchronized (getTreeLock()) { 2777 ComponentPeer peer = this.peer; 2778 boolean wasValid = isValid(); 2779 if (!wasValid && peer != null) { 2780 Font newfont = getFont(); 2781 Font oldfont = peerFont; 2782 if (newfont != oldfont && (oldfont == null 2783 || !oldfont.equals(newfont))) { 2784 peer.setFont(newfont); 2785 peerFont = newfont; 2786 } 2787 peer.layout(); 2788 } 2789 valid = true; 2790 if (!wasValid) { 2791 mixOnValidating(); 2792 } 2793 } 2794 } 2795 2796 /** 2797 * Invalidates this component and its ancestors. 2798 * <p> 2799 * All ancestors of this component up to the nearest validate root (or up 2800 * to the root of the hierarchy if there's no a validate root container 2801 * present) are marked invalid also. Marking a container <i>invalid</i> 2802 * indicates that the container needs to be laid out. 2803 * <p> 2804 * This method is called automatically when any layout-related information 2805 * changes (e.g. setting the bounds of the component, or adding the 2806 * component to a container). 2807 * <p> 2808 * This method can be called often, so it should work fast. 2809 * 2810 * @see #validate 2811 * @see #doLayout 2812 * @see LayoutManager 2813 * @see java.awt.Container#isValidateRoot 2814 * @since JDK1.0 2815 */ 2816 public void invalidate() { 2817 synchronized (getTreeLock()) { 2818 /* Nullify cached layout and size information. 2819 * For efficiency, propagate invalidate() upwards only if 2820 * some other component hasn't already done so first. 2821 */ 2822 valid = false; 2823 if (!isPreferredSizeSet()) { 2824 prefSize = null; 2825 } 2826 if (!isMinimumSizeSet()) { 2827 minSize = null; 2828 } 2829 if (!isMaximumSizeSet()) { 2830 maxSize = null; 2831 } 2832 invalidateParent(); 2833 } 2834 } 2835 2836 /** 2837 * Invalidates the parent of this component if any. 2838 * 2839 * This method MUST BE invoked under the TreeLock. 2840 */ 2841 void invalidateParent() { 2842 if (parent != null) { 2843 parent.invalidateIfValid(); 2844 } 2845 } 2846 2847 /** Invalidates the component unless it is already invalid. 2848 */ 2849 final void invalidateIfValid() { 2850 if (isValid()) { 2851 invalidate(); 2852 } 2853 } 2854 2855 /** 2856 * Creates a graphics context for this component. This method will 2857 * return <code>null</code> if this component is currently not 2858 * displayable. 2859 * @return a graphics context for this component, or <code>null</code> 2860 * if it has none 2861 * @see #paint 2862 * @since JDK1.0 2863 */ 2864 public Graphics getGraphics() { 2865 if (peer instanceof LightweightPeer) { |