001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: KiwiAppletContext.java,v $ 023 Revision 1.4 2004/05/06 00:46:52 markl 024 comment block updates 025 026 Revision 1.3 2003/06/02 06:49:44 markl 027 Added applet map management to context. 028 029 Revision 1.2 2003/06/01 11:08:55 markl 030 Final refinements for release 1.4.2 031 ---------------------------------------------------------------------------- 032*/ 033 034package kiwi.ui.applet; 035 036import java.applet.*; 037import java.awt.*; 038import java.io.*; 039import java.net.*; 040import java.util.*; 041 042import kiwi.ui.*; 043 044/** A basic implementation of an applet context. The 045 * <code>showDocument()</code> and <code>showStatus()</code> methods are 046 * no-ops and may be overriden by subclasses to provide application-specific 047 * behavior. 048 * 049 * @author Mark Lindner 050 * @since Kiwi 1.4.2 051 */ 052 053public abstract class KiwiAppletContext implements AppletContext 054 { 055 private Hashtable applets; 056 private Hashtable streams; 057 058 /** Construct a new Kiwi applet context. 059 */ 060 061 public KiwiAppletContext() 062 { 063 applets = new Hashtable(); 064 streams = new Hashtable(); 065 } 066 067 /** Add an applet to the applet context. 068 * 069 * @param name The name of the applet. 070 * @param applet The applet to add. 071 */ 072 073 public void addApplet(String name, Applet applet) 074 { 075 applets.put(name, applet); 076 } 077 078 /** Remove an applet from the applet context. 079 * 080 * @param name The name of the applet to remove. 081 */ 082 083 public void removeApplet(String name) 084 { 085 applets.remove(name); 086 } 087 088 /** Look up an applet by name. 089 * 090 * @param name The name of the applet 091 * @return The <code>Applet</code> object on success, or <code>null</code> 092 * if an applet with the given name was not found in this applet context. 093 */ 094 095 public Applet getApplet(String name) 096 { 097 return((Applet)applets.get(name)); 098 } 099 100 /** Get all of the applets managed by this applet context. 101 * 102 * @return An enumeration of <code>Applet</code> objects. 103 */ 104 105 public Enumeration getApplets() 106 { 107 return(applets.elements()); 108 } 109 110 /** Load an audio clip at the specified URL. 111 * 112 * @param url The URL of the audio clip to load. 113 * @return The audio clip on success, or <code>null</code> on failure. 114 */ 115 116 public java.applet.AudioClip getAudioClip(URL url) 117 { 118 java.applet.AudioClip ac = null; 119 120 try 121 { 122 ac = new kiwi.ui.AudioClip(url); 123 124 } 125 catch(Exception ex) { ex.printStackTrace(); } 126 127 return(ac); 128 } 129 130 /** Load an image at the specified URL. 131 * 132 * @param url The URL of the image to load. 133 * @return The image on success, or <code>null</code> on failure. 134 */ 135 136 public Image getImage(URL url) 137 { 138 Toolkit tk = Toolkit.getDefaultToolkit(); 139 140 Image img = tk.getImage(url); 141 142 return(img); 143 } 144 145 /** Display the document at the given URL. The default implementation does 146 * nothing. 147 */ 148 149 public void showDocument(URL url) 150 { 151 } 152 153 /** Display the document at the given URL. The default implementation does 154 * nothing. 155 */ 156 157 public void showDocument(URL url, String target) 158 { 159 } 160 161 /** Get a list of keys of the streams associated with this applet context. 162 * 163 * @return An iterator for the stream keys. 164 */ 165 166 public Iterator getStreamKeys() 167 { 168 return(streams.keySet().iterator()); 169 } 170 171 /** Associate a stream with this applet context. 172 * 173 * @param key The key for the stream. 174 * @param stream The stream. 175 * @exception java.io.IOException If an I/O exception occurs. 176 */ 177 178 public void setStream(String key, InputStream stream) throws IOException 179 { 180 streams.put(key, stream); 181 } 182 183 /** Look up a stream by key. 184 * 185 * @param key The key for the stream. 186 * @return The <code>InputStream</code> on success, or <code>null</code> if 187 * a stream with the given key is not associated with this applet context. 188 */ 189 190 public InputStream getStream(String key) 191 { 192 return((InputStream)streams.get(key)); 193 } 194 195 /** Display a status message from the applet. The default implementation 196 * does nothing. 197 * 198 * @param msg The message to display. 199 */ 200 201 public void showStatus(String msg) 202 { 203 } 204 205 } 206 207/* end of source file */