Line | |
---|
1 | package negotiator.onetomany.etc;
|
---|
2 |
|
---|
3 | import java.awt.Canvas;
|
---|
4 | import java.awt.Graphics;
|
---|
5 | import java.util.HashMap;
|
---|
6 |
|
---|
7 | import negotiator.onetomany.DemandPlan;
|
---|
8 | import negotiator.onetomany.Portfolio;
|
---|
9 | import negotiator.onetomany.Product;
|
---|
10 |
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * @author Faria Nassiri-Mofakham
|
---|
14 | *
|
---|
15 | */
|
---|
16 | public 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 | int offset=d/2;
|
---|
37 |
|
---|
38 |
|
---|
39 | for (Product product : p.getDemandPlan().keySet())
|
---|
40 | {
|
---|
41 | Integer q = p.getQuantity(product);
|
---|
42 |
|
---|
43 | System.out.println("For product " + product + ", the quantity I want to draw is: " + q);
|
---|
44 |
|
---|
45 | g.setColor(product.getColor());
|
---|
46 | for (int i=0; i<q; i++)
|
---|
47 | {
|
---|
48 | if (x+2*r+d < g.getClipBounds().width)
|
---|
49 | x += d/2;
|
---|
50 | else
|
---|
51 | {
|
---|
52 | x=xx+d;
|
---|
53 | yOffset+=offset;
|
---|
54 | }
|
---|
55 | g.fillOval(x, g.getClipBounds().y+yOffset, 2*r, 2*r); // it also need to became dynamic
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | x=xx;
|
---|
60 | yOffset+=offset; // no condition for the height ?!
|
---|
61 | }
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | }
|
---|
67 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.