merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / java / perftest / WindowAdapter.java
blob992fa2d0fcf5c65344e02fb9e25f735b8a387bad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WindowAdapter.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 import sun.awt.*;
32 import com.sun.star.awt.*;
35 public class WindowAdapter
36 // defacto implementing the interface, but not deriving from it, since
37 // we're no real XInterface here
38 // implements com.sun.star.awt.XWindow
40 // the frame object we're generating. TODO: Remove public access.
41 public java.awt.Frame frame;
42 private boolean fullscreen;
44 public WindowAdapter( int windowHandle,
45 boolean _fullscreen )
47 CanvasUtils.printLog( "WindowAdapter(X11): constructor called" );
48 fullscreen = false;
50 if( _fullscreen )
52 // create a normal Java frame, and set it into fullscreen mode
53 frame = new javax.swing.JFrame( "Presentation" );
54 frame.setUndecorated( true );
55 frame.setVisible( true );
57 java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics();
58 if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() )
60 CanvasUtils.printLog( "WindowAdapter(X11): entering fullscreen mode" );
61 graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( frame );
62 fullscreen = true;
64 else
66 CanvasUtils.printLog( "WindowAdapter(X11): fullscreen not supported" );
69 graphics.dispose();
71 else
73 // we're initialized with the operating system window handle
74 // as the parameter. We then generate a dummy Java frame with
75 // that window as the parent, to fake a root window for the
76 // Java implementation.
78 // now, we're getting slightly system dependent here.
79 String os = (String) System.getProperty("os.name");
81 System.err.println("WindowAdapter created");
83 // create the embedded frame
84 if( os.startsWith("Linux") )
86 // create a java frame from that
87 // TODO: Maybe that's the reason why we crash on Linux 1.5beta
88 // immediately: Try XAWT here, or naked X: sun.awt.X11.XEmbeddedFrame
90 //frame = new sun.awt.motif.MEmbeddedFrame( windowHandle );
91 //frame = new sun.awt.X11.XEmbeddedFrame( windowHandle ); // cannot currently compile
92 CanvasUtils.printLog( "WindowAdapter(X11): no frame created for now" );
93 frame = null;
95 else
97 throw new com.sun.star.uno.RuntimeException();
102 //----------------------------------------------------------------------------------
104 public void dispose()
106 if( fullscreen )
108 java.awt.Graphics2D graphics = (java.awt.Graphics2D)frame.getGraphics();
109 if( graphics.getDeviceConfiguration().getDevice().isFullScreenSupported() )
111 CanvasUtils.printLog( "WindowAdapter(X11): leaving fullscreen mode" );
112 graphics.getDeviceConfiguration().getDevice().setFullScreenWindow( null );
114 graphics.dispose();
117 if( frame != null )
118 frame.dispose();
121 //----------------------------------------------------------------------------------
124 // XWindow interface
125 // =================
127 public void setPosSize( int X, int Y, int Width, int Height, short Flags )
129 frame.setBounds( new java.awt.Rectangle( X, Y, Width, Height ) );
132 public com.sun.star.awt.Rectangle getPosSize( )
134 java.awt.Rectangle bounds = frame.getBounds();
136 return new com.sun.star.awt.Rectangle( bounds.x, bounds.y, bounds.width, bounds.height );
139 public void setVisible( boolean visible )
141 frame.setVisible( visible );
144 public void setEnable( boolean enable )
146 frame.setEnabled( enable );
149 public void setFocus()
153 public void addWindowListener( XWindowListener xListener )
157 public void removeWindowListener( XWindowListener xListener )
161 public void addFocusListener( XFocusListener xListener )
165 public void removeFocusListener( XFocusListener xListener )
169 public void addKeyListener( XKeyListener xListener )
173 public void removeKeyListener( XKeyListener xListener )
177 public void addMouseListener( XMouseListener xListener )
181 public void removeMouseListener( XMouseListener xListener )
185 public void addMouseMotionListener( XMouseMotionListener xListener )
189 public void removeMouseMotionListener( XMouseMotionListener xListener )
193 public void addPaintListener( XPaintListener xListener )
197 public void removePaintListener( XPaintListener xListener )