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