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

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

GUI updated (using Jpanel). DemandPlanDrawing updated. PutImaged renamed to DrawImage. DemandPlan is updating for the Utility, Bid, and Preference classes. Protocol and Agents packages (and some classes) added.

File size: 1.4 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 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.