home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.iavazip;
-
- import com.sfs.debug.Debug;
- import com.sfs.iavazip.viewer.Viewer;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.GridLayout;
- import java.awt.Insets;
- import java.awt.Label;
- import java.awt.Panel;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Date;
- import java.util.zip.ZipEntry;
-
- class ViewerPanel extends Panel {
- ZipEntry zipEntry;
- iavaZip mainApp;
- File tempFile;
- Label Name;
- Label Size;
- Label Time;
- Viewer viewer;
-
- public Insets getInsets() {
- return new Insets(2, 2, 2, 2);
- }
-
- public void viewZipEntry(ZipEntry var1) {
- this.mainApp.showStatus("Extracting " + var1.getName() + ". Please wait ...");
- if (this.tempFile != null) {
- ((Container)this).remove(this.viewer);
- this.viewer.flush();
- this.viewer = null;
- System.runFinalization();
- System.gc();
- if (!this.tempFile.delete()) {
- Debug.Info("ViewerPanel: delete failed.");
- }
- }
-
- String var2 = "temporary";
- String var3 = "";
-
- try {
- InputStream var4 = this.mainApp.zipFile.getInputStream(var1);
- String var5 = var1.getName();
- int var6 = var5.lastIndexOf(".");
- if (var6 > var5.lastIndexOf("/")) {
- String var15 = var5.substring(var6 + 1, var5.length());
- var3 = var15.toLowerCase();
- var2 = var2 + "." + var3;
- }
-
- FileOutputStream var7 = new FileOutputStream(var2);
- this.tempFile = new File(var2);
- byte[] var8 = new byte[256];
-
- int var9;
- while((var9 = var4.read(var8)) != -1) {
- var7.write(var8, 0, var9);
- }
-
- ((OutputStream)var7).flush();
- var7.close();
- Object var19 = null;
- } catch (IOException var14) {
- this.mainApp.showStatus("IOException by writing temporary file occured.");
- Debug.Info("ioexception by writing " + var2);
- ((Throwable)var14).printStackTrace();
- }
-
- String var16 = this.mainApp.assigments.getProperty(var3);
- if (var16 == null) {
- var16 = this.mainApp.assigments.getProperty("default");
- }
-
- try {
- Class var17 = Class.forName(var16);
- this.viewer = (Viewer)var17.newInstance();
- if (this.viewer instanceof Viewer) {
- this.viewer.setArgs(this.mainApp, var2);
- ((Container)this).add(this.viewer);
- if (!((Component)this).isVisible()) {
- ((Component)this).setVisible(true);
- }
-
- this.mainApp.doLayout();
- ((Container)this).validateTree();
- } else {
- this.mainApp.showStatus("Error: Associated viewer \"" + var16 + "\" is not an instanceof viewer.Viewer.");
- }
-
- this.Name.setText(var1.getName());
- this.Size.setText(Long.toString(var1.getSize()) + " byte");
- Date var18 = new Date(var1.getTime());
- this.Time.setText(var18.toString());
- } catch (ClassNotFoundException var11) {
- Debug.Info("ClassNotFoundException");
- this.mainApp.showStatus("ClassNotFoundException by lookup viewer class occured.");
- } catch (InstantiationException var12) {
- Debug.Info("InstantiationException");
- this.mainApp.showStatus("InstantiationException by instantiating viewer class occured.");
- } catch (IllegalAccessException var13) {
- Debug.Info("IllegalAccessException by instantiating viewer class occured.");
- }
-
- this.mainApp.showStatus("Viewing " + var1.getName());
- }
-
- public Dimension getMinimumSize() {
- return new Dimension(440, 480);
- }
-
- public Dimension getPreferredSize() {
- return ((Component)this).getSize();
- }
-
- public void finalize() throws Throwable {
- Debug.Info("finalize viewerpanel");
- if (this.viewer != null) {
- this.viewer.flush();
- if (!this.tempFile.delete()) {
- Debug.Info("ViewerPanel.finalize(): delete tempFile failed.");
- }
- }
-
- super.finalize();
- }
-
- public ViewerPanel(iavaZip var1) {
- this.mainApp = var1;
- ((Container)this).setLayout(new 1(this));
- ((Component)this).setBackground(Color.gray);
- Panel var2 = new Panel();
- ((Container)var2).setLayout(new GridLayout(3, 2));
- ((Container)var2).add(new Label("Name :", 2));
- ((Container)var2).add(this.Name = new Label(""));
- ((Container)var2).add(new Label("Size :", 2));
- ((Container)var2).add(this.Size = new Label(""));
- ((Container)var2).add(new Label("Last changed :", 2));
- ((Container)var2).add(this.Time = new Label(""));
- ((Container)this).add("North", var2);
- }
- }
-