This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/client/ui/ContactsSearchRenderer.java

84 lines
2.7 KiB
Java

package envoy.client.ui;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.*;
import envoy.client.Settings;
import envoy.client.event.SendEvent;
import envoy.client.ui.list.ComponentList;
import envoy.client.ui.list.ComponentListCellRenderer;
import envoy.data.User;
import envoy.event.ContactOperationEvent;
import envoy.event.EventBus;
/**
* Defines how a contact is displayed.<br>
* <br>
* Project: <strong>envoy-client</strong><br>
* File: <strong>ContactsSearchRenderer.java</strong><br>
* Created: <strong>08.02.2020</strong><br>
*
* @author Maximilian K&auml;fer
* @author Kai S. K. Engelbart
* @since Envoy v0.3-alpha
*/
public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
@Override
public JComponent getListCellComponent(ComponentList<? extends User> list, User value, boolean isSelected) {
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
if (isSelected) {
panel.setBackground(Color.DARK_GRAY);
panel.setForeground(Color.RED);
} else {
panel.setBackground(list.getBackground());
panel.setForeground(list.getForeground());
}
// TODO: Handle message attachments
final String text = value.getName();
// Getting the UserColor in the Chat of the current theme
String textColor = Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getMessageColorChat().toHex();
JLabel display = new JLabel(String.format("<html><p style=\"color:%s\">%s</html>", textColor, text));
display.setAlignmentX(Component.LEFT_ALIGNMENT);
display.setAlignmentY(Component.CENTER_ALIGNMENT);
display.setFont(new Font("Arial", Font.PLAIN, 16));
panel.add(display);
PrimaryButton add = new PrimaryButton("+");
add.setFont(new Font("Arial", Font.PLAIN, 19));
add.setPreferredSize(new Dimension(45, 45));
add.setMinimumSize(new Dimension(45, 45));
add.setMaximumSize(new Dimension(45, 45));
add.setBackground(list.getBackground());
add.setForeground(list.getForeground());
add.addActionListener(evt -> {
ContactOperationEvent contactsOperationEvent = new ContactOperationEvent(value, ContactOperationEvent.Operation.ADD);
EventBus.getInstance().dispatch(contactsOperationEvent);
EventBus.getInstance().dispatch(new SendEvent(contactsOperationEvent));
});
panel.add(add);
// Define some space to the messages below
panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 15, 0), BorderFactory.createEtchedBorder()));
// Define a maximum height of 50px
Dimension size = new Dimension(435, 50);
panel.setMaximumSize(size);
panel.setMinimumSize(size);
panel.setPreferredSize(size);
return panel;
}
}