home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-02-11 | 6.1 KB | 254 lines |
- /* ****************************************************************
- ** @(#)searchPop.java 1.3 97/05/23
- **
- ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
- **
- ** ****************************************************************
- */
-
- import java.awt.*;
- import java.util.Vector;
- import java.util.StringTokenizer;
-
- public class searchPop extends Frame {
-
- private Vector search;
- private Vector foundindex;
-
- private String labels[];
-
- private namedb parent;
-
- private searchPop gui;
-
- public Label field_label;
- public Choice field_choice;
- public Label param_label;
- public TextField param_text;
- public Label result_label;
- public List result_list;
- public Button search_button;
- public Button view_button;
- public Button exit_button;
-
- public void init() {
- gui=(searchPop)this;
- setTitle("Search");
- this.setName("searchPop");
-
- labels=new String[7];
- labels[0]="all";
- labels[1]="name";
- labels[2]="address1";
- labels[3]="address2";
- labels[4]="phone";
- labels[5]="email";
- labels[6]="other";
-
- // main panel
- GridBagLayout grid = new GridBagLayout();
- int rowHeights[] = {10,20,20,20,20,20,20,20,20,20,20};
- int columnWidths[] = {30,30,30,30,30,30,30};
- double rowWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
- double columnWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
- grid.rowHeights = rowHeights;
- grid.columnWidths = columnWidths;
- grid.rowWeights = rowWeights;
- grid.columnWeights = columnWeights;
-
- field_label=new Label("select criteria:");
- field_label.setName("field_label");
- add(field_label);
-
- field_choice=new Choice();
- field_choice.setName("field_choice");
- add(field_choice);
-
- param_label=new Label("contains strings:");
- param_label.setName("param_label");
- add(param_label);
-
- param_text=new TextField(30);
- param_text.setName("param_text");
- add(param_text);
-
- result_label=new Label("search results:");
- result_label.setName("result_label");
- add(result_label);
-
- result_list=new List(5);
- result_list.setName("result_list");
- add(result_list);
-
- search_button=new Button("Search");
- search_button.setName("dosearch_button");
- add(search_button);
-
- view_button=new Button("View Result");
- view_button.setName("searchview_button");
- add(view_button);
-
- exit_button=new Button("Close");
- exit_button.setName("searchclose_button");
- add(exit_button);
-
- GridBagConstraints con = new GridBagConstraints();
- reset(con);
- con.gridx = 1;
- con.gridy = 1;
- con.gridwidth = 1;
- con.gridheight = 1;
- con.anchor = GridBagConstraints.WEST;
- grid.setConstraints(field_label, con);
-
- con = new GridBagConstraints();
- reset(con);
- con.gridx = 2;
- con.gridy = 1;
- con.gridwidth = 1;
- con.gridheight = 1;
- con.anchor = GridBagConstraints.WEST;
- grid.setConstraints(field_choice, con);
-
- reset(con);
- con.gridx = 1;
- con.gridy = 2;
- con.gridwidth = 1;
- con.gridheight = 1;
- con.anchor = GridBagConstraints.WEST;
- grid.setConstraints(param_label, con);
-
- reset(con);
- con.gridx = 2;
- con.gridy = 2;
- con.gridwidth = 4;
- con.gridheight = 1;
- con.anchor = GridBagConstraints.WEST;
- grid.setConstraints(param_text, con);
-
- reset(con);
- con.gridx = 1;
- con.gridy = 4;
- con.gridwidth = 1;
- con.gridheight = 1;
- con.anchor = GridBagConstraints.WEST;
- grid.setConstraints(result_label, con);
-
- reset(con);
- con.gridx = 2;
- con.gridy = 4;
- con.gridwidth = 3;
- con.gridheight = 4;
- con.anchor = GridBagConstraints.WEST;
- grid.setConstraints(result_list, con);
-
- reset(con);
- con.gridx = 2;
- con.gridy = 9;
- con.gridwidth = 1;
- con.gridheight = 1;
- con.fill = GridBagConstraints.HORIZONTAL;
- con.anchor = GridBagConstraints.WEST;
- grid.setConstraints(search_button, con);
-
- reset(con);
- con.gridx = 3;
- con.gridy = 9;
- con.gridwidth = 1;
- con.gridheight = 1;
- con.anchor = GridBagConstraints.WEST;
- con.fill = GridBagConstraints.HORIZONTAL;
- grid.setConstraints(view_button, con);
-
- reset(con);
- con.gridx = 4;
- con.gridy = 9;
- con.gridwidth = 1;
- con.gridheight = 1;
- con.anchor = GridBagConstraints.WEST;
- con.fill = GridBagConstraints.HORIZONTAL;
- grid.setConstraints(exit_button, con);
-
- // Resize behavior management and parent heirarchy
- setLayout(grid);
-
- for(int i=0;i<6;i++) {
- field_choice.add(labels[i]);
- }
- field_choice.select(0);
- }
-
- public boolean handleEvent(Event event) {
-
- if (event.target == exit_button && event.id == event.ACTION_EVENT) {
- dispose();
- } else
- if (event.target == view_button && event.id == event.ACTION_EVENT) {
- viewit();
- } else
- if (event.target == search_button && event.id == event.ACTION_EVENT) {
- search();
- } else
- return super.handleEvent(event);
-
- return true;
- }
-
- private void reset(GridBagConstraints con) {
- con.gridx = GridBagConstraints.RELATIVE;
- con.gridy = GridBagConstraints.RELATIVE;
- con.gridwidth = 1;
- con.gridheight = 1;
-
- con.weightx = 0;
- con.weighty = 0;
- con.anchor = GridBagConstraints.CENTER;
- con.fill = GridBagConstraints.NONE;
-
- con.insets = new Insets(0, 0, 0, 0);
- con.ipadx = 0;
- con.ipady = 0;
-
-
- }
- public void search() {
- foundindex=parent.getRoloApi().searchIt( field_choice.getSelectedIndex(),
- param_text.getText() );
- result_list.removeAll();
- RoloEntry re;
- for (int i=0;i<foundindex.size();i++) {
- re=parent.getRoloApi().getEntry(((Integer)foundindex.elementAt(i)).intValue());
- result_list.add( re.name );
- }
- }
-
- public void clearsearch() {
- field_choice.select(0);
- param_text.setText("");
- result_list.removeAll();
- }
-
- public void viewit() {
- int item=result_list.getSelectedIndex();
- if (item== -1)
- return;
- int view=((Integer)foundindex.elementAt(item)).intValue();
- parent.getRoloApi().showEntry(view);
- parent.updateScreen();
- }
- public void showit() {
- pack();
- show();
- }
- public void setParent(namedb caller) {
- parent = caller;
- }
-
- }
-
-
-
-
-
-
-