
/*
 * A dialog box to display the incoming call information.
 * Instantiated for every incoming call by the UAServer object.
 *
 * Author: Janet H. Park
 * Date: August, 1998
 *
 */

import java.awt.*;

public class CalleeDialog extends Frame
{
    UAServer svr;
    
	public CalleeDialog()
	{
		// 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
		GridBagLayout gridBagLayout;
		gridBagLayout = new GridBagLayout();
		setLayout(gridBagLayout);
		setVisible(false);
		setSize(insets().left + insets().right + 426,insets().top + insets().bottom + 439);
		panel1 = new java.awt.Panel();
		panel1.setLayout(null);
		panel1.setBounds(insets().left + 10,insets().top + 10,406,419);
		panel1.setFont(new Font("Dialog", Font.PLAIN, 12));
		panel1.setBackground(new Color(13231359));
		GridBagConstraints gbc;
		gbc = new GridBagConstraints();
		gbc.weightx = 100.0;
		gbc.weighty = 100.0;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.insets = new Insets(10,10,10,10);
		((GridBagLayout)getLayout()).setConstraints(panel1, gbc);
		add(panel1);
		labelLog = new java.awt.Label("Incoming Call Information");
		labelLog.setBounds(38,194,192,24);
		labelLog.setFont(new Font("Dialog", Font.BOLD, 12));
		labelLog.setForeground(new Color(-16777152));
		panel1.add(labelLog);
		buttonReject = new java.awt.Button();
		buttonReject.setActionCommand("button");
		buttonReject.setLabel("Reject");
		buttonReject.setBounds(170,158,80,20);
		buttonReject.setFont(new Font("Dialog", Font.PLAIN, 12));
		buttonReject.setForeground(new Color(16777215));
		buttonReject.setBackground(new Color(-12565076));
		panel1.add(buttonReject);
		buttonAccept = new java.awt.Button();
		buttonAccept.setActionCommand("button");
		buttonAccept.setLabel("Accept");
		buttonAccept.setBounds(62,158,80,20);
		buttonAccept.setFont(new Font("Dialog", Font.PLAIN, 12));
		buttonAccept.setForeground(new Color(16777215));
		buttonAccept.setBackground(new Color(-12565076));
		panel1.add(buttonAccept);
		textAreaLog = new java.awt.TextArea();
		textAreaLog.setBounds(26,218,372,144);
		textAreaLog.setForeground(new Color(-16777125));
		panel1.add(textAreaLog);
		buttonRedirect = new java.awt.Button();
		buttonRedirect.setActionCommand("button");
		buttonRedirect.setLabel("Redirect");
		buttonRedirect.setBounds(278,158,80,20);
		buttonRedirect.setFont(new Font("Dialog", Font.PLAIN, 12));
		buttonRedirect.setForeground(new Color(16777215));
		buttonRedirect.setBackground(new Color(4212140));
		panel1.add(buttonRedirect);
		labelCallerId = new java.awt.Label("From:",Label.RIGHT);
		labelCallerId.setBounds(38,14,48,24);
		labelCallerId.setFont(new Font("Dialog", Font.BOLD, 12));
		labelCallerId.setForeground(new Color(-16777152));
		panel1.add(labelCallerId);
		labelCallerAddr = new java.awt.Label("At:",Label.RIGHT);
		labelCallerAddr.setBounds(182,14,24,24);
		labelCallerAddr.setFont(new Font("Dialog", Font.BOLD, 12));
		labelCallerAddr.setForeground(new Color(-16777152));
		panel1.add(labelCallerAddr);
		labelCalleeId = new java.awt.Label("To:",Label.RIGHT);
		labelCalleeId.setBounds(50,38,36,24);
		labelCalleeId.setFont(new Font("Dialog", Font.BOLD, 12));
		labelCalleeId.setForeground(new Color(-16777152));
		panel1.add(labelCalleeId);
		labelCalleeAddr = new java.awt.Label("At:",Label.RIGHT);
		labelCalleeAddr.setBounds(182,38,24,24);
		labelCalleeAddr.setFont(new Font("Dialog", Font.BOLD, 12));
		labelCalleeAddr.setForeground(new Color(-16777152));
		panel1.add(labelCalleeAddr);
		labelConn = new java.awt.Label("Connection:",Label.RIGHT);
		labelConn.setBounds(2,86,84,24);
		labelConn.setFont(new Font("Dialog", Font.BOLD, 12));
		labelConn.setForeground(new Color(-16777152));
		panel1.add(labelConn);
		labelPriority = new java.awt.Label("Priority:");
		labelPriority.setBounds(194,86,60,24);
		labelPriority.setFont(new Font("Dialog", Font.BOLD, 12));
		labelPriority.setForeground(new Color(-16777152));
		panel1.add(labelPriority);
		labelSubject = new java.awt.Label("Subject:",Label.RIGHT);
		labelSubject.setBounds(14,62,72,24);
		labelSubject.setFont(new Font("Dialog", Font.BOLD, 12));
		labelSubject.setForeground(new Color(-16777152));
		panel1.add(labelSubject);
		labelCallerIdVal = new java.awt.Label("");
		labelCallerIdVal.setBounds(98,14,84,21);
		panel1.add(labelCallerIdVal);
		labelCallerAddrVal = new java.awt.Label("");
		labelCallerAddrVal.setBounds(218,14,204,20);
		panel1.add(labelCallerAddrVal);
		labelCalleeIdVal = new java.awt.Label("");
		labelCalleeIdVal.setBounds(98,38,86,22);
		panel1.add(labelCalleeIdVal);
		labelCalleeAddrVal = new java.awt.Label("");
		labelCalleeAddrVal.setBounds(218,38,204,24);
		panel1.add(labelCalleeAddrVal);
		labelSubjectVal = new java.awt.Label("");
		labelSubjectVal.setBounds(98,62,304,24);
		labelSubjectVal.setBackground(new Color(13231359));
		panel1.add(labelSubjectVal);
		labelPriorityVal = new java.awt.Label("");
		labelPriorityVal.setBounds(254,86,96,24);
		panel1.add(labelPriorityVal);
		labelSessVal = new java.awt.Label("");
		labelSessVal.setBounds(98,110,312,24);
		panel1.add(labelSessVal);
		buttonDone = new java.awt.Button();
		buttonDone.setActionCommand("button");
		buttonDone.setLabel("Done");
		buttonDone.setBounds(146,374,106,26);
		buttonDone.setForeground(new Color(16777215));
		buttonDone.setBackground(new Color(-12565076));
		panel1.add(buttonDone);
		labelConnVal = new java.awt.Label("");
		labelConnVal.setBounds(98,86,96,24);
		panel1.add(labelConnVal);
		labelSess = new java.awt.Label("Session:",Label.RIGHT);
		labelSess.setBounds(14,110,72,24);
		labelSess.setFont(new Font("Dialog", Font.BOLD, 12));
		panel1.add(labelSess);
		labelSessInfoVal = new java.awt.Label("");
		labelSessInfoVal.setBounds(98,134,312,24);
		panel1.add(labelSessInfoVal);
		setTitle("Incoming Call");
		//}}

		//{{INIT_MENUS
		//}}

		//{{REGISTER_LISTENERS
		SymWindow aSymWindow = new SymWindow();
		this.addWindowListener(aSymWindow);
		SymAction lSymAction = new SymAction();
		buttonAccept.addActionListener(lSymAction);
		buttonReject.addActionListener(lSymAction);
		buttonRedirect.addActionListener(lSymAction);
		buttonDone.addActionListener(lSymAction);
		//}}
	}

	public CalleeDialog(String title, UAServer svr)
	{
		this();
		setTitle(title);
		this.svr = svr;
	}

	public synchronized void show()
	{
		move(50, 50);
		super.show();
	}

	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;

	//{{DECLARE_CONTROLS
	java.awt.Panel panel1;
	java.awt.Label labelLog;
	java.awt.Button buttonReject;
	java.awt.Button buttonAccept;
	java.awt.TextArea textAreaLog;
	java.awt.Button buttonRedirect;
	java.awt.Label labelCallerId;
	java.awt.Label labelCallerAddr;
	java.awt.Label labelCalleeId;
	java.awt.Label labelCalleeAddr;
	java.awt.Label labelConn;
	java.awt.Label labelPriority;
	java.awt.Label labelSubject;
	java.awt.Label labelCallerIdVal;
	java.awt.Label labelCallerAddrVal;
	java.awt.Label labelCalleeIdVal;
	java.awt.Label labelCalleeAddrVal;
	java.awt.Label labelSubjectVal;
	java.awt.Label labelPriorityVal;
	java.awt.Label labelSessVal;
	java.awt.Button buttonDone;
	java.awt.Label labelConnVal;
	java.awt.Label labelSess;
	java.awt.Label labelSessInfoVal;
	//}}

	//{{DECLARE_MENUS
	//}}

	class SymWindow extends java.awt.event.WindowAdapter
	{
		public void windowClosing(java.awt.event.WindowEvent event)
		{
			Object object = event.getSource();
			if (object == CalleeDialog.this)
				Frame1_WindowClosing(event);
		}
	}
	
	void Frame1_WindowClosing(java.awt.event.WindowEvent event)
	{
		hide();		 // hide the Frame
	}

	class SymAction implements java.awt.event.ActionListener
	{
		public void actionPerformed(java.awt.event.ActionEvent event)
		{
			Object object = event.getSource();
			if (object == buttonAccept)
				buttonAccept_Action(event);
			else if (object == buttonReject)
				buttonReject_Action(event);
			else if (object == buttonRedirect)
				buttonRedirect_Action(event);
			else if (object == buttonDone)
				buttonDone_Action(event);
		}
	}

	void buttonAccept_Action(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.

		svr.answer();
			 
		//{{CONNECTION
		// Hide the Frame
		// setVisible(false);
		//}}
	}

	void buttonReject_Action(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
		svr.reject();
			 
		//{{CONNECTION
		// Hide the Frame
		// setVisible(false);
		//}}
	}

	void buttonRedirect_Action(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
		svr.moved();
			 
		//{{CONNECTION
		// Hide the Frame
		// setVisible(false);
		//}}
	}


	synchronized void log(String msg) {
		textAreaLog.append(msg+"\n");
		// System.out.println(msg);
	}

	synchronized void debug(String msg) {
		System.out.println(msg);
	}

	final static String OK = "200 OK";
	final static String DECLINE = "603 Decline";
	final static String MOVED = "302 Moved Temporarily";
	final static String BADREQ = "400 Bad Request";


	void buttonDone_Action(java.awt.event.ActionEvent event)
	{
		// to do: code goes here.
			 
		//{{CONNECTION
		// Hide the Frame
		setVisible(false);
		dispose();
		//}}
	}

	void setCallerId(String s) {
		labelCallerIdVal.setText(s);
	}

	void setCallerAddr(String s) {
		labelCallerAddrVal.setText(s);
	}

	void setCalleeId(String s) {
		labelCalleeIdVal.setText(s);
	}

	void setCalleeAddr(String s) {
		labelCalleeAddrVal.setText(s);
	}

	void setSubject(String s) {
		labelSubjectVal.setText(s);
	}

	void setPriority(String s) {
		labelPriorityVal.setText(s);
	}

	void setConn(String s) {
		labelConnVal.setText(s);
	}

	void setSess(String s) {
		labelSessVal.setText(s);
	}

	void setSessInfo(String s) {
		labelSessInfoVal.setText(s);
	}

}
