flatscape.util
Class DataSource

java.lang.Object
  |
  +--flatscape.util.DataSource

public class DataSource
extends java.lang.Object

The DataSource class contains static utility methods related to opening data for applications and applets from local files, jar files, files on the same web site as an applet, and other fully specified URL's. For the class to work properly for applets, the setApplet method must be called before any other methods are used.

Since:
flatscape %Version%
Version:
%Version%, %Time%
See Also:

Copyright (c) 2001 Rutgers, The State University of New Jersey


Method Summary
static java.lang.String getFile(java.awt.Component parent, java.lang.String current, javax.swing.filechooser.FileFilter filter)
           
static java.lang.String getFile(java.awt.Component parent, java.lang.String current, javax.swing.filechooser.FileFilter filter, java.lang.String source)
          Displays a dialog to specify a file to open, and returns the appropriate source String.
static java.lang.String getSaveFile(java.awt.Component parent, java.lang.String current, javax.swing.filechooser.FileFilter filter)
          Opens file chooser dialog and returns the filename selected or typed by the user
static java.net.URL getURL(java.lang.String source)
          Returns a fully specified URL based on the source String.
static boolean isApplet()
          Returns true if setApplet has been called.
static java.io.InputStream openStream(java.lang.String source)
          Returns an open input stream to the specified source.
static void setApplet(java.applet.Applet applet)
          Sets this class to attempt to resove URL's in the specified applet's code base context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isApplet

public static boolean isApplet()
Returns true if setApplet has been called.


setApplet

public static void setApplet(java.applet.Applet applet)
Sets this class to attempt to resove URL's in the specified applet's code base context.


getURL

public static java.net.URL getURL(java.lang.String source)
Returns a fully specified URL based on the source String. First, fully specified URL's are parsed and returned. If the source String is not a fully specified URL, the classpath is searched including any loaded jar files. Finally, if a valid URL is still not generated, and an applet has been set, a URL is constructed using the applet's code base context.

Returns:
A fully specified URL, or null if all steps fail to produce a URL.

openStream

public static java.io.InputStream openStream(java.lang.String source)
                                      throws java.io.IOException
Returns an open input stream to the specified source. The source parameter is resolved using the getURL method.

Throws:
java.io.IOException - Thrown if the source string is invalid, or a stream could not be opened.

getFile

public static java.lang.String getFile(java.awt.Component parent,
                                       java.lang.String current,
                                       javax.swing.filechooser.FileFilter filter)

getFile

public static java.lang.String getFile(java.awt.Component parent,
                                       java.lang.String current,
                                       javax.swing.filechooser.FileFilter filter,
                                       java.lang.String source)
Displays a dialog to specify a file to open, and returns the appropriate source String. If setApplet has been called, a simple input dialog is shown to allow entry of file names relative to the applet's code base. Otherwise a file chooser is displayed. The current and filter arguments can be set to null if not needed.


getSaveFile

public static java.lang.String getSaveFile(java.awt.Component parent,
                                           java.lang.String current,
                                           javax.swing.filechooser.FileFilter filter)
Opens file chooser dialog and returns the filename selected or typed by the user



Copyright (c) 2003 Rutgers, The State University of New Jersey