source: src/main/java/negotiator/onetomany/etc/DemandPlanDrawing.java@ 225

Last change on this file since 225 was 225, checked in by Faria Nassiri Mofakham, 6 years ago

DemandPlanDrawing updated.

File size: 1.3 KB
Line 
1package negotiator.onetomany.etc;
2
3import java.awt.Canvas;
4import java.awt.Graphics;
5import java.util.HashMap;
6
7import negotiator.onetomany.DemandPlan;
8import negotiator.onetomany.Portfolio;
9import negotiator.onetomany.Product;
10
11
12/**
13 * @author Faria Nassiri-Mofakham
14 *
15 */
16public class DemandPlanDrawing extends Canvas
17{
18
19 private static final long serialVersionUID = 1L;
20 DemandPlan p;
21
22 public DemandPlanDrawing(DemandPlan p2)
23 {
24 p = p2;
25 }
26
27
28 public void paint(Graphics g)
29 {
30 int z = p.getDemandPlan().size();
31 int yOffset=50;
32 int r=30/z;
33 int d=(g.getClipBounds().width-z*2*r)/(z+4); // it is enough to be divided by z+1, but for making the distance smaller, larger numbers are better
34 int x = g.getClipBounds().x;//+ d;
35 final int xx =x;
36
37 for (Product product : p.getDemandPlan().keySet())
38 {
39 Integer q = p.getQuantity(product);
40
41 System.out.println("For product " + product + ", the quantity I want to draw is: " + q);
42
43 g.setColor(product.getColor());
44 for (int i=0; i<q; i++)
45 {
46 if (x+2*r+d < g.getClipBounds().width)
47 x += d;
48 else
49 {
50 x=xx+d;
51 yOffset+=50;
52 }
53 g.fillOval(x, g.getClipBounds().y+yOffset, 2*r, 2*r); // it also need to became dynamic
54
55 }
56
57 x=xx;
58 yOffset+=50; // no condition for the height ?!
59 }
60
61 }
62
63
64}
65
Note: See TracBrowser for help on using the repository browser.