Implemented ContactRenderer and built a properScrollPane with list, etc.
This commit is contained in:
parent
5086ad62b6
commit
90409c1d90
@ -17,6 +17,7 @@ import envoy.client.event.MessageCreationEvent;
|
|||||||
import envoy.client.event.ThemeChangeEvent;
|
import envoy.client.event.ThemeChangeEvent;
|
||||||
import envoy.client.net.Client;
|
import envoy.client.net.Client;
|
||||||
import envoy.client.ui.list.ComponentList;
|
import envoy.client.ui.list.ComponentList;
|
||||||
|
import envoy.client.ui.list.ComponentListModel;
|
||||||
import envoy.client.ui.settings.SettingsScreen;
|
import envoy.client.ui.settings.SettingsScreen;
|
||||||
import envoy.client.util.EnvoyLog;
|
import envoy.client.util.EnvoyLog;
|
||||||
import envoy.data.Message;
|
import envoy.data.Message;
|
||||||
@ -59,12 +60,13 @@ public class ChatWindow extends JFrame {
|
|||||||
private PrimaryButton addContact = new PrimaryButton("+");
|
private PrimaryButton addContact = new PrimaryButton("+");
|
||||||
|
|
||||||
// Search Contacts
|
// Search Contacts
|
||||||
private JPanel searchPane = new JPanel();
|
private final JPanel searchPane = new JPanel();
|
||||||
private PrimaryButton cancelButton = new PrimaryButton("x");
|
private final PrimaryButton cancelButton = new PrimaryButton("x");
|
||||||
private PrimaryTextArea searchField = new PrimaryTextArea(space);
|
private final PrimaryTextArea searchField = new PrimaryTextArea(space);
|
||||||
private PrimaryScrollPane possibleContacts = new PrimaryScrollPane();
|
private final PrimaryScrollPane possibleContacts = new PrimaryScrollPane();
|
||||||
private ComponentList<User> contactList; // TODO Implement data rendering model as already done with the
|
private final ContactsSearchRenderer contactRenderer = new ContactsSearchRenderer();
|
||||||
// messages
|
private final ComponentListModel<User> contactsSearchModel = new ComponentListModel<>();
|
||||||
|
private final ComponentList<User> contactList = new ComponentList<>(contactRenderer);
|
||||||
|
|
||||||
private static final Logger logger = EnvoyLog.getLogger(ChatWindow.class.getSimpleName());
|
private static final Logger logger = EnvoyLog.getLogger(ChatWindow.class.getSimpleName());
|
||||||
|
|
||||||
@ -218,10 +220,10 @@ public class ChatWindow extends JFrame {
|
|||||||
gbc_userList.fill = GridBagConstraints.VERTICAL;
|
gbc_userList.fill = GridBagConstraints.VERTICAL;
|
||||||
gbc_userList.gridx = 0;
|
gbc_userList.gridx = 0;
|
||||||
gbc_userList.gridy = 2;
|
gbc_userList.gridy = 2;
|
||||||
|
gbc_userList.gridheight = 2;
|
||||||
gbc_userList.anchor = GridBagConstraints.PAGE_START;
|
gbc_userList.anchor = GridBagConstraints.PAGE_START;
|
||||||
gbc_userList.insets = insets;
|
gbc_userList.insets = insets;
|
||||||
|
|
||||||
|
|
||||||
contentPane.add(userList, gbc_userList);
|
contentPane.add(userList, gbc_userList);
|
||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
|
|
||||||
@ -260,6 +262,8 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
searchPane.add(cancelButton, gbc_cancelButton);
|
searchPane.add(cancelButton, gbc_cancelButton);
|
||||||
|
|
||||||
|
contactList.setModel(contactsSearchModel);
|
||||||
|
possibleContacts.setBorder(new EmptyBorder(space, space, space, space));
|
||||||
possibleContacts.setViewportView(contactList);
|
possibleContacts.setViewportView(contactList);
|
||||||
|
|
||||||
GridBagConstraints gbc_possibleContacts = new GridBagConstraints();
|
GridBagConstraints gbc_possibleContacts = new GridBagConstraints();
|
||||||
@ -272,6 +276,7 @@ public class ChatWindow extends JFrame {
|
|||||||
|
|
||||||
searchPane.add(possibleContacts, gbc_possibleContacts);
|
searchPane.add(possibleContacts, gbc_possibleContacts);
|
||||||
|
|
||||||
|
|
||||||
// Contacts Header
|
// Contacts Header
|
||||||
|
|
||||||
GridBagConstraints gbc_contactsHeader = new GridBagConstraints();
|
GridBagConstraints gbc_contactsHeader = new GridBagConstraints();
|
||||||
@ -355,6 +360,7 @@ public class ChatWindow extends JFrame {
|
|||||||
});
|
});
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -406,9 +412,8 @@ public class ChatWindow extends JFrame {
|
|||||||
searchField.setForeground(theme.getUserNameColor());
|
searchField.setForeground(theme.getUserNameColor());
|
||||||
cancelButton.setBackground(theme.getInteractableBackgroundColor());
|
cancelButton.setBackground(theme.getInteractableBackgroundColor());
|
||||||
cancelButton.setForeground(theme.getInteractableForegroundColor());
|
cancelButton.setForeground(theme.getInteractableForegroundColor());
|
||||||
// TODO: Uncomment if renderer is implemented
|
contactList.setForeground(theme.getMessageColorChat());
|
||||||
// contactList.setForeground(theme.getMessageColorChat());
|
contactList.setBackground(theme.getCellColor());
|
||||||
// contactList.setBackground(theme.getCellColor());
|
|
||||||
possibleContacts.applyTheme(theme);
|
possibleContacts.applyTheme(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,6 +470,9 @@ public class ChatWindow extends JFrame {
|
|||||||
localDb.getChats().add(new Chat(user));
|
localDb.getChats().add(new Chat(user));
|
||||||
});
|
});
|
||||||
SwingUtilities.invokeLater(() -> userList.setModel(userListModel));
|
SwingUtilities.invokeLater(() -> userList.setModel(userListModel));
|
||||||
|
|
||||||
|
revalidate();
|
||||||
|
repaint();
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,7 +486,6 @@ public class ChatWindow extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void drawChatBox(GridBagConstraints gbc_scrollPane) {
|
private void drawChatBox(GridBagConstraints gbc_scrollPane) {
|
||||||
contentPane.remove(searchPane);
|
contentPane.remove(searchPane);
|
||||||
contentPane.add(scrollPane, gbc_scrollPane);
|
contentPane.add(scrollPane, gbc_scrollPane);
|
||||||
@ -494,6 +501,7 @@ public class ChatWindow extends JFrame {
|
|||||||
contentPane.remove(scrollPane);
|
contentPane.remove(scrollPane);
|
||||||
contentPane.add(searchPane, gbc_searchPane);
|
contentPane.add(searchPane, gbc_searchPane);
|
||||||
contentPane.revalidate();
|
contentPane.revalidate();
|
||||||
|
contactRenderer.setScrollPane(possibleContacts);
|
||||||
contentPane.repaint();
|
contentPane.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
83
src/main/java/envoy/client/ui/ContactsSearchRenderer.java
Normal file
83
src/main/java/envoy/client/ui/ContactsSearchRenderer.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
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.ui.list.ComponentList;
|
||||||
|
import envoy.client.ui.list.ComponentListCellRenderer;
|
||||||
|
import envoy.data.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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äfer
|
||||||
|
* @author Kai S. K. Engelbart
|
||||||
|
* @since Envoy v0.3-alpha
|
||||||
|
*/
|
||||||
|
public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
||||||
|
|
||||||
|
private PrimaryScrollPane scrollPane = new PrimaryScrollPane();
|
||||||
|
|
||||||
|
|
||||||
|
@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);
|
||||||
|
// TODO: Selection
|
||||||
|
// setBackground(list.getSelectionBackground());
|
||||||
|
// setForeground(list.getSelectionForeground());
|
||||||
|
} 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());
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Use this method properly
|
||||||
|
public void setScrollPane(PrimaryScrollPane scrollPane) { this.scrollPane = scrollPane; }
|
||||||
|
}
|
@ -14,7 +14,7 @@ import envoy.data.Message;
|
|||||||
* Defines how a message is displayed.<br>
|
* Defines how a message is displayed.<br>
|
||||||
* <br>
|
* <br>
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
* File: <strong>UserListRenderer.java</strong><br>
|
* File: <strong>MessageListRenderer.java</strong><br>
|
||||||
* Created: <strong>19 Oct 2019</strong><br>
|
* Created: <strong>19 Oct 2019</strong><br>
|
||||||
*
|
*
|
||||||
* @author Kai S. K. Engelbart
|
* @author Kai S. K. Engelbart
|
||||||
|
Reference in New Issue
Block a user