KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > jmail > base > FolderRenderer


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.jmail.base;
20
21 import java.awt.*;
22 import javax.swing.*;
23 import javax.swing.tree.*;
24
25 import org.lucane.applications.jmail.JMailPlugin;
26
27 public class FolderRenderer extends DefaultTreeCellRenderer
28 {
29     private JMailPlugin plugin;
30     private Icon inboxIcon;
31     private Icon sentIcon;
32     private Icon draftsIcon;
33     private Icon trashIcon;
34     private Icon openedFolderIcon;
35     private Icon closedFolderIcon;
36
37     public FolderRenderer(JMailPlugin plugin)
38     {
39         this.plugin = plugin;
40         this.inboxIcon = plugin.getImageIcon("folders/inbox.png");
41         this.sentIcon = plugin.getImageIcon("folders/sent.png");
42         this.draftsIcon = plugin.getImageIcon("folders/drafts.png");
43         this.trashIcon = plugin.getImageIcon("folders/trash.png");
44         this.openedFolderIcon = plugin.getImageIcon("folders/openedFolder.png");
45         this.closedFolderIcon = plugin.getImageIcon("folders/closedFolder.png");
46     }
47         
48     public Component getTreeCellRendererComponent(JTree tree,
49             Object JavaDoc value, boolean sel, boolean expanded, boolean leaf,
50             int row, boolean hasFocus)
51     {
52         JLabel label = (JLabel)super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
53
54         //-- tree root
55
if(value.toString().equalsIgnoreCase("Mailbox"))
56         {
57             label.setText("<html><b>" +tr("folder.root") + "</b></html>");
58             label.setIcon(null);
59         }
60         //-- well known folders
61
else if(value.toString().equalsIgnoreCase("INBOX"))
62         {
63             label.setText(tr("folder.inbox"));
64             label.setIcon(this.inboxIcon);
65         }
66         else if(value.toString().equalsIgnoreCase("Sent"))
67         {
68             label.setText(tr("folder.sent"));
69             label.setIcon(this.sentIcon);
70         }
71         else if(value.toString().equalsIgnoreCase("Drafts"))
72         {
73             label.setText(tr("folder.drafts"));
74             label.setIcon(this.draftsIcon);
75         }
76         else if(value.toString().equalsIgnoreCase("Trash"))
77         {
78             label.setText(tr("folder.trash"));
79             label.setIcon(this.trashIcon);
80         }
81             
82         //-- user defined folders
83
else if(expanded)
84             label.setIcon(this.openedFolderIcon);
85         else
86             label.setIcon(this.openedFolderIcon);
87
88         return label;
89     }
90     
91     private String JavaDoc tr(String JavaDoc s)
92     {
93         return plugin.tr(s);
94     }
95 }
Popular Tags