package com.ts3client.ui; import com.ts3client.config.Settings; import javax.swing.BorderFactory; 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.BorderLayout; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; /** * 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 JPanel { 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) { super(new BorderLayout()); this.settings = settings; setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); JPanel p = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 2, 2); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridwidth = 2; c.gridy = 0; colorContacts.setSelected(settings.colorContacts); colorContacts.setToolTipText("Friends in green and blocked clients in red, as the TeamSpeak client shows them"); p.add(colorContacts, c); c.gridy = 1; c.insets = new Insets(12, 2, 2, 2); p.add(new JLabel("Whispers: who is allowed to whisper to you"), c); c.gridy = 2; c.insets = new Insets(2, 2, 2, 2); 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."); p.add(whisperPolicy, c); c.gridy = 3; c.insets = new Insets(12, 2, 2, 2); c.fill = GridBagConstraints.NONE; 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); }); p.add(defaults, c); add(p, BorderLayout.NORTH); } /** Copies the page into the settings; the caller saves them. */ void apply() { settings.colorContacts = colorContacts.isSelected(); settings.whisperPolicy = (Settings.WhisperPolicy) whisperPolicy.getSelectedItem(); } }