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

  1. /* ****************************************************************
  2. ** @(#)namePop.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.  
  11. public class namePop extends Frame {        
  12.  
  13.   public List nameList;
  14.   public Button viewBtn;
  15.   public Button exitBtn;
  16.   private namedb parent;
  17.  
  18.   public void init() {
  19.     setTitle("Names");
  20.     
  21.     GridBagLayout grid = new GridBagLayout();
  22.     int rowHeights[] = {30,30,30,30,30,30,30};
  23.     int columnWidths[] = {30,30,30,30,30,30};
  24.     double rowWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
  25.     double columnWeights[] = {0.0,0.0,0.0,0.0,0.0,0.0};
  26.     grid.rowHeights = rowHeights;
  27.     grid.columnWidths = columnWidths;
  28.     grid.rowWeights = rowWeights;
  29.     grid.columnWeights = columnWeights;
  30.     
  31.     this.setName("namePop");
  32.  
  33.     nameList = new List(5);
  34.     nameList.setName("name_list");
  35.     this.add(nameList);
  36.     
  37.     viewBtn = new Button();
  38.     viewBtn.setLabel("View");
  39.     viewBtn.setName("nameview_button");
  40.     this.add(viewBtn);
  41.     
  42.     exitBtn = new Button();
  43.     exitBtn.setLabel("Close");
  44.     exitBtn.setName("nameclose_button");
  45.     this.add(exitBtn);
  46.     
  47.     // Geometry management
  48.     GridBagConstraints con = new GridBagConstraints();
  49.     reset(con);
  50.     con.gridx = 1;
  51.     con.gridy = 1;
  52.     con.gridwidth = 4;
  53.     con.gridheight = 3;
  54.     con.anchor = GridBagConstraints.WEST;
  55.     con.fill = GridBagConstraints.NONE;
  56.     grid.setConstraints(nameList, con);
  57.     
  58.     reset(con);
  59.     con.gridx = 2;
  60.     con.gridy = 5;
  61.     con.anchor = GridBagConstraints.CENTER;
  62.     con.fill = GridBagConstraints.HORIZONTAL;
  63.     grid.setConstraints(exitBtn, con);
  64.     
  65.     reset(con);
  66.     con.gridx = 1;
  67.     con.gridy = 5;
  68.     con.anchor = GridBagConstraints.CENTER;
  69.     con.fill = GridBagConstraints.HORIZONTAL;
  70.     grid.setConstraints(viewBtn, con);
  71.     
  72.     setLayout(grid);
  73.     
  74.   }
  75.  
  76.   public boolean handleEvent(Event event) {
  77.     if (event.target == exitBtn && event.id == event.ACTION_EVENT) {
  78.       popCancel();
  79.     } else
  80.       if (event.target == viewBtn && event.id == event.ACTION_EVENT) {
  81.     popOk();
  82.       } else
  83.     if (event.id==event.KEY_ACTION && event.key==event.F4 && event.modifiers==event.ALT_MASK) {  // Alt-F4 always exits
  84.       System.exit(3);
  85.     } else
  86.       return super.handleEvent(event);
  87.     return true;
  88.   }
  89.   
  90.   private void reset(GridBagConstraints con) {
  91.     con.gridx = GridBagConstraints.RELATIVE;
  92.     con.gridy = GridBagConstraints.RELATIVE;
  93.     con.gridwidth = 1;
  94.     con.gridheight = 1;
  95.  
  96.     con.weightx = 0;
  97.     con.weighty = 0;
  98.     con.anchor = GridBagConstraints.CENTER;
  99.     con.fill = GridBagConstraints.NONE;
  100.     
  101.     con.insets = new Insets(0, 0, 0, 0);
  102.     con.ipadx = 0;
  103.     con.ipady = 0;
  104.   }
  105.   public void setParent(namedb caller) {
  106.     parent = caller;
  107.   }
  108.   
  109.   public void updateData() {
  110.     int i=0;
  111.     String listItems[]=parent.getRoloApi().getAllKeys();
  112.     nameList.clear();
  113.     for (i=0;i<listItems.length;i++) {
  114.       nameList.addItem(listItems[i]);
  115.     }
  116.   }
  117.   public void showIt() {
  118.     updateData();
  119.     pack();
  120.     show();
  121.   }
  122.   
  123.   public void popCancel() {
  124.     dispose();
  125.   }
  126.   
  127.   public void popOk() {
  128.     if (nameList.getSelectedIndex() == -1) {
  129.       return;
  130.     }
  131.     parent.getRoloApi().showEntry(nameList.getSelectedIndex());
  132.     parent.updateScreen();
  133.   }
  134. }
  135.  
  136.  
  137.