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.renderkit.css;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import java.lang.invoke.MethodHandles;
26  import java.util.regex.Pattern;
27  
28  /**
29   * This is a list of used font-awesome icons in Tobago. Feel free to extend.
30   */
31  public enum Icons implements CssItem {
32  
33    ANGLE_DOUBLE_LEFT,
34    ANGLE_DOUBLE_RIGHT,
35    ANGLE_DOWN,
36    ANGLE_LEFT,
37    ANGLE_RIGHT,
38    ANGLE_UP,
39    BACKWARD,
40    BARS,
41    CALENDAR,
42    CLOCK_O,
43    ELLIPSIS_H,
44    EXCLAMATION,
45    FOLDER_OPEN,
46    FORWARD,
47    MINUS_SQUARE_O,
48    PLUS_SQUARE_O,
49    QUESTION,
50    SQUARE_O,
51    STEP_BACKWARD,
52    STEP_FORWARD;
53  
54    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
55  
56    public static final CssItem FA = new CssItem() {
57      @Override
58      public String getName() {
59        return "fa";
60      }
61    };
62  
63    private static final Pattern PATTERN = Pattern.compile("^(fa(-[a-z]+)+)$");
64  
65    private String fa;
66  
67    Icons() {
68      this.fa = "fa-" + name().toLowerCase().replaceAll("_", "-");
69    }
70  
71    @Override
72    public String getName() {
73      return fa;
74    }
75  
76    public static CssItem custom(final String name) {
77  
78      return new CssItem() {
79  
80        @Override
81        public String getName() {
82          if (PATTERN.matcher(name).matches()) {
83            return name;
84          } else {
85            LOG.warn("Unknown Icon: '" + name + "'");
86            return null;
87          }
88        }
89      };
90    }
91  
92  }