/** * This is the constructor of the SidePanel. * * @param c * @param model */ public SidePanel(MainController controller, Model model) { this.model = model; this.controller = controller; this.model.addObserver(this); this.model.getChatCollection().addObserver(this); this.users = new ArrayList<UserDataWrapper>(); this.chatCollection = this.model.getChatCollection(); // Panel Properties setLayout(new BorderLayout()); setPreferredSize(new Dimension(150, 500)); setGradientColors(Color.BLACK, Color.WHITE); // List preferences listPane = new CustomListPane(); listPane.setGradientColors(model.primaryColor, model.secondaryColor); listPane.textColor = model.primaryTextColor; listPane.opaque = false; // rightclick menu rightClickMenu = new JPopupMenu(); JMenuItem menuItem4 = new JMenuItem( "Remove Conversation", new ImageIcon(this.getClass().getResource("/images/buddylist/delete_user.png"))); menuItem4.addActionListener(new removeConversationListener()); rightClickMenu.add(menuItem4); this.add(listPane.getWithScroller(), BorderLayout.CENTER); }
private void removeClosedConversations() { UserDataWrapper foundUser = null; ArrayList<UserDataWrapper> usersToRemove = new ArrayList<UserDataWrapper>(); // Remove from the sidePanel, and make a list for (UserDataWrapper u : this.users) { foundUser = null; for (Conversation c : this.chatCollection.getVisibleConversations()) { if (c == u.getConversation()) { foundUser = u; break; } } if (foundUser == null) { foundUser = u; listPane.removeSidePanelUser(foundUser); usersToRemove.add(u); } } // Remove the users from the list for (UserDataWrapper u : usersToRemove) { this.users.remove(u); } listPane.updateUI(); return; }
/** * Adds new conversations to the list when the list is refreshed * * @throws XMPPException */ private void addNewConversationsToList() throws XMPPException { UserDataWrapper userWrapper = null; for (Conversation c : this.chatCollection.getVisibleConversations()) { userWrapper = null; for (UserDataWrapper u : this.users) { if (u.getConversation().getUser() != null) { u.getConversation().getUser().getTypingState(); } if (u.getConversation() == c) { userWrapper = u; break; } } if (userWrapper == null) { userWrapper = new UserDataWrapper(c, this.model); this.users.add(userWrapper); } if (!listPane.sidePanelUserExists(userWrapper)) { ImageIcon leafIcon = controller.getAvatarPicture(c.getUser()); listPane.addElement(userWrapper.toString(), leafIcon, userWrapper, new SelectListener()); } } // refreshes the list on the screen with the new data listPane.updateUI(); }
/** * Update according to the UpdatedType. * * @param t * @param o */ public void update(Observable t, Object o) { if (t instanceof ChatCollectionData) { try { addNewConversationsToList(); removeClosedConversations(); } catch (XMPPException e) { e.printStackTrace(); } } if (o == UpdatedType.COLOR) { listPane.textColor = model.primaryTextColor; listPane.updateTextColor(model.primaryTextColor); } return; }