69 lines
2.2 KiB
Java
69 lines
2.2 KiB
Java
package envoy.client.ui;
|
|
|
|
import java.awt.Component;
|
|
import java.awt.Dimension;
|
|
import java.awt.Font;
|
|
|
|
import javax.swing.*;
|
|
|
|
import envoy.client.data.Settings;
|
|
import envoy.client.event.SendEvent;
|
|
import envoy.client.ui.list.ComponentList;
|
|
import envoy.client.ui.primary.PrimaryButton;
|
|
import envoy.data.User;
|
|
import envoy.event.ContactOperationEvent;
|
|
import envoy.event.EventBus;
|
|
|
|
/**
|
|
* Project: <strong>envoy-client</strong>
|
|
* File: <strong>ContactSearchComponent.java</strong>
|
|
* Created: <strong>21.03.2020</strong>
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @since Envoy v0.1-beta
|
|
*/
|
|
public class ContactSearchComponent extends JComponent {
|
|
|
|
private static final long serialVersionUID = 3166795412575239455L;
|
|
|
|
public ContactSearchComponent(ComponentList<? extends User> list, User user) {
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
|
|
|
setBackground(list.getBackground());
|
|
setForeground(list.getForeground());
|
|
|
|
JLabel display = new JLabel(user.getName());
|
|
display.setForeground(Settings.getInstance().getCurrentTheme().getMessageTextColor());
|
|
display.setAlignmentX(Component.LEFT_ALIGNMENT);
|
|
display.setAlignmentY(Component.CENTER_ALIGNMENT);
|
|
display.setFont(new Font("Arial", Font.PLAIN, 16));
|
|
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(user, ContactOperationEvent.Operation.ADD);
|
|
EventBus.getInstance().dispatch(contactsOperationEvent);
|
|
EventBus.getInstance().dispatch(new SendEvent(contactsOperationEvent));
|
|
});
|
|
|
|
add(add);
|
|
|
|
// Define some space to the messages below
|
|
setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0, 0, 15, 0), BorderFactory.createEtchedBorder()));
|
|
|
|
// Define a maximum height of 50px
|
|
Dimension size = new Dimension(435, 50);
|
|
setMaximumSize(size);
|
|
setMinimumSize(size);
|
|
setPreferredSize(size);
|
|
}
|
|
}
|