1
2
3
4
5
6
7
8
9 package tsukuba_bunko.peko.resource;
10
11 import java.awt.Dimension;
12
13 import org.xml.sax.SAXException;
14
15 import tsukuba_bunko.resource.SimpleDeserializer;
16
17
18 /***
19 * {@link java.awt.Dimension} 型のリソースに対する {@link tsukuba_bunko.resource.ResourceDeserializer} 実装です。
20 * @author $Author: ppoi $
21 * @version $Revision: 1.1 $
22 * @see <a href="http://softlab.tsukuba-bunko.org/peko/userguide/resource.html#type-peko:dimension">peko:dimension 型のリソース</a>
23 */
24 public class DimensionDeserializer extends SimpleDeserializer {
25
26 /***
27 * <code>DimensionDeserializer</code> のインスタンスを作成します。
28 */
29 public DimensionDeserializer()
30 {
31 super();
32 }
33
34
35
36
37
38 protected Object convertValue( String source )
39 throws SAXException
40 {
41 try {
42 return DimensionDeserializer.parseDimension( source );
43 }
44 catch( Exception e ) {
45 throw new SAXException( e );
46 }
47 }
48
49
50 /***
51 * <code>source</code> を Dimension として解析します。
52 * @param source 解析元の文字列
53 * @return 解析結果
54 */
55 public static Dimension parseDimension( String source )
56 throws IllegalArgumentException
57 {
58 try {
59 int delm = source.indexOf( ',' );
60 int x = Integer.parseInt( source.substring(0, delm) );
61 int y = Integer.parseInt( source.substring(delm + 1) );
62 return new Dimension( x, y );
63 }
64 catch( Exception e ) {
65 throw new IllegalArgumentException( e.getMessage() );
66 }
67 }
68 }