FileDocCategorySizeDatePackage
CaptureDialog.javaAPI DocJMF 2.1.1e17537Mon May 12 12:20:32 BST 2003jmapps.jmstudio

CaptureDialog

public class CaptureDialog extends JMDialog implements ItemListener

Fields Summary
private JMAppsCfg
cfgJMApps
private Vector
vectorDevices
private Vector
vectorAudioDevices
private Vector
vectorVideoDevices
private Panel
panelDevices
private Checkbox
checkUseVideo
private Checkbox
checkUseAudio
private Choice
comboVideoDevice
private Choice
comboAudioDevice
private Panel
panelVideoFormat
private Panel
panelAudioFormat
private AudioFormatChooser
chooserAudio
private VideoFormatChooser
chooserVideo
private Button
buttonOK
private Button
buttonCancel
Constructors Summary
public CaptureDialog(Frame parentFrame, JMAppsCfg cfgJMApps)



            
        super ( parentFrame, JMFI18N.getResource("jmstudio.capture.title"), true );

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

        int                  nIndex;
        String               strCmd;
        CaptureDeviceInfo    infoCaptureDevice;


        strCmd = event.getActionCommand ();
        if ( strCmd.equals(ACTION_OK) ) {
            this.setAction ( ACTION_OK );
            saveCfgData ();
        }
        else {
            this.setAction ( ACTION_CANCEL );
        }

        dispose();
    
private voidcreateAudioChooser(javax.media.format.AudioFormat formatDefault)

        int                     i;
        CaptureDeviceInfo       infoCaptureDevice;
        Format                  arrFormats [];

        if ( panelAudioFormat == null )
            return;

        panelAudioFormat.removeAll ();

        i = comboAudioDevice.getSelectedIndex ();
        infoCaptureDevice = (CaptureDeviceInfo) vectorAudioDevices.elementAt ( i );
        arrFormats = infoCaptureDevice.getFormats ();
        chooserAudio = new AudioFormatChooser ( arrFormats, formatDefault, false, null );
        panelAudioFormat.add ( chooserAudio, BorderLayout.CENTER );
    
private java.awt.PanelcreateAudioPanel()

        int                 i, j;
        int                 nCount;
        JMPanel             panelAudio;
        JMPanel             panelContent;
        Panel               panel;
        Panel               panelTemp;
        CaptureDeviceInfo   infoCaptureDevice;
        Format              arrFormats [];
        boolean             boolState = true;
        AudioFormat         formatDefault = null;
        String              strDeviceName;
        boolean             boolContains;
        JMAppsCfg.CaptureDeviceData   dataCapture = null;


        nCount = vectorDevices.size ();
        vectorAudioDevices = new Vector ();
        for ( i = 0;  i < nCount;  i++ ) {
            infoCaptureDevice = (CaptureDeviceInfo) vectorDevices.elementAt ( i );
            arrFormats = infoCaptureDevice.getFormats ();
            for ( j = 0;  j < arrFormats.length;  j++ ) {
                if ( arrFormats[j] instanceof AudioFormat ) {
                    vectorAudioDevices.addElement ( infoCaptureDevice );
                    break;
                }
            }
        }

        if ( vectorAudioDevices.isEmpty() )
            return ( null );

        if ( cfgJMApps != null )
            dataCapture = cfgJMApps.getLastCaptureAudioData();
        if ( dataCapture!= null ) {
            boolState = dataCapture.boolUse;
            if ( dataCapture.format instanceof AudioFormat )
                formatDefault = (AudioFormat) dataCapture.format;
        }

        panelAudio = new JMPanel ( new BorderLayout(6,6) );
        panelAudio.setEtchedBorder ();

        panelContent = new JMPanel ( new BorderLayout(6,6) );
        panelContent.setEmptyBorder ( 6, 6, 6, 6 );
        panelAudio.add ( panelContent, BorderLayout.CENTER );
        panel = panelContent;

        panelTemp = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelTemp, BorderLayout.NORTH );
        checkUseAudio = new Checkbox ( JMFI18N.getResource("jmstudio.capture.audio.usedevice"), boolState );
        checkUseAudio.addItemListener ( this );
        panelTemp.add ( checkUseAudio, BorderLayout.WEST );
        panelTemp = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelTemp, BorderLayout.CENTER );
        panel = panelTemp;

        panelTemp = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelTemp, BorderLayout.NORTH );
        comboAudioDevice = new Choice ();
        panelTemp.add ( comboAudioDevice, BorderLayout.CENTER );
        nCount = vectorAudioDevices.size ();
        boolContains = false;
        for ( i = 0;  i < nCount;  i++ ) {
            infoCaptureDevice = (CaptureDeviceInfo) vectorAudioDevices.elementAt ( i );
            strDeviceName = infoCaptureDevice.getName ();
            comboAudioDevice.addItem ( strDeviceName );
            if ( boolContains == false  &&  dataCapture!= null
                                &&  dataCapture.strDeviceName != null ) {
                boolContains = dataCapture.strDeviceName.equals ( strDeviceName );
            }
        }
        if ( boolContains == true )
            comboAudioDevice.select ( dataCapture.strDeviceName );
        comboAudioDevice.addItemListener ( this );
        comboAudioDevice.setEnabled ( boolState );

        panelAudioFormat = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelAudioFormat, BorderLayout.CENTER );
        createAudioChooser ( formatDefault );
        if ( chooserAudio != null )
            chooserAudio.setEnabled ( boolState );

        return ( panelAudio );
    
public javax.media.protocol.DataSourcecreateCaptureDataSource()

        DataSource          dataSource = null;
        String              audioDeviceName = null;
        String              videoDeviceName = null;
        CaptureDeviceInfo   cdi;

        cdi = getAudioDevice();
        if (cdi != null && isAudioDeviceUsed())
            audioDeviceName = cdi.getName();
        cdi = getVideoDevice();
        if (cdi != null && isVideoDeviceUsed())
            videoDeviceName = cdi.getName();
        dataSource = JMFUtils.createCaptureDataSource(audioDeviceName,
						      getAudioFormat(),
						      videoDeviceName,
						      getVideoFormat());

        return ( dataSource );
    
private voidcreateVideoChooser(javax.media.format.VideoFormat formatDefault)

        int                     i;
        CaptureDeviceInfo       infoCaptureDevice;
        Format                  arrFormats [];

        if ( panelVideoFormat == null )
            return;

        panelVideoFormat.removeAll ();

        i = comboVideoDevice.getSelectedIndex ();
        infoCaptureDevice = (CaptureDeviceInfo) vectorVideoDevices.elementAt ( i );
        arrFormats = infoCaptureDevice.getFormats ();
        chooserVideo = new VideoFormatChooser ( arrFormats, formatDefault, false, null, true);
        panelVideoFormat.add ( chooserVideo, BorderLayout.CENTER );
    
private java.awt.PanelcreateVideoPanel()

        int                 i, j;
        int                 nCount;
        JMPanel             panelVideo;
        JMPanel             panelContent;
        Panel               panel;
        Panel               panelTemp;
        CaptureDeviceInfo   infoCaptureDevice;
        Format              arrFormats [];
        boolean             boolState = true;
        VideoFormat         formatDefault = null;
        String              strDeviceName;
        boolean             boolContains;
        JMAppsCfg.CaptureDeviceData   dataCapture = null;


        nCount = vectorDevices.size ();
        vectorVideoDevices = new Vector ();
        for ( i = 0;  i < nCount;  i++ ) {
            infoCaptureDevice = (CaptureDeviceInfo) vectorDevices.elementAt ( i );
            arrFormats = infoCaptureDevice.getFormats ();
            for ( j = 0;  j < arrFormats.length;  j++ ) {
                if ( arrFormats[j] instanceof VideoFormat ) {
                    vectorVideoDevices.addElement ( infoCaptureDevice );
                    break;
                }
            }
        }

        if ( vectorVideoDevices.isEmpty() )
            return ( null );

        if ( cfgJMApps != null )
            dataCapture = cfgJMApps.getLastCaptureVideoData();
        if ( dataCapture!= null ) {
            boolState = dataCapture.boolUse;
            if ( dataCapture.format instanceof VideoFormat )
                formatDefault = (VideoFormat) dataCapture.format;
        }
        panelVideo = new JMPanel ( new BorderLayout(6,6) );
        panelVideo.setEtchedBorder ();

        panelContent = new JMPanel ( new BorderLayout(6,6) );
        panelContent.setEmptyBorder ( 6, 6, 6, 6 );
        panelVideo.add ( panelContent, BorderLayout.CENTER );
        panel = panelContent;

        panelTemp = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelTemp, BorderLayout.NORTH );
        checkUseVideo = new Checkbox ( JMFI18N.getResource("jmstudio.capture.video.usedevice"), boolState );
        checkUseVideo.addItemListener ( this );
        panelTemp.add ( checkUseVideo, BorderLayout.WEST );
        panelTemp = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelTemp, BorderLayout.CENTER );
        panel = panelTemp;

        panelTemp = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelTemp, BorderLayout.NORTH );
        comboVideoDevice = new Choice ();
        panelTemp.add ( comboVideoDevice, BorderLayout.CENTER );
        nCount = vectorVideoDevices.size ();
        boolContains = false;
        for ( i = 0;  i < nCount;  i++ ) {
            infoCaptureDevice = (CaptureDeviceInfo) vectorVideoDevices.elementAt ( i );
            strDeviceName = infoCaptureDevice.getName ();
            comboVideoDevice.addItem ( strDeviceName );
            if ( boolContains == false  &&  dataCapture!= null
                                &&  dataCapture.strDeviceName != null ) {
                boolContains = dataCapture.strDeviceName.equals ( strDeviceName );
            }
        }
        if ( boolContains == true )
            comboVideoDevice.select ( dataCapture.strDeviceName );
        comboVideoDevice.addItemListener ( this );
        comboVideoDevice.setEnabled ( boolState );

        panelVideoFormat = new Panel ( new BorderLayout(6,6) );
        panel.add ( panelVideoFormat, BorderLayout.CENTER );
        createVideoChooser ( formatDefault);
        if ( chooserVideo != null )
            chooserVideo.setEnabled ( boolState );

        return ( panelVideo );
    
public javax.media.CaptureDeviceInfogetAudioDevice()

        int                     i;
        CaptureDeviceInfo       infoCaptureDevice = null;

        if ( comboAudioDevice != null  &&  isAudioDeviceUsed() ) {
            i = comboAudioDevice.getSelectedIndex ();
            infoCaptureDevice = (CaptureDeviceInfo) vectorAudioDevices.elementAt ( i );
        }
        return ( infoCaptureDevice );
    
public javax.media.format.AudioFormatgetAudioFormat()

        AudioFormat    format = null;

        if ( chooserAudio != null  &&  isAudioDeviceUsed() )
            format = (AudioFormat) chooserAudio.getFormat ();
        return ( format );
    
public javax.media.CaptureDeviceInfogetVideoDevice()

        int                     i;
        CaptureDeviceInfo       infoCaptureDevice = null;

        if ( comboVideoDevice != null  &&  isVideoDeviceUsed() ) {
            i = comboVideoDevice.getSelectedIndex ();
            infoCaptureDevice = (CaptureDeviceInfo) vectorVideoDevices.elementAt ( i );
        }
        return ( infoCaptureDevice );
    
public javax.media.format.VideoFormatgetVideoFormat()

        VideoFormat    format = null;

        if ( chooserVideo != null  &&  isVideoDeviceUsed() )
            format = (VideoFormat) chooserVideo.getFormat ();
        return ( format );
    
private voidinit()

        Panel       panel;
        Panel       panelButtons;
        JMPanel     panelContent;
        Label       label;


        this.setLayout ( new BorderLayout() );

        panelContent = new JMPanel ( new BorderLayout() );
        panelContent.setEmptyBorder ( 6, 6, 6, 6 );
        panelContent.setBackground ( Color.lightGray );
        this.add ( panelContent, BorderLayout.CENTER );

        vectorDevices = CaptureDeviceManager.getDeviceList ( null );
        if ( vectorDevices == null  ||  vectorDevices.size() < 1 ) {
            label = new Label ( JMFI18N.getResource("jmstudio.capture.nodevices") );
            panelContent.add ( label, BorderLayout.CENTER );
        }
        else {
            panelDevices = new Panel ( new GridLayout(1,0,6,6) );
            panelContent.add ( panelDevices, BorderLayout.CENTER );

            panel = createVideoPanel ();
            if ( panel != null )
                panelDevices.add ( panel );
            panel = createAudioPanel ();
            if ( panel != null )
                panelDevices.add ( panel );
        }

        panel = new JMPanel ( new FlowLayout(FlowLayout.CENTER) );
        panelContent.add ( panel, BorderLayout.SOUTH );
        if ( vectorDevices != null  &&  vectorDevices.size() > 0 )
            panelButtons = createButtonPanel ( new String[] { ACTION_OK, ACTION_CANCEL } );
        else
            panelButtons = createButtonPanel ( new String[] { ACTION_OK } );
        panel.add ( panelButtons );

        this.pack ();
        this.setResizable ( false );
    
public booleanisAudioDeviceUsed()

        boolean         boolUsed = false;

        if ( checkUseAudio != null )
            boolUsed = checkUseAudio.getState ();
        return ( boolUsed );
    
public booleanisVideoDeviceUsed()

        boolean         boolUsed = false;

        if ( checkUseVideo != null )
            boolUsed = checkUseVideo.getState ();
        return ( boolUsed );
    
public voiditemStateChanged(java.awt.event.ItemEvent event)

        Object          objectSource;
        boolean         boolEnable;

        objectSource = event.getSource ();

        if ( objectSource == checkUseVideo ) {
            boolEnable = checkUseVideo.getState ();
            comboVideoDevice.setEnabled ( boolEnable );
            chooserVideo.setEnabled ( boolEnable );
        }
        else if ( objectSource == checkUseAudio ) {
            boolEnable = checkUseAudio.getState ();
            comboAudioDevice.setEnabled ( boolEnable );
            chooserAudio.setEnabled ( boolEnable );
        }
        else if ( objectSource == comboVideoDevice ) {
            createVideoChooser ( null );
            validate ();
        }
        else if ( objectSource == comboAudioDevice ) {
            createAudioChooser ( null );
            validate ();
        }
    
private voidsaveCfgData()

        CaptureDeviceInfo               cdi;
        JMAppsCfg.CaptureDeviceData   dataCapture;

        if ( cfgJMApps == null )
            return;

        // audio
        dataCapture = cfgJMApps.createCaptureDeviceDataObject ();
        dataCapture.boolUse = isAudioDeviceUsed ();
        if ( comboAudioDevice != null )
            dataCapture.strDeviceName = comboAudioDevice.getSelectedItem ();
        if ( chooserAudio != null )
            dataCapture.format = chooserAudio.getFormat ();
        cfgJMApps.setLastCaptureAudioData ( dataCapture );

        // video
        dataCapture = cfgJMApps.createCaptureDeviceDataObject ();
        dataCapture.boolUse = isVideoDeviceUsed ();
        if ( comboVideoDevice != null )
            dataCapture.strDeviceName = comboVideoDevice.getSelectedItem ();
        if ( chooserVideo != null )
            dataCapture.format =  chooserVideo.getFormat ();
        cfgJMApps.setLastCaptureVideoData ( dataCapture );
    
public java.lang.StringtoString()

        String                  strValue = "";
        CaptureDeviceInfo       cdiAudio;
        CaptureDeviceInfo       cdiVideo;
    	MediaLocator            deviceURL;

        cdiAudio = getAudioDevice();
        if ( cdiAudio != null  &&  isAudioDeviceUsed() ) {
            deviceURL = cdiAudio.getLocator ();
            if ( strValue.length() > 0 )
                strValue = strValue + " & ";
            strValue = strValue + deviceURL.toString ();
        }

        cdiVideo = getVideoDevice ();
        if ( cdiVideo != null  &&  isVideoDeviceUsed() ) {
            deviceURL = cdiVideo.getLocator ();
            if ( strValue.length() > 0 )
                strValue = strValue + " & ";
            strValue = strValue + deviceURL.toString ();
        }

        return ( strValue );
    
public voidwindowClosing(java.awt.event.WindowEvent event)

        this.setAction ( ACTION_CANCEL );
        this.dispose ();