Coverage report

  %line %branch
tsukuba_bunko.peko.canvas.stage.Stage
0% 
0% 

 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: Stage.java,v 1.3 2005/08/19 03:18:11 ppoi Exp $
 18  
  */
 19  
 package tsukuba_bunko.peko.canvas.stage;
 20  
 
 21  
 import	java.awt.Color;
 22  
 import	java.awt.Image;
 23  
 
 24  
 import	java.io.Serializable;
 25  
 
 26  
 import	java.util.HashMap;
 27  
 import	java.util.Iterator;
 28  
 import	java.util.Map;
 29  
 
 30  
 import	tsukuba_bunko.peko.Logger;
 31  
 
 32  
 import	tsukuba_bunko.peko.resource.ColorManager;
 33  
 
 34  
 
 35  
 /**
 36  
  * 舞台を表示するキャンバスです。
 37  
  * @author	$Author: ppoi $
 38  
  * @version	$Revision: 1.3 $
 39  
  */
 40  
 public class Stage	implements Serializable	{
 41  
 
 42  
 	/**
 43  
 	 * serial version UID
 44  
 	 */
 45  
 	private static final long	serialVersionUID	= -5885153839184445498L;
 46  
 
 47  
 	/**
 48  
 	 * このステージを描画する StageCanvas
 49  
 	 */
 50  0
 	transient private StageCanvas	_canvas = null;
 51  
 
 52  
 	/**
 53  
 	 * 音楽を再生する AudioPlayer
 54  
 	 */
 55  0
 	private AudioPlayer	_audioPlayer = new AudioPlayer();
 56  
 
 57  
 
 58  
 	/**
 59  
 	 * 登場人物
 60  
 	 */
 61  0
 	transient private Map	_actors = new HashMap();
 62  
 
 63  
 	/**
 64  
 	 * 確定した登場人物
 65  
 	 */
 66  0
 	private HashMap	_committedActors = new HashMap();
 67  
 
 68  
 	/**
 69  
 	 * 背景
 70  
 	 */
 71  0
 	transient private String	_background = null;
 72  
 
 73  
 	/**
 74  
 	 * 確定した背景
 75  
 	 */
 76  0
 	private String	_committedBackground = null;
 77  
 
 78  
 	/**
 79  
 	 * 背景画像
 80  
 	 */
 81  0
 	transient private Image	_backgroundImage = null;
 82  
 
 83  
 	/**
 84  
 	 * 背景色
 85  
 	 */
 86  0
 	transient private Color	_backgroundColor = null;
 87  
 
 88  
 	/**
 89  
 	 * 確定した背景色
 90  
 	 */
 91  0
 	private Color	_committedBackgroundColor = null;
 92  
 
 93  
 	/**
 94  
 	 * スライド名
 95  
 	 */
 96  0
 	transient private String	_slide = null;
 97  
 
 98  
 	/**
 99  
 	 * 確定したスライド名
 100  
 	 */
 101  0
 	private String	_committedSlide = null;
 102  
 
 103  
 	/**
 104  
 	 * スライド画像
 105  
 	 */
 106  0
 	transient private Image	_slideImage = null;
 107  
 
 108  
 
 109  
 	/**
 110  
 	 * <code>Stage</code> のインスタンスを作成します。
 111  
 	 */
 112  
 	public Stage()
 113  
 	{
 114  0
 		super();
 115  0
 	}
 116  
 
 117  
 
 118  
 	/**
 119  
 	 * 人物を舞台に登場させます。
 120  
 	 * @param	actor	人物
 121  
 	 */
 122  
 	public void enter( Actor actor )
 123  
 	{
 124  0
 		_actors.put( actor.getName(), actor );
 125  0
 	}
 126  
 
 127  
 	/**
 128  
 	 * 人物を取得します。
 129  
 	 */
 130  
 	public Actor getName( String name )
 131  
 	{
 132  0
 		return (Actor)_actors.get( name );
 133  
 	}
 134  
 
 135  
 	/**
 136  
 	 * 人物を舞台から退場させます。
 137  
 	 */
 138  
 	public Actor exit( String name )
 139  
 	{
 140  0
 		Actor	actor = (Actor)_actors.remove( name );
 141  0
 		if( actor != null )	{
 142  0
 			actor.disposeLooks();
 143  
 		}
 144  0
 		return actor;
 145  
 	}
 146  
 
 147  
 	/**
 148  
 	 * 全ての人物を舞台から退場させます。
 149  
 	 */
 150  
 	public void exitAll()
 151  
 	{
 152  0
 		String[]	names = (String[])_actors.keySet().toArray( new String[_actors.size()] );
 153  0
 		for( int i = 0; i < names.length; ++i )	{
 154  0
 			exit( names[i] );
 155  
 		}
 156  0
 	}
 157  
 
 158  
 	/**
 159  
 	 * 人物を取得します。
 160  
 	 */
 161  
 	public Actor getActor( String name )
 162  
 	{
 163  0
 		return (Actor)_actors.get( name );
 164  
 	}
 165  
 
 166  
 	/**
 167  
 	 * 人物リストを取得します。
 168  
 	 */
 169  
 	public Map getActors()
 170  
 	{
 171  0
 		return _actors;	//	クローニングした方が良いかも?
 172  
 	}
 173  
 
 174  
 	/**
 175  
 	 * 背景画像を設定します。このメソッドを呼び出すと、背景色は null に設定されます。
 176  
 	 * @param	image	背景画像
 177  
 	 */
 178  
 	public void setBackgroundImage( String image )
 179  
 	{
 180  0
 		ImageManager	images = ImageManager.getInstance();
 181  0
 		if( (_backgroundImage != null) && !_background.equals(image)  )	{
 182  0
 			images.putImage( _background, _backgroundImage );
 183  0
 			_backgroundImage = null;
 184  
 		}
 185  
 
 186  0
 		Image	background = images.getImage( image );
 187  0
 		if( background != null )	{
 188  0
 			_backgroundImage = background;
 189  0
 			_background = image;
 190  0
 			_backgroundColor = null;
 191  0
 		}
 192  0
 		else if( background == null )	{
 193  0
 			Logger.error( "[canvas.stage] invalid background-image :" + image );
 194  0
 			_backgroundColor = Color.black;
 195  0
 			_background = "black";
 196  
 		}
 197  0
 	}
 198  
 
 199  
 	/**
 200  
 	 * 背景画像を取得します。
 201  
 	 * @return	背景画像
 202  
 	 */
 203  
 	public Image getBackgroundImage()
 204  
 	{
 205  0
 		return _backgroundImage;
 206  
 	}
 207  
 
 208  
 	/**
 209  
 	 * 背景色を設定します。このメソッドを呼び出すと、背景画像は null に設定されます。
 210  
 	 * @param	color	背景色
 211  
 	 */
 212  
 	public void setBackgroundColor( String color )
 213  
 	{
 214  0
 		if( _backgroundImage != null )	{
 215  0
 			ImageManager	images = ImageManager.getInstance();
 216  0
 			images.putImage( _background, _backgroundImage );
 217  0
 			_backgroundImage = null;
 218  
 		}
 219  0
 		ColorManager	colors = ColorManager.getInstance();
 220  0
 		_backgroundColor = colors.getColor( color );
 221  0
 		_background = color;
 222  0
 	}
 223  
 
 224  
 	/**
 225  
 	 * 背景色を取得します。
 226  
 	 * @return	背景色
 227  
 	 */
 228  
 	public Color getBackgroundColor()
 229  
 	{
 230  0
 		return _backgroundColor;
 231  
 	}
 232  
 
 233  
 	/**
 234  
 	 * スライドを表示します。
 235  
 	 * @param	slide	スライド名
 236  
 	 */
 237  
 	public void showSlide( String slide )
 238  
 	{
 239  0
 		ImageManager	images = ImageManager.getInstance();
 240  0
 		if( (_slide != null) && !_slide.equals(slide) )	{
 241  0
 			images.putImage( _slide, _slideImage );
 242  
 		}
 243  0
 		_slideImage = images.getImage( slide );
 244  0
 		_slide = slide;
 245  0
 	}
 246  
 
 247  
 	/**
 248  
 	 * スライドを隠します。
 249  
 	 */
 250  
 	public void hideSlide()
 251  
 	{
 252  0
 		if( _slideImage != null )	{
 253  0
 			ImageManager	images = ImageManager.getInstance();
 254  0
 			images.putImage( _slide, _slideImage );
 255  
 		}
 256  0
 		_slide = null;
 257  0
 		_slideImage = null;
 258  0
 	}
 259  
 
 260  
 	/**
 261  
 	 * スライド名を取得します。
 262  
 	 * @return	スライド名
 263  
 	 */
 264  
 	public String getSlide()
 265  
 	{
 266  0
 		return _slide;
 267  
 	}
 268  
 
 269  
 	/**
 270  
 	 * スライド画像を取得します。
 271  
 	 * @return	スライド画像
 272  
 	 */
 273  
 	public Image getSlideImage()
 274  
 	{
 275  0
 		return _slideImage;
 276  
 	}
 277  
 
 278  
 	/**
 279  
 	 * BGM を再生します。
 280  
 	 * @param	id	BGM ID
 281  
 	 * @param	clipName	クリップ名
 282  
 	 * @param	loop	ループする場合は <code>true</code>、しない場合は <code>false</code>
 283  
 	 */
 284  
 	public void playBGM( String id, String clipName, boolean loop )
 285  
 	{
 286  0
 		_audioPlayer.playBGM( id, clipName, loop );
 287  0
 	}
 288  
 
 289  
 	/**
 290  
 	 * BGM を停止します。
 291  
 	 * @param	id	停止する BGM の ID
 292  
 	 * @param	mode	停止モード
 293  
 	 */
 294  
 	public void stopBGM( String id, int mode )
 295  
 	{
 296  0
 		_audioPlayer.stop( id, mode );
 297  0
 	}
 298  
 
 299  
 	/**
 300  
 	 * SE を停止します。
 301  
 	 * @param	id	停止する SE の ID
 302  
 	 */
 303  
 	public void stopSE( String id, int mode )
 304  
 	{
 305  0
 		_audioPlayer.stop( id, mode );
 306  0
 	}
 307  
 
 308  
 	/**
 309  
 	 * SE を再生します。
 310  
 	 * @param	id	SE ID
 311  
 	 * @param	clipName	クリップ名
 312  
 	 * @param	loop	ループする場合は <code>true</code>、しない場合は <code>false</code>
 313  
 	 */
 314  
 	public void playSE( String id, String clipName, boolean loop )
 315  
 	{
 316  0
 		_audioPlayer.playSE( id, clipName, loop );
 317  0
 	}
 318  
 
 319  
 	/**
 320  
 	 * サウンド効果を処理するオーディオプレーヤーを設定します。
 321  
 	 * @param	audioPlayer	オーディオプレーヤー
 322  
 	 */
 323  
 	public void setAudioPlayer( AudioPlayer audioPlayer )
 324  
 	{
 325  0
 		_audioPlayer = audioPlayer;
 326  0
 	}
 327  
 
 328  
 	/**
 329  
 	 * サウンド効果を処理するオーディオプレーヤーを取得します。
 330  
 	 * @return	オーディオプレーヤー
 331  
 	 */
 332  
 	public AudioPlayer getAudioPlayer()
 333  
 	{
 334  0
 		return _audioPlayer;
 335  
 	}
 336  
 
 337  
 	/**
 338  
 	 * このステージを描画するキャンバスを設定します。
 339  
 	 * @param	canvas	このステージを描画するキャンバス
 340  
 	 */
 341  
 	void setStageCanvas( StageCanvas canvas )
 342  
 	{
 343  0
 		_canvas = canvas;
 344  0
 	}
 345  
 
 346  
 	/**
 347  
 	 * このステージを描画するキャンバスを取得します。
 348  
 	 * @return	ステージキャンバス
 349  
 	 */
 350  
 	public StageCanvas getStageCanvas()
 351  
 	{
 352  0
 		return _canvas;
 353  
 	}
 354  
 
 355  
 	/**
 356  
 	 * このステージを描画しているキャンバスを最新の状態に更新します。
 357  
 	 */
 358  
 	public void updateCanvas()
 359  
 	{
 360  0
 		_canvas.updateCanvas( null );
 361  0
 	}
 362  
 
 363  
 	/**
 364  
 	 * このステージを描画しているキャンバスを最新の状態に更新します。
 365  
 	 */
 366  
 	public void updateCanvas( String effect )
 367  
 	{
 368  0
 		if( _canvas != null )	{
 369  0
 			Logger.debug( "[canvas.stage] effect :" + effect );
 370  0
 			_canvas.updateCanvas( effect );
 371  
 		}
 372  0
 	}
 373  
 
 374  
 
 375  
 	public void commit()
 376  
 	{
 377  0
 		_committedActors.clear();
 378  0
 		_committedActors.putAll( _actors );
 379  0
 		_committedBackground = _background;
 380  0
 		_committedBackgroundColor = _backgroundColor;
 381  0
 		_committedSlide = _slide;
 382  0
 	}
 383  
 
 384  
 	/**
 385  
 	 * Stage を破棄します。
 386  
 	 */
 387  
 	void dispose()
 388  
 	{
 389  0
 		Iterator	itr = _actors.values().iterator();
 390  0
 		while( itr.hasNext() )	{
 391  0
 			((Actor)itr.next()).disposeLooks();
 392  0
 		}
 393  
 
 394  0
 		if( _backgroundImage != null )	{
 395  0
 			ImageManager	images = ImageManager.getInstance();
 396  0
 			images.putImage( _background, _backgroundImage );
 397  
 		}
 398  
 
 399  0
 		_audioPlayer.stopAll();
 400  0
 	}
 401  
 
 402  
 	/**
 403  
 	 * Stage を描画する準備を実行します。
 404  
 	 */
 405  
 	public void prepare()
 406  
 	{
 407  0
 		if( _actors == null )	{
 408  0
 			_actors = (Map)_committedActors.clone();
 409  
 		}
 410  
 
 411  0
 		Iterator	itr = _actors.values().iterator();
 412  0
 		while( itr.hasNext() )	{
 413  0
 			((Actor)itr.next()).prepare();
 414  0
 		}
 415  
 
 416  0
 		if( _committedBackgroundColor == null )	{
 417  0
 			setBackgroundImage( _committedBackground );
 418  0
 		}
 419  
 		else	{
 420  0
 			_background = _committedBackground;
 421  0
 			_backgroundColor = _committedBackgroundColor;
 422  
 		}
 423  
 
 424  0
 		if( _committedSlide != null )	{
 425  0
 			showSlide( _committedSlide );
 426  
 		}
 427  
 
 428  0
 		updateCanvas();
 429  0
 	}
 430  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.