1
2
3
4
5
6
7
8
9 package tsukuba_bunko.peko.scenario.select;
10
11 import java.util.List;
12
13 import tsukuba_bunko.peko.Logger;
14
15 import tsukuba_bunko.peko.canvas.CanvasManager;
16
17 import tsukuba_bunko.peko.canvas.select.SelectItem;
18
19 import tsukuba_bunko.peko.scenario.Coordinator;
20
21
22 /***
23 * SelectCanvas に対する処理を取り持つコーディネータモジュールです。
24 * @author $Author: ppoi $
25 * @version $Revision: 1.1 $
26 */
27 public class SelectCoordinator extends Coordinator {
28
29 /***
30 * 選択肢リスト
31 */
32 protected List _selectItems = null;
33
34 /***
35 * 現在アクティブなスレッド
36 */
37 protected Thread _activeThread = null;
38
39
40 /***
41 * <code>SelectCoordinator</code> のインスタンスを生成します。
42 */
43 public SelectCoordinator()
44 {
45 super();
46 }
47
48
49 /***
50 * SelectCanvas に対する操作を開始します。
51 */
52 public void begin()
53 {
54 if( isActiveThread() ) {
55 getActionControler().setSaveEnabled( true );
56 _selectItems = new java.util.ArrayList( 4 );
57 }
58 }
59
60 /***
61 * SelectCanvas に対する操作を終了し、キャンバスの状態を確定します。
62 */
63 public void commit()
64 {
65 if( isActiveThread() ) {
66 getActionControler().setSaveEnabled( false );
67 }
68 }
69
70 /***
71 * 選択肢を追加します。
72 * @param id 選択肢 ID
73 * @param text 選択肢の文章
74 */
75 public void addSelectItem( String id, String text )
76 {
77 if( id == null ) {
78 throw new IllegalArgumentException( "id is not specified." );
79 }
80 else if( text == null) {
81 throw new IllegalArgumentException( "text is not specified." );
82 }
83
84 if( isActiveThread() ) {
85 SelectItem item = new SelectItem();
86 item.setID( id );
87 item.setText( text );
88 _selectItems.add( item );
89 }
90 }
91
92 /***
93 * ユーザーに対し選択肢を表示し、選択された ID を取得します。
94 * @return 選択された選択肢の選択肢 ID
95 */
96 public String select()
97 {
98 if( isActiveThread() ) {
99 if( (_selectItems == null) || _selectItems.isEmpty() ) {
100 Logger.debug( "[scenario.select] no select items!" );
101 return null;
102 }
103 else {
104 CanvasManager canvasManager = getCanvasManager();
105 String id = canvasManager.showSelect( _selectItems );
106 if( id == null ) {
107 Logger.debug( "[scenario.select] canceled." );
108 }
109 canvasManager.advancesNewPage();
110 return id;
111 }
112 }
113 else {
114 return null;
115 }
116 }
117
118 /***
119 * SelectCanvas に対する操作を終了します。
120 */
121 public void end()
122 {
123 if( isActiveThread() ) {
124 _activeThread = null;
125 if( _selectItems != null ) {
126 _selectItems.clear();
127 _selectItems = null;
128 }
129 }
130 }
131 }