ProjektGraph/graph/MarkedEdge.java
2024-07-09 15:51:40 +02:00

99 lines
2.4 KiB
Java

package graph;
import java.awt.Color;
/**
* The MarkedEdge class extends the Edge class and includes additional attributes
* for marking and visualization on a screen. It supports constructors to initialize
* these attributes and provides getter and setter methods for accessing and modifying them.
*
* @param <U> A type that extends EdgeMarking, used for marking the edge.
*/
public class MarkedEdge<U extends EdgeMarking> extends Edge {
// ATTRIBUTES
private U marking;
private visualizationElements.Edge screenEdge;
// CONSTRUCTORS
/**
* Default constructor initializes the edge with default values.
*/
public MarkedEdge() {
super();
this.screenEdge = new visualizationElements.Edge(null, null);
}
/**
* Constructor initializes the edge with a name, vertices, and marking.
*
* @param s The name of the edge.
* @param n1 The source vertex of the edge.
* @param n2 The destination vertex of the edge.
* @param u The marking of the edge.
*/
public MarkedEdge(String s, Vertex n1, Vertex n2, U u) {
super(s, n1, n2);
this.marking = u;
EdgeWeightMarking m = (EdgeWeightMarking) this.marking;
this.screenEdge = new visualizationElements.Edge(
n1.getScreenVertex(),
n2.getScreenVertex(),
Integer.toString(m.getWeight()),
Color.BLACK);
}
// GETTERS
/**
* Gets the marking of the edge.
*
* @return The marking of the edge.
*/
public U getMarking() {
return this.marking;
}
/**
* Gets the screen edge used for visualization.
*
* @return The screen edge.
*/
public visualizationElements.Edge getScreenEdge() {
return this.screenEdge;
}
// SETTERS
/**
* Sets the marking of the edge.
*
* @param u The new marking of the edge.
*/
public void setMarking(U u) {
this.marking = u;
EdgeWeightMarking m = (EdgeWeightMarking) this.marking;
this.screenEdge.setMarking(Integer.toString(m.getWeight()));
}
// OUTPUT
/**
* Returns a string representation of the MarkedEdge.
*
* @return A string representing the MarkedEdge.
*/
@Override
public String toString() {
return "MarkedEdge " + this.getName() + " from " + this.getSource().getName() + " to " + this.getDestination().getName();
}
}