jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java
changeset 2459 08f3416ff334
parent 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
2458:f4bee3ba17ee 2459:08f3416ff334
    25 package sun.awt.X11;
    25 package sun.awt.X11;
    26 
    26 
    27 import java.awt.*;
    27 import java.awt.*;
    28 import java.awt.peer.*;
    28 import java.awt.peer.*;
    29 
    29 
    30 import sun.awt.ComponentAccessor;
       
    31 import sun.awt.SunToolkit;
    30 import sun.awt.SunToolkit;
    32 
    31 
    33 import sun.awt.X11GraphicsConfig;
    32 import sun.awt.X11GraphicsConfig;
    34 import sun.awt.X11GraphicsDevice;
    33 import sun.awt.X11GraphicsDevice;
    35 
    34 
    52         if (SunToolkit.getSunAwtNoerasebackground()) {
    51         if (SunToolkit.getSunAwtNoerasebackground()) {
    53             disableBackgroundErase();
    52             disableBackgroundErase();
    54         }
    53         }
    55     }
    54     }
    56 
    55 
    57     void resetTargetGC(Component target) {
    56     /* Get a GraphicsConfig with the same visual on the new
    58         ComponentAccessor.resetGC(target);
    57      * screen, which should be easy in Xinerama mode.
       
    58      */
       
    59     public GraphicsConfiguration getAppropriateGraphicsConfiguration(
       
    60                                     GraphicsConfiguration gc)
       
    61     {
       
    62         if (graphicsConfig == null || gc == null) {
       
    63             return gc;
       
    64         }
       
    65         // Opt: Only need to do if we're not using the default GC
       
    66 
       
    67         int screenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen();
       
    68 
       
    69         X11GraphicsConfig parentgc;
       
    70         // save vis id of current gc
       
    71         int visual = graphicsConfig.getVisual();
       
    72 
       
    73         X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment.
       
    74             getLocalGraphicsEnvironment().
       
    75             getScreenDevices()[screenNum];
       
    76 
       
    77         for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) {
       
    78             if (visual == newDev.getConfigVisualId(i, screenNum)) {
       
    79                 // use that
       
    80                 graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i];
       
    81                 break;
       
    82             }
       
    83         }
       
    84         // just in case...
       
    85         if (graphicsConfig == null) {
       
    86             graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment.
       
    87                 getLocalGraphicsEnvironment().
       
    88                 getScreenDevices()[screenNum].
       
    89                 getDefaultConfiguration();
       
    90         }
       
    91 
       
    92         return graphicsConfig;
    59     }
    93     }
    60 
    94 
    61     /*
       
    62      * Called when the Window this
       
    63      * Canvas is on is moved onto another Xinerama screen.
       
    64      *
       
    65      * Canvases can be created with a non-defulat GraphicsConfiguration.  The
       
    66      * GraphicsConfiguration needs to be changed to one on the new screen,
       
    67      * preferably with the same visual ID.
       
    68      *
       
    69      * Up-called for other windows peer instances (XPanelPeer, XWindowPeer).
       
    70      *
       
    71      * Should only be called from the event thread.
       
    72      */
       
    73     public void displayChanged(int screenNum) {
       
    74         resetLocalGC(screenNum);
       
    75         resetTargetGC(target);
       
    76     }
       
    77 
       
    78     /* Set graphicsConfig to a GraphicsConfig with the same visual on the new
       
    79      * screen, which should be easy in Xinerama mode.
       
    80      *
       
    81      * Should only be called from displayChanged(), and therefore only from
       
    82      * the event thread.
       
    83      */
       
    84     void resetLocalGC(int screenNum) {
       
    85         // Opt: Only need to do if we're not using the default GC
       
    86         if (graphicsConfig != null) {
       
    87             X11GraphicsConfig parentgc;
       
    88             // save vis id of current gc
       
    89             int visual = graphicsConfig.getVisual();
       
    90 
       
    91             X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment.
       
    92                 getLocalGraphicsEnvironment().
       
    93                 getScreenDevices()[screenNum];
       
    94 
       
    95             for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) {
       
    96                 if (visual == newDev.getConfigVisualId(i, screenNum)) {
       
    97                     // use that
       
    98                     graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i];
       
    99                     break;
       
   100                 }
       
   101             }
       
   102             // just in case...
       
   103             if (graphicsConfig == null) {
       
   104                 graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment.
       
   105                     getLocalGraphicsEnvironment().
       
   106                     getScreenDevices()[screenNum].
       
   107                     getDefaultConfiguration();
       
   108             }
       
   109         }
       
   110     }
       
   111     protected boolean shouldFocusOnClick() {
    95     protected boolean shouldFocusOnClick() {
   112         // Canvas should always be able to be focused by mouse clicks.
    96         // Canvas should always be able to be focused by mouse clicks.
   113         return true;
    97         return true;
   114     }
    98     }
   115 
    99