/*
 * Moderator.java
 *
 * Author: Jonathan Boldiga
 * Date: July 22, 2002
 *
 * Description: This is the Moderator interface for ORBChat, a CORBA based chat program.
 *				This class uses SWING and implements multiple methods which allow moderation
 *				of the ORBChat program. To run ORBChat::Moderator, execute the Client.java
 *				class file and log in as "administrator".
 *
 * Copyright (c) 1993-2001 IONA Technologies PLC.
 *  			All Rights Reserved
 *
*/

package Chat;

import java.io.*;

import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;

import java.awt.*;
import java.awt.event.*;

import org.omg.CORBA.*;


public class Moderator extends JFrame {

	Chat.ChatRemote cr;
    protected static JTextArea textArea;
    protected static String newline = "\n";

    public Moderator(ChatRemote cRemote) {

        //Do frame stuff.
        super("ORBChat :: Moderator");
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                closeMe();
            }
        });

        cr = cRemote;


        //Create the toolbar.
        JToolBar toolBar = new JToolBar();
        addActions(toolBar);

        //Create the text area used for output.
		textArea = new JTextArea(5, 30);
		textArea.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(textArea);


        //Lay out the content pane.
        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());
        contentPane.setPreferredSize(new Dimension(400, 150));
        contentPane.add(toolBar, BorderLayout.NORTH);
        contentPane.add(scrollPane, BorderLayout.CENTER);
        setContentPane(contentPane);
    }

	public void addActions(final JToolBar toolBar){
		JButton button = null;

		//message button
		button = new JButton("Message");
		button.setToolTipText("Send a message to a client");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Message talk = new Message(cr);
				talk.pack();
				talk.setVisible(true);
			}
		});
		toolBar.add(button);


		//kick button
		button = new JButton("Kick");
		button.setToolTipText("Kick a client offline");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Kick kick = new Kick(cr);
				kick.pack();
				kick.setVisible(true);
			}
		});
		toolBar.add(button);

		//who button
		button = new JButton("Who");
		button.setToolTipText("List available clients");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ClientListGUI clg = new ClientListGUI(cr);
				clg.pack();
				clg.setVisible(true);
			}
		});
		toolBar.add(button);

		//exit button
		button = new JButton("Exit");
		button.setToolTipText("Exit ORBChat");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				closeMe();
			}
		});
        toolBar.add(button);

	}

	protected static void displayResult(String message, String source) {
		textArea.append(source + ":" + " " + message + newline);
	}

	public void closeMe(){
        System.exit(0);
	}

}

