FileDocCategorySizeDatePackage
PanelParticipants.javaAPI DocJMF 2.1.1e25306Mon May 12 12:20:32 BST 2003jmapps.rtp

PanelParticipants

public class PanelParticipants extends JMPanel implements ComponentListener, ActionListener, ReceiveStreamListener, SessionListener, RemoteListener

Fields Summary
private SessionManager
mngrSession
private TreeControl
controlTree
private JMPanel
panelView
private CardLayout
layoutView
private JMPanel
panelCurrentView
private static final int
MARGINH
public static final String
PARTICIPANTS
public static final String
REMOTE_RECEIVE_STREAM
public static final String
UNKNOWN_STREAM
public static final String
REPORT
public static final String
LATEST_SENDER_REPORT
public static final String
REPORT_BLOCK
public static final String
REPORT_BLOCK_BY_ME
public static final String
SENDER_REPORT_BLOCK
Constructors Summary
public PanelParticipants(SessionManager mngrSession)



          
	    super ();

        this.mngrSession = mngrSession;
        try {
            init();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

        Object      objSource;
        String      strAction;

        objSource = event.getSource ();
        if ( objSource == null  ||  !(objSource instanceof TreeNode) )
            return;

        strAction = event.getActionCommand ();
        if ( strAction.equals(TreeNode.ACTION_NODE_ADDED) ) {
        }
        else if ( strAction.equals(TreeNode.ACTION_NODE_REMOVED) ) {
            removeViewPanel ( (TreeNode)objSource );
        }
        else if ( strAction.equals(TreeNode.ACTION_NODE_EXPANDED) ) {
        }
        else if ( strAction.equals(TreeNode.ACTION_NODE_COLLAPSED) ) {
        }
        else if ( strAction.equals(TreeNode.ACTION_NODE_SETCURRENT) ) {
            setViewPanel ( (TreeNode)objSource );
        }
        else if ( strAction.equals(TreeNode.ACTION_NODE_RESETCURRENT) ) {
        }
    
private voidaddParticipant(javax.media.rtp.Participant participant)

        TreeNode    nodeParent;
        TreeNode    node;
        String      strName;
        JMPanel     panel;
        Object      objPanel;

        if ( participant == null )
            return;

        nodeParent = findParticipantListNode ();
        node = findParticipantNode ( participant );
        if ( node != null )
            // is there already
            return;

        strName = participant.getCNAME ();
        node = controlTree.createSubElement ( nodeParent, strName );
        panel = new ViewParticipantInfo ( mngrSession, participant );
        node.setUserData ( panel );
        fillParticipantInfoNode ( node, participant );
        node.addActionListener ( this );

        objPanel = nodeParent.getUserData();
        if ( objPanel != null  &&  (objPanel instanceof ViewParticipantList) )
            ((ViewParticipantList)objPanel).updateFields ();
    
private voidaddReport(javax.media.rtp.Participant participant, javax.media.rtp.rtcp.Report report)

        TreeNode    nodeParticipant;

        if ( participant == null )
            return;
        nodeParticipant = findParticipantNode ( participant );
        addReport ( nodeParticipant, report );
    
private voidaddReport(jmapps.ui.TreeNode nodeParticipant, javax.media.rtp.rtcp.Report report)

        String      strName;
        TreeNode    node;
        Object      objPanel;

        if ( nodeParticipant == null )
            return;
        strName = createReportNodeName ( report );
        node = nodeParticipant.getSubElement(strName);
        if ( node != null ) {
            // just update the existing report
            objPanel = node.getUserData();
            if ( objPanel != null  ) {
                if ( objPanel instanceof ViewReceiverReport  &&  report instanceof ReceiverReport )
                    ((ViewReceiverReport)objPanel).updateFields ( (ReceiverReport)report );
                else if ( objPanel instanceof ViewSenderReport  &&  report instanceof SenderReport )
                    ((ViewSenderReport)objPanel).updateFields ( (SenderReport)report );
            }
            updateReportBlocks ( node, report );
        }
        else {
            // create new node
            node = controlTree.createSubElement ( nodeParticipant, strName );
            if ( report instanceof SenderReport ) {
                objPanel = new ViewSenderReport ( mngrSession, (SenderReport)report );
            }
            else if ( report instanceof ReceiverReport ) {
                objPanel = new ViewReceiverReport ( (ReceiverReport)report );
            }
            else {
                objPanel = null;
            }
            node.setUserData ( objPanel );
            fillReportInfoNode ( node, report );
            node.addActionListener ( this );

            objPanel = nodeParticipant.getUserData();
            if ( objPanel != null  &&  (objPanel instanceof ViewParticipantInfo) )
                ((ViewParticipantInfo)objPanel).updateFields ( report );
        }

        if ( report instanceof SenderReport ) {
            node = findStreamNode ( nodeParticipant, ((SenderReport)report).getStream() );
            if ( node != null )
                node = findStreamLatestReportNode ( node );
            if ( node != null ) {
                objPanel = node.getUserData();
                if ( objPanel != null  &&  (objPanel instanceof ViewSenderReport) )
                    ((ViewSenderReport)objPanel).updateFields ( (SenderReport)report );
                updateReportBlocks ( node, report );
            }
        }
    
private voidaddRtpStream(javax.media.rtp.Participant participant, javax.media.rtp.RTPStream stream)

        TreeNode    nodeParticipant;
        TreeNode    nodeStream;

        nodeParticipant = findParticipantNode ( participant );
        addRtpStream ( nodeParticipant, stream );
    
private voidaddRtpStream(jmapps.ui.TreeNode nodeParticipant, javax.media.rtp.RTPStream stream)

        TreeNode    nodeStream;
        String      strName;
        JMPanel     panel;

        if ( nodeParticipant == null )
            return;
        nodeStream = findStreamNode ( nodeParticipant, stream );
        if ( nodeStream != null )
            return;

        strName = createStreamNodeName ( stream );
        nodeStream = controlTree.createSubElement ( nodeParticipant, strName );
        panel = new ViewRtpStreamInfo ( mngrSession, stream );
        nodeStream.setUserData ( panel );
        fillStreamInfoNode ( nodeStream, stream );
        nodeStream.addActionListener ( this );
    
public voidcomponentHidden(java.awt.event.ComponentEvent event)

    
public voidcomponentMoved(java.awt.event.ComponentEvent event)

    
public voidcomponentResized(java.awt.event.ComponentEvent event)

        layoutComponents ();
    
public voidcomponentShown(java.awt.event.ComponentEvent event)

    
private java.lang.StringcreateReportNodeName(javax.media.rtp.rtcp.Report report)

        String      strName;
        long        lSSRC;

        lSSRC = report.getSSRC ();
        strName = REPORT + " " + Signed.UnsignedInt((int)lSSRC);
        return ( strName );
    
private java.lang.StringcreateStreamLatestReportNodeName()

        String      strName;

        strName = LATEST_SENDER_REPORT;
        return ( strName );
    
private java.lang.StringcreateStreamNodeName(javax.media.rtp.RTPStream stream)

        String      strName;

        if ( stream == null )
            return ( null );

        if ( stream instanceof ReceiveStream )
            strName = REMOTE_RECEIVE_STREAM + ": ";
        else
            strName = UNKNOWN_STREAM + ": ";
        strName = strName + stream.getParticipant().getCNAME ();
        return ( strName );
    
private voidfillParticipantInfoNode(jmapps.ui.TreeNode nodeParent, javax.media.rtp.Participant participant)

        int             i;
        int             nCount;
        TreeNode        node;
        Vector          vectorStreams;
        Object          objStream;
        Vector          vectorReports;
        Object          objReport;
        String          strName;
        long            lSSRC;
        JMPanel         panel;
        Object          objPanel;

        if ( participant == null )
            return;

        vectorStreams = participant.getStreams ();
        nCount = vectorStreams.size ();
        for ( i = 0;  i < nCount;  i++ ) {
            objStream = vectorStreams.elementAt ( i );
            if ( objStream == null  ||  !(objStream instanceof RTPStream) )
                continue;
            addRtpStream ( nodeParent, (RTPStream)objStream );
        }

        vectorReports = participant.getReports ();
        nCount = vectorReports.size ();
        for ( i = 0;  i < nCount;  i++ ) {
            objReport = vectorReports.elementAt ( i );
            if ( objReport == null  ||  !(objReport instanceof Report) )
                continue;
            addReport ( nodeParent, (Report)objReport );
        }
    
private voidfillParticipantsNode(jmapps.ui.TreeNode nodeParent)

        int         i;
        int         nCount;
        Vector      vectorParticipants;
        Vector      vector;
        Object      objParticipant;
        String      strName;
        TreeNode    node;
        JMPanel     panel;

        // get all participants into one vector
        vectorParticipants = mngrSession.getRemoteParticipants ();
        objParticipant = mngrSession.getLocalParticipant ();
        if ( !vectorParticipants.contains(objParticipant) )
            vectorParticipants.addElement ( objParticipant );
        vector = mngrSession.getActiveParticipants ();
        nCount = vector.size ();
        for ( i = 0;  i < nCount;  i++ ) {
            objParticipant = vector.elementAt ( i );
            if ( vectorParticipants.contains(objParticipant) )
                continue;
            vectorParticipants.addElement ( objParticipant );
        }
        vector = mngrSession.getPassiveParticipants ();
        nCount = vector.size ();
        for ( i = 0;  i < nCount;  i++ ) {
            objParticipant = vector.elementAt ( i );
            if ( vectorParticipants.contains(objParticipant) )
                continue;
            vectorParticipants.addElement ( objParticipant );
        }

        // now fill the tree with participants from collected vector
        nCount = vectorParticipants.size ();
        for ( i = 0;  i < nCount;  i++ ) {
            objParticipant = vectorParticipants.elementAt ( i );
            if ( objParticipant == null  ||  !(objParticipant instanceof Participant) )
                continue;

            strName = ((Participant)objParticipant).getCNAME ();
            node = controlTree.createSubElement ( nodeParent, strName );
            panel = new ViewParticipantInfo ( mngrSession, (Participant)objParticipant );
            node.setUserData ( panel );
            fillParticipantInfoNode ( node, (Participant)objParticipant );
            node.addActionListener ( this );
        }
    
private voidfillReportInfoNode(jmapps.ui.TreeNode nodeParent, javax.media.rtp.rtcp.Report objReport)

        updateReportBlocks ( nodeParent, objReport );
    
private voidfillStreamInfoNode(jmapps.ui.TreeNode nodeParent, javax.media.rtp.RTPStream streamRtp)

        SenderReport    reportSender;
        TreeNode        node;
        String          strName;
        JMPanel         panel;

        if ( streamRtp == null )
            return;

        reportSender = streamRtp.getSenderReport();
        if ( reportSender != null ) {
            strName = createStreamLatestReportNodeName ();
            node = controlTree.createSubElement ( nodeParent, strName );
            panel = new ViewSenderReport ( mngrSession, reportSender );
            node.setUserData ( panel );
            fillReportInfoNode ( node, reportSender );
            node.addActionListener ( this );
        }
    
private jmapps.ui.TreeNodefindParticipantListNode()

        TreeNode    nodeRoot;

        nodeRoot = controlTree.getRootElement ();
        return ( nodeRoot );
    
private jmapps.ui.TreeNodefindParticipantNode(javax.media.rtp.Participant participant)

        TreeNode    nodeRoot;
        TreeNode    node;

        nodeRoot = controlTree.getRootElement ();
        node = nodeRoot.getSubElement ( participant.getCNAME() );
        return ( node );
    
private jmapps.ui.TreeNodefindStreamLatestReportNode(jmapps.ui.TreeNode nodeStream)

        String      strName;
        TreeNode    node;

        strName = createStreamLatestReportNodeName ();
        node = nodeStream.getSubElement ( strName );
        return ( node );
    
private jmapps.ui.TreeNodefindStreamNode(jmapps.ui.TreeNode nodeParticipant, javax.media.rtp.RTPStream stream)

        TreeNode    node;
        String      strName;

        strName = createStreamNodeName ( stream );
        node = nodeParticipant.getSubElement ( strName );
        return ( node );
    
public java.awt.DimensiongetPreferredSize()

        Dimension   dim;

        dim = new Dimension ( 480, 360 );
        return ( dim );
    
private voidinit()

        TreeNode    nodeRoot;
        TreeNode    node;
        JMPanel     panel;

        this.addComponentListener ( this );
        this.setLayout ( null );

        controlTree = new TreeControl ();
        this.add ( controlTree );

        layoutView = new CardLayout ();
        panelView = new JMPanel ( layoutView );
        panelView.setEtchedBorder ();
        this.add ( panelView );

        nodeRoot = controlTree.createRootElement ( PARTICIPANTS );
        panel = new ViewParticipantList ( mngrSession );
        nodeRoot.setUserData ( panel );
        fillParticipantsNode ( nodeRoot );
        controlTree.setCurrentElement ( nodeRoot );
        nodeRoot.addActionListener ( this );
        this.setViewPanel ( nodeRoot );

        mngrSession.addSessionListener ( this );
        mngrSession.addReceiveStreamListener ( this );
        mngrSession.addRemoteListener ( this );
    
private voidlayoutComponents()

        Dimension   dim;
        int         nWidthTree;

        dim = this.getSize ();
        nWidthTree = (dim.width - MARGINH) / 2;
        if ( controlTree != null )
            controlTree.setBounds ( 0, 0, nWidthTree, dim.height );
        if ( panelView != null ) {
            panelView.setBounds ( nWidthTree + MARGINH, 0, dim.width - (nWidthTree + MARGINH), dim.height );
            panelView.doLayout ();
        }
        repaint ();
    
private voidremoveParticipant(javax.media.rtp.Participant participant)

        TreeNode    nodeParent;
        TreeNode    node;
        String      strName;
        JMPanel     panel;
        Object      objPanel;

        node = findParticipantNode ( participant );
        if ( node == null )
            return;

        nodeParent = findParticipantListNode ();
        controlTree.destroySubElement ( nodeParent, node );

        objPanel = nodeParent.getUserData();
        if ( objPanel != null  &&  (objPanel instanceof ViewParticipantList) )
            ((ViewParticipantList)objPanel).updateFields ();
    
private voidremoveRtpStream(javax.media.rtp.RTPStream stream)

        Participant participant;
        TreeNode    nodeParticipant;
        TreeNode    nodeStream;

        participant = stream.getParticipant();
        if ( participant == null )
            return;

        nodeParticipant = findParticipantNode ( participant );
        removeRtpStream ( nodeParticipant, stream );
    
private voidremoveRtpStream(jmapps.ui.TreeNode nodeParticipant, javax.media.rtp.RTPStream stream)

        TreeNode    nodeStream;

        if ( nodeParticipant == null )
            return;
        nodeStream = findStreamNode ( nodeParticipant, stream );
        if ( nodeStream == null )
            return;

        controlTree.destroySubElement ( nodeParticipant, nodeStream );
    
private voidremoveViewPanel(jmapps.ui.TreeNode node)

        Object      objData;
        String      strName;

        objData = node.getUserData ();
        if ( objData != null  &&  objData instanceof JMPanel ) {
            if ( ((JMPanel)objData).getParent() == panelView )
                panelView.remove ( (JMPanel)objData );
        }
        setViewPanel ( controlTree.getCurrentElement() );
    
private voidsetViewPanel(jmapps.ui.TreeNode node)

        Object      objData;
        String      strName;

        if ( node == null )
            return;

        objData = node.getUserData ();
        strName = node.getFullPathName ();
        if ( objData != null  &&  objData instanceof JMPanel ) {
            panelCurrentView = (JMPanel) objData;
            if ( panelCurrentView.getParent() == null )
                panelView.add ( panelCurrentView, strName );
            layoutView.show ( panelView, strName );
        }
    
public voidupdate(javax.media.rtp.event.SessionEvent event)

        Participant     participant;

        if ( event instanceof NewParticipantEvent ) {
            participant = ((NewParticipantEvent)event).getParticipant();
            addParticipant ( participant );
        }
    
public voidupdate(javax.media.rtp.event.RemoteEvent event)

        Participant     participant;
        ReceiverReport  reportReceiver;
        SenderReport    reportSender;
        TreeNode        node;
        Object          objPanel;

        if ( event instanceof ReceiverReportEvent ){
            participant = ((ReceiverReportEvent)event).getReport().getParticipant();
            if ( participant != null  &&  participant.getStreams().size() == 0 ) {
                node = findParticipantListNode ();
                if ( node != null ) {
                    objPanel = node.getUserData ();
                    if ( objPanel != null  &&  objPanel instanceof ViewParticipantList )
                        ((ViewParticipantList)objPanel).updateFields ();

                    reportReceiver = ((ReceiverReportEvent)event).getReport();
                    addReport ( participant, reportReceiver );
                }
            }
        }
        if ( event instanceof SenderReportEvent ) {
            participant = ((SenderReportEvent)event).getReport().getParticipant();
            if ( participant != null  &&  participant.getStreams().size() > 0 ) {
                node = findParticipantListNode ();
                if ( node != null ) {
                    objPanel = node.getUserData ();
                    if ( objPanel != null  &&  objPanel instanceof ViewParticipantList )
                        ((ViewParticipantList)objPanel).updateFields ();

                    reportSender = ((SenderReportEvent)event).getReport();
                    addReport ( participant, reportSender );
                }
            }
        }
    
public voidupdate(javax.media.rtp.event.ReceiveStreamEvent event)

        Participant     participant;
        ReceiveStream   stream;
        TreeNode        node;
        Object          objPanel;

        // if this is a timeOut or ByeEvent, we need to remove the
        // participants from the list of participants
        if ( event instanceof TimeoutEvent  ||  event instanceof ByeEvent ) {
            participant = null;
            stream = null;

            if ( event instanceof TimeoutEvent  &&  ((TimeoutEvent)event).participantLeaving() ) {
                participant = ((TimeoutEvent)event).getParticipant();
            }
            if ( event instanceof ByeEvent  &&  ((ByeEvent)event).participantLeaving() ) {
                participant = ((ByeEvent)event).getParticipant();
            }
            else if ( event instanceof TimeoutEvent ) {
                stream = ((TimeoutEvent)event).getReceiveStream();
            }
            else if ( event instanceof ByeEvent ) {
                stream = ((ByeEvent)event).getReceiveStream();
            }

            if ( participant != null ) {
                removeParticipant ( participant );
            }
            if ( stream != null ) {
                removeRtpStream ( stream );
            }
        }
        // if this is a NewReceiveStreamEvent, from an already existant
        // PASSVE paritcipant, we will need to remove the
        // Participant from the Passive list and add it to the
        // active list
        if ( event instanceof NewReceiveStreamEvent ) {
            stream = ((NewReceiveStreamEvent)event).getReceiveStream();
            participant = stream.getParticipant ();
            if ( participant == null )
                return;

            node = findParticipantNode ( participant );
            if ( node == null )
                addParticipant ( participant );
            addRtpStream ( participant, stream );

            node = this.findParticipantListNode ();
            objPanel = node.getUserData();
            if ( objPanel != null  &&  (objPanel instanceof ViewParticipantList) )
                ((ViewParticipantList)objPanel).updateFields ();

        }
        if ( event instanceof InactiveReceiveStreamEvent ) {
            // don't know what to do here
        }
        if ( event instanceof ActiveReceiveStreamEvent ) {
        }
    
private voidupdateReportBlocks(jmapps.ui.TreeNode nodeReport, javax.media.rtp.rtcp.Report report)

        int             i;
        int             nCount;
        SenderReport    reportSender;
        ReceiverReport  reportReceiver;
        Vector          vectorFeedbacks;
        Feedback        feedback;
        TreeNode        node;
        String          strName;
        JMPanel         panel;
        Object          objPanel;

        if ( report == null )
            return;

        if ( report instanceof SenderReport ) {
            reportSender = (SenderReport)report;

            feedback = reportSender.getSenderFeedback ();
            strName = REPORT_BLOCK_BY_ME;
            node = nodeReport.getSubElement ( strName );
            if ( node == null ) {
                node = controlTree.createSubElement ( nodeReport, strName );
                panel = new ViewReportBlock ( feedback );
                node.setUserData ( panel );
                node.addActionListener ( this );
            }
            else {
                objPanel = node.getUserData();
                if ( objPanel != null  &&  objPanel instanceof ViewReportBlock )
                    ((ViewReportBlock)objPanel).updateFields ( feedback );
            }


            vectorFeedbacks = reportSender.getFeedbackReports ();
            nCount = vectorFeedbacks.size ();
            for ( i = 0;  i < nCount;  i++ ) {
                feedback = (Feedback) vectorFeedbacks.elementAt ( i );
                strName = SENDER_REPORT_BLOCK + " " + i;
                node = nodeReport.getSubElement ( strName );
                if ( node == null ) {
                    node = controlTree.createSubElement ( nodeReport, strName );
                    panel = new ViewReportBlock ( feedback );
                    node.setUserData ( panel );
                    node.addActionListener ( this );
                }
                else {
                    objPanel = node.getUserData();
                    if ( objPanel != null  &&  objPanel instanceof ViewReportBlock )
                        ((ViewReportBlock)objPanel).updateFields ( feedback );
                }
            }
        }
        else if ( report instanceof ReceiverReport ) {
            reportReceiver = (ReceiverReport)report;
            vectorFeedbacks = reportReceiver.getFeedbackReports ();
            nCount = vectorFeedbacks.size ();
            for ( i = 0;  i < nCount;  i++ ) {
                feedback = (Feedback) vectorFeedbacks.elementAt ( i );
                strName = REPORT_BLOCK + " " + i;
                node = nodeReport.getSubElement ( strName );
                if ( node == null ) {
                    node = controlTree.createSubElement ( nodeReport, strName );
                    panel = new ViewReportBlock ( feedback );
                    node.setUserData ( panel );
                    node.addActionListener ( this );
                }
                else {
                    objPanel = node.getUserData();
                    if ( objPanel != null  &&  objPanel instanceof ViewReportBlock )
                        ((ViewReportBlock)objPanel).updateFields ( feedback );
                }
            }
        }