2024-10-09 22:21:57 +03:00
|
|
|
package _VisualDVM.ProjectData.Files.UI;
|
2024-10-14 18:41:02 +03:00
|
|
|
import Common.MainModule_;
|
2024-10-08 22:33:49 +03:00
|
|
|
import Common.Visual.Fonts.VisualiserFonts;
|
2024-10-09 20:35:18 +03:00
|
|
|
import Common.Visual.Trees.StyledTreeCellRenderer;
|
2024-10-14 15:19:13 +03:00
|
|
|
import Common.Visual.UI_;
|
|
|
|
|
import _VisualDVM.Global;
|
2024-10-09 22:21:57 +03:00
|
|
|
import _VisualDVM.ProjectData.Files.DBProjectFile;
|
|
|
|
|
import _VisualDVM.ProjectData.Files.FileState;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
|
|
|
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());
|
2024-10-14 18:41:02 +03:00
|
|
|
setFont(MainModule_.instance.getUI().getTheme().Fonts.get(VisualiserFonts.TreePlain));
|
2023-09-17 22:13:42 +03:00
|
|
|
} else if (o instanceof DBProjectFile) {
|
|
|
|
|
DBProjectFile file = (DBProjectFile) o;
|
|
|
|
|
if (Global.files_multiselection) {
|
|
|
|
|
setIcon(file.GetSelectionIcon());
|
|
|
|
|
} else {
|
|
|
|
|
setIcon(file.GetIcon());
|
|
|
|
|
}
|
|
|
|
|
setText(file.file.getName());
|
2024-10-14 18:41:02 +03:00
|
|
|
if (file.IsMain()) setFont(MainModule_.instance.getUI().getTheme().Fonts.get(VisualiserFonts.TreeBold));
|
|
|
|
|
else setFont(MainModule_.instance.getUI().getTheme().Fonts.get(VisualiserFonts.TreePlain));
|
2023-09-17 22:13:42 +03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|