/* A basic extension of the java.awt.Dialog class */ import java.awt.*; import twinfeats.io.*; import twinfeats.conf.core.*; public class ChangePasswordDialog extends Dialog { private ClientWin client; public ChangePasswordDialog(Frame parent, boolean modal) { super(parent, modal); // This code is automatically generated by Visual Cafe when you add // components to the visual environment. It instantiates and initializes // the components. To modify the code, only use code syntax that matches // what Visual Cafe can generate, or Visual Cafe may be unable to back // parse your Java file into its visual environment. //{{INIT_CONTROLS setLayout(null); setSize(insets().left + insets().right + 300,insets().top + insets().bottom + 190); setFont(new Font("SansSerif", Font.PLAIN, 12)); oldPW = new java.awt.TextField(); oldPW.setBounds(insets().left + 106,insets().top + 25,172,31); add(oldPW); newPW = new java.awt.TextField(); newPW.setBounds(insets().left + 106,insets().top + 63,172,31); add(newPW); label1 = new java.awt.Label("Old password",Label.RIGHT); label1.setBounds(insets().left + 7,insets().top + 23,93,33); add(label1); label2 = new java.awt.Label("New password",Label.RIGHT); label2.setBounds(insets().left + 7,insets().top + 61,93,33); add(label2); OK = new java.awt.Button(); OK.setLabel("OK"); OK.setBounds(insets().left + 67,insets().top + 108,60,40); OK.setBackground(java.awt.Color.lightGray); add(OK); Cancel = new java.awt.Button(); Cancel.setLabel("Cancel"); Cancel.setBounds(insets().left + 158,insets().top + 109,60,40); Cancel.setBackground(java.awt.Color.lightGray); add(Cancel); Status = new java.awt.TextField(); Status.setEditable(false); Status.setBounds(insets().left + 11,insets().top + 156,281,27); add(Status); setTitle("Change Password"); //}} //{{REGISTER_LISTENERS SymWindow aSymWindow = new SymWindow(); this.addWindowListener(aSymWindow); SymAction lSymAction = new SymAction(); OK.addActionListener(lSymAction); Cancel.addActionListener(lSymAction); oldPW.addActionListener(lSymAction); newPW.addActionListener(lSymAction); //}} client = (ClientWin)parent; new ReadListener(client.getComm(),client.getComm().getName(),ConfBean.CHANGEPASSWORD,new HandleChangePassword()); } public void addNotify() { // Record the size of the window prior to calling parents addNotify. Dimension d = getSize(); super.addNotify(); if (fComponentsAdjusted) return; // Adjust components according to the insets setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height); Component components[] = getComponents(); for (int i = 0; i < components.length; i++) { Point p = components[i].getLocation(); p.translate(insets().left, insets().top); components[i].setLocation(p); } fComponentsAdjusted = true; } // Used for addNotify check. boolean fComponentsAdjusted = false; public ChangePasswordDialog(Frame parent, String title, boolean modal) { this(parent, modal); setTitle(title); } public synchronized void show() { Rectangle bounds = getParent().bounds(); Rectangle abounds = bounds(); move(bounds.x + (bounds.width - abounds.width)/ 2, bounds.y + (bounds.height - abounds.height)/2); super.show(); } //{{DECLARE_CONTROLS java.awt.TextField oldPW; java.awt.TextField newPW; java.awt.Label label1; java.awt.Label label2; java.awt.Button OK; java.awt.Button Cancel; java.awt.TextField Status; //}} class SymWindow extends java.awt.event.WindowAdapter { public void windowClosing(java.awt.event.WindowEvent event) { Object object = event.getSource(); if (object == ChangePasswordDialog.this) Dialog1_WindowClosing(event); } } void Dialog1_WindowClosing(java.awt.event.WindowEvent event) { hide(); dispose(); } class SymAction implements java.awt.event.ActionListener { public void actionPerformed(java.awt.event.ActionEvent event) { Object object = event.getSource(); if (object == OK) OK_Action(event); else if (object == Cancel) Cancel_Action(event); else if (object == oldPW) oldPW_EnterHit(event); else if (object == newPW) newPW_EnterHit(event); } } void OK_Action(java.awt.event.ActionEvent event) { // to do: code goes here. String oldpw = oldPW.getText(); String newpw = newPW.getText(); if (oldpw.equals("") || newpw.equals("")) { Status.setText("Enter both your old and new passwords"); return; } client.changePassword(oldpw,newpw); Status.setText("Sending request..."); CommMessage msg = new CommMessage(client.getComm().getName(),ConfBean.CONFERENCESERVER,ConfBean.CHANGEPASSWORD, new MsgChangePassword(oldpw,newpw)); client.getComm().send(msg); } void Cancel_Action(java.awt.event.ActionEvent event) { // to do: code goes here. hide(); dispose(); } void oldPW_EnterHit(java.awt.event.ActionEvent event) { // to do: code goes here. OK_Action(null); } void newPW_EnterHit(java.awt.event.ActionEvent event) { // to do: code goes here. OK_Action(null); } class HandleChangePassword implements GenericMessageListener { HandleChangePassword() { } /** * CommMessageListener: A message has been received */ public void message(CommMessageEvent cme) { CommMessage msg = cme.getCommMessage(); MsgChangePassword body = (MsgChangePassword)msg.getBody(); if (body != null) { if (body.isChanged()) { Status.setText("Password has been changed"); OK.disable(); return; } } Status.setText("Request failed"); } } }