ProjektGraph/graph/MarkedVertex.java

138 lines
3.3 KiB
Java
Raw Normal View History

2024-06-15 14:48:28 +00:00
package graph;
2024-07-02 22:46:21 +00:00
import java.awt.*;
2024-07-07 21:07:56 +00:00
/**
* 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
2024-06-15 14:48:28 +00:00
private T marking;
2024-07-02 22:46:21 +00:00
private int xCord;
private int yCord;
private visualizationElements.Vertex screenVertex;
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
// CONSTRUCTORS
2024-06-15 14:48:28 +00:00
2024-07-07 21:07:56 +00:00
/**
* Default constructor initializes the vertex with default values.
*/
2024-06-15 14:48:28 +00:00
public MarkedVertex() {
super();
2024-07-02 22:46:21 +00:00
this.screenVertex = new visualizationElements.Vertex(0, 0);
this.xCord = 0;
this.yCord = 0;
2024-06-15 14:48:28 +00:00
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* Constructor initializes the vertex with a name and marking.
*
* @param s The name of the vertex.
* @param t The marking of the vertex.
*/
2024-06-15 14:48:28 +00:00
public MarkedVertex(String s, T t) {
super(s);
this.marking = t;
2024-07-06 19:08:54 +00:00
this.screenVertex = new visualizationElements.Vertex(0, 0);
2024-07-02 22:46:21 +00:00
this.xCord = 0;
this.yCord = 0;
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* 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);
2024-07-02 22:46:21 +00:00
this.marking = t;
this.screenVertex = new visualizationElements.Vertex(xCord, yCord, name, color);
2024-07-02 22:46:21 +00:00
this.xCord = xCord;
this.yCord = yCord;
2024-06-15 14:48:28 +00:00
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
// GETTERS
2024-06-15 14:48:28 +00:00
2024-07-07 21:07:56 +00:00
/**
* Gets the marking of the vertex.
*
* @return The marking of the vertex.
*/
2024-06-15 14:48:28 +00:00
public T getMarking() {
return this.marking;
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* Gets the screen vertex used for visualization.
*
* @return The screen vertex.
*/
2024-07-02 22:46:21 +00:00
public visualizationElements.Vertex getScreenVertex() {
return this.screenVertex;
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* Gets the coordinates of the vertex.
*
* @return An array containing the x and y coordinates of the vertex.
*/
2024-07-02 22:46:21 +00:00
public int[] getCords() {
return new int[]{this.xCord, this.yCord};
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
// SETTERS
2024-07-02 22:46:21 +00:00
2024-07-07 21:07:56 +00:00
/**
* Sets the marking of the vertex.
*
* @param t The new marking of the vertex.
*/
2024-06-15 14:48:28 +00:00
public void setMarking(T t) {
this.marking = t;
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
/**
* 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.
*/
2024-07-02 22:46:21 +00:00
public void setCords(int[] cords) {
this.xCord = cords[0];
this.yCord = cords[1];
this.screenVertex.setXpos(cords[0]);
this.screenVertex.setYpos(cords[1]);
}
2024-07-07 22:11:04 +00:00
2024-07-07 21:07:56 +00:00
// OUTPUT
2024-07-02 22:46:21 +00:00
2024-07-07 21:07:56 +00:00
/**
* Returns a string representation of the MarkedVertex.
*
* @return A string representing the MarkedVertex.
*/
@Override
2024-06-15 14:48:28 +00:00
public String toString() {
return "MarkedVertex " + this.getName();
2024-06-15 14:48:28 +00:00
}
}