source: exampleparties/humangui/src/main/java/geniusweb/exampleparties/humangui/HumanGui.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 2.9 KB
Line 
1package geniusweb.exampleparties.humangui;
2
3import java.awt.BorderLayout;
4import java.util.Arrays;
5import java.util.Collections;
6import java.util.HashSet;
7import java.util.logging.Level;
8
9import javax.swing.JFrame;
10import javax.swing.WindowConstants;
11
12import geniusweb.actions.Action;
13import geniusweb.actions.Offer;
14import geniusweb.inform.ActionDone;
15import geniusweb.inform.Finished;
16import geniusweb.inform.Inform;
17import geniusweb.inform.Settings;
18import geniusweb.inform.YourTurn;
19import geniusweb.party.Capabilities;
20import geniusweb.party.DefaultParty;
21import geniusweb.party.Party;
22import geniusweb.profile.Profile;
23import geniusweb.profileconnection.ProfileConnectionFactory;
24import geniusweb.profileconnection.ProfileInterface;
25import tudelft.utilities.logging.Reporter;
26
27/**
28 * A {@link Party} that shows a GUI to the user showing the last received offer
29 * and allowing the user to enter his own bid, make an offer or accept the
30 * received offer. The GUI is shown on the window attached to the machine where
31 * the party runs, so this usually will be on the partyserver. Therefore the
32 * users usually will install a partyserver on their local machine to use this
33 * party.
34 */
35public class HumanGui extends DefaultParty {
36
37 private JFrame frame;
38 private BiddingInfo biddinginfo;
39
40 public HumanGui() {
41 }
42
43 public HumanGui(Reporter reporter) {
44 super(reporter); // for debugging
45 }
46
47 @Override
48 public void notifyChange(Inform info) {
49 try {
50 if (info instanceof Settings) {
51 Settings settings = (Settings) info;
52 ProfileInterface profileint = ProfileConnectionFactory
53 .create(settings.getProfile().getURI(), reporter);
54 biddinginfo = new BiddingInfo(settings, getConnection(),
55 getReporter(), profileint);
56 initGUI();
57 } else if (info instanceof ActionDone) {
58 Action otheract = ((ActionDone) info).getAction();
59 if (otheract instanceof Offer) {
60 biddinginfo.receivedOffer((Offer) otheract);
61 }
62 } else if (info instanceof YourTurn) {
63 biddinginfo.setMyTurn(true);
64 } else if (info instanceof Finished) {
65 getReporter().log(Level.INFO, "Final ourcome:" + info);
66 if (frame != null)
67 frame.setVisible(false);
68 }
69 } catch (Exception e) {
70 throw new RuntimeException("Failed to handle info", e);
71 }
72 }
73
74 private void initGUI() {
75 frame = new JFrame("Negotiation for " + biddinginfo.getMyId());
76 frame.getContentPane().setLayout(new BorderLayout());
77 frame.add(new MyGUI(biddinginfo), BorderLayout.CENTER);
78 frame.pack();
79 // we could do frame.addWindowListener but that's a lot of code..
80 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
81 frame.setVisible(true);
82 }
83
84 @Override
85 public Capabilities getCapabilities() {
86 return new Capabilities(new HashSet<>(Arrays.asList("SAOP")),
87 Collections.singleton(Profile.class));
88 }
89
90 @Override
91 public String getDescription() {
92 return "Offers a GUI to the human owning the partiesserver to manually make offers";
93 }
94
95}
Note: See TracBrowser for help on using the repository browser.