jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java
changeset 3938 ef327bd847c0
parent 2805 9f18d7e66042
child 4214 0fa32d38146b
equal deleted inserted replaced
3934:487e1aa949c4 3938:ef327bd847c0
    64 import java.security.*;
    64 import java.security.*;
    65 import java.util.Collection;
    65 import java.util.Collection;
    66 import java.util.HashSet;
    66 import java.util.HashSet;
    67 import java.util.Set;
    67 import java.util.Set;
    68 import java.util.Vector;
    68 import java.util.Vector;
    69 import java.util.logging.*;
    69 import sun.util.logging.PlatformLogger;
       
    70 
    70 import sun.awt.*;
    71 import sun.awt.*;
    71 import sun.awt.event.IgnorePaintEvent;
    72 import sun.awt.event.IgnorePaintEvent;
    72 import sun.awt.image.SunVolatileImage;
    73 import sun.awt.image.SunVolatileImage;
    73 import sun.awt.image.ToolkitImage;
    74 import sun.awt.image.ToolkitImage;
    74 import sun.java2d.BackBufferCapsProvider;
    75 import sun.java2d.BackBufferCapsProvider;
    75 import sun.java2d.pipe.Region;
    76 import sun.java2d.pipe.Region;
    76 
    77 
    77 public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer,
    78 public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer,
    78     BackBufferCapsProvider
    79     BackBufferCapsProvider
    79 {
    80 {
    80     private static final Logger log = Logger.getLogger("sun.awt.X11.XComponentPeer");
    81     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer");
    81     private static final Logger buffersLog = Logger.getLogger("sun.awt.X11.XComponentPeer.multibuffer");
    82     private static final PlatformLogger buffersLog = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer.multibuffer");
    82     private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XComponentPeer");
    83     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XComponentPeer");
    83     private static final Logger fontLog = Logger.getLogger("sun.awt.X11.font.XComponentPeer");
    84     private static final PlatformLogger fontLog = PlatformLogger.getLogger("sun.awt.X11.font.XComponentPeer");
    84     private static final Logger enableLog = Logger.getLogger("sun.awt.X11.enable.XComponentPeer");
    85     private static final PlatformLogger enableLog = PlatformLogger.getLogger("sun.awt.X11.enable.XComponentPeer");
    85     private static final Logger shapeLog = Logger.getLogger("sun.awt.X11.shape.XComponentPeer");
    86     private static final PlatformLogger shapeLog = PlatformLogger.getLogger("sun.awt.X11.shape.XComponentPeer");
    86 
    87 
    87     boolean paintPending = false;
    88     boolean paintPending = false;
    88     boolean isLayouting = false;
    89     boolean isLayouting = false;
    89     boolean enabled;
    90     boolean enabled;
    90 
    91 
   157             if( comp != null && !comp.isEnabled() && !comp.isLightweight() ){
   158             if( comp != null && !comp.isEnabled() && !comp.isLightweight() ){
   158                 setEnabled(false);
   159                 setEnabled(false);
   159                 break;
   160                 break;
   160             }
   161             }
   161         }
   162         }
   162         enableLog.log(Level.FINE, "Initial enable state: {0}", new Object[] {Boolean.valueOf(enabled)});
   163         enableLog.fine("Initial enable state: {0}", Boolean.valueOf(enabled));
   163 
   164 
   164         if (target.isVisible()) {
   165         if (target.isVisible()) {
   165             setVisible(true);
   166             setVisible(true);
   166         }
   167         }
   167     }
   168     }
   251 
   252 
   252     /**
   253     /**
   253      * Called when component receives focus
   254      * Called when component receives focus
   254      */
   255      */
   255     public void focusGained(FocusEvent e) {
   256     public void focusGained(FocusEvent e) {
   256         focusLog.log(Level.FINE, "{0}", new Object[] {e});
   257         focusLog.fine("{0}", e);
   257         bHasFocus = true;
   258         bHasFocus = true;
   258     }
   259     }
   259 
   260 
   260     /**
   261     /**
   261      * Called when component loses focus
   262      * Called when component loses focus
   262      */
   263      */
   263     public void focusLost(FocusEvent e) {
   264     public void focusLost(FocusEvent e) {
   264         focusLog.log(Level.FINE, "{0}", new Object[] {e});
   265         focusLog.fine("{0}", e);
   265         bHasFocus = false;
   266         bHasFocus = false;
   266     }
   267     }
   267 
   268 
   268     public boolean isFocusable() {
   269     public boolean isFocusable() {
   269         /* should be implemented by other sub-classes */
   270         /* should be implemented by other sub-classes */
   331           case XKeyboardFocusManagerPeer.SNFH_FAILURE:
   332           case XKeyboardFocusManagerPeer.SNFH_FAILURE:
   332               return false;
   333               return false;
   333           case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
   334           case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
   334               // Currently we just generate focus events like we deal with lightweight instead of calling
   335               // Currently we just generate focus events like we deal with lightweight instead of calling
   335               // XSetInputFocus on native window
   336               // XSetInputFocus on native window
   336               if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Proceeding with request to " +
   337               if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Proceeding with request to " +
   337                   lightweightChild + " in " + target);
   338                   lightweightChild + " in " + target);
   338               /**
   339               /**
   339                * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
   340                * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
   340                * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
   341                * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
   341                * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
   342                * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
   356                * when a component inside a Frame is requesting focus.
   357                * when a component inside a Frame is requesting focus.
   357                * See 6314575 for details.
   358                * See 6314575 for details.
   358                */
   359                */
   359               boolean res = wpeer.requestWindowFocus(null);
   360               boolean res = wpeer.requestWindowFocus(null);
   360 
   361 
   361               if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Requested window focus: " + res);
   362               if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Requested window focus: " + res);
   362               // If parent window can be made focused and has been made focused(synchronously)
   363               // If parent window can be made focused and has been made focused(synchronously)
   363               // then we can proceed with children, otherwise we retreat.
   364               // then we can proceed with children, otherwise we retreat.
   364               if (!(res && parentWindow.isFocused())) {
   365               if (!(res && parentWindow.isFocused())) {
   365                   return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
   366                   return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
   366               }
   367               }
   376         }
   377         }
   377         return false;
   378         return false;
   378     }
   379     }
   379 
   380 
   380     private boolean rejectFocusRequestHelper(String logMsg) {
   381     private boolean rejectFocusRequestHelper(String logMsg) {
   381         if (focusLog.isLoggable(Level.FINER)) focusLog.finer(logMsg);
   382         if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(logMsg);
   382         XKeyboardFocusManagerPeer.removeLastFocusRequest(target);
   383         XKeyboardFocusManagerPeer.removeLastFocusRequest(target);
   383         return false;
   384         return false;
   384     }
   385     }
   385 
   386 
   386     void handleJavaFocusEvent(AWTEvent e) {
   387     void handleJavaFocusEvent(AWTEvent e) {
   387         if (focusLog.isLoggable(Level.FINER)) focusLog.finer(e.toString());
   388         if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(e.toString());
   388         if (e.getID() == FocusEvent.FOCUS_GAINED) {
   389         if (e.getID() == FocusEvent.FOCUS_GAINED) {
   389             focusGained((FocusEvent)e);
   390             focusGained((FocusEvent)e);
   390         } else {
   391         } else {
   391             focusLost((FocusEvent)e);
   392             focusLost((FocusEvent)e);
   392         }
   393         }
   412 
   413 
   413     /**
   414     /**
   414      * @see java.awt.peer.ComponentPeer
   415      * @see java.awt.peer.ComponentPeer
   415      */
   416      */
   416     public void setEnabled(boolean value) {
   417     public void setEnabled(boolean value) {
   417         enableLog.log(Level.FINE, "{0}ing {1}", new Object[] {(value?"Enabl":"Disabl"), this});
   418         enableLog.fine("{0}ing {1}", (value?"Enabl":"Disabl"), this);
   418         boolean repaintNeeded = (enabled != value);
   419         boolean repaintNeeded = (enabled != value);
   419         enabled = value;
   420         enabled = value;
   420         if (target instanceof Container) {
   421         if (target instanceof Container) {
   421             Component list[] = ((Container)target).getComponents();
   422             Component list[] = ((Container)target).getComponents();
   422             for (int i = 0; i < list.length; ++i) {
   423             for (int i = 0; i < list.length; ++i) {
   688         g.drawLine(x+1, y+height, x+width, y+height); // bottom
   689         g.drawLine(x+1, y+height, x+width, y+height); // bottom
   689         g.drawLine(x+width, y+height, x+width, y+1);  // right
   690         g.drawLine(x+width, y+height, x+width, y+1);  // right
   690     }
   691     }
   691 
   692 
   692     public void setBackground(Color c) {
   693     public void setBackground(Color c) {
   693         if (log.isLoggable(Level.FINE)) log.fine("Set background to " + c);
   694         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set background to " + c);
   694         synchronized (getStateLock()) {
   695         synchronized (getStateLock()) {
   695             background = c;
   696             background = c;
   696         }
   697         }
   697         super.setBackground(c);
   698         super.setBackground(c);
   698         repaint();
   699         repaint();
   699     }
   700     }
   700 
   701 
   701     public void setForeground(Color c) {
   702     public void setForeground(Color c) {
   702         if (log.isLoggable(Level.FINE)) log.fine("Set foreground to " + c);
   703         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set foreground to " + c);
   703         synchronized (getStateLock()) {
   704         synchronized (getStateLock()) {
   704             foreground = c;
   705             foreground = c;
   705         }
   706         }
   706         repaint();
   707         repaint();
   707     }
   708     }
   716      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
   717      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
   717      * @see       Toolkit#getFontMetrics(Font)
   718      * @see       Toolkit#getFontMetrics(Font)
   718      * @since     JDK1.0
   719      * @since     JDK1.0
   719      */
   720      */
   720     public FontMetrics getFontMetrics(Font font) {
   721     public FontMetrics getFontMetrics(Font font) {
   721         if (fontLog.isLoggable(Level.FINE)) fontLog.fine("Getting font metrics for " + font);
   722         if (fontLog.isLoggable(PlatformLogger.FINE)) fontLog.fine("Getting font metrics for " + font);
   722         return sun.font.FontDesignMetrics.getMetrics(font);
   723         return sun.font.FontDesignMetrics.getMetrics(font);
   723     }
   724     }
   724 
   725 
   725     public void setFont(Font f) {
   726     public void setFont(Font f) {
   726         synchronized (getStateLock()) {
   727         synchronized (getStateLock()) {
  1186     private BufferCapabilities backBufferCaps;
  1187     private BufferCapabilities backBufferCaps;
  1187 
  1188 
  1188     public void createBuffers(int numBuffers, BufferCapabilities caps)
  1189     public void createBuffers(int numBuffers, BufferCapabilities caps)
  1189       throws AWTException
  1190       throws AWTException
  1190     {
  1191     {
  1191         if (buffersLog.isLoggable(Level.FINE)) {
  1192         if (buffersLog.isLoggable(PlatformLogger.FINE)) {
  1192             buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")");
  1193             buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")");
  1193         }
  1194         }
  1194         // set the caps first, they're used when creating the bb
  1195         // set the caps first, they're used when creating the bb
  1195         backBufferCaps = caps;
  1196         backBufferCaps = caps;
  1196         backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps);
  1197         backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps);
  1204     }
  1205     }
  1205 
  1206 
  1206     public void flip(int x1, int y1, int x2, int y2,
  1207     public void flip(int x1, int y1, int x2, int y2,
  1207                      BufferCapabilities.FlipContents flipAction)
  1208                      BufferCapabilities.FlipContents flipAction)
  1208     {
  1209     {
  1209         if (buffersLog.isLoggable(Level.FINE)) {
  1210         if (buffersLog.isLoggable(PlatformLogger.FINE)) {
  1210             buffersLog.fine("flip(" + flipAction + ")");
  1211             buffersLog.fine("flip(" + flipAction + ")");
  1211         }
  1212         }
  1212         if (backBuffer == 0) {
  1213         if (backBuffer == 0) {
  1213             throw new IllegalStateException("Buffers have not been created");
  1214             throw new IllegalStateException("Buffers have not been created");
  1214         }
  1215         }
  1215         graphicsConfig.flip(this, target, xBackBuffer,
  1216         graphicsConfig.flip(this, target, xBackBuffer,
  1216                             x1, y1, x2, y2, flipAction);
  1217                             x1, y1, x2, y2, flipAction);
  1217     }
  1218     }
  1218 
  1219 
  1219     public Image getBackBuffer() {
  1220     public Image getBackBuffer() {
  1220         if (buffersLog.isLoggable(Level.FINE)) {
  1221         if (buffersLog.isLoggable(PlatformLogger.FINE)) {
  1221             buffersLog.fine("getBackBuffer()");
  1222             buffersLog.fine("getBackBuffer()");
  1222         }
  1223         }
  1223         if (backBuffer == 0) {
  1224         if (backBuffer == 0) {
  1224             throw new IllegalStateException("Buffers have not been created");
  1225             throw new IllegalStateException("Buffers have not been created");
  1225         }
  1226         }
  1226         return xBackBuffer;
  1227         return xBackBuffer;
  1227     }
  1228     }
  1228 
  1229 
  1229     public void destroyBuffers() {
  1230     public void destroyBuffers() {
  1230         if (buffersLog.isLoggable(Level.FINE)) {
  1231         if (buffersLog.isLoggable(PlatformLogger.FINE)) {
  1231             buffersLog.fine("destroyBuffers()");
  1232             buffersLog.fine("destroyBuffers()");
  1232         }
  1233         }
  1233         graphicsConfig.destroyBackBuffer(backBuffer);
  1234         graphicsConfig.destroyBackBuffer(backBuffer);
  1234         backBuffer = 0;
  1235         backBuffer = 0;
  1235         xBackBuffer = null;
  1236         xBackBuffer = null;
  1260      * Returns true if this event is disabled and shouldn't be processed by window
  1261      * Returns true if this event is disabled and shouldn't be processed by window
  1261      * Currently if target component is disabled the following event will be disabled on window:
  1262      * Currently if target component is disabled the following event will be disabled on window:
  1262      * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify
  1263      * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify
  1263      */
  1264      */
  1264     protected boolean isEventDisabled(XEvent e) {
  1265     protected boolean isEventDisabled(XEvent e) {
  1265         enableLog.log(Level.FINEST, "Component is {1}, checking for disabled event {0}", new Object[] {e, (isEnabled()?"enabled":"disable")});
  1266         enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable"));
  1266         if (!isEnabled()) {
  1267         if (!isEnabled()) {
  1267             switch (e.get_type()) {
  1268             switch (e.get_type()) {
  1268               case XConstants.ButtonPress:
  1269               case XConstants.ButtonPress:
  1269               case XConstants.ButtonRelease:
  1270               case XConstants.ButtonRelease:
  1270               case XConstants.KeyPress:
  1271               case XConstants.KeyPress:
  1271               case XConstants.KeyRelease:
  1272               case XConstants.KeyRelease:
  1272               case XConstants.EnterNotify:
  1273               case XConstants.EnterNotify:
  1273               case XConstants.LeaveNotify:
  1274               case XConstants.LeaveNotify:
  1274               case XConstants.MotionNotify:
  1275               case XConstants.MotionNotify:
  1275                   enableLog.log(Level.FINER, "Event {0} is disable", new Object[] {e});
  1276                   enableLog.finer("Event {0} is disable", e);
  1276                   return true;
  1277                   return true;
  1277             }
  1278             }
  1278         }
  1279         }
  1279         switch(e.get_type()) {
  1280         switch(e.get_type()) {
  1280           case XConstants.MapNotify:
  1281           case XConstants.MapNotify:
  1391      * Applies the shape to the X-window.
  1392      * Applies the shape to the X-window.
  1392      * @since 1.7
  1393      * @since 1.7
  1393      */
  1394      */
  1394     public void applyShape(Region shape) {
  1395     public void applyShape(Region shape) {
  1395         if (XlibUtil.isShapingSupported()) {
  1396         if (XlibUtil.isShapingSupported()) {
  1396             if (shapeLog.isLoggable(Level.FINER)) {
  1397             if (shapeLog.isLoggable(PlatformLogger.FINER)) {
  1397                 shapeLog.finer(
  1398                 shapeLog.finer(
  1398                         "*** INFO: Setting shape: PEER: " + this
  1399                         "*** INFO: Setting shape: PEER: " + this
  1399                         + "; WINDOW: " + getWindow()
  1400                         + "; WINDOW: " + getWindow()
  1400                         + "; TARGET: " + target
  1401                         + "; TARGET: " + target
  1401                         + "; SHAPE: " + shape);
  1402                         + "; SHAPE: " + shape);
  1421                 }
  1422                 }
  1422             } finally {
  1423             } finally {
  1423                 XToolkit.awtUnlock();
  1424                 XToolkit.awtUnlock();
  1424             }
  1425             }
  1425         } else {
  1426         } else {
  1426             if (shapeLog.isLoggable(Level.FINER)) {
  1427             if (shapeLog.isLoggable(PlatformLogger.FINER)) {
  1427                 shapeLog.finer("*** WARNING: Shaping is NOT supported!");
  1428                 shapeLog.finer("*** WARNING: Shaping is NOT supported!");
  1428             }
  1429             }
  1429         }
  1430         }
  1430     }
  1431     }
  1431 
  1432