View Javadoc
1 /*** 2 * Copyright (c) 2003 held jointly by the individual authors. 3 * 4 * This library is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU Lesser General Public License as published 6 * by the Free Software Foundation; either version 2.1 of the License, or 7 * (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; with out even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this library; if not, write to the Free Software Foundation, 16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 17 * 18 * > http://www.gnu.org/copyleft/lesser.html 19 * > http://www.opensource.org/licenses/lgpl-license.php 20 */ 21 package net.mlw.gfw.ext.basic.client.component; 22 23 import java.awt.BorderLayout; 24 import java.awt.Dimension; 25 import java.util.ArrayList; 26 import java.util.List; 27 28 import javax.swing.DefaultListModel; 29 import javax.swing.JList; 30 import javax.swing.JScrollPane; 31 import javax.swing.SwingUtilities; 32 33 import net.mlw.gfw.client.ClientContext; 34 import net.mlw.gfw.event.Event; 35 import net.mlw.gfw.event.InvalidEventException; 36 import net.mlw.gfw.event.impl.ConnectEvent; 37 import net.mlw.gfw.event.impl.DisconnectEvent; 38 39 /*** 40 * @author Matthew L. Wilson 41 * @version $Revision: 1.1 $ $Date: 2004/07/01 14:31:39 $ 42 */ 43 public class PlayerListPanel extends BaseJPanel 44 { 45 46 private final DefaultListModel players = new DefaultListModel(); 47 48 private final List mutedPlayers = new ArrayList(); 49 50 /*** 51 * @see net.mlw.gfw.client.ClientEventHandler#init(net.mlw.gfw.client.ClientContext) 52 * 53 * @todo Support muting of players. 54 */ 55 public void init(ClientContext context) 56 { 57 JList list = new JList(players); 58 /* 59 * list.setCellRenderer(new DefaultListCellRenderer() { public Component 60 * getListCellRendererComponent( JList list, Object value, int index, 61 * boolean isSelected, boolean cellHasFocus) { 62 * super.getListCellRendererComponent(list, value, index, isSelected, 63 * cellHasFocus); return this; } }); 64 */ 65 66 setLayout(new BorderLayout()); 67 add(new JScrollPane(list), BorderLayout.CENTER); 68 } 69 70 public Dimension getPreferredSize() 71 { 72 return new Dimension(80, 80); 73 } 74 75 /*** 76 * @see net.mlw.gfw.event.EventHandler#onEvent(net.mlw.gfw.event.Event) 77 */ 78 public void onEvent(Event event) 79 { 80 if (event instanceof ConnectEvent) 81 { 82 final String userName = ((ConnectEvent) event).getUserName(); 83 SwingUtilities.invokeLater(new Runnable() 84 { 85 86 public void run() 87 { 88 players.addElement(userName); 89 } 90 }); 91 } 92 else if (event instanceof DisconnectEvent) 93 { 94 final String userName = ((DisconnectEvent) event).getUserName(); 95 SwingUtilities.invokeLater(new Runnable() 96 { 97 98 public void run() 99 { 100 players.removeElement(userName); 101 } 102 }); 103 } 104 else 105 { 106 throw new InvalidEventException(this, event); 107 } 108 } 109 110 }

This page was automatically generated by Maven