home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
InfoDlg.java
< prev
next >
Wrap
Text File
|
1997-07-03
|
11KB
|
299 lines
package borland.samples.apps.chess.client ;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
/**Displays a Dialog where the user can supply personal information as desired
*/
public class InfoDlg extends Dialog implements OkCancelDialog ,PlayerListListener
{
Panel dlgPanel = new Panel();
Button cancelButton = new Button();
Button okButton = new Button();
String[] data;
String userValue;
String ratingValue;
String nameValue;
String emailValue;
String locationValue;
String otherValue;
TextField nameText = new TextField();
TextField otherText = new TextField();
TextField emailText = new TextField();
TextField locationText = new TextField();
TextField noteText = new TextField();
Checkbox cb = new Checkbox();
List list = new List();
Button sendButton = new Button();
Label userText = new Label();
Label ratingText = new Label();
Vector listVector = new Vector();
Panel buttonPanel = new Panel();
Panel client = new Panel();
Label eastSpace = new Label();
Label westSpace = new Label();
Label nameLabel = new Label();
Label emailLabel = new Label();
Label locationLabel = new Label();
Label otherLabel = new Label();
BorderLayout dialogLayout = new BorderLayout();
GridBagLayout clientGridBagLayout = new GridBagLayout();
String lastRecipient = "";
Panel panel1 = new Panel();
GridLayout gridLayout1 = new GridLayout();
FlowLayout flowLayout1 = new FlowLayout();
ChessViewer dlgParent;
/**Constructor
*@param ChessViewer theParent gives access to the frame
*@param String[] data array of the fields sent from the server in the Information msg
*/
public InfoDlg(ChessViewer theParent,String[] data) {
super(theParent.f,CVS.YOUR_PUBLIC,false);
this.data = data;
dlgParent = theParent;
if (data.length < 9) {
theParent.statusLine.setText(CVS.EXPECTED_EIGHT_PIECES + data.length);
}
else {
try {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
dlgParent.statusLine.setText(CVS.CHANGE_AS_DESIRED);
dlgParent.sendMsg("LogonList","");
dlgParent.setListListener(this);
userValue = data[1];
ratingValue = CVS.RATING + data[7] + " " + data[8] + CVS.GAMES_PLAYED;
nameValue = data[3];
emailValue = data[4];
locationValue = data[5];
otherValue = data[6];
jbInit();
add(dlgPanel);
dlgParent.setModal(true);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public void jbInit() throws Exception {
Font boldFont = new Font(getFont().getName(),Font.BOLD,getFont().getSize());
userText.setFont(boldFont);
dlgPanel.setLayout(dialogLayout);
dlgPanel.add(eastSpace,BorderLayout.EAST);
dlgPanel.add(westSpace,BorderLayout.WEST);
dlgPanel.add(client,BorderLayout.NORTH);
dlgPanel.add(list,BorderLayout.CENTER);
dlgPanel.add(buttonPanel,BorderLayout.SOUTH);
buttonPanel.add(cb);
buttonPanel.add(panel1, null);
panel1.add(okButton);
panel1.add(cancelButton);
list.addItemListener(new ListListener(this));
client.setLayout(clientGridBagLayout);
userText.setText(userValue);
ratingText.setText(ratingValue);
buttonPanel.setLayout(flowLayout1);
nameLabel.setText(CVS.NAME);
nameText.setText(nameValue);
emailLabel.setText(CVS.EMAIL_ADDRESS);
emailText.setText(emailValue);
locationLabel.setText(CVS.LOCATION);
locationText.setText(locationValue);
otherLabel.setText(CVS.OTHER_STUFF);
gridLayout1.setHgap(6);
flowLayout1.setHgap(25);
panel1.setLayout(gridLayout1);
otherText.setText(otherValue);
sendButton.setLabel(CVS.SEND_NOTE);
sendButton.setEnabled(false);
noteText.setText(CVS.NOTE_INSTRUCTIONS);
noteText.setEditable(false);
client.add(userText,new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 20, 4, 10), 20, 0));
client.add(ratingText,new GridBagConstraints2(1,0,1,1,1.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.HORIZONTAL,new Insets(4,0,4,20),100,0));
client.add(nameLabel,new GridBagConstraints2(0,1,1,1,0.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.NONE,new Insets(4,20,4,0),20,0));
client.add(nameText,new GridBagConstraints2(1,1,1,1,1.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.HORIZONTAL,new Insets(4,0,4,20),100,0));
client.add(emailLabel,new GridBagConstraints2(0,2,1,1,0.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.NONE,new Insets(4,20,4,0),20,0));
client.add(emailText,new GridBagConstraints2(1,2,1,1,1.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.HORIZONTAL,new Insets(4,0,4,20),100,0));
client.add(locationLabel,new GridBagConstraints2(0,3,1,1,0.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.NONE,new Insets(4,20,4,0),20,0));
client.add(locationText,new GridBagConstraints2(1,3,1,1,1.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.HORIZONTAL,new Insets(4,0,4,20),100,0));
client.add(otherLabel,new GridBagConstraints2(0,4,1,1,0.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.NONE,new Insets(4,20,4,0),20,0));
client.add(otherText,new GridBagConstraints2(1,4,1,1,1.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.HORIZONTAL,new Insets(4,0,4,20),100,0));
client.add(sendButton,new GridBagConstraints2(0,5,1,1,0.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.NONE,new Insets(4,20,4,0),20,0));
client.add(noteText,new GridBagConstraints2(1,5,1,1,1.0,0.0,GridBagConstraints.WEST
,GridBagConstraints.HORIZONTAL,new Insets(4,0,4,20),100,0));
sendButton.addActionListener(new SendButtonListener(this));
okButton.setLabel(CVS.OK);
cancelButton.setLabel(CVS.CANCEL);
okButton.addActionListener(new OkButtonListener(this));
cancelButton.addActionListener(new CancelButtonListener(this));
cb.setLabel(CVS.ONLY_SHOW);
cb.setState(true);
cb.addItemListener(new CBListener(this));
eastSpace.setText(" ");
westSpace.setText(" ");
}
public void show() {
super.show();
nameText.requestFocus();
}
public void displayData(String[] data) {
if (data.length > 8){
boolean editable = data[1].equals(dlgParent.myName);
if (editable) {
noteText.setText(CVS.NOTE_INSTRUCTIONS);
setTitle(CVS.YOUR_PUBLIC);
}
else {
setTitle(CVS.PUBLIC_INFO + data[1]);
noteText.setText("");
}
noteText.setEditable(!editable);
sendButton.setEnabled(!editable);
nameText.setEditable(editable);
emailText.setEditable(editable);
locationText.setEditable(editable);
otherText.setEditable(editable);
userText.setText(data[1]);
ratingText.setText(CVS.RATING + data[7] + " " + data[8] + CVS.GAMES_PLAYED);
nameText.setText(data[3]);
emailText.setText(data[4]);
locationText.setText(data[5]);
otherText.setText(data[6]);
}
}
public void listMessage(String msg) {
String[] data = PersistString.parse(msg) ;
System.out.println("parmcount=" + data.length + " " + msg);
int i = 0;
while (i+2 < data.length) {
listVector.addElement(data[i+1]);
list.addItem(data[i ] + " " + data[i+1] + " " + data[i+2]);
i = i + 3;
}
}
public void listItemSelected() {
int index = list.getSelectedIndex();
String id = (String)listVector.elementAt(index);
dlgParent.sendMsg("Information",id);
}
public void cbAction() {
list.removeAll();
listVector.removeAllElements();
if (cb.getState())
dlgParent.sendMsg("LogonList","");
else
dlgParent.sendMsg("PlayerList","");
}
public void sendNote(ActionEvent e) {
String[] data = new String[2];
data[0] = userText.getText();
String note = noteText.getText();
if (note.length() > 0 && !note.startsWith(CVS.MESSAGE_SENT)) {
data[1] = dlgParent.myName + ": " + note;
dlgParent.sendMsg("Note",data);
noteText.setText(CVS.MESSAGE_SENT + data[0]);
}
}
/** method that the OkButtonListener calls when button is pressed
*
*/
public void ok(ActionEvent evt) {
try {
if (data[1].equals(dlgParent.myName)) {
data[3] = nameText.getText().trim();
data[4] = emailText.getText().trim();
data[5] = locationText.getText().trim();
data[6] = otherText.getText().trim();
dlgParent.sendMsg("UpdateInfo",data);
dlgParent.statusLine.setText(CVS.USER_DATA_UPDATED);
}
dispose();
dlgParent.setModal(false);
}
catch (Exception e) {
e.printStackTrace();
}
}
/**ovveride so window can close if system close is pressed
*
*/
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING)
cancel(null);
else
super.processWindowEvent(e);
}
/**Method called when the CancelButtonListener is invoked by a button press
*/
public void cancel(ActionEvent evt) {
try {
dlgParent.removeListListener();
dlgParent.statusLine.setText("");
dispose();
dlgParent.setModal(false);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
class CBListener implements ItemListener{
InfoDlg adaptee;
CBListener(InfoDlg adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent parm1) {
adaptee.cbAction();
}
}
class ListListener implements ItemListener{
InfoDlg adaptee;
ListListener(InfoDlg adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent parm1) {
adaptee.listItemSelected();
}
}
class SendButtonListener implements ActionListener {
InfoDlg adaptee;
SendButtonListener(InfoDlg adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.sendNote(e);
}
}