/*
 * ClientListGUI.java
 *
 * Author: Jonathan Boldiga
 * Date: July 22, 2002
 *
 * Description: This is the ClientListGUI for ORBChat, a CORBA based chat program.
 *				This class uses SWING and implements a method called printClientList() which
 *				displays a list of all current online users/clients. To run ORBChat, execute
 *				the Client.java class file.
 *
 * Copyright (c) 1993-2001 IONA Technologies PLC.
 *  			All Rights Reserved
 *
*/

package Chat;

import java.io.*;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

import org.omg.CORBA.*;

public class ClientListGUI extends JFrame{

	static Chat.ChatRemote cr;
	protected JScrollPane scrollPane;
	protected JList usersOnline;
    protected static String newline = "\n";

	public ClientListGUI(Chat.ChatRemote cRemote) {

        //Do frame stuff.
        super("Current Users");
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                setVisible(false);
				dispose();
            }
        });

		cr = cRemote;

		usersOnline = new JList(cr.who());
		usersOnline.setBackground(Color.cyan);
		scrollPane = new JScrollPane(usersOnline);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

		usersOnline.addListSelectionListener(new ListSelectionListener(){
			public void valueChanged(ListSelectionEvent event){
		    	java.lang.Object[] users = usersOnline.getSelectedValues();
		    	String selectedUser = null;

				for (int i = 0; i < users.length; i++){
		        	selectedUser = (String)users[i];
				}
		   	}
         });


        //Lay out the content pane.
        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());
        contentPane.setPreferredSize(new Dimension(150, 300));
        contentPane.add(scrollPane, BorderLayout.CENTER);
        setContentPane(contentPane);

    }

}