View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.layout;
21  
22  
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  
27  public enum TextAlign {
28  
29    LEFT("left"),
30    RIGHT("right"),
31    CENTER("center"),
32    JUSTIFY("justify");
33  
34    public static final String STRING_LEFT = "left";
35    public static final String STRING_RIGHT = "right";
36    public static final String STRING_CENTER = "center";
37    public static final String STRING_JUSTIFY = "justify";
38  
39    private final String value;
40  
41    TextAlign(final String value) {
42      this.value = value;
43    }
44  
45    public String getValue() {
46      return value;
47    }
48  
49    private static final Map<String, TextAlign> MAPPING;
50  
51    static {
52      MAPPING = new HashMap<String, TextAlign>();
53  
54      for (final TextAlign textAlign : TextAlign.values()) {
55        MAPPING.put(textAlign.getValue(), textAlign);
56      }
57    }
58  
59    public static TextAlign parse(final String string) {
60      if (string == null) {
61        return null;
62      }
63      final TextAlign value = MAPPING.get(string);
64      if (value != null) {
65        return value;
66      } else {
67        throw new IllegalArgumentException("Unknown value for TextAlign: '" + string + "'");
68      }
69    }
70  
71  }