diff options
Diffstat (limited to 'avmedia/source/java')
-rw-r--r-- | avmedia/source/java/FrameGrabber.java | 190 | ||||
-rw-r--r-- | avmedia/source/java/Manager.java | 148 | ||||
-rw-r--r-- | avmedia/source/java/MediaUno.java | 67 | ||||
-rw-r--r-- | avmedia/source/java/Player.java | 325 | ||||
-rw-r--r-- | avmedia/source/java/PlayerWindow.java | 600 | ||||
-rw-r--r-- | avmedia/source/java/WindowAdapter.java | 508 | ||||
-rw-r--r-- | avmedia/source/java/avmedia.jar | bin | 0 -> 15776 bytes | |||
-rw-r--r-- | avmedia/source/java/avmedia.jar.component | 34 | ||||
-rw-r--r-- | avmedia/source/java/makefile.mk | 69 | ||||
-rw-r--r-- | avmedia/source/java/manifest | 2 | ||||
-rw-r--r-- | avmedia/source/java/win/SystemWindowAdapter.java | 53 | ||||
-rw-r--r-- | avmedia/source/java/x11/SystemWindowAdapter.java | 123 |
12 files changed, 2119 insertions, 0 deletions
diff --git a/avmedia/source/java/FrameGrabber.java b/avmedia/source/java/FrameGrabber.java new file mode 100644 index 000000000000..1a0deda4ce57 --- /dev/null +++ b/avmedia/source/java/FrameGrabber.java @@ -0,0 +1,190 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XEventListener; +import com.sun.star.awt.*; +import com.sun.star.media.*; +import com.sun.star.graphic.*; + +// ----------------- +// - Player Window - +// ----------------- + +public class FrameGrabber implements com.sun.star.lang.XServiceInfo, + com.sun.star.media.XFrameGrabber +{ + private com.sun.star.lang.XMultiServiceFactory maFactory = null; + private javax.media.Player maPlayer = null; + private javax.media.control.FrameGrabbingControl maFrameGrabbingControl = null; + + // ------------------------------------------------------------------------- + + public FrameGrabber( com.sun.star.lang.XMultiServiceFactory aFactory, String aURL ) + { + maFactory = aFactory; + + try + { + maPlayer = javax.media.Manager.createRealizedPlayer( new java.net.URL( aURL ) ); + } + catch( java.net.MalformedURLException e ) + { + } + catch( java.io.IOException e ) + { + } + catch( javax.media.NoPlayerException e ) + { + } + catch( javax.media.CannotRealizeException e ) + { + } + catch( java.lang.Exception e ) + { + } + + if( maPlayer != null ) + { + maFrameGrabbingControl = (javax.media.control.FrameGrabbingControl) maPlayer.getControl( + "javax.media.control.FrameGrabbingControl" ); + } + } + + // ------------------------------------------------------------------------- + + public com.sun.star.graphic.XGraphic implImageToXGraphic( java.awt.Image aImage ) + { + com.sun.star.graphic.XGraphic aRet = null; + + if( maFactory != null && aImage != null ) + { + if( aImage instanceof java.awt.image.BufferedImage ) + { + java.io.File aTempFile = null; + + try + { + aTempFile = java.io.File.createTempFile( "sv0", ".png" ); + + if( aTempFile.canWrite() ) + { + javax.imageio.ImageIO.write( (java.awt.image.BufferedImage) aImage, "png", aTempFile ); + + com.sun.star.graphic.XGraphicProvider aProvider = + (com.sun.star.graphic.XGraphicProvider) UnoRuntime.queryInterface( + com.sun.star.graphic.XGraphicProvider.class, + maFactory.createInstance("com.sun.star.graphic.GraphicProvider") ); + + if( aProvider != null ) + { + com.sun.star.beans.PropertyValue[] aArgs = new com.sun.star.beans.PropertyValue[ 1 ]; + + aArgs[ 0 ] = new com.sun.star.beans.PropertyValue(); + aArgs[ 0 ].Name = "URL"; + aArgs[ 0 ].Value = "file://" + aTempFile.toString(); + + aRet = aProvider.queryGraphic( aArgs ); + } + } + } + catch( java.lang.IllegalArgumentException aExcp ) + { + } + catch( java.io.IOException aExcp ) + { + } + catch( com.sun.star.uno.Exception aExcp ) + { + } + + if( aTempFile != null ) + aTempFile.delete(); + } + } + + return aRet; + } + + // ----------------- + // - XFrameGrabber - + // ----------------- + + public synchronized com.sun.star.graphic.XGraphic grabFrame( double fMediaTime ) + { + com.sun.star.graphic.XGraphic aRet = null; + + if( maFrameGrabbingControl != null ) + { + if( fMediaTime >= 0.0 && fMediaTime <= maPlayer.getDuration().getSeconds() ) + { + maPlayer.setMediaTime( new javax.media.Time( fMediaTime ) ); + + javax.media.Buffer aBuffer = maFrameGrabbingControl.grabFrame(); + + if( aBuffer != null && aBuffer.getFormat() instanceof javax.media.format.VideoFormat ) + { + aRet = implImageToXGraphic( new javax.media.util.BufferToImage( + (javax.media.format.VideoFormat) aBuffer.getFormat() ). + createImage( aBuffer ) ); + } + } + } + + return aRet; + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.FrameGrabber_Java"; + private static final String s_serviceName = "com.sun.star.media.FrameGrabber_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/avmedia/source/java/Manager.java b/avmedia/source/java/Manager.java new file mode 100644 index 000000000000..47707478fd5b --- /dev/null +++ b/avmedia/source/java/Manager.java @@ -0,0 +1,148 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; + +// media +import com.sun.star.media.*; + +public class Manager implements com.sun.star.lang.XServiceInfo, + com.sun.star.lang.XTypeProvider, + com.sun.star.media.XManager + +{ + private com.sun.star.lang.XMultiServiceFactory maFactory; + + // ------------------------------------------------------------------------- + + public Manager( com.sun.star.lang.XMultiServiceFactory aFactory ) + { + maFactory = aFactory; + } + + // ------------ + // - XManager - + // ------------ + + public com.sun.star.media.XPlayer createPlayer( String aURL ) + { + javax.media.Player aPlayer = null; + + try + { + aPlayer = javax.media.Manager.createRealizedPlayer( new java.net.URL( aURL ) ); + } + catch( java.net.MalformedURLException e ) + { + } + catch( java.io.IOException e ) + { + } + catch( javax.media.NoPlayerException e ) + { + } + catch( javax.media.CannotRealizeException e ) + { + } + catch( java.lang.Exception e ) + { + } + + if( aPlayer != null ) + { + return new Player( maFactory, aPlayer, aURL ); + } + else + return null; + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.media.Manager_Java"; + private static final String s_serviceName = "com.sun.star.media.Manager_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } + + // ----------------- + // - XTypeProvider - + // ----------------- + protected byte[] maImplementationId; + + public com.sun.star.uno.Type[] getTypes() + { + com.sun.star.uno.Type[] retValue = new com.sun.star.uno.Type[ 3 ]; + + retValue[ 0 ]= new com.sun.star.uno.Type( com.sun.star.lang.XServiceInfo.class ); + retValue[ 1 ]= new com.sun.star.uno.Type( com.sun.star.lang.XTypeProvider.class ); + retValue[ 2 ]= new com.sun.star.uno.Type( com.sun.star.media.XManager.class ); + + return retValue; + } + + // ------------------------------------------------------------------------- + + synchronized public byte[] getImplementationId() + { + if( maImplementationId == null) + { + maImplementationId = new byte[ 16 ]; + + int hash = hashCode(); + + maImplementationId[ 0 ] = (byte)(hash & 0xff); + maImplementationId[ 1 ] = (byte)((hash >>> 8) & 0xff); + maImplementationId[ 2 ] = (byte)((hash >>> 16) & 0xff); + maImplementationId[ 3 ] = (byte)((hash >>>24) & 0xff); + } + + return maImplementationId; + } +} diff --git a/avmedia/source/java/MediaUno.java b/avmedia/source/java/MediaUno.java new file mode 100644 index 000000000000..3e4387840741 --- /dev/null +++ b/avmedia/source/java/MediaUno.java @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; + +public class MediaUno +{ + private static final String s_implName = "com.sun.star.comp.media.Manager_Java"; + private static final String s_serviceName = "com.sun.star.media.Manager_Java"; + + // ------------------------------------------------------------------------- + + public MediaUno() + { + } + + // ------------------------------------------------------------------------- + + public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory( + String implName, + com.sun.star.lang.XMultiServiceFactory multiFactory, + com.sun.star.registry.XRegistryKey regKey ) + { + if (implName.equals( s_implName )) + { + try + { + return com.sun.star.comp.loader.FactoryHelper.getServiceFactory( + Class.forName( "Manager" ), s_serviceName, multiFactory, regKey ); + } + catch( java.lang.ClassNotFoundException exception ) + { + } + } + + return null; + } +} diff --git a/avmedia/source/java/Player.java b/avmedia/source/java/Player.java new file mode 100644 index 000000000000..be3b3d62d367 --- /dev/null +++ b/avmedia/source/java/Player.java @@ -0,0 +1,325 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// UNO +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; + +// awt +import com.sun.star.awt.*; + +// media +import com.sun.star.media.*; + +public class Player implements javax.media.ControllerListener, + com.sun.star.lang.XServiceInfo, + com.sun.star.media.XPlayer, + com.sun.star.lang.XComponent + + +{ + private com.sun.star.lang.XMultiServiceFactory maFactory; + private String maURL; + private javax.media.Player maPlayer; + private javax.media.GainControl maGainControl; + private boolean mbStarted = false; + private boolean mbLooping = false; + + // ------------------------------------------------------------------------- + + public Player( com.sun.star.lang.XMultiServiceFactory aFactory, + javax.media.Player aPlayer, String aURL ) + { + maFactory = aFactory; + maURL = aURL; + maPlayer = aPlayer; + maPlayer.addControllerListener( this ); + maGainControl = maPlayer.getGainControl(); + } + + // ------------------------------------------------------------------------- + + public synchronized void controllerUpdate( javax.media.ControllerEvent aEvt ) + { + if( aEvt instanceof javax.media.EndOfMediaEvent || + aEvt instanceof javax.media.StopAtTimeEvent ) + { + mbStarted = false; + + if( mbLooping ) + { + setMediaTime( 0.0 ); + start(); + } + else if( aEvt instanceof javax.media.EndOfMediaEvent ) + setMediaTime( getDuration() ); + } + } + + // ----------- + // - XPlayer - + // ----------- + + public synchronized void start() + { + if( !mbStarted ) + { + maPlayer.start(); + mbStarted = true; + } + } + + // ------------------------------------------------------------------------- + + public synchronized void stop() + { + if( mbStarted ) + { + maPlayer.stop(); + mbStarted = false; + } + } + + // ------------------------------------------------------------------------- + + public synchronized boolean isPlaying() + { + return mbStarted; + } + + // ------------------------------------------------------------------------- + + public synchronized double getDuration() + { + return maPlayer.getDuration().getSeconds(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setMediaTime( double fTime ) + { + if( fTime >= 0.0 && fTime <= getDuration() ) + maPlayer.setMediaTime( new javax.media.Time( fTime ) ); + } + + // ------------------------------------------------------------------------- + + public synchronized double getMediaTime() + { + return maPlayer.getMediaTime().getSeconds(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setStopTime( double fTime ) + { + boolean bOldStarted = mbStarted; + + if( mbStarted ) + stop(); + + maPlayer.setStopTime( new javax.media.Time( fTime ) ); + + if( bOldStarted ) + start(); + } + + // ------------------------------------------------------------------------- + + public synchronized double getStopTime() + { + return maPlayer.getStopTime().getSeconds(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setRate( double fRate ) + { + boolean bOldStarted = mbStarted; + + if( mbStarted ) + stop(); + + maPlayer.setRate( (float) fRate ); + + if( bOldStarted ) + start(); + } + + // ------------------------------------------------------------------------- + + public synchronized double getRate() + { + return (double) maPlayer.getRate(); + } + + // ------------------------------------------------------------------------- + + public synchronized void setPlaybackLoop( boolean bSet ) + { + mbLooping = bSet; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean isPlaybackLoop() + { + return mbLooping; + } + + // ------------------------------------------------------------------------- + + public synchronized void setVolumeDB( short nVolumeDB ) + { + if( maGainControl != null ) + maGainControl.setDB( nVolumeDB ); + } + + // ------------------------------------------------------------------------- + + public synchronized short getVolumeDB() + { + return( maGainControl != null ? (short) maGainControl.getDB() : 0 ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setMute( boolean bSet ) + { + if( maGainControl != null ) + maGainControl.setMute( bSet ); + } + + // ------------------------------------------------------------------------- + + public synchronized boolean isMute() + { + return( maGainControl != null ? maGainControl.getMute() : false ); + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.awt.Size getPreferredPlayerWindowSize() + { + java.awt.Component aVisualComponent = maPlayer.getVisualComponent(); + com.sun.star.awt.Size aSize = new com.sun.star.awt.Size( 0, 0 ); + + if( aVisualComponent != null ) + { + java.awt.Dimension aDim = aVisualComponent.getPreferredSize(); + + aSize.Width = Math.max( aDim.width, 0 ); + aSize.Height = Math.max( aDim.height, 0 ); + } + + return aSize; + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.media.XPlayerWindow createPlayerWindow( java.lang.Object[] aArgs ) + { + try + { + com.sun.star.media.XPlayerWindow xPlayerWindow = ( ( ( aArgs.length > 1 ) && ( AnyConverter.toInt( aArgs[ 0 ] ) > 0 ) ) ? + new PlayerWindow( maFactory, aArgs, maPlayer ) : + null ); + + // check if it is a real player window (video window) + if( xPlayerWindow != null && xPlayerWindow.getZoomLevel() == com.sun.star.media.ZoomLevel.NOT_AVAILABLE ) + xPlayerWindow = null; + + return xPlayerWindow; + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + return null; + } + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.media.XFrameGrabber createFrameGrabber() + { + return( (com.sun.star.media.XFrameGrabber) new FrameGrabber( maFactory, maURL ) ); + } + + // -------------- + // - XComponent - + // -------------- + + public synchronized void addEventListener( com.sun.star.lang.XEventListener xListener ) + { + } + + // ------------------------------------------------------------------------- + + public synchronized void removeEventListener( com.sun.star.lang.XEventListener xListener ) + { + } + + // ------------------------------------------------------------------------- + + public synchronized void dispose() + { + if( maPlayer != null ) + { + maPlayer.stop(); + maPlayer.close(); + maPlayer = null; + } + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.Player_Java"; + private static final String s_serviceName = "com.sun.star.media.Player_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/avmedia/source/java/PlayerWindow.java b/avmedia/source/java/PlayerWindow.java new file mode 100644 index 000000000000..2229e4f1644b --- /dev/null +++ b/avmedia/source/java/PlayerWindow.java @@ -0,0 +1,600 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.IQueryInterface; +import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XEventListener; +import com.sun.star.awt.*; +import com.sun.star.media.*; + +// ----------------- +// - Player Window - +// ----------------- + +public class PlayerWindow implements java.awt.event.KeyListener, + java.awt.event.MouseListener, + java.awt.event.MouseMotionListener, + java.awt.event.FocusListener, + com.sun.star.lang.XServiceInfo, + com.sun.star.media.XPlayerWindow +{ + private com.sun.star.lang.XMultiServiceFactory maFactory; + private WindowAdapter maFrame; + private javax.media.Player maPlayer; + private com.sun.star.media.ZoomLevel meZoomLevel = com.sun.star.media.ZoomLevel.ORIGINAL; + private boolean mbShowControls = false; + + + // ------------------------------------------------------------------------- + + public PlayerWindow( com.sun.star.lang.XMultiServiceFactory aFactory, + java.lang.Object[] aArgs, javax.media.Player aPlayer ) + { + maFactory = aFactory; + + try + { + if( aArgs.length > 1 ) + { + com.sun.star.awt.Rectangle aBoundRect = (com.sun.star.awt.Rectangle) aArgs[ 1 ]; + + maFrame = new WindowAdapter( AnyConverter.toInt( aArgs[ 0 ] ) ); + maFrame.setPosSize( aBoundRect.X, aBoundRect.Y, aBoundRect.Width, aBoundRect.Height, (short) 0 ); + mbShowControls = false; + + java.awt.Panel aPanel = new java.awt.Panel( new java.awt.BorderLayout() ); + + aPanel.setLayout( null ); + aPanel.setBackground( java.awt.Color.black ); + aPanel.addKeyListener( this ); + aPanel.addMouseListener( this ); + aPanel.addMouseMotionListener( this ); + + if( mbShowControls ) + { + java.awt.Component aControlComponent = aPlayer.getControlPanelComponent(); + + if( aControlComponent != null ) + aPanel.add( aControlComponent ); + else + mbShowControls = false; + } + + java.awt.Component aVisualComponent = aPlayer.getVisualComponent(); + + if( aVisualComponent != null ) + { + aVisualComponent.addKeyListener( this ); + aVisualComponent.addMouseListener( this ); + aVisualComponent.addMouseMotionListener( this ); + aVisualComponent.addFocusListener( this ); + aPanel.add( aVisualComponent ); + } + else + meZoomLevel = com.sun.star.media.ZoomLevel.NOT_AVAILABLE; + + if( maFrame.getJavaFrame() != null ) + maFrame.getJavaFrame().add( aPanel ); + + LayoutComponents(); + } + } + catch( com.sun.star.lang.IllegalArgumentException e ) + { + } + } + + // ------------------------------------------------------------------------- + + protected synchronized void LayoutComponents() + { + if( maFrame.getJavaFrame() != null ) + { + java.awt.Panel aPanel = (java.awt.Panel) maFrame.getJavaFrame().getComponent( 0 ); + int nW = maFrame.getJavaFrame().getWidth(); + int nH = maFrame.getJavaFrame().getHeight(); + int nControlH = 0; + + aPanel.setBounds( 0, 0, nW, nH ); + + if( mbShowControls ) + { + java.awt.Component aControlComponent = aPanel.getComponent( 0 ); + + if( aControlComponent != null ) + { + java.awt.Dimension aControlDimension = aControlComponent.getPreferredSize(); + + nControlH = Math.min( nH, aControlDimension.height ); + aControlComponent.setBounds( 0, nH - nControlH, nW, nControlH ); + } + } + + if( com.sun.star.media.ZoomLevel.NOT_AVAILABLE != meZoomLevel ) + { + java.awt.Component aVisualComponent = aPanel.getComponent( mbShowControls ? 1 : 0 ); + + if( aVisualComponent != null ) + { + java.awt.Dimension aPrefDim = aVisualComponent.getPreferredSize(); + int nVideoW = nW, nVideoH = ( nH - nControlH ); + int nX = 0, nY = 0, nWidth = 0, nHeight = 0; + boolean bDone = false, bZoom = false; + + if( com.sun.star.media.ZoomLevel.ORIGINAL == meZoomLevel ) + { + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_1_TO_4 == meZoomLevel ) + { + aPrefDim.width >>= 2; + aPrefDim.height >>= 2; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_1_TO_2 == meZoomLevel ) + { + aPrefDim.width >>= 1; + aPrefDim.height >>= 1; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_2_TO_1 == meZoomLevel ) + { + aPrefDim.width <<= 1; + aPrefDim.height <<= 1; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.ZOOM_4_TO_1 == meZoomLevel ) + { + aPrefDim.width <<= 2; + aPrefDim.height <<= 2; + bZoom = true; + } + else if( com.sun.star.media.ZoomLevel.FIT_TO_WINDOW == meZoomLevel ) + { + nWidth = nVideoW; + nHeight = nVideoH; + bDone = true; + } + + if( bZoom ) + { + if( ( aPrefDim.width <= nVideoW ) && ( aPrefDim.height <= nVideoH ) ) + { + nX = ( nVideoW - aPrefDim.width ) >> 1; + nY = ( nVideoH - aPrefDim.height ) >> 1; + nWidth = aPrefDim.width; + nHeight = aPrefDim.height; + bDone = true; + } + } + + if( !bDone ) + { + if( aPrefDim.width > 0 && aPrefDim.height > 0 && nVideoW > 0 && nVideoH > 0 ) + { + double fPrefWH = (double) aPrefDim.width / aPrefDim.height; + + if( fPrefWH < ( (double) nVideoW / nVideoH ) ) + nVideoW = (int)( nVideoH * fPrefWH ); + else + nVideoH = (int)( nVideoW / fPrefWH ); + + nX = ( nW - nVideoW ) >> 1; + nY = ( nH - nControlH - nVideoH ) >> 1; + nWidth = nVideoW; + nHeight = nVideoH; + } + else + nX = nY = nWidth = nHeight = 0; + } + + aVisualComponent.setBounds( nX, nY, nWidth, nHeight ); + aVisualComponent.requestFocus(); + } + else + aPanel.requestFocus(); + } + else + aPanel.requestFocus(); + } + } + + // ------------------------------------------------------------------------- + + private void implFireMouseEvent( java.awt.event.MouseEvent aEvt ) + { + if( aEvt.getSource() != null && + aEvt.getSource() instanceof java.awt.Component ) + { + aEvt.translatePoint( ( (java.awt.Component) aEvt.getSource() ).getX(), + ( (java.awt.Component) aEvt.getSource() ).getY() ); + } + + maFrame.fireMouseEvent( aEvt ); + } + + // --------------- + // - KeyListener - + // --------------- + + public void keyPressed( java.awt.event.KeyEvent aEvt ) + { + maFrame.fireKeyEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void keyReleased( java.awt.event.KeyEvent aEvt ) + { + maFrame.fireKeyEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void keyTyped( java.awt.event.KeyEvent aEvt ) + { + maFrame.fireKeyEvent( aEvt ); + } + + // ----------------- + // - MouseListener - + // ----------------- + + public void mousePressed( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseClicked( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseEntered( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseExited( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseReleased( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ----------------------- + // - MouseMotionListener - + // ----------------------- + + public void mouseDragged( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void mouseMoved( java.awt.event.MouseEvent aEvt ) + { + implFireMouseEvent( aEvt ); + } + + // ----------------------- + // - FocusListener - + // ----------------------- + + public void focusGained( java.awt.event.FocusEvent aEvt ) + { + if( maFrame.getJavaFrame() != null ) + maFrame.fireFocusEvent( aEvt ); + } + + // ------------------------------------------------------------------------- + + public void focusLost( java.awt.event.FocusEvent aEvt ) + { + if( maFrame.getJavaFrame() != null ) + maFrame.fireFocusEvent( aEvt ); + } + + // ----------------- + // - XPlayerWindow - + // ----------------- + + public synchronized void update() + { + if( maFrame.getJavaFrame() != null ) + maFrame.getJavaFrame().repaint(); + } + + // ------------------------------------------------------------------------- + + public synchronized boolean setZoomLevel( com.sun.star.media.ZoomLevel eZoomLevel ) + { + boolean bRet = false; + + if( com.sun.star.media.ZoomLevel.NOT_AVAILABLE != meZoomLevel && + com.sun.star.media.ZoomLevel.NOT_AVAILABLE != eZoomLevel ) + { + if( eZoomLevel != meZoomLevel ) + { + meZoomLevel = eZoomLevel; + LayoutComponents(); + } + + bRet = true; + } + + return bRet; + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.media.ZoomLevel getZoomLevel() + { + return meZoomLevel; + } + + // ------------------------------------------------------------------------- + + public synchronized void setPointerType( int nPointerType ) + { + if( maFrame.getJavaFrame() != null ) + { + int nCursor; + + switch( nPointerType ) + { + case( com.sun.star.awt.SystemPointer.CROSS ): nCursor = java.awt.Cursor.CROSSHAIR_CURSOR; break; + case( com.sun.star.awt.SystemPointer.HAND ): nCursor = java.awt.Cursor.HAND_CURSOR; break; + case( com.sun.star.awt.SystemPointer.MOVE ): nCursor = java.awt.Cursor.MOVE_CURSOR; break; + case( com.sun.star.awt.SystemPointer.WAIT ): nCursor = java.awt.Cursor.WAIT_CURSOR; break; + + default: nCursor = java.awt.Cursor.DEFAULT_CURSOR; break; + } + + maFrame.getJavaFrame().setCursor( java.awt.Cursor.getPredefinedCursor( nCursor ) ); + } + } + + // -------------- + // - XComponent - + // -------------- + + public synchronized void dispose() + { + if( maFrame != null ) + { + java.awt.Panel aPanel = (java.awt.Panel) maFrame.getJavaFrame().getComponent( 0 ); + + if( aPanel != null && aPanel.getComponent( 0 ) != null ) + aPanel.getComponent( 0 ).removeFocusListener( this ); + + if( maFrame.getJavaFrame() != null ) + maFrame.getJavaFrame().dispose(); + + maFrame.fireDisposingEvent(); + } + + maFrame = null; + } + + // ----------- + // - XWindow - + // ----------- + + public synchronized void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + if( maFrame != null ) + { + maFrame.setPosSize( X, Y, Width, Height, Flags ); + LayoutComponents(); + } + } + + // ------------------------------------------------------------------------- + + public synchronized com.sun.star.awt.Rectangle getPosSize() + { + return( ( maFrame != null ) ? maFrame.getPosSize() : new com.sun.star.awt.Rectangle() ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setVisible( boolean visible ) + { + if( maFrame != null ) + maFrame.setVisible( visible ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setEnable( boolean enable ) + { + if( maFrame != null ) + maFrame.setEnable( enable ); + } + + // ------------------------------------------------------------------------- + + public synchronized void setFocus() + { + if( maFrame != null ) + maFrame.setFocus(); + } + + // ------------------------------------------------------------------------- + + public synchronized void addEventListener( com.sun.star.lang.XEventListener xListener ) + { + if( maFrame != null ) + maFrame.addEventListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeEventListener( com.sun.star.lang.XEventListener xListener ) + { + if( maFrame != null ) + maFrame.removeEventListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addWindowListener( XWindowListener xListener ) + { + if( maFrame != null ) + maFrame.addWindowListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeWindowListener( XWindowListener xListener ) + { + if( maFrame != null ) + maFrame.removeWindowListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addFocusListener( XFocusListener xListener ) + { + if( maFrame != null ) + maFrame.addFocusListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeFocusListener( XFocusListener xListener ) + { + if( maFrame != null ) + maFrame.removeFocusListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addKeyListener( XKeyListener xListener ) + { + if( maFrame != null ) + maFrame.addKeyListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeKeyListener( XKeyListener xListener ) + { + if( maFrame != null ) + maFrame.removeKeyListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addMouseListener( XMouseListener xListener ) + { + if( maFrame != null ) + maFrame.addMouseListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeMouseListener( XMouseListener xListener ) + { + if( maFrame != null ) + maFrame.removeMouseListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addMouseMotionListener( XMouseMotionListener xListener ) + { + if( maFrame != null ) + maFrame.addMouseMotionListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removeMouseMotionListener( XMouseMotionListener xListener ) + { + if( maFrame != null ) + maFrame.removeMouseMotionListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void addPaintListener( XPaintListener xListener ) + { + if( maFrame != null ) + maFrame.addPaintListener( xListener ); + } + + // ------------------------------------------------------------------------- + + public synchronized void removePaintListener( XPaintListener xListener ) + { + if( maFrame != null ) + maFrame.removePaintListener( xListener ); + } + + // ---------------- + // - XServiceInfo - + // ---------------- + + private static final String s_implName = "com.sun.star.comp.PlayerWindow_Java"; + private static final String s_serviceName = "com.sun.star.media.PlayerWindow_Java"; + + public synchronized String getImplementationName() + { + return s_implName; + } + + // ------------------------------------------------------------------------- + + public synchronized String [] getSupportedServiceNames() + { + return new String [] { s_serviceName }; + } + + // ------------------------------------------------------------------------- + + public synchronized boolean supportsService( String serviceName ) + { + return serviceName.equals( s_serviceName ); + } +} diff --git a/avmedia/source/java/WindowAdapter.java b/avmedia/source/java/WindowAdapter.java new file mode 100644 index 000000000000..bd11aec5e738 --- /dev/null +++ b/avmedia/source/java/WindowAdapter.java @@ -0,0 +1,508 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import sun.awt.*; +import com.sun.star.awt.*; +import com.sun.star.lang.*; +import java.util.*; +import javax.swing.*; + +public class WindowAdapter +{ + private java.awt.Frame maFrame; + private LinkedList maEventListeners = new LinkedList(); + private LinkedList maWindowListeners = new LinkedList(); + private LinkedList maFocusListeners = new LinkedList(); + private LinkedList maKeyListeners = new LinkedList(); + private LinkedList maMouseListeners = new LinkedList(); + private LinkedList maMouseMotionListeners = new LinkedList(); + private LinkedList maPaintListeners = new LinkedList(); + private boolean mbShift = false, mbMod1 = false, mbMod2 = false; + + // ----------------- + // - WindowAdapter - + // ----------------- + + public WindowAdapter( int windowHandle ) + { + maFrame = SystemWindowAdapter.createFrame( windowHandle ); + } + + //---------------------------------------------------------------------------------- + + public java.awt.Frame getJavaFrame() + { + return maFrame; + } + + //---------------------------------------------------------------------------------- + + private short implGetUNOKeyCode( int nJavaKeyCode ) + { + short nRet = 0; + + switch( nJavaKeyCode ) + { + case( java.awt.event.KeyEvent.VK_NUMPAD0 ): + case( java.awt.event.KeyEvent.VK_0 ): nRet = com.sun.star.awt.Key.NUM0; break; + case( java.awt.event.KeyEvent.VK_NUMPAD1 ): + case( java.awt.event.KeyEvent.VK_1 ): nRet = com.sun.star.awt.Key.NUM1; break; + case( java.awt.event.KeyEvent.VK_NUMPAD2 ): + case( java.awt.event.KeyEvent.VK_2 ): nRet = com.sun.star.awt.Key.NUM2; break; + case( java.awt.event.KeyEvent.VK_NUMPAD3 ): + case( java.awt.event.KeyEvent.VK_3 ): nRet = com.sun.star.awt.Key.NUM3; break; + case( java.awt.event.KeyEvent.VK_NUMPAD4 ): + case( java.awt.event.KeyEvent.VK_4 ): nRet = com.sun.star.awt.Key.NUM4; break; + case( java.awt.event.KeyEvent.VK_NUMPAD5 ): + case( java.awt.event.KeyEvent.VK_5 ): nRet = com.sun.star.awt.Key.NUM5; break; + case( java.awt.event.KeyEvent.VK_NUMPAD6 ): + case( java.awt.event.KeyEvent.VK_6 ): nRet = com.sun.star.awt.Key.NUM6; break; + case( java.awt.event.KeyEvent.VK_NUMPAD7 ): + case( java.awt.event.KeyEvent.VK_7 ): nRet = com.sun.star.awt.Key.NUM7; break; + case( java.awt.event.KeyEvent.VK_NUMPAD8 ): + case( java.awt.event.KeyEvent.VK_8 ): nRet = com.sun.star.awt.Key.NUM8; break; + case( java.awt.event.KeyEvent.VK_NUMPAD9 ): + case( java.awt.event.KeyEvent.VK_9 ): nRet = com.sun.star.awt.Key.NUM9; break; + + case( java.awt.event.KeyEvent.VK_A ): nRet = com.sun.star.awt.Key.A; break; + case( java.awt.event.KeyEvent.VK_B ): nRet = com.sun.star.awt.Key.B; break; + case( java.awt.event.KeyEvent.VK_C ): nRet = com.sun.star.awt.Key.C; break; + case( java.awt.event.KeyEvent.VK_D ): nRet = com.sun.star.awt.Key.D; break; + case( java.awt.event.KeyEvent.VK_E ): nRet = com.sun.star.awt.Key.E; break; + case( java.awt.event.KeyEvent.VK_F ): nRet = com.sun.star.awt.Key.F; break; + case( java.awt.event.KeyEvent.VK_G ): nRet = com.sun.star.awt.Key.G; break; + case( java.awt.event.KeyEvent.VK_H ): nRet = com.sun.star.awt.Key.H; break; + case( java.awt.event.KeyEvent.VK_I ): nRet = com.sun.star.awt.Key.I; break; + case( java.awt.event.KeyEvent.VK_J ): nRet = com.sun.star.awt.Key.J; break; + case( java.awt.event.KeyEvent.VK_K ): nRet = com.sun.star.awt.Key.K; break; + case( java.awt.event.KeyEvent.VK_L ): nRet = com.sun.star.awt.Key.L; break; + case( java.awt.event.KeyEvent.VK_M ): nRet = com.sun.star.awt.Key.M; break; + case( java.awt.event.KeyEvent.VK_N ): nRet = com.sun.star.awt.Key.N; break; + case( java.awt.event.KeyEvent.VK_O ): nRet = com.sun.star.awt.Key.O; break; + case( java.awt.event.KeyEvent.VK_P ): nRet = com.sun.star.awt.Key.P; break; + case( java.awt.event.KeyEvent.VK_Q ): nRet = com.sun.star.awt.Key.Q; break; + case( java.awt.event.KeyEvent.VK_R ): nRet = com.sun.star.awt.Key.R; break; + case( java.awt.event.KeyEvent.VK_S ): nRet = com.sun.star.awt.Key.S; break; + case( java.awt.event.KeyEvent.VK_T ): nRet = com.sun.star.awt.Key.T; break; + case( java.awt.event.KeyEvent.VK_U ): nRet = com.sun.star.awt.Key.U; break; + case( java.awt.event.KeyEvent.VK_V ): nRet = com.sun.star.awt.Key.V; break; + case( java.awt.event.KeyEvent.VK_W ): nRet = com.sun.star.awt.Key.W; break; + case( java.awt.event.KeyEvent.VK_X ): nRet = com.sun.star.awt.Key.X; break; + case( java.awt.event.KeyEvent.VK_Y ): nRet = com.sun.star.awt.Key.Y; break; + case( java.awt.event.KeyEvent.VK_Z ): nRet = com.sun.star.awt.Key.Z; break; + + case( java.awt.event.KeyEvent.VK_F1 ): nRet = com.sun.star.awt.Key.F1; break; + case( java.awt.event.KeyEvent.VK_F2 ): nRet = com.sun.star.awt.Key.F2; break; + case( java.awt.event.KeyEvent.VK_F3 ): nRet = com.sun.star.awt.Key.F3; break; + case( java.awt.event.KeyEvent.VK_F4 ): nRet = com.sun.star.awt.Key.F4; break; + case( java.awt.event.KeyEvent.VK_F5 ): nRet = com.sun.star.awt.Key.F5; break; + case( java.awt.event.KeyEvent.VK_F6 ): nRet = com.sun.star.awt.Key.F6; break; + case( java.awt.event.KeyEvent.VK_F7 ): nRet = com.sun.star.awt.Key.F7; break; + case( java.awt.event.KeyEvent.VK_F8 ): nRet = com.sun.star.awt.Key.F8; break; + case( java.awt.event.KeyEvent.VK_F9 ): nRet = com.sun.star.awt.Key.F9; break; + case( java.awt.event.KeyEvent.VK_F10 ): nRet = com.sun.star.awt.Key.F10; break; + case( java.awt.event.KeyEvent.VK_F11 ): nRet = com.sun.star.awt.Key.F11; break; + case( java.awt.event.KeyEvent.VK_F12 ): nRet = com.sun.star.awt.Key.F12; break; + case( java.awt.event.KeyEvent.VK_F13 ): nRet = com.sun.star.awt.Key.F13; break; + case( java.awt.event.KeyEvent.VK_F14 ): nRet = com.sun.star.awt.Key.F14; break; + case( java.awt.event.KeyEvent.VK_F15 ): nRet = com.sun.star.awt.Key.F15; break; + case( java.awt.event.KeyEvent.VK_F16 ): nRet = com.sun.star.awt.Key.F16; break; + case( java.awt.event.KeyEvent.VK_F17 ): nRet = com.sun.star.awt.Key.F17; break; + case( java.awt.event.KeyEvent.VK_F18 ): nRet = com.sun.star.awt.Key.F18; break; + case( java.awt.event.KeyEvent.VK_F19 ): nRet = com.sun.star.awt.Key.F19; break; + case( java.awt.event.KeyEvent.VK_F20 ): nRet = com.sun.star.awt.Key.F20; break; + case( java.awt.event.KeyEvent.VK_F21 ): nRet = com.sun.star.awt.Key.F21; break; + case( java.awt.event.KeyEvent.VK_F22 ): nRet = com.sun.star.awt.Key.F22; break; + case( java.awt.event.KeyEvent.VK_F23 ): nRet = com.sun.star.awt.Key.F23; break; + case( java.awt.event.KeyEvent.VK_F24 ): nRet = com.sun.star.awt.Key.F24; break; + + case( java.awt.event.KeyEvent.VK_UP ): nRet = com.sun.star.awt.Key.UP; break; + case( java.awt.event.KeyEvent.VK_DOWN): nRet = com.sun.star.awt.Key.DOWN; break; + case( java.awt.event.KeyEvent.VK_LEFT ): nRet = com.sun.star.awt.Key.LEFT; break; + case( java.awt.event.KeyEvent.VK_RIGHT ): nRet = com.sun.star.awt.Key.RIGHT; break; + + case( java.awt.event.KeyEvent.VK_HOME ): nRet = com.sun.star.awt.Key.HOME; break; + case( java.awt.event.KeyEvent.VK_END ): nRet = com.sun.star.awt.Key.END; break; + + case( java.awt.event.KeyEvent.VK_PAGE_UP ): nRet = com.sun.star.awt.Key.PAGEUP; break; + case( java.awt.event.KeyEvent.VK_PAGE_DOWN ): nRet = com.sun.star.awt.Key.PAGEDOWN; break; + + case( java.awt.event.KeyEvent.VK_ENTER ): nRet = com.sun.star.awt.Key.RETURN; break; + case( java.awt.event.KeyEvent.VK_ESCAPE ): nRet = com.sun.star.awt.Key.ESCAPE; break; + + case( java.awt.event.KeyEvent.VK_TAB ): nRet = com.sun.star.awt.Key.TAB; break; + case( java.awt.event.KeyEvent.VK_BACK_SPACE ): nRet = com.sun.star.awt.Key.BACKSPACE; break; + case( java.awt.event.KeyEvent.VK_SPACE ): nRet = com.sun.star.awt.Key.SPACE; break; + case( java.awt.event.KeyEvent.VK_INSERT): nRet = com.sun.star.awt.Key.INSERT; break; + case( java.awt.event.KeyEvent.VK_DELETE): nRet = com.sun.star.awt.Key.DELETE; break; + case( java.awt.event.KeyEvent.VK_ADD ): nRet = com.sun.star.awt.Key.ADD; break; + case( java.awt.event.KeyEvent.VK_SUBTRACT ): nRet = com.sun.star.awt.Key.SUBTRACT; break; + case( java.awt.event.KeyEvent.VK_MULTIPLY ): nRet = com.sun.star.awt.Key.MULTIPLY; break; + case( java.awt.event.KeyEvent.VK_DIVIDE ): nRet = com.sun.star.awt.Key.DIVIDE; break; + case( java.awt.event.KeyEvent.VK_DECIMAL ): nRet = com.sun.star.awt.Key.POINT; break; + // case( java.awt.event.KeyEvent.VK_ COMMA; break; + case( java.awt.event.KeyEvent.VK_LESS ): nRet = com.sun.star.awt.Key.LESS; break; + case( java.awt.event.KeyEvent.VK_GREATER ): nRet = com.sun.star.awt.Key.GREATER; break; + case( java.awt.event.KeyEvent.VK_EQUALS ): nRet = com.sun.star.awt.Key.EQUAL; break; + // case( java.awt.event.KeyEvent.VK_ OPEN; break; + // case( java.awt.event.KeyEvent.VK_ CUT; break; + // case( java.awt.event.KeyEvent.VK_ COPY; break; + // case( java.awt.event.KeyEvent.VK_ PASTE; break; + // case( java.awt.event.KeyEvent.VK_ UNDO; break; + // case( java.awt.event.KeyEvent.VK_ REPEAT; break; + // case( java.awt.event.KeyEvent.VK_ FIND; break; + // case( java.awt.event.KeyEvent.VK_ PROPERTIES; break; + // case( java.awt.event.KeyEvent.VK_ FRONT; break; + // case( java.awt.event.KeyEvent.VK_ CONTEXTMENU; break; + // case( java.awt.event.KeyEvent.VK_ HELP; break; + + default: + break; + } + + return nRet; + } + + //---------------------------------------------------------------------------------- + + public void fireKeyEvent( java.awt.event.KeyEvent aEvt ) + { + if( maKeyListeners.size() > 0 ) + { + boolean bProcess = false, bPressed = false; + + if( java.awt.event.KeyEvent.KEY_PRESSED == aEvt.getID() ) + { + switch( aEvt.getKeyCode() ) + { + case( java.awt.event.KeyEvent.VK_SHIFT ): mbShift = true; break; + case( java.awt.event.KeyEvent.VK_CONTROL ): mbMod1 = true; break; + case( java.awt.event.KeyEvent.VK_ALT ): mbMod2 = true; break; + + default: + { + bProcess = bPressed = true; + } + break; + } + } + else if( java.awt.event.KeyEvent.KEY_RELEASED == aEvt.getID() ) + { + switch( aEvt.getKeyCode() ) + { + case( java.awt.event.KeyEvent.VK_SHIFT ): mbShift = false; break; + case( java.awt.event.KeyEvent.VK_CONTROL ): mbMod1 = false; break; + case( java.awt.event.KeyEvent.VK_ALT ): mbMod2 = false; break; + + default: + { + bProcess = true; + } + break; + } + } + + if( bProcess ) + { + KeyEvent aUNOEvt = new KeyEvent(); + + aUNOEvt.Modifiers = 0; + + if( mbShift ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.SHIFT; + + if( mbMod1 ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD1; + + if( mbMod2 ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD2; + + aUNOEvt.KeyCode = implGetUNOKeyCode( aEvt.getKeyCode() ); + aUNOEvt.KeyChar = aEvt.getKeyChar(); + aUNOEvt.KeyFunc = com.sun.star.awt.KeyFunction.DONTKNOW; + + ListIterator aIter = maKeyListeners.listIterator( 0 ); + + while( aIter.hasNext() ) + { + if( bPressed ) + ( (XKeyListener) aIter.next() ).keyPressed( aUNOEvt ); + else + ( (XKeyListener) aIter.next() ).keyReleased( aUNOEvt ); + } + } + } + } + + //---------------------------------------------------------------------------------- + + public void fireMouseEvent( java.awt.event.MouseEvent aEvt ) + { + MouseEvent aUNOEvt = new MouseEvent(); + + aUNOEvt.Modifiers = 0; + aUNOEvt.Buttons = 0; + aUNOEvt.X = aEvt.getX(); + aUNOEvt.Y = aEvt.getY(); + aUNOEvt.PopupTrigger = false; + + // Modifiers + if( aEvt.isShiftDown() ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.SHIFT; + + if( aEvt.isControlDown() ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD1; + + if( aEvt.isAltDown() ) + aUNOEvt.Modifiers |= com.sun.star.awt.KeyModifier.MOD2; + + // Buttons + if( SwingUtilities.isLeftMouseButton( aEvt ) ) + aUNOEvt.Buttons |= com.sun.star.awt.MouseButton.LEFT; + + if( SwingUtilities.isMiddleMouseButton( aEvt ) ) + aUNOEvt.Buttons |= com.sun.star.awt.MouseButton.MIDDLE; + + if( SwingUtilities.isRightMouseButton( aEvt ) ) + aUNOEvt.Buttons |= com.sun.star.awt.MouseButton.RIGHT; + + // event type + if( java.awt.event.MouseEvent.MOUSE_PRESSED == aEvt.getID() ) + { + ListIterator aIter = maMouseListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 1; + + while( aIter.hasNext() ) + ( (XMouseListener) aIter.next() ).mousePressed( aUNOEvt ); + } + else if( java.awt.event.MouseEvent.MOUSE_RELEASED == aEvt.getID() ) + { + ListIterator aIter = maMouseListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 1; + + while( aIter.hasNext() ) + ( (XMouseListener) aIter.next() ).mouseReleased( aUNOEvt ); + } + else if( java.awt.event.MouseEvent.MOUSE_DRAGGED == aEvt.getID() ) + { + ListIterator aIter = maMouseMotionListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 0; + + while( aIter.hasNext() ) + ( (XMouseMotionListener) aIter.next() ).mouseDragged( aUNOEvt ); + } + else if( java.awt.event.MouseEvent.MOUSE_MOVED == aEvt.getID() ) + { + ListIterator aIter = maMouseMotionListeners.listIterator( 0 ); + + aUNOEvt.ClickCount = 0; + + while( aIter.hasNext() ) + ( (XMouseMotionListener) aIter.next() ).mouseMoved( aUNOEvt ); + } + } + + //---------------------------------------------------------------------------------- + + public void fireFocusEvent( java.awt.event.FocusEvent aEvt ) + { + if( java.awt.event.FocusEvent.FOCUS_GAINED == aEvt.getID() ) + { + ListIterator aIter = maFocusListeners.listIterator( 0 ); + FocusEvent aUNOEvt = new FocusEvent(); + + while( aIter.hasNext() ) + { + ( (XFocusListener) aIter.next() ).focusGained( aUNOEvt ); + } + } + } + + //---------------------------------------------------------------------------------- + + public void fireDisposingEvent() + { + ListIterator aIter = maEventListeners.listIterator( 0 ); + + while( aIter.hasNext() ) + { + ( (XEventListener) aIter.next() ).disposing( new com.sun.star.lang.EventObject() ); + } + } + + // -------------------- + // - XWindow methods - + // -------------------- + + public void setPosSize( int X, int Y, int Width, int Height, short Flags ) + { + maFrame.setBounds( X, Y, Width, Height ); + } + + //---------------------------------------------------------------------------------- + + public com.sun.star.awt.Rectangle getPosSize( ) + { + java.awt.Rectangle bounds = maFrame.getBounds(); + return new com.sun.star.awt.Rectangle( bounds.x, bounds.y, bounds.width, bounds.height ); + } + + //---------------------------------------------------------------------------------- + + public void setVisible( boolean visible ) + { + maFrame.setVisible( visible ); + } + + //---------------------------------------------------------------------------------- + + public void setEnable( boolean enable ) + { + maFrame.setEnabled( enable ); + } + + //---------------------------------------------------------------------------------- + + public void setFocus() + { + } + + //---------------------------------------------------------------------------------- + + public void addEventListener( XEventListener xListener ) + { + if( xListener != null ) + maEventListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeEventListener( XEventListener xListener ) + { + if( xListener != null ) + maEventListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addWindowListener( XWindowListener xListener ) + { + if( xListener != null ) + maWindowListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeWindowListener( XWindowListener xListener ) + { + if( xListener != null ) + maWindowListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addFocusListener( XFocusListener xListener ) + { + if( xListener != null ) + maFocusListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeFocusListener( XFocusListener xListener ) + { + if( xListener != null ) + maFocusListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addKeyListener( XKeyListener xListener ) + { + if( xListener != null ) + maKeyListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeKeyListener( XKeyListener xListener ) + { + if( xListener != null ) + maKeyListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addMouseListener( XMouseListener xListener ) + { + if( xListener != null ) + maMouseListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeMouseListener( XMouseListener xListener ) + { + if( xListener != null ) + maMouseListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addMouseMotionListener( XMouseMotionListener xListener ) + { + if( xListener != null ) + maMouseMotionListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removeMouseMotionListener( XMouseMotionListener xListener ) + { + if( xListener != null ) + maMouseMotionListeners.remove( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void addPaintListener( XPaintListener xListener ) + { + if( xListener != null ) + maPaintListeners.add( xListener ); + } + + //---------------------------------------------------------------------------------- + + public void removePaintListener( XPaintListener xListener ) + { + if( xListener != null ) + maPaintListeners.remove( xListener ); + } +} diff --git a/avmedia/source/java/avmedia.jar b/avmedia/source/java/avmedia.jar Binary files differnew file mode 100644 index 000000000000..85a98bbcf33c --- /dev/null +++ b/avmedia/source/java/avmedia.jar diff --git a/avmedia/source/java/avmedia.jar.component b/avmedia/source/java/avmedia.jar.component new file mode 100644 index 000000000000..d7cc160bd7d0 --- /dev/null +++ b/avmedia/source/java/avmedia.jar.component @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.Java2" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.media.Manager_Java"> + <service name="com.sun.star.media.Manager_Java"/> + </implementation> +</component> diff --git a/avmedia/source/java/makefile.mk b/avmedia/source/java/makefile.mk new file mode 100644 index 000000000000..1fe771c117f2 --- /dev/null +++ b/avmedia/source/java/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************** + +# Builds the Java Canvas implementation. + +PRJNAME = avmedia +PRJ = ..$/.. +TARGET = avmedia +PACKAGE = avmedia + +# --- Settings ----------------------------------------------------- + +.INCLUDE: settings.mk + +.IF "$(GUIBASE)"=="javamedia" + +JAVAFILES = \ + Manager.java \ + Player.java \ + PlayerWindow.java \ + WindowAdapter.java \ + MediaUno.java \ + FrameGrabber.java \ + x11$/SystemWindowAdapter.java + +JARFILES = jurt.jar unoil.jar ridl.jar juh.jar java_uno.jar jmf.jar +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:s/.java//).class) + +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE +CUSTOMMANIFESTFILE = manifest + +.ENDIF # "$(GUIBASE)"=="javamedia" + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk + +ALLTAR : $(MISC)/avmedia.jar.component + +$(MISC)/avmedia.jar.component .ERRREMOVE : \ + $(SOLARENV)/bin/createcomponent.xslt avmedia.jar.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_JAVA)avmedia.jar' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt avmedia.jar.component diff --git a/avmedia/source/java/manifest b/avmedia/source/java/manifest new file mode 100644 index 000000000000..fa9c2500d385 --- /dev/null +++ b/avmedia/source/java/manifest @@ -0,0 +1,2 @@ +RegistrationClassName: MediaUno +UNO-Type-Path: diff --git a/avmedia/source/java/win/SystemWindowAdapter.java b/avmedia/source/java/win/SystemWindowAdapter.java new file mode 100644 index 000000000000..ebf3cac99307 --- /dev/null +++ b/avmedia/source/java/win/SystemWindowAdapter.java @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import sun.awt.*; +import com.sun.star.awt.*; + +public class SystemWindowAdapter +{ + static public java.awt.Frame createFrame( int windowHandle ) + { + java.awt.Frame aFrame; + + // we're initialized with the operating system window handle + // as the parameter. We then generate a dummy Java frame with + // that window as the parent, to fake a root window for the + // Java implementation. + + // now, we're getting slightly system dependent here. + String os = (String) System.getProperty( "os.name" ); + + // create the embedded frame + if( os.startsWith( "Windows" ) ) + aFrame = new sun.awt.windows.WEmbeddedFrame( windowHandle ); + else + throw new com.sun.star.uno.RuntimeException(); + + return aFrame; + } +} diff --git a/avmedia/source/java/x11/SystemWindowAdapter.java b/avmedia/source/java/x11/SystemWindowAdapter.java new file mode 100644 index 000000000000..4292dabe6775 --- /dev/null +++ b/avmedia/source/java/x11/SystemWindowAdapter.java @@ -0,0 +1,123 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +import java.awt.*; +import java.lang.reflect.*; + +public class SystemWindowAdapter +{ + static public java.awt.Frame createFrame( int windowHandle ) + { + String aOS = (String) System.getProperty( "os.name" ); + java.awt.Frame aFrame = null; + + if( aOS.startsWith( "SunOS" ) ) + { + try + { + Class aClass = Class.forName( "sun.awt.motif.MEmbeddedFrame" ); + + if( aClass != null ) + { + try + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class, boolean.class } ); + + if( aCtor != null ) + { + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ), + new Boolean( false ) } ); + } + } + catch( Exception e ) + { + } + + if( aFrame == null ) + { + try + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class } ); + + if( aCtor != null ) + { + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } ); + } + } + catch( Exception e ) + { + } + } + } + } + catch( Exception e ) + { + } + } + else + { + try + { + Class aClass = Class.forName( "sun.awt.motif.MEmbeddedFrame" ); + + if( aClass != null ) + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class } ); + + if( aCtor != null ) + { + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } ); + } + } + } + catch( Exception e ) + { + } + + if( aFrame == null ) + { + try + { + Class aClass = Class.forName( "sun.awt.X11.XEmbeddedFrame" ); + + if( aClass != null ) + { + Constructor aCtor = aClass.getConstructor( new Class[] { long.class } ); + + if( aCtor != null ) + aFrame = (java.awt.Frame) aCtor.newInstance( new Object[] { new Long( windowHandle ) } ); + } + } + catch( Exception e ) + { + } + } + } + + return aFrame; + } +} |