home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.iavazip.viewer;
-
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.Toolkit;
- import java.awt.image.DirectColorModel;
- import java.io.DataInputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.net.URL;
-
- public class ImageLoader implements Runnable {
- public boolean imageLoaded;
- public Image newImage;
- protected ProgressStatus imageClient;
- protected int[] frameBuffer;
- protected FileInput imageFile = new FileInput();
- protected boolean debug;
- protected int xRes;
- protected int yRes;
- protected int actLine;
- protected int lastPercent;
- protected int actPercent;
- private static Component client;
- private MediaTracker tracker;
- private ImageLoader newLoader;
- private DirectColorModel colorModel;
- private DataInputStream data;
- private Thread runner;
- private static int done;
- private String theFileName;
- private ImageClassLoader classLoader;
- protected ImageLoaderProducer myProd;
-
- public final void initFrameBuffer(int var1, int var2) {
- this.xRes = var1;
- this.yRes = var2;
- this.frameBuffer = new int[var1 * var2];
- }
-
- protected final void sleep(int var1) {
- try {
- Thread.sleep((long)var1);
- } catch (InterruptedException var2) {
- }
- }
-
- public final void setClient(ProgressStatus var1) {
- this.imageClient = var1;
- }
-
- protected void loadPicture() throws IOException {
- this.print("default loadPicture() method");
- }
-
- public Image load(URL var1, Component var2) {
- String var3 = var1.getFile().toUpperCase();
- this.print("URL file name: " + var1.getFile());
- client = var2;
- this.colorModel = new DirectColorModel(24, 16711680, 65280, 255);
- this.theFileName = var3;
- if (var3.endsWith("GIF") | var3.endsWith("JPG") | var3.endsWith("JPEG")) {
- this.tracker = new MediaTracker(client);
- this.newImage = Toolkit.getDefaultToolkit().getImage(var1);
- this.tracker.addImage(this.newImage, 0);
-
- try {
- this.tracker.waitForID(0);
- } catch (InterruptedException var7) {
- this.print(((Throwable)var7).getMessage());
- }
-
- this.imageLoaded = true;
- } else {
- try {
- this.data = new DataInputStream(var1.openStream());
- this.startLoadProcess(var3, this.data);
- } catch (IOException var6) {
- this.print(((Throwable)var6).getMessage());
- }
- }
-
- return this.newImage;
- }
-
- public Image load(String var1, Component var2) {
- String var3 = var1.toUpperCase();
- client = var2;
- this.colorModel = new DirectColorModel(24, 16711680, 65280, 255);
- this.theFileName = var3;
- if (var3.endsWith("GIF") | var3.endsWith("JPG") | var3.endsWith("JPEG")) {
- this.tracker = new MediaTracker(client);
- this.newImage = Toolkit.getDefaultToolkit().getImage(var1);
- this.tracker.addImage(this.newImage, 0);
-
- try {
- this.tracker.waitForID(0);
- } catch (InterruptedException var7) {
- this.print(((Throwable)var7).getMessage());
- }
-
- this.imageLoaded = true;
- } else {
- try {
- this.data = new DataInputStream(new FileInputStream(var1));
- this.startLoadProcess(var3, this.data);
- } catch (FileNotFoundException var6) {
- this.print(((Throwable)var6).getMessage());
- }
- }
-
- return this.newImage;
- }
-
- public final void debug(boolean var1) {
- this.debug = var1;
- }
-
- public String getInfo() {
- return "";
- }
-
- private boolean startLoadProcess(String var1, DataInputStream var2) {
- Object var3 = null;
- int var4 = var1.length();
- int var5 = var1.lastIndexOf(".");
- String var6 = var1.substring(var5 + 1, var4);
- this.newImage = client.createImage(1, 1);
-
- try {
- Class var7 = this.getClass();
- Class var16;
- if (var7.getClassLoader() == null) {
- this.classLoader = new ImageClassLoader();
- var16 = this.classLoader.loadClass(var7.getName() + var6, true);
- } else {
- try {
- var16 = Class.forName("zfileio.ImageLoader" + var6);
- var16.getName();
- } catch (ClassNotFoundException var14) {
- var16 = null;
- this.print(((Throwable)var14).getMessage());
- }
- }
-
- if (var16 == null) {
- this.print("ImageLoader subclass 'ImageLoader" + var6 + ".class' not found.");
- }
-
- try {
- this.print("Invoking ImageLoader class: " + var16.toString());
- this.newLoader = (ImageLoader)var16.newInstance();
- this.newLoader.debug(this.debug);
- this.newLoader.setClient(this.imageClient);
- this.newLoader.imageFile.use(var2);
- this.print("Starting loader " + this.newLoader.toString());
-
- try {
- this.newLoader.readHeader();
- } catch (IOException var10) {
- this.print(((Throwable)var10).getMessage());
- }
-
- if (client == null) {
- return false;
- }
-
- this.newLoader.myProd = new ImageLoaderProducer();
- this.newLoader.myProd.setDimensions(this.newLoader.xRes, this.newLoader.yRes, this.colorModel);
- this.newImage = this.newLoader.myProd.createImage(client);
- this.start();
- } catch (IOException var11) {
- this.print(((Throwable)var11).getMessage());
- } catch (InstantiationException var12) {
- this.print(((Throwable)var12).getMessage());
- } catch (IllegalAccessException var13) {
- this.print(((Throwable)var13).getMessage());
- }
- } catch (ClassNotFoundException var15) {
- this.print(((Throwable)var15).getMessage());
- }
-
- return false;
- }
-
- public void start() {
- this.runner = new Thread(this);
- this.runner.start();
- }
-
- protected void readHeader() throws IOException {
- this.print("default readHeader() method");
- }
-
- public void run() {
- try {
- this.print("Loading the image...");
- this.newLoader.loadPicture();
- this.print("Updating the frame's buffer...");
- this.newLoader.myProd.update(this.newLoader.frameBuffer);
- Graphics var1 = client.getGraphics();
- client.paint(var1);
- if (this.imageClient != null) {
- this.imageClient.imageLoaded(100, this.newImage, "Image completed ");
- }
- } catch (IOException var3) {
- this.print(((Throwable)var3).getMessage());
- }
-
- this.runner.stop();
- this.runner = null;
- System.gc();
- }
-
- protected final void print(String var1) {
- if (this.debug) {
- System.out.println(var1);
- }
-
- }
- }
-