KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > sharedfolder > gui > FolderTreeRenderer


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
20 package org.lucane.applications.sharedfolder.gui;
21
22 import org.lucane.applications.sharedfolder.model.FolderInfo;
23 import org.lucane.applications.sharedfolder.SharedFolderPlugin;
24
25 import javax.swing.*;
26 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
27 import java.awt.*;
28
29 public class FolderTreeRenderer extends DefaultTreeCellRenderer JavaDoc
30 {
31     private ImageIcon folderIcon;
32     private String JavaDoc rootLabel;
33
34     public FolderTreeRenderer(SharedFolderPlugin plugin)
35     {
36         this.folderIcon = plugin.getImageIcon("folder.png");
37         this.rootLabel = plugin.tr("folder.root");
38     }
39
40     public Component getTreeCellRendererComponent(JTree tree, Object JavaDoc value, boolean sel,
41        boolean expanded, boolean leaf, int row, boolean hasFocus)
42     {
43         Component cmp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
44         JLabel label = (JLabel)cmp;
45
46         FolderInfo item = (FolderInfo)value;
47         if(item.getId() == FolderInfo.ROOT_ID)
48             label.setText(rootLabel);
49         else
50             label.setText(item.getName());
51
52         label.setIcon(folderIcon);
53
54         if(item.isWritable())
55             label.setForeground(Color.BLUE);
56         else if(item.isReadable())
57             label.setForeground(Color.BLACK);
58         else
59             label.setForeground(Color.GRAY);
60
61         return label;
62     }
63 }
Popular Tags