%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.swing.converters.DebugGraphicsConverter |
|
|
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 javax.swing.DebugGraphics; |
|
19 | import java.util.StringTokenizer; |
|
20 | ||
21 | import org.apache.commons.beanutils.Converter; |
|
22 | import org.apache.commons.beanutils.ConvertUtils; |
|
23 | ||
24 | /** |
|
25 | * A Converter that turns Strings in one of the constants of |
|
26 | * {@link DebugGraphics} to their appropriate integer constant. |
|
27 | * |
|
28 | * @author <a href="mailto:paul@activemath.org">Paul Libbrecht</a> |
|
29 | * @version $Revision: 155420 $ |
|
30 | */ |
|
31 | 4 | public class DebugGraphicsConverter implements Converter { |
32 | ||
33 | 4 | private static String usageText = |
34 | "DebugGraphics options are set as a \"|\" separated list of words using one of the constants of DebugGraphics: log, flash, or buffered."; |
|
35 | ||
36 | public static void register() { |
|
37 | 0 | ConvertUtils.register( |
38 | new DebugGraphicsConverter(), |
|
39 | 0 | java.lang.Integer.class); |
40 | 0 | } |
41 | ||
42 | /** Part of the Converter interface. |
|
43 | * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class, java.lang.Object) |
|
44 | */ |
|
45 | public Object convert(Class type, Object value) { |
|
46 | 0 | return convert(value); |
47 | } |
|
48 | ||
49 | /** This is not part of the converter interface, it's for use by |
|
50 | * classes that don't use DebugGraphicsConverter through BeanUtils. |
|
51 | * @param from |
|
52 | * @return |
|
53 | */ |
|
54 | public Object convert(Object value) { |
|
55 | 0 | if (value != null) { |
56 | 0 | int result = 0; |
57 | 0 | StringTokenizer stok = |
58 | new StringTokenizer(value.toString(), ", \t|", false); |
|
59 | 0 | while (stok.hasMoreTokens()) { |
60 | 0 | String tok = stok.nextToken(); |
61 | 0 | result = result | recognizeOption(tok); |
62 | } |
|
63 | 0 | return new Integer(result); |
64 | } |
|
65 | 0 | return null; |
66 | } |
|
67 | ||
68 | protected int recognizeOption(String value) { |
|
69 | 0 | value = value.toString().toLowerCase(); |
70 | ||
71 | 0 | if ("log".equals(value) || "log_option".equals(value)) { |
72 | 0 | return DebugGraphics.LOG_OPTION; |
73 | } |
|
74 | 0 | else if ("flash".equals(value) || "flash_option".equals(value)) { |
75 | 0 | return DebugGraphics.FLASH_OPTION; |
76 | } |
|
77 | 0 | else if ("buffered".equals(value) || "buffered_option".equals(value)) { |
78 | 0 | return DebugGraphics.BUFFERED_OPTION; |
79 | } |
|
80 | else { |
|
81 | 0 | throw new IllegalArgumentException(usageText); |
82 | } |
|
83 | } |
|
84 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |