/* Graph class */ package ciips.animation.graph; import java.awt.*; import java.io.*; import java.net.*; import java.util.*; import ciips.animation.tree.Arrow; public class Graph { Node nodes[]; public Edge edges[]; Arrow arrows[]; int n_nodes, n_edges, n_arrows, arrow_status; public int node_cnt, edge_cnt, arrow_cnt; int type; Node source_node; static int padding = 100; public static final int orig_colour = 1; public static final int inter_colour = 2; public static final int final_colour = 3; Color darkGreen = new Color(0, 160, 0); public Graph( int n_nodes, int n_edges, int arrow_status ) { this.n_nodes = n_nodes; this.n_edges = n_edges; this.arrow_status = arrow_status; //System.out.println( "New Graph " + n_nodes + " nodes, " + n_edges + " edges" ); n_arrows = n_edges; nodes = new Node[n_nodes]; edges = new Edge[n_edges]; arrows = new Arrow[n_arrows]; node_cnt = edge_cnt = arrow_cnt = 0; } public void Insert_Ans(Graphics g, int n_id) { int i; for (i = 0; i < node_cnt; i++) { if (nodes[i].Get_ID() == n_id) { nodes[i].Show_Ans(g); break; } } } public void Add_Node( Node n ) { nodes[node_cnt++] = n; //line added for testing purposes //System.out.println( "" + node_cnt ); } public int Node_Cnt( ) { return node_cnt; } public void Add_Edge( Edge edge ) { edges[edge_cnt++] = edge; } public int Edge_Cnt() { return edge_cnt; } public void Add_Arrow( Arrow arrow ) { arrows[arrow_cnt++] = arrow; } public void Draw_Graph( Graphics g, int height, int width ) { int i, j, x; int start_id, end_id, num_arcs = 1; double x_scale, y_scale; int max_x = 0, max_y = 0; if (n_nodes != 0) { for( i=0; i max_x ) max_x = x; x = nodes[i].Mid_Y(); if ( x > max_y ) max_y = x; } x_scale = (double)width / ( max_x + padding ); y_scale = (double)height/ ( max_y + padding ); nodes[0].Set_Scale( x_scale, y_scale ); for( i = 0; i< node_cnt; i++ ) { nodes[i].Draw_Node( g ); } for( i = 0; i< edge_cnt; i++ ) { start_id = edges[i].Get_Start(); end_id = edges[i].Get_End(); for( j = 0; j