46 import java.beans.PropertyChangeListener;
47 import java.beans.VetoableChangeListener;
48 import java.beans.VetoableChangeSupport;
49 import java.beans.Transient;
50
51 import java.applet.Applet;
52
53 import java.io.Serializable;
54 import java.io.ObjectOutputStream;
55 import java.io.ObjectInputStream;
56 import java.io.IOException;
57 import java.io.ObjectInputValidation;
58 import java.io.InvalidObjectException;
59
60 import javax.swing.border.*;
61 import javax.swing.event.*;
62 import javax.swing.plaf.*;
63 import static javax.swing.ClientPropertyKey.*;
64 import javax.accessibility.*;
65
66 import sun.swing.SwingUtilities2;
67 import sun.swing.UIClientPropertyKey;
68
69 /**
70 * The base class for all Swing components except top-level containers.
71 * To use a component that inherits from <code>JComponent</code>,
72 * you must place the component in a containment hierarchy
73 * whose root is a top-level Swing container.
74 * Top-level Swing containers --
75 * such as <code>JFrame</code>, <code>JDialog</code>,
76 * and <code>JApplet</code> --
77 * are specialized components
78 * that provide a place for other Swing components to paint themselves.
79 * For an explanation of containment hierarchies, see
80 * <a
81 href="http://java.sun.com/docs/books/tutorial/uiswing/overview/hierarchy.html">Swing Components and the Containment Hierarchy</a>,
82 * a section in <em>The Java Tutorial</em>.
83 *
84 * <p>
85 * The <code>JComponent</code> class provides:
4784 Autoscroller.stop(this);
4785 }
4786 }
4787
4788
4789 /**
4790 * Adds the specified region to the dirty region list if the component
4791 * is showing. The component will be repainted after all of the
4792 * currently pending events have been dispatched.
4793 *
4794 * @param tm this parameter is not used
4795 * @param x the x value of the dirty region
4796 * @param y the y value of the dirty region
4797 * @param width the width of the dirty region
4798 * @param height the height of the dirty region
4799 * @see #isPaintingOrigin()
4800 * @see java.awt.Component#isShowing
4801 * @see RepaintManager#addDirtyRegion
4802 */
4803 public void repaint(long tm, int x, int y, int width, int height) {
4804 RepaintManager.currentManager(this).addDirtyRegion(this, x, y, width, height);
4805 }
4806
4807
4808 /**
4809 * Adds the specified region to the dirty region list if the component
4810 * is showing. The component will be repainted after all of the
4811 * currently pending events have been dispatched.
4812 *
4813 * @param r a <code>Rectangle</code> containing the dirty region
4814 * @see #isPaintingOrigin()
4815 * @see java.awt.Component#isShowing
4816 * @see RepaintManager#addDirtyRegion
4817 */
4818 public void repaint(Rectangle r) {
4819 repaint(0,r.x,r.y,r.width,r.height);
4820 }
4821
4822
4823 /**
4824 * Supports deferred automatic layout.
4839 * updating differs from the AWT because programs generally no
4840 * longer need to invoke <code>validate</code> to get the contents of the
4841 * GUI to update.
4842 * <p>
4843 *
4844 * @see java.awt.Component#invalidate
4845 * @see java.awt.Container#validate
4846 * @see #isValidateRoot
4847 * @see RepaintManager#addInvalidComponent
4848 */
4849 public void revalidate() {
4850 if (getParent() == null) {
4851 // Note: We don't bother invalidating here as once added
4852 // to a valid parent invalidate will be invoked (addImpl
4853 // invokes addNotify which will invoke invalidate on the
4854 // new Component). Also, if we do add a check to isValid
4855 // here it can potentially be called before the constructor
4856 // which was causing some people grief.
4857 return;
4858 }
4859 if (SwingUtilities.isEventDispatchThread()) {
4860 invalidate();
4861 RepaintManager.currentManager(this).addInvalidComponent(this);
4862 }
4863 else {
4864 // To avoid a flood of Runnables when constructing GUIs off
4865 // the EDT, a flag is maintained as to whether or not
4866 // a Runnable has been scheduled.
4867 synchronized(this) {
4868 if (getFlag(REVALIDATE_RUNNABLE_SCHEDULED)) {
4869 return;
4870 }
4871 setFlag(REVALIDATE_RUNNABLE_SCHEDULED, true);
4872 }
4873 Runnable callRevalidate = new Runnable() {
4874 public void run() {
4875 synchronized(JComponent.this) {
4876 setFlag(REVALIDATE_RUNNABLE_SCHEDULED, false);
4877 }
4878 revalidate();
4879 }
4880 };
4881 SwingUtilities.invokeLater(callRevalidate);
4882 }
4883 }
4884
4885 /**
4886 * If this method returns true, <code>revalidate</code> calls by
4887 * descendants of this component will cause the entire tree
4888 * beginning with this root to be validated.
4889 * Returns false by default. <code>JScrollPane</code> overrides
4890 * this method and returns true.
4891 *
4892 * @return always returns false
4893 * @see #revalidate
4894 * @see java.awt.Component#invalidate
4895 * @see java.awt.Container#validate
4896 * @see java.awt.Container#isValidateRoot
4897 */
4898 @Override
4899 public boolean isValidateRoot() {
4900 return false;
4901 }
|
46 import java.beans.PropertyChangeListener;
47 import java.beans.VetoableChangeListener;
48 import java.beans.VetoableChangeSupport;
49 import java.beans.Transient;
50
51 import java.applet.Applet;
52
53 import java.io.Serializable;
54 import java.io.ObjectOutputStream;
55 import java.io.ObjectInputStream;
56 import java.io.IOException;
57 import java.io.ObjectInputValidation;
58 import java.io.InvalidObjectException;
59
60 import javax.swing.border.*;
61 import javax.swing.event.*;
62 import javax.swing.plaf.*;
63 import static javax.swing.ClientPropertyKey.*;
64 import javax.accessibility.*;
65
66 import sun.awt.SunToolkit;
67 import sun.swing.SwingUtilities2;
68 import sun.swing.UIClientPropertyKey;
69
70 /**
71 * The base class for all Swing components except top-level containers.
72 * To use a component that inherits from <code>JComponent</code>,
73 * you must place the component in a containment hierarchy
74 * whose root is a top-level Swing container.
75 * Top-level Swing containers --
76 * such as <code>JFrame</code>, <code>JDialog</code>,
77 * and <code>JApplet</code> --
78 * are specialized components
79 * that provide a place for other Swing components to paint themselves.
80 * For an explanation of containment hierarchies, see
81 * <a
82 href="http://java.sun.com/docs/books/tutorial/uiswing/overview/hierarchy.html">Swing Components and the Containment Hierarchy</a>,
83 * a section in <em>The Java Tutorial</em>.
84 *
85 * <p>
86 * The <code>JComponent</code> class provides:
4785 Autoscroller.stop(this);
4786 }
4787 }
4788
4789
4790 /**
4791 * Adds the specified region to the dirty region list if the component
4792 * is showing. The component will be repainted after all of the
4793 * currently pending events have been dispatched.
4794 *
4795 * @param tm this parameter is not used
4796 * @param x the x value of the dirty region
4797 * @param y the y value of the dirty region
4798 * @param width the width of the dirty region
4799 * @param height the height of the dirty region
4800 * @see #isPaintingOrigin()
4801 * @see java.awt.Component#isShowing
4802 * @see RepaintManager#addDirtyRegion
4803 */
4804 public void repaint(long tm, int x, int y, int width, int height) {
4805 RepaintManager.currentManager(SunToolkit.targetToAppContext(this))
4806 .addDirtyRegion(this, x, y, width, height);
4807 }
4808
4809
4810 /**
4811 * Adds the specified region to the dirty region list if the component
4812 * is showing. The component will be repainted after all of the
4813 * currently pending events have been dispatched.
4814 *
4815 * @param r a <code>Rectangle</code> containing the dirty region
4816 * @see #isPaintingOrigin()
4817 * @see java.awt.Component#isShowing
4818 * @see RepaintManager#addDirtyRegion
4819 */
4820 public void repaint(Rectangle r) {
4821 repaint(0,r.x,r.y,r.width,r.height);
4822 }
4823
4824
4825 /**
4826 * Supports deferred automatic layout.
4841 * updating differs from the AWT because programs generally no
4842 * longer need to invoke <code>validate</code> to get the contents of the
4843 * GUI to update.
4844 * <p>
4845 *
4846 * @see java.awt.Component#invalidate
4847 * @see java.awt.Container#validate
4848 * @see #isValidateRoot
4849 * @see RepaintManager#addInvalidComponent
4850 */
4851 public void revalidate() {
4852 if (getParent() == null) {
4853 // Note: We don't bother invalidating here as once added
4854 // to a valid parent invalidate will be invoked (addImpl
4855 // invokes addNotify which will invoke invalidate on the
4856 // new Component). Also, if we do add a check to isValid
4857 // here it can potentially be called before the constructor
4858 // which was causing some people grief.
4859 return;
4860 }
4861 if (SunToolkit.isDispatchThreadForAppContext(this)) {
4862 invalidate();
4863 RepaintManager.currentManager(this).addInvalidComponent(this);
4864 }
4865 else {
4866 // To avoid a flood of Runnables when constructing GUIs off
4867 // the EDT, a flag is maintained as to whether or not
4868 // a Runnable has been scheduled.
4869 synchronized(this) {
4870 if (getFlag(REVALIDATE_RUNNABLE_SCHEDULED)) {
4871 return;
4872 }
4873 setFlag(REVALIDATE_RUNNABLE_SCHEDULED, true);
4874 }
4875 Runnable callRevalidate = new Runnable() {
4876 public void run() {
4877 synchronized(JComponent.this) {
4878 setFlag(REVALIDATE_RUNNABLE_SCHEDULED, false);
4879 }
4880 revalidate();
4881 }
4882 };
4883 SunToolkit.executeOnEventHandlerThread(this, callRevalidate);
4884 }
4885 }
4886
4887 /**
4888 * If this method returns true, <code>revalidate</code> calls by
4889 * descendants of this component will cause the entire tree
4890 * beginning with this root to be validated.
4891 * Returns false by default. <code>JScrollPane</code> overrides
4892 * this method and returns true.
4893 *
4894 * @return always returns false
4895 * @see #revalidate
4896 * @see java.awt.Component#invalidate
4897 * @see java.awt.Container#validate
4898 * @see java.awt.Container#isValidateRoot
4899 */
4900 @Override
4901 public boolean isValidateRoot() {
4902 return false;
4903 }
|