home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2003 July / PCpro_2003_07.ISO / vollvers / edhtml / EdHTMLv5.0.exe / Main / IndexPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2003-05-14  |  5.2 KB  |  231 lines

  1. import java.awt.BorderLayout;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Dimension;
  7. import java.awt.Event;
  8. import java.awt.Font;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.List;
  12. import java.awt.Panel;
  13. import java.awt.TextField;
  14. import java.net.URL;
  15. import java.util.Vector;
  16.  
  17. class IndexPanel extends Panel {
  18.    private HHCtrl m_applet;
  19.    private DialogLayout m_Layout;
  20.    private boolean m_fInitialized;
  21.    private Dimension m_Size;
  22.    private ElementList m_list;
  23.    private Color m_backColor;
  24.    private Image m_bgImage;
  25.    private Font m_font;
  26.    private Color m_foreColor;
  27.    TextField txtUser;
  28.    List lstIndex;
  29.    Button btnDisplay;
  30.    String m_targetFrame;
  31.    private boolean m_isMatched;
  32.    private int m_numMatched;
  33.    private int m_lastLength;
  34.  
  35.    private void matchSeeAlso(String var1) {
  36.       for(int var2 = 0; var2 < this.lstIndex.countItems(); ++var2) {
  37.          if (var1.equalsIgnoreCase(((Element)this.m_list.elementAt(var2)).m_text)) {
  38.             this.lstIndex.select(var2);
  39.             this.lstIndex.makeVisible(var2);
  40.             this.lstIndex.requestFocus();
  41.          }
  42.       }
  43.  
  44.    }
  45.  
  46.    public void setBackgroundImage(Image var1) {
  47.       this.m_bgImage = var1;
  48.    }
  49.  
  50.    boolean isInitialized() {
  51.       return this.m_fInitialized;
  52.    }
  53.  
  54.    public boolean loadFromHHC(URL var1) {
  55.       ElementList var4 = new ElementList(this.m_applet);
  56.       Element var2 = new Element(this.m_applet.getString("idx.load.elementname"), 0, this.m_applet);
  57.       ((Vector)var4).addElement(var2);
  58.       this.setList(var4);
  59.       ElementList var3 = new ElementList(this.m_applet);
  60.       SitemapParser var5 = new SitemapParser(var1, var3, this.m_applet);
  61.       if (var5.success()) {
  62.          this.m_targetFrame = var5.getFrame();
  63.          this.setList(var3);
  64.          this.m_applet.showStatus(this.m_applet.getString("idx.load.success"));
  65.          ((Component)this).repaint();
  66.          this.txtUser.requestFocus();
  67.          return true;
  68.       } else {
  69.          return false;
  70.       }
  71.    }
  72.  
  73.    public void setBackground(Color var1) {
  74.       this.m_backColor = var1;
  75.    }
  76.  
  77.    boolean CreateControls() {
  78.       ((Container)this).setLayout(new BorderLayout(0, 6));
  79.       this.txtUser = new TextField("");
  80.       this.txtUser.setBackground(Color.white);
  81.       this.txtUser.setEditable(true);
  82.       this.txtUser.setFont(this.m_font);
  83.       this.txtUser.setForeground(this.m_foreColor);
  84.       ((Container)this).add("North", this.txtUser);
  85.       this.lstIndex = new List(1, false);
  86.       ((Container)this).add("Center", this.lstIndex);
  87.       this.lstIndex.setBackground(Color.white);
  88.       this.lstIndex.setForeground(this.m_foreColor);
  89.       this.lstIndex.setFont(this.m_font);
  90.       this.btnDisplay = new Button("  " + this.m_applet.getString("idx.display") + "  ");
  91.       ((Container)this).add("South", this.btnDisplay);
  92.       ((Container)this).validate();
  93.       this.m_fInitialized = true;
  94.       return true;
  95.    }
  96.  
  97.    public void paint(Graphics var1) {
  98.       var1.setColor(this.m_backColor);
  99.       var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  100.       if (this.m_bgImage != null) {
  101.          try {
  102.             if (this.m_bgImage.getWidth(this) != -1 && this.m_bgImage.getHeight(this) != -1) {
  103.                for(int var3 = 0; var3 < ((Component)this).size().width; var3 += this.m_bgImage.getWidth(this)) {
  104.                   var1.drawImage(this.m_bgImage, var3, 0, this.m_backColor, this);
  105.  
  106.                   for(int var2 = 0; var2 < ((Component)this).size().height; var2 += this.m_bgImage.getHeight(this)) {
  107.                      var1.drawImage(this.m_bgImage, var3, var2, this.m_backColor, this);
  108.                   }
  109.                }
  110.  
  111.                return;
  112.             }
  113.          } catch (Exception var4) {
  114.          }
  115.       }
  116.  
  117.    }
  118.  
  119.    public String getFrame() {
  120.       return this.m_targetFrame;
  121.    }
  122.  
  123.    private void setList(ElementList var1) {
  124.       int var3 = 0;
  125.       this.m_list = var1;
  126.       if (this.lstIndex.countItems() > 0) {
  127.          this.lstIndex.clear();
  128.       }
  129.  
  130.       for(var3 = 0; var3 < this.m_list.size(); ++var3) {
  131.          int var4 = 0;
  132.          String var2 = "";
  133.  
  134.          for(var2 = ""; var4 < ((Element)((Vector)var1).elementAt(var3)).m_level; ++var4) {
  135.             var2 = var2 + "      ";
  136.          }
  137.  
  138.          this.lstIndex.addItem(var2 + ((Element)((Vector)var1).elementAt(var3)).m_text);
  139.       }
  140.  
  141.       if (var3 > 0) {
  142.          this.lstIndex.select(0);
  143.       }
  144.  
  145.    }
  146.  
  147.    public void setFont(Font var1, Color var2) {
  148.       if (var1 != null && var1 instanceof Font) {
  149.          this.m_font = var1;
  150.       }
  151.  
  152.       this.m_foreColor = var2;
  153.    }
  154.  
  155.    private void activateItem() {
  156.       if (((Element)this.m_list.elementAt(this.lstIndex.getSelectedIndex())).m_url.compareTo("") == 0 && ((Element)this.m_list.elementAt(this.lstIndex.getSelectedIndex())).m_seeAlso.compareTo("") != 0) {
  157.          if (((Element)this.m_list.elementAt(this.lstIndex.getSelectedIndex())).m_seeAlso.compareTo("") != 0) {
  158.             this.matchSeeAlso(((Element)this.m_list.elementAt(this.lstIndex.getSelectedIndex())).m_seeAlso);
  159.          }
  160.  
  161.       } else {
  162.          Event var1 = new Event(this, 1001, this.m_list.elementAt(this.lstIndex.getSelectedIndex()));
  163.          ((Component)this).postEvent(var1);
  164.       }
  165.    }
  166.  
  167.    public boolean handleEvent(Event var1) {
  168.       if ((var1.target != this.btnDisplay || var1.id != 1001) && (var1.target != this.lstIndex || var1.id != 1001) && (var1.target != this.txtUser || var1.id != 1001)) {
  169.          if (var1.target == this.lstIndex && var1.id == 701) {
  170.             this.txtUser.setText(this.lstIndex.getSelectedItem().trim());
  171.             this.m_isMatched = false;
  172.             this.m_numMatched = 0;
  173.             return true;
  174.          } else {
  175.             if (var1.target == this.txtUser && var1.id == 402) {
  176.                this.matchText();
  177.             }
  178.  
  179.             if (var1.target == this.lstIndex && var1.id == 402 && var1.key == 10) {
  180.                this.activateItem();
  181.                return true;
  182.             } else {
  183.                return super.handleEvent(var1);
  184.             }
  185.          }
  186.       } else {
  187.          this.activateItem();
  188.          return true;
  189.       }
  190.    }
  191.  
  192.    IndexPanel(HHCtrl var1) {
  193.       this.m_backColor = Color.gray;
  194.       this.m_foreColor = Color.black;
  195.       this.m_applet = var1;
  196.    }
  197.  
  198.    private void matchText() {
  199.       int var1;
  200.       if (this.m_isMatched && this.txtUser.getText().length() >= this.m_numMatched) {
  201.          var1 = this.lstIndex.getSelectedIndex();
  202.       } else {
  203.          var1 = 0;
  204.          this.m_isMatched = false;
  205.          this.m_numMatched = 0;
  206.       }
  207.  
  208.       for(int var2 = this.m_numMatched; var2 < this.txtUser.getText().length(); ++var2) {
  209.          int var3;
  210.          for(var3 = var1; var3 < this.lstIndex.countItems(); ++var3) {
  211.             String var4 = ((Element)this.m_list.elementAt(var3)).m_text.toUpperCase();
  212.             String var5 = this.txtUser.getText().substring(0, var2 + 1).toUpperCase();
  213.             if (var4.startsWith(var5) && ((Element)this.m_list.elementAt(var3)).m_level == 0) {
  214.                var1 = var3;
  215.                this.m_numMatched = var2 + 1;
  216.                this.lstIndex.select(var3);
  217.                this.lstIndex.makeVisible(var3);
  218.                this.txtUser.requestFocus();
  219.                this.m_isMatched = true;
  220.                break;
  221.             }
  222.          }
  223.  
  224.          if (var3 == this.lstIndex.countItems()) {
  225.             break;
  226.          }
  227.       }
  228.  
  229.    }
  230. }
  231.