KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > client > acl > AclRenderer


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2005 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.client.acl;
20
21 import java.awt.Component JavaDoc;
22
23 import javax.swing.DefaultListCellRenderer JavaDoc;
24 import javax.swing.ImageIcon JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JList JavaDoc;
27
28 import org.lucane.common.acl.AclInfo;
29 import org.lucane.common.concepts.Concept;
30 import org.lucane.common.concepts.GroupConcept;
31 import org.lucane.common.concepts.UserConcept;
32 import org.lucane.client.Client;
33
34 public class AclRenderer extends DefaultListCellRenderer JavaDoc
35 {
36     private ImageIcon JavaDoc userIcon;
37     private ImageIcon JavaDoc groupIcon;
38     
39     public AclRenderer()
40     {
41         this.userIcon = Client.getImageIcon("user.png");
42         this.groupIcon = Client.getImageIcon("group.png");
43     }
44     
45     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus)
46     {
47         Component JavaDoc c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
48         JLabel JavaDoc label = (JLabel JavaDoc)c;
49         Concept concept = (Concept)value;
50         
51         if(concept instanceof GroupConcept)
52             label.setIcon(groupIcon);
53         else if(concept instanceof UserConcept)
54             label.setIcon(userIcon);
55
56         label.setText(concept.getName());
57
58         return label;
59     }
60 }
Popular Tags