< prev index next >

src/java.desktop/share/classes/sun/awt/PaintEventDispatcher.java

Print this page




  23  * questions.
  24  */
  25 package sun.awt;
  26 
  27 import java.awt.Component;
  28 import java.awt.Rectangle;
  29 import java.awt.event.PaintEvent;
  30 
  31 /**
  32  * PaintEventDispatcher is responsible for dispatching PaintEvents.  There
  33  * can be only one PaintEventDispatcher active at a particular time.
  34  *
  35  */
  36 public class PaintEventDispatcher {
  37     /**
  38      * Singleton dispatcher.
  39      */
  40     private static PaintEventDispatcher dispatcher;
  41 
  42     /**
  43      * Sets the current <code>PaintEventDispatcher</code>.
  44      *
  45      * @param dispatcher PaintEventDispatcher
  46      */
  47     public static void setPaintEventDispatcher(
  48                           PaintEventDispatcher dispatcher) {
  49         synchronized(PaintEventDispatcher.class) {
  50             PaintEventDispatcher.dispatcher = dispatcher;
  51         }
  52     }
  53 
  54     /**
  55      * Returns the currently active <code>PaintEventDispatcher</code>.  This
  56      * will never return null.
  57      *
  58      * @return PaintEventDispatcher
  59      */
  60     public static PaintEventDispatcher getPaintEventDispatcher() {
  61         synchronized(PaintEventDispatcher.class) {
  62             if (dispatcher == null) {
  63                 dispatcher = new PaintEventDispatcher();
  64             }
  65             return dispatcher;
  66         }
  67     }
  68 
  69     /**
  70      * Creates and returns the <code>PaintEvent</code> that should be
  71      * dispatched for the specified component.  If this returns null
  72      * no <code>PaintEvent</code> is dispatched.
  73      * <p>
  74      * <b>WARNING:</b> This is invoked from the native thread, be careful
  75      * what methods you end up invoking here.
  76      */
  77     public PaintEvent createPaintEvent(Component target, int x, int y, int w,
  78                                        int h) {
  79 
  80         return new PaintEvent(target, PaintEvent.PAINT,
  81                               new Rectangle(x, y, w, h));
  82     }
  83 
  84     /**
  85      * Returns true if a native background erase should be done for
  86      * the specified Component.
  87      */
  88     public boolean shouldDoNativeBackgroundErase(Component c) {
  89         return true;
  90     }
  91 
  92     /**


  23  * questions.
  24  */
  25 package sun.awt;
  26 
  27 import java.awt.Component;
  28 import java.awt.Rectangle;
  29 import java.awt.event.PaintEvent;
  30 
  31 /**
  32  * PaintEventDispatcher is responsible for dispatching PaintEvents.  There
  33  * can be only one PaintEventDispatcher active at a particular time.
  34  *
  35  */
  36 public class PaintEventDispatcher {
  37     /**
  38      * Singleton dispatcher.
  39      */
  40     private static PaintEventDispatcher dispatcher;
  41 
  42     /**
  43      * Sets the current {@code PaintEventDispatcher}.
  44      *
  45      * @param dispatcher PaintEventDispatcher
  46      */
  47     public static void setPaintEventDispatcher(
  48                           PaintEventDispatcher dispatcher) {
  49         synchronized(PaintEventDispatcher.class) {
  50             PaintEventDispatcher.dispatcher = dispatcher;
  51         }
  52     }
  53 
  54     /**
  55      * Returns the currently active {@code PaintEventDispatcher}.  This
  56      * will never return null.
  57      *
  58      * @return PaintEventDispatcher
  59      */
  60     public static PaintEventDispatcher getPaintEventDispatcher() {
  61         synchronized(PaintEventDispatcher.class) {
  62             if (dispatcher == null) {
  63                 dispatcher = new PaintEventDispatcher();
  64             }
  65             return dispatcher;
  66         }
  67     }
  68 
  69     /**
  70      * Creates and returns the {@code PaintEvent} that should be
  71      * dispatched for the specified component.  If this returns null
  72      * no {@code PaintEvent} is dispatched.
  73      * <p>
  74      * <b>WARNING:</b> This is invoked from the native thread, be careful
  75      * what methods you end up invoking here.
  76      */
  77     public PaintEvent createPaintEvent(Component target, int x, int y, int w,
  78                                        int h) {
  79 
  80         return new PaintEvent(target, PaintEvent.PAINT,
  81                               new Rectangle(x, y, w, h));
  82     }
  83 
  84     /**
  85      * Returns true if a native background erase should be done for
  86      * the specified Component.
  87      */
  88     public boolean shouldDoNativeBackgroundErase(Component c) {
  89         return true;
  90     }
  91 
  92     /**
< prev index next >