src/solaris/classes/sun/awt/X11/XComponentPeer.java

Print this page




  65 import sun.util.logging.PlatformLogger;
  66 import sun.awt.*;
  67 import sun.awt.event.IgnorePaintEvent;
  68 import sun.awt.image.SunVolatileImage;
  69 import sun.awt.image.ToolkitImage;
  70 import sun.java2d.BackBufferCapsProvider;
  71 import sun.java2d.pipe.Region;
  72 
  73 public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer,
  74     BackBufferCapsProvider
  75 {
  76     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer");
  77     private static final PlatformLogger buffersLog = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer.multibuffer");
  78     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XComponentPeer");
  79     private static final PlatformLogger fontLog = PlatformLogger.getLogger("sun.awt.X11.font.XComponentPeer");
  80     private static final PlatformLogger enableLog = PlatformLogger.getLogger("sun.awt.X11.enable.XComponentPeer");
  81     private static final PlatformLogger shapeLog = PlatformLogger.getLogger("sun.awt.X11.shape.XComponentPeer");
  82 
  83     boolean paintPending = false;
  84     boolean isLayouting = false;
  85     boolean enabled;
  86 
  87     // Actually used only by XDecoratedPeer
  88     protected int boundsOperation;
  89 
  90     Color foreground;
  91     Color background;
  92 
  93     // Colors calculated as on Motif using MotifColorUtilties.
  94     // If you use these, call updateMotifColors() in the peer's Constructor and
  95     // setBackground().  Examples are XCheckboxPeer and XButtonPeer.
  96     Color darkShadow;
  97     Color lightShadow;
  98     Color selectColor;
  99 
 100     Font font;
 101     private long backBuffer = 0;
 102     private VolatileImage xBackBuffer = null;
 103 
 104     static Color[] systemColors;
 105 


 111     }
 112 
 113     XComponentPeer(Component target, long parentWindow, Rectangle bounds) {
 114         super(target, parentWindow, bounds);
 115     }
 116 
 117     /**
 118      * Standard peer constructor, with corresponding Component
 119      */
 120     XComponentPeer(Component target) {
 121         super(target);
 122     }
 123 
 124 
 125     void preInit(XCreateWindowParams params) {
 126         super.preInit(params);
 127         boundsOperation = DEFAULT_OPERATION;
 128     }
 129     void postInit(XCreateWindowParams params) {
 130         super.postInit(params);
 131         Color c;
 132         Font  f;
 133         Cursor cursor;
 134 
 135         pSetCursor(target.getCursor());
 136 
 137         foreground = target.getForeground();
 138         background = target.getBackground();
 139         font = target.getFont();
 140 
 141         if (isInitialReshape()) {
 142             Rectangle r = target.getBounds();
 143             reshape(r.x, r.y, r.width, r.height);
 144         }
 145 
 146         enabled = target.isEnabled();
 147 
 148         // If any of our heavyweight ancestors are disable, we should be too
 149         // See 6176875 for more information
 150         Component comp = target;
 151         while( !(comp == null || comp instanceof Window) ) {
 152             comp = comp.getParent();
 153             if( comp != null && !comp.isEnabled() && !comp.isLightweight() ){
 154                 setEnabled(false);
 155                 break;
 156             }
 157         }
 158         enableLog.fine("Initial enable state: {0}", Boolean.valueOf(enabled));
 159 
 160         if (target.isVisible()) {
 161             setVisible(true);
 162         }
 163     }
 164 
 165     protected boolean isInitialReshape() {
 166         return true;
 167     }
 168 
 169     public void reparent(ContainerPeer newNativeParent) {
 170         XComponentPeer newPeer = (XComponentPeer)newNativeParent;
 171         XToolkit.awtLock();
 172         try {
 173             XlibWrapper.XReparentWindow(XToolkit.getDisplay(), getWindow(), newPeer.getContentWindow(), x, y);
 174             parentWindow = newPeer;
 175         } finally {
 176             XToolkit.awtUnlock();
 177         }
 178     }


 367         }
 368     }
 369 
 370     void handleJavaWindowFocusEvent(AWTEvent e) {
 371     }
 372 
 373     /*************************************************
 374      * END OF FOCUS STUFF
 375      *************************************************/
 376 
 377 
 378 
 379     public void setVisible(boolean b) {
 380         xSetVisible(b);
 381     }
 382 
 383     public void hide() {
 384         setVisible(false);
 385     }
 386 
 387 
 388     /**
 389      * @see java.awt.peer.ComponentPeer
 390      */
 391     public void setEnabled(boolean value) {
 392         enableLog.fine("{0}ing {1}", (value?"Enabl":"Disabl"), this);
 393         boolean repaintNeeded = (enabled != value);
 394         enabled = value;














 395         if (target instanceof Container) {
 396             Component list[] = ((Container)target).getComponents();
 397             for (int i = 0; i < list.length; ++i) {
 398                 boolean childEnabled = list[i].isEnabled();
 399                 ComponentPeer p = list[i].getPeer();
 400                 if ( p != null ) {
 401                     p.setEnabled(value && childEnabled);
 402                 }
 403             }
 404         }
 405         if (repaintNeeded) {
 406             repaint();
 407         }
 408     }
 409 
 410     //
 411     // public so aw/Window can call it
 412     //
 413     public boolean isEnabled() {

 414         return enabled;
 415     }
 416 
 417 
 418 
 419     public void enable() {
 420         setEnabled(true);
 421     }
 422 
 423     public void disable() {
 424         setEnabled(false);
 425     }
 426     @Override
 427     public void paint(final Graphics g) {
 428         super.paint(g);
 429         // allow target to change the picture
 430         target.paint(g);
 431     }
 432 
 433     public Graphics getGraphics() {
 434         return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont());
 435     }
 436     public void print(Graphics g) {
 437         // clear rect here to emulate X clears rect before Expose
 438         g.setColor(target.getBackground());
 439         g.fillRect(0, 0, target.getWidth(), target.getHeight());
 440         g.setColor(target.getForeground());
 441         // paint peer
 442         paintPeer(g);
 443         // allow target to change the picture
 444         target.print(g);
 445     }




  65 import sun.util.logging.PlatformLogger;
  66 import sun.awt.*;
  67 import sun.awt.event.IgnorePaintEvent;
  68 import sun.awt.image.SunVolatileImage;
  69 import sun.awt.image.ToolkitImage;
  70 import sun.java2d.BackBufferCapsProvider;
  71 import sun.java2d.pipe.Region;
  72 
  73 public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer,
  74     BackBufferCapsProvider
  75 {
  76     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer");
  77     private static final PlatformLogger buffersLog = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer.multibuffer");
  78     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XComponentPeer");
  79     private static final PlatformLogger fontLog = PlatformLogger.getLogger("sun.awt.X11.font.XComponentPeer");
  80     private static final PlatformLogger enableLog = PlatformLogger.getLogger("sun.awt.X11.enable.XComponentPeer");
  81     private static final PlatformLogger shapeLog = PlatformLogger.getLogger("sun.awt.X11.shape.XComponentPeer");
  82 
  83     boolean paintPending = false;
  84     boolean isLayouting = false;
  85     private boolean enabled;
  86 
  87     // Actually used only by XDecoratedPeer
  88     protected int boundsOperation;
  89 
  90     Color foreground;
  91     Color background;
  92 
  93     // Colors calculated as on Motif using MotifColorUtilties.
  94     // If you use these, call updateMotifColors() in the peer's Constructor and
  95     // setBackground().  Examples are XCheckboxPeer and XButtonPeer.
  96     Color darkShadow;
  97     Color lightShadow;
  98     Color selectColor;
  99 
 100     Font font;
 101     private long backBuffer = 0;
 102     private VolatileImage xBackBuffer = null;
 103 
 104     static Color[] systemColors;
 105 


 111     }
 112 
 113     XComponentPeer(Component target, long parentWindow, Rectangle bounds) {
 114         super(target, parentWindow, bounds);
 115     }
 116 
 117     /**
 118      * Standard peer constructor, with corresponding Component
 119      */
 120     XComponentPeer(Component target) {
 121         super(target);
 122     }
 123 
 124 
 125     void preInit(XCreateWindowParams params) {
 126         super.preInit(params);
 127         boundsOperation = DEFAULT_OPERATION;
 128     }
 129     void postInit(XCreateWindowParams params) {
 130         super.postInit(params);



 131 
 132         pSetCursor(target.getCursor());
 133 
 134         foreground = target.getForeground();
 135         background = target.getBackground();
 136         font = target.getFont();
 137 
 138         if (isInitialReshape()) {
 139             Rectangle r = target.getBounds();
 140             reshape(r.x, r.y, r.width, r.height);
 141         }
 142 
 143         setEnabled(target.isEnabled());












 144 
 145         if (target.isVisible()) {
 146             setVisible(true);
 147         }
 148     }
 149 
 150     protected boolean isInitialReshape() {
 151         return true;
 152     }
 153 
 154     public void reparent(ContainerPeer newNativeParent) {
 155         XComponentPeer newPeer = (XComponentPeer)newNativeParent;
 156         XToolkit.awtLock();
 157         try {
 158             XlibWrapper.XReparentWindow(XToolkit.getDisplay(), getWindow(), newPeer.getContentWindow(), x, y);
 159             parentWindow = newPeer;
 160         } finally {
 161             XToolkit.awtUnlock();
 162         }
 163     }


 352         }
 353     }
 354 
 355     void handleJavaWindowFocusEvent(AWTEvent e) {
 356     }
 357 
 358     /*************************************************
 359      * END OF FOCUS STUFF
 360      *************************************************/
 361 
 362 
 363 
 364     public void setVisible(boolean b) {
 365         xSetVisible(b);
 366     }
 367 
 368     public void hide() {
 369         setVisible(false);
 370     }
 371 

 372     /**
 373      * @see java.awt.peer.ComponentPeer
 374      */
 375     public void setEnabled(final boolean value) {
 376         if (enableLog.isLoggable(PlatformLogger.FINE)) {
 377             enableLog.fine("{0}ing {1}", (value ? "Enabl" : "Disabl"), this);
 378         }
 379         boolean status = value;
 380         // If any of our heavyweight ancestors are disable, we should be too
 381         // See 6176875 for more information
 382         final Container cp = SunToolkit.getNativeContainer(target);
 383         if (cp != null) {
 384             status &= ((XComponentPeer) cp.getPeer()).isEnabled();
 385         }
 386         synchronized (getStateLock()) {
 387             if (enabled == status) {
 388                 return;
 389             }
 390             enabled = status;
 391         }
 392 
 393         if (target instanceof Container) {
 394             final Component[] list = ((Container) target).getComponents();
 395             for (final Component child : list) {
 396                 final ComponentPeer p = child.getPeer();
 397                 if (p != null) {
 398                     p.setEnabled(status && child.isEnabled());

 399                 }
 400             }
 401         }

 402         repaint();
 403     }

 404 
 405     //
 406     // public so aw/Window can call it
 407     //
 408     public final boolean isEnabled() {
 409         synchronized (getStateLock()) {
 410             return enabled;
 411         }





 412     }
 413 



 414     @Override
 415     public void paint(final Graphics g) {
 416         super.paint(g);
 417         // allow target to change the picture
 418         target.paint(g);
 419     }
 420 
 421     public Graphics getGraphics() {
 422         return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont());
 423     }
 424     public void print(Graphics g) {
 425         // clear rect here to emulate X clears rect before Expose
 426         g.setColor(target.getBackground());
 427         g.fillRect(0, 0, target.getWidth(), target.getHeight());
 428         g.setColor(target.getForeground());
 429         // paint peer
 430         paintPeer(g);
 431         // allow target to change the picture
 432         target.print(g);
 433     }