home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
InfoDlg.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
12KB
|
321 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
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
{
ResourceBundle res = ResourceBundle.getBundle("borland.samples.apps.chess.client.Res");
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,"",false);
setTitle(res.getString("YOUR_PUBLIC"));
this.data = data;
dlgParent = theParent;
if (data.length < 9) {
theParent.statusLine.setText(res.getString("EXPECTED_EIGHT_PIECES") + data.length);
}
else {
try {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
dlgParent.statusLine.setText(res.getString("CHANGE_AS_DESIRED"));
dlgParent.sendMsg("LogonList","");
dlgParent.setListListener(this);
userValue = data[1];
ratingValue = res.getString("RATING") + data[7] + " " + data[8] + res.getString("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();
}
}
}
private 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(res.getString("NAME"));
nameText.setText(nameValue);
emailLabel.setText(res.getString("EMAIL_ADDRESS"));
emailText.setText(emailValue);
locationLabel.setText(res.getString("LOCATION"));
locationText.setText(locationValue);
otherLabel.setText(res.getString("OTHER_STUFF"));
gridLayout1.setHgap(6);
flowLayout1.setHgap(25);
panel1.setLayout(gridLayout1);
otherText.setText(otherValue);
sendButton.setLabel(res.getString("SEND_NOTE"));
sendButton.setEnabled(false);
noteText.setText(res.getString("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(res.getString("OK"));
cancelButton.setLabel(res.getString("CANCEL"));
okButton.addActionListener(new OkButtonListener(this));
cancelButton.addActionListener(new CancelButtonListener(this));
cb.setLabel(res.getString("ONLY_SHOW"));
cb.setState(true);
cb.addItemListener(new CBListener(this));
eastSpace.setText(" ");
westSpace.setText(" ");
}
public void setVisible(boolean isVisible) {
super.setVisible(isVisible);
if (isVisible)
nameText.requestFocus();
}
public void displayData(String[] data) {
if (data.length > 8){
boolean editable = data[1].equals(dlgParent.myName);
if (editable) {
noteText.setText(res.getString("NOTE_INSTRUCTIONS"));
setTitle(res.getString("YOUR_PUBLIC"));
}
else {
setTitle(res.getString("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(res.getString("RATING") + data[7] + " " + data[8] + res.getString("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(res.getString("MESSAGE_SENT"))) {
data[1] = dlgParent.myName + ": " + note;
dlgParent.sendMsg("Note",data);
noteText.setText(res.getString("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(res.getString("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);
}
}