1 /*
   2  * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.X11;
  27 
  28 import sun.awt.EmbeddedFrame;
  29 import java.awt.*;
  30 import java.awt.AWTKeyStroke;
  31 import java.util.logging.Logger;
  32 
  33 public class XEmbeddedFrame extends EmbeddedFrame {
  34 
  35     private static final Logger log = Logger.getLogger(XEmbeddedFrame.class.getName());
  36 
  37     long handle;
  38     public XEmbeddedFrame() {
  39     }
  40 
  41     // handle should be a valid X Window.
  42     public XEmbeddedFrame(long handle) {
  43         this(handle, false);
  44     }
  45 
  46     // Handle is the valid X window
  47     public XEmbeddedFrame(long handle, boolean supportsXEmbed, boolean isTrayIconWindow) {
  48         super(handle, supportsXEmbed);
  49 
  50         if (isTrayIconWindow) {
  51             XTrayIconPeer.suppressWarningString(this);
  52         }
  53 
  54         this.handle = handle;
  55         if (handle != 0) { // Has actual parent
  56             addNotify();
  57             if (!isTrayIconWindow) {
  58                 show();
  59             }
  60         }
  61     }
  62 
  63     public void addNotify()
  64     {
  65         if (getPeer() == null) {
  66             XToolkit toolkit = (XToolkit)Toolkit.getDefaultToolkit();
  67             setPeer(toolkit.createEmbeddedFrame(this));
  68         }
  69         super.addNotify();
  70     }
  71 
  72     public XEmbeddedFrame(long handle, boolean supportsXEmbed) {
  73         this(handle, supportsXEmbed, false);
  74     }
  75 
  76     /*
  77      * The method shouldn't be called in case of active XEmbed.
  78      */
  79     public boolean traverseIn(boolean direction) {
  80         XEmbeddedFramePeer peer = (XEmbeddedFramePeer)getPeer();
  81         if (peer != null) {
  82             if (peer.supportsXEmbed() && peer.isXEmbedActive()) {
  83                 log.fine("The method shouldn't be called when XEmbed is active!");
  84             } else {
  85                 return super.traverseIn(direction);
  86             }
  87         }
  88         return false;
  89     }
  90 
  91     protected boolean traverseOut(boolean direction) {
  92         XEmbeddedFramePeer xefp = (XEmbeddedFramePeer) getPeer();
  93         if (direction == FORWARD) {
  94             xefp.traverseOutForward();
  95         }
  96         else {
  97             xefp.traverseOutBackward();
  98         }
  99         return true;
 100     }
 101 
 102     /*
 103      * The method shouldn't be called in case of active XEmbed.
 104      */
 105     public void synthesizeWindowActivation(boolean doActivate) {
 106         XEmbeddedFramePeer peer = (XEmbeddedFramePeer)getPeer();
 107         if (peer != null) {
 108             if (peer.supportsXEmbed() && peer.isXEmbedActive()) {
 109                 log.fine("The method shouldn't be called when XEmbed is active!");
 110             } else {
 111                 peer.synthesizeFocusInOut(doActivate);
 112             }
 113         }
 114     }
 115 
 116     public void registerAccelerator(AWTKeyStroke stroke) {
 117         XEmbeddedFramePeer xefp = (XEmbeddedFramePeer) getPeer();
 118         if (xefp != null) {
 119             xefp.registerAccelerator(stroke);
 120         }
 121     }
 122     public void unregisterAccelerator(AWTKeyStroke stroke) {
 123         XEmbeddedFramePeer xefp = (XEmbeddedFramePeer) getPeer();
 124         if (xefp != null) {
 125             xefp.unregisterAccelerator(stroke);
 126         }
 127     }
 128 }