Update ooo320-m1
[ooovba.git] / canvas / source / java / java_Service.java
blob5ce39ea3085b6087902b192ea84a2e42d82d71a1
2 import com.sun.star.uno.UnoRuntime;
3 import com.sun.star.uno.XComponentContext;
4 import com.sun.star.awt.*;
6 public class java_Service
7 extends com.sun.star.lib.uno.helper.WeakBase
8 implements com.sun.star.lang.XServiceInfo, foo.XBar
10 private XToolkit m_xToolkit;
11 private XVclWindowPeer m_xPeer;
12 private javax.swing.JFrame m_frame;
14 public java_Service( XComponentContext xContext )
16 try
18 m_xToolkit =
19 (XToolkit) UnoRuntime.queryInterface(
20 XToolkit.class,
21 xContext.getServiceManager().createInstanceWithContext(
22 "com.sun.star.awt.Toolkit", xContext ) );
24 catch (com.sun.star.uno.Exception exc)
26 throw new com.sun.star.uno.RuntimeException(
27 "exception occured gettin toolkit: " + exc, this );
31 // XBar impl
32 public void raiseAndCloseWindows( foo.XBar [] seq )
33 throws com.sun.star.uno.Exception
35 for ( int nPos = 0; nPos < seq.length; ++nPos )
36 seq[ nPos ].raiseWindows( "called by Java code" );
38 // modal dialog before closing
39 javax.swing.JOptionPane.showMessageDialog(
40 null, "[Java] all windows created." );
42 for ( int nPos = 0; nPos < seq.length; ++nPos )
43 seq[ nPos ].closeWindows();
46 public void raiseWindows( String msg )
47 throws com.sun.star.uno.Exception
49 // create java frame
50 m_frame = new javax.swing.JFrame(
51 "[java frame created by Java code] " + msg );
52 m_frame.setSize( 500, 50 );
53 m_frame.setLocation( 200, 500 );
54 m_frame.setVisible( true );
56 // create office workwindow
57 m_xPeer = (XVclWindowPeer) UnoRuntime.queryInterface(
58 XVclWindowPeer.class,
59 m_xToolkit.createWindow(
60 new WindowDescriptor(
61 WindowClass.TOP, "workwindow", null, (short) -1,
62 new Rectangle( 800, 500, 500, 50 ),
63 WindowAttribute.SHOW |
64 WindowAttribute.BORDER |
65 WindowAttribute.SIZEABLE |
66 WindowAttribute.MOVEABLE |
67 WindowAttribute.CLOSEABLE ) ) );
68 m_xPeer.setProperty(
69 "Title", "[office window created by Java code] " + msg );
72 public void closeWindows()
73 throws com.sun.star.uno.Exception
75 m_frame.dispose();
76 m_xPeer.dispose();
80 private static final String s_implName = "foo.java.impl";
81 private static final String s_serviceName = "foo.java";
83 // XServiceInfo impl
84 public String getImplementationName()
86 return s_implName;
89 public String [] getSupportedServiceNames()
91 return new String [] { s_serviceName };
94 public boolean supportsService( String serviceName )
96 return serviceName.equals( s_serviceName );
99 public static com.sun.star.lang.XSingleServiceFactory __getServiceFactory(
100 String implName,
101 com.sun.star.lang.XMultiServiceFactory multiFactory,
102 com.sun.star.registry.XRegistryKey regKey )
104 if (implName.equals( s_implName ))
106 return com.sun.star.comp.loader.FactoryHelper.getServiceFactory(
107 java_Service.class, s_serviceName, multiFactory, regKey );
109 return null;
112 public static boolean __writeRegistryServiceInfo(
113 com.sun.star.registry.XRegistryKey regKey )
115 return com.sun.star.comp.loader.FactoryHelper.writeRegistryServiceInfo(
116 s_implName, s_serviceName, regKey );