home *** CD-ROM | disk | FTP | other *** search
/ Internet CD 2005 August / MICD_2005_08.iso / Multimedia / Twist / TwistEval.exe / Main / webhelp0.cab / hhapplet / IndexPane.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-06-19  |  9.3 KB  |  582 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.Component;
  8. import java.awt.Container;
  9. import java.awt.Event;
  10. import java.awt.Font;
  11. import java.awt.Label;
  12. import java.awt.LayoutManager;
  13. import java.awt.List;
  14. import java.awt.Panel;
  15. import java.awt.TextField;
  16. import java.net.MalformedURLException;
  17. import java.net.URL;
  18. import java.util.Vector;
  19.  
  20. public class IndexPane extends Panel implements DialogDoneTarget, Runnable {
  21.    protected Applet m_applet;
  22.    protected Vector m_vSecondaryEntries = new Vector();
  23.    protected List m_list;
  24.    protected List m_listHolder;
  25.    protected IndexTree m_forapplelistHolder;
  26.    protected IndexTree m_forapplelist;
  27.    protected TextField m_tfEdit = new TextField();
  28.    protected Button m_btnDisplay = new Button(ResourceLib.GetRes("Display"));
  29.    protected IndexSecondaryDialog m_dlgSecondary;
  30.    protected int m_nSelectedIndex = -1;
  31.    protected Panel m_pnlEditArea = new Panel();
  32.    protected Label m_lblEditArea = new Label(ResourceLib.GetRes("IndexInputPrompt"));
  33.    protected LayoutManager m_layEditArea = new BorderLayout(0, 0);
  34.    protected boolean m_bIsIE4 = false;
  35.    protected boolean m_bIsNSWin16 = false;
  36.    protected boolean m_bIsNSWin32 = false;
  37.    protected boolean m_bIsIE3 = false;
  38.    protected boolean m_bMacOS = false;
  39.    protected boolean m_bUseForAppleList = false;
  40.    int m_bResearch = 1;
  41.    private Object m_Cursor = null;
  42.    private LayoutManager m_layout;
  43.    private int[] m_charorder = null;
  44.    Thread m_textChangedThread = null;
  45.  
  46.    public boolean gotFocus(Event var1, Object var2) {
  47.       if (this.m_bUseForAppleList) {
  48.          if (var1.target != this.m_tfEdit && var1.target != this.m_forapplelist && var1.target != this.m_btnDisplay) {
  49.             this.m_tfEdit.requestFocus();
  50.          }
  51.       } else if (var1.target != this.m_tfEdit && var1.target != this.m_list && var1.target != this.m_btnDisplay) {
  52.          this.m_tfEdit.requestFocus();
  53.       }
  54.  
  55.       return true;
  56.    }
  57.  
  58.    public void HideList() {
  59.       if (this.m_bUseForAppleList) {
  60.          ((Container)this).add("Center", this.m_forapplelistHolder);
  61.          this.m_forapplelistHolder.show(true);
  62.          this.m_forapplelist.show(false);
  63.       } else {
  64.          ((Container)this).add("Center", this.m_listHolder);
  65.          this.m_listHolder.show(true);
  66.          this.m_list.show(false);
  67.       }
  68.  
  69.       ((Container)this).validate();
  70.    }
  71.  
  72.    public IndexTree getForAppleList() {
  73.       return this.m_forapplelistHolder;
  74.    }
  75.  
  76.    public void MoveSelectionDown() {
  77.    }
  78.  
  79.    public void dialogDone() {
  80.       this.m_dlgSecondary = null;
  81.    }
  82.  
  83.    public IndexPane(Applet var1) {
  84.       this.m_applet = var1;
  85.       String var2 = ResourceLib.GetRes("langorder");
  86.       if (var2 != null) {
  87.          this.m_charorder = new int[256];
  88.          int var3 = 0;
  89.          int var4 = var2.indexOf(44, var3);
  90.  
  91.          for(int var5 = 0; var4 != -1; var4 = var2.indexOf(44, var3)) {
  92.             String var6 = var2.substring(var3, var4);
  93.             if (var6 != null) {
  94.                this.m_charorder[var5] = Integer.parseInt(var6);
  95.                ++var5;
  96.             }
  97.  
  98.             var3 = var4 + 1;
  99.          }
  100.       }
  101.  
  102.       try {
  103.          if (System.getProperty("os.name").startsWith("MacOS")) {
  104.             this.m_bMacOS = true;
  105.          }
  106.  
  107.          if (System.getProperty("java.vendor").startsWith("Netscape")) {
  108.             if (System.getProperty("os.name").startsWith("16-bit Windows")) {
  109.                this.m_bIsNSWin16 = true;
  110.             } else if (System.getProperty("os.name").startsWith("Windows")) {
  111.                if (System.getProperty("java.version").equalsIgnoreCase("1.02")) {
  112.                   this.m_bUseForAppleList = true;
  113.                }
  114.  
  115.                this.m_bIsNSWin32 = true;
  116.             } else if (System.getProperty("os.name").startsWith("Mac")) {
  117.                this.m_bUseForAppleList = true;
  118.             }
  119.          } else if (System.getProperty("java.vendor").startsWith("Microsoft")) {
  120.             if (System.getProperty("java.version").startsWith("1.1")) {
  121.                this.m_bIsIE4 = true;
  122.             } else {
  123.                this.m_bIsIE3 = true;
  124.             }
  125.  
  126.             if (System.getProperty("os.name").startsWith("Mac")) {
  127.                this.m_bUseForAppleList = true;
  128.             }
  129.  
  130.             if (System.getProperty("java.version").equalsIgnoreCase("1.1")) {
  131.                this.m_bUseForAppleList = true;
  132.             } else if (System.getProperty("java.version").equalsIgnoreCase("1.0.2")) {
  133.                this.m_bUseForAppleList = true;
  134.             }
  135.          }
  136.       } finally {
  137.          ;
  138.       }
  139.  
  140.       if (this.m_bUseForAppleList) {
  141.          this.m_forapplelist = new IndexTree(this);
  142.          this.m_forapplelistHolder = new IndexTree((IndexPane)null);
  143.          this.m_forapplelistHolder.addItem(ResourceLib.GetRes("LoadingIndex"));
  144.       } else {
  145.          this.m_list = new List();
  146.          this.m_listHolder = new List();
  147.          this.m_listHolder.addItem(ResourceLib.GetRes("LoadingIndex"));
  148.          this.m_listHolder.setBackground(Color.white);
  149.       }
  150.  
  151.       this.m_pnlEditArea.setLayout(this.m_layEditArea);
  152.       this.m_pnlEditArea.add("North", this.m_lblEditArea);
  153.       this.m_pnlEditArea.add("Center", this.m_tfEdit);
  154.       this.m_layout = new BorderLayout(2, 2);
  155.       ((Container)this).setLayout(this.m_layout);
  156.       if (!this.m_bUseForAppleList) {
  157.          this.m_list.setBackground(Color.white);
  158.       }
  159.  
  160.       int var11 = BsscFontFixPatch.GetFontSize();
  161.       if (!this.m_bUseForAppleList) {
  162.          this.m_list.setFont(new Font(BsscFontFixPatch.GetFontName(), 0, var11));
  163.       }
  164.  
  165.       this.m_tfEdit.setFont(new Font(BsscFontFixPatch.GetFontName(), 0, var11));
  166.       this.m_btnDisplay.setFont(new Font(BsscFontFixPatch.GetFontName(), 0, var11));
  167.       if (this.m_bUseForAppleList) {
  168.          ((Container)this).add("Center", this.m_forapplelistHolder);
  169.       } else {
  170.          ((Container)this).add("North", this.m_pnlEditArea);
  171.          ((Container)this).add("Center", this.m_listHolder);
  172.          ((Container)this).add("South", this.m_btnDisplay);
  173.       }
  174.  
  175.       this.m_tfEdit.requestFocus();
  176.    }
  177.  
  178.    public void add(String var1, Vector var2) {
  179.       if (this.m_bUseForAppleList) {
  180.          this.m_forapplelist.addItem(var1);
  181.       } else {
  182.          this.m_list.addItem(var1);
  183.       }
  184.  
  185.       this.m_vSecondaryEntries.addElement(var2);
  186.    }
  187.  
  188.    public boolean mouseUp(Event var1, int var2, int var3) {
  189.       return super.mouseUp(var1, var2, var3);
  190.    }
  191.  
  192.    private int compareString(String var1, String var2) {
  193.       if (this.m_charorder == null) {
  194.          String var5 = var1.toLowerCase();
  195.          String var4 = var2.toLowerCase();
  196.          return var5.compareTo(var4);
  197.       } else {
  198.          for(int var3 = 0; var3 < var1.length() && var3 < var2.length(); ++var3) {
  199.             if (this.m_charorder[var1.charAt(var3)] < this.m_charorder[var2.charAt(var3)]) {
  200.                return -1;
  201.             }
  202.  
  203.             if (this.m_charorder[var1.charAt(var3)] > this.m_charorder[var2.charAt(var3)]) {
  204.                return 1;
  205.             }
  206.          }
  207.  
  208.          if (var1.length() < var2.length()) {
  209.             return -1;
  210.          } else {
  211.             return var1.length() > var2.length() ? 1 : 0;
  212.          }
  213.       }
  214.    }
  215.  
  216.    public List getList() {
  217.       return this.m_list;
  218.    }
  219.  
  220.    public void MoveSelectionPageDown() {
  221.    }
  222.  
  223.    public int FindBaseKeywordForAppleList(int var1, int var2) {
  224.       while(var1 > 0 && var2 < 0 || var1 < this.m_forapplelist.countItems() - 1 && var2 > 0) {
  225.          if (this.m_forapplelist.getItem(var1).charAt(0) != ' ') {
  226.             return var1;
  227.          }
  228.  
  229.          var1 += var2;
  230.       }
  231.  
  232.       return var1;
  233.    }
  234.  
  235.    public void ShowList() {
  236.       if (this.m_bUseForAppleList) {
  237.          ((Container)this).add("North", this.m_pnlEditArea);
  238.          ((Container)this).add("Center", this.m_forapplelist);
  239.          ((Container)this).add("South", this.m_btnDisplay);
  240.          this.m_forapplelist.show(true);
  241.          this.m_forapplelistHolder.show(false);
  242.       } else {
  243.          if (!System.getProperty("java.vendor").startsWith("Netscape")) {
  244.             ((Container)this).add("North", this.m_pnlEditArea);
  245.          }
  246.  
  247.          ((Container)this).add("Center", this.m_list);
  248.          ((Container)this).add("South", this.m_btnDisplay);
  249.          this.m_list.show(true);
  250.          this.m_listHolder.show(false);
  251.       }
  252.  
  253.       ((Container)this).validate();
  254.    }
  255.  
  256.    public TextField getEditBox() {
  257.       return this.m_tfEdit;
  258.    }
  259.  
  260.    public boolean keyUp(Event var1, int var2) {
  261.       if ((var1.target == this.m_forapplelist || var1.target == this.m_list) && System.getProperty("java.version").equals("1.1") && System.getProperty("java.vendor").startsWith("Microsoft") && var1.key == 10) {
  262.          this.action(var1, var1.target);
  263.          return true;
  264.       } else if (var1.target == this.m_tfEdit && System.getProperty("java.version").equals("1.1") && System.getProperty("java.vendor").startsWith("Microsoft") && var1.key == 10) {
  265.          this.action(var1, var1.target);
  266.          return true;
  267.       } else {
  268.          if (this.m_bIsNSWin16) {
  269.             var2 &= 255;
  270.          }
  271.  
  272.          boolean var3 = super.keyUp(var1, var2);
  273.          if ((var2 == 8 || var2 >= 32 && var2 <= 126) && var1.target == this.m_tfEdit) {
  274.             try {
  275.                this.textChanged();
  276.                if (var1.target == this.m_tfEdit) {
  277.                   this.m_tfEdit.requestFocus();
  278.                }
  279.             } finally {
  280.                ;
  281.             }
  282.          }
  283.  
  284.          return var3;
  285.       }
  286.    }
  287.  
  288.    public boolean GetUseForAppleListFlag() {
  289.       return this.m_bUseForAppleList;
  290.    }
  291.  
  292.    public void ResetCursor() {
  293.    }
  294.  
  295.    public void gotoSelectedIndex() {
  296.       int var1 = -1;
  297.       if (this.m_bUseForAppleList) {
  298.          var1 = this.m_forapplelist.getSelectedIndex();
  299.       } else {
  300.          var1 = this.m_list.getSelectedIndex();
  301.       }
  302.  
  303.       if (var1 != -1) {
  304.          if (((Vector)this.m_vSecondaryEntries.elementAt(var1)).size() == 1) {
  305.             IndexSecondaryEntry var2 = (IndexSecondaryEntry)((Vector)this.m_vSecondaryEntries.elementAt(var1)).elementAt(0);
  306.             if (var2.see_also != null) {
  307.                for(int var7 = 0; var7 < this.m_vSecondaryEntries.size(); ++var7) {
  308.                   if (((Vector)this.m_vSecondaryEntries.elementAt(var7)).size() == 1) {
  309.                      IndexSecondaryEntry var9 = (IndexSecondaryEntry)((Vector)this.m_vSecondaryEntries.elementAt(var7)).elementAt(0);
  310.                      if (var9.name.equals(var2.see_also)) {
  311.                         if (this.m_bUseForAppleList) {
  312.                            this.m_forapplelist.select(var7);
  313.                            if (var7 > 0) {
  314.                               this.m_forapplelist.setTopIndex(var7 - 1);
  315.                            } else {
  316.                               this.m_forapplelist.setTopIndex(var7);
  317.                            }
  318.  
  319.                            this.gotoSelectedIndex();
  320.                            return;
  321.                         }
  322.  
  323.                         if (this.m_list.getVisibleIndex() != var7) {
  324.                            this.m_list.makeVisible(this.m_forapplelist.countItems() - 1);
  325.                            if (var7 > 0) {
  326.                               this.m_list.makeVisible(var7 - 1);
  327.                            } else {
  328.                               this.m_list.makeVisible(var7);
  329.                            }
  330.                         }
  331.  
  332.                         this.m_list.select(var7);
  333.                         this.gotoSelectedIndex();
  334.                         return;
  335.                      }
  336.                   }
  337.                }
  338.  
  339.             } else {
  340.                try {
  341.                   URL var3 = URLFileHandler.makeURL(this.m_applet.getDocumentBase(), var2.local, var2.url);
  342.                   String var4 = var3.toString();
  343.                   if (var4.indexOf("file:/\\\\") == 0) {
  344.                      var4 = "file://" + var4.substring(8);
  345.                      var3 = new URL(var4);
  346.                   }
  347.  
  348.                   if (var2.frame != null) {
  349.                      this.m_applet.getAppletContext().showDocument(var3, var2.frame);
  350.                   } else {
  351.                      this.m_applet.getAppletContext().showDocument(var3, "_self");
  352.                   }
  353.                } catch (MalformedURLException var5) {
  354.                   ((Throwable)var5).printStackTrace();
  355.                }
  356.             }
  357.          } else {
  358.             if (this.m_dlgSecondary != null) {
  359.                this.m_dlgSecondary.closeDialog();
  360.                this.m_dlgSecondary = null;
  361.             }
  362.  
  363.             this.m_dlgSecondary = new IndexSecondaryDialog(this.m_applet, (Vector)this.m_vSecondaryEntries.elementAt(var1), this);
  364.             this.m_dlgSecondary.showTopic();
  365.             this.m_dlgSecondary.getList().requestFocus();
  366.          }
  367.       }
  368.    }
  369.  
  370.    public void SetWaitCursor() {
  371.    }
  372.  
  373.    public int FindBaseKeyword(int var1, int var2) {
  374.       while(var1 > 0 && var2 < 0 || var1 < this.m_list.countItems() - 1 && var2 > 0) {
  375.          if (this.m_list.getItem(var1).charAt(0) != ' ') {
  376.             return var1;
  377.          }
  378.  
  379.          var1 += var2;
  380.       }
  381.  
  382.       return var1;
  383.    }
  384.  
  385.    protected void finalize() throws Throwable {
  386.       if (this.m_bUseForAppleList) {
  387.          this.m_forapplelist.clear();
  388.          this.m_forapplelist = null;
  389.       } else {
  390.          this.m_list.clear();
  391.          this.m_list = null;
  392.       }
  393.  
  394.       super.finalize();
  395.    }
  396.  
  397.    public boolean action(Event var1, Object var2) {
  398.       this.gotoSelectedIndex();
  399.       return true;
  400.    }
  401.  
  402.    public void run() {
  403.       try {
  404.          while(true) {
  405.             if (this.m_bResearch <= 0) {
  406.                try {
  407.                   Thread.sleep(100L);
  408.                } catch (InterruptedException var8) {
  409.                   ((Throwable)var8).printStackTrace();
  410.                }
  411.             } else {
  412.                String var1 = this.m_tfEdit.getText().toUpperCase();
  413.                int var2 = var1.length();
  414.                if (var2 > 0) {
  415.                   if (this.m_bUseForAppleList) {
  416.                      int var3 = 0;
  417.                      int var4 = this.FindBaseKeywordForAppleList(this.m_forapplelist.countItems() - 1, -1);
  418.  
  419.                      int var5;
  420.                      for(var5 = this.FindBaseKeywordForAppleList((this.m_forapplelist.countItems() - 1) / 2, -1); var3 < var4; var5 = this.FindBaseKeywordForAppleList((var3 + var4) / 2, -1)) {
  421.                         String var6 = this.m_forapplelist.getItem(var5).toUpperCase();
  422.                         int var7 = this.compareString(var6, var1);
  423.                         if (var7 > 0) {
  424.                            var4 = var5;
  425.                         } else if (var7 < 0) {
  426.                            var3 = this.FindBaseKeywordForAppleList(var5 + 1, 1);
  427.                         } else {
  428.                            var3 = var5;
  429.                            var4 = var5;
  430.                         }
  431.                      }
  432.  
  433.                      while(var5 > 0) {
  434.                         String var13 = this.m_forapplelist.getItem(var5 - 1);
  435.                         int var16 = this.compareString(var13, var1);
  436.                         if (var16 != 0) {
  437.                            break;
  438.                         }
  439.  
  440.                         --var5;
  441.                      }
  442.  
  443.                      this.m_forapplelist.getItem(var5).toUpperCase();
  444.                      if (var5 > this.m_forapplelist.countItems() - 1) {
  445.                         var5 = this.m_forapplelist.countItems() - 1;
  446.                      }
  447.  
  448.                      if (var5 < 0) {
  449.                         var5 = 0;
  450.                      }
  451.  
  452.                      if (var5 != this.m_nSelectedIndex) {
  453.                         this.m_forapplelist.makeVisible(this.m_forapplelist.countItems() - 1);
  454.                         if (var5 > 0) {
  455.                            this.m_forapplelist.makeVisible(var5 - 1);
  456.                         } else {
  457.                            this.m_forapplelist.makeVisible(var5);
  458.                         }
  459.  
  460.                         this.m_forapplelist.getVisibleIndex();
  461.                         this.m_forapplelist.select(var5);
  462.                         this.m_nSelectedIndex = var5;
  463.                      }
  464.  
  465.                      this.m_applet.showStatus(this.m_forapplelist.getSelectedItem());
  466.                   } else {
  467.                      int var10 = 0;
  468.                      int var11 = this.FindBaseKeyword(this.m_list.countItems() - 1, -1);
  469.  
  470.                      int var12;
  471.                      for(var12 = this.FindBaseKeyword((this.m_list.countItems() - 1) / 2, -1); var10 < var11; var12 = this.FindBaseKeyword((var10 + var11) / 2, -1)) {
  472.                         String var14 = this.m_list.getItem(var12).toUpperCase();
  473.                         int var17 = this.compareString(var14, var1);
  474.                         if (var17 > 0) {
  475.                            var11 = var12;
  476.                         } else if (var17 < 0) {
  477.                            var10 = this.FindBaseKeyword(var12 + 1, 1);
  478.                         } else {
  479.                            var10 = var12;
  480.                            var11 = var12;
  481.                         }
  482.                      }
  483.  
  484.                      while(var12 > 0) {
  485.                         String var15 = this.m_list.getItem(var12 - 1);
  486.                         int var18 = this.compareString(var15, var1);
  487.                         if (var18 != 0) {
  488.                            break;
  489.                         }
  490.  
  491.                         --var12;
  492.                      }
  493.  
  494.                      this.m_list.getItem(var12).toUpperCase();
  495.                      if (var12 > this.m_list.countItems() - 1) {
  496.                         var12 = this.m_list.countItems() - 1;
  497.                      }
  498.  
  499.                      if (var12 < 0) {
  500.                         var12 = 0;
  501.                      }
  502.  
  503.                      if (var12 != this.m_nSelectedIndex) {
  504.                         this.m_list.makeVisible(this.m_list.countItems() - 1);
  505.                         if (var12 > 0) {
  506.                            this.m_list.makeVisible(var12 - 1);
  507.                         } else {
  508.                            this.m_list.makeVisible(var12);
  509.                         }
  510.  
  511.                         this.m_list.getVisibleIndex();
  512.                         this.m_list.select(var12);
  513.                         this.m_nSelectedIndex = var12;
  514.                      }
  515.  
  516.                      this.m_applet.showStatus(this.m_list.getSelectedItem());
  517.                   }
  518.                }
  519.  
  520.                this.m_bResearch += -1;
  521.             }
  522.          }
  523.       } catch (Exception var9) {
  524.          ((Throwable)var9).printStackTrace();
  525.       }
  526.    }
  527.  
  528.    public boolean handleEvent(Event var1) {
  529.       if (var1.id == 401 && var1.key == 9 && System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("java.version").startsWith("1.1.2")) {
  530.          ((Component)this).nextFocus();
  531.          return true;
  532.       } else if (System.getProperty("java.version").startsWith("1.1.5") && this.m_bIsNSWin32 && var1.id == 401 && var1.key == 10 && var1.target == this.m_btnDisplay) {
  533.          this.action(var1, var1.target);
  534.          return true;
  535.       } else if (this.m_bIsIE4 && var1.id == 1001 && var1.target == this.m_tfEdit) {
  536.          return true;
  537.       } else {
  538.          if (var1.target == this.m_list) {
  539.             if (var1.id == 701 && this.m_list.getSelectedIndex() != this.m_nSelectedIndex) {
  540.                this.m_nSelectedIndex = this.m_list.getSelectedIndex();
  541.                String var2 = this.m_list.getItem(this.m_nSelectedIndex);
  542.                if (var2 != null) {
  543.                   var2 = var2.trim();
  544.                   this.m_tfEdit.setText(var2);
  545.                   this.m_applet.showStatus(var2);
  546.                }
  547.             }
  548.          } else if (var1.target == this.m_tfEdit && var1.id == 401 && var1.key == 10 && (!System.getProperty("java.version").equals("1.1") || !System.getProperty("java.vendor").startsWith("Microsoft")) && !System.getProperty("java.vendor").startsWith("Netscape")) {
  549.             this.action(var1, var1.target);
  550.             return true;
  551.          }
  552.  
  553.          return super.handleEvent(var1);
  554.       }
  555.    }
  556.  
  557.    public void textChanged() {
  558.       if (this.m_textChangedThread == null) {
  559.          this.m_textChangedThread = new Thread(this);
  560.          this.m_textChangedThread.setPriority(4);
  561.          this.m_textChangedThread.start();
  562.       } else {
  563.          ++this.m_bResearch;
  564.       }
  565.    }
  566.  
  567.    public void MoveSelectionUp() {
  568.    }
  569.  
  570.    public void MoveSelectionPageUp() {
  571.    }
  572.  
  573.    public boolean keyDown(Event var1, int var2) {
  574.       if ((var1.target == this.m_forapplelist || var1.target == this.m_list) && (!System.getProperty("java.version").equals("1.1") || !System.getProperty("java.vendor").startsWith("Microsoft")) && var1.key == 10) {
  575.          this.action(var1, var1.target);
  576.          return true;
  577.       } else {
  578.          return super.keyDown(var1, var2);
  579.       }
  580.    }
  581. }
  582.