| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.cb.cardboard.AbstractCardBoardModel |
|
|
| 1 | // START LICENSE |
|
| 2 | // JSet - a Java JSet card board game implementation |
|
| 3 | // Copyright (C) 2004 Jerome Lacoste |
|
| 4 | // |
|
| 5 | // This program is free software; you can redistribute it and/or modify |
|
| 6 | // it under the terms of the GNU General Public License as published by |
|
| 7 | // the Free Software Foundation; either version 2 of the License, or (at |
|
| 8 | // your option) any later version. |
|
| 9 | // |
|
| 10 | // This program is distributed in the hope that it will be useful, but |
|
| 11 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 | // General Public License for more details. |
|
| 14 | // |
|
| 15 | // You should have received a copy of the GNU General Public License |
|
| 16 | // along with this program; if not, write to the Free Software |
|
| 17 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 18 | // END LICENSE |
|
| 19 | ||
| 20 | package org.cb.cardboard; |
|
| 21 | ||
| 22 | import java.util.List; |
|
| 23 | import java.util.ArrayList; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * Abstract CardBoardModel implementation. |
|
| 27 | * |
|
| 28 | * Provides methods to register remove listeners. |
|
| 29 | * |
|
| 30 | * @author jerome@coffeebreaks.org - last modified by $LastModifiedBy$ |
|
| 31 | * @version $Id: AbstractCardBoardModel.java 83 2004-04-13 13:51:09Z jerome $ |
|
| 32 | */ |
|
| 33 | 1 | public abstract class AbstractCardBoardModel implements CardBoardModel |
| 34 | { |
|
| 35 | /** the list of listeners. */ |
|
| 36 | 1 | private final List _boardListeners = new ArrayList(); |
| 37 | ||
| 38 | ||
| 39 | /** |
|
| 40 | * Adds the specified listener to the instance's listener's list. |
|
| 41 | * @param listener the listener to add |
|
| 42 | */ |
|
| 43 | public void addBoardDataListener(final CardBoardModelListener listener) |
|
| 44 | { |
|
| 45 | 0 | _boardListeners.add(listener); |
| 46 | 0 | } |
| 47 | ||
| 48 | /** |
|
| 49 | * Removes the specified listener to the instance's listener's list. |
|
| 50 | * @param listener the listener to remove |
|
| 51 | */ |
|
| 52 | public void removeBoardDataListener(final CardBoardModelListener listener) |
|
| 53 | { |
|
| 54 | 0 | _boardListeners.remove(listener); |
| 55 | 0 | } |
| 56 | ||
| 57 | /** |
|
| 58 | * Fire the specified contents changed event |
|
| 59 | * @param event |
|
| 60 | * @see CardBoardModelListener#contentsChanged(org.cb.cardboard.CardBoardEvent) |
|
| 61 | */ |
|
| 62 | protected final void fireContentsChanged(class="keyword">final CardBoardEvent event) |
|
| 63 | { |
|
| 64 | 17 | if (_boardListeners != null) |
| 65 | { |
|
| 66 | 17 | for (int i = 0; i < _boardListeners.size(); i++) |
| 67 | { |
|
| 68 | 0 | final CardBoardModelListener boardListenerIF = (CardBoardModelListener) _boardListeners.get(i); |
| 69 | 0 | boardListenerIF.contentsChanged(event); |
| 70 | } |
|
| 71 | } |
|
| 72 | 17 | } |
| 73 | ||
| 74 | /** |
|
| 75 | * Fire the specified interval added event |
|
| 76 | * @param event |
|
| 77 | * @see CardBoardModelListener#intervalAdded(org.cb.cardboard.CardBoardEvent) |
|
| 78 | */ |
|
| 79 | protected final void fireIntervalAdded(class="keyword">final CardBoardEvent event) |
|
| 80 | { |
|
| 81 | 1 | if (_boardListeners != null) |
| 82 | { |
|
| 83 | 1 | for (int i = 0; i < _boardListeners.size(); i++) |
| 84 | { |
|
| 85 | 0 | final CardBoardModelListener boardListenerIF = (CardBoardModelListener) _boardListeners.get(i); |
| 86 | 0 | boardListenerIF.intervalAdded(event); |
| 87 | } |
|
| 88 | } |
|
| 89 | 1 | } |
| 90 | ||
| 91 | /** |
|
| 92 | * Fire the specified interval removed event |
|
| 93 | * @param event |
|
| 94 | * @see CardBoardModelListener#intervalRemoved(org.cb.cardboard.CardBoardEvent) |
|
| 95 | */ |
|
| 96 | protected final void fireIntervalRemoved(class="keyword">final CardBoardEvent event) |
|
| 97 | { |
|
| 98 | 51 | if (_boardListeners != null) |
| 99 | { |
|
| 100 | 51 | for (int i = 0; i < _boardListeners.size(); i++) |
| 101 | { |
|
| 102 | 0 | final CardBoardModelListener boardListenerIF = (CardBoardModelListener) _boardListeners.get(i); |
| 103 | 0 | boardListenerIF.intervalRemoved(event); |
| 104 | } |
|
| 105 | } |
|
| 106 | 51 | } |
| 107 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |