<commit_before>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.media;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.media.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

import net.java.sip.communicator.service.media.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.swing.*;
import net.java.sip.communicator.util.*;

import org.osgi.framework.*;

/**
 * @author <NAME>
 */
public class MediaConfigurationPanel
    extends TransparentPanel
{
    private static final int HGAP = 5;

    private static final int VGAP = 5;

    private static MediaServiceImpl getMediaService()
    {
        BundleContext bundleContext = MediaActivator.getBundleContext();
        ServiceReference serviceReference =
            bundleContext.getServiceReference(MediaService.class.getName());

        return (serviceReference == null) ? null
            : (MediaServiceImpl) bundleContext.getService(serviceReference);
    }

    private final Logger logger =
        Logger.getLogger(MediaConfigurationPanel.class);

    private final MediaServiceImpl mediaService = getMediaService();

    public MediaConfigurationPanel()
    {
        super(new GridLayout(0, 1, HGAP, VGAP));

        int[] types =
            new int[]
            { DeviceConfigurationComboBoxModel.AUDIO,
                DeviceConfigurationComboBoxModel.VIDEO };
        for (int i = 0; i < types.length; i++)
            add(createControls(types[i]));
    }

    private void controllerUpdateForPreview(ControllerEvent event,
        Container videoContainer)
    {
        if (event instanceof RealizeCompleteEvent)
        {
            Player player = (Player) event.getSourceController();
            Component video = player.getVisualComponent();

            showPreview(videoContainer, video, player);
        }
    }

    private Component createControls(int type)
    {
        final JComboBox comboBox = new JComboBox();
        comboBox.setEditable(false);

        JLabel label = new JLabel(getLabelText(type));
        label.setDisplayedMnemonic(getDisplayedMnemonic(type));
        label.setLabelFor(comboBox);

        final JComponent preview;
        ActionListener comboBoxListener = null;
        if (type == DeviceConfigurationComboBoxModel.VIDEO)
        {
            JLabel noPreview =
                new JLabel(MediaActivator.getResources().getI18NString(
                    "MediaConfigurationPanel_noPreview"));
            noPreview.setHorizontalAlignment(SwingConstants.CENTER);
            noPreview.setVerticalAlignment(SwingConstants.CENTER);

            preview = createVideoContainer(noPreview);
            Dimension previewSize = new Dimension(150, 150);
            preview.setMaximumSize(previewSize);
            preview.setMinimumSize(previewSize);
            preview.setPreferredSize(previewSize);

            comboBoxListener = new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    Object selection = comboBox.getSelectedItem();
                    CaptureDeviceInfo device = null;
                    if (selection instanceof DeviceConfigurationComboBoxModel.CaptureDevice)
                    {
                        device =
                            ((DeviceConfigurationComboBoxModel.CaptureDevice) selection).info;
                    }

                    createPreview(device, preview);
                }
            };
            comboBox.addActionListener(comboBoxListener);
        } else
            preview = null;

        Container deviceContainer = new TransparentPanel(new GridBagLayout());
        GridBagConstraints deviceConstraints = new GridBagConstraints();
        deviceConstraints.anchor = GridBagConstraints.NORTHWEST;
        deviceConstraints.gridx = 0;
        deviceConstraints.gridy = 0;
        deviceConstraints.weightx = 0;
        deviceContainer.add(label, deviceConstraints);
        deviceConstraints.gridx = 1;
        deviceConstraints.weightx = 1;
        deviceContainer.add(comboBox, deviceConstraints);
        if (preview != null)
        {
            deviceConstraints.gridx = 2;
            deviceConstraints.weightx = 0;
            deviceContainer.add(preview, deviceConstraints);
        }

        comboBox.setModel(new DeviceConfigurationComboBoxModel(mediaService
            .getDeviceConfiguration(), type));
        if (comboBoxListener != null)
            comboBoxListener.actionPerformed(null);

        Container container = new TransparentPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.weighty = 0;
        container.add(deviceContainer, constraints);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.gridy = 1;
        constraints.weighty = 1;
        container.add(createEncodingControls(type), constraints);
        return container;
    }

    private Component createEncodingControls(int type)
    {
        ResourceManagementService resources = MediaActivator.getResources();
        String key;

        final JTable table = new JTable();
        table.setFillsViewportHeight(true);
        table.setShowGrid(false);
        table.setTableHeader(null);
 
        key = "MediaConfigurationPanel_encodings";
        JLabel label = new JLabel(resources.getI18NString(key));
        label.setDisplayedMnemonic(resources.getI18nMnemonic(key));
        label.setLabelFor(table);

        key = "MediaConfigurationPanel_up";
        final JButton upButton = new JButton(resources.getI18NString(key));
        upButton.setMnemonic(resources.getI18nMnemonic(key));

        key = "MediaConfigurationPanel_down";
        final JButton downButton = new JButton(resources.getI18NString(key));
        downButton.setMnemonic(resources.getI18nMnemonic(key));

        Container buttonBar = new TransparentPanel(new GridLayout(0, 1));
        buttonBar.add(upButton);
        buttonBar.add(downButton);

        Container container = new TransparentPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.anchor = GridBagConstraints.NORTHWEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridwidth = 2;
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 0;
        constraints.weighty = 0;
        container.add(label, constraints);
        constraints.anchor = GridBagConstraints.CENTER;<commit_msg>Removes a use of JTable.setFillsViewportHeight because it requires Java 1.6.<commit_after>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.media;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.media.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

import net.java.sip.communicator.service.media.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.swing.*;
import net.java.sip.communicator.util.*;

import org.osgi.framework.*;

/**
 * @author <NAME>
 */
public class MediaConfigurationPanel
    extends TransparentPanel
{
    private static final int HGAP = 5;

    private static final int VGAP = 5;

    private static MediaServiceImpl getMediaService()
    {
        BundleContext bundleContext = MediaActivator.getBundleContext();
        ServiceReference serviceReference =
            bundleContext.getServiceReference(MediaService.class.getName());

        return (serviceReference == null) ? null
            : (MediaServiceImpl) bundleContext.getService(serviceReference);
    }

    private final Logger logger =
        Logger.getLogger(MediaConfigurationPanel.class);

    private final MediaServiceImpl mediaService = getMediaService();

    public MediaConfigurationPanel()
    {
        super(new GridLayout(0, 1, HGAP, VGAP));

        int[] types =
            new int[]
            { DeviceConfigurationComboBoxModel.AUDIO,
                DeviceConfigurationComboBoxModel.VIDEO };
        for (int i = 0; i < types.length; i++)
            add(createControls(types[i]));
    }

    private void controllerUpdateForPreview(ControllerEvent event,
        Container videoContainer)
    {
        if (event instanceof RealizeCompleteEvent)
        {
            Player player = (Player) event.getSourceController();
            Component video = player.getVisualComponent();

            showPreview(videoContainer, video, player);
        }
    }

    private Component createControls(int type)
    {
        final JComboBox comboBox = new JComboBox();
        comboBox.setEditable(false);

        JLabel label = new JLabel(getLabelText(type));
        label.setDisplayedMnemonic(getDisplayedMnemonic(type));
        label.setLabelFor(comboBox);

        final JComponent preview;
        ActionListener comboBoxListener = null;
        if (type == DeviceConfigurationComboBoxModel.VIDEO)
        {
            JLabel noPreview =
                new JLabel(MediaActivator.getResources().getI18NString(
                    "MediaConfigurationPanel_noPreview"));
            noPreview.setHorizontalAlignment(SwingConstants.CENTER);
            noPreview.setVerticalAlignment(SwingConstants.CENTER);

            preview = createVideoContainer(noPreview);
            Dimension previewSize = new Dimension(150, 150);
            preview.setMaximumSize(previewSize);
            preview.setMinimumSize(previewSize);
            preview.setPreferredSize(previewSize);

            comboBoxListener = new ActionListener()
            {
                public void actionPerformed(ActionEvent event)
                {
                    Object selection = comboBox.getSelectedItem();
                    CaptureDeviceInfo device = null;
                    if (selection instanceof DeviceConfigurationComboBoxModel.CaptureDevice)
                    {
                        device =
                            ((DeviceConfigurationComboBoxModel.CaptureDevice) selection).info;
                    }

                    createPreview(device, preview);
                }
            };
            comboBox.addActionListener(comboBoxListener);
        } else
            preview = null;

        Container deviceContainer = new TransparentPanel(new GridBagLayout());
        GridBagConstraints deviceConstraints = new GridBagConstraints();
        deviceConstraints.anchor = GridBagConstraints.NORTHWEST;
        deviceConstraints.gridx = 0;
        deviceConstraints.gridy = 0;
        deviceConstraints.weightx = 0;
        deviceContainer.add(label, deviceConstraints);
        deviceConstraints.gridx = 1;
        deviceConstraints.weightx = 1;
        deviceContainer.add(comboBox, deviceConstraints);
        if (preview != null)
        {
            deviceConstraints.gridx = 2;
            deviceConstraints.weightx = 0;
            deviceContainer.add(preview, deviceConstraints);
        }

        comboBox.setModel(new DeviceConfigurationComboBoxModel(mediaService
            .getDeviceConfiguration(), type));
        if (comboBoxListener != null)
            comboBoxListener.actionPerformed(null);

        Container container = new TransparentPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.weighty = 0;
        container.add(deviceContainer, constraints);
        constraints.fill = GridBagConstraints.BOTH;
        constraints.gridy = 1;
        constraints.weighty = 1;
        container.add(createEncodingControls(type), constraints);
        return container;
    }

    private Component createEncodingControls(int type)
    {
        ResourceManagementService resources = MediaActivator.getResources();
        String key;

        final JTable table = new JTable();
        table.setShowGrid(false);
        table.setTableHeader(null);
 
        key = "MediaConfigurationPanel_encodings";
        JLabel label = new JLabel(resources.getI18NString(key));
        label.setDisplayedMnemonic(resources.getI18nMnemonic(key));
        label.setLabelFor(table);

        key = "MediaConfigurationPanel_up";
        final JButton upButton = new JButton(resources.getI18NString(key));
        upButton.setMnemonic(resources.getI18nMnemonic(key));

        key = "MediaConfigurationPanel_down";
        final JButton downButton = new JButton(resources.getI18NString(key));
        downButton.setMnemonic(resources.getI18nMnemonic(key));

        Container buttonBar = new TransparentPanel(new GridLayout(0, 1));
        buttonBar.add(upButton);
        buttonBar.add(downButton);

        Container container = new TransparentPanel(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.anchor = GridBagConstraints.NORTHWEST;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.gridwidth = 2;
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 0;
        constraints.weighty = 0;
        container.add(label, constraints);
        constraints.anchor = GridBagConstraints.CENTER;
{'fraction_non_alphanumeric': 0.0856976997315144, 'fraction_numerical': 0.006675858065452435, 'mean_word_length': 2.589997395154988, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3836187', 'n_tokens_mistral': 3587, 'n_tokens_neox': 3398, 'n_words': 707}