Added renderer to ContactsChooserDialog
This commit is contained in:
parent
ceb50cd01c
commit
930da62b79
@ -4,7 +4,10 @@ import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -126,30 +129,19 @@ public class ChatWindow extends JFrame {
|
||||
comp.setBackground(isSelected ? theme.getSelectionColor() : theme.getCellColor());
|
||||
|
||||
// ContextMenu
|
||||
Map<String, ActionListener> commands = new HashMap<>() {
|
||||
Map<String, ActionListener> commands = Map.of("forward selected message", evt -> {
|
||||
final Message selectedMessage = messageList.getSingleSelectedElement();
|
||||
List<User> chosenContacts = ContactsChooserDialog
|
||||
.showForwardingDialog("Forward selected message to", null, selectedMessage, localDb.getUsers().values());
|
||||
if (chosenContacts != null && chosenContacts.size() > 0) forwardMessage(selectedMessage, chosenContacts.toArray(new User[0]));
|
||||
}, "copy", evt -> {
|
||||
// TODO should be enhanced to allow also copying of message attachments,
|
||||
// especially pictures
|
||||
StringSelection copy = new StringSelection(messageList.getSingleSelectedElement().getText());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(copy, copy);
|
||||
// TODO insert implementation to edit and delete messages
|
||||
}, "delete", evt -> {}, "edit", evt -> {}, "quote", evt -> {});
|
||||
|
||||
private static final long serialVersionUID = -2755235774946990126L;
|
||||
|
||||
{
|
||||
put("forward selected message", evt -> {
|
||||
final Message selectedMessage = messageList.getSingleSelectedElement();
|
||||
forwardMessage(selectedMessage,
|
||||
ContactsChooserDialog
|
||||
.showForwardingDialog("Forward selected message to", null, selectedMessage, localDb.getUsers().values())
|
||||
.toArray(new User[0]));
|
||||
});
|
||||
put("copy", evt -> {
|
||||
// TODO should be enhanced to allow also copying of message attachments,
|
||||
// especially pictures
|
||||
StringSelection copy = new StringSelection(messageList.getSingleSelectedElement().getText());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(copy, copy);
|
||||
});
|
||||
// TODO insert implementation to edit and delete messages
|
||||
put("delete", evt -> {});
|
||||
put("edit", evt -> {});
|
||||
put("quote", evt -> {});
|
||||
}
|
||||
};
|
||||
if (isSelected) {
|
||||
contextMenu = new ContextMenu(null, comp, commands, null, null).build();
|
||||
contextMenu.show(comp, 0, 0);
|
||||
@ -210,7 +202,7 @@ public class ChatWindow extends JFrame {
|
||||
gbc_messageEnterTextArea.fill = GridBagConstraints.BOTH;
|
||||
gbc_messageEnterTextArea.gridx = 1;
|
||||
gbc_messageEnterTextArea.gridy = 3;
|
||||
gbc_messageEnterTextArea.insets = insets;
|
||||
gbc_messageEnterTextArea.insets = insets;
|
||||
contentPane.add(messageEnterTextArea, gbc_messageEnterTextArea);
|
||||
|
||||
// Post Button
|
||||
@ -218,7 +210,7 @@ public class ChatWindow extends JFrame {
|
||||
gbc_postButton.fill = GridBagConstraints.BOTH;
|
||||
gbc_postButton.gridx = 2;
|
||||
gbc_postButton.gridy = 3;
|
||||
gbc_postButton.insets = insets;
|
||||
gbc_postButton.insets = insets;
|
||||
postButton.addActionListener((evt) -> { postMessage(); });
|
||||
postButton.setEnabled(false);
|
||||
contentPane.add(postButton, gbc_postButton);
|
||||
|
@ -18,6 +18,7 @@ import envoy.client.ui.Theme;
|
||||
import envoy.client.ui.list.ComponentList;
|
||||
import envoy.client.ui.list.ComponentList.SelectionMode;
|
||||
import envoy.client.ui.list.Model;
|
||||
import envoy.client.ui.list_component.UserComponent;
|
||||
import envoy.data.Message;
|
||||
import envoy.data.User;
|
||||
|
||||
@ -35,7 +36,8 @@ public class ContactsChooserDialog extends JDialog {
|
||||
|
||||
private static final long serialVersionUID = -5774558118579032256L;
|
||||
|
||||
private ComponentList<User> contactList = new ComponentList<User>().setModel(new Model<User>());
|
||||
private ComponentList<User> contactList = new ComponentList<User>().setModel(new Model<User>())
|
||||
.setRenderer((list, user) -> new UserComponent(user));
|
||||
private JButton okButton = new JButton("Ok");
|
||||
private JButton cancelButton = new JButton("Cancel");
|
||||
|
||||
@ -77,6 +79,7 @@ public class ContactsChooserDialog extends JDialog {
|
||||
dialog.addOkButtonActionListener(e -> { results.addAll(dialog.getContactList().getSelectedElements()); dialog.dispose(); });
|
||||
Model<User> contactListModel = dialog.getContactList().getModel();
|
||||
users.forEach(contactListModel::add);
|
||||
dialog.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
dialog.setVisible(true);
|
||||
dialog.repaint();
|
||||
dialog.revalidate();
|
||||
@ -90,12 +93,16 @@ public class ContactsChooserDialog extends JDialog {
|
||||
*/
|
||||
private ContactsChooserDialog(Component parent) {
|
||||
contactList.setSelectionMode(SelectionMode.MULTIPLE);
|
||||
contactList.setSelectionHandler((user, comp, isSelected) -> {
|
||||
final var theme = Settings.getInstance().getCurrentTheme();
|
||||
comp.setBackground(isSelected ? theme.getSelectionColor() : theme.getCellColor());
|
||||
});
|
||||
// setBounds(100, 100, 450, 300);
|
||||
setModal(true);
|
||||
setLocationRelativeTo(parent);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
setBackground(theme.getBackgroundColor());
|
||||
setForeground(theme.getTextColor());
|
||||
setSize(400, 400);
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(new BorderLayout(0, 0));
|
||||
@ -117,6 +124,17 @@ public class ContactsChooserDialog extends JDialog {
|
||||
buttonPane.add(cancelButton, BorderLayout.WEST);
|
||||
}
|
||||
}
|
||||
applyTheme(Settings.getInstance().getCurrentTheme());
|
||||
}
|
||||
|
||||
private void applyTheme(Theme theme) {
|
||||
contentPanel.setBackground(theme.getBackgroundColor());
|
||||
contentPanel.setForeground(theme.getTextColor());
|
||||
contactList.setBackground(theme.getCellColor());
|
||||
okButton.setBackground(theme.getInteractableBackgroundColor());
|
||||
okButton.setForeground(theme.getTextColor());
|
||||
cancelButton.setBackground(theme.getInteractableBackgroundColor());
|
||||
cancelButton.setForeground(theme.getTextColor());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,17 +83,18 @@ public class ComponentList<E> extends JPanel {
|
||||
*/
|
||||
public void selectElement(int index) {
|
||||
final JComponent element = getComponent(index);
|
||||
|
||||
if (selection.contains(index)) {
|
||||
|
||||
// Remove selection of element at index
|
||||
// Deselect if clicked again
|
||||
if (selectionHandler != null) selectionHandler.selectionChanged(model.get(index), element, true);
|
||||
selection.remove(index);
|
||||
|
||||
} else {
|
||||
|
||||
// Remove old selection if single selection is enabled
|
||||
if (selectionMode == SelectionMode.SINGLE) clearSelection();
|
||||
|
||||
// Select item
|
||||
if (selectionMode != SelectionMode.NONE) {
|
||||
|
||||
// Assign new selection
|
||||
|
Reference in New Issue
Block a user