source: src/main/java/agents/EnterBidDialogOfferForVoting.java@ 126

Last change on this file since 126 was 126, checked in by Aron Hammond, 6 years ago

Added function to calculate opposition to MultiLateralAnalysis.java

Moved code to add RLBOA listeners to RLBOAUtils is misc package

Added input for strategyParameters to SessionPanel (gui)

!! close SessionInfo after tournament; this caused /tmp/ to fill up with GeniusData files

Our own package:

  • Added opponents and strategies that are mentioned in the report
  • Change class hierarchy, agents can now extend from RLBOAagentBilateral to inherit RL functionality.
  • States extend from AbstractState
File size: 5.9 KB
Line 
1package agents;
2
3import java.awt.BorderLayout;
4import java.awt.Color;
5import java.awt.Container;
6import java.awt.FlowLayout;
7import java.awt.Frame;
8
9import javax.swing.JButton;
10import javax.swing.JDialog;
11import javax.swing.JOptionPane;
12import javax.swing.JPanel;
13import javax.swing.JTable;
14import javax.swing.JTextArea;
15import javax.swing.WindowConstants;
16
17import genius.core.Bid;
18import genius.core.actions.Accept;
19import genius.core.actions.EndNegotiation;
20import genius.core.actions.Offer;
21import genius.core.actions.OfferForVoting;
22import genius.core.exceptions.Warning;
23import genius.core.parties.AbstractNegotiationParty;
24import genius.core.utility.AdditiveUtilitySpace;
25
26/**
27 *
28 * @author W.Pasman
29 */
30public class EnterBidDialogOfferForVoting extends JDialog implements
31 EnterBidDialogInterface {
32
33 private static final long serialVersionUID = -8582527630534972706L;
34 private NegoInfo negoinfo; // the table model
35 private genius.core.actions.Action selectedAction;
36 private AbstractNegotiationParty party;
37 private JTextArea negotiationMessages = new JTextArea("NO MESSAGES YET");
38 // Wouter: we have some whitespace in the buttons,
39 // that makes nicer buttons and also artificially increases the window size.
40 private JButton buttonEnd = new JButton("End Negotiation");
41 private JButton buttonBid = new JButton(" Propose ");
42 private JPanel buttonPanel = new JPanel();
43 private JTable BidTable;
44
45 public EnterBidDialogOfferForVoting(AbstractNegotiationParty party,
46 Frame parent, boolean modal, AdditiveUtilitySpace us) throws Exception {
47 super(parent, modal);
48 this.party = party;
49 negoinfo = new NegoProposeOffer(null, null, us);
50 initThePanel();
51 }
52
53 // quick hack.. we can't refer to the Agent's utilitySpace because
54 // the field is protected and there is no getUtilitySpace function either.
55 // therefore the Agent has to inform us when utilspace changes.
56 public void setUtilitySpace(AdditiveUtilitySpace us) {
57 negoinfo.utilitySpace = us;
58 }
59
60 private void initThePanel() {
61 if (negoinfo == null)
62 throw new NullPointerException("negoinfo is null");
63 Container pane = getContentPane();
64 pane.setLayout(new BorderLayout());
65 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
66 setTitle("Choose action for party " + party.getPartyId().toString());
67 // setSize(new java.awt.Dimension(600, 400));
68 // setBounds(0,0,640,480);
69
70 // createFrom north field: the message field
71 pane.add(negotiationMessages, "North");
72
73 // createFrom center panel: the bid table
74 BidTable = new JTable(negoinfo);
75 // BidTable.setModel(negoinfo); // need a model for column size etc...
76 // Why doesn't this work???
77 BidTable.setGridColor(Color.lightGray);
78 JPanel tablepane = new JPanel(new BorderLayout());
79 tablepane.add(BidTable.getTableHeader(), "North");
80 tablepane.add(BidTable, "Center");
81 pane.add(tablepane, "Center");
82 BidTable.setRowHeight(35);
83 // createFrom south panel: the buttons:
84 buttonPanel.setLayout(new FlowLayout());
85 buttonPanel.add(buttonEnd);
86 // buttonPanel.add(buttonSkip);
87 buttonPanel.add(buttonBid);
88 pane.add(buttonPanel, "South");
89 buttonBid.setSelected(true);
90
91 // set action listeners for the buttons
92 buttonBid.addActionListener(new java.awt.event.ActionListener() {
93 public void actionPerformed(java.awt.event.ActionEvent evt) {
94 buttonBidActionPerformed(evt);
95 }
96 });
97 // buttonSkip.addActionListener(new java.awt.event.ActionListener() {
98 // public void actionPerformed(java.awt.event.ActionEvent evt) {
99 // buttonSkipActionPerformed(evt);
100 // }
101 // });
102 buttonEnd.addActionListener(new java.awt.event.ActionListener() {
103 public void actionPerformed(java.awt.event.ActionEvent evt) {
104 buttonEndActionPerformed(evt);
105 }
106 });
107 pack(); // pack will do complete layout, getting all cells etc.
108 }
109
110 private Bid getBid() {
111 Bid bid = null;
112 try {
113 bid = negoinfo.getBid();
114 } catch (Exception e) {
115 JOptionPane.showMessageDialog(null,
116 "There is a problem with your bid: " + e.getMessage());
117 }
118 return bid;
119 }
120
121 private void buttonBidActionPerformed(java.awt.event.ActionEvent evt) {
122
123 Bid bid = getBid();
124 if (bid != null) {
125 selectedAction = new OfferForVoting(party.getPartyId(), bid);
126 setVisible(false);
127 }
128 }
129
130 private void buttonEndActionPerformed(java.awt.event.ActionEvent evt) {
131 System.out.println("End Negotiation performed");
132 selectedAction = new EndNegotiation(party.getPartyId());
133 this.dispose();
134 }
135
136 /**
137 * This is called by UIAgent repeatedly, to ask for next action.
138 *
139 * @param opponentAction
140 * is action done by opponent
141 * @param myPreviousBid
142 * @return our next negotionat action.
143 */
144 public genius.core.actions.Action askUserForAction(
145 genius.core.actions.Action opponentAction, Bid myPreviousBid) {
146
147 setTitle("Choose action for party " + party.getPartyId().toString());
148 negoinfo.lastAccepted = null;
149 if (opponentAction == null) {
150 negotiationMessages.setText("Opponent did not send any action.");
151 }
152 if (opponentAction instanceof Accept) {
153 negotiationMessages.setText("Opponent accepted your last bid!");
154 negoinfo.lastAccepted = myPreviousBid;
155 }
156 if (opponentAction instanceof EndNegotiation) {
157 negotiationMessages.setText("Opponent cancels the negotiation.");
158 }
159 if (opponentAction instanceof Offer) {
160 negotiationMessages.setText("Opponent proposes the following bid:");
161 negoinfo.lastAccepted = ((Offer) opponentAction).getBid();
162 }
163 try {
164 negoinfo.setOurBid(null);
165 } catch (Exception e) {
166 new Warning("error in askUserForAction:", e, true, 2);
167 }
168
169 BidTable.setDefaultRenderer(BidTable.getColumnClass(0),
170 new MyCellRenderer1(negoinfo));
171 BidTable.setDefaultEditor(BidTable.getColumnClass(0), new MyCellEditor(
172 negoinfo));
173
174 pack();
175 setVisible(true); // this returns only after the panel closes.
176 // Wouter: this WILL return normally if Thread is killed, and the
177 // ThreadDeath exception will disappear.
178 return selectedAction;
179 }
180}
181
182/********************************************************/
183
Note: See TracBrowser for help on using the repository browser.