1 19 package org.lucane.applications.forum.gui; 20 21 import java.awt.Color ; 22 import java.awt.Component ; 23 import java.util.ArrayList ; 24 25 import javax.swing.DefaultListCellRenderer ; 26 import javax.swing.JLabel ; 27 import javax.swing.JList ; 28 import org.lucane.applications.forum.model.ForumInfo; 29 30 public class ForumList extends JList 31 { 32 public ForumList() 33 { 34 super(); 35 this.setCellRenderer(new ForumListRenderer()); 36 } 37 38 public void setForums(ArrayList forums) 39 { 40 this.setListData(forums.toArray()); 41 } 42 43 public ForumInfo getSelectedForum() 44 { 45 return (ForumInfo)getSelectedValue(); 46 } 47 } 48 49 class ForumListRenderer extends DefaultListCellRenderer 50 { 51 public Component getListCellRendererComponent(JList list, Object value, 52 int index, boolean isSelected, boolean cellHasFocus) 53 { 54 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 55 JLabel label = (JLabel )c; 56 57 ForumInfo info = (ForumInfo)value; 58 59 label.setText(info.getName()); 60 if(info.getAccess().equals(ForumInfo.MODERATE)) 61 label.setForeground(Color.ORANGE); 62 else if(info.getAccess().equals(ForumInfo.WRITE)) 63 label.setForeground(Color.BLUE); 64 else if(info.getAccess().equals(ForumInfo.READ)) 65 label.setForeground(Color.LIGHT_GRAY); 66 67 return label; 68 } 69 } 70 71 | Popular Tags |