package com.ts3client.ui; import com.ts3client.config.Settings; import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.SwingUtilities; import java.awt.Component; import java.awt.FlowLayout; import java.awt.GridBagConstraints; /** * Options page for the contact list: whether friends and blocked clients are * coloured in the server tree, whose whispers get through (TeamSpeak's whisper * options), and the defaults a new contact starts with. */ final class ContactsPanel extends FormPanel { private final Settings settings; private final JCheckBox colorContacts = new JCheckBox("Colour friends and blocked clients in the server tree"); private final JComboBox whisperPolicy = new JComboBox<>(Settings.WhisperPolicy.values()); ContactsPanel(Settings settings) { this.settings = settings; GridBagConstraints c = gbc(); colorContacts.setSelected(settings.colorContacts); colorContacts.setToolTipText("Friends in green and blocked clients in red, as the TeamSpeak client shows them"); whisperPolicy.setSelectedItem(settings.whisperPolicy); whisperPolicy.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focus) { super.getListCellRendererComponent(list, value, index, selected, focus); if (value instanceof Settings.WhisperPolicy) setText(((Settings.WhisperPolicy) value).label()); return this; } }); whisperPolicy.setToolTipText("Use individual settings in contacts, else allow: a client not on your " + "contact list may whisper to you.
Use individual settings in contacts, else deny: only " + "contacts marked \"Allow whisper\" may.
Nobody: individual contact settings are ignored."); JButton defaults = new JButton("Contact defaults…"); defaults.setToolTipText("Configure default settings when adding a client to the Contact Manager"); defaults.addActionListener(e -> { java.awt.Window owner = SwingUtilities.getWindowAncestor(this); new ContactDefaultsDialog(owner instanceof JDialog ? (JDialog) owner : null, settings).setVisible(true); }); JPanel defaultsRow = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); defaultsRow.add(defaults); int row = 0; addSection(this, c, row++, "Server Tree"); addWide(this, c, row++, colorContacts); addSection(this, c, row++, "Whispers"); addRow(this, c, row++, new JLabel("Allow whispers from:"), whisperPolicy); addSection(this, c, row++, "New Contacts"); addWide(this, c, row++, defaultsRow); addFiller(this, c, row); } /** Copies the page into the settings; the caller saves them. */ void apply() { settings.colorContacts = colorContacts.isSelected(); settings.whisperPolicy = (Settings.WhisperPolicy) whisperPolicy.getSelectedItem(); } }