home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / edtplug / classes / netscape / plugin / composer / ImageEncoder.java < prev    next >
Encoding:
Java Source  |  1998-04-08  |  6.9 KB  |  162 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. package netscape.plugin.composer;
  20.  
  21. import java.io.IOException;
  22. import java.io.OutputStream;
  23. import java.awt.image.ImageProducer;
  24. import java.util.Vector;
  25. import java.util.Enumeration;
  26.  
  27. /** ImageEncoders allow image data to be encoded to match specific image formats.
  28.  * All composer image encoders descend from this class. When the user asks for
  29.  * an image to be encoded, the image encoder's encode method is called with
  30.  * the image data and an output stream. The encoder examins the input data,
  31.  * communicates with the user as nescessary, and then writes the encoded
  32.  * image to the output stream.
  33.  *
  34.  * ImageEncoders are like Applet or Application, in that they are the main class
  35.  * of your mini appication. This is where the flow of control transfers from the
  36.  * editor to you.
  37.  *
  38.  * Your encoder is instantiated when the first composer window is opened, and is
  39.  * deleted when the application exits.
  40.  *
  41.  * <p>Packageing Image Encoders
  42.  * <p>To package your image encoder, create an uncompressed zip file with the file name
  43.  * cpXXX.zip, where XXX can be anything you want. (It has to be unique, so use
  44.  * your company name, or the plugin name, or something like that.)
  45.  * Put all your classes into that .zip file. At the top level of the .zip archive,
  46.  * add a file called "netscape_plugin_composer.ini".
  47.  * <p> Format of the "netscape_plugin_composer.ini" file.
  48.  * <p> It is in standard java "Properties" file format.
  49.  * The following properties are 'well known', and are used by the composer plugin
  50.  * framework:
  51.  * <pre>
  52.  * netscape.plugin.composer.imageEncoder.factory - a single classname of a Factory class.
  53.  * netscape.plugin.composer.imageEncoder.classes - a colon-seperated list of the classnames of the plugins in
  54.  * this archive.
  55.  * </pre>
  56.  * <p> Your encoder's class name should be listed as the value of the
  57.  * netscape.plugin.composer.imageEncoder.classes
  58.  * property. You can place several encoders in the same plugin file. All the encoder names should be
  59.  * listed in the netscape.plugin.composer.imageEncoder.classes property.
  60.  * <p> Alternatively, you can use a factory class to create your image encoders at runtime.
  61.  * <p>
  62.  * <p>Installing the Image Encoder package.
  63.  * <p> Put that .zip file in the Netscape Plugins directory (or a subdirectory.) Then restart the
  64.  * Composer application.
  65.  * @see netscape.plugin.composer.Plugin
  66.  * @see netscape.plugin.composer.ImageEncoderFactory
  67.  *
  68.  */
  69. public class ImageEncoder {
  70.     /** The default constructor for an image encoder. If you have a default constructor, it must be public.
  71.      * so that your image encoder can be instantiated by name. (Also, your image encoder class must be a public
  72.      * class so that it can be instantiated by name.)
  73.      */
  74.     public ImageEncoder() {}
  75.  
  76.     /** Get the human readable name of the image encoder. Defaults to the name of the image encoder class. This
  77.      * text will show up as the text of a menu item.
  78.      * @return the human readable name of the image encoder.
  79.      */
  80.     public String getName()
  81.     {
  82.         return getClass().getName();
  83.     }
  84.  
  85.     /** Get the human readable hint text for the image encoder. This is a one-sentence description of
  86.      * what the image encoder does. Defaults to the name of the image encoder class. This text will
  87.      * show up in the status line as the user moves the mouse over the plug-in's menu item.
  88.      * @return the human readable hint for the image encoder.
  89.      */
  90.     public String getHint()
  91.     {
  92.         return getClass().getName();
  93.     }
  94.  
  95.     /** Get the standard file extension of the image format. Defaults to the
  96.      * empty string. Does not include the period.
  97.      * @return the human readable category of the image encoder.
  98.      */
  99.     public String getFileExtension()
  100.     {
  101.         return new String();
  102.     }
  103.  
  104.     /** Get the Macintosh FileType of the image format. Defaults to '????'.
  105.      * @param type - a 4 byte array to be filled in with the FileType of the image format.
  106.      */
  107.     public void getFileType(byte[] type)
  108.     {
  109.         type[0] = '?';
  110.         type[1] = '?';
  111.         type[2] = '?';
  112.         type[3] = '?';
  113.     }
  114.  
  115.     /** Does the source image have to be quantized? If this method returns true,
  116.      * then the source image will be quantized (by some method) to contain
  117.      * 256 or fewer distinct colors. If you want to use a specific quantization
  118.      * technique, or if you want to interact with the user to optionally quantize,
  119.      * then you will have to return false from this method, and supply your own
  120.      * quantization code.
  121.      * <p> Returns false by default.
  122.      * @return true if the source image must be quantized before it is passed to encode().
  123.      */
  124.     public boolean needsQuantizedSource(){
  125.         return false;
  126.     }
  127.  
  128.     /** Encode the image.
  129.      * Override this method to perform the bulk of your work.
  130.      * This is where your image encoder reads the image information out of the
  131.      * image source, interacts
  132.      * with the user, and writes the encoded information to the output stream.
  133.      * <p>
  134.      * The rest of the composer user interface is held in a modal state while your image encoder
  135.      * is executing. So either finish quickly, or display a progress dialog, or otherwise
  136.      * let the user know what's going on.
  137.      * <p>
  138.      * By default this method returns false.
  139.      * @param source the image to encode.
  140.      * @param destination the output stream to write the encoded information to.
  141.      * @return true if the encoding should be permenent. False if the
  142.      * encoding should be cancled. (Return false if the user Cancels the operation.)
  143.      */
  144.     public boolean encode(ImageProducer source, OutputStream output) throws IOException {
  145.         return false;
  146.     }
  147.  
  148.     /** Used to register an encoder with the system. Registered encoders are
  149.      * available for any program to use.
  150.      * @param encoder An encoder to be register.
  151.      */
  152.     public static void register(ImageEncoder encoder) {
  153.         encoders_.addElement(encoder);
  154.     }
  155.     /* Returns the registered encoders.
  156.      */
  157.     public static Enumeration encoders() {
  158.         return encoders_.elements();
  159.     }
  160.     private static Vector encoders_ = new Vector();
  161. }
  162.