Перенос.
This commit is contained in:
46
src/ProjectData/Files/UI/FilesTreeCellRenderer.java
Normal file
46
src/ProjectData/Files/UI/FilesTreeCellRenderer.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package ProjectData.Files.UI;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.UI.Themes.VisualiserFonts;
|
||||
import Common.UI.Trees.StyledTreeCellRenderer;
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user