1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
   |  
public void draw(Graphics2D g2d, AffineTransform aff, 
	Color shapeBackground, Color shapeOutline, float shapeTransparency, 
	float shapeThickness, float[] shapeStyle, String texturePath, 
	Color splitBackground, Color splitOutline, float splitTransparency) {
 
	/** On affecte la transparence. */
	g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getTransparency()));
 
        /** On crée la rotation permettant de ramener la Shape à une forme droite... */
        double angle = getAngle360(); // retourne l'angle de la forme...
        AffineTransform affInverseRotation = new AffineTransform();
        affInverseRotation.rotate(-angle, getBounds2D().getCenterX(), getBounds2D().getCenterY());
        Shape staightShape = affInverseRotation.createTransformedShape(shape); // shape est la forme à dessiner : celle-ci est déjà tournée mais pas scalée...
 
	/** On crée la Shape modifiée. */
	Shape modifiedShape = aff.createTransformedShape(shape); // on applique le scale à la forme déjà tournée (c'est le contour que l'on va dessiner par la suite)
 
	/** Transformation à appliquer au Graphics : rotation + scale */
	AffineTransform affPlusRotate = new AffineTransform();
	affPlusRotate.concatenate(aff);
	affPlusRotate.rotate(angle, getBounds2D().getCenterX(), getBounds2D().getCenterY());
 
	/** Gestion de la texture. */
	if (getTexturePath() != null && getTexturePath().length() > 0) {
 
    		/** On transforme le Graphics. */
	        	g2d.transform(affPlusRotate);
 
    		/** On affecte la texture. */
    		BufferedImage img;
    		img = ImageFilesReader.read(getTexturePath());
 
	            if (img != null) {
             	            	g2d.setPaint(new TexturePaint(img, staightShape.getBounds2D())); // forme non-tournée, non-scalée!
 
        			/** On remplit la forme non-transformée! */
	            		g2d.fill(staightShape);
	            }
	            else {
            			System.out.println("img == null");
	            }
	}
	else {
	            g2d.setColor(new Color(getBackgroundColorCode()));
		g2d.fill(modifiedShape);
	}
 
	/** On affecte la couleur, la transparence et l'épaisseur du trait */
	g2d.setColor(new Color(getOutlineColorCode()));
	g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
	g2d.setStroke(new BasicStroke(getThickness(), BasicStroke.CAP_ROUND, 
              BasicStroke.JOIN_MITER, 10.0f, getStyle(), 1));
 
	/** On applique la transformation inverse, pour revenir dans la configuration initiale. */
	try {
		g2d.transform(affPlusRotate.createInverse());
	} catch (NoninvertibleTransformException e) {
		e.printStackTrace();
	}
 
	/** On dessine la Shape transformée! */
	g2d.draw(modifiedShape); // g2d est dans sa configuration initiale => on doit dessiner la shape totalement transformée
} |