// File: ConstEdgeDialog.java // Classes: ConstEdgeDialog // Original Author: Kedar Patankar // Date 11 Feb 1997 package uci.graphedit; import java.awt.Label; import java.awt.TextField; import java.awt.List; import java.awt.Button; import java.awt.Event; import java.awt.Frame; import java.awt.Panel; import java.awt.BorderLayout; import java.awt.Color; import gjt.DialogClient; import gjt.GJTDialog; import gjt.ButtonPanel; import gjt.RowLayout; public class ConstEdgeDialog extends GJTDialog { private TextField _vertex_name; private List _cardList; private Button _execute,_cancel; private String _name; private String _card; public ConstEdgeDialog(Frame f,DialogClient c,String t,String name,String card) { this(f,c,t); _name=name; _vertex_name.setText(name); _vertex_name.select(0,name.length()); int index=0; if ("1".equals(card)) index = 0; else if ("0..1".equals(card)) index = 1; else if ("0..*".equals(card)) index = 2; else if ("1..*".equals(card)) index = 3; _cardList.select(index); } public ConstEdgeDialog(Frame frame,DialogClient client,String title) { super(frame,title,client,true); Label actionName= new Label("Edge Name "); Label cardinality=new Label("Cardinality"); _vertex_name = new TextField(25); _cardList = new List(); _execute = new Button("OK"); _cancel = new Button("Cancel"); Panel nameP = new Panel(); nameP.setLayout(new BorderLayout()); nameP.add("North",actionName); nameP.add("Center",_vertex_name); Panel cardP = new Panel(); cardP.setLayout(new BorderLayout()); cardP.add("North",cardinality); cardP.add("Center",_cardList); Panel textP = new Panel(); textP.setLayout(new RowLayout()); textP.add(nameP); textP.add(cardP); textP.setBackground(Color.lightGray); ButtonPanel buttonPanel = new ButtonPanel(); buttonPanel.add(_execute); buttonPanel.add(_cancel); buttonPanel.setBackground(Color.lightGray); setLayout(new BorderLayout()); add("Center",textP); add("South",buttonPanel); _cardList.addItem("1"); _cardList.addItem("0..1"); _cardList.addItem("0..*"); _cardList.addItem("1..*"); _cardList.select(0); pack(); } public void show() { _vertex_name.requestFocus(); super.show(); } public boolean handleEvent(Event e) { switch(e.id) { case Event.WINDOW_DESTROY: close(); return true; case Event.LIST_SELECT: return true; } return super.handleEvent(e); } public boolean action(Event e, Object what) { if (e.target == _cancel) { close(); return true; } else if ((e.target == _execute)||(e.target==_vertex_name)) { if (_vertex_name.getText().length() != 0) { hide(); executeCommand(e); dispose(); return true; } } return false; } public void close() { hide(); dispose(); } private void executeCommand(Event e) { _name=_vertex_name.getText(); _card=_cardList.getSelectedItem(); client.dialogDismissed(this); } public String get_edge_name() {return _name;} public String get_cardinality() {return _card;} } /* end class ConstEdgeDialog */