home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / edtplug / classes / netscape / test / plugin / composer / TextImageEncoder.java < prev   
Encoding:
Java Source  |  1998-04-08  |  3.7 KB  |  108 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.test.plugin.composer;
  20.  
  21. import netscape.plugin.composer.*;
  22. import java.io.*;
  23. import java.awt.image.*;
  24. import java.util.*;
  25.  
  26. public class TextImageEncoder extends ImageEncoder {
  27.     public static void main(String[] args){
  28.         ImageEncoderTest.Test(args, new TextImageEncoder());
  29.     }
  30.     public String getName(){
  31.         return "Text Image Encoder";
  32.     }
  33.     public void getFileType(byte[] type){
  34.         type[0] = 'T';
  35.         type[1] = 'E';
  36.         type[2] = 'X';
  37.         type[3] = 'T';
  38.     }
  39.     public String getFileExtension(){
  40.         return "txt";
  41.     }
  42.     public String getFormatName(){
  43.         return "Text";
  44.     }
  45.     public String getHint(){
  46.         return "Text Image Format";
  47.     }
  48.     public boolean encode(ImageProducer input, OutputStream output)
  49.         throws IOException {
  50.         PrintStream s = new PrintStream(output);
  51.         s.println("I am a test. The image is:");
  52.         ImageConsumer consumer = new TextImageConsumer(s);
  53.         input.addConsumer(consumer);
  54.         input.requestTopDownLeftRightResend(consumer);
  55.         input.removeConsumer(consumer);
  56.         return true;
  57.     }
  58. }
  59.  
  60.  
  61. class TextImageConsumer implements ImageConsumer {
  62.     public TextImageConsumer(PrintStream s) {
  63.         stream = s;
  64.     }
  65.     public void imageComplete(int status){
  66.         stream.println("imageComplete(" + status + ")");
  67.     }
  68.     public void setColorModel(ColorModel model){
  69.         stream.println("setColorModel(" + model + ")");
  70.     }
  71.     public void setDimensions(int x , int y) {
  72.         stream.println("setDimensions(" + x + ", " + y + ")");
  73.     }
  74.     public void setHints(int hint) {
  75.         stream.println("setHints(" + hint + ")");
  76.     }
  77.     public void setPixels(int x, int y, int w, int h,
  78.         ColorModel model, byte pixels[], int offset, int scansize) {
  79.         stream.println("setPixels(" + x + ", " + y + ", "
  80.             + w + ", " + h + ", " + model + ", " + pixels
  81.             + ", " + offset + ", " + scansize + ")");
  82.         for(int j = 0; j < h; j++ ) {
  83.             stream.print("[" + j + "]");
  84.             for (int i = 0; i < w; i++ ) {
  85.                 stream.print(" " + Integer.toHexString(pixels[scansize * j + i + offset]));
  86.             }
  87.             stream.println();
  88.         }
  89.     }
  90.     public void setPixels(int x, int y, int w, int h,
  91.         ColorModel model, int pixels[], int offset, int scansize) {
  92.         stream.println("setPixels(" + x + ", " + y + ", "
  93.             + w + ", " + h + ", " + model + ", " + pixels
  94.             + ", " + offset + ", " + scansize + ")");
  95.         for(int j = 0; j < h; j++ ) {
  96.             stream.print("[" + j + "]");
  97.             for (int i = 0; i < w; i++ ) {
  98.                 stream.print(" " + Integer.toHexString(pixels[scansize * j + i + offset]));
  99.             }
  100.             stream.println();
  101.         }
  102.     }
  103.     public void setProperties(Hashtable properties ) {
  104.     stream.println("setProperties(" + properties + ")");
  105.   }
  106.     private PrintStream stream;
  107. }
  108.