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

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