package testApplication; import java.awt.Color; import java.awt.Graphics; import java.util.Vector; import visualisation.DrawArea; import visualizationElements.BarChart; import visualizationElements.BarChartElement; import visualizationElements.ChessBoard; import visualizationElements.DotChart; import visualizationElements.Edge; import visualizationElements.EdgeStyle; import visualizationElements.Graph; import visualizationElements.Hashtable; import visualizationElements.List; import visualizationElements.Maze; import visualizationElements.Queue; import visualizationElements.Stack; import visualizationElements.Table; import visualizationElements.Vertex; import logging.LogElementList; /** * This class provides an example for using visualization.DrawArea. * @see logging.Algorithm @author MSch�fer * DHBW Stuttgart/Campus Horb AI2008
*
*/ public class TestDrawArea extends DrawArea{ private static final long serialVersionUID = 1L; private Maze maze; /** * Standard constructor. */ public TestDrawArea() { super(); } /** * Creates a test draw area and sets the specified log list. * @param logList the draw area's log list test log elements. * @param drawAreaName The display name over the draw area. */ public TestDrawArea(LogElementList logList, String drawAreaName){ super(logList, drawAreaName); this.maze = new Maze(10, 10); } /** * Draws a visualization element. */ public void draw(Graphics g){ //drawBarChart(g); //drawDotChart(g); //drawTable(g); //drawChessBoard(g); //drawHashtable(g); //drawList(g); //drawQueue(g); //drawStack(g); //drawMaze(g, maze); drawGraph(g); } private void drawGraph(Graphics g) { // create/add vertexes Vector vertexes = new Vector(); vertexes.add(new Vertex(20, 20, "1", Color.BLACK)); vertexes.add(new Vertex(80, 20, "2", Color.BLACK)); vertexes.add(new Vertex(100, 80, "3", Color.BLACK)); vertexes.add(new Vertex(180, 60, "4", Color.BLUE)); vertexes.add(new Vertex(20, 80, "5", Color.BLACK)); vertexes.add(new Vertex(120, 140, "6", Color.BLACK)); vertexes.add(new Vertex(20, 180, "7", Color.BLACK)); // create/add edges Vector edges = new Vector(); edges.add(new Edge(vertexes.get(0), vertexes.get(1), "1", Color.WHITE)); edges.add(new Edge(vertexes.get(1), vertexes.get(4), "1", Color.BLACK)); edges.add(new Edge(vertexes.get(0), vertexes.get(4), "1", Color.BLACK)); edges.add(new Edge(vertexes.get(2), vertexes.get(3), "1", Color.BLACK)); edges.add(new Edge(vertexes.get(3), vertexes.get(2), "1", Color.BLACK)); edges.add(new Edge(vertexes.get(4), vertexes.get(6), "1", Color.BLACK)); edges.add(new Edge(vertexes.get(6), vertexes.get(6), "1", Color.BLACK)); // create graph Graph graph = new Graph(vertexes, edges, false, EdgeStyle.Direct); graph.draw(g); } private void drawDotChart(Graphics g) { Vector valueList = new Vector(); for(int i = 0; i< 2*logList.size(); i++){ valueList.add(i); } DotChart dotChart = new DotChart(valueList, this.getHeight(), this.getWidth()); dotChart.draw(g); } private void drawMaze(Graphics g, Maze maze) { maze.draw(g); } private void drawStack(Graphics g) { Vector values = new Vector(); for(int i = 0; i values = new Vector(); for(int i = 0; i values = new Vector(); for(int i = 0; i valueList = new Vector(); for(int i = 0; i< logList.size(); i++){ TestLogElement logElement = (TestLogElement) logList.get(i); BarChartElement barChartElement = new BarChartElement((int) logElement.getValue(), Color.BLUE); valueList.add(barChartElement); } for(int i = 0; i< logList.size(); i++){ TestLogElement logElement = (TestLogElement) logList.get(i); BarChartElement barChartElement = new BarChartElement((int) logElement.getValue(), Color.RED); valueList.add(barChartElement); } BarChart barChart = new BarChart(valueList, this.getWidth(), this.getHeight()); barChart.draw(g); } }