home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1999 January / maximum-cd-1999-01.iso / Benchmarks / 12 Step / MusicMatch Jukebox / mmsetup.EXE / data1.cab / Help_Files / WebHelp.cab / hhapplet / IndexPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-27  |  4.8 KB  |  209 lines

  1. package hhapplet;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.BorderLayout;
  5. import java.awt.Button;
  6. import java.awt.Color;
  7. import java.awt.Container;
  8. import java.awt.Event;
  9. import java.awt.Font;
  10. import java.awt.LayoutManager;
  11. import java.awt.List;
  12. import java.awt.Panel;
  13. import java.awt.TextField;
  14. import java.net.MalformedURLException;
  15. import java.util.Vector;
  16.  
  17. public class IndexPane extends Panel implements DialogDoneTarget {
  18.    protected Applet m_applet;
  19.    protected Vector m_vSecondaryEntries = new Vector();
  20.    protected List m_list = new List();
  21.    protected TextField m_tfEdit = new TextField();
  22.    protected Button m_btnDisplay = new Button("Display");
  23.    protected IndexSecondaryDialog m_dlgSecondary;
  24.    protected int m_nSelectedIndex = -1;
  25.    protected boolean m_bIsIE4;
  26.    protected boolean m_bIsNSWin16;
  27.    protected boolean m_bIsNSWin32;
  28.    protected boolean m_bIsIE3;
  29.    private LayoutManager m_layout;
  30.  
  31.    public boolean gotFocus(Event var1, Object var2) {
  32.       if (var1.target != this.m_tfEdit && var1.target != this.m_list && var1.target != this.m_btnDisplay) {
  33.          this.m_tfEdit.requestFocus();
  34.       }
  35.  
  36.       return true;
  37.    }
  38.  
  39.    public void dialogDone() {
  40.       this.m_dlgSecondary = null;
  41.       this.m_tfEdit.requestFocus();
  42.    }
  43.  
  44.    public IndexPane(Applet var1) {
  45.       this.m_applet = var1;
  46.       this.m_layout = new BorderLayout(5, 5);
  47.       ((Container)this).setLayout(this.m_layout);
  48.       this.m_list.setBackground(Color.white);
  49.  
  50.       try {
  51.          if (System.getProperty("java.vendor").startsWith("Netscape")) {
  52.             if (System.getProperty("os.name").startsWith("16-bit Windows")) {
  53.                this.m_bIsNSWin16 = true;
  54.             } else if (System.getProperty("os.name").startsWith("Windows")) {
  55.                this.m_bIsNSWin32 = true;
  56.             }
  57.          } else if (System.getProperty("java.vendor").startsWith("Microsoft")) {
  58.             if (System.getProperty("java.version").startsWith("1.1")) {
  59.                this.m_bIsIE4 = true;
  60.             } else {
  61.                this.m_bIsIE3 = true;
  62.             }
  63.          }
  64.       } finally {
  65.          ;
  66.       }
  67.  
  68.       int var2 = WebHelp.GetFontSize();
  69.       this.m_list.setFont(new Font(WebHelp.GetFontName(), 0, var2));
  70.       this.m_tfEdit.setFont(new Font(WebHelp.GetFontName(), 0, var2));
  71.       ((Container)this).add("North", this.m_tfEdit);
  72.       ((Container)this).add("Center", this.m_list);
  73.       ((Container)this).add("South", this.m_btnDisplay);
  74.       this.m_tfEdit.requestFocus();
  75.    }
  76.  
  77.    public void add(String var1, Vector var2) {
  78.       this.m_list.addItem(var1);
  79.       this.m_vSecondaryEntries.addElement(var2);
  80.    }
  81.  
  82.    public List getList() {
  83.       return this.m_list;
  84.    }
  85.  
  86.    public boolean keyUp(Event var1, int var2) {
  87.       if (this.m_bIsNSWin16) {
  88.          var2 &= 255;
  89.       }
  90.  
  91.       if ((this.m_bIsIE4 || this.m_bIsIE3 || this.m_bIsNSWin32) && var1.key == 10) {
  92.          this.action(var1, var1.target);
  93.          return true;
  94.       } else {
  95.          boolean var3 = super.keyUp(var1, var2);
  96.          if (var2 >= 32 && var2 <= 126) {
  97.             try {
  98.                this.textChanged();
  99.                if (var1.target == this.m_tfEdit) {
  100.                   this.m_tfEdit.requestFocus();
  101.                }
  102.             } finally {
  103.                ;
  104.             }
  105.          }
  106.  
  107.          return var3;
  108.       }
  109.    }
  110.  
  111.    protected void gotoSelectedIndex() {
  112.       int var1 = this.m_list.getSelectedIndex();
  113.       if (var1 != -1) {
  114.          if (((Vector)this.m_vSecondaryEntries.elementAt(var1)).size() != 1) {
  115.             if (this.m_dlgSecondary == null) {
  116.                this.m_dlgSecondary = new IndexSecondaryDialog(this.m_applet, (Vector)this.m_vSecondaryEntries.elementAt(var1), this);
  117.                this.m_dlgSecondary.show();
  118.                this.m_dlgSecondary.requestFocus();
  119.             }
  120.  
  121.          } else {
  122.             IndexSecondaryEntry var2 = (IndexSecondaryEntry)((Vector)this.m_vSecondaryEntries.elementAt(var1)).elementAt(0);
  123.             if (var2.see_also != null) {
  124.                for(int var3 = 0; var3 < this.m_vSecondaryEntries.size(); ++var3) {
  125.                   if (((Vector)this.m_vSecondaryEntries.elementAt(var3)).size() == 1) {
  126.                      IndexSecondaryEntry var4 = (IndexSecondaryEntry)((Vector)this.m_vSecondaryEntries.elementAt(var3)).elementAt(0);
  127.                      if (var4.name.equals(var2.see_also)) {
  128.                         this.m_list.select(var3);
  129.                         if (this.m_list.getVisibleIndex() != var3) {
  130.                            this.m_list.makeVisible(var3);
  131.                         }
  132.  
  133.                         this.gotoSelectedIndex();
  134.                         return;
  135.                      }
  136.                   }
  137.                }
  138.             } else {
  139.                try {
  140.                   if (var2.frame != null) {
  141.                      this.m_applet.getAppletContext().showDocument(URLFileHandler.makeURL(this.m_applet.getDocumentBase(), var2.local, var2.url), var2.frame);
  142.                   } else {
  143.                      this.m_applet.getAppletContext().showDocument(URLFileHandler.makeURL(this.m_applet.getDocumentBase(), var2.local, var2.url), "_self");
  144.                   }
  145.                } catch (MalformedURLException var5) {
  146.                }
  147.             }
  148.  
  149.             this.m_tfEdit.requestFocus();
  150.          }
  151.       }
  152.    }
  153.  
  154.    protected void finalize() throws Throwable {
  155.       this.m_list.clear();
  156.       super.finalize();
  157.    }
  158.  
  159.    public boolean action(Event var1, Object var2) {
  160.       this.gotoSelectedIndex();
  161.       return true;
  162.    }
  163.  
  164.    public boolean handleEvent(Event var1) {
  165.       if (this.m_bIsIE4 && var1.id == 1001 && var1.target == this.m_tfEdit) {
  166.          return true;
  167.       } else {
  168.          if (var1.target == this.m_list && var1.id == 701 && this.m_list.getSelectedIndex() != this.m_nSelectedIndex) {
  169.             String var2 = this.m_list.getSelectedItem();
  170.             this.m_nSelectedIndex = this.m_list.getSelectedIndex();
  171.             if (var2 != null) {
  172.                this.m_tfEdit.setText(var2);
  173.                this.m_applet.showStatus(var2);
  174.                this.m_list.requestFocus();
  175.             }
  176.          }
  177.  
  178.          return super.handleEvent(var1);
  179.       }
  180.    }
  181.  
  182.    public void textChanged() {
  183.       String var1 = this.m_tfEdit.getText().toUpperCase();
  184.       int var2 = var1.length();
  185.       if (var2 != 0) {
  186.          for(int var3 = 0; var3 < this.m_list.countItems(); ++var3) {
  187.             String var4 = this.m_list.getItem(var3).toUpperCase();
  188.             if (var4.startsWith(var1)) {
  189.                try {
  190.                   this.m_list.deselect(this.m_list.getSelectedIndex());
  191.                } catch (ArrayIndexOutOfBoundsException var6) {
  192.                }
  193.  
  194.                this.m_list.select(var3);
  195.                this.m_nSelectedIndex = var3;
  196.                this.m_applet.showStatus(this.m_list.getSelectedItem());
  197.                int var5 = this.m_list.getVisibleIndex();
  198.                if (var5 > var3 || var5 < var3 + 10) {
  199.                   this.m_list.makeVisible(var3);
  200.                }
  201.  
  202.                return;
  203.             }
  204.          }
  205.  
  206.       }
  207.    }
  208. }
  209.