deviceLabel.setDisplayedMnemonic(getDisplayedMnemonic(type));
deviceLabel.setLabelFor(deviceComboBox);
final Container devicePanel
= new TransparentPanel(new FlowLayout(FlowLayout.CENTER));
devicePanel.setMaximumSize(new Dimension(WIDTH, 25));
devicePanel.add(deviceLabel);
devicePanel.add(deviceComboBox);
final JPanel deviceAndPreviewPanel
= new TransparentPanel(new BorderLayout());
int preferredDeviceAndPreviewPanelHeight;
switch (type)
{
case DeviceConfigurationComboBoxModel.AUDIO:
preferredDeviceAndPreviewPanelHeight = 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);
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())
{
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);