1 17 18 package com.finalist.jaggenerator; 19 20 import com.finalist.jaggenerator.modules.*; 21 22 import javax.swing.tree.DefaultTreeCellRenderer ; 23 import javax.swing.*; 24 import java.awt.*; 25 26 31 public class JagTreeCellRenderer extends DefaultTreeCellRenderer { 32 ImageIcon relationIcon; 33 ImageIcon entityIcon; 34 ImageIcon associationEntityIcon; 35 ImageIcon sessionIcon; 36 ImageIcon configIcon; 37 ImageIcon rootIcon; 38 ImageIcon businessMethodIcon; 39 ImageIcon fieldIcon; 40 ImageIcon pkFieldIcon; 41 42 public JagTreeCellRenderer() { 43 relationIcon = new ImageIcon("../images/relation.png"); 44 entityIcon = new ImageIcon("../images/entity.png"); 45 associationEntityIcon = new ImageIcon("../images/associationEntity.png"); 46 sessionIcon = new ImageIcon("../images/session.png"); 47 configIcon = new ImageIcon("../images/config.png"); 48 rootIcon = new ImageIcon("../images/root.png"); 49 businessMethodIcon = new ImageIcon("../images/business.png"); 50 fieldIcon = new ImageIcon("../images/field.png"); 51 pkFieldIcon = new ImageIcon("../images/pkfield.png"); 52 } 53 54 public Component getTreeCellRendererComponent(JTree tree, 55 Object value, 56 boolean sel, 57 boolean expanded, 58 boolean leaf, 59 int row, 60 boolean hasFocus) { 61 super.getTreeCellRendererComponent(tree, value, sel, 62 expanded, leaf, row, 63 hasFocus); 64 super.setIcon(rootIcon); 65 66 if (leaf && value instanceof Relation) { 67 setIcon(relationIcon); 68 } 69 if (leaf && value instanceof BusinessMethod) { 70 setIcon(businessMethodIcon); 71 } 72 else if (value instanceof Entity) { 73 if ("true".equals(((Entity) value).getIsAssociationEntity())) { 74 setIcon(associationEntityIcon); 75 } else { 76 setIcon(entityIcon); 77 } 78 } 79 else if (value instanceof Session) { 80 setIcon(sessionIcon); 81 } 82 else if (leaf && value instanceof Config) { 83 setIcon(configIcon); 84 } 85 else if (leaf && value instanceof App) { 86 setIcon(configIcon); 87 } 88 else if (leaf && value instanceof Datasource) { 89 setIcon(configIcon); 90 } 91 else if (leaf && value instanceof Paths) { 92 setIcon(configIcon); 93 } 94 else if (leaf && value instanceof Field) { 95 if ( ((Field) value).isPrimaryKey() ) { 96 setIcon(pkFieldIcon); 97 } else { 98 setIcon(fieldIcon); 99 } 100 } 101 return this; 102 } 103 104 } 105 | Popular Tags |