1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 import java.awt.*;
29 import java.lang.reflect.*;
30 
31 public class SystemWindowAdapter
32 {
33     static public java.awt.Frame createFrame( int windowHandle )
34     {
35         String          aOS = (String) System.getProperty( "os.name" );
36         java.awt.Frame  aFrame = null;
37 
38         if( aOS.startsWith( "SunOS" ) )
39         {
40             try
41             {
42                 Class aClass = Class.forName( "sun.awt.motif.MEmbeddedFrame" );
43 
44                 if( aClass != null )
45                 {
46                     try
47                     {
48                         Constructor aCtor = aClass.getConstructor( new Class[] { long.class, boolean.class } );
49 
50                         if( aCtor != null )
51                         {
52                             aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ),
53                                                                                     new Boolean( false ) } );
54                         }
55                     }
56                     catch( Exception e )
57                     {
58                     }
59 
60                     if( aFrame == null )
61                     {
62                         try
63                         {
64                             Constructor aCtor = aClass.getConstructor( new Class[] { long.class } );
65 
66                             if( aCtor != null )
67                             {
68                                  aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } );
69                             }
70                         }
71                         catch( Exception e )
72                         {
73                         }
74                     }
75                 }
76             }
77             catch( Exception e )
78             {
79             }
80         }
81         else
82         {
83             try
84             {
85                 Class aClass = Class.forName( "sun.awt.motif.MEmbeddedFrame" );
86 
87                 if( aClass != null )
88                 {
89                     Constructor aCtor = aClass.getConstructor( new Class[] { long.class } );
90 
91                     if( aCtor != null )
92                     {
93                         aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } );
94                     }
95                 }
96             }
97             catch( Exception e )
98             {
99             }
100 
101             if( aFrame == null )
102             {
103                 try
104                 {
105                     Class aClass = Class.forName( "sun.awt.X11.XEmbeddedFrame" );
106 
107                     if( aClass != null )
108                     {
109                         Constructor aCtor = aClass.getConstructor( new Class[] { long.class } );
110 
111                         if( aCtor != null )
112                             aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } );
113                     }
114                 }
115                 catch( Exception e )
116                 {
117                 }
118             }
119         }
120 
121         return aFrame;
122     }
123 }
124