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 / VersionPanel.java < prev    next >
Encoding:
Java Source  |  1996-10-10  |  4.8 KB  |  193 lines

  1. // VersionPanel.java
  2. //
  3. // Created 09/25/96
  4. //
  5. // (C)Copyright 1996 Microsoft Corporation, All rights reserved.
  6. //
  7.  
  8. import java.awt.*;
  9. import java.util.*;
  10. import java.io.*;
  11. import com.ms.util.*;
  12.  
  13. public
  14. class VersionPanel extends Panel
  15. {
  16.     static Label addText (String str, Panel p, GridBagConstraints c)
  17.     {
  18.         Label text = new Label(str);
  19.  
  20.         ((GridBagLayout)p.getLayout()).setConstraints(text,c);
  21.         p.add(text);
  22.  
  23.         return text;
  24.     }
  25.  
  26.     List items;
  27.     TextArea value;
  28.     Label filever;
  29.     Label descr;
  30.     Label copyright;
  31.     Properties version;
  32.  
  33.     void addVersionItems (Properties version, List items)
  34.     {
  35.         Enumeration e;
  36.  
  37.         e = version.keys();
  38.  
  39.         while (e.hasMoreElements())
  40.         {
  41.             String key = (String)e.nextElement();
  42.             String value = version.getProperty(key);
  43.  
  44.             if (!(   key.equals("LegalCopyright") 
  45.                   || key.equals("FileVersion") 
  46.                   || key.equals("Description")    ))
  47.             {
  48.                 items.addItem(key);
  49.             }
  50.         }
  51.     }
  52.  
  53.     public VersionPanel ()
  54.     {
  55.         version = null;
  56.     
  57.         GridBagLayout grid = new GridBagLayout();
  58.         setLayout(grid);
  59.  
  60.         GridBagConstraints c = new GridBagConstraints();
  61.  
  62.         c.anchor = GridBagConstraints.WEST;
  63.         c.fill = GridBagConstraints.HORIZONTAL;
  64.         addText("File version:",this,c);
  65.         
  66.         c.gridwidth = GridBagConstraints.REMAINDER;
  67.         filever = addText("", this, c);
  68.  
  69.         c.gridwidth = 1;
  70.         addText("Description:",this,c);
  71.         
  72.         c.gridwidth = GridBagConstraints.REMAINDER;
  73.         descr = addText("",this,c);
  74.  
  75.         c.gridwidth = 1;
  76.         addText("Copyright:",this,c);
  77.         
  78.         c.gridwidth = GridBagConstraints.REMAINDER;
  79.         copyright = addText("",this,c);
  80.  
  81.         c.anchor = GridBagConstraints.SOUTHWEST;
  82.         addText("Other version information",this,c);
  83.  
  84.  
  85.         c.weightx = 1;
  86.         c.weighty = 1;
  87.         c.anchor = GridBagConstraints.CENTER;
  88.         c.gridheight = GridBagConstraints.REMAINDER;
  89.         c.fill = GridBagConstraints.BOTH;
  90.         Panel bot = new Panel();
  91.         grid.setConstraints(bot,c);        
  92.         add(bot);
  93.         grid = new GridBagLayout();
  94.         bot.setLayout(grid);
  95.  
  96.         c.weightx = 0;
  97.         c.weighty = 0;
  98.         c.gridheight = 1;
  99.         c.gridwidth = 1;
  100.         c.anchor = GridBagConstraints.SOUTHWEST;
  101.         c.fill = GridBagConstraints.NONE;
  102.         addText("Item name:",bot,c);
  103.  
  104.         c.gridwidth = GridBagConstraints.REMAINDER;
  105.         addText("Value:",bot,c);
  106.  
  107.         c.weightx = 1;
  108.         c.weighty = 1;
  109.         c.gridwidth = 1;
  110.         c.gridheight = GridBagConstraints.REMAINDER;
  111.         c.anchor = GridBagConstraints.CENTER;
  112.         c.fill = GridBagConstraints.BOTH;
  113.         items = new List();
  114.         grid.setConstraints(items,c);
  115.         bot.add(items);
  116.  
  117.         c.gridwidth = GridBagConstraints.REMAINDER;
  118.         value = new TextArea();
  119.         value.setEditable(false);
  120.         grid.setConstraints(value,c);
  121.         bot.add(value);
  122.     }
  123.  
  124.     VersionPanel (Properties i_version)
  125.     {
  126.         this();
  127.         version = i_version;
  128.  
  129.         changeInfo(version);
  130.     }
  131.  
  132.     public boolean handleEvent (Event e)
  133.     {
  134.         if (e.id == Event.LIST_SELECT)
  135.         {
  136.             value.setText((String)version.getProperty(items.getItem(items.getSelectedIndex())));
  137.             return true;
  138.         }
  139.  
  140.         return false;
  141.     }
  142.  
  143.     public void clearInfo ()
  144.     {
  145.         if (version == null)
  146.             return;
  147.             
  148.         items.clear();
  149.         value.setText("");
  150.         version = null;
  151.         filever.setText("");
  152.         descr.setText("");
  153.         copyright.setText("");
  154.     }
  155.  
  156.     public void changeInfo (Properties newinfo)
  157.     {
  158.         if (newinfo == null)
  159.         {
  160.             clearInfo();
  161.             version = null;
  162.             return;
  163.         }
  164.     
  165.         version = newinfo;
  166.         
  167.         items.clear();
  168.         value.setText("");
  169.  
  170.         String prop = version.getProperty("FileVersion");
  171.  
  172.         if (prop == null)
  173.         {
  174.             filever.setText(
  175.                          version.getProperty("MajorVersion")+"."
  176.                         +version.getProperty("MinorVersion")+"."
  177.                         +version.getProperty("BuildNumber")+"."
  178.                         +version.getProperty("BuildIncrement")
  179.                         );
  180.         }
  181.         else
  182.         {
  183.             filever.setText(prop);
  184.         }
  185.  
  186.         addVersionItems(version,items);
  187.         
  188.         descr.setText(version.getProperty("Description"));
  189.         copyright.setText(version.getProperty("LegalCopyright"));
  190.     }
  191. }
  192.  
  193.