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

  1. /* ****************************************************************
  2. ** @(#)searchPop.java    1.4 97/05/23
  3. **
  4. ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
  5. **
  6. ** ****************************************************************
  7. */
  8.  
  9. import java.awt.*;
  10. import java.util.Vector;
  11. import java.util.StringTokenizer;
  12.  
  13. public class searchPop extends Frame {        
  14.  
  15.   private Vector search;
  16.   private Vector foundindex;
  17.  
  18.   private String labels[];
  19.  
  20.   private namedb parent;
  21.  
  22.   private searchPop gui;
  23.  
  24.   public Label field_label;
  25.   public Choice field_choice;
  26.   public Label param_label;
  27.   public TextField param_text;
  28.   public Label result_label;
  29.   public List result_list;
  30.   public Button search_button;
  31.   public Button view_button;
  32.   public Button exit_button;
  33.  
  34. public void init() {
  35.   gui=(searchPop)this;
  36.   setTitle("Search");
  37.  
  38.   labels=new String[7];
  39.   labels[0]="all";
  40.   labels[1]="name";
  41.   labels[2]="address1";
  42.   labels[3]="address2";
  43.   labels[4]="phone";
  44.   labels[5]="email";
  45.   labels[6]="other";
  46.  
  47.   // main panel
  48.   GridBagLayout grid = new GridBagLayout();
  49.   int rowHeights[] = {10,20,20,20,20,20,20,20,20,20,20};
  50.   int columnWidths[] = {30,30,30,30,30,30,30};
  51.   double rowWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
  52.   double columnWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
  53.   grid.rowHeights = rowHeights;
  54.   grid.columnWidths = columnWidths;
  55.   grid.rowWeights = rowWeights;
  56.   grid.columnWeights = columnWeights;
  57.   
  58.   field_label=new Label("select criteria:");
  59.   add(field_label);
  60.  
  61.   field_choice=new Choice();
  62.   add(field_choice);
  63.   
  64.   param_label=new Label("contains strings:");
  65.   add(param_label);
  66.  
  67.   param_text=new TextField(30);
  68.   add(param_text);
  69.   
  70.   result_label=new Label("search results:");
  71.   add(result_label);
  72.   
  73.   result_list=new List(5);
  74.   add(result_list);
  75.   
  76.   search_button=new Button("Search");
  77.   add(search_button);
  78.  
  79.   view_button=new Button("View Result");
  80.   add(view_button);
  81.  
  82.   exit_button=new Button("Close");
  83.   add(exit_button);
  84.   
  85.   GridBagConstraints con = new GridBagConstraints();
  86.   reset(con);
  87.   con.gridx = 1;
  88.   con.gridy = 1;
  89.   con.gridwidth = 1;
  90.   con.gridheight = 1;
  91.   con.anchor = GridBagConstraints.WEST;
  92.   grid.setConstraints(field_label, con);
  93.   
  94.   con = new GridBagConstraints();
  95.   reset(con);
  96.   con.gridx = 2;
  97.   con.gridy = 1;
  98.   con.gridwidth = 1;
  99.   con.gridheight = 1;
  100.   con.anchor = GridBagConstraints.WEST;
  101.   grid.setConstraints(field_choice, con);
  102.   
  103.   reset(con);
  104.   con.gridx = 1;
  105.   con.gridy = 2;
  106.   con.gridwidth = 1;
  107.   con.gridheight = 1;
  108.   con.anchor = GridBagConstraints.WEST;
  109.   grid.setConstraints(param_label, con);
  110.  
  111.   reset(con);
  112.   con.gridx = 2;
  113.   con.gridy = 2;
  114.   con.gridwidth = 4;
  115.   con.gridheight = 1;
  116.   con.anchor = GridBagConstraints.WEST;
  117.   grid.setConstraints(param_text, con);
  118.   
  119.   reset(con);
  120.   con.gridx = 1;
  121.   con.gridy = 4;
  122.   con.gridwidth = 1;
  123.   con.gridheight = 1;
  124.   con.anchor = GridBagConstraints.WEST;
  125.   grid.setConstraints(result_label, con);
  126.   
  127.   reset(con);
  128.   con.gridx = 2;
  129.   con.gridy = 4;
  130.   con.gridwidth = 3;
  131.   con.gridheight = 4;
  132.   con.anchor = GridBagConstraints.WEST;
  133.   grid.setConstraints(result_list, con);
  134.   
  135.   reset(con);
  136.   con.gridx = 2;
  137.   con.gridy = 9;
  138.   con.gridwidth = 1;
  139.   con.gridheight = 1;
  140.   con.fill = GridBagConstraints.HORIZONTAL;
  141.   con.anchor = GridBagConstraints.WEST;
  142.   grid.setConstraints(search_button, con);
  143.   
  144.   reset(con);
  145.   con.gridx = 3;
  146.   con.gridy = 9;
  147.   con.gridwidth = 1;
  148.   con.gridheight = 1;
  149.   con.anchor = GridBagConstraints.WEST;
  150.   con.fill = GridBagConstraints.HORIZONTAL;
  151.   grid.setConstraints(view_button, con);
  152.   
  153.   reset(con);
  154.   con.gridx = 4;
  155.   con.gridy = 9;
  156.   con.gridwidth = 1;
  157.   con.gridheight = 1;
  158.   con.anchor = GridBagConstraints.WEST;
  159.   con.fill = GridBagConstraints.HORIZONTAL;
  160.   grid.setConstraints(exit_button, con);
  161.  
  162.   // Resize behavior management and parent heirarchy
  163.   setLayout(grid);
  164.  
  165.   for(int i=0;i<6;i++) {
  166.     field_choice.add(labels[i]);
  167.   }
  168.   field_choice.select(0);
  169. }
  170.  
  171. public boolean handleEvent(Event event) {
  172.   
  173.   if (event.target == exit_button && event.id == event.ACTION_EVENT) {
  174.     dispose();
  175.   } else
  176.   if (event.target == view_button && event.id == event.ACTION_EVENT) {
  177.     viewit();
  178.   } else
  179.   if (event.target == search_button && event.id == event.ACTION_EVENT) {
  180.     search();
  181.   } else
  182.     return super.handleEvent(event);
  183.  
  184.   return true;
  185. }
  186.  
  187.   private void reset(GridBagConstraints con) {
  188.     con.gridx = GridBagConstraints.RELATIVE;
  189.     con.gridy = GridBagConstraints.RELATIVE;
  190.     con.gridwidth = 1;
  191.     con.gridheight = 1;
  192.  
  193.     con.weightx = 0;
  194.     con.weighty = 0;
  195.     con.anchor = GridBagConstraints.CENTER;
  196.     con.fill = GridBagConstraints.NONE;
  197.  
  198.     con.insets = new Insets(0, 0, 0, 0);
  199.     con.ipadx = 0;
  200.     con.ipady = 0;
  201.  
  202.     
  203. }
  204.   public void search() {
  205.     foundindex=parent.getRoloApi().searchIt( field_choice.getSelectedIndex(), 
  206.                      param_text.getText() );
  207.     result_list.removeAll();
  208.     RoloEntry re;
  209.     for (int i=0;i<foundindex.size();i++) {
  210.       re=parent.getRoloApi().getEntry(((Integer)foundindex.elementAt(i)).intValue());
  211.       result_list.add( re.name );
  212.     }
  213.   }
  214.  
  215.   public void clearsearch() {
  216.     field_choice.select(0);
  217.     param_text.setText("");
  218.     result_list.removeAll();
  219.   }
  220.  
  221.   public void viewit() {
  222.     int item=result_list.getSelectedIndex();
  223.     if (item== -1)
  224.       return;
  225.     int view=((Integer)foundindex.elementAt(item)).intValue();
  226.     parent.getRoloApi().showEntry(view);
  227.     parent.updateScreen();
  228.   }
  229.   public void showit() {
  230.     pack();
  231.     show();
  232.   }
  233.   public void setParent(namedb caller) {
  234.     parent = caller;
  235.   }
  236.   
  237. }
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.