001    /**
002     * Created by IntelliJ IDEA.
003     * User: Wei Wang
004     * Date: Feb 26, 2003
005     * Time: 7:57:30 PM
006     */
007    
008    package EVolve.util.painters.placements;
009    
010    import java.awt.Rectangle;
011    
012    import EVolve.util.painters.shapes.Shape;
013    import EVolve.visualization.AutoImage;
014    
015    public class RoundPlacement extends Placement{
016    
017        public RoundPlacement(int shapeSize) {
018            super();
019            this.shapeSize = shapeSize;
020        }
021    
022        public String getName() {
023            return "Round Placement";
024        }
025    
026        public Rectangle initialPlacement(AutoImage image) {
027            int totalShapes = parties[0].size() + parties[1].size();
028            int startX, startY;
029            double angle, radius, delta, x, y;
030    
031            if (parties[0] == parties[1]) totalShapes /= 2;
032    
033            radius = shapeSize/(Math.sin(Math.PI/totalShapes));
034            startX = startY = (int)radius+INDENT;
035            angle = 0;
036            delta = 2*Math.asin(shapeSize/radius);
037    
038            int i = 0,producerSize = parties[0].size();
039            while (i<totalShapes) {
040                for (int j=0; j<parties[i/producerSize].size(); j++) {
041                    Shape object = (Shape)parties[i/producerSize].get(new Integer(j));
042                    x = startX + radius * Math.cos(angle);
043                    y = startY + radius * Math.sin(angle);
044                    object.move((int)x-shapeSize/2,(int)y-shapeSize/2);
045                    angle += delta;
046                }
047                i += parties[i/producerSize].size();
048            }
049            Rectangle bounds = new Rectangle();
050            bounds.height = bounds.width = (int)(radius * 2 + shapeSize + INDENT*2);
051    
052            image.setImageSize(bounds.width, bounds.height);
053    
054            return bounds;
055        }
056    
057    }