Begin SVG.
This commit is contained in:
49
src/ecoparasite/svg/elements/Circle.java
Normal file
49
src/ecoparasite/svg/elements/Circle.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package ecoparasite.svg.elements;
|
||||
|
||||
import ecoparasite.svg.Coordonnees;
|
||||
|
||||
public class Circle extends Element {
|
||||
|
||||
private int rayon;
|
||||
private String color;
|
||||
|
||||
public Circle(Coordonnees coordonnees, int rayon, String color) {
|
||||
super(coordonnees);
|
||||
this.rayon = rayon;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Circle(Coordonnees coordonnees, int rayon) {
|
||||
super(coordonnees);
|
||||
this.rayon = rayon;
|
||||
this.color = ElementsFactory.COLOR_RED;
|
||||
}
|
||||
|
||||
public int getRayon() {
|
||||
return rayon;
|
||||
}
|
||||
|
||||
public void setRayon(int rayon) {
|
||||
this.rayon = rayon;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSVG() {
|
||||
StringBuilder svg = new StringBuilder();
|
||||
svg.append("<circle ");
|
||||
|
||||
String str = String.format( "r=\"%d\" cx=\"%d\" cy=\"%d\" fill=\"%s\"", this.rayon, this.coordonnees.getX(), this.coordonnees.getY(), this.color);
|
||||
svg.append( str );
|
||||
svg.append(" />");
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
}
|
||||
31
src/ecoparasite/svg/elements/Element.java
Normal file
31
src/ecoparasite/svg/elements/Element.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package ecoparasite.svg.elements;
|
||||
|
||||
import ecoparasite.svg.Coordonnees;
|
||||
|
||||
abstract public class Element {
|
||||
|
||||
protected Coordonnees coordonnees;
|
||||
|
||||
public Element(Coordonnees coordonnees) {
|
||||
this.coordonnees = coordonnees;
|
||||
}
|
||||
|
||||
public Coordonnees getCoordonnees() {
|
||||
return coordonnees;
|
||||
}
|
||||
|
||||
public void setCoordonnees(Coordonnees coordonnees) {
|
||||
this.coordonnees = coordonnees;
|
||||
}
|
||||
|
||||
public void setCoordonnees(int x, int y) {
|
||||
this.coordonnees = new Coordonnees(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode abstraite qui va permettre de transformer notre élément en SVG.
|
||||
* @return La String SVF
|
||||
*/
|
||||
abstract public String toSVG();
|
||||
|
||||
}
|
||||
68
src/ecoparasite/svg/elements/ElementsFactory.java
Normal file
68
src/ecoparasite/svg/elements/ElementsFactory.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package ecoparasite.svg.elements;
|
||||
|
||||
import ecoparasite.svg.Coordonnees;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ElementsFactory {
|
||||
|
||||
final public static int SVG_SIZE = 800;
|
||||
final public static int SVG_OFFSET = 50;
|
||||
|
||||
final public static int AXES_TEXT_SIZE = 10;
|
||||
|
||||
final public static String COLOR_RED = "red";
|
||||
final public static String COLOR_BLUE = "blue";
|
||||
final public static String COLOR_BLACK = "black";
|
||||
|
||||
/**
|
||||
* Permet de générer les éléments axes du fichier SVG.
|
||||
* @return
|
||||
*/
|
||||
public static ArrayList<Element> SVGAxes(String HName, String VName ){
|
||||
|
||||
final int begin = SVG_OFFSET + AXES_TEXT_SIZE + (AXES_TEXT_SIZE / 2);
|
||||
final int end = SVG_SIZE - SVG_OFFSET - AXES_TEXT_SIZE - (AXES_TEXT_SIZE / 2);
|
||||
|
||||
Element V = new Line(
|
||||
new Coordonnees( begin, begin ),
|
||||
new Coordonnees( begin, SVG_SIZE - SVG_OFFSET ),
|
||||
COLOR_BLACK,
|
||||
2
|
||||
);
|
||||
|
||||
Element H = new Line(
|
||||
new Coordonnees( begin, SVG_SIZE - SVG_OFFSET ),
|
||||
new Coordonnees( end, SVG_SIZE - SVG_OFFSET ),
|
||||
COLOR_BLACK,
|
||||
2
|
||||
);
|
||||
|
||||
Element VLabel = new Text(
|
||||
new Coordonnees( SVG_OFFSET, SVG_OFFSET ),
|
||||
VName,
|
||||
COLOR_BLACK,
|
||||
AXES_TEXT_SIZE
|
||||
);
|
||||
Element HLabel = new Text(
|
||||
new Coordonnees( SVG_SIZE - SVG_OFFSET - AXES_TEXT_SIZE, SVG_SIZE - SVG_OFFSET - AXES_TEXT_SIZE ),
|
||||
HName,
|
||||
COLOR_BLACK,
|
||||
AXES_TEXT_SIZE
|
||||
);
|
||||
|
||||
ArrayList<Element> SVGAxes = new ArrayList<>();
|
||||
SVGAxes.add(V);
|
||||
SVGAxes.add(H);
|
||||
SVGAxes.add(VLabel);
|
||||
SVGAxes.add(HLabel);
|
||||
return SVGAxes;
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<Element> SVGAxes(){
|
||||
return SVGAxes( "None", "None" );
|
||||
}
|
||||
|
||||
}
|
||||
76
src/ecoparasite/svg/elements/Line.java
Normal file
76
src/ecoparasite/svg/elements/Line.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package ecoparasite.svg.elements;
|
||||
|
||||
import ecoparasite.svg.Coordonnees;
|
||||
|
||||
public class Line extends Element {
|
||||
|
||||
private Coordonnees coordonneesB;
|
||||
private String color;
|
||||
private int lineWidth;
|
||||
|
||||
public Line(Coordonnees coordonneesA, Coordonnees coordonneesB, String color, int lineWidth) {
|
||||
super(coordonneesA);
|
||||
this.coordonneesB = coordonneesB;
|
||||
this.color = color;
|
||||
this.lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
public Line(Coordonnees coordonneesA, Coordonnees coordonneesB) {
|
||||
super(coordonneesA);
|
||||
this.coordonneesB = coordonneesB;
|
||||
this.color = ElementsFactory.COLOR_RED;
|
||||
this.lineWidth = 1;
|
||||
}
|
||||
|
||||
public Coordonnees getCoordonneesA() {
|
||||
return coordonnees;
|
||||
}
|
||||
|
||||
public void setCoordonneesA(Coordonnees coordonnees) {
|
||||
this.coordonnees = coordonnees;
|
||||
}
|
||||
|
||||
public Coordonnees getCoordonneesB() {
|
||||
return coordonneesB;
|
||||
}
|
||||
|
||||
public void setCoordonneesB(Coordonnees coordonnees) {
|
||||
this.coordonneesB = coordonnees;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getLineWidth() {
|
||||
return lineWidth;
|
||||
}
|
||||
|
||||
public void setLineWidth(int lineWidth) {
|
||||
this.lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSVG() {
|
||||
StringBuilder svg = new StringBuilder();
|
||||
svg.append("<line ");
|
||||
|
||||
String params = String.format( "x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"stroke:%s;stroke-width:%d\"",
|
||||
this.coordonnees.getX(),
|
||||
this.coordonnees.getY(),
|
||||
this.coordonneesB.getX(),
|
||||
this.coordonneesB.getY(),
|
||||
this.color,
|
||||
this.lineWidth
|
||||
);
|
||||
svg.append(params);
|
||||
svg.append( "/>" );
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
62
src/ecoparasite/svg/elements/Text.java
Normal file
62
src/ecoparasite/svg/elements/Text.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package ecoparasite.svg.elements;
|
||||
|
||||
import ecoparasite.svg.Coordonnees;
|
||||
|
||||
public class Text extends Element {
|
||||
|
||||
private String text;
|
||||
private String color;
|
||||
private int size;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSVG() {
|
||||
StringBuilder svg = new StringBuilder();
|
||||
svg.append("<text ");
|
||||
|
||||
String params = String.format( "x=\"%d\" y=\"%d\" 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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user