source: src/main/java/negotiator/parties/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 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.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)
47 throws Exception {
48 super(parent, modal);
49 this.party = party;
50 negoinfo = new NegoProposeOffer(null, null, us);
51 initThePanel();
52 }
53
54 // quick hack.. we can't refer to the Agent's utilitySpace because
55 // the field is protected and there is no getUtilitySpace function either.
56 // therefore the Agent has to inform us when utilspace changes.
57 public void setUtilitySpace(AdditiveUtilitySpace us) {
58 negoinfo.utilitySpace = us;
59 }
60
61 private void initThePanel() {
62 if (negoinfo == null)
63 throw new NullPointerException("negoinfo is null");
64 Container pane = getContentPane();
65 pane.setLayout(new BorderLayout());
66 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
67 setTitle("Choose action for party " + party.getPartyId().toString());
68 // setSize(new java.awt.Dimension(600, 400));
69 // setBounds(0,0,640,480);
70
71 // createFrom north field: the message field
72 pane.add(negotiationMessages, "North");
73
74 // createFrom center panel: the bid table
75 BidTable = new JTable(negoinfo);
76 // BidTable.setModel(negoinfo); // need a model for column size etc...
77 // Why doesn't this work???
78 BidTable.setGridColor(Color.lightGray);
79 JPanel tablepane = new JPanel(new BorderLayout());
80 tablepane.add(BidTable.getTableHeader(), "North");
81 tablepane.add(BidTable, "Center");
82 pane.add(tablepane, "Center");
83 BidTable.setRowHeight(35);
84 // createFrom south panel: the buttons:
85 buttonPanel.setLayout(new FlowLayout());
86 buttonPanel.add(buttonEnd);
87 // buttonPanel.add(buttonSkip);
88 buttonPanel.add(buttonBid);
89 pane.add(buttonPanel, "South");
90 buttonBid.setSelected(true);
91
92 // set action listeners for the buttons
93 buttonBid.addActionListener(new java.awt.event.ActionListener() {
94 public void actionPerformed(java.awt.event.ActionEvent evt) {
95 buttonBidActionPerformed(evt);
96 }
97 });
98 // buttonSkip.addActionListener(new java.awt.event.ActionListener() {
99 // public void actionPerformed(java.awt.event.ActionEvent evt) {
100 // buttonSkipActionPerformed(evt);
101 // }
102 // });
103 buttonEnd.addActionListener(new java.awt.event.ActionListener() {
104 public void actionPerformed(java.awt.event.ActionEvent evt) {
105 buttonEndActionPerformed(evt);
106 }
107 });
108 pack(); // pack will do complete layout, getting all cells etc.
109 }
110
111 private Bid getBid() {
112 Bid bid = null;
113 try {
114 bid = negoinfo.getBid();
115 } catch (Exception e) {
116 JOptionPane.showMessageDialog(null,
117 "There is a problem with your bid: " + e.getMessage());
118 }
119 return bid;
120 }
121
122 private void buttonBidActionPerformed(java.awt.event.ActionEvent evt) {
123
124 Bid bid = getBid();
125 if (bid != null) {
126 selectedAction = new OfferForVoting(party.getPartyId(), bid);
127 setVisible(false);
128 }
129 }
130
131 private void buttonEndActionPerformed(java.awt.event.ActionEvent evt) {
132 System.out.println("End Negotiation performed");
133 selectedAction = new EndNegotiation(party.getPartyId());
134 this.dispose();
135 }
136
137 /**
138 * This is called by UIAgent repeatedly, to ask for next action.
139 *
140 * @param opponentAction
141 * is action done by opponent
142 * @param myPreviousBid
143 * @return our next negotionat action.
144 */
145 public genius.core.actions.Action askUserForAction(
146 genius.core.actions.Action opponentAction, Bid myPreviousBid) {
147
148 setTitle("Choose action for party " + party.getPartyId().toString());
149 negoinfo.lastAccepted = null;
150 if (opponentAction == null) {
151 negotiationMessages.setText("Opponent did not send any action.");
152 }
153 if (opponentAction instanceof Accept) {
154 negotiationMessages.setText("Opponent accepted your last bid!");
155 negoinfo.lastAccepted = myPreviousBid;
156 }
157 if (opponentAction instanceof EndNegotiation) {
158 negotiationMessages.setText("Opponent cancels the negotiation.");
159 }
160 if (opponentAction instanceof Offer) {
161 negotiationMessages.setText("Opponent proposes the following bid:");
162 negoinfo.lastAccepted = ((Offer) opponentAction).getBid();
163 }
164 try {
165 negoinfo.setOurBid(null);
166 } catch (Exception e) {
167 new Warning("error in askUserForAction:", e, true, 2);
168 }
169
170 BidTable.setDefaultRenderer(BidTable.getColumnClass(0),
171 new MyCellRenderer1(negoinfo));
172 BidTable.setDefaultEditor(BidTable.getColumnClass(0), new MyCellEditor(
173 negoinfo));
174
175 pack();
176 setVisible(true); // this returns only after the panel closes.
177 // Wouter: this WILL return normally if Thread is killed, and the
178 // ThreadDeath exception will disappear.
179 return selectedAction;
180 }
181}
182
183/********************************************************/
184
Note: See TracBrowser for help on using the repository browser.