FileDocCategorySizeDatePackage
AccountSetPanel.javaAPI DocExample6633Sun Mar 02 22:01:02 GMT 1997bank.client

AccountSetPanel

public class AccountSetPanel extends imaginary.gui.PersistentSetPanel implements ActionListener, RemotePanel
A Java panel with a CardLayout that allows the user to flip through accounts.

Fields Summary
private int
current_account
private Button
next_button
private AccountPanel[]
panels
private Button
previous_button
Constructors Summary
public AccountSetPanel(Button[] buttons, imaginary.persist.RemoteLockHolder h)
Creates a new AccountSetPanel. The buttons array are the next and previous buttons placed on the customer panel. Visually, they fit better on the customer panel. Process-wise, however, this panel is interested in their events.

param
buttons the next and previous buttons in that order
param
h the lock holder for any modifications


      
                                                                 
        
      
        super(h);
        next_button = buttons[0];
        previous_button = buttons[1];
        createComponents();
    
public AccountSetPanel(Button[] buttons, imaginary.persist.RemoteLockHolder h, imaginary.persist.RemotePersistentSet set)
Constructs an AccountSetPanel observing the specified set.

param
buttons the next and previous buttons in that order
param
h the lock holder for any modifications
param
set the set being observed

        super(h, set);
        next_button = buttons[0];
        previous_button = buttons[1];
        createComponents();
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)
This method is new to JDK 1.1. It handles action events for components this class has expressed interest in. In the case of the account set panel, we want to know when one of the buttons are clicked.

param
event the triggered event

        Button b = (Button)event.getSource();

        // the user clicked next
        if( b == next_button ) {
            // flip to the next account in the card layout
            ((CardLayout)getLayout()).next(this);
            // up the marker
            current_account++;
            // if this is the last account, disable the next button
            if( current_account == panels.length ) {
                next_button.enable(false);
            }
            // if this is not the first account, enable the previous button
            if( current_account > 1 ) {
                previous_button.enable(true);
            }
        }
        else {
            // flip to the previous account in the card layout
            ((CardLayout)getLayout()).previous(this);
            // decrement the marker
            current_account--;
            // if this is the first account, disable the previous button
            if( current_account < 2 ) {
                previous_button.enable(false);
            }
            // if this is not the last account, enable the next button
            if( current_account < panels.length ) {
                next_button.enable(true);
            }
        }           
    
protected voidcleanUp()
When the window gets destroyed or this panel is removed, cleanUp() gets called to allow the panel to remove itself from the observer list of its set.

        RemoteObservable o = getObserved();

        if( o != null ) {
            try {
                o.deleteObserver(this);
            }
            catch( RemoteException e ) {
            }
        }
        if( panels != null ) {
            for(int i=0; i<panels.length; i++) {
                panels[i].cleanUp();
            }
        }
    
protected voidcreateComponents()
Places the individual widgets on the panel.

exception
java.rmi.RemoteException if the observed set is out of reach

        RemoteAccountSet set = (RemoteAccountSet)getObserved();
        RemotePersistent[] accounts;

        // CardLayout allows us to view one account panel at a time
        setLayout(new CardLayout(0,0));
        // Don't draw anything if no set is being observed
        if( set == null ) {
            return;
        }
        accounts = set.getPersistents();
        current_account = 1;
        panels = new AccountPanel[accounts.length];
        // For each observed account, add an account panel
        for(int i=0; i<accounts.length; i++) {
            panels[i] = new AccountPanel(getLockHolder(),
                                         (RemoteAccount)accounts[i]);
            
            panels[i].reshape(insets().left + 24,insets().top + 132,384,120);
            add("" + i, panels[i]);
        }
        previous_button.addActionListener(this);
        previous_button.enable(false);
        next_button.addActionListener(this);
        if( panels.length < 2 ) {
            next_button.enable(false);
        }
    
public bank.server.RemoteAccountgetSelectedAccount()

return
the account currently being viewed

        AccountPanel acct_panel = panels[current_account-1];

        return (RemoteAccount)acct_panel.getObserved();
    
public voidobserveChange()
Implementation of the ChangeObserver method for handling changes in observed objects.

        // Since this application does not support the addition
        // or deletion of accounts, it will not actually
        // observe any changes.  If it did, however, you would use
        // this method to add new panels or remove deleted ones