home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-02-11 | 3.4 KB | 137 lines |
- /* ****************************************************************
- ** @(#)namePop.java 1.3 97/05/23
- **
- ** Copyright 1997 Sun Microsystems, Inc. All Rights Reserved
- **
- ** ****************************************************************
- */
-
- import java.awt.*;
-
- public class namePop extends Frame {
-
- public List nameList;
- public Button viewBtn;
- public Button exitBtn;
- private namedb parent;
-
- public void init() {
- setTitle("Names");
-
- GridBagLayout grid = new GridBagLayout();
- int rowHeights[] = {30,30,30,30,30,30,30};
- int columnWidths[] = {30,30,30,30,30,30};
- double rowWeights[] = {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};
- grid.rowHeights = rowHeights;
- grid.columnWidths = columnWidths;
- grid.rowWeights = rowWeights;
- grid.columnWeights = columnWeights;
-
- this.setName("namePop");
-
- nameList = new List(5);
- nameList.setName("name_list");
- this.add(nameList);
-
- viewBtn = new Button();
- viewBtn.setLabel("View");
- viewBtn.setName("nameview_button");
- this.add(viewBtn);
-
- exitBtn = new Button();
- exitBtn.setLabel("Close");
- exitBtn.setName("nameclose_button");
- this.add(exitBtn);
-
- // Geometry management
- GridBagConstraints con = new GridBagConstraints();
- reset(con);
- con.gridx = 1;
- con.gridy = 1;
- con.gridwidth = 4;
- con.gridheight = 3;
- con.anchor = GridBagConstraints.WEST;
- con.fill = GridBagConstraints.NONE;
- grid.setConstraints(nameList, con);
-
- reset(con);
- con.gridx = 2;
- con.gridy = 5;
- con.anchor = GridBagConstraints.CENTER;
- con.fill = GridBagConstraints.HORIZONTAL;
- grid.setConstraints(exitBtn, con);
-
- reset(con);
- con.gridx = 1;
- con.gridy = 5;
- con.anchor = GridBagConstraints.CENTER;
- con.fill = GridBagConstraints.HORIZONTAL;
- grid.setConstraints(viewBtn, con);
-
- setLayout(grid);
-
- }
-
- public boolean handleEvent(Event event) {
- if (event.target == exitBtn && event.id == event.ACTION_EVENT) {
- popCancel();
- } else
- if (event.target == viewBtn && event.id == event.ACTION_EVENT) {
- popOk();
- } else
- if (event.id==event.KEY_ACTION && event.key==event.F4 && event.modifiers==event.ALT_MASK) { // Alt-F4 always exits
- System.exit(3);
- } 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 setParent(namedb caller) {
- parent = caller;
- }
-
- public void updateData() {
- int i=0;
- String listItems[]=parent.getRoloApi().getAllKeys();
- nameList.clear();
- for (i=0;i<listItems.length;i++) {
- nameList.addItem(listItems[i]);
- }
- }
- public void showIt() {
- updateData();
- pack();
- show();
- }
-
- public void popCancel() {
- dispose();
- }
-
- public void popOk() {
- if (nameList.getSelectedIndex() == -1) {
- return;
- }
- parent.getRoloApi().showEntry(nameList.getSelectedIndex());
- parent.updateScreen();
- }
- }
-
-
-