mappingstreecellrenderer.java
来自「Hibernate开发及整合应用大全 蔡雪焘编著 本书用典型的示例剖析Hiber」· Java 代码 · 共 103 行
JAVA
103 行
/* * Created on 20-04-2003 * */package net.sf.hibernate.console;import java.awt.Color;import java.awt.Component;import javax.swing.JTree;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.TreeCellRenderer;import net.sf.hibernate.console.node.BaseNode;import net.sf.hibernate.console.node.ClassNode;import net.sf.hibernate.console.node.PersistentCollectionNode;import net.sf.hibernate.console.node.TypeNode;import net.sf.hibernate.Hibernate;import net.sf.hibernate.type.PersistentCollectionType;import net.sf.hibernate.type.Type;/** * @author max * */public class MappingsTreeCellRenderer extends DefaultTreeCellRenderer implements TreeCellRenderer { Color defaultForeground; static boolean useFullyQualifiedNames = false; static void setUseFullyQualifiedNames(boolean b) { useFullyQualifiedNames = b; } public 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); setIcon(null); setToolTipText(null); if(value instanceof BaseNode) { setIcon(((BaseNode)value).getIcon()); setText(((BaseNode)value).renderLabel(useFullyQualifiedNames)); } Type type = null; if (value instanceof TypeNode) { TypeNode tn = (TypeNode) value; type = tn.getType(); } else if (value instanceof PersistentCollectionNode) { type = ((PersistentCollectionNode)value).getType(); } if(defaultForeground!=null) { setForeground(defaultForeground); } if (value instanceof ClassNode) { ClassNode cn = (ClassNode)value; if(!Hibernate.isInitialized(cn.getValue())) { if(defaultForeground==null) { defaultForeground = getForeground(); } setForeground(Color.BLUE); } } String s = tooltipForType(type); setToolTipText(s); return this; } /** * @param type * @return */ private String tooltipForType(Type type) { if(type==null) return null; String s = "<html>"; s += "TypeClass: " + type.getClass() + "<br>"; s += "TypeName:" + type.getName() + "<br>"; s += "Association: " + type.isAssociationType() + "<br>"; s += "Component: " + type.isComponentType() + "<br>"; s += "Entity: " + type.isEntityType() + "<br>"; s += "Mutable: " + type.isMutable() + "<br>"; s += "ObjectType: " + type.isObjectType() + "<br>"; s += "PersistentCollection: " + type.isPersistentCollectionType(); if (type.isPersistentCollectionType()) { PersistentCollectionType ptype = (PersistentCollectionType) type; s += "<br>"; s += "Role: " + ptype.getRole() + "<br>"; s += "ForeignKeyDirection:" + ptype.getForeignKeyDirection() ; } return s; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?