From 83f12115f37601cb94e01a9492d223d5cb6a86ab Mon Sep 17 00:00:00 2001 From: Jonathan-Kalmbach Date: Wed, 10 Jul 2024 05:57:39 +0000 Subject: [PATCH] Dateien nach "visualizationElements" hochladen --- visualizationElements/Vertex.java | 160 ++++++++++++++++++ .../VisualizationElement.java | 20 +++ 2 files changed, 180 insertions(+) create mode 100644 visualizationElements/Vertex.java create mode 100644 visualizationElements/VisualizationElement.java diff --git a/visualizationElements/Vertex.java b/visualizationElements/Vertex.java new file mode 100644 index 0000000..bc1d61a --- /dev/null +++ b/visualizationElements/Vertex.java @@ -0,0 +1,160 @@ +package visualizationElements; + +import java.awt.Color; +import java.awt.Graphics; + +/** + * Represents a vertex of a graph to visualize. + * @author MSchaefer + * + */ +public class Vertex { + + private static final String DEFAULT_MARKING = ""; + private static final Color DEFAULT_COLOR = Color.BLACK; + private final int VERTEX_DIAMETER = 20; + private int xpos; + private int ypos; + private String marking; + private Color color; + + /** + * Creates a new Vertex. + * @param xpos X-Position of the vertex. + * @param ypos Y-Position of the vertex. + * @param marking The marking of the vertex. + * @param color Color the vertex is showed. + */ + public Vertex(int xpos, int ypos, String marking, Color color){ + this.setXpos(xpos); + this.setYpos(ypos); + this.setMarking(marking); + this.setColor(color); + } + + + /** + * Creates a new Vertex without marking. + * @param xpos X-Position of the vertex. + * @param ypos Y-Position of the vertex. + * @param color Color the vertex is showed. + */ + public Vertex(int xpos, int ypos, Color color){ + this.xpos = xpos; + this.ypos = ypos; + this.marking = DEFAULT_MARKING; + this.color = color; + } + + + /** + * Creates a new black Vertex. + * @param xpos X-Position of the vertex. + * @param ypos Y-Position of the vertex. + * @param marking The marking of the vertex. + */ + public Vertex(int xpos, int ypos, String marking){ + this.xpos = xpos; + this.ypos = ypos; + this.marking = marking; + this.color = DEFAULT_COLOR; + } + + + /** + * Creates a new black Vertex without marking. + * @param xpos X-Position of the vertex. + * @param ypos Y-Position of the vertex. + */ + public Vertex(int xpos, int ypos){ + this.xpos = xpos; + this.ypos = ypos; + this.marking = DEFAULT_MARKING; + this.color = DEFAULT_COLOR; + } + + + /** + * @param ypos the y position to set + */ + public void setYpos(int ypos) { + this.ypos = ypos; + } + + + /** + * @return the y position + */ + public int getYpos() { + return ypos; + } + + + /** + * @param xpos the x position to set + */ + public void setXpos(int xpos) { + this.xpos = xpos; + } + + + /** + * @return the x position + */ + public int getXpos() { + return xpos; + } + + + /** + * @param color the color to set + */ + public void setColor(Color color) { + this.color = color; + } + + + /** + * @return the color + */ + public Color getColor() { + return color; + } + + + /** + * @param marking + */ + public void setMarking(String marking) { + this.marking = marking; + } + + + /** + * @return the marking + */ + public String getMarking(){ + return this.marking; + } + + + /** + * @return the vERTEX_DIAMETER + */ + public int getVertexDiameter() { + return VERTEX_DIAMETER; + } + + /** + * Draws the vertex. + * @param g Graphics object to draw to the DrawArea + * + */ + public void draw(Graphics g){ + g.setColor(getColor()); + g.fillOval(getXpos(), getYpos(), VERTEX_DIAMETER, VERTEX_DIAMETER); + + g.setColor(Color.BLACK); + g.drawString(getMarking(), getXpos(), getYpos()-5); + } +} diff --git a/visualizationElements/VisualizationElement.java b/visualizationElements/VisualizationElement.java new file mode 100644 index 0000000..bd01c49 --- /dev/null +++ b/visualizationElements/VisualizationElement.java @@ -0,0 +1,20 @@ +/** + * + */ +package visualizationElements; + +import java.awt.Graphics; + +/** + * Represents an graphical element to visualize algorithms and abstract data types + * @author MSchaefer + * + */ +public abstract class VisualizationElement { + + /** + * Draws the visualization element. + * @param g The Graphics object to draw the element to the DrawArea. + */ + public abstract void draw(Graphics g); +}