⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javaphoneframe.java

📁 基于Cisco CTI OS 6.0的Java 软电话简单实例
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

		// Get a reference to the CIL's singleton LogManager or create one
		// if it doesn't exist.  This will give us the ability to post
		// trace messages to interested listeners such as LogWrapper objects.
		LogManager lmTraceLog = LogManager.Instance();

		// Setup tracing to go to System.out and to a logfile
		try
		{
	    	// Trace to the console. With no filename provided, this will
			// default to tracing to System.out.
	   	 	lwConsole = new LogWrapper();

	    	// Trace to a log file using the utility class provided in the
			// ctios.util package.  Users may use this for standalone apps
			// or they must provide their own tracing mechanism by implementing
			// an ILogListener class and registering to receive JavaCIL trace
			// from the LogManager. It is important to note that the
			// constructor of the LogWrapper class automatically registers
			// it as a listener with the LogManager.
	    	lwLogFile = new LogWrapper("./Log/JavaPhone.log");

			// Set the default trace mask. 0x7 is effectively:
			// TRACE_MASK_CRITICAL | TRACE_MASK_WARNING | TRACE_MASK_EVT_REQ_HIGH
			// found in util.Logger.  It affects all trace statements posted
			// to the LogManager.
			//
			// This mask can be manipulated at runtime by the user through
			// this method.  This sample does not provide a means to do that
			// but the user would be expected to provide a way to do it for
			// troubleshooting purposes.
		    lmTraceLog.SetTraceMask(0x00000007);
		}
		catch(Exception e)
		{
			// Since only one call may have failed we still might be tracing
			// to the console.  Trace it anyway.  Use our UtilityMethod for
			// getting a string with the stack trace from the Exception object
			// so we can trace it to all Log Event listeners instead of just
			// doing an e.printStackTrace().
			lmTraceLog.Trace(Logger.TRACE_MASK_CRITICAL,
						"main, Caught Exception: " +
						Utility_Methods.GetStackTraceString(e));

			// We'll still print here just in case.  Who cares it comes out twice?
			System.out.println("main, Caught Exception: " +
								Utility_Methods.GetStackTraceString(e));
		}

		try
		{
			(new JavaPhoneFrame()).setVisible(true);  // Create the GUI
		}
		catch (Exception e2)
		{
			// We haven't created any of our tracing mechanisms yet so just
			// print to
			lmTraceLog.Trace(Logger.TRACE_MASK_CRITICAL,
						"main, Caught Exception creating JavaPhoneFrame: " +
						Utility_Methods.GetStackTraceString(e2));
			System.exit(1);
		}

	} // main

	///////////////////////////////////////////////////////////////////////////
    /**
     * Some GUI stuff.
     */
	///////////////////////////////////////////////////////////////////////////
	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(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
		Component components[] = getComponents();
		for (int i = 0; i < components.length; i++)
		{
			Point p = components[i].getLocation();
			p.translate(getInsets().left, getInsets().top);
			components[i].setLocation(p);
		}
		fComponentsAdjusted = true;
	}

	///////////////////////////////////////////////////////////////////////////
    /**
     * Setup a window adapter for trapping the close event
     */
	///////////////////////////////////////////////////////////////////////////
	class JavaPhoneWindow extends java.awt.event.WindowAdapter
	{
		public void windowClosing(java.awt.event.WindowEvent event)
		{
			Object object = event.getSource();
			if (object == JavaPhoneFrame.this)
				JavaPhoneFrame_WindowClosing(event);
		}

	} // class JavaPhoneWindow

	///////////////////////////////////////////////////////////////////////////
    /**
     * Handler for the WindowClosing event
     */
	///////////////////////////////////////////////////////////////////////////
	void JavaPhoneFrame_WindowClosing(java.awt.event.WindowEvent event)
	{
		try
		{
			// QuitDialog Create and show as modal
			(new QuitDialog(this, true)).setVisible(true);
		}
		catch (Exception e)
		{
			m_Log.Trace(TRACE_MASK_ALWAYS, "JavaPhoneFrame_WindowClosing, Caught Exception: " +
						Utility_Methods.GetStackTraceString(e));
		}

	} // JavaPhoneFrame_WindowClosing

	///////////////////////////////////////////////////////////////////////////
    /**
     * Setup a mouse adapter for trapping Mouse events
     */
	///////////////////////////////////////////////////////////////////////////
	class JavaPhoneMouse extends java.awt.event.MouseAdapter
	{
		public void mouseClicked(java.awt.event.MouseEvent event)
		{
			Object object = event.getSource();
			if (object == m_btnConnect)
				m_btnConnect_MouseClicked(event);
			else if (object == m_btnDisconnect)
				m_btnDisconnect_MouseClicked(event);
			else if (object == m_btnLogin)
				m_btnLogin_MouseClicked(event);
			else if (object == m_btnLogout)
	            m_btnLogout_MouseClicked(event);
			else if (object == m_btnReady)
	            m_btnReady_MouseClicked(event);
			else if (object == m_btnNotReady)
	            m_btnNotReady_MouseClicked(event);
			else if (object == m_btnMakeCall)
	            m_btnMakeCall_MouseClicked(event);
			else if (object == m_btnAnswer)
	            m_btnAnswer_MouseClicked(event);
			else if (object == m_btnRelease)
	            m_btnRelease_MouseClicked(event);
			else if (object == m_btnHold)
	            m_btnHold_MouseClicked(event);
			else if (object == m_btnRetrieve)
	            m_btnRetrieve_MouseClicked(event);
			else if (object == m_btnCCConference)
	            m_btnCCConference_MouseClicked(event);
			else if (object == m_btnConference)
	            m_btnConference_MouseClicked(event);
			else if (object == m_btnSSConference)
	            m_btnSSConference_MouseClicked(event);
			else if (object == m_btnCCTransfer)
	            m_btnCCTransfer_MouseClicked(event);
			else if (object == m_btnTransfer)
	            m_btnTransfer_MouseClicked(event);
			else if (object == m_btnSSTransfer)
	            m_btnSSTransfer_MouseClicked(event);
			else if (object == m_btnGetData)
	            m_btnGetData_MouseClicked(event);
			else if (object == m_btnSetData)
	            m_btnSetData_MouseClicked(event);
			else if (object ==  m_btnGetContext)
	            m_btnGetContext_MouseClicked(event);
	        else if (object ==  m_btnClearLog)
	            m_btnClearLog_MouseClicked(event);
		}
	} // JavaPhoneMouse

	///////////////////////////////////////////////////////////////////////////
    /**
     * Connect button was clicked
     */
	///////////////////////////////////////////////////////////////////////////
	void m_btnConnect_MouseClicked(java.awt.event.MouseEvent event)
	{
		int     iRetVal = CIL_OK;
		boolean bValid  = true;
	
		// Check to see if we are already connected, if so return
		if (m_bSessionConnected == true)
		{
			AddLogMessage("Already Connected!");
			return;
		}
	
		// Write a status message to the log window
		AddLogMessage("Connecting to CTIOS Server...");
	
		// Get the host A info
		m_sHostA  = m_edtHostA.getText();
		m_iPortA = Integer.parseInt(m_edtPortA.getText());
	
		// Get the host B info
		m_sHostB  = m_edtHostB.getText();
		m_iPortB = Integer.parseInt(m_edtPortB.getText());
	
		// Create an Arguments object to pass our values in to Connect()
		Arguments rArgSessionConn   = new Arguments();
	
		// Set the connection info in the Arguments
		rArgSessionConn.SetValue(CTIOS_CTIOSA, m_sHostA );
		rArgSessionConn.SetValue(CTIOS_PORTA, m_iPortA );
		rArgSessionConn.SetValue(CTIOS_CTIOSB, m_sHostB );
		rArgSessionConn.SetValue(CTIOS_PORTB, m_iPortB );
		rArgSessionConn.SetValue(CTIOS_HEARTBEAT, m_iHeartBeat );
	
		// Open the connection
		iRetVal = m_ctiSession.Connect(rArgSessionConn);
	
		// Request failed
		if (iRetVal < 1)
		{
			AddLogMessage("Session->Connect to CTIOS Server Failed");
			return;
		}

		// Request successfully posted but we won't know if the
		// connect succeded until we get an OnConnection event!
		AddLogMessage("Connecting...");
		m_edtConnection.setText("Connecting...");

	} // m_btnConnect_MouseClicked

	///////////////////////////////////////////////////////////////////////////
    /**
     * Disconnect button was clicked
     */
	///////////////////////////////////////////////////////////////////////////
	void m_btnDisconnect_MouseClicked(java.awt.event.MouseEvent event)
	{
        AddLogMessage("Disconnecting from CTIOS Server...");

        // Set our Agent object to null because we won't be
		// logged in as an agent anymore.
        m_ctiAgent = null;

		// No arguments required so just create an empty Arguments
		// object and pass that in.
        m_ctiSession.Disconnect( new Arguments() );

		// Update the status
        m_edtConnection.setText("Offline");

	} // m_btnDisconnect_MouseClicked

	///////////////////////////////////////////////////////////////////////////
    /**
     * Login button was clicked
     */
	///////////////////////////////////////////////////////////////////////////
	void m_btnLogin_MouseClicked(java.awt.event.MouseEvent event)
	{
		// Check to see if we are already connected
		if ( !IsSessionConnected() )
		{
			AddLogMessage("Must be connected first!");
			return;
		}

		if (IsLoginInProgress())
		{
			AddLogMessage("Login already in progress!");
			return;
		}

		SetLoginInProgress(true);
	
		// Create an Agent object for us to set in the session.
		if (m_ctiAgent == null)
			m_ctiAgent = new Agent();

	    AddLogMessage("Requesting Login");
	
		if ( m_ctiAgent != null)
		{
			// Get agent info from the entry fields
			String sAgentID = m_edtAgentID.getText();
			SetAgentID( sAgentID );

			String sPassword = m_edtPassword.getText();
			SetAgentPassword( sPassword );

            String sInstrument = m_edtInstrument.getText();
			SetAgentInstrument( sInstrument );

			String sPeripheralID = m_edtPeripheralID.getText();
			SetPeripheralID( Integer.parseInt( sPeripheralID ) );
	
			// Set the properties on the agent object
			m_ctiAgent.SetValue(CTIOS_AGENTID, sAgentID);
			m_ctiAgent.SetValue(CTIOS_AGENTPASSWORD, sPassword);
			m_ctiAgent.SetValue(CTIOS_AGENTINSTRUMENT, sInstrument);
			m_ctiAgent.SetValue(CTIOS_PERIPHERALID, Integer.parseInt( sPeripheralID ) );
			m_ctiAgent.SetValue(CTIOS_AUTOLOGIN, 1 );
	
			AddLogMessage("Calling Session->SetAgent");

			// perform SetAgent
			m_ctiSession.SetAgent( m_ctiAgent );
	
			// In order to perform the actual login you must wait for
			// the OnSetAgentMode() event.  So the real Login is peformed
			// in the OnSetAgentMode event handler (EventSink.java)
		}
		else
		{
			AddLogMessage("m_btnLogin_MouseClicked Failed to create agent object");
			SetLoginInProgress(false);
		}
	
	} // m_btnLogin_MouseClicked

	///////////////////////////////////////////////////////////////////////////
    /**
     * Convenience method to simplify some of our button handlers below
     */
	///////////////////////////////////////////////////////////////////////////
	boolean CheckAgentState()
	{
	    // Check to see if we are already connected
	    if ( !IsSessionConnected() )
	    {
		    AddLogMessage("Must be connected first!");
		    return false;
	    }

	    // Check to see if we are already logged in
		if (m_ctiAgent == null)
		{
		    AddLogMessage("No current Agent");
		    return false;
		}

	    int iCurrentState = m_ctiAgent.GetAgentState();
	    if ( iCurrentState == eUnknown || iCurrentState == eLogout )
	    {
		    AddLogMessage("Must login first!");
		    return false;
	    }

		// If we got here, we're good to go
		return true;

	} // CheckAgentState

	///////////////////////////////////////////////////////////////////////////
    /**
     * Logout button was clicked
     */
	///////////////////////////////////////////////////////////////////////////
	void m_btnLogout_MouseClicked(java.awt.event.MouseEvent event)
	{
		// Make sure session is open, agent logged in, etc.
		if ( !CheckAgentState() )
		    return;

	    AddLogMessage("Requesting Logout");

	    // No arguments required, just use an empty Arguments object
	    m_ctiAgent.Logout( new Arguments() );

	} // m_btnLogout_MouseClicked

	///////////////////////////////////////////////////////////////////////////
    /**
     * Ready button was clicked
     */
	///////////////////////////////////////////////////////////////////////////
	void m_btnReady_MouseClicked(java.awt.event.MouseEvent event)
	{
		// Make sure session is open, agent logged in, etc.
		if ( !CheckAgentState() )
		    return;

	    // create and add arguments
	    Arguments rReqArgs = new Arguments();

		// Set the necessary parameters.  Reason code is not always
		// required.  It depends on the ACD and the Agent's desk
		// settings.  We'll throw it in so we don't get errors
		// in the sample
	    rReqArgs.SetValue(CTIOS_AGENTSTATE, eAvailable);
	    rReqArgs.SetValue(CTIOS_EVENTREASONCODE, "1234");

		// Set the Agent's new state
	    m_ctiAgent.SetAgentState(rReqArgs);

	    AddLogMessage("Requesting Agent State = Ready");
	}

	///////////////////////////////////////////////////////////////////////////
    /**
     * NotReady button was clicked
     */
	///////////////////////////////////////////////////////////////////////////
	void m_btnNotReady_MouseClicked(java.awt.event.MouseEvent event)
	{
		// Make sure session is open, agent logged in, etc.
		if ( !CheckAgentState() )
		    return;

	    // create and add arguments
	    Arguments rReqArgs = new Arguments();

		// Set the necessary parameters.  Reason code is not always
		// required.  It depends on the ACD and the Agent's desk
		// settings.  We'll throw it in so we don't get errors
		// in the sample
	    rReqArgs.SetValue(CTIOS_AGENTSTATE, eNotReady);
	    rReqArgs.SetValue(CTIOS_EVENTREASONCODE, "1234");

		// Set the Agent's new state
	    m_ctiAgent.SetAgentState(rReqArgs);

	    AddLogMessage("Requesting Agent State = NotReady");

	} // m_btnNotReady_MouseClicked

	///////////////////////////////////////////////////////////////////////////
    /**
     * MakeCall button was clicked
     */
	///////////////////////////////////////////////////////////////////////////
	void m_btnMakeCall_MouseClicked(java.awt.event.MouseEvent event)
	{
		// Make sure session is open, agent logged in, etc.
		if ( !CheckAgentState() )
		    return;

	    // Get phone number and call variable (if present)
	    String dn = m_edtPhoneNumber.getText();
	    String cv = m_edtCallVariable1.getText();

	    if (dn.compareTo("") == 0)
	    {
		    AddLogMessage("Must provide phone number to dial!");
		    return;
	    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -