home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 25 / IOPROG_25.ISO / SOFT / JavaS / javastar-eval.exe / data1.cab / Program_Files / examples / namedb / searchPop.java < prev    next >
Encoding:
Java Source  |  1999-02-11  |  6.3 KB  |  210 lines

  1. /* ****************************************************************
  2. ** @(#)searchPop.java    1.2 0
  3. **
  4. ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
  5. **
  6. ** ****************************************************************
  7. */
  8.  
  9. import java.awt.*;
  10. import java.awt.event.*;
  11. import java.util.Vector;
  12. import java.util.StringTokenizer;
  13. import gjt.*;
  14.  
  15. public class searchPop extends Frame implements ActionListener {
  16.   private Vector search;
  17.   private Vector foundindex;
  18.  
  19.   private String labels[];
  20.  
  21.   private namedb parent;
  22.  
  23.   public Label field_label;
  24.   public Choice field_choice;
  25.   public Label param_label;
  26.   public TextField param_text;
  27.   public Label result_label;
  28.   public List result_list;
  29.   public OpenlookButton search_button;
  30.   public OpenlookButton view_button;
  31.   public OpenlookButton exit_button;
  32.   public Panel bpanel,mpanel,spanel;
  33.  
  34. public void init() {
  35.  
  36.   setTitle(parent.strings.searchPop());
  37.   setBackground(Color.lightGray);
  38.   if (parent.UseSetName)
  39.     this.setName("searchPop");
  40.  
  41.   labels=new String[7];
  42.   labels[0]="all";
  43.   labels[1]="name";
  44.   labels[2]="address1";
  45.   labels[3]="address2";
  46.   labels[4]="phone";
  47.   labels[5]="title";
  48.   labels[6]="salary";
  49.  
  50.   mpanel=new Panel();
  51.   add(mpanel);
  52.  
  53.   bpanel=new Panel();
  54.   bpanel.setLayout(new GridLayout(1,3));
  55.   Box box1=new Box(bpanel,"");
  56.   mpanel.add(box1);
  57.  
  58.   // main panel
  59.   GridBagLayout grid = new GridBagLayout();
  60.   GridBagLayout bgrid = new GridBagLayout();
  61.  
  62.   field_label=new Label(parent.strings.fieldl());
  63.   if (parent.UseSetName)
  64.     field_label.setName("field_label");
  65.   field_label.setFont(new Font("Serif",Font.ITALIC,16));
  66.   mpanel.add(field_label);
  67.  
  68.   field_choice=new Choice();
  69.   if (parent.UseSetName)
  70.     field_choice.setName("field_choice");
  71.   field_choice.setBackground(Color.lightGray);
  72.   field_choice.setFont(new Font("Serif",Font.ITALIC,16));
  73.   mpanel.add(field_choice);
  74.   
  75.   param_label=new Label(parent.strings.paraml());
  76.   if (parent.UseSetName)
  77.     param_label.setName("param_label");
  78.   param_label.setFont(new Font("Serif",Font.ITALIC,16));
  79.   mpanel.add(param_label);
  80.  
  81.   param_text=new TextField(30);
  82.   if (parent.UseSetName)
  83.     param_text.setName("param_text");
  84.   param_text.setBackground(Color.lightGray);
  85.   param_text.setFont(new Font("Serif",Font.ITALIC,16));
  86.   mpanel.add(param_text);
  87.   
  88.   result_label=new Label(parent.strings.fieldl());
  89.   if (parent.UseSetName)
  90.     result_label.setName("result_label");
  91.   result_label.setFont(new Font("Serif",Font.ITALIC,16));
  92.   mpanel.add(result_label);
  93.   
  94.   result_list=new List(5);
  95.   if (parent.UseSetName)
  96.     result_list.setName("result_list");
  97.   result_list.setBackground(Color.lightGray);
  98.   result_list.setFont(new Font("Serif",Font.ITALIC,16));
  99.   mpanel.add(result_list);
  100.   
  101.   search_button=new OpenlookButton(parent.strings.dosearchb());
  102.   if (parent.UseSetName)
  103.     search_button.setName("dosearch_button");
  104.   search_button.setFont(new Font("Serif",Font.ITALIC,16));
  105.   search_button.addActionListener(this);
  106.   bpanel.add(search_button,new Point(0,1));
  107.  
  108.   view_button=new OpenlookButton(parent.strings.searchviewb());
  109.   if (parent.UseSetName)
  110.     view_button.setName("searchview_button");
  111.   view_button.setFont(new Font("Serif",Font.ITALIC,16));
  112.   view_button.addActionListener(this);
  113.   bpanel.add(view_button,new Point(0,2));
  114.  
  115.   exit_button=new OpenlookButton(parent.strings.searchcloseb());
  116.   if (parent.UseSetName)
  117.     exit_button.setName("searchclose_button");
  118.   exit_button.setFont(new Font("Serif",Font.ITALIC,16));
  119.   exit_button.addActionListener(this);
  120.   bpanel.add(exit_button,new Point(0,3));
  121.   
  122.   constrain(grid,field_label,0,0,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,0,0,0,0,0,0,0,0);
  123.   constrain(grid,field_choice,1,0,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,0,0,0,0,0,0,0,0);
  124.   constrain(grid,param_label,0,1,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,0,0,0,0,0,0,0,0);
  125.   constrain(grid,param_text,1,1,2,1,GridBagConstraints.WEST,GridBagConstraints.NONE,0,0,0,0,0,0,0,0);
  126.   constrain(grid,result_label,0,2,1,1,GridBagConstraints.WEST,GridBagConstraints.NONE,0,0,0,0,0,0,0,0);
  127.   constrain(grid,result_list,1,2,1,4,GridBagConstraints.WEST,GridBagConstraints.NONE,0,0,0,0,0,0,0,0);
  128.   constrain(grid,box1,0,6,3,1,GridBagConstraints.CENTER,GridBagConstraints.NONE,0,0,0,0,0,0,0,0);
  129.  
  130.   mpanel.setLayout(grid);
  131.  
  132.   GridBagLayout mgrid=new GridBagLayout();
  133.   constrain(mgrid,mpanel,0,0,1,1,GridBagConstraints.CENTER,GridBagConstraints.NONE,0,0,10,30,10,30,0,0);
  134.   setLayout(mgrid);
  135.  
  136.   for(int i=0;i<labels.length;i++) {
  137.     field_choice.add(labels[i]);
  138.   }
  139.   field_choice.select(0);
  140. }
  141.  
  142. public void actionPerformed(ActionEvent event) {
  143.   Component comp=(Component)event.getSource();
  144.   if (comp == exit_button) {
  145.     hide();
  146.   }
  147.   if (comp == view_button) {
  148.     viewit();
  149.   }
  150.   if (comp == search_button) {
  151.     search();
  152.   }
  153. }
  154.  
  155.   public void search() {
  156.     foundindex=parent.getApi().searchIt( field_choice.getSelectedIndex(), 
  157.                      param_text.getText() );
  158.     result_list.removeAll();
  159.     RoloEntry re;
  160.     for (int i=0;i<foundindex.size();i++) {
  161.       re=parent.getApi().getEntry(((Integer)foundindex.elementAt(i)).intValue());
  162.       result_list.add( re.name );
  163.     }
  164.   }
  165.  
  166.   public void clearsearch() {
  167.     field_choice.select(0);
  168.     param_text.setText("");
  169.     result_list.removeAll();
  170.   }
  171.  
  172.   public void viewit() {
  173.     int item=result_list.getSelectedIndex();
  174.     if (item== -1)
  175.       return;
  176.     int view=((Integer)foundindex.elementAt(item)).intValue();
  177.     parent.getApi().showEntry(view);
  178.     parent.updateScreen();
  179.   }
  180.   public void showit() {
  181.     pack();
  182.     show();
  183.   }
  184.   public void setParent(namedb caller) {
  185.     parent = caller;
  186.   }
  187.   
  188.   public void constrain(GridBagLayout grid,Component comp,int gridx,int gridy,int gridwidth,int gridheight,int anchor,int fill,int ipadx,int ipady,int top,int left,int bottom,int right,double weightx,double weighty) {
  189.     GridBagConstraints con=new GridBagConstraints();
  190.     con.gridx = gridx;
  191.     con.gridy = gridy;
  192.     con.gridwidth = gridwidth;
  193.     con.gridheight = gridheight;
  194.     con.anchor = anchor;
  195.     con.fill = fill;
  196.     con.ipadx = ipadx;
  197.     con.ipady = ipady;
  198.     con.weightx=weightx;
  199.     con.weighty=weighty;
  200.     con.insets = new Insets(top,left,bottom,right);
  201.     grid.setConstraints(comp,con);
  202.   }
  203. }
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.