xref: /AOO41X/main/odk/examples/DevelopersGuide/OfficeBean/OOoBeanViewer.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir package com.sun.star.comp.beans;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir import javax.swing.filechooser.*;
38*cdf0e10cSrcweir import javax.swing.*;
39*cdf0e10cSrcweir import java.io.*;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir /** A simple Applet that contains the SimpleBean.
42*cdf0e10cSrcweir  *
43*cdf0e10cSrcweir  * This applet is a sample implementation of the
44*cdf0e10cSrcweir  * OpenOffice.org bean.
45*cdf0e10cSrcweir  * When initally loaded the applet has two buttons
46*cdf0e10cSrcweir  * one for opening an existant file and one to open
47*cdf0e10cSrcweir  * a blank document of a given type supported by
48*cdf0e10cSrcweir  * OpenOffice.org eg. Writer, Calc, Impress, .....
49*cdf0e10cSrcweir  *
50*cdf0e10cSrcweir  */
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir public class OOoBeanViewer extends java.applet.Applet
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir    /**
56*cdf0e10cSrcweir     * Private variables declaration - GUI components
57*cdf0e10cSrcweir     */
58*cdf0e10cSrcweir    private java.awt.Panel rightPanel;
59*cdf0e10cSrcweir    private java.awt.Panel bottomPanel;
60*cdf0e10cSrcweir    private javax.swing.JButton closeButton;
61*cdf0e10cSrcweir    private javax.swing.JButton terminateButton;
62*cdf0e10cSrcweir    private javax.swing.JButton newDocumentButton;
63*cdf0e10cSrcweir    private javax.swing.JPopupMenu documentTypePopUp;
64*cdf0e10cSrcweir    private javax.swing.JCheckBox menuBarButton;
65*cdf0e10cSrcweir    private javax.swing.JCheckBox mainBarButton;
66*cdf0e10cSrcweir    private javax.swing.JCheckBox toolBarButton;
67*cdf0e10cSrcweir    private javax.swing.JCheckBox statusBarButton;
68*cdf0e10cSrcweir    private javax.swing.JButton storeDocumentButton;
69*cdf0e10cSrcweir    private javax.swing.JButton loadDocumentButton;
70*cdf0e10cSrcweir    private javax.swing.JButton syswinButton;
71*cdf0e10cSrcweir    private JTextField documentURLTextField;
72*cdf0e10cSrcweir    private JMenuItem item;
73*cdf0e10cSrcweir    private JFileChooser fileChooser;
74*cdf0e10cSrcweir    private byte buffer[];
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir    /**
77*cdf0e10cSrcweir     * Private variables declaration - SimpleBean variables
78*cdf0e10cSrcweir     */
79*cdf0e10cSrcweir    private OOoBean aBean;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir    /**
82*cdf0e10cSrcweir     * Initialize the Appplet
83*cdf0e10cSrcweir     */
84*cdf0e10cSrcweir    public void init()
85*cdf0e10cSrcweir    {
86*cdf0e10cSrcweir 		//The aBean needs to be initialized to add it to the applet
87*cdf0e10cSrcweir 		aBean = new OOoBean();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         //Initialize GUI components
90*cdf0e10cSrcweir         rightPanel = new java.awt.Panel();
91*cdf0e10cSrcweir         bottomPanel = new java.awt.Panel();
92*cdf0e10cSrcweir         closeButton = new javax.swing.JButton("close");
93*cdf0e10cSrcweir         terminateButton = new javax.swing.JButton("terminate");
94*cdf0e10cSrcweir         newDocumentButton = new javax.swing.JButton("new document...");
95*cdf0e10cSrcweir         documentTypePopUp = new javax.swing.JPopupMenu();
96*cdf0e10cSrcweir         storeDocumentButton = new javax.swing.JButton("store to buffer");
97*cdf0e10cSrcweir         loadDocumentButton = new javax.swing.JButton("load from buffer");
98*cdf0e10cSrcweir         syswinButton = new javax.swing.JButton("release/aquire");
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir         menuBarButton = new javax.swing.JCheckBox("MenuBar");
101*cdf0e10cSrcweir 		menuBarButton.setSelected( aBean.isMenuBarVisible() );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir         mainBarButton = new javax.swing.JCheckBox("MainBar");
104*cdf0e10cSrcweir 		mainBarButton.setSelected( aBean.isStandardBarVisible() );
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir         toolBarButton = new javax.swing.JCheckBox("ToolBar");
107*cdf0e10cSrcweir 		toolBarButton.setSelected( aBean.isToolBarVisible() );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         statusBarButton = new javax.swing.JCheckBox("StatusBar");
110*cdf0e10cSrcweir 		statusBarButton.setSelected( aBean.isStatusBarVisible() );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir         documentURLTextField = new javax.swing.JTextField();
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         //Set up the Popup Menu to create a blank document
115*cdf0e10cSrcweir         documentTypePopUp.setToolTipText("Create an empty document");
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         item = documentTypePopUp.add("Text Document");
118*cdf0e10cSrcweir         item.addActionListener(new java.awt.event.ActionListener()
119*cdf0e10cSrcweir         {
120*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
121*cdf0e10cSrcweir             {
122*cdf0e10cSrcweir                 createBlankDoc("private:factory/swriter",
123*cdf0e10cSrcweir                     "New text document");
124*cdf0e10cSrcweir             }
125*cdf0e10cSrcweir         });
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir         item = documentTypePopUp.add("Presentation Document");
128*cdf0e10cSrcweir         item.addActionListener(new java.awt.event.ActionListener()
129*cdf0e10cSrcweir         {
130*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
131*cdf0e10cSrcweir             {
132*cdf0e10cSrcweir                 createBlankDoc("private:factory/simpress",
133*cdf0e10cSrcweir                     "New presentation document");
134*cdf0e10cSrcweir             }
135*cdf0e10cSrcweir         });
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir         item = documentTypePopUp.add("Drawing Document");
138*cdf0e10cSrcweir         item.addActionListener(new java.awt.event.ActionListener()
139*cdf0e10cSrcweir         {
140*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
141*cdf0e10cSrcweir             {
142*cdf0e10cSrcweir                 createBlankDoc("private:factory/sdraw",
143*cdf0e10cSrcweir                    "New drawing document");
144*cdf0e10cSrcweir             }
145*cdf0e10cSrcweir         });
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir         item = documentTypePopUp.add("Formula Document");
148*cdf0e10cSrcweir         item.addActionListener(new java.awt.event.ActionListener()
149*cdf0e10cSrcweir         {
150*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
151*cdf0e10cSrcweir             {
152*cdf0e10cSrcweir                 createBlankDoc("private:factory/smath",
153*cdf0e10cSrcweir                     "New formula document");
154*cdf0e10cSrcweir             }
155*cdf0e10cSrcweir         });
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir         item = documentTypePopUp.add("Spreadsheet Document");
158*cdf0e10cSrcweir         item.addActionListener(new java.awt.event.ActionListener()
159*cdf0e10cSrcweir         {
160*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
161*cdf0e10cSrcweir             {
162*cdf0e10cSrcweir                 createBlankDoc("private:factory/scalc",
163*cdf0e10cSrcweir                     "New spreadsheet document");
164*cdf0e10cSrcweir             }
165*cdf0e10cSrcweir         });
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir         syswinButton.addActionListener(
168*cdf0e10cSrcweir 				new java.awt.event.ActionListener()
169*cdf0e10cSrcweir         {
170*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
171*cdf0e10cSrcweir             {
172*cdf0e10cSrcweir 				try
173*cdf0e10cSrcweir 				{
174*cdf0e10cSrcweir 					aBean.releaseSystemWindow();
175*cdf0e10cSrcweir 					aBean.aquireSystemWindow();
176*cdf0e10cSrcweir 				}
177*cdf0e10cSrcweir 				catch ( com.sun.star.comp.beans.NoConnectionException aExc )
178*cdf0e10cSrcweir 				{}
179*cdf0e10cSrcweir 				catch ( com.sun.star.comp.beans.SystemWindowException aExc )
180*cdf0e10cSrcweir 				{}
181*cdf0e10cSrcweir 			}
182*cdf0e10cSrcweir        });
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir         storeDocumentButton.addActionListener(
185*cdf0e10cSrcweir 				new java.awt.event.ActionListener()
186*cdf0e10cSrcweir         {
187*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
188*cdf0e10cSrcweir             {
189*cdf0e10cSrcweir 				try
190*cdf0e10cSrcweir 				{
191*cdf0e10cSrcweir 					buffer = aBean.storeToByteArray( null, null );
192*cdf0e10cSrcweir 				}
193*cdf0e10cSrcweir 				catch ( Throwable aExc )
194*cdf0e10cSrcweir 				{
195*cdf0e10cSrcweir 					System.err.println( "storeToBuffer failed: " + aExc );
196*cdf0e10cSrcweir 					aExc.printStackTrace( System.err );
197*cdf0e10cSrcweir 				}
198*cdf0e10cSrcweir 			}
199*cdf0e10cSrcweir        });
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         loadDocumentButton.addActionListener(
202*cdf0e10cSrcweir 				new java.awt.event.ActionListener()
203*cdf0e10cSrcweir         {
204*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
205*cdf0e10cSrcweir             {
206*cdf0e10cSrcweir 				try
207*cdf0e10cSrcweir 				{
208*cdf0e10cSrcweir 					aBean.loadFromByteArray( buffer, null );
209*cdf0e10cSrcweir 				}
210*cdf0e10cSrcweir 				catch ( Throwable aExc )
211*cdf0e10cSrcweir 				{
212*cdf0e10cSrcweir 					System.err.println( "loadFromBuffer failed: " + aExc );
213*cdf0e10cSrcweir 					aExc.printStackTrace( System.err );
214*cdf0e10cSrcweir 				}
215*cdf0e10cSrcweir 			}
216*cdf0e10cSrcweir        });
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir        closeButton.addActionListener(new java.awt.event.ActionListener()
219*cdf0e10cSrcweir        {
220*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
221*cdf0e10cSrcweir             {
222*cdf0e10cSrcweir                 close();
223*cdf0e10cSrcweir             }
224*cdf0e10cSrcweir        });
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir        terminateButton.addActionListener(new java.awt.event.ActionListener()
227*cdf0e10cSrcweir        {
228*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
229*cdf0e10cSrcweir             {
230*cdf0e10cSrcweir                 terminate();
231*cdf0e10cSrcweir             }
232*cdf0e10cSrcweir        });
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir        newDocumentButton.addActionListener(new java.awt.event.ActionListener()
235*cdf0e10cSrcweir        {
236*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
237*cdf0e10cSrcweir             {
238*cdf0e10cSrcweir                 documentTypePopUp.show((java.awt.Component)evt.getSource(), 0,0);
239*cdf0e10cSrcweir             }
240*cdf0e10cSrcweir        });
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir        menuBarButton.addActionListener(new java.awt.event.ActionListener()
243*cdf0e10cSrcweir        {
244*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
245*cdf0e10cSrcweir             {
246*cdf0e10cSrcweir 				aBean.setMenuBarVisible( !aBean.isMenuBarVisible() );
247*cdf0e10cSrcweir             }
248*cdf0e10cSrcweir        });
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir        mainBarButton.addActionListener(new java.awt.event.ActionListener()
251*cdf0e10cSrcweir        {
252*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
253*cdf0e10cSrcweir             {
254*cdf0e10cSrcweir 				aBean.setStandardBarVisible( !aBean.isStandardBarVisible() );
255*cdf0e10cSrcweir             }
256*cdf0e10cSrcweir        });
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir        toolBarButton.addActionListener(new java.awt.event.ActionListener()
259*cdf0e10cSrcweir        {
260*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
261*cdf0e10cSrcweir             {
262*cdf0e10cSrcweir 				aBean.setToolBarVisible( !aBean.isToolBarVisible() );
263*cdf0e10cSrcweir             }
264*cdf0e10cSrcweir        });
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir        statusBarButton.addActionListener(new java.awt.event.ActionListener()
267*cdf0e10cSrcweir        {
268*cdf0e10cSrcweir             public void actionPerformed(java.awt.event.ActionEvent evt)
269*cdf0e10cSrcweir             {
270*cdf0e10cSrcweir 				aBean.setStatusBarVisible( !aBean.isStatusBarVisible() );
271*cdf0e10cSrcweir             }
272*cdf0e10cSrcweir        });
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir        documentURLTextField.setEditable(false);
275*cdf0e10cSrcweir        documentURLTextField.setPreferredSize(new java.awt.Dimension(200, 30));
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir        rightPanel.setLayout( new java.awt.GridLayout(10,1) );
278*cdf0e10cSrcweir        rightPanel.add(closeButton);
279*cdf0e10cSrcweir        rightPanel.add(terminateButton);
280*cdf0e10cSrcweir        rightPanel.add(newDocumentButton);
281*cdf0e10cSrcweir        rightPanel.add(storeDocumentButton);
282*cdf0e10cSrcweir        rightPanel.add(loadDocumentButton);
283*cdf0e10cSrcweir        rightPanel.add(syswinButton);
284*cdf0e10cSrcweir        rightPanel.add(menuBarButton);
285*cdf0e10cSrcweir        rightPanel.add(mainBarButton);
286*cdf0e10cSrcweir        rightPanel.add(toolBarButton);
287*cdf0e10cSrcweir        rightPanel.add(statusBarButton);
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir        //bottomPanel.setLayout( new java.awt.GridLayout(1,1) );
290*cdf0e10cSrcweir        bottomPanel.setLayout( new java.awt.BorderLayout() );
291*cdf0e10cSrcweir        bottomPanel.add(documentURLTextField);
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir        setLayout(new java.awt.BorderLayout());
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir        add(aBean, java.awt.BorderLayout.CENTER);
296*cdf0e10cSrcweir        add(rightPanel, java.awt.BorderLayout.EAST);
297*cdf0e10cSrcweir        add(bottomPanel, java.awt.BorderLayout.SOUTH);
298*cdf0e10cSrcweir    }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir    /**
301*cdf0e10cSrcweir     * Create a blank document of type <code>desc</code>
302*cdf0e10cSrcweir     *
303*cdf0e10cSrcweir     * @param url The private internal URL of the OpenOffice.org
304*cdf0e10cSrcweir     *            document describing the document
305*cdf0e10cSrcweir     * @param desc A description of the document to be created
306*cdf0e10cSrcweir     */
307*cdf0e10cSrcweir    private void createBlankDoc(String url, String desc)
308*cdf0e10cSrcweir    {
309*cdf0e10cSrcweir 		//Create a blank document
310*cdf0e10cSrcweir 		try
311*cdf0e10cSrcweir 		{
312*cdf0e10cSrcweir             documentURLTextField.setText(desc);
313*cdf0e10cSrcweir             //Get the office process to load the URL
314*cdf0e10cSrcweir             aBean.loadFromURL( url, null );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 	   		aBean.aquireSystemWindow();
317*cdf0e10cSrcweir 		}
318*cdf0e10cSrcweir 		catch ( com.sun.star.comp.beans.SystemWindowException aExc )
319*cdf0e10cSrcweir       	{
320*cdf0e10cSrcweir 			System.err.println( "OOoBeanViewer.1:" );
321*cdf0e10cSrcweir    			aExc.printStackTrace();
322*cdf0e10cSrcweir 		}
323*cdf0e10cSrcweir 		catch ( com.sun.star.comp.beans.NoConnectionException aExc )
324*cdf0e10cSrcweir 		{
325*cdf0e10cSrcweir 			System.err.println( "OOoBeanViewer.2:" );
326*cdf0e10cSrcweir 			aExc.printStackTrace();
327*cdf0e10cSrcweir 		}
328*cdf0e10cSrcweir 		catch ( Exception aExc )
329*cdf0e10cSrcweir 		{
330*cdf0e10cSrcweir 			System.err.println( "OOoBeanViewer.3:" );
331*cdf0e10cSrcweir 			aExc.printStackTrace();
332*cdf0e10cSrcweir 			//return;
333*cdf0e10cSrcweir 		}
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	/** closes the bean viewer, leaves OOo running.
337*cdf0e10cSrcweir 	 */
338*cdf0e10cSrcweir    private void close()
339*cdf0e10cSrcweir    {
340*cdf0e10cSrcweir 			setVisible(false);
341*cdf0e10cSrcweir 			aBean.stopOOoConnection();
342*cdf0e10cSrcweir 			stop();
343*cdf0e10cSrcweir 			System.exit(0);
344*cdf0e10cSrcweir    }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 	/** closes the bean viewer and tries to terminate OOo.
347*cdf0e10cSrcweir 	 */
348*cdf0e10cSrcweir    private void terminate()
349*cdf0e10cSrcweir    {
350*cdf0e10cSrcweir 			setVisible(false);
351*cdf0e10cSrcweir 			com.sun.star.frame.XDesktop xDesktop = null;
352*cdf0e10cSrcweir 			try {
353*cdf0e10cSrcweir 				xDesktop = aBean.getOOoDesktop();
354*cdf0e10cSrcweir 			}
355*cdf0e10cSrcweir 			catch ( com.sun.star.comp.beans.NoConnectionException aExc ) {} // ignore
356*cdf0e10cSrcweir 			aBean.stopOOoConnection();
357*cdf0e10cSrcweir 			stop();
358*cdf0e10cSrcweir 			if ( xDesktop != null )
359*cdf0e10cSrcweir 				xDesktop.terminate();
360*cdf0e10cSrcweir 			System.exit(0);
361*cdf0e10cSrcweir    }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir    /**
364*cdf0e10cSrcweir     * An ExitListener listening for windowClosing events
365*cdf0e10cSrcweir     */
366*cdf0e10cSrcweir    private class ExitListener extends java.awt.event.WindowAdapter
367*cdf0e10cSrcweir    {
368*cdf0e10cSrcweir         /**
369*cdf0e10cSrcweir          * windowClosed
370*cdf0e10cSrcweir          *
371*cdf0e10cSrcweir          * @param e A WindowEvent for a closed Window event
372*cdf0e10cSrcweir          */
373*cdf0e10cSrcweir         public void windowClosed( java.awt.event.WindowEvent e)
374*cdf0e10cSrcweir         {
375*cdf0e10cSrcweir 			close();
376*cdf0e10cSrcweir         }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir         /**
379*cdf0e10cSrcweir          * windowClosing for a closing window event
380*cdf0e10cSrcweir          *
381*cdf0e10cSrcweir          * @param e A WindowEvent for a closing window event
382*cdf0e10cSrcweir          */
383*cdf0e10cSrcweir         public void windowClosing( java.awt.event.WindowEvent e)
384*cdf0e10cSrcweir         {
385*cdf0e10cSrcweir             ((java.awt.Window)e.getSource()).dispose();
386*cdf0e10cSrcweir         }
387*cdf0e10cSrcweir    }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir    public static void main(String args[])
390*cdf0e10cSrcweir    {
391*cdf0e10cSrcweir        java.awt.Frame frame = new java.awt.Frame("OpenOffice.org Demo");
392*cdf0e10cSrcweir        OOoBeanViewer aViewer = new OOoBeanViewer();
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir        frame.setLayout(new java.awt.BorderLayout());
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir        frame.addWindowListener( aViewer.new ExitListener() );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir        aViewer.init();
399*cdf0e10cSrcweir        aViewer.start();
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir        frame.add(aViewer);
402*cdf0e10cSrcweir        frame.setLocation( 200, 200 );
403*cdf0e10cSrcweir        frame.setSize( 800, 480 );
404*cdf0e10cSrcweir        frame.show();
405*cdf0e10cSrcweir    }
406*cdf0e10cSrcweir }
407*cdf0e10cSrcweir 
408