2023-09-17 22:13:42 +03:00
|
|
|
package ProjectData.Files.UI;
|
2024-10-07 00:58:29 +03:00
|
|
|
import Common_old.Current;
|
|
|
|
|
import _VisualDVM.Global;
|
|
|
|
|
import Common_old.UI.Themes.VisualiserFonts;
|
|
|
|
|
import Common_old.UI.Trees.StyledTreeCellRenderer;
|
2023-09-17 22:13:42 +03:00
|
|
|
import ProjectData.Files.DBProjectFile;
|
|
|
|
|
import ProjectData.Files.FileState;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.font.TextAttribute;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
//https://kodejava.org/how-do-i-create-jtree-with-different-icons-for-each-node/
|
|
|
|
|
//https://ru.coredump.biz/questions/14968005/dynamically-change-icon-of-specific-nodes-in-jtree
|
|
|
|
|
public class FilesTreeCellRenderer extends StyledTreeCellRenderer {
|
|
|
|
|
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
|
|
|
|
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
|
|
|
|
|
Object o = ((DefaultMutableTreeNode) value).getUserObject();
|
|
|
|
|
if (o instanceof File) {
|
|
|
|
|
//это папка.
|
|
|
|
|
File dir = (File) o;
|
|
|
|
|
setIcon(new ImageIcon(getClass().getResource("/icons/Folder.png")));
|
|
|
|
|
setText(dir.getName());
|
|
|
|
|
setFont(Current.getTheme().Fonts.get(VisualiserFonts.TreePlain));
|
|
|
|
|
} else if (o instanceof DBProjectFile) {
|
|
|
|
|
DBProjectFile file = (DBProjectFile) o;
|
|
|
|
|
if (Global.files_multiselection) {
|
|
|
|
|
setIcon(file.GetSelectionIcon());
|
|
|
|
|
} else {
|
|
|
|
|
setIcon(file.GetIcon());
|
|
|
|
|
}
|
|
|
|
|
setText(file.file.getName());
|
|
|
|
|
if (file.IsMain()) setFont(Current.getTheme().Fonts.get(VisualiserFonts.TreeBold));
|
|
|
|
|
else setFont(Current.getTheme().Fonts.get(VisualiserFonts.TreePlain));
|
|
|
|
|
if (file.state.equals(FileState.Excluded)) {
|
|
|
|
|
Map attributes = getFont().getAttributes();
|
|
|
|
|
attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
|
|
|
|
|
setFont(new Font(attributes));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setForeground(tree.getForeground());
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
}
|