ProjektGraph/graph/MarkedEdge.java

94 lines
2.4 KiB
Java
Raw Normal View History

2024-06-15 14:48:28 +00:00
package graph;
2024-07-03 17:41:46 +00:00
import java.awt.*;
2024-07-07 21:07:56 +00:00
/**
* 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 {
2024-06-15 14:48:28 +00:00
2024-07-07 21:07:56 +00:00
// ATTRIBUTES
2024-06-15 14:48:28 +00:00
private U marking;
2024-07-02 22:46:21 +00:00
private visualizationElements.Edge screenEdge;
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 edge with default values.
*/
2024-06-15 14:48:28 +00:00
public MarkedEdge() {
super();
2024-07-02 22:46:21 +00:00
this.screenEdge = new visualizationElements.Edge(null, null);
2024-06-15 14:48:28 +00:00
}
2024-07-07 21:07:56 +00:00
/**
* 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.
*/
2024-06-15 14:48:28 +00:00
public MarkedEdge(String s, Vertex n1, Vertex n2, U u) {
super(s, n1, n2);
this.marking = u;
2024-07-07 14:29:45 +00:00
EdgeWeightMarking m = (EdgeWeightMarking) this.marking;
2024-07-07 21:07:56 +00:00
this.screenEdge = new visualizationElements.Edge(
n1.getScreenVertex(),
n2.getScreenVertex(),
Integer.toString(m.getWeight()),
Color.BLACK);
2024-06-15 14:48:28 +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 edge.
*
* @return The marking of the edge.
*/
2024-06-15 14:48:28 +00:00
public U getMarking() {
return this.marking;
}
2024-07-07 21:07:56 +00:00
/**
* Gets the screen edge used for visualization.
*
* @return The screen edge.
*/
2024-07-02 22:46:21 +00:00
public visualizationElements.Edge getScreenEdge() {
return this.screenEdge;
}
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 edge.
*
* @param u The new marking of the edge.
*/
2024-06-15 14:48:28 +00:00
public void setMarking(U u) {
this.marking = u;
2024-07-07 14:29:45 +00:00
EdgeWeightMarking m = (EdgeWeightMarking) this.marking;
this.screenEdge.setMarking(Integer.toString(m.getWeight()));
2024-06-15 14:48:28 +00:00
}
2024-07-07 21:07:56 +00:00
// OUTPUT
2024-06-15 14:48:28 +00:00
2024-07-07 21:07:56 +00:00
/**
* Returns a string representation of the MarkedEdge.
*
* @return A string representing the MarkedEdge.
*/
@Override
2024-06-15 14:48:28 +00:00
public String toString() {
return "MarkedEdge " + this.getName() + " from " + this.getSource().getName() + " to " + this.getDestination().getName();
2024-06-15 14:48:28 +00:00
}
}
2024-07-07 21:07:56 +00:00