225 lines
5.9 KiB
Java
225 lines
5.9 KiB
Java
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<63>fer
|
||
* DHBW Stuttgart/Campus Horb AI2008<br>
|
||
* <br>
|
||
*/
|
||
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<TestLogElement> 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<Vertex> vertexes = new Vector<Vertex>();
|
||
|
||
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<Edge> edges = new Vector<Edge>();
|
||
|
||
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<Integer> valueList = new Vector<Integer>();
|
||
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<Long> values = new Vector<Long>();
|
||
for(int i = 0; i<logList.size(); i++){
|
||
values.add(((TestLogElement) logList.get(i)).getValue());
|
||
}
|
||
|
||
Stack stack = new Stack(values) ;
|
||
stack.draw(g);
|
||
}
|
||
|
||
private void drawQueue(Graphics g) {
|
||
Vector<Long> values = new Vector<Long>();
|
||
for(int i = 0; i<logList.size(); i++){
|
||
values.add(((TestLogElement) logList.get(i)).getValue());
|
||
}
|
||
|
||
Queue queue = new Queue(values);
|
||
queue.draw(g);
|
||
|
||
}
|
||
|
||
private void drawList(Graphics g) {
|
||
|
||
Vector<Long> values = new Vector<Long>();
|
||
for(int i = 0; i<logList.size(); i++){
|
||
values.add(((TestLogElement) logList.get(i)).getValue());
|
||
}
|
||
|
||
List list = new List(values);
|
||
list.draw(g);
|
||
}
|
||
|
||
private void drawHashtable(Graphics g) {
|
||
String[][] array = new String[10][2];
|
||
for(int i = 0; i< logList.size(); i++){
|
||
TestLogElement element = (TestLogElement) logList.get(i);
|
||
|
||
array[i][0] = String.valueOf(element.getValue());
|
||
}
|
||
|
||
for(int i = 0; i< logList.size(); i++){
|
||
TestLogElement element = (TestLogElement) logList.get(i);
|
||
|
||
array[i][1] = String.valueOf(element.getValue());
|
||
}
|
||
|
||
Hashtable table = new Hashtable(array);
|
||
table.draw(g);
|
||
}
|
||
|
||
private void drawChessBoard(Graphics g) {
|
||
boolean[][] board = new boolean[8][8];
|
||
board[0][0]= true;
|
||
board[0][1]= true;
|
||
ChessBoard chessBoard = new ChessBoard(board, this.getWidth(), this.getHeight(), "D");
|
||
chessBoard.draw(g);
|
||
}
|
||
|
||
private void drawTable(Graphics g) {
|
||
String[][] array = new String[10][2];
|
||
for(int i = 0; i< logList.size(); i++){
|
||
TestLogElement element = (TestLogElement) logList.get(i);
|
||
|
||
array[i][0] = String.valueOf(element.getValue());
|
||
}
|
||
|
||
for(int i = 0; i< logList.size(); i++){
|
||
TestLogElement element = (TestLogElement) logList.get(i);
|
||
|
||
array[i][1] = String.valueOf(element.getValue());
|
||
}
|
||
|
||
String[] captions = new String[2];
|
||
captions[0] = "Caption 1";
|
||
captions[1] = "Caption 2";
|
||
Table table = new Table(array, captions, 0, 0);
|
||
table.draw(g);
|
||
}
|
||
|
||
private void drawBarChart(Graphics g) {
|
||
Vector<BarChartElement> valueList = new Vector<BarChartElement>();
|
||
|
||
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);
|
||
|
||
}
|
||
}
|