KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > forum > gui > ForumList


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.forum.gui;
20
21 import java.awt.Color JavaDoc;
22 import java.awt.Component JavaDoc;
23 import java.util.ArrayList JavaDoc;
24
25 import javax.swing.DefaultListCellRenderer JavaDoc;
26 import javax.swing.JLabel JavaDoc;
27 import javax.swing.JList JavaDoc;
28 import org.lucane.applications.forum.model.ForumInfo;
29
30 public class ForumList extends JList JavaDoc
31 {
32     public ForumList()
33     {
34         super();
35         this.setCellRenderer(new ForumListRenderer());
36     }
37
38     public void setForums(ArrayList JavaDoc 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 JavaDoc
50 {
51     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
52              int index, boolean isSelected, boolean cellHasFocus)
53     {
54         Component JavaDoc c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
55         JLabel JavaDoc label = (JLabel JavaDoc)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