View Javadoc
1 /*** 2 * Copyright (c) 2003 held jointly by the individual authors. 3 * 4 * This library is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU Lesser General Public License as published 6 * by the Free Software Foundation; either version 2.1 of the License, or 7 * (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; with out even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this library; if not, write to the Free Software Foundation, 16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 17 * 18 * > http://www.gnu.org/copyleft/lesser.html 19 * > http://www.opensource.org/licenses/lgpl-license.php 20 */ 21 package net.mlw.gfw.ext.card.component; 22 23 import java.awt.GridBagConstraints; 24 import java.awt.HeadlessException; 25 import java.awt.Insets; 26 import java.awt.event.ActionEvent; 27 import java.awt.event.ActionListener; 28 import java.util.Iterator; 29 30 import javax.swing.JButton; 31 import javax.swing.JDialog; 32 import javax.swing.JFrame; 33 import javax.swing.JLabel; 34 import javax.swing.JPanel; 35 import javax.swing.JScrollPane; 36 import javax.swing.JSpinner; 37 import javax.swing.JTable; 38 import javax.swing.SpinnerNumberModel; 39 import javax.swing.table.DefaultTableModel; 40 41 import net.mlw.gfw.client.ClientContext; 42 import net.mlw.gfw.event.Event; 43 import net.mlw.gfw.ext.basic.client.component.BaseJPanel; 44 import net.mlw.gfw.ext.card.Bid; 45 import net.mlw.gfw.ext.card.event.BidEvent; 46 47 /*** 48 * @author Matthew L. Wilson 49 * @version $Revision: 1.3 $ $Date: 2004/06/29 20:32:56 $ 50 */ 51 public class BidPanel extends BaseJPanel 52 { 53 private final SpinnerNumberModel bidModel = new SpinnerNumberModel(70, 70, 180, 5); 54 private final JSpinner bidSpinner = new JSpinner(bidModel); 55 56 private String[] titles = { "Name", "Bid" }; 57 private DefaultTableModel history = new DefaultTableModel(titles, 0); 58 59 private final JButton passButton = new JButton("Pass"); 60 private final JButton bidButton = new JButton("Bid"); 61 62 private JDialog dialog; 63 64 private ClientContext context; 65 66 /*** 67 * @param owner 68 * @param title 69 * @param modal 70 * @throws HeadlessException 71 */ 72 public BidPanel(JFrame parent, String title, boolean modal) throws HeadlessException 73 { 74 dialog = new JDialog(parent, title, modal); 75 dialog.getContentPane().add(this); 76 dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 77 } 78 79 /*** 80 * @see net.mlw.gfw.client.ClientEventHandler#init(net.mlw.gfw.client.ClientContext) 81 */ 82 public void init(final ClientContext context) 83 { 84 this.context = context; 85 setLayout(new java.awt.GridBagLayout()); 86 87 JTable table = new JTable(history); 88 table.setEnabled(false); 89 90 add( 91 new JScrollPane(table), 92 new GridBagConstraints(0, 0, 2, 1, 1, .7, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(1, 5, 1, 5), 1, 1)); 93 94 add(new JLabel("Bid:"), new GridBagConstraints(0, 1, 1, 1, 1, .1, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1, 5, 1, 5), 1, 1)); 95 96 add(bidSpinner, new GridBagConstraints(1, 1, 1, 1, 1, .1, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(1, 5, 1, 5), 1, 1)); 97 98 JPanel buttons = new JPanel(); 99 100 passButton.addActionListener(new ActionListener() 101 { 102 public void actionPerformed(ActionEvent e) 103 { 104 getEventHandlers().onEvent(new BidEvent(new Bid(context.getUserName(), Bid.PASSED))); 105 } 106 }); 107 108 bidButton.addActionListener(new ActionListener() 109 { 110 public void actionPerformed(ActionEvent e) 111 { 112 getEventHandlers().onEvent(new BidEvent(new Bid(context.getUserName(), ((Number) bidModel.getValue()).intValue()))); 113 } 114 }); 115 116 buttons.add(passButton); 117 buttons.add(bidButton); 118 119 add(buttons, new GridBagConstraints(0, 2, 2, 1, 1, .1, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1, 5, 1, 5), 1, 1)); 120 121 dialog.setSize(260, 200); 122 setEnabled(false); 123 } 124 125 /*** 126 * @see net.mlw.gfw.event.EventHandler#onEvent(net.mlw.gfw.event.Event) 127 */ 128 public void onEvent(Event event) 129 { 130 BidEvent be = (BidEvent) event; 131 Integer minBid = new Integer(be.getMinimum()); 132 bidModel.setMinimum(minBid); 133 bidModel.setValue(minBid); 134 135 int i = 0; 136 Object[][] values = new Object[be.getBids().size()][2]; 137 for (Iterator bids = be.getBids().iterator(); bids.hasNext(); i++) 138 { 139 Bid bid = (Bid) bids.next(); 140 values[i][0] = bid.getUserName(); 141 if (bid.getBid() > 0) 142 { 143 values[i][1] = new Integer(bid.getBid()); 144 } 145 else 146 { 147 values[i][1] = "pass"; 148 } 149 } 150 151 setEnabled(context.getUserName().equals(be.getUserName())); 152 153 history.setDataVector(values, titles); 154 155 dialog.setVisible(true); 156 } 157 158 public void setEnabled(boolean enabled) 159 { 160 passButton.setEnabled(enabled); 161 bidButton.setEnabled(enabled); 162 bidSpinner.setEnabled(enabled); 163 } 164 165 public JDialog toJDialog() 166 { 167 return dialog; 168 } 169 170 }

This page was automatically generated by Maven