Implemented ContactRenderer and built a properScrollPane with list, etc.
This commit is contained in:
		| @@ -17,6 +17,7 @@ import envoy.client.event.MessageCreationEvent; | ||||
| import envoy.client.event.ThemeChangeEvent; | ||||
| import envoy.client.net.Client; | ||||
| import envoy.client.ui.list.ComponentList; | ||||
| import envoy.client.ui.list.ComponentListModel; | ||||
| import envoy.client.ui.settings.SettingsScreen; | ||||
| import envoy.client.util.EnvoyLog; | ||||
| import envoy.data.Message; | ||||
| @@ -54,17 +55,18 @@ public class ChatWindow extends JFrame { | ||||
| 	private PrimaryButton			settingsButton			= new PrimaryButton("Settings"); | ||||
|  | ||||
| 	// Contacts Header | ||||
| 	private JPanel		contactsHeader	= new JPanel(); | ||||
| 	private JTextPane	contactsDisplay	= new JTextPane(); | ||||
| 	private JPanel			contactsHeader	= new JPanel(); | ||||
| 	private JTextPane		contactsDisplay	= new JTextPane(); | ||||
| 	private PrimaryButton	addContact		= new PrimaryButton("+"); | ||||
|  | ||||
| 	// Search Contacts | ||||
| 	private JPanel searchPane = new JPanel(); | ||||
| 	private PrimaryButton	cancelButton	= new PrimaryButton("x"); | ||||
| 	private PrimaryTextArea	searchField		= new PrimaryTextArea(space); | ||||
| 	private PrimaryScrollPane	possibleContacts	= new PrimaryScrollPane(); | ||||
| 	private ComponentList<User>	contactList;									// TODO Implement data rendering model as already done with the | ||||
| 																				// messages | ||||
| 	private final JPanel					searchPane			= new JPanel(); | ||||
| 	private final PrimaryButton				cancelButton		= new PrimaryButton("x"); | ||||
| 	private final PrimaryTextArea			searchField			= new PrimaryTextArea(space); | ||||
| 	private final PrimaryScrollPane			possibleContacts	= new PrimaryScrollPane(); | ||||
| 	private final ContactsSearchRenderer	contactRenderer		= new ContactsSearchRenderer(); | ||||
| 	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()); | ||||
|  | ||||
| @@ -215,12 +217,12 @@ public class ChatWindow extends JFrame { | ||||
| 		userList.setBorder(new EmptyBorder(space, space, space, space)); | ||||
|  | ||||
| 		GridBagConstraints gbc_userList = new GridBagConstraints(); | ||||
| 		gbc_userList.fill	= GridBagConstraints.VERTICAL; | ||||
| 		gbc_userList.gridx	= 0; | ||||
| 		gbc_userList.gridy	= 2; | ||||
| 		gbc_userList.anchor	= GridBagConstraints.PAGE_START; | ||||
| 		gbc_userList.insets	= insets; | ||||
|  | ||||
| 		gbc_userList.fill		= GridBagConstraints.VERTICAL; | ||||
| 		gbc_userList.gridx		= 0; | ||||
| 		gbc_userList.gridy		= 2; | ||||
| 		gbc_userList.gridheight	= 2; | ||||
| 		gbc_userList.anchor		= GridBagConstraints.PAGE_START; | ||||
| 		gbc_userList.insets		= insets; | ||||
|  | ||||
| 		contentPane.add(userList, gbc_userList); | ||||
| 		contentPane.revalidate(); | ||||
| @@ -260,6 +262,8 @@ public class ChatWindow extends JFrame { | ||||
|  | ||||
| 		searchPane.add(cancelButton, gbc_cancelButton); | ||||
|  | ||||
| 		contactList.setModel(contactsSearchModel); | ||||
| 		possibleContacts.setBorder(new EmptyBorder(space, space, space, space)); | ||||
| 		possibleContacts.setViewportView(contactList); | ||||
|  | ||||
| 		GridBagConstraints gbc_possibleContacts = new GridBagConstraints(); | ||||
| @@ -272,6 +276,7 @@ public class ChatWindow extends JFrame { | ||||
|  | ||||
| 		searchPane.add(possibleContacts, gbc_possibleContacts); | ||||
|  | ||||
|  | ||||
| 		// Contacts Header | ||||
|  | ||||
| 		GridBagConstraints gbc_contactsHeader = new GridBagConstraints(); | ||||
| @@ -320,7 +325,7 @@ public class ChatWindow extends JFrame { | ||||
|  | ||||
| 		// Listen to received messages | ||||
| 		EventBus.getInstance().register(MessageCreationEvent.class, (evt) -> { | ||||
| 			Message message = ((MessageCreationEvent) evt).get(); | ||||
| 			Message	message	= ((MessageCreationEvent) evt).get(); | ||||
| 			Chat	chat	= localDb.getChats().stream().filter(c -> c.getRecipient().getId() == message.getSenderId()).findFirst().get(); | ||||
| 			chat.appendMessage(message); | ||||
|  | ||||
| @@ -355,6 +360,7 @@ public class ChatWindow extends JFrame { | ||||
| 		}); | ||||
|  | ||||
| 		revalidate(); | ||||
| 		repaint(); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| @@ -406,9 +412,8 @@ public class ChatWindow extends JFrame { | ||||
| 		searchField.setForeground(theme.getUserNameColor()); | ||||
| 		cancelButton.setBackground(theme.getInteractableBackgroundColor()); | ||||
| 		cancelButton.setForeground(theme.getInteractableForegroundColor()); | ||||
| 		// TODO: Uncomment if renderer is implemented | ||||
| 		// contactList.setForeground(theme.getMessageColorChat()); | ||||
| 		// contactList.setBackground(theme.getCellColor()); | ||||
| 		contactList.setForeground(theme.getMessageColorChat()); | ||||
| 		contactList.setBackground(theme.getCellColor()); | ||||
| 		possibleContacts.applyTheme(theme); | ||||
| 	} | ||||
|  | ||||
| @@ -465,6 +470,9 @@ public class ChatWindow extends JFrame { | ||||
| 					localDb.getChats().add(new Chat(user)); | ||||
| 			}); | ||||
| 			SwingUtilities.invokeLater(() -> userList.setModel(userListModel)); | ||||
|  | ||||
| 			revalidate(); | ||||
| 			repaint(); | ||||
| 		}).start(); | ||||
| 	} | ||||
|  | ||||
| @@ -478,7 +486,6 @@ public class ChatWindow extends JFrame { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	 | ||||
| 	private void drawChatBox(GridBagConstraints gbc_scrollPane) { | ||||
| 		contentPane.remove(searchPane); | ||||
| 		contentPane.add(scrollPane, gbc_scrollPane); | ||||
| @@ -494,6 +501,7 @@ public class ChatWindow extends JFrame { | ||||
| 		contentPane.remove(scrollPane); | ||||
| 		contentPane.add(searchPane, gbc_searchPane); | ||||
| 		contentPane.revalidate(); | ||||
| 		contactRenderer.setScrollPane(possibleContacts); | ||||
| 		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> | ||||
|  * <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> | ||||
|  * | ||||
|  * @author Kai S. K. Engelbart | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 DieGurke
					DieGurke