/* -------------------------------------------------------------------------- */ /* */ /* T-TREE CANVAS */ /* */ /* Frans Coenen */ /* */ /* 27 June 2003 */ /* Updates: 8 September 2008. */ /* */ /* Department of Computer Science */ /* The University of Liverpool */ /* */ /* -------------------------------------------------------------------------- */ /** Modules to paint a representation of the T-tree so that all T-tree nodes are placed in an X-Y plane which is then processed and output. */ import java.awt.*; // Java extension packages import javax.swing.*; public class TtreeCanvas extends JPanel { /** 3-D array, indexes: (1) the index for the node, (2) is the Y node index, (3) is an index into the data --- label (item set number), support, node type).

Five types of node: (a) no branches, (b) siblimng branch only, (c) child branch only, (d) sibling and child branches, and (e) vertical arc. */ protected int[][][] nodeArray; /* FIELDS */ /** The width of a single T-tree node. */ protected static final int NODE_WIDTH = 25; /** The height of a single T-tree node. */ protected static final int NODE_HEIGHT = 13; protected static final int ARC_WIDTH = 10; protected static final int ARC_HEIGHT = 10; protected static final int GAP_WIDTH = 28; protected static final int GAP_HEIGHT = 20; protected static final int SPACING_W = NODE_WIDTH+GAP_WIDTH; protected static final int SPACING_H = NODE_HEIGHT+GAP_HEIGHT; protected static final int BORDER = 20; /** Referece to start of T-tree data structure. */ private TtreeNode[] startTtreeRef = null; /** Thr ninmum support threshold value in terms of a number of records. */ protected double minSupport; /* CONSTRUCTORS */ public TtreeCanvas(int numXnodes, int numYnodes, TtreeNode[] tTreeRef, double supp) { super(); startTtreeRef=tTreeRef; minSupport = supp; //System.out.println("TtreeCanvas: numXnodes = " + numXnodes + ", numYnodes = " + //numYnodes); // Initialise node array nodeArray=new int[numXnodes][numYnodes][3]; for (int colIndex=0;colIndex=minSupport) g.setColor(new Color(255,255,204)); else g.setColor(Color.pink); g.fillRoundRect(x,y,NODE_WIDTH,NODE_HEIGHT,ARC_WIDTH,ARC_HEIGHT); g.setColor(Color.red); g.drawRoundRect(x,y,NODE_WIDTH,NODE_HEIGHT,ARC_WIDTH,ARC_HEIGHT); // Label g.setColor(Color.black); Font mono = new Font("Monospaced",Font.BOLD,10); g.setFont(mono); FontMetrics newFM = g.getFontMetrics(mono); int xLength = newFM.stringWidth(label); g.drawString(label,(x+(NODE_WIDTH/2)-(xLength/2)),y+11); // Support double supp=support/100.0; if (supp>=minSupport) g.setColor(Color.blue); else g.setColor(Color.orange); g.drawString(Double.toString(supp),x+NODE_WIDTH,y+NODE_HEIGHT+11); } /* DRAW ARC */ /** Draws arcs between two Ttree nodes according to "type" setting: 0) no arcs, 1) horizontal arc, 2) vertical arc, 3) horizontal and vertical arcs. @param g the graphics context @param x the x coordinate @param y the y coordinate @param i1 the "x" index @param i2 the "y" index @param type the nature of the arc: horizontal, vertical or both. */ private void drawArc(Graphics g, int x, int y, int i1, int i2, int type) { g.setColor(Color.black); // Horizontal arc only if (type==1) g.drawLine(x+NODE_WIDTH/2,y+NODE_HEIGHT/2, x+NODE_WIDTH/2+SPACING_W,y+NODE_HEIGHT/2); // Vertical Arc only if (type==2) { int length=arcVerticalLength(i1,i2); g.drawLine(x+NODE_WIDTH/2,y+NODE_HEIGHT/2,x+NODE_WIDTH/2, y+(length*SPACING_H)+NODE_HEIGHT/2); } // Horizontal and vertical arcs if (type==3) { g.drawLine(x+NODE_WIDTH/2,y+NODE_HEIGHT/2, x+NODE_WIDTH/2+SPACING_W,y+NODE_HEIGHT/2); int length=arcVerticalLength(i1,i2); g.drawLine(x+NODE_WIDTH/2,y+NODE_HEIGHT/2,x+NODE_WIDTH/2, y+(length*SPACING_H)+NODE_HEIGHT/2); } } /* ARC VERTICAL LENGTH */ /** Determines vertical distance of arc in T-tree. @param i1 the "x" index @param i2 the "y" index @retun the length of the vertical arc. */ private int arcVerticalLength(int i1, int i2) { int length=1; // Icrement "Y" index and loop i2++; while(true) { if (nodeArray[i1][i2][0]!=0) break; else { length++; i2++; } } // Return return(length); } /* --------------------------------------------------------- */ /* */ /* POPULATE NODE ARRAY */ /* */ /* --------------------------------------------------------- */ /** @param startColIndex the X index into the node array for the start of the T-tree array (0 at start). @rowIndex rowIndex the Y index unto the node array (current level) for the T-tree array (0 at start). @param treeRef the reference into the current level in the T-tree (top at start). */ protected void populateArray(int startColIndex, int rowIndex, TtreeNode[] treeRef) { // Count number of supported nodes at current level (we do not want // to output unsupported nodes) int numSupportedNodes=0; for(int index=1;index0;index--) { // Check if supported if (treeRef[index]!=null) { // Lable nodeArray[colIndex][rowIndex][0] = index; // support nodeArray[colIndex][rowIndex][1] = (int) ((treeRef[index].support+0.005)*100); // If strat and supported child nodes then type 2 else type 0 if (start) { if (supportedChildNodes(treeRef[index].childRef)) { nodeArray[colIndex][rowIndex][2]=2; populateArray(colIndex,rowIndex+1,treeRef[index].childRef); } else nodeArray[colIndex][rowIndex][2]=0; } // If not start and supported child nodes then type 3, otherwise // type 1. else { if (supportedChildNodes(treeRef[index].childRef)) { nodeArray[colIndex][rowIndex][2]=3; populateArray(colIndex,rowIndex+1,treeRef[index].childRef); } else nodeArray[colIndex][rowIndex][2]=1; } // Decrement volumn index colIndex--; // Set start flag to false start=false; } } } /* CHECK FOR SUPPORT CHILD NODES */ private boolean supportedChildNodes(TtreeNode[] treeRef) { if (treeRef==null) return(false); // Loop for (int index=1;index