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://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.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:
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(this).addDirtyRegion(this, x, y, width, height);
4806 }
4807
4808
4809 /**
4810 * Adds the specified region to the dirty region list if the component
4811 * is showing. The component will be repainted after all of the
4812 * currently pending events have been dispatched.
4813 *
4814 * @param r a <code>Rectangle</code> containing the dirty region
4815 * @see #isPaintingOrigin()
4816 * @see java.awt.Component#isShowing
4817 * @see RepaintManager#addDirtyRegion
4818 */
4819 public void repaint(Rectangle r) {
4820 repaint(0,r.x,r.y,r.width,r.height);
4821 }
4822
4823
4824 /**
4825 * Supports deferred automatic layout.
4839 * internal layout of this component has been affected. This automatic
4840 * updating differs from the AWT because programs generally no
4841 * longer need to invoke <code>validate</code> to get the contents of the
4842 * GUI to update.
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://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.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:
4786 Autoscroller.stop(this);
4787 }
4788 }
4789
4790
4791 /**
4792 * Adds the specified region to the dirty region list if the component
4793 * is showing. The component will be repainted after all of the
4794 * currently pending events have been dispatched.
4795 *
4796 * @param tm this parameter is not used
4797 * @param x the x value of the dirty region
4798 * @param y the y value of the dirty region
4799 * @param width the width of the dirty region
4800 * @param height the height of the dirty region
4801 * @see #isPaintingOrigin()
4802 * @see java.awt.Component#isShowing
4803 * @see RepaintManager#addDirtyRegion
4804 */
4805 public void repaint(long tm, int x, int y, int width, int height) {
4806 RepaintManager.currentManager(SunToolkit.targetToAppContext(this))
4807 .addDirtyRegion(this, x, y, width, height);
4808 }
4809
4810
4811 /**
4812 * Adds the specified region to the dirty region list if the component
4813 * is showing. The component will be repainted after all of the
4814 * currently pending events have been dispatched.
4815 *
4816 * @param r a <code>Rectangle</code> containing the dirty region
4817 * @see #isPaintingOrigin()
4818 * @see java.awt.Component#isShowing
4819 * @see RepaintManager#addDirtyRegion
4820 */
4821 public void repaint(Rectangle r) {
4822 repaint(0,r.x,r.y,r.width,r.height);
4823 }
4824
4825
4826 /**
4827 * Supports deferred automatic layout.
4841 * internal layout of this component has been affected. This automatic
4842 * updating differs from the AWT because programs generally no
4843 * longer need to invoke <code>validate</code> to get the contents of the
4844 * GUI to update.
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 SunToolkit.executeOnEventHandlerThread(this, () -> {
4876 synchronized(JComponent.this) {
4877 setFlag(REVALIDATE_RUNNABLE_SCHEDULED, false);
4878 }
4879 revalidate();
4880 });
4881 }
4882 }
4883
4884 /**
4885 * If this method returns true, <code>revalidate</code> calls by
4886 * descendants of this component will cause the entire tree
4887 * beginning with this root to be validated.
4888 * Returns false by default. <code>JScrollPane</code> overrides
4889 * this method and returns true.
4890 *
4891 * @return always returns false
4892 * @see #revalidate
4893 * @see java.awt.Component#invalidate
4894 * @see java.awt.Container#validate
4895 * @see java.awt.Container#isValidateRoot
4896 */
4897 @Override
4898 public boolean isValidateRoot() {
4899 return false;
4900 }
|