package bank.client;
import bank.server.RemoteAccount;
import bank.server.RemoteCustomer;
import imaginary.gui.PersistentPanel;
import imaginary.persist.RemoteLockHolder;
import imaginary.persist.RemotePersistent;
import imaginary.util.RemoteObservable;
import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;
import java.rmi.RemoteException;
public class CustomerPanel extends PersistentPanel implements RemotePanel {
private AccountSetPanel accounts_panel;
private TextField id_field = new TextField();
private Label id_label = new Label("Customer ID:",Label.RIGHT);
private TextField name_field = new TextField();
private Label name_label = new Label("Name:", Label.RIGHT);
public CustomerPanel(RemoteLockHolder h) throws RemoteException {
super(h);
createComponents();
}
public CustomerPanel(RemoteLockHolder h, RemotePersistent p)
throws RemoteException {
super(h, p);
createComponents();
}
public RemoteAccount getSelectedAccount() {
return accounts_panel.getSelectedAccount();
}
protected void createComponents() throws RemoteException {
RemoteCustomer c = (RemoteCustomer)getObserved();
setLayout(null);
{ // ID
id_label.reshape(insets().left + 12,insets().top + 24,88,24);
add(id_label);
id_field.setEditable(false);
id_field.reshape(insets().left + 108,insets().top + 24,120,24);
add(id_field);
}
{ // Name
name_label.reshape(insets().left + 36,insets().top + 72,64,24);
add(name_label);
name_field = new TextField();
name_field.setEditable(false);
name_field.reshape(insets().left + 108,insets().top + 72,204,24);
add(name_field);
}
{ // Accounts and buttons
Button[] b = new Button[2];
b[0] = new Button(">>");
b[1] = new Button("<<");
if( c == null ) {
accounts_panel = new AccountSetPanel(b, getLockHolder());
}
else {
accounts_panel = new AccountSetPanel(b, getLockHolder(),
c.getAccountSet());
}
accounts_panel.reshape(insets().left + 12,insets().top + 120, 348,
120);
add(accounts_panel);
b[0].reshape(insets().left + 384,insets().top + 144,36,24);
add(b[0]);
b[1].reshape(insets().left + 384,insets().top + 180,36,24);
add(b[1]);
}
if( c != null ) {
observeChange();
}
}
protected void cleanUp() {
RemoteObservable o = getObserved();
if( o != null ) {
try {
o.deleteObserver(this);
}
catch( RemoteException e ) {
}
}
accounts_panel.cleanUp();
}
public void observeChange() {
RemoteCustomer c = (RemoteCustomer)getObserved();
try {
id_field.setText("" + c.getId());
name_field.setText(c.getLastName() + ", " + c.getFirstName());
}
catch( RemoteException e ) {
e.printStackTrace();
id_field.setText("");
name_field.setText("");
}
}
}
|