home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / pr8adpl7 / jfscomponent.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.3 KB  |  78 lines

  1. // JFScomponent.java
  2. // The base component from which all JFS client applets are derived. This
  3. // means that a file browser can load a client program to handle some file
  4. // type, and be sure that it has certain needed methods.
  5. import java.awt.*;
  6. import JFSclient;
  7.  
  8. public abstract class JFScomponent extends Panel
  9. {
  10.     JFSclient client;    // connection to JFS server
  11.  
  12.     // init
  13.     // This method is called after the constructor, for the component
  14.     // to create it's user interface. If the component is being loaded
  15.     // only to load() and print() something, this method will not be
  16.     // called. Note - if init() is called, then it is guaranteed to be
  17.     // before connect() and load().
  18.     void init(java.applet.Applet a) { }
  19.  
  20.     // connect
  21.     // Use the given client (which should be already connected and
  22.     // authenticated) for communication. The component should only
  23.     // enable itself when this method is called.
  24.     void connect(JFSclient c)
  25.     {
  26.     client = c;
  27.     }
  28.  
  29.     // load
  30.     // Load the given file. It must be of some type that this
  31.     // component can handle
  32.     void load(String file, int ver) throws RequestException
  33.     {
  34.     throw new RequestException("No load method defined for "+
  35.                    this.getClass().getName());
  36.     }
  37.  
  38.     // render
  39.     // Render a representation of the loaded data into a Graphics. This
  40.     // could be called by a program like a word processor that can
  41.     // embed other data into a document.
  42.     void render(Graphics g, int w, int h) { }
  43.  
  44.     // wantedsize
  45.     // Return the size that this component would like to be. There is
  46.     // no guarantee that it will actually get to be this size though.
  47.     abstract Dimension wantedsize();
  48.  
  49.     // print
  50.     // Prints the current document to the given printer, which is of
  51.     // the given type (ie. Postscript, Text, ...)
  52.     void print(String printer, String type) throws RequestException
  53.     {
  54.     throw new RequestException("No print method defined for "+
  55.                    this.getClass().getName());
  56.     }
  57.  
  58.     // save
  59.     // A convenience function for writing data to a file. If the file
  60.     // doesn't already exist then the version actually used is
  61.     // set to something sensible.
  62.     void save(byte data[], String file, String type, int ver, boolean m)
  63.         throws RequestException
  64.     {
  65.     boolean exists = true;
  66.     try client.statfile(file);
  67.     catch(RequestException e)
  68.         exists = false;
  69.     if (!exists) {
  70.         if (m) ver = 1;
  71.         else ver = 0;
  72.         }
  73.     client.put(file, ver, data, type);
  74.     client.setcurrent(file, type);
  75.     }
  76. }
  77.  
  78.