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: import tide.editor.linemessages.LineMessagesManager;
013:
014: /** colorized files and folders, with compile bar, edit symbol, ignoerd cross, main and executable arrow,
015: * and message point.
016: */
017: public final class SourcesTreeRenderer extends DefaultTreeCellRenderer {
018:
019: private final SourcesTreeIcon fileIcon = new SourcesTreeIcon(false,
020: UIManager.getFont("Tree.font").getSize() + 2);
021: private final SourcesTreeIcon dirIcon = new SourcesTreeIcon(true,
022: UIManager.getFont("Tree.font").getSize() + 2);
023:
024: public SourcesTreeRenderer() {
025: super ();
026: }
027:
028: @Override
029: public Component getTreeCellRendererComponent(JTree tree,
030: Object value, boolean selected, boolean expanded,
031: boolean _leaf, int row, boolean hasFocus) {
032:
033: if (value instanceof SourceFile) {
034: SourceFile node = (SourceFile) value;
035: boolean leaf = !node.isDirectory;
036: JLabel comp = (JLabel) super .getTreeCellRendererComponent(
037: tree, value, selected, expanded, leaf, row,
038: hasFocus);
039:
040: fileIcon.setIgnored(node.getIgnoredType());
041: dirIcon.setIgnored(node.getIgnoredType());
042:
043: fileIcon.setLetter("");
044: dirIcon.setLetter("");
045: if (node.isBeingEdited()) {
046: fileIcon.setLetter("E");
047: dirIcon.setLetter("E");
048: }
049:
050: dirIcon.compiled = node.isCompiled();
051: fileIcon.compiled = node.isCompiled();
052:
053: fileIcon.hasMainMethod = node.sourceFileDependencies.hasStaticMain;
054: fileIcon.isMainProjectClass = node.isProjectMainClass;
055:
056: if (!node.isDirectory) {
057: // node is a File
058: fileIcon.hasMessages = LineMessagesManager
059: .getInstance().hasMessages(node.getJavaName());
060: comp.setText(node.getNodeNameToDisplayInTree());
061: fileIcon.setType(node.iconColor);
062: comp.setIcon(fileIcon);
063: return comp;
064: } else {
065: // node is a directory
066:
067: comp.setText(node.getNodeNameToDisplayInTree());
068: dirIcon.setType(node.iconColor);
069: comp.setIcon(dirIcon);
070:
071: return comp;
072:
073: }
074:
075: } else {
076: // is not a node entry
077: JLabel comp = (JLabel) super .getTreeCellRendererComponent(
078: tree, value, selected, expanded, _leaf, row,
079: hasFocus);
080: return comp;
081: }
082: }
083:
084: /** Used for the tree as well as for the history bar.
085: */
086: public static void setupIconFor(SourcesTreeIcon icon, SourceFile sf) {
087: if (sf == null)
088: return;
089: icon.setLetter("");
090: if (sf.isBeingEdited()) {
091: icon.setLetter("E");
092: }
093: icon.compiled = sf.isCompiled();
094: icon.setIgnored(sf.getIgnoredType());
095: icon.setType(sf.iconColor);
096: icon.hasMainMethod = sf.sourceFileDependencies.hasStaticMain;
097: icon.isMainProjectClass = sf.isProjectMainClass;
098: }
099:
100: }
|