79 lines
1.7 KiB
Java
79 lines
1.7 KiB
Java
package ecoparasite.svg.elements;
|
|
|
|
import ecoparasite.svg.Coordonnees;
|
|
|
|
import java.util.Locale;
|
|
|
|
/**
|
|
* Élement qui permet de générer un texte sur le SVG.
|
|
*/
|
|
public class Text extends Element {
|
|
|
|
private String text;
|
|
private String color;
|
|
private int size;
|
|
|
|
/**
|
|
* Constructeur
|
|
* @param coordonnees Les coordonnées du texte
|
|
* @param text
|
|
* @param color Provenant de ElementsFactory
|
|
* @param size La taille du texte
|
|
*/
|
|
public Text(Coordonnees coordonnees, String text, String color, int size) {
|
|
super(coordonnees);
|
|
this.text = text;
|
|
this.color = color;
|
|
this.size = size;
|
|
}
|
|
|
|
public Text(Coordonnees coordonnees, String text) {
|
|
super(coordonnees);
|
|
this.text = text;
|
|
this.color = ElementsFactory.COLOR_BLACK;
|
|
this.size = ElementsFactory.AXES_TEXT_SIZE;
|
|
}
|
|
|
|
public String getText() {
|
|
return text;
|
|
}
|
|
|
|
public void setText(String text) {
|
|
this.text = text;
|
|
}
|
|
|
|
public String getColor() {
|
|
return color;
|
|
}
|
|
|
|
public void setColor(String color) {
|
|
this.color = color;
|
|
}
|
|
|
|
public int getSize() {
|
|
return size;
|
|
}
|
|
|
|
public void setSize(int size) {
|
|
this.size = size;
|
|
}
|
|
|
|
/**
|
|
* Génère la string SVG.
|
|
* @return
|
|
*/
|
|
@Override
|
|
public String toSVG() {
|
|
StringBuilder svg = new StringBuilder();
|
|
svg.append("<text ");
|
|
|
|
String params = String.format(Locale.US,"x=\"%f\" y=\"%f\" fill=\"%s\" font-size=\"%s\"", coordonnees.getX(), coordonnees.getY(), color, size);
|
|
svg.append(params);
|
|
svg.append(" >");
|
|
svg.append( this.text );
|
|
svg.append("</text>");
|
|
return svg.toString();
|
|
}
|
|
|
|
}
|