ProjektGraph/graph/MarkedVertex.java
2024-07-08 00:11:04 +02:00

138 lines
3.3 KiB
Java

package graph;
import java.awt.*;
/**
* The MarkedVertex class extends the Vertex class and includes additional attributes
* for marking, coordinates, and visualization on a screen. It supports various
* constructors to initialize these attributes and provides getter and setter methods
* for accessing and modifying them.
*
* @param <T> A type that extends VertexMarking, used for marking the vertex.
*/
public class MarkedVertex<T extends VertexMarking> extends Vertex {
// ATTRIBUTE
private T marking;
private int xCord;
private int yCord;
private visualizationElements.Vertex screenVertex;
// CONSTRUCTORS
/**
* Default constructor initializes the vertex with default values.
*/
public MarkedVertex() {
super();
this.screenVertex = new visualizationElements.Vertex(0, 0);
this.xCord = 0;
this.yCord = 0;
}
/**
* Constructor initializes the vertex with a name and marking.
*
* @param s The name of the vertex.
* @param t The marking of the vertex.
*/
public MarkedVertex(String s, T t) {
super(s);
this.marking = t;
this.screenVertex = new visualizationElements.Vertex(0, 0);
this.xCord = 0;
this.yCord = 0;
}
/**
* Constructor initializes the vertex with coordinates, name, marking, and color.
*
* @param xCord The x-coordinate of the vertex.
* @param yCord The y-coordinate of the vertex.
* @param name The name of the vertex.
* @param t The marking of the vertex.
* @param color The color of the vertex for visualization purposes.
*/
public MarkedVertex(int xCord, int yCord, String name, T t, Color color) {
super(name);
this.marking = t;
this.screenVertex = new visualizationElements.Vertex(xCord, yCord, name, color);
this.xCord = xCord;
this.yCord = yCord;
}
// GETTERS
/**
* Gets the marking of the vertex.
*
* @return The marking of the vertex.
*/
public T getMarking() {
return this.marking;
}
/**
* Gets the screen vertex used for visualization.
*
* @return The screen vertex.
*/
public visualizationElements.Vertex getScreenVertex() {
return this.screenVertex;
}
/**
* Gets the coordinates of the vertex.
*
* @return An array containing the x and y coordinates of the vertex.
*/
public int[] getCords() {
return new int[]{this.xCord, this.yCord};
}
// SETTERS
/**
* Sets the marking of the vertex.
*
* @param t The new marking of the vertex.
*/
public void setMarking(T t) {
this.marking = t;
}
/**
* Sets the coordinates of the vertex and updates the screen vertex's position.
*
* @param cords An array containing the new x and y coordinates of the vertex.
*/
public void setCords(int[] cords) {
this.xCord = cords[0];
this.yCord = cords[1];
this.screenVertex.setXpos(cords[0]);
this.screenVertex.setYpos(cords[1]);
}
// OUTPUT
/**
* Returns a string representation of the MarkedVertex.
*
* @return A string representing the MarkedVertex.
*/
@Override
public String toString() {
return "MarkedVertex " + this.getName();
}
}