src/net/java/sip/communicator/impl/neomedia/MediaConfigurationImpl.java
/**
     * Initializes a new <tt>Component</tt> which.is to preview and/or allow
     * detailed configuration of an audio or video <tt>DeviceSystem</tt>.
     *
     * @param type either {@link DeviceConfigurationComboBoxModel#AUDIO} or
     * {@link DeviceConfigurationComboBoxModel#VIDEO}
     * @param comboBox the <tt>JComboBox</tt> which lists the available
     * alternatives and the selection which is to be previewed. May be
     * <tt>null</tt> in the case of audio in which case it is assumed that the
     * user is not allowed to set the <tt>AudioSystem</tt> to be used and the
     * selection is determined by the <tt>DeviceConfiguration</tt> of the
     * <tt>MediaService</tt>.
     * @param prefSize the preferred size to be applied to the preview
     * @return a new <tt>Component</tt> which is to preview and/or allow
     * detailed configuration of the <tt>DeviceSystem</tt> identified by
     * <tt>type</tt> and <tt>comboBox</tt>
     */
Initializes a new Component which.is to preview and/or allow
detailed configuration of an audio or video DeviceSystem.

@param type either  DeviceConfigurationComboBoxModel#AUDIO or
DeviceConfigurationComboBoxModel#VIDEO
@param comboBox the JComboBox which lists the available
alternatives and the selection which is to be previewed. May be
null in the case of audio in which case it is assumed that the
user is not allowed to set the AudioSystem to be used and the
selection is determined by the DeviceConfiguration of the
MediaService.
@param prefSize the preferred size to be applied to the preview
@return a new Component which is to preview and/or allow
detailed configuration of the DeviceSystem identified by
type and comboBox
Initializes a new Component which . is to preview and / or allow detailed configuration of an audio or video DeviceSystem . @param type either DeviceConfigurationComboBoxModel#AUDIO or DeviceConfigurationComboBoxModel#VIDEO @param comboBox the JComboBox which lists the available alternatives and the selection which is to be previewed . May be null in the case of audio in which case it is assumed that the user is not allowed to set the AudioSystem to be used and the selection is determined by the DeviceConfiguration of the MediaService . @param prefSize the preferred size to be applied to the preview @return a new Component which is to preview and / or allow detailed configuration of the DeviceSystem identified by type and comboBox
private Component createPreview(
            int type,
            DeviceComboBoxField comboBox,
            Dimension prefSize)
    {
        JComponent preview = null;
        if (type == DeviceConfigurationComboBoxModel.AUDIO)
        {
            AudioSystem audioSystem = null;
            /*
             * If the Audio System combo box is disabled (i.e. the user is not
             * allowed to set the AudioSystem to be used), the current
             * AudioSystem (specified by the DeviceConfiguration of the
             * MediaService) is to be configured.
             */
            if ((comboBox == null) || !comboBox.getComponent().isEnabled())
            {
                audioSystem
                    = mediaService.getDeviceConfiguration().getAudioSystem();
            }
            else
            {
                Object selectedItem = comboBox.getSelectedItem();
                if (selectedItem instanceof AudioSystem)
                {
                    audioSystem = (AudioSystem) selectedItem;
                    AudioSystem mediaServiceDeviceConfigurationAudioSystem
                        = mediaService
                            .getDeviceConfiguration()
                                .getAudioSystem();
                    if (audioSystem
                            != mediaServiceDeviceConfigurationAudioSystem)
                    {
                        logger.warn(
                                "JComboBox.selectedItem is not identical to"
                                    + " MediaService.deviceConfiguration.audioSystem!");
                    }
                }
            }
            if ((audioSystem != null)
                    && !NoneAudioSystem.LOCATOR_PROTOCOL.equalsIgnoreCase(
                            audioSystem.getLocatorProtocol()))
            {
                preview = new TransparentPanel(new GridBagLayout());
                createAudioSystemControls(audioSystem, preview);
            }
            else
            {
                /*
                 * If there are AudioSystems other than "None" and they have all
                 * not been reported as available, then each of them failed to
                 * detect any devices whatsoever.
                 */
                AudioSystem[] audioSystems = AudioSystem.getAudioSystems();
                if ((audioSystems != null) && (audioSystems.length != 1))
                {
                    AudioSystem[] availableAudioSystems
                        = mediaService
                            .getDeviceConfiguration()
                                .getAvailableAudioSystems();
                    if ((availableAudioSystems != null)
                            && (availableAudioSystems.length == 1))
                    {
                        String noAvailableAudioDevice
                            = NeomediaActivator.getResources().getI18NString(
                                "impl.media.configform.NO_AVAILABLE_AUDIO_DEVICE");
                        preview = new TransparentPanel(new GridBagLayout());
                        preview.add(new JLabel(noAvailableAudioDevice));
                    }
                }
            }
        }
        else if (type == DeviceConfigurationComboBoxModel.VIDEO)
        {
            JLabel noPreview
                = new JLabel(
                        NeomediaActivator.getResources().getI18NString(
                                "impl.media.configform.NO_PREVIEW"));
            noPreview.setHorizontalAlignment(SwingConstants.CENTER);
            noPreview.setVerticalAlignment(SwingConstants.CENTER);
            preview = createVideoContainer(noPreview);
            preview.setPreferredSize(prefSize);
            Object selectedItem = comboBox.getSelectedItem();
            CaptureDeviceInfo device = null;
            if (selectedItem
                    instanceof
                        DeviceConfigurationComboBoxModel.CaptureDevice)
                device
                    = ((DeviceConfigurationComboBoxModel.CaptureDevice)
                            selectedItem)
                        .info;
            Exception exception;
            try
            {
                createVideoPreview(device, preview);
                exception = null;
            }
            catch (IOException ex)
            {
                exception = ex;
            }
            catch (MediaException ex)
            {
                exception = ex;
            }
            if (exception != null)
            {
                logger.error(
                        "Failed to create preview for device " + device,
                        exception);
            }
        }
        return preview;
    }
private Component createPreview ( int type , DeviceComboBoxField comboBox , Dimension prefSize ) { JComponent preview = null ; if ( type == DeviceConfigurationComboBoxModel . AUDIO ) { AudioSystem audioSystem = null ; /*
             * If the Audio System combo box is disabled (i.e. the user is not
             * allowed to set the AudioSystem to be used), the current
             * AudioSystem (specified by the DeviceConfiguration of the
             * MediaService) is to be configured.
             */ if ( ( comboBox == null ) || ! comboBox . getComponent ( ) . isEnabled ( ) ) { audioSystem = mediaService . getDeviceConfiguration ( ) . getAudioSystem ( ) ; } else { Object selectedItem = comboBox . getSelectedItem ( ) ; if ( selectedItem instanceof AudioSystem ) { audioSystem = ( AudioSystem ) selectedItem ; AudioSystem mediaServiceDeviceConfigurationAudioSystem = mediaService . getDeviceConfiguration ( ) . getAudioSystem ( ) ; if ( audioSystem != mediaServiceDeviceConfigurationAudioSystem ) { logger . warn ( "JComboBox.selectedItem is not identical to" + " MediaService.deviceConfiguration.audioSystem!" ) ; } } } if ( ( audioSystem != null ) && ! NoneAudioSystem . LOCATOR_PROTOCOL . equalsIgnoreCase ( audioSystem . getLocatorProtocol ( ) ) ) { preview = new TransparentPanel ( new GridBagLayout ( ) ) ; createAudioSystemControls ( audioSystem , preview ) ; } else { /*
                 * If there are AudioSystems other than "None" and they have all
                 * not been reported as available, then each of them failed to
                 * detect any devices whatsoever.
                 */ AudioSystem [ ] audioSystems = AudioSystem . getAudioSystems ( ) ; if ( ( audioSystems != null ) && ( audioSystems . length != 1 ) ) { AudioSystem [ ] availableAudioSystems = mediaService . getDeviceConfiguration ( ) . getAvailableAudioSystems ( ) ; if ( ( availableAudioSystems != null ) && ( availableAudioSystems . length == 1 ) ) { String noAvailableAudioDevice = NeomediaActivator . getResources ( ) . getI18NString ( "impl.media.configform.NO_AVAILABLE_AUDIO_DEVICE" ) ; preview = new TransparentPanel ( new GridBagLayout ( ) ) ; preview . add ( new JLabel ( noAvailableAudioDevice ) ) ; } } } } else if ( type == DeviceConfigurationComboBoxModel . VIDEO ) { JLabel noPreview = new JLabel ( NeomediaActivator . getResources ( ) . getI18NString ( "impl.media.configform.NO_PREVIEW" ) ) ; noPreview . setHorizontalAlignment ( SwingConstants . CENTER ) ; noPreview . setVerticalAlignment ( SwingConstants . CENTER ) ; preview = createVideoContainer ( noPreview ) ; preview . setPreferredSize ( prefSize ) ; Object selectedItem = comboBox . getSelectedItem ( ) ; CaptureDeviceInfo device = null ; if ( selectedItem instanceof DeviceConfigurationComboBoxModel . CaptureDevice ) device = ( ( DeviceConfigurationComboBoxModel . CaptureDevice ) selectedItem ) . info ; Exception exception ; try { createVideoPreview ( device , preview ) ; exception = null ; } catch ( IOException ex ) { exception = ex ; } catch ( MediaException ex ) { exception = ex ; } if ( exception != null ) { logger . error ( "Failed to create preview for device " + device , exception ) ; } } return preview ; }
Initializes a new <tt>Component</tt> which.is to preview and/or allow
 detailed configuration of an audio or video <tt>DeviceSystem</tt>.
Initializes a new <tt > Component< / tt > which . is to preview and / or allow detailed configuration of an audio or video <tt > DeviceSystem< / tt > .