Dateien nach "visualizationElements" hochladen

This commit is contained in:
Jonathan-Kalmbach 2024-07-10 05:57:39 +00:00
parent d27d48f734
commit 83f12115f3
2 changed files with 180 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}