// ex:sw=3 package chat; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; /** * **/ public class PeoplePanel extends JPanel { /** * **/ private static Color BG_COLOR = Color.black; /** * **/ private static Color TEXT_COLOR = Color.red; /** * **/ private JList _peopleList; /** * **/ private UserServer _userServer; /** * **/ private String _context; /** * **/ public PeoplePanel(DefaultListModel members, Dimension size, // UserServer userServer, String context) { super(); _userServer = userServer; _context = context; _peopleList = new JList(members); _peopleList.setBackground(BG_COLOR); _peopleList.setForeground(TEXT_COLOR); setLayout(new BorderLayout()); add(_peopleList,BorderLayout.CENTER); setPreferredSize(size); installPeopleListener(); } /** * **/ private void installPeopleListener() { MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { // int index = _peopleList.locationToIndex(e.getPoint()); Object value = _peopleList.getSelectedValue(); if(value == null) return; if(value instanceof User) { _userServer.friendSelected( _context, ((User)value).getIdentification(), e.getClickCount() ); } } }; _peopleList.addMouseListener(mouseListener); /* _peopleList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent lse) { if(lse.getValueIsAdjusting()) return; Object value = _peopleList.getSelectedValue(); if(value == null) return; if(value instanceof User) { _userServer.friendSelected(((User)value).getIdentification(),// _context); } else { //System.err.println("Kein User-Object: "+value); } } }); */ } }