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