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
)
19 (XToolkit
) UnoRuntime
.queryInterface(
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 );
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
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(
59 m_xToolkit
.createWindow(
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
) ) );
69 "Title", "[office window created by Java code] " + msg
);
72 public void closeWindows()
73 throws com
.sun
.star
.uno
.Exception
80 private static final String s_implName
= "foo.java.impl";
81 private static final String s_serviceName
= "foo.java";
84 public String
getImplementationName()
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(
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
);
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
);