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

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