home *** CD-ROM | disk | FTP | other *** search
/ Chip Special: HTML & Java / Chip-Special_1997-01_HTML-a-Java.bin / javasdk / sdk-java.exe / SDKJava.cab / Samples / Version / VersionPanelTest.java < prev    next >
Encoding:
Java Source  |  1996-10-10  |  2.5 KB  |  115 lines

  1. // VersionPanelTest.java
  2. //
  3. // Created 09/25/96
  4. //
  5. // (C)Copyright 1996 Microsoft Corporation, All rights reserved.
  6. //
  7.  
  8. import java.io.*;
  9. import java.awt.*;
  10. import com.ms.util.*;
  11.  
  12.  
  13. public
  14. class VersionPanelTest extends TestFrame
  15. {
  16.     MenuItem openitem;
  17.     VersionPanel verpanel;
  18.     static String BASE_TITLE = "VersionPanelTest";
  19.  
  20.  
  21.     // Updates the window with information about a new file, if available.
  22.  
  23.     public void newfile (File file)
  24.     {
  25.         if (file == null)
  26.         {
  27.             verpanel.clearInfo();
  28.             return;
  29.         }
  30.     
  31.         try
  32.         {
  33.             FileVersionInformation version;
  34.         
  35.             version = new FileVersionInformation(file);
  36.             verpanel.changeInfo(version);
  37.         }
  38.         catch (IOException e)
  39.         {
  40.             // Information could not be obtained.
  41.         
  42.             verpanel.clearInfo();
  43.         }
  44.         catch (SecurityException e)
  45.         {
  46.             // If an applet, the exception was probably already logged.
  47.                 
  48.             if (!isapplet)
  49.             {
  50.                 System.err.println("unexpected FileVersionInformation error: "+e);
  51.                 e.printStackTrace();
  52.             }
  53.             
  54.             verpanel.clearInfo();
  55.         }
  56.  
  57.         setTitle(BASE_TITLE + " - " + file.getAbsolutePath());
  58.         verpanel.repaint();
  59.     }
  60.  
  61.  
  62.     // from TestFrame - add custom File menu items
  63.  
  64.     protected void addFileMenuItems (Menu filemenu)
  65.     {
  66.         openitem = new MenuItem("Open...");
  67.         filemenu.add(openitem);
  68.     }
  69.  
  70.  
  71.     public VersionPanelTest (File file)
  72.     {
  73.         super(BASE_TITLE);
  74.  
  75.         verpanel = new VersionPanel();
  76.         add("Center",verpanel);
  77.         
  78.         pack();
  79.  
  80.         newfile(file);
  81.         
  82.         show();
  83.     }
  84.  
  85.  
  86.     public boolean handleEvent (Event e)
  87.     {
  88.         if (e.target == openitem)
  89.         {
  90.             FileDialog dlg = new FileDialog(this, "Get File Version");
  91.             dlg.show();
  92.             if (dlg.getFile() != null)
  93.             {
  94.                 String filename = dlg.getDirectory()+dlg.getFile();
  95.                 newfile(new File(filename));
  96.             }
  97.         }
  98.  
  99.         return super.handleEvent(e);
  100.     }
  101.  
  102.  
  103.     public static void main (String[] args)
  104.     {
  105.         if (args.length > 1)
  106.         {
  107.             System.err.println("usage: VersionPanelText [file]");
  108.             System.exit(1);
  109.         }
  110.  
  111.         new VersionPanelTest(args.length > 0 ? new File(args[0]) : null);
  112.     }
  113. }
  114.  
  115.