home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / IAVAZIP.EXE / DATA.Z / ViewerPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-18  |  4.7 KB  |  151 lines

  1. package com.sfs.iavazip;
  2.  
  3. import com.sfs.debug.Debug;
  4. import com.sfs.iavazip.viewer.Viewer;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Dimension;
  9. import java.awt.GridLayout;
  10. import java.awt.Insets;
  11. import java.awt.Label;
  12. import java.awt.Panel;
  13. import java.io.File;
  14. import java.io.FileOutputStream;
  15. import java.io.IOException;
  16. import java.io.InputStream;
  17. import java.io.OutputStream;
  18. import java.util.Date;
  19. import java.util.zip.ZipEntry;
  20.  
  21. class ViewerPanel extends Panel {
  22.    ZipEntry zipEntry;
  23.    iavaZip mainApp;
  24.    File tempFile;
  25.    Label Name;
  26.    Label Size;
  27.    Label Time;
  28.    Viewer viewer;
  29.  
  30.    public Insets getInsets() {
  31.       return new Insets(2, 2, 2, 2);
  32.    }
  33.  
  34.    public void viewZipEntry(ZipEntry var1) {
  35.       this.mainApp.showStatus("Extracting " + var1.getName() + ". Please wait ...");
  36.       if (this.tempFile != null) {
  37.          ((Container)this).remove(this.viewer);
  38.          this.viewer.flush();
  39.          this.viewer = null;
  40.          System.runFinalization();
  41.          System.gc();
  42.          if (!this.tempFile.delete()) {
  43.             Debug.Info("ViewerPanel: delete failed.");
  44.          }
  45.       }
  46.  
  47.       String var2 = "temporary";
  48.       String var3 = "";
  49.  
  50.       try {
  51.          InputStream var4 = this.mainApp.zipFile.getInputStream(var1);
  52.          String var5 = var1.getName();
  53.          int var6 = var5.lastIndexOf(".");
  54.          if (var6 > var5.lastIndexOf("/")) {
  55.             String var15 = var5.substring(var6 + 1, var5.length());
  56.             var3 = var15.toLowerCase();
  57.             var2 = var2 + "." + var3;
  58.          }
  59.  
  60.          FileOutputStream var7 = new FileOutputStream(var2);
  61.          this.tempFile = new File(var2);
  62.          byte[] var8 = new byte[256];
  63.  
  64.          int var9;
  65.          while((var9 = var4.read(var8)) != -1) {
  66.             var7.write(var8, 0, var9);
  67.          }
  68.  
  69.          ((OutputStream)var7).flush();
  70.          var7.close();
  71.          Object var19 = null;
  72.       } catch (IOException var14) {
  73.          this.mainApp.showStatus("IOException by writing temporary file occured.");
  74.          Debug.Info("ioexception by writing " + var2);
  75.          ((Throwable)var14).printStackTrace();
  76.       }
  77.  
  78.       String var16 = this.mainApp.assigments.getProperty(var3);
  79.       if (var16 == null) {
  80.          var16 = this.mainApp.assigments.getProperty("default");
  81.       }
  82.  
  83.       try {
  84.          Class var17 = Class.forName(var16);
  85.          this.viewer = (Viewer)var17.newInstance();
  86.          if (this.viewer instanceof Viewer) {
  87.             this.viewer.setArgs(this.mainApp, var2);
  88.             ((Container)this).add(this.viewer);
  89.             if (!((Component)this).isVisible()) {
  90.                ((Component)this).setVisible(true);
  91.             }
  92.  
  93.             this.mainApp.doLayout();
  94.             ((Container)this).validateTree();
  95.          } else {
  96.             this.mainApp.showStatus("Error: Associated viewer \"" + var16 + "\" is not an instanceof viewer.Viewer.");
  97.          }
  98.  
  99.          this.Name.setText(var1.getName());
  100.          this.Size.setText(Long.toString(var1.getSize()) + " byte");
  101.          Date var18 = new Date(var1.getTime());
  102.          this.Time.setText(var18.toString());
  103.       } catch (ClassNotFoundException var11) {
  104.          Debug.Info("ClassNotFoundException");
  105.          this.mainApp.showStatus("ClassNotFoundException by lookup viewer class occured.");
  106.       } catch (InstantiationException var12) {
  107.          Debug.Info("InstantiationException");
  108.          this.mainApp.showStatus("InstantiationException by instantiating viewer class occured.");
  109.       } catch (IllegalAccessException var13) {
  110.          Debug.Info("IllegalAccessException by instantiating viewer class occured.");
  111.       }
  112.  
  113.       this.mainApp.showStatus("Viewing " + var1.getName());
  114.    }
  115.  
  116.    public Dimension getMinimumSize() {
  117.       return new Dimension(440, 480);
  118.    }
  119.  
  120.    public Dimension getPreferredSize() {
  121.       return ((Component)this).getSize();
  122.    }
  123.  
  124.    public void finalize() throws Throwable {
  125.       Debug.Info("finalize viewerpanel");
  126.       if (this.viewer != null) {
  127.          this.viewer.flush();
  128.          if (!this.tempFile.delete()) {
  129.             Debug.Info("ViewerPanel.finalize(): delete tempFile failed.");
  130.          }
  131.       }
  132.  
  133.       super.finalize();
  134.    }
  135.  
  136.    public ViewerPanel(iavaZip var1) {
  137.       this.mainApp = var1;
  138.       ((Container)this).setLayout(new 1(this));
  139.       ((Component)this).setBackground(Color.gray);
  140.       Panel var2 = new Panel();
  141.       ((Container)var2).setLayout(new GridLayout(3, 2));
  142.       ((Container)var2).add(new Label("Name :", 2));
  143.       ((Container)var2).add(this.Name = new Label(""));
  144.       ((Container)var2).add(new Label("Size :", 2));
  145.       ((Container)var2).add(this.Size = new Label(""));
  146.       ((Container)var2).add(new Label("Last changed :", 2));
  147.       ((Container)var2).add(this.Time = new Label(""));
  148.       ((Container)this).add("North", var2);
  149.    }
  150. }
  151.