001    /**
002     * Created by IntelliJ IDEA.
003     * User: Wei Wang
004     * Date: Feb 26, 2003
005     * Time: 7:58:18 PM
006     */
007    
008    package EVolve.util.painters.placements;
009    
010    import java.awt.Rectangle;
011    import java.util.ArrayList;
012    import java.util.HashMap;
013    
014    import EVolve.exceptions.NoDataPlotException;
015    import EVolve.util.painters.shapes.Shape;
016    import EVolve.visualization.AutoImage;
017    
018    public abstract class Placement{
019        public static final int INDENT = 50;
020        protected int shapeSize = 10;
021        protected HashMap parties[];
022    
023        public Placement() {
024            parties = new HashMap[2];
025        }
026    
027        public void categorize(AutoImage image, int consumer_type) {
028            int w = image.getW(), h = image.getH();
029    
030            parties[0] = new HashMap();
031            parties[1] = new HashMap();
032    
033            for (int j=0; j<h; j++) {
034                for (int i=0; i<w; i++) {
035                    Object value = image.getColor(i,j);
036                    if (value == null) continue;
037                    for (int k=0; k<((ArrayList)value).size(); k++) {
038                        Shape consumer = (Shape)((ArrayList)value).get(k);
039                        if (consumer.getEntityType() == consumer_type) {
040                            parties[1].put(new Integer(parties[1].size()),consumer);
041                            break;
042                        }
043                    }
044                }
045            }
046    
047    
048            for (int i=0; i<w; i++) {
049                for (int j=0; j<h; j++) {
050                    Object value = image.getColor(i,j);
051                    if (value == null) continue;
052                    for (int k=0; k<((ArrayList)value).size(); k++) {
053                        Shape producer = (Shape)((ArrayList)value).get(k);
054                        if (producer.getEntityType() != consumer_type) {
055                            parties[0].put(new Integer(parties[0].size()),producer);
056                            break;
057                        }
058                    }
059                }
060            }
061    
062        }
063    
064        public abstract String getName();
065    
066        public abstract Rectangle initialPlacement(AutoImage image) throws NoDataPlotException;
067    }