source: src/main/java/negotiator/onetomany/GUI.java@ 228

Last change on this file since 228 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: 5.2 KB
Line 
1package negotiator.onetomany;
2
3import java.awt.Canvas;
4import java.awt.Color;
5import java.awt.Font;
6
7import javax.swing.BorderFactory;
8import javax.swing.JButton;
9import javax.swing.JFrame;
10import javax.swing.JLabel;
11import javax.swing.JPanel;
12
13import negotiator.onetomany.etc.PortfolioDrawing;
14import negotiator.onetomany.etc.DemandPlanDrawing;
15import negotiator.onetomany.etc.Line;
16import negotiator.onetomany.etc.DrawImage;
17import net.miginfocom.swing.MigLayout;
18
19/**
20 * @author Faria Nassiri-Mofakham
21 *
22 */
23public class GUI extends JFrame
24{
25 Main main;
26 private static final long serialVersionUID = -5602032021645365870L;
27
28
29 public GUI(Main m) //throws MalformedURLException, IOException
30 {
31 super("Bob gets ready for negotiation ...");
32 main = m;
33
34
35 // Show the GUI
36 setLayout(new MigLayout("", "", ""));
37
38 // Could not `resize' and show small CWI-ACUMEX QR-code
39// Canvas canvas00 = new PutImage("C:\\Users\\fnm\\Pictures\\qr_code.png");
40// canvas00.setBounds(0,0,50,50);
41// canvas00.setSize(50, 50);
42// add(canvas00);
43
44
45 // how to change to url address of Bob ? "./NegotiatorGUI/src/main/java/negotiator/onetomany/etc/Bob.png"
46 Canvas canvas0 = new DrawImage("C:\\Users\\fnm\\eclipse-workspace\\NegotiatorGUI\\src\\main\\java\\negotiator\\onetomany\\etc\\Bob.png");
47// Canvas canvas0 = new Bob("NegotiatorGUI.src.main.java.negotiator.onetomany.etc.Bob.png");
48 canvas0.setSize(400, 200);
49 add(canvas0, "cell 0 0, span 1 4, growx, center"); //cannot make it center
50
51 //defining a font
52 Font f1 = new Font("TimesRoman",Font.BOLD,20);
53 Font f2 = new Font("TimesRoman",Font.ITALIC,20);
54 Font f3 = new Font("TimesRoman",Font.PLAIN,16);
55
56
57// JLabel l1 = new JLabel("The `Agent' receives Bob's PORTFOLIO containing "+m.getPortfolio().size()+" different products as follows:");
58 JLabel l1 = new JLabel("Bob's PORTFOLIO contains "+m.getPortfolio().size()+" different products as follows:");
59 l1.setFont(f1);
60
61 add(l1, "cell 1 1, center, width 100:550:1000, wrap"); // no notice to min and max constraints for column width, just the preferred (the middle number)
62
63
64 JPanel panel1 = new JPanel();
65 panel1.setForeground(Color.WHITE);
66 panel1.setFont(f3);
67
68 panel1.setBorder(BorderFactory.createTitledBorder("Portfolio"));
69 panel1.setBackground(Color.decode("#5C8585"));
70 Canvas canvas1 = new PortfolioDrawing(m.getPortfolio());
71 canvas1.setBackground(Color.decode("#5C8585"));
72 canvas1.setSize(550, 200);
73 panel1.add(canvas1);
74 add(panel1, "cell 1 2, growx, center, wrap");
75
76
77
78// Canvas canvas1 = new PortfolioDrawing(m.getPortfolio());
79// canvas1.setBackground(Color.decode("#5C8585"));
80// canvas1.setSize(200, 200);
81// add(canvas1, "cell 1 2, growx, center, wrap");
82
83 add(new JLabel(" "), "center, wrap");
84
85
86
87
88 //a line
89 int w = (canvas0.getWidth()+canvas1.getWidth())*3; // doesn't calculate dynamically well!
90
91
92
93
94
95 Canvas canvas2 = new Line(Color.BLACK,w);
96 canvas2.setSize(1, 1);
97 add(canvas2, "span 2 0, growx, center, wrap");
98
99 add(new JLabel(" "), "center, wrap");
100
101
102// JLabel l2 = new JLabel("It also receives Bob's DEMAND PLAN as follows:");
103 JLabel l2 = new JLabel("And his DEMAND has been planed as the following quantities:");
104 l2.setFont(f1);
105
106 add(l2, "span 2 0, center, wrap");
107
108
109
110
111 add(new JLabel(" "), "center, wrap");
112
113 JLabel n = new JLabel(m.getDemandPlan().toString());
114 n.setFont(f2);
115 add(n, "span 2 0, center, wrap");
116
117
118 JPanel panel2 = new JPanel();
119 //panel2.setFont(f1);
120 panel2.setBackground(Color.WHITE);
121 panel2.setBorder(BorderFactory.createTitledBorder("Demand Plan"));
122 Canvas canvas3 = new DemandPlanDrawing(m.getDemandPlan());
123 canvas3.setBackground(Color.WHITE);
124 canvas3.setSize(800, 300);
125 panel2.add(canvas3);
126 add(panel2, "span 2 0, growx, growy, center, wrap");
127
128
129
130// Canvas canvas3 = new DemandPlanDrawing(m.getDemandPlan());
131// canvas3.setBackground(Color.WHITE);
132// canvas3.setSize(200, 400);
133// add(canvas3, "span 2 0, growx, growy, center, wrap");
134
135
136
137
138
139 add(new JLabel(" "), "span 2 0, center, wrap");
140
141 //a line
142// Canvas canvas4 = new Line(Color.BLACK,w);
143// canvas4.setSize(1, 1);
144// add(canvas4, "span 2 0, growx, center, wrap");
145
146 add(new JLabel(" "), "span 2 0, center, wrap");
147
148 //buttons
149
150 add(new JButton("Edit..."), "cell 0 12, span 2 0, center, w 90"); // at dynamic position ? for the height ?! by canvases heights, or counting the rows and columns?
151 add(new JButton("Delete..."), "cell 0 12, span 2 0, center, w 90");
152 add(new JButton("Next..."), "cell 0 12, span 2 0, center, w 90");
153 add(new JButton("Close"), "cell 0 12, span 2 0, center, wrap, w 90");
154
155 //setting the background as the Bob's image
156 getContentPane().setBackground(Color.decode("#AFD6D6"));
157
158 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
159 pack();
160
161 setLocationRelativeTo(null);
162// Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
163// setBounds(0,0,screenSize.width, screenSize.height);
164
165 setVisible(true);
166 }
167
168 /**
169 * @param args
170 */
171 public static void main(String[] args)
172 {
173 Main main = new Main();
174 GUI gui = new GUI(main);
175
176 }
177
178}
179
180
Note: See TracBrowser for help on using the repository browser.