update dev300-m58
[ooovba.git] / sj2 / stardiv / applet / Document.java
blobb1eb9c5a7ab2efd599f23469947bce3c7667eb4a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Document.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package stardiv.applet;
32 import java.awt.Image;
34 // import java.applet.Applet;
35 // import java.applet.AppletContext;
36 // import java.applet.AudioClip;
39 import java.io.IOException;
41 import java.util.Enumeration;
42 import java.util.Hashtable;
43 import java.util.Observer;
44 import java.util.Observable;
46 import java.net.URL;
48 import java.applet.Applet;
49 import java.applet.AppletContext;
50 import java.applet.AudioClip;
52 import com.sun.star.lib.sandbox.ExecutionContext;
53 import com.sun.star.lib.sandbox.ResourceProxy;
55 class Document implements LiveConnectable {
56 private Hashtable executionContexts = new Hashtable();
57 private URL documentBase = null;
58 private java.awt.Toolkit toolkit;
60 Document(URL url, java.awt.Toolkit toolkit) {
61 // Create the document base.
62 //For example, suppose an applet is contained within the document:
63 //http://java.sun.com/products/jdk/1.2/index.html
64 //The document base is:
65 //http://java.sun.com/products/jdk/1.2/
67 String s= url.toString();
68 int index= s.lastIndexOf('/');
69 if( index != -1)
71 s=s.substring(0, index + 1);
73 try{
74 documentBase = new URL(s);
75 }catch(Exception e){
77 this.toolkit = toolkit;
80 void addExecutionContext(ExecutionContext executionContext, String name) {
81 executionContexts.put(name, executionContext);
84 void removeExecutionContext(String name) {
85 executionContexts.remove(name);
88 Enumeration getExecutionContexts() {
89 return executionContexts.elements();
92 URL getDocumentBase() {
93 return documentBase;
96 ExecutionContext getExecutionContext(String name) {
97 return (ExecutionContext)executionContexts.get(name);
100 Enumeration getExcutionContexts() {
101 return executionContexts.elements();
105 * Get the javascript environment for this applet.
108 public native Object getJavaScriptJSObjectWindow();
109 public native void appletResize( int width, int height );
110 public native void showDocument( URL url, String aTarget );
111 public native void showStatus( String status );
114 public AudioClip getAudioClip(URL url) {
115 ResourceProxy resourceProxy = ResourceProxy.load(url, null);
116 AudioClip audioClip = resourceProxy.getAudioClip();
118 return audioClip;
121 public Image getImage(URL url) {
122 ResourceProxy resourceProxy = ResourceProxy.load(url, null);
123 Image image = toolkit.createImage(resourceProxy.getImageProducer());
125 return image;
128 AppletExecutionContext getAppletExecutionContext() {
129 AppletExecutionContext appletExecutionContext = null;
131 for(Enumeration e = executionContexts.elements(); e.hasMoreElements();) {
132 Object object = e.nextElement();
133 if(object instanceof AppletExecutionContext) {
134 appletExecutionContext = (AppletExecutionContext)object;
137 return appletExecutionContext;
141 void showDocument(URL url, String aTarget) {
142 AppletExecutionContext appletExecutionContext = getAppletExecutionContext();
143 if(appletExecutionContext != null) appletExecutionContext.printDocument(url, aTarget);
146 public void showDocument(URL url) {
147 showDocument(url, "_top");
150 void showStatus(String status) {
151 status = (status == null) ? "" : status;
153 AppletExecutionContext appletExecutionContext = getAppletExecutionContext();
154 if(appletExecutionContext != null) appletExecutionContext.printStatus(status);
157 public Object getJavaScriptJSObjectWindow() {
158 Object object = null;
160 AppletExecutionContext appletExecutionContext = getAppletExecutionContext();
161 if(appletExecutionContext != null)
162 object = appletExecutionContext.getJavaScriptJSObjectWindow();
164 return object;