package com.ts3client.ui; import com.ts3client.audio.AudioDevice; import javax.swing.JComboBox; import java.util.List; /** The device pickers of the Playback and Capture pages. */ final class AudioDevices { private static final String HINT = "Named devices are PipeWire's, and are routed through it " + "(so per-application volume and rerouting keep working).
" + "ALSA: entries talk to the sound card directly, taking it exclusively."; private AudioDevices() { } /** A picker over {@code devices} with {@code selectedId} chosen, or the first (default) one. */ static JComboBox combo(List devices, String selectedId) { JComboBox combo = new JComboBox<>(devices.toArray(new AudioDevice[0])); combo.setToolTipText(HINT); if (combo.getItemCount() == 0) return combo; combo.setSelectedIndex(0); if (selectedId != null && !selectedId.isEmpty()) { for (int i = 0; i < combo.getItemCount(); i++) { if (selectedId.equals(combo.getItemAt(i).id())) { combo.setSelectedIndex(i); break; } } } return combo; } static String selectedId(JComboBox combo) { AudioDevice d = (AudioDevice) combo.getSelectedItem(); return d == null ? "" : d.id(); } }