ProjektGraph/visualizationElements/Vertex.java
2024-07-02 21:13:30 +02:00

160 lines
2.8 KiB
Java

package visualizationElements;
import java.awt.*;
/**
* 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);
}
}