1 /*
   2  * Copyright (c) 2004, 2014, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import sun.awt.X11.XEmbeddedFrame;
  25 
  26 import java.awt.*;
  27 import java.io.BufferedReader;
  28 import java.io.File;
  29 import java.io.FileReader;
  30 
  31 /*
  32  * @summary GUI of XEmbedMemoryTestTask. It creates an SWT shell on which an
  33  *          AWT Frame is embedded. Components will be added in the AWT frame
  34  *          and checked for any memory leak when they are removed.
  35  * @author Girish R (girish.ramachandran@sun.com), AWT-SQE
  36  */
  37 
  38 public class GUIXEmbedMemory extends Frame {
  39 
  40     XEmbeddedFrame frame;
  41     String windowID;
  42     Process process;
  43     static String WINDOW_ID_FILE = "window_id";
  44 
  45     public void destroyProcess() {
  46         if (process != null)
  47             process.destroy();
  48     }
  49 
  50     public GUIXEmbedMemory() throws Exception {
  51         //Check if the OS is Solaris or Linux and the toolkit is XToolkit
  52         String osName = System.getProperty("os.name");
  53         if (!osName.equals("Linux") && !osName.equals("SunOS")) {
  54             return;
  55         }
  56         process = Runtime.getRuntime().exec("./gtk-embedder");
  57 
  58         File file = new File(WINDOW_ID_FILE);
  59         int waitCount = 0;
  60         while (!file.exists() && waitCount < 20) {
  61             try { Thread.sleep(100); } catch (Exception e) {}
  62             waitCount++;
  63         }
  64 
  65         windowID = new BufferedReader(new FileReader(file)).readLine();
  66 
  67         long window = Long.decode(windowID).longValue();
  68         frame = new XEmbeddedFrame(window);
  69 
  70         frame.setLayout(new FlowLayout());
  71         frame.setSize(500, 270);
  72 
  73         frame.setBackground(Color.red);
  74     }
  75 }