Coverage report

| %line | %branch
--- | --- | ---
tsukuba_bunko.peko.canvas.CanvasManager |
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: CanvasManager.java,v 1.3 2005/07/23 17:34:52 ppoi Exp $
18 |  |
      */
19 |  |
     package tsukuba_bunko.peko.canvas;
20 |  |
21 |  |
     import	java.awt.Color;
22 |  |
     import	java.awt.Dimension;
23 |  |
     import	java.awt.Font;
24 |  |
25 |  |
     import	java.awt.font.TextAttribute;
26 |  |
27 |  |
     import	java.io.Serializable;
28 |  |
29 |  |
     import	java.util.List;
30 |  |
     import	java.util.Map;
31 |  |
32 |  |
     import	javax.swing.ImageIcon;
33 |  |
     import	javax.swing.JComponent;
34 |  |
     import	javax.swing.JFrame;
35 |  |
36 |  |
     import	tsukuba_bunko.peko.ActionControler;
37 |  |
     import	tsukuba_bunko.peko.Logger;
38 |  |
     import	tsukuba_bunko.peko.PekoSystem;
39 |  |
40 |  |
     import	tsukuba_bunko.peko.canvas.select.SelectCanvas;
41 |  |
     import	tsukuba_bunko.peko.canvas.select.SelectItem;
42 |  |
     import	tsukuba_bunko.peko.canvas.select.SelectItemButton;
43 |  |
44 |  |
     import	tsukuba_bunko.peko.canvas.stage.Stage;
45 |  |
     import	tsukuba_bunko.peko.canvas.stage.StageCanvas;
46 |  |
47 |  |
     import	tsukuba_bunko.peko.canvas.text.Page;
48 |  |
     import	tsukuba_bunko.peko.canvas.text.TextCanvas;
49 |  |
50 |  |
     import	tsukuba_bunko.peko.resource.ResourceManager;
51 |  |
     import	tsukuba_bunko.peko.resource.FontManager;
52 |  |
53 |  |
     import	tsukuba_bunko.peko.session.Session;
54 |  |
55 |  |
56 |  |
     /**
57 |  |
      * Canvas を管理する機能を提供します。
58 |  |
      * @author	$Author: ppoi $
59 |  |
      * @version	$Revision: 1.3 $
60 |  |
      */
61 |  |
     public class CanvasManager	{
62 |  |
63 |  |
     	/**
64 |  |
     	 * テキストキャンバス
65 |  |
     	 */
66 | 0 |
     	private TextCanvas	_text = null;
67 |  |
68 |  |
     	/**
69 |  |
     	 * ステージキャンバス
70 |  |
     	 */
71 | 0 |
     	private StageCanvas	_stage = null;
72 |  |
73 |  |
     	/**
74 |  |
     	 * 選択肢キャンバス
75 |  |
     	 */
76 | 0 |
     	private SelectCanvas	_select = null;
77 |  |
78 |  |
79 |  |
     	/**
80 |  |
     	 * テキストの履歴
81 |  |
     	 */
82 | 0 |
     	private List	_history = null;
83 |  |
84 |  |
     	/**
85 |  |
     	 * テキストの履歴の最大数
86 |  |
     	 */
87 | 0 |
     	private int	_maxHistoryCount = 0;
88 |  |
89 |  |
     	/**
90 |  |
     	 * 現在の Page
91 |  |
     	 */
92 | 0 |
     	private Page	_currentPage = null;
93 |  |
94 |  |
     	/**
95 |  |
     	 * 現在選択肢を表示中かどうか
96 |  |
     	 */
97 | 0 |
     	private boolean	_selecting = false;
98 |  |
99 |  |
100 |  |
101 |  |
     	/**
102 |  |
     	 * 選択肢ボタンスタイル
103 |  |
     	 */
104 | 0 |
     	private Map	_selectStyle = null;
105 |  |
106 |  |
     	/**
107 |  |
     	 * タイトルメニューボタンスタイル
108 |  |
     	 */
109 | 0 |
     	private Map	_titleStyle = null;
110 |  |
111 |  |
112 |  |
     	/**
113 |  |
     	 * <code>CanvasManager</code> のインスタンスを作成します。
114 |  |
     	 */
115 |  |
     	public CanvasManager()
116 |  |
     	{
117 | 0 |
     		super();
118 | 0 |
     	}
119 |  |
120 |  |
121 |  |
     	/**
122 |  |
     	 * 初期化します。
123 |  |
     	 */
124 |  |
     	public void initialize()
125 |  |
     	{
126 | 0 |
     		PekoSystem	system = PekoSystem.getInstance();
127 | 0 |
     		ResourceManager	resources = ResourceManager.getInstance();
128 |  |
129 | 0 |
     		_history = new java.util.ArrayList();
130 |  |
131 | 0 |
     		JFrame	mainWindow = system.getMainWindow();
132 |  |
133 | 0 |
     		String	title = (String)resources.getResource( "game-info.title" );
134 | 0 |
     		Dimension	canvasSize = (Dimension)resources.getResource( ResourceIDs.CANVAS_SIZE );
135 | 0 |
     		ImageIcon	icon = (ImageIcon)resources.getResource( "game-info.icon" );
136 |  |
137 | 0 |
     		mainWindow.setTitle( title );
138 | 0 |
     		if( (icon.getIconHeight() > 0) && (icon.getIconWidth() > 0) )	{
139 | 0 |
     			mainWindow.setIconImage( icon.getImage() );
140 |  |
     		}
141 |  |
142 | 0 |
     		mainWindow.setResizable( true );
143 | 0 |
     		JComponent	contentPane = (JComponent)mainWindow.getContentPane();
144 | 0 |
     		contentPane.setPreferredSize( canvasSize );
145 | 0 |
     		contentPane.setSize( canvasSize );
146 | 0 |
     		contentPane.setLayout( null );
147 |  |
148 | 0 |
     		_stage = new StageCanvas();
149 | 0 |
     		_stage.setStage( new Stage() );
150 | 0 |
     		contentPane.add( _stage );
151 | 0 |
     		_stage.setLocation( 0, 0 );
152 |  |
153 | 0 |
     		_text = new TextCanvas();
154 | 0 |
     		_text.setPreferredSize( canvasSize );
155 | 0 |
     		_text.setSize( canvasSize );
156 | 0 |
     		_text.setVisible( false );
157 | 0 |
     		_stage.add( _text );
158 | 0 |
     		_text.setLocation( 0, 0 );
159 |  |
160 | 0 |
     		_select = new SelectCanvas();
161 | 0 |
     		_select.setPreferredSize( canvasSize );
162 | 0 |
     		_select.setSize( canvasSize );
163 | 0 |
     		_select.setVisible( false );
164 | 0 |
     		_stage.add( _select );
165 | 0 |
     		_select.setLocation( 0, 0 );
166 | 0 |
     		mainWindow.addKeyListener( _select );
167 |  |
168 | 0 |
     		Integer	maxHistory = (Integer)resources.getResource( ResourceIDs.CANVAS_PAGE_HISTORY );
169 | 0 |
     		if( maxHistory == null )	{
170 | 0 |
     			_maxHistoryCount = 10;
171 | 0 |
     		}
172 |  |
     		else	{
173 | 0 |
     			_maxHistoryCount = maxHistory.intValue();
174 |  |
     		}
175 |  |
176 | 0 |
     		initializeSelectStyle();
177 | 0 |
     		initializeTitleStyle();
178 | 0 |
     	}
179 |  |
180 |  |
     	/**
181 |  |
     	 * 選択肢のスタイルを設定します。
182 |  |
     	 */
183 |  |
     	protected void initializeSelectStyle()
184 |  |
     	{
185 | 0 |
     		ResourceManager	resources = ResourceManager.getInstance();
186 |  |
187 | 0 |
     		_selectStyle = new java.util.HashMap( 17 );
188 |  |
189 | 0 |
     		Color	colorValue = (Color)resources.getResource( ResourceIDs.SELECT_BUTTON_BACKGROUND_COLOR );
190 | 0 |
     		if( colorValue == null )	{
191 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_BACKGROUND_COLOR, "black"} );
192 | 0 |
     			colorValue = Color.black;
193 |  |
     		}
194 | 0 |
     		_selectStyle.put( SelectItemButton.STYLE_BACKGROUND_COLOR, colorValue );
195 |  |
196 | 0 |
     		Float	floatValue = (Float)resources.getResource( ResourceIDs.SELECT_BUTTON_BACKGROUND_TRANSPARENCY );
197 | 0 |
     		if( floatValue == null )	{
198 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_BACKGROUND_TRANSPARENCY, "0.5f"} );
199 | 0 |
     			floatValue = new Float( 0.5f );
200 | 0 |
     		}
201 | 0 |
     		else if( floatValue.floatValue() < 0f )	{
202 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_BACKGROUND_TRANSPARENCY, "0.5f"} );
203 | 0 |
     			floatValue = new Float( 0.5f );
204 |  |
     		}
205 | 0 |
     		_selectStyle.put( SelectItemButton.STYLE_BACKGROUND_TRANSPARENCY, floatValue );
206 |  |
207 | 0 |
     		Integer	intValue = (Integer)resources.getResource( ResourceIDs.SELECT_BUTTON_WIDTH );
208 | 0 |
     		if( intValue == null )	{
209 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_WIDTH, "320"} );
210 | 0 |
     			intValue = new Integer( 320 );
211 |  |
     		}
212 | 0 |
     		_selectStyle.put( SelectItemButton.STYLE_WIDTH, intValue );
213 |  |
214 | 0 |
     		colorValue = (Color)resources.getResource( ResourceIDs.SELECT_BUTTON_FOREGROUND_SELECTED );
215 | 0 |
     		if( colorValue == null )	{
216 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_FOREGROUND_SELECTED, "white"} );
217 | 0 |
     			colorValue = Color.white;
218 |  |
     		}
219 | 0 |
     		_selectStyle.put( SelectItemButton.STYLE_FOREGROUND_SELECTED, colorValue );
220 |  |
221 | 0 |
     		colorValue = (Color)resources.getResource( ResourceIDs.SELECT_BUTTON_FOREGROUND_UNSELECTED );
222 | 0 |
     		if( colorValue == null )	{
223 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_FOREGROUND_UNSELECTED, "darkGray"} );
224 | 0 |
     			colorValue = Color.darkGray;
225 |  |
     		}
226 | 0 |
     		_selectStyle.put( SelectItemButton.STYLE_FOREGROUND_UNSELECTED, colorValue );
227 |  |
228 | 0 |
     		colorValue = (Color)resources.getResource( ResourceIDs.SELECT_BUTTON_FOREGROUND_SHADOW );
229 | 0 |
     		if( colorValue == null )	{
230 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_FOREGROUND_SHADOW, "black"} );
231 | 0 |
     			colorValue = Color.black;
232 |  |
     		}
233 | 0 |
     		_selectStyle.put( SelectItemButton.STYLE_FOREGROUND_SHADOW, colorValue );
234 |  |
235 | 0 |
     		Font	fontValue = (Font)resources.getResource( ResourceIDs.SELECT_BUTTON_FONT );
236 | 0 |
     		if( fontValue == null )	{
237 | 0 |
     			Map	attributes = new java.util.HashMap( 17 );
238 | 0 |
     			attributes.put( TextAttribute.FAMILY, "SansSerif" );
239 | 0 |
     			attributes.put( TextAttribute.SIZE, new Float(16f) );
240 | 0 |
     			fontValue = FontManager.getInstance().getFont( attributes );
241 |  |
     		}
242 | 0 |
     		_selectStyle.put( SelectItemButton.STYLE_FONT, fontValue );
243 | 0 |
     	}
244 |  |
245 |  |
246 |  |
     	/**
247 |  |
     	 * タイトルメニューのスタイルを設定します。
248 |  |
     	 */
249 |  |
     	protected void initializeTitleStyle()
250 |  |
     	{
251 | 0 |
     		ResourceManager	resources = ResourceManager.getInstance();
252 |  |
253 | 0 |
     		_titleStyle = new java.util.HashMap( 17 );
254 |  |
255 | 0 |
     		Color	colorValue = (Color)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_BACKGROUND_COLOR );
256 | 0 |
     		if( colorValue == null )	{
257 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_BACKGROUND_COLOR, "black"} );
258 | 0 |
     			colorValue = Color.black;
259 |  |
     		}
260 | 0 |
     		_titleStyle.put( SelectItemButton.STYLE_BACKGROUND_COLOR, colorValue );
261 |  |
262 | 0 |
     		Float	floatValue = (Float)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_BACKGROUND_TRANSPARENCY );
263 | 0 |
     		if( floatValue == null )	{
264 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_BACKGROUND_TRANSPARENCY, "0.5f"} );
265 | 0 |
     			floatValue = new Float( 0.5f );
266 | 0 |
     		}
267 | 0 |
     		else if( floatValue.floatValue() < 0f )	{
268 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_BACKGROUND_TRANSPARENCY, "0.5f"} );
269 | 0 |
     			floatValue = new Float( 0.5f );
270 |  |
     		}
271 | 0 |
     		_titleStyle.put( SelectItemButton.STYLE_BACKGROUND_TRANSPARENCY, floatValue );
272 |  |
273 | 0 |
     		Integer	intValue = (Integer)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_WIDTH );
274 | 0 |
     		if( intValue == null )	{
275 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_WIDTH, "320"} );
276 | 0 |
     			intValue = new Integer( 320 );
277 |  |
     		}
278 | 0 |
     		_titleStyle.put( SelectItemButton.STYLE_WIDTH, intValue );
279 |  |
280 | 0 |
     		colorValue = (Color)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_FOREGROUND_SELECTED );
281 | 0 |
     		if( colorValue == null )	{
282 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_FOREGROUND_SELECTED, "white"} );
283 | 0 |
     			colorValue = Color.white;
284 |  |
     		}
285 | 0 |
     		_titleStyle.put( SelectItemButton.STYLE_FOREGROUND_SELECTED, colorValue );
286 |  |
287 | 0 |
     		colorValue = (Color)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_FOREGROUND_UNSELECTED );
288 | 0 |
     		if( colorValue == null )	{
289 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_FOREGROUND_UNSELECTED, "darkGray"} );
290 | 0 |
     			colorValue = Color.darkGray;
291 |  |
     		}
292 | 0 |
     		_titleStyle.put( SelectItemButton.STYLE_FOREGROUND_UNSELECTED, colorValue );
293 |  |
294 | 0 |
     		colorValue = (Color)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_FOREGROUND_SHADOW );
295 | 0 |
     		if( colorValue == null )	{
296 | 0 |
     			Logger.warn( MessageIDs.CVS3003W, new Object[]{SelectItemButton.STYLE_FOREGROUND_SHADOW, "black"} );
297 | 0 |
     			colorValue = Color.black;
298 |  |
     		}
299 | 0 |
     		_titleStyle.put( SelectItemButton.STYLE_FOREGROUND_SHADOW, colorValue );
300 |  |
301 | 0 |
     		Font	fontValue = (Font)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_FONT );
302 | 0 |
     		if( fontValue == null )	{
303 | 0 |
     			Map	attributes = new java.util.HashMap( 17 );
304 | 0 |
     			attributes.put( TextAttribute.FAMILY, "SansSerif" );
305 | 0 |
     			attributes.put( TextAttribute.SIZE, new Float(16f) );
306 | 0 |
     			fontValue = FontManager.getInstance().getFont( attributes );
307 |  |
     		}
308 | 0 |
     		_titleStyle.put( SelectItemButton.STYLE_FONT, fontValue );
309 | 0 |
     	}
310 |  |
311 |  |
     	/**
312 |  |
     	 * テキストキャンバスを取得します。
313 |  |
     	 * @return	テキストキャンバス
314 |  |
     	 */
315 |  |
     	public TextCanvas getTextCanvas()
316 |  |
     	{
317 | 0 |
     		return _text;
318 |  |
     	}
319 |  |
320 |  |
     	/**
321 |  |
     	 * ステージキャンバスを取得します。
322 |  |
     	 * @return	ステージキャンバス
323 |  |
     	 */
324 |  |
     	public StageCanvas getStageCanvas()
325 |  |
     	{
326 | 0 |
     		return _stage;
327 |  |
     	}
328 |  |
329 |  |
     	/**
330 |  |
     	 * ステージを取得します。
331 |  |
     	 */
332 |  |
     	public Stage getStage()
333 |  |
     	{
334 | 0 |
     		return _stage.getStage();
335 |  |
     	}
336 |  |
337 |  |
     	/**
338 |  |
     	 * 現在のページを取得します。
339 |  |
     	 */
340 |  |
     	public Page getCurrentPage()
341 |  |
     	{
342 | 0 |
     		return _text.getPage();
343 |  |
     	}
344 |  |
345 |  |
     	/**
346 |  |
     	 * 次の新しいページに移動します。
347 |  |
     	 * @return	現在のページ(移動後)
348 |  |
     	 */
349 |  |
     	public Page advancesNewPage()
350 |  |
     	{
351 | 0 |
     		Page	page = _text.getPage();
352 | 0 |
     		if( page != null )	{
353 | 0 |
     			synchronized( page )	{
354 | 0 |
     				putTextHistory( page );
355 | 0 |
     				page.clearLines();
356 | 0 |
     			}
357 | 0 |
     		}
358 |  |
     		else	{
359 | 0 |
     			page = new Page();
360 | 0 |
     			_text.setPage( page );
361 |  |
     		}
362 |  |
363 | 0 |
     		_currentPage = page;
364 | 0 |
     		return page;
365 |  |
     	}
366 |  |
367 |  |
     	/**
368 |  |
     	 * <code>page</code> をテキストの履歴に追加します。
369 |  |
     	 * @param	page	履歴に追加するページ
370 |  |
     	 */
371 |  |
     	protected void putTextHistory( Page page )
372 |  |
     	{
373 | 0 |
     		if( page.getLineCount() == 0 )	{
374 |  |
     			//	空白ページは履歴に入れないデス
375 | 0 |
     			return;
376 |  |
     		}
377 |  |
378 | 0 |
     		Page	previous = null;
379 | 0 |
     		if( _history.size() >= _maxHistoryCount )	{
380 | 0 |
     			previous = (Page)_history.remove( 0 );
381 | 0 |
     			page.clone( previous );
382 | 0 |
     		}
383 |  |
     		else	{
384 | 0 |
     			previous = (Page)page.clone();
385 |  |
     		}
386 | 0 |
     		_history.add( previous );
387 | 0 |
     	}
388 |  |
389 |  |
     	/**
390 |  |
     	 * 過去の文章を表示します。
391 |  |
     	 * @param	index	戻るページ数。
392 |  |
     	 * @return	次があれば true
393 |  |
     	 */
394 |  |
     	public boolean readAgain( int index )
395 |  |
     	{
396 | 0 |
     		if( _selecting )	{
397 | 0 |
     			_select.setVisible( false );
398 |  |
     		}
399 |  |
400 | 0 |
     		Page	previous = (Page)_history.get( _history.size() - index );
401 | 0 |
     		_text.setPage( previous );
402 | 0 |
     		_text.updateCanvas();
403 | 0 |
     		_text.updateText();
404 | 0 |
     		return ((_history.size() - index) > 0);
405 |  |
     	}
406 |  |
407 |  |
     	/**
408 |  |
     	 * 現在のページに戻ります。
409 |  |
     	 */
410 |  |
     	public void returnCurrent()
411 |  |
     	{
412 | 0 |
     		_text.setPage( _currentPage );
413 | 0 |
     		_text.updateCanvas();
414 | 0 |
     		_text.updateText();
415 |  |
416 | 0 |
     		if( _selecting )	{
417 | 0 |
     			hideTextCanvas();
418 | 0 |
     			_select.setVisible( true );
419 |  |
     		}
420 | 0 |
     	}
421 |  |
422 |  |
     	/**
423 |  |
     	 * 履歴として保存されている過去のページ数を取得します。
424 |  |
     	 * @return	履歴として保存されている過去のページ数
425 |  |
     	 */
426 |  |
     	public int getPageHistoryCount()
427 |  |
     	{
428 | 0 |
     		return _history.size();
429 |  |
     	}
430 |  |
431 |  |
     	/**
432 |  |
     	 * 現在選択肢を表示中かどうかを取得します。
433 |  |
     	 * @return	選択肢表示中の場合 <code>true</code>
434 |  |
     	 */
435 |  |
     	public boolean isShowingSelect()
436 |  |
     	{
437 | 0 |
     		return _selecting;
438 |  |
     	}
439 |  |
440 |  |
     	/**
441 |  |
     	 * 選択肢を表示します。
442 |  |
     	 * @param	selectItems	選択肢リスト
443 |  |
     	 * @return	選択された選択肢の ID
444 |  |
     	 */
445 |  |
     	public String showSelect( List selectItems )
446 |  |
     	{
447 | 0 |
     		ResourceManager	resources = ResourceManager.getInstance();
448 |  |
449 | 0 |
     		String	alignment = (String)resources.getResource( ResourceIDs.SELECT_ALIGN );
450 | 0 |
     		if( alignment == null )	{
451 | 0 |
     			Logger.warn( MessageIDs.CVS3001W, new Object[]{"center"} );
452 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_CENTER );
453 | 0 |
     		}
454 | 0 |
     		else if( "center".equalsIgnoreCase(alignment) )	{
455 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_CENTER );
456 | 0 |
     		}
457 | 0 |
     		else if( "left".equalsIgnoreCase(alignment) )	{
458 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_LEFT );
459 | 0 |
     		}
460 | 0 |
     		else if( "right".equalsIgnoreCase(alignment) )	{
461 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_RIGHT );
462 | 0 |
     		}
463 |  |
     		else	{
464 | 0 |
     			Logger.warn( MessageIDs.CVS3001W, new Object[]{"center"} );
465 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_CENTER );
466 |  |
     		}
467 |  |
468 | 0 |
     		String	valign = (String)resources.getResource( ResourceIDs.SELECT_VERTICAL_ALIGN );
469 | 0 |
     		if( valign == null )	{
470 | 0 |
     			Logger.warn( MessageIDs.CVS3006W, new Object[]{"middle"} );
471 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_MIDDLE );
472 | 0 |
     		}
473 | 0 |
     		else if( "top".equalsIgnoreCase(valign) )	{
474 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_TOP );
475 | 0 |
     		}
476 | 0 |
     		else if( "middle".equalsIgnoreCase(valign) )	{
477 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_MIDDLE );
478 | 0 |
     		}
479 | 0 |
     		else if( "bottom".equalsIgnoreCase(valign) )	{
480 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_BOTTOM );
481 | 0 |
     		}
482 |  |
     		else	{
483 | 0 |
     			Logger.warn( MessageIDs.CVS3006W, new Object[]{"middle"} );
484 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_MIDDLE );
485 |  |
     		}
486 |  |
487 | 0 |
     		Integer	columns = (Integer)resources.getResource( ResourceIDs.SELECT_COLUMNS );
488 | 0 |
     		if( columns == null )	{
489 | 0 |
     			Logger.warn( MessageIDs.CVS3002W, new Object[]{"1"} );
490 | 0 |
     			_select.setColumns( 1 );
491 | 0 |
     		}
492 |  |
     		else	{
493 | 0 |
     			_select.setColumns( columns.intValue() );
494 |  |
     		}
495 |  |
496 | 0 |
     		Integer	span = (Integer)resources.getResource( ResourceIDs.SELECT_SPAN_COLUMN );
497 | 0 |
     		if( span == null )	{
498 | 0 |
     			Logger.warn( MessageIDs.CVS3004W, new Object[]{"5"} );
499 | 0 |
     			_select.setColumnSpan( 5 );
500 | 0 |
     		}
501 |  |
     		else	{
502 | 0 |
     			_select.setColumnSpan( span.intValue() );
503 |  |
     		}
504 |  |
505 | 0 |
     		span = (Integer)resources.getResource( ResourceIDs.SELECT_SPAN_ROW );
506 | 0 |
     		if( span == null )	{
507 | 0 |
     			Logger.warn( MessageIDs.CVS3005W, new Object[]{"5"} );
508 | 0 |
     			_select.setRowSpan( 5 );
509 | 0 |
     		}
510 |  |
     		else	{
511 | 0 |
     			_select.setRowSpan( span.intValue() );
512 |  |
     		}
513 |  |
514 | 0 |
     		span = (Integer)resources.getResource( ResourceIDs.SELECT_SPAN_BOUND );
515 | 0 |
     		if( span == null )	{
516 | 0 |
     			Logger.warn( MessageIDs.CVS3007W, new Object[]{"20"} );
517 | 0 |
     			_select.setBoundSpan( 20 );
518 | 0 |
     		}
519 |  |
     		else	{
520 | 0 |
     			_select.setBoundSpan( span.intValue() );
521 |  |
     		}
522 |  |
523 | 0 |
     		_select.setButtonStyle( _selectStyle );
524 |  |
525 | 0 |
     		if( _text.isVisible() )	{
526 | 0 |
     			hideTextCanvas();
527 |  |
     		}
528 |  |
529 | 0 |
     		Page	page = advancesNewPage();
530 | 0 |
     		page.commit();
531 |  |
532 | 0 |
     		_selecting = true;
533 |  |
534 | 0 |
     		ActionControler	controler = PekoSystem.getInstance().getActionControler();
535 | 0 |
     		if( controler.getPlayMode() == ActionControler.PM_SKIP )	{
536 | 0 |
     			controler.setPlayModeToNormal();
537 |  |
     		}
538 |  |
539 | 0 |
     		_select.setVisible( true );
540 | 0 |
     		String	id = _select.select( selectItems );
541 | 0 |
     		_select.setVisible( false );
542 |  |
543 | 0 |
     		_selecting = false;
544 |  |
545 | 0 |
     		return id;
546 |  |
     	}
547 |  |
548 |  |
     	/**
549 |  |
     	 * タイトル画面を描画します。
550 |  |
     	 * @param	showTitle	オープニングを表示するかどうか
551 |  |
     	 */
552 |  |
     	public String showTitle( boolean showTitle )
553 |  |
     	{
554 | 0 |
     		ResourceManager	resources = ResourceManager.getInstance();
555 |  |
556 | 0 |
     		String	alignment = (String)resources.getResource( ResourceIDs.TITLE_MENU_ALIGN );
557 | 0 |
     		if( alignment == null )	{
558 | 0 |
     			Logger.warn( MessageIDs.CVS3001W, new Object[]{"center"} );
559 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_CENTER );
560 | 0 |
     		}
561 | 0 |
     		else if( "center".equalsIgnoreCase(alignment) )	{
562 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_CENTER );
563 | 0 |
     		}
564 | 0 |
     		else if( "left".equalsIgnoreCase(alignment) )	{
565 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_LEFT );
566 | 0 |
     		}
567 | 0 |
     		else if( "right".equalsIgnoreCase(alignment) )	{
568 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_RIGHT );
569 | 0 |
     		}
570 |  |
     		else	{
571 | 0 |
     			Logger.warn( MessageIDs.CVS3001W, new Object[]{"center"} );
572 | 0 |
     			_select.setAlignment( SelectCanvas.ALIGN_CENTER );
573 |  |
     		}
574 |  |
575 | 0 |
     		String	valign = (String)resources.getResource( ResourceIDs.TITLE_MENU_VERTICAL_ALIGN );
576 | 0 |
     		if( valign == null )	{
577 | 0 |
     			Logger.warn( MessageIDs.CVS3006W, new Object[]{"bottom"} );
578 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_BOTTOM );
579 | 0 |
     		}
580 | 0 |
     		else if( "top".equalsIgnoreCase(valign) )	{
581 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_TOP );
582 | 0 |
     		}
583 | 0 |
     		else if( "middle".equalsIgnoreCase(valign) )	{
584 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_MIDDLE );
585 | 0 |
     		}
586 | 0 |
     		else if( "bottom".equalsIgnoreCase(valign) )	{
587 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_BOTTOM );
588 | 0 |
     		}
589 |  |
     		else	{
590 | 0 |
     			Logger.warn( MessageIDs.CVS3006W, new Object[]{"bottom"} );
591 | 0 |
     			_select.setVerticalAlignment( SelectCanvas.VALIGN_BOTTOM );
592 |  |
     		}
593 |  |
594 | 0 |
     		Integer	columns = (Integer)resources.getResource( ResourceIDs.TITLE_MENU_COLUMNS );
595 | 0 |
     		if( columns == null )	{
596 | 0 |
     			Logger.warn( MessageIDs.CVS3002W, new Object[]{"1"} );
597 | 0 |
     			_select.setColumns( 1 );
598 | 0 |
     		}
599 |  |
     		else	{
600 | 0 |
     			_select.setColumns( columns.intValue() );
601 |  |
     		}
602 |  |
603 | 0 |
     		String	startCaption = (String)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_CAPTION_START );
604 | 0 |
     		if( startCaption == null )	{
605 | 0 |
     			startCaption = "Start";
606 | 0 |
     			Logger.warn( MessageIDs.CVS4001W, new Object[]{"start", startCaption} );
607 |  |
     		}
608 | 0 |
     		String	resumeCaption = (String)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_CAPTION_RESUME );
609 | 0 |
     		if( resumeCaption == null )	{
610 | 0 |
     			resumeCaption = "Load";
611 | 0 |
     			Logger.warn( MessageIDs.CVS4001W, new Object[]{"resume", resumeCaption} );
612 |  |
     		}
613 | 0 |
     		String	exitCaption = (String)resources.getResource( ResourceIDs.TITLE_MENU_BUTTON_CAPTION_EXIT );
614 | 0 |
     		if( exitCaption == null )	{
615 | 0 |
     			exitCaption = "Exit";
616 | 0 |
     			Logger.warn( MessageIDs.CVS4001W, new Object[]{"exit", exitCaption} );
617 |  |
     		}
618 |  |
619 | 0 |
     		_select.setButtonStyle( _titleStyle );
620 |  |
621 | 0 |
     		Integer	span = (Integer)resources.getResource( ResourceIDs.TITLE_MENU_SPAN_COLUMN );
622 | 0 |
     		if( span == null )	{
623 | 0 |
     			Logger.warn( MessageIDs.CVS3004W, new Object[]{"5"} );
624 | 0 |
     			_select.setColumnSpan( 5 );
625 | 0 |
     		}
626 |  |
     		else	{
627 | 0 |
     			_select.setColumnSpan( span.intValue() );
628 |  |
     		}
629 |  |
630 | 0 |
     		span = (Integer)resources.getResource( ResourceIDs.TITLE_MENU_SPAN_ROW );
631 | 0 |
     		if( span == null )	{
632 | 0 |
     			Logger.warn( MessageIDs.CVS3005W, new Object[]{"5"} );
633 | 0 |
     			_select.setRowSpan( 5 );
634 | 0 |
     		}
635 |  |
     		else	{
636 | 0 |
     			_select.setRowSpan( span.intValue() );
637 |  |
     		}
638 |  |
639 | 0 |
     		span = (Integer)resources.getResource( ResourceIDs.TITLE_MENU_SPAN_BOUND );
640 | 0 |
     		if( span == null )	{
641 | 0 |
     			Logger.warn( MessageIDs.CVS3007W, new Object[]{"20"} );
642 | 0 |
     			_select.setBoundSpan( 20 );
643 | 0 |
     		}
644 |  |
     		else	{
645 | 0 |
     			_select.setBoundSpan( span.intValue() );
646 |  |
     		}
647 |  |
648 |  |
649 | 0 |
     		List	items = new java.util.ArrayList( 3 );
650 | 0 |
     		SelectItem	item = new SelectItem();
651 | 0 |
     		item.setID( "start" );
652 | 0 |
     		item.setText( startCaption );
653 | 0 |
     		items.add( item );
654 | 0 |
     		item = new SelectItem();
655 | 0 |
     		item.setID( "resume" );
656 | 0 |
     		item.setText( resumeCaption );
657 | 0 |
     		items.add( item );
658 | 0 |
     		item = new SelectItem();
659 | 0 |
     		item.setID( "exit" );
660 | 0 |
     		item.setText( exitCaption );
661 | 0 |
     		items.add( item );
662 |  |
663 | 0 |
     		if( showTitle )	{
664 | 0 |
     			String	imageName = (String)resources.getResource( ResourceIDs.TITLE_IMAGE );
665 | 0 |
     			if( (imageName != null) && (imageName.length() > 0) )	{
666 | 0 |
     				_stage.getStage().setBackgroundImage( imageName );
667 | 0 |
     			}
668 |  |
     			else	{
669 | 0 |
     				_stage.getStage().setBackgroundColor( "white" );
670 |  |
     			}
671 | 0 |
     			_stage.updateCanvas( "mofing" );
672 |  |
673 | 0 |
     			String	bgmName = (String)resources.getResource( ResourceIDs.OPENING_BGM, true );
674 | 0 |
     			if( (bgmName != null) && (bgmName.length() > 0) )	{
675 | 0 |
     				Logger.debug( "playBGM: " + bgmName );
676 | 0 |
     				_stage.getStage().getAudioPlayer().playBGM( "opening", bgmName, true );
677 |  |
     			}
678 |  |
     		}
679 |  |
680 | 0 |
     		hideTextCanvas();
681 |  |
682 | 0 |
     		_selecting = true;
683 | 0 |
     		_select.setVisible( true );
684 | 0 |
     		String	id = _select.select( items );
685 | 0 |
     		_select.setVisible( false );
686 | 0 |
     		_selecting = false;
687 |  |
688 | 0 |
     		return id;
689 |  |
     	}
690 |  |
691 |  |
692 |  |
     	/**
693 |  |
     	 * テキストキャンバスを隠します。
694 |  |
     	 */
695 |  |
     	public void hideTextCanvas()
696 |  |
     	{
697 | 0 |
     		_text.setVisible( false );
698 | 0 |
     		_stage.paintPageBackground( false );
699 | 0 |
     	}
700 |  |
701 |  |
     	/**
702 |  |
     	 * テキストキャンバスを表示します。
703 |  |
     	 */
704 |  |
     	public void showTextCanvas()
705 |  |
     	{
706 | 0 |
     		_stage.paintPageBackground( true );
707 | 0 |
     		_text.setVisible( true );
708 | 0 |
     	}
709 |  |
710 |  |
711 |  |
     	/**
712 |  |
     	 * キャンバスを全てクリアし、初期状態に戻します。
713 |  |
     	 */
714 |  |
     	public synchronized void clearAll()
715 |  |
     	{
716 | 0 |
     		Logger.debug( "[canvas] clear All." );
717 | 0 |
     		_select.setVisible( false );
718 | 0 |
     		hideTextCanvas();
719 |  |
     //		_text.setVisible( false );
720 | 0 |
     		_select.cancel();
721 | 0 |
     		_stage.getStage().getAudioPlayer().stopAll();
722 | 0 |
     		advancesNewPage();
723 | 0 |
     		_text.getPage().commit();
724 | 0 |
     		_history.clear();
725 | 0 |
     		Stage	stage = _stage.getStage();
726 | 0 |
     		stage.exitAll();
727 | 0 |
     		stage.setBackgroundColor( "black" );
728 | 0 |
     		stage.hideSlide();
729 | 0 |
     		_stage.updateCanvas( "mofing" );
730 | 0 |
     		stage.commit();
731 | 0 |
     	}
732 |  |
733 |  |
734 |  |
     	/**
735 |  |
     	 * <code>serializableForm</code> に格納された状態を復元します。
736 |  |
     	 * @param	session	状態を格納したオブジェクト
737 |  |
     	 */
738 |  |
     	public void resume( Session session )
739 |  |
     	{
740 | 0 |
     		Stage	stage = _stage.getStage();
741 | 0 |
     		stage.setBackgroundColor( "black" );
742 | 0 |
     		stage.updateCanvas( "mofing" );
743 | 0 |
     		_stage.setVisible( false );
744 |  |
745 |  |
     		try	{
746 | 0 |
     			SerializableForm	form = (SerializableForm)session.getSessionAttribute( "canvasManager" );
747 | 0 |
     			_text.setPage( form.page );
748 | 0 |
     			_stage.setStage( form.stage );
749 | 0 |
     			form.stage.prepare();
750 | 0 |
     			form.page.rollback();
751 |  |
     		}
752 | 0 |
     		catch( Throwable th )	{
753 | 0 |
     			Logger.fatal( "[canvas] unsupported serializable form.", th );
754 | 0 |
     		}
755 |  |
756 | 0 |
     		_stage.setVisible( true );
757 | 0 |
     		_stage.getStage().getAudioPlayer().prepare();
758 | 0 |
     	}
759 |  |
760 |  |
     	/**
761 |  |
     	 * 状態保存用のオブジェクトを取得します。
762 |  |
     	 * @return	状態を格納したオブジェクト
763 |  |
     	 */
764 |  |
     	public void saveState( Session session )
765 |  |
     	{
766 | 0 |
     		SerializableForm	serializable = new SerializableForm();
767 | 0 |
     		serializable.page = _text.getPage();
768 | 0 |
     		serializable.stage = _stage.getStage();
769 | 0 |
     		session.setSessionAttribute( "canvasManager", serializable );
770 | 0 |
     	}
771 |  |
772 |  |
773 |  |
774 |  |
     	/**
775 |  |
     	 * Canvas の状態を保持します。
776 |  |
     	 */
777 |  |
     	public static class SerializableForm	implements Serializable	{
778 |  |
779 |  |
     		/**
780 |  |
     		 * serial version UID
781 |  |
     		 */
782 |  |
     		private static final long	serialVersionUID	= 7595927208130407689L;
783 |  |
784 |  |
     		/**
785 |  |
     		 * Stage
786 |  |
     		 */
787 |  |
     		public Stage	stage = null;
788 |  |
789 |  |
     		/**
790 |  |
     		 * Page
791 |  |
     		 */
792 |  |
     		public Page	page = null;
793 |  |
     	}
794 |  |
     }

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