Package org.asteriskjava.iax.ui

Source Code of org.asteriskjava.iax.ui.GuiEventSender

package org.asteriskjava.iax.ui;

import org.asteriskjava.iax.protocol.Call;
import org.asteriskjava.iax.protocol.Friend;
import org.asteriskjava.iax.protocol.ProtocolEventListener;

/**
* Decouples events from the main threads. This class it used by Friend.
*/

public class GuiEventSender implements ProtocolEventListener {

    private ProtocolEventListener _gui;
    private Call _call;

    /**
     * Constructor for the GuiEventSender object
     *
     * @param gui The protocol event listener
     */
    public GuiEventSender(ProtocolEventListener gui) {
        _gui = gui;
    }

    /**
     * Received a new call.
     * Via invokeLater() this is passed on to the ProtocolEventListener parameter.
     *
     * @param c The call object
     */
    public void newCall(Call c) {
        _call = c;
        Runnable r = new Runnable() {
            public void run() {
                if (_gui != null) {
                    _gui.newCall(_call);
                }
            }
        };
        javax.swing.SwingUtilities.invokeLater(r);
    }

    /**
     * Hung up.
     * Via invokeLater() this is passed on to the ProtocolEventListener parameter.
     *
     * @param c The call object
     */
    public void hungUp(Call c) {
        _call = c;
        Runnable r = new Runnable() {
            public void run() {
                if (_gui != null) {
                    _gui.hungUp(_call);
                }
            }
        };
        javax.swing.SwingUtilities.invokeLater(r);
    }

    /**
     * Ringing.
     * Via invokeLater() this is passed on to the ProtocolEventListener parameter.
     *
     * @param c The call object
     */
    public void ringing(Call c) {
        _call = c;
        Runnable r = new Runnable() {
            public void run() {
                if (_gui != null) {
                    _gui.ringing(_call);
                }
            }
        };
        javax.swing.SwingUtilities.invokeLater(r);
    }

    /**
     * Answered.
     * Via invokeLater() this is passed on to the ProtocolEventListener parameter.
     *
     * @param c The call object
     */
    public void answered(Call c) {
        _call = c;
        Runnable r = new Runnable() {
            public void run() {
                if (_gui != null) {
                    _gui.answered(_call);
                }
            }
        };
        javax.swing.SwingUtilities.invokeLater(r);
    }

    /**
     * registered
     *
     * @param f Friend
     * @param s boolean
     */
    public void registered(Friend f, boolean s) {
        final Friend ff = f;
        final boolean fs = s;
        Runnable r = new Runnable() {
            public void run() {
                if (_gui != null) {
                    _gui.registered(ff, fs);
                }
            }
        };
        javax.swing.SwingUtilities.invokeLater(r);
    }

    /**
     * setHostReachable
     *
     * @param f         Friend
     * @param b         boolean
     * @param roundtrip int
     */
    public void setHostReachable(Friend f, boolean b, int roundtrip) {
        final Friend ff = f;
        final boolean fb = b;
        final int fr = roundtrip;
        Runnable r = new Runnable() {
            public void run() {
                if (_gui != null) {
                    _gui.setHostReachable(ff, fb, fr);
                }
            }
        };
        javax.swing.SwingUtilities.invokeLater(r);

    }

}
TOP

Related Classes of org.asteriskjava.iax.ui.GuiEventSender

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.