KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > swing > ResourcePathCellRenderer


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.swing;
20
21 import java.awt.*;
22
23 import javax.swing.*;
24
25 import org.openharmonise.swing.FontManager;
26 import org.openharmonise.vfs.*;
27
28
29 /**
30  *
31  * @author Matthew Large
32  * @version $Revision: 1.2 $
33  *
34  */

35 public class ResourcePathCellRenderer extends JLabel implements ListCellRenderer {
36
37     AbstractVirtualFileSystem m_vfs = null;
38     
39     private Color m_selectedColor = new Color(173,169,143);
40     
41
42     /**
43      *
44      */

45     public ResourcePathCellRenderer(AbstractVirtualFileSystem vfs) {
46         super();
47         this.m_vfs = vfs;
48     }
49
50     /* (non-Javadoc)
51      * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
52      */

53     public Component getListCellRendererComponent(
54         JList arg0,
55         Object JavaDoc arg1,
56         int nIndex,
57         boolean isSelected,
58         boolean hasFocus) {
59         
60         if(arg1 instanceof SelfRenderListCell) {
61             Component comp = ((SelfRenderListCell)arg1).getRenderComponent(isSelected, hasFocus);
62             comp.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) );
63             return comp;
64         } else {
65             String JavaDoc sPath = (String JavaDoc)arg1;
66             VirtualFileSystemView vfsView = this.m_vfs.getVirtualFileSystemView();
67         
68             VirtualFile vfFile = this.m_vfs.getVirtualFile(sPath).getResource();
69 //
70
// String fontName = "Dialog";
71
// int fontSize = 11;
72
// Font font = new Font(fontName, Font.PLAIN, fontSize);
73
// this.setFont(font);
74

75             this.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) );
76         
77             this.setIcon( vfsView.getIcon(vfFile) );
78             this.setText(vfsView.getDisplayName(vfFile));
79             this.setToolTipText(vfFile.getFullPath());
80         
81             this.setOpaque(true);
82             this.setBackground(Color.WHITE);
83             this.setBorder(BorderFactory.createLineBorder(Color.WHITE));
84             this.setBorder(BorderFactory.createLineBorder(Color.WHITE));
85         
86             if(isSelected) {
87                 this.setBackground(m_selectedColor);
88                 this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
89             }
90             
91             if(hasFocus) {
92                 this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
93             }
94
95             return this;
96         }
97     }
98
99 }
100
Popular Tags