001: package tide.sources;
002:
003: import java.io.*;
004: import java.util.*;
005:
006: import java.awt.*;
007: import java.awt.event.*;
008: import javax.swing.*;
009: import javax.swing.tree.*;
010: import javax.swing.event.*;
011: import javax.swing.border.*;
012:
013: public class LibTreeRenderer extends DefaultTreeCellRenderer {
014:
015: private final SourcesTreeIcon fileIcon = new SourcesTreeIcon(false,
016: UIManager.getFont("Tree.font").getSize() + 2);
017: private final SourcesTreeIcon dirIcon = new SourcesTreeIcon(true,
018: UIManager.getFont("Tree.font").getSize() + 2);
019:
020: public LibTreeRenderer() {
021: super ();
022:
023: fileIcon.doNotDrawCompiledBar = true;
024: dirIcon.doNotDrawCompiledBar = true;
025: }
026:
027: @Override
028: public Component getTreeCellRendererComponent(JTree tree,
029: Object value, boolean selected, boolean expanded,
030: boolean _leaf, int row, boolean hasFocus) {
031:
032: if (value instanceof LibFileItem) {
033: LibFileItem node = (LibFileItem) value;
034: boolean leaf = !node.isDirectory();
035: JLabel comp = (JLabel) super .getTreeCellRendererComponent(
036: tree, value, selected, expanded, leaf, row,
037: hasFocus);
038:
039: fileIcon.setLetter("");
040: dirIcon.setLetter("");
041:
042: if (node.isSourceFile()) {
043: fileIcon.setLetter("S");
044: } else if (node.isClassFile()) {
045: fileIcon.setLetter("C");
046: }
047:
048: boolean isIgnored = node.isIgnored();
049:
050: if (isIgnored) {
051: fileIcon.setIgnored(SourcesTreeIcon.Ignored.Yes); // Recurse ? todo.
052: dirIcon.setIgnored(SourcesTreeIcon.Ignored.Yes);
053: } else {
054: fileIcon.setIgnored(SourcesTreeIcon.Ignored.No); // Recurse ? todo.
055: dirIcon.setIgnored(SourcesTreeIcon.Ignored.No);
056: }
057:
058: if (!node.isDirectory()) {
059: // node is a File
060:
061: comp.setText(node.getName());
062: //fileIcon.setType( node.iconColor );
063: comp.setIcon(fileIcon);
064: return comp;
065: } else {
066: // node is a directory
067:
068: comp.setText(node.getName());
069: //dirIcon.setType( node.iconColor );
070: comp.setIcon(dirIcon);
071:
072: return comp;
073:
074: }
075:
076: } else {
077: // is not a node entry
078: JLabel comp = (JLabel) super .getTreeCellRendererComponent(
079: tree, value, selected, expanded, _leaf, row,
080: hasFocus);
081: return comp;
082: }
083: }
084:
085: /** used for the tree as well as for the history bar
086: */
087: public static void setupIconFor(SourcesTreeIcon icon, LibFileItem sf) {
088: if (sf == null)
089: return;
090:
091: icon.doNotDrawCompiledBar = true;
092: icon.setLetter("");
093: if (sf.isSourceFile()) {
094: icon.setLetter("S");
095: } else if (sf.isClassFile()) {
096: icon.setLetter("C");
097: }
098: }
099:
100: }
|