View Javadoc

1   /*
2    * All Rights Reserved.
3    * Copyright (C) 1999-2005 Tsukuba Bunko.
4    *
5    * Licensed under the BSD License ("the License"); you may not use
6    * this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *       http://www.tsukuba-bunko.org/licenses/LICENSE.txt
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   * $Id: Actor.java,v 1.2 2005/07/23 18:52:15 ppoi Exp $
18   */
19  package tsukuba_bunko.peko.canvas.stage;
20  
21  import	java.awt.Image;
22  
23  import	java.io.Serializable;
24  
25  
26  /***
27   * 舞台上の登場人物です。
28   * @author	$Author: ppoi $
29   * @version	$Revision: 1.2 $
30   */
31  public class Actor	implements Serializable	{
32  
33  	/***
34  	 * serial version UID
35  	 */
36  	private static final long	serialVersionUID	= 2277045062381106716L;
37  
38  	/***
39  	 * 立ち位置:中央
40  	 */
41  	public static final int	POSITION_CENTER = 0;
42  
43  	/***
44  	 * 立ち位置:左
45  	 */
46  	public static final int	POSITION_LEFT = 1;
47  
48  	/***
49  	 * 立ち位置:右
50  	 */
51  	public static final int	POSITION_RIGHT = 2;
52  
53  	/***
54  	 * 立ち位置:絶対指定
55  	 */
56  	public static final int	POSITION_ABSOLUTE = 3;
57  
58  
59  	/***
60  	 * 人物名
61  	 */
62  	private String	_name = null;
63  
64  	/***
65  	 * 描画イメージ名
66  	 */
67  	private String	_looks = null;
68  
69  	/***
70  	 * 描画イメージ
71  	 */
72  	transient private Image	_looksImage = null;
73  
74  	/***
75  	 * 立ち位置
76  	 */
77  	private int	_position = Actor.POSITION_CENTER;
78  
79  	/***
80  	 * 立ち位置の絶対位置
81  	 */
82  	private float	_absolutePosition = 0.0f;
83  
84  
85  	/***
86  	 * <code>Actor</code> のインスタンスを作成します。
87  	 * @param	name	人物名
88  	 * @throws	IllegalArgumentException	<code>name</code> が <code>null</code> の場合
89  	 */
90  	public Actor( String name )
91  	{
92  		super();
93  		if( name == null )	{
94  			throw new IllegalArgumentException( "name is not specified." );
95  		}
96  		_name = name;
97  	}
98  
99  
100 	/***
101 	 * 人物名を取得します。
102 	 * @return	人物名
103 	 */
104 	public String getName()
105 	{
106 		return _name;
107 	}
108 
109 	/***
110 	 * 表情(立ち絵)を設定します。
111 	 * @param	looks	表情(立ち絵)
112 	 */
113 	public void setLooks( String looks )
114 	{
115 		ImageManager	images = ImageManager.getInstance();
116 		if( (_looks != null) && _looks.equals(looks) )	{
117 			if( _looksImage == null )	{
118 				setLooksImage( images.getImage(looks, true) );
119 			}
120 		}
121 		else	{
122 			if( _looksImage != null )	{
123 				images.putImage( _looks, _looksImage );
124 			}
125 			setLooksImage( images.getImage(looks, true) );
126 		}
127 		_looks = looks;
128 	}
129 
130 	/***
131 	 * 表情(立ち絵)を取得します。
132 	 * @return	表情(立ち絵)
133 	 */
134 	public String getLooks()
135 	{
136 		return _looks;
137 	}
138 
139 	/***
140 	 * 表情(立ち絵)画像を設定します。
141 	 * @param	looks	表情(立ち絵)
142 	 */
143 	public void setLooksImage( Image looks )
144 	{
145 		_looksImage = looks;
146 	}
147 
148 	/***
149 	 * 表情(立ち絵)画像を取得します。
150 	 * @return	表情(立ち絵)
151 	 */
152 	public Image getLooksImage()
153 	{
154 		return _looksImage;
155 	}
156 
157 	/***
158 	 * 立ち位置を設定します。
159 	 * @param	position	立ち位置。{@link #POSITION_CENTER}, {@link #POSITION_LEFT}, {@link #POSITION_RIGHT} から選択します。
160 	 */
161 	public void setPosition( int position )
162 	{
163 		if( (position == Actor.POSITION_CENTER) || (position == Actor.POSITION_LEFT) || (position == Actor.POSITION_RIGHT) )	{
164 			_position = position;
165 		}
166 		else	{
167 			throw new IllegalArgumentException( "invalid position type is specified." );
168 		}
169 	}
170 
171 	/***
172 	 * 立ち位置を絶対指定で設定します。
173 	 * @param	absolutePosition	絶対指定された立ち位置
174 	 */
175 	public void setPosition( float absolutePosition )
176 	{
177 		_position = Actor.POSITION_ABSOLUTE;
178 		_absolutePosition = absolutePosition;
179 	}
180 
181 	/***
182 	 * 立ち位置を取得します。
183 	 * @return	立ち位置
184 	 */
185 	public int getPosition()
186 	{
187 		return _position;
188 	}
189 
190 	/***
191 	 * 立ち位置の絶対位置を取得します。
192 	 * @return	絶対指定された立ち位置
193 	 */
194 	public float getAbsolutePosition()
195 	{
196 		return _absolutePosition;
197 	}
198 
199 	/***
200 	 * この Actor を破棄します。
201 	 */
202 	void disposeLooks()
203 	{
204 		if( _looksImage != null )	{
205 			ImageManager	images = ImageManager.getInstance();
206 			images.putImage( _looks, _looksImage );
207 			_looksImage = null;
208 		}
209 	}
210 
211 	/***
212 	 */
213 	void prepare()
214 	{
215 		setLooks( _looks );
216 	}
217 
218 
219 	/***
220 	 * 現在の状態を <code>actor</code> にコピーします。
221 	 * @param	actor	コピー先の Actor オブジェクト
222 	 */
223 	public void copyTo( Actor actor )
224 	{
225 		actor._name = _name;
226 		actor._looksImage = _looksImage;
227 		actor._looks = _looks;
228 		actor._position = _position;
229 		actor._absolutePosition = _absolutePosition;
230 	}
231 }