/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/browser/FileCellRenderer.java
Java | 159 lines | 101 code | 22 blank | 36 comment | 16 complexity | a7aaf67c9c4ffbfdd1769a6166f9395d MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- /*
- * FileCellRenderer.java - renders list and tree cells for the VFS browser
- * :tabSize=8:indentSize=8:noTabs=false:
- * :folding=explicit:collapseFolds=1:
- *
- * Copyright (C) 1999 Jason Ginchereau
- * Portions copyright (C) 2001 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- package org.gjt.sp.jedit.browser;
- //{{{ Imports
- import java.awt.*;
- import javax.swing.*;
- import javax.swing.tree.*;
- import javax.swing.border.*;
- import org.gjt.sp.jedit.io.VFS;
- import org.gjt.sp.jedit.*;
- //}}}
- public class FileCellRenderer extends DefaultTreeCellRenderer
- {
- public static Icon fileIcon = GUIUtilities.loadIcon("file.gif");
- public static Icon dirIcon = GUIUtilities.loadIcon("closed_folder.gif");
- public static Icon openDirIcon = GUIUtilities.loadIcon("open_folder.gif");
- public static Icon filesystemIcon = GUIUtilities.loadIcon("drive.gif");
- public static Icon loadingIcon = GUIUtilities.loadIcon("drive.gif");
- //{{{ FileCellRenderer constructor
- public FileCellRenderer()
- {
- plainFont = UIManager.getFont("Tree.font");
- boldFont = plainFont.deriveFont(Font.BOLD);
- setBorder(new EmptyBorder(1,0,1,0));
- } //}}}
- //{{{ getTreeCellRendererComponent() method
- public Component getTreeCellRendererComponent(JTree tree, Object value,
- boolean sel, boolean expanded, boolean leaf, int row,
- boolean focus)
- {
- super.getTreeCellRendererComponent(tree,value,sel,expanded,
- leaf,row,focus);
- DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)value;
- Object userObject = treeNode.getUserObject();
- if(userObject instanceof VFS.DirectoryEntry)
- {
- VFS.DirectoryEntry file = (VFS.DirectoryEntry)userObject;
- underlined = (jEdit.getBuffer(file.path) != null);
- setIcon(showIcons
- ? getIconForFile(file,expanded)
- : null);
- setFont(file.type == VFS.DirectoryEntry.FILE
- ? plainFont : boldFont);
- setText(file.name);
- if(!sel)
- {
- Color color = file.getColor();
- setForeground(color == null
- ? tree.getForeground()
- : color);
- }
- }
- else if(userObject instanceof BrowserView.LoadingPlaceholder)
- {
- setIcon(showIcons ? loadingIcon : null);
- setFont(plainFont);
- setText(jEdit.getProperty("vfs.browser.tree.loading"));
- underlined = false;
- }
- else if(userObject instanceof String)
- {
- setIcon(showIcons ? dirIcon : null);
- setFont(boldFont);
- setText((String)userObject);
- underlined = false;
- }
- else
- {
- // userObject is null?
- setIcon(null);
- setText(null);
- }
- return this;
- } //}}}
- //{{{ paintComponent() method
- public void paintComponent(Graphics g)
- {
- if(underlined)
- {
- Font font = getFont();
- FontMetrics fm = getFontMetrics(getFont());
- int x = (getIcon() == null ? 0
- : getIcon().getIconWidth()
- + getIconTextGap());
- g.setColor(getForeground());
- g.drawLine(x,fm.getAscent() + 2,
- x + fm.stringWidth(getText()),
- fm.getAscent() + 2);
- }
- super.paintComponent(g);
- } //}}}
- //{{{ Package-private members
- boolean showIcons;
- //{{{ propertiesChanged() method
- void propertiesChanged()
- {
- showIcons = jEdit.getBooleanProperty("vfs.browser.showIcons");
- } //}}}
- //}}}
- //{{{ Private members
- //{{{ Instance members
- private Font plainFont;
- private Font boldFont;
- private boolean underlined;
- //}}}
- //{{{ getIconForFile() method
- private Icon getIconForFile(VFS.DirectoryEntry file, boolean expanded)
- {
- if(file.type == VFS.DirectoryEntry.DIRECTORY)
- return (expanded ? openDirIcon : dirIcon);
- else if(file.type == VFS.DirectoryEntry.FILESYSTEM)
- return filesystemIcon;
- else
- return fileIcon;
- } //}}}
- //}}}
- }