1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
package tsukuba_bunko.peko.resource; |
10 |
|
|
11 |
|
import java.awt.Insets; |
12 |
|
|
13 |
|
import tsukuba_bunko.resource.SimpleDeserializer; |
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
public class InsetsDeserializer extends SimpleDeserializer { |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
public InsetsDeserializer() |
28 |
|
{ |
29 |
0 |
super(); |
30 |
0 |
} |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
protected Object convertValue( String source ) |
37 |
|
{ |
38 |
0 |
return parseInsets( source ); |
39 |
|
} |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public static Insets parseInsets( String source ) |
48 |
|
{ |
49 |
|
try { |
50 |
|
int top, right, bottom, left; |
51 |
0 |
int begin = 0; |
52 |
0 |
int end = source.indexOf( ',' ); |
53 |
0 |
if( end == -1 ) { |
54 |
0 |
top = Integer.parseInt( source.trim() ); |
55 |
0 |
return new Insets( top, top, top, top ); |
56 |
|
} |
57 |
|
else { |
58 |
0 |
top = Integer.parseInt( source.substring(begin, end).trim() ); |
59 |
|
} |
60 |
|
|
61 |
0 |
begin = end + 1; |
62 |
0 |
end = source.indexOf( ',', begin ); |
63 |
0 |
if( end == -1 ) { |
64 |
0 |
right = Integer.parseInt( source.substring(begin).trim() ); |
65 |
0 |
return new Insets( top, right, top, right ); |
66 |
|
} |
67 |
|
else { |
68 |
0 |
right = Integer.parseInt( source.substring(begin, end).trim() ); |
69 |
|
} |
70 |
|
|
71 |
0 |
begin = end + 1; |
72 |
0 |
end = source.indexOf( ',', begin ); |
73 |
0 |
if( end == -1 ) { |
74 |
0 |
bottom = Integer.parseInt( source.substring(begin).trim() ); |
75 |
0 |
return new Insets( top, right, bottom, right ); |
76 |
|
} |
77 |
|
else { |
78 |
0 |
bottom = Integer.parseInt( source.substring(begin, end).trim() ); |
79 |
|
} |
80 |
|
|
81 |
0 |
begin = end + 1; |
82 |
0 |
left = Integer.parseInt( source.substring(begin).trim() ); |
83 |
|
|
84 |
0 |
return new Insets( top, left, bottom, right ); |
85 |
|
} |
86 |
0 |
catch( Exception e ) { |
87 |
0 |
throw new IllegalArgumentException( e.getMessage() ); |
88 |
|
} |
89 |
|
} |
90 |
|
} |