1 | package onetomany.etc;
|
---|
2 |
|
---|
3 | import java.awt.Canvas;
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Dimension;
|
---|
6 | import java.awt.Font;
|
---|
7 | import java.awt.Toolkit;
|
---|
8 | import java.awt.image.BufferedImage;
|
---|
9 |
|
---|
10 | import javax.swing.BorderFactory;
|
---|
11 | import javax.swing.JButton;
|
---|
12 | import javax.swing.JFrame;
|
---|
13 | import javax.swing.JLabel;
|
---|
14 | import javax.swing.JPanel;
|
---|
15 |
|
---|
16 | import onetomany.etc.CloseButtonListener;
|
---|
17 | import net.miginfocom.swing.MigLayout;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * @author Faria Nassiri-Mofakham
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public 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 |
|
---|
46 |
|
---|
47 | // how to change to url address of Bob ? "./NegotiatorGUI/src/main/java/negotiator/onetomany/etc/Bob.png"
|
---|
48 | Canvas canvas0 = new DrawImage("C:\\Users\\fnm\\Pictures\\Bob.png");
|
---|
49 | // Canvas canvas0 = new Bob("NegotiatorGUI.src.main.java.negotiator.onetomany.etc.Bob.png");
|
---|
50 | canvas0.setSize(400, 200);
|
---|
51 | add(canvas0, "cell 0 0, span 1 4, growx, center"); //cannot make it center
|
---|
52 |
|
---|
53 | //defining a font
|
---|
54 | Font f1 = new Font("TimesRoman",Font.BOLD,20);
|
---|
55 | Font f2 = new Font("TimesRoman",Font.ITALIC,20);
|
---|
56 | Font f3 = new Font("TimesRoman",Font.PLAIN,16);
|
---|
57 |
|
---|
58 |
|
---|
59 | // JLabel l1 = new JLabel("The `Agent' receives Bob's PORTFOLIO containing "+m.getPortfolio().size()+" different products as follows:");
|
---|
60 | JLabel l1 = new JLabel("Bob's PORTFOLIO contains "+m.getPortfolio().size()+" different products as follows:");
|
---|
61 | l1.setFont(f1);
|
---|
62 |
|
---|
63 | 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)
|
---|
64 |
|
---|
65 |
|
---|
66 | JPanel panel1 = new JPanel();
|
---|
67 | panel1.setForeground(Color.WHITE);
|
---|
68 | panel1.setFont(f3);
|
---|
69 |
|
---|
70 | panel1.setBorder(BorderFactory.createTitledBorder("Portfolio"));
|
---|
71 | panel1.setBackground(Color.decode("#5C8585"));
|
---|
72 | Canvas canvas1 = new PortfolioDrawing(m.getPortfolio());
|
---|
73 | canvas1.setBackground(Color.decode("#5C8585"));
|
---|
74 | canvas1.setSize(550, 200);
|
---|
75 | panel1.add(canvas1);
|
---|
76 | add(panel1, "cell 1 2, growx, center, wrap");
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 | // Canvas canvas1 = new PortfolioDrawing(m.getPortfolio());
|
---|
81 | // canvas1.setBackground(Color.decode("#5C8585"));
|
---|
82 | // canvas1.setSize(200, 200);
|
---|
83 | // add(canvas1, "cell 1 2, growx, center, wrap");
|
---|
84 |
|
---|
85 | add(new JLabel(" "), "center, wrap");
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | //a line
|
---|
91 | int w = (canvas0.getWidth()+canvas1.getWidth())*3; // doesn't calculate dynamically well!
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 | Canvas canvas2 = new Line(Color.BLACK,w);
|
---|
98 | canvas2.setSize(1, 1);
|
---|
99 | add(canvas2, "span 2 0, growx, center, wrap");
|
---|
100 |
|
---|
101 | add(new JLabel(" "), "center, wrap");
|
---|
102 |
|
---|
103 |
|
---|
104 | // JLabel l2 = new JLabel("It also receives Bob's DEMAND PLAN as follows:");
|
---|
105 | JLabel l2 = new JLabel("And his DEMAND has been planed as the following quantities:");
|
---|
106 | l2.setFont(f1);
|
---|
107 |
|
---|
108 | add(l2, "span 2 0, center, wrap");
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 | add(new JLabel(" "), "center, wrap");
|
---|
114 |
|
---|
115 | JLabel n = new JLabel(m.getDemandPlan().toString());
|
---|
116 | n.setFont(f2);
|
---|
117 | add(n, "span 2 0, center, wrap");
|
---|
118 |
|
---|
119 |
|
---|
120 | JPanel panel2 = new JPanel();
|
---|
121 | //panel2.setFont(f1);
|
---|
122 | panel2.setBackground(Color.WHITE);
|
---|
123 | panel2.setBorder(BorderFactory.createTitledBorder("Demand Plan"));
|
---|
124 |
|
---|
125 |
|
---|
126 | //Canvas canvas3 = new DemandPlan(m.getDemandPlan());
|
---|
127 | //canvas3.setBackground(Color.WHITE);
|
---|
128 | //canvas3.setSize(800, 300);
|
---|
129 |
|
---|
130 |
|
---|
131 | //panel2.add(canvas3);
|
---|
132 | //add(panel2, "span 2 0, growx, growy, center, wrap");
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 | // Canvas canvas3 = new DemandPlanDrawing(m.getDemandPlan());
|
---|
137 | // canvas3.setBackground(Color.WHITE);
|
---|
138 | // canvas3.setSize(200, 400);
|
---|
139 | // add(canvas3, "span 2 0, growx, growy, center, wrap");
|
---|
140 |
|
---|
141 |
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 | add(new JLabel(" "), "span 2 0, center, wrap");
|
---|
146 |
|
---|
147 | //a line
|
---|
148 | // Canvas canvas4 = new Line(Color.BLACK,w);
|
---|
149 | // canvas4.setSize(1, 1);
|
---|
150 | // add(canvas4, "span 2 0, growx, center, wrap");
|
---|
151 |
|
---|
152 | add(new JLabel(" "), "span 2 0, center, wrap");
|
---|
153 |
|
---|
154 | //buttons
|
---|
155 |
|
---|
156 | JButton a = new JButton("Edit...");
|
---|
157 | add(a, "cell 0 12, span 2 0, center, w 90");
|
---|
158 | // at dynamic position ? for the height ?! by canvases heights, or counting the rows and columns?
|
---|
159 | JButton b = new JButton("Delete...");
|
---|
160 | add(b, "cell 0 12, span 2 0, center, w 90");
|
---|
161 |
|
---|
162 | add(new JButton("Next..."), "cell 0 12, span 2 0, center, w 90");
|
---|
163 |
|
---|
164 | JButton d = new JButton("Close");
|
---|
165 | d.addActionListener(new CloseButtonListener(this)); // <-- only this was added to this from examples closeButtonListenner and ClosableWindow
|
---|
166 | add(d, "cell 0 12, span 2 0, center, wrap, w 90");
|
---|
167 |
|
---|
168 |
|
---|
169 | //setting the background as the Bob's image
|
---|
170 | getContentPane().setBackground(Color.decode("#AFD6D6"));
|
---|
171 |
|
---|
172 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
173 | pack();
|
---|
174 |
|
---|
175 | setLocationRelativeTo(null);
|
---|
176 | // Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
---|
177 | // setBounds(0,0,screenSize.width, screenSize.height);
|
---|
178 |
|
---|
179 | setVisible(true);
|
---|
180 | }
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * @param args
|
---|
184 | */
|
---|
185 | public static void main(String[] args)
|
---|
186 | {
|
---|
187 | Main main = new Main();
|
---|
188 | GUI gui = new GUI(main);
|
---|
189 |
|
---|
190 | }
|
---|
191 |
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|