deviceLabel.setDisplayedMnemonic(getDisplayedMnemonic(type));
deviceLabel.setLabelFor(deviceComboBox);
final Container devicePanel
= new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
devicePanel.setMaximumSize(new Dimension(WIDTH, 25));
final boolean isAudioSystemComboDisabled
= (type == DeviceConfigurationComboBoxModel.AUDIO)
&& NeomediaActivator.getConfigurationService().getBoolean(
AUDIO_SYSTEM_DISABLED_PROP,
false);
// For audio configuration form first check if the audio system
// property is disabled.
if (!isAudioSystemComboDisabled)
{
devicePanel.add(deviceLabel);
devicePanel.add(deviceComboBox);
}
final JPanel deviceAndPreviewPanel
= new TransparentPanel(new BorderLayout());
int preferredDeviceAndPreviewPanelHeight;
switch (type)
{
case DeviceConfigurationComboBoxModel.AUDIO:
preferredDeviceAndPreviewPanelHeight
= isAudioSystemComboDisabled ? 180 : 225;
break;
case DeviceConfigurationComboBoxModel.VIDEO:
preferredDeviceAndPreviewPanelHeight = 305;
break;
default:
preferredDeviceAndPreviewPanelHeight = 0;
break;
}
if (preferredDeviceAndPreviewPanelHeight > 0)
{
deviceAndPreviewPanel.setPreferredSize(
new Dimension(WIDTH, preferredDeviceAndPreviewPanelHeight));
}
deviceAndPreviewPanel.add(devicePanel, BorderLayout.NORTH);
// For audio configuration if the audio system combo is disabled we're
// going to look directly in the device configuration and show the
// preview panel, which in this case contains audio configuration
// components.
if (isAudioSystemComboDisabled)
{
Component preview = null;
if (mediaService.getDeviceConfiguration().getAudioSystem() != null)
{
preview = createPreview(type, deviceComboBox,
deviceAndPreviewPanel.getPreferredSize());
}
if (preview != null)
{
deviceAndPreviewPanel.add(preview, BorderLayout.CENTER);
}
}
final ActionListener deviceComboBoxActionListener
= new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
boolean revalidateAndRepaint = false;
for (int i = deviceAndPreviewPanel.getComponentCount() - 1;
i >= 0;
i--)
{
Component c = deviceAndPreviewPanel.getComponent(i);
if (c != devicePanel)
{
deviceAndPreviewPanel.remove(i);
revalidateAndRepaint = true;
}
}
Component preview = null;
if ((deviceComboBox.getSelectedItem() != null)
&& (deviceComboBox.isShowing()
|| isAudioSystemComboDisabled))
{
preview
= createPreview(
type,
deviceComboBox,
deviceAndPreviewPanel.getPreferredSize());
}
if (preview != null)
{
deviceAndPreviewPanel.add(preview, BorderLayout.CENTER);
revalidateAndRepaint = true;
}
if (revalidateAndRepaint)
{
deviceAndPreviewPanel.revalidate();
deviceAndPreviewPanel.repaint();
}
}
};
deviceComboBox.addActionListener(deviceComboBoxActionListener);