View Javadoc

1   /*
2    * Created on Nov 16, 2004 
3    * Original filename was TooltipFilter.java
4    * 
5    *   Magic-Project is a turn based strategy simulator
6    *   Copyright (C) 2003-2007 Fabrice Daugan
7    *
8    *   This program is free software; you can redistribute it and/or modify it 
9    * under the terms of the GNU General Public License as published by the Free 
10   * Software Foundation; either version 2 of the License, or (at your option) any
11   * later version.
12   *
13   *   This program is distributed in the hope that it will be useful, but WITHOUT 
14   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
16   * details.
17   *
18   *   You should have received a copy of the GNU General Public License along  
19   * with this program; if not, write to the Free Software Foundation, Inc., 
20   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   * 
22   */
23  package net.sf.magicproject.ui;
24  
25  import java.io.IOException;
26  import java.io.InputStream;
27  
28  import net.sf.magicproject.clickable.targetable.card.MCard;
29  import net.sf.magicproject.test.Test;
30  import net.sf.magicproject.test.TestFactory;
31  import net.sf.magicproject.tools.Log;
32  
33  /***
34   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
35   * @since 0.80
36   */
37  public class TooltipFilter {
38  
39  	/***
40  	 * <ul>
41  	 * Structure of stream : Data[size]
42  	 * <li>display powerANDtoughness yes=1,no=0 [1]</li>
43  	 * <li>display states yes=1,no=0 [1]</li>
44  	 * <li>display types yes=1,no=0 [1]</li>
45  	 * <li>display colors yes=1,no=0 [1]</li>
46  	 * <li>display properties yes=1,no=0 [1]</li>
47  	 * <li>display damage yes=1,no=0 [1]</li>
48  	 * <li>filter [...]</li>
49  	 * </ul>
50  	 * 
51  	 * @param inputFile
52  	 *          file containing the states picture
53  	 * @throws IOException
54  	 *           If some other I/O error occurs
55  	 */
56  	public TooltipFilter(InputStream inputFile) throws IOException {
57  		powerANDtoughness = inputFile.read() == 1;
58  		states = inputFile.read() == 1;
59  		types = inputFile.read() == 1;
60  		colors = inputFile.read() == 1;
61  		properties = inputFile.read() == 1;
62  		damage = inputFile.read() == 1;
63  		test = TestFactory.readNextTest(inputFile);
64  	}
65  
66  	/***
67  	 * The instance of TooltipFilter containing all fields set to
68  	 * <code>true</code>
69  	 */
70  	public static TooltipFilter fullInstance = new TooltipFilter();
71  
72  	/***
73  	 * Creates a new instance of TooltipFilter with all displayed information <br>
74  	 */
75  	private TooltipFilter() {
76  		powerANDtoughness = true;
77  		states = true;
78  		types = true;
79  		colors = true;
80  		properties = true;
81  		damage = true;
82  	}
83  
84  	/***
85  	 * Return true if this tooltip can be displayed for this specified card.
86  	 * 
87  	 * @param card
88  	 *          the tested card.
89  	 * @return true if this tooltip can be displayed for this specified card.
90  	 */
91  	public boolean suits(MCard card) {
92  		try {
93  			return test.test(null, card);
94  		} catch (NullPointerException e) {
95  			Log
96  					.error("Test of tooltip filter should 'onTestedCard'. Fix this error and rebuild this TBS\n\t error : "
97  							+ e.getStackTrace()[0]);
98  			return false;
99  		}
100 	}
101 
102 	/***
103 	 * Are the power / toughness displayed
104 	 */
105 	public boolean powerANDtoughness;
106 
107 	/***
108 	 * Are the states displayed
109 	 */
110 	public boolean states;
111 
112 	/***
113 	 * Are the types displayed
114 	 */
115 	public boolean types;
116 
117 	/***
118 	 * Are the properties displayed
119 	 */
120 	public boolean properties;
121 
122 	/***
123 	 * Are the colors displayed
124 	 */
125 	public boolean colors;
126 
127 	/***
128 	 * Are the damage displayed
129 	 */
130 	public boolean damage;
131 
132 	/***
133 	 * The filtering test of this tooltip.
134 	 */
135 	public Test test;
136 
137 }