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: AtOnceHandler.java,v 1.2 2005/08/18 14:37:40 ppoi Exp $
18   */
19  package tsukuba_bunko.peko.scenario.stage;
20  
21  import	org.xml.sax.Attributes;
22  import	org.xml.sax.SAXException;
23  
24  import	tsukuba_bunko.peko.scenario.HandlerRegistry;
25  import	tsukuba_bunko.peko.scenario.PSMLUtil;
26  
27  
28  /***
29   * <samp>at-once</samp> 要素を処理する ElementHandler です。
30   * @author	$Author: ppoi $
31   * @version	$Revision: 1.2 $
32   */
33  public class AtOnceHandler	extends StageElementHandler	{
34  
35  	/***
36  	 * 現在使用中の StageElementHandler
37  	 */
38  	private StageElementHandler	_child = null;
39  
40  	/***
41  	 * level
42  	 */
43  	private int	_level = 0;
44  
45  	/***
46  	 * 更新に使用するエフェクト
47  	 */
48  	private String	_effect = null;
49  
50  	/***
51  	 * スライド操作を含むかどうか
52  	 */
53  	private boolean	_containsSlideOperation = false;
54  
55  
56  	/***
57  	 * <code>AtOnceHandler</code> のインスタンスを作成します。
58  	 */
59  	public AtOnceHandler()
60  	{
61  		super();
62  	}
63  
64  
65  //
66  //	ContentHandler の実装
67  //
68  	public void startDocument()
69  	{
70  		_child = null;
71  		_level = 0;
72  		_containsSlideOperation = false;
73  		super.startDocument();
74  	}
75  
76  	public void endDocument()
77  	{
78  		StageCoordinator	coordinator = getStageCoordinator();
79  		if( _effect == null )	{
80  			coordinator.updateStage();
81  		}
82  		else	{
83  			if( !coordinator.isSlideVisible() || _containsSlideOperation )	{
84  				coordinator.updateStage( _effect );
85  			}
86  		}
87  		super.endDocument();
88  	}
89  
90  	public void startElement( String namespaceURI, String localName, String qName, Attributes attrs )
91  		throws SAXException
92  	{
93  		if( _child != null )	{
94  			_level++;
95  			_child.startElement( namespaceURI, localName, qName, attrs );
96  		}
97  		else if( localName.equals("at-once") )	{
98  			_effect = PSMLUtil.getAttributeValue( attrs, "effect" );
99  		}
100 		else	{
101 			HandlerRegistry	registry = getSceneContext().getSceneProcessor().getHandlerRegistry();
102 			_child = (StageElementHandler)registry.getElementHandler( namespaceURI, localName );
103 			if( _child instanceof SlideHandler )	{
104 				_containsSlideOperation = true;
105 			}
106 			if( _child != null )	{
107 				_child.setParentHandler( this );
108 				_child.setSceneContext( getSceneContext() );
109 				_child.startDocument();
110 				_level++;
111 				_child.startElement( namespaceURI, localName, qName, attrs );
112 			}
113 		}
114 	}
115 
116 	public void endElement( String namespaceURI, String localName, String qName )
117 		throws SAXException
118 	{
119 		if( _child != null )	{
120 			_level--;
121 			_child.endElement( namespaceURI, localName, qName );
122 			if( _level == 0 )	{
123 				_child.endDocument();
124 				_child.setParentHandler( null );
125 				_child.setSceneContext( null );
126 				_child = null;
127 			}
128 		}
129 	}
130 }