%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.swing.converters.PointConverter |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.commons.jelly.tags.swing.converters; |
|
17 | ||
18 | import java.awt.Point; |
|
19 | import java.util.StringTokenizer; |
|
20 | ||
21 | import org.apache.commons.beanutils.Converter; |
|
22 | ||
23 | /** |
|
24 | * A Converter that turns Strings in the form "x, y" into Point objects |
|
25 | * |
|
26 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
27 | * @version $Revision: 155420 $ |
|
28 | */ |
|
29 | 4 | public class PointConverter implements Converter { |
30 | ||
31 | public Object convert(Class type, Object value) { |
|
32 | 16 | if ( value != null ) { |
33 | 16 | String text = value.toString(); |
34 | 16 | StringTokenizer pointEnum = new StringTokenizer( text, "," ); |
35 | 16 | int x = 0; |
36 | 16 | int y = 0; |
37 | 16 | if ( pointEnum.hasMoreTokens() ) { |
38 | 16 | x = parseNumber( pointEnum.nextToken() ); |
39 | } |
|
40 | 16 | if ( pointEnum.hasMoreTokens() ) { |
41 | 12 | y = parseNumber( pointEnum.nextToken() ); |
42 | } |
|
43 | ||
44 | // now lets parse the Point... |
|
45 | 16 | return new Point( x, y ); |
46 | } |
|
47 | 0 | return null; |
48 | } |
|
49 | ||
50 | protected int parseNumber(String text) { |
|
51 | 28 | text = text.trim(); |
52 | 28 | return Integer.parseInt(text); |
53 | } |
|
54 | ||
55 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |