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; 22 23 import java.util.ArrayList; 24 import java.util.List; 25 26 import javax.swing.BoundedRangeModel; 27 28 /*** 29 * @author Matthew L. Wilson 30 * @version $Revision: 1.2 $ $Date: 2004/06/29 20:32:54 $ 31 */ 32 public class ScrollableTableModel extends DefaultTableModel 33 { 34 private int maxIndex = 0; 35 private List history = new ArrayList(20); 36 37 private BoundedRangeModel rangeModel; 38 39 /*** 40 * @param numberOfPlayers 41 */ 42 public ScrollableTableModel(BoundedRangeModel rangeModel, int numberOfPlayers) 43 { 44 super(numberOfPlayers); 45 this.rangeModel = rangeModel; 46 history.add(cards); 47 } 48 49 /*** 50 * @return Returns the index. 51 */ 52 public int getIndex() 53 { 54 return rangeModel.getValue(); 55 } 56 57 /*** 58 * @param index The index to set. 59 */ 60 public void setIndex(int index) 61 { 62 rangeModel.setValue(index); 63 } 64 65 /*** 66 * @return Returns the maxIndex. 67 */ 68 public int getMaxIndex() 69 { 70 return maxIndex; 71 } 72 73 /*** 74 * @see net.mlw.gfw.ext.card.TableModel#clear() 75 */ 76 public void clear() 77 { 78 Card[] cards = new Card[super.cards.length]; 79 for (int i = 0; i < cards.length; i++) 80 { 81 cards[i] = super.cards[i]; 82 } 83 84 int max = rangeModel.getMaximum(); 85 history.add(cards); 86 87 rangeModel.setMaximum(max + 1); 88 rangeModel.setValue(max); 89 rangeModel.setMinimum(2); 90 91 super.clear(); 92 } 93 94 /*** 95 * @see net.mlw.gfw.ext.card.TableModel#getCard(int) 96 */ 97 public Card getCard(int seat) 98 { 99 return getCards()[seat]; 100 } 101 102 /*** 103 * @see net.mlw.gfw.ext.card.TableModel#getCards() 104 */ 105 public Card[] getCards() 106 { 107 return (Card[]) history.get(rangeModel.getValue() - 1); 108 } 109 110 }

This page was automatically generated by Maven