View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
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  
17  package net.sf.ehcache.hibernate.management.impl;
18  
19  import java.awt.Color;
20  
21  /***
22   * CacheRegionUtils
23   * 
24   * @author gkeim
25   */
26  public abstract class CacheRegionUtils {
27    /***
28     * HIT_COLOR
29     */
30    public static final Color HIT_COLOR = Color.green;
31    
32    /***
33     * MISS_COLOR
34     */
35    public static final Color MISS_COLOR = Color.red;
36    
37    /***
38     * PUT_COLOR
39     */
40    public static final Color PUT_COLOR = Color.blue;
41    
42    /***
43     * HIT_FILL_COLOR
44     */
45    public static final Color HIT_FILL_COLOR = CacheRegionUtils.HIT_COLOR.brighter().brighter().brighter();
46    
47    /***
48     * MISS_FILL_COLOR
49     */
50    public static final Color MISS_FILL_COLOR = CacheRegionUtils.MISS_COLOR.brighter().brighter().brighter();
51    
52    /***
53     * PUT_FILL_COLOR
54     */
55    public static final Color PUT_FILL_COLOR = CacheRegionUtils.PUT_COLOR.brighter().brighter().brighter();
56    
57    /***
58     * HIT_DRAW_COLOR
59     */
60    public static final Color HIT_DRAW_COLOR = CacheRegionUtils.HIT_COLOR.darker();
61    
62    /***
63     * MISS_DRAW_COLOR
64     */
65    public static final Color MISS_DRAW_COLOR = CacheRegionUtils.MISS_COLOR.darker();
66    
67    /***
68     * PUT_DRAW_COLOR
69     */
70    public static final Color PUT_DRAW_COLOR = CacheRegionUtils.PUT_COLOR.darker();
71    
72  
73    /***
74     * determineShortName
75     * 
76     * @param fullName
77     */
78    public static String determineShortName(String fullName) {
79      String result = fullName;
80  
81      if (fullName != null) {
82        String[] comps = fullName.split("//.");
83        if (comps.length == 1) {
84            return fullName;
85        }
86        boolean truncate = true;
87        for (int i = 0; i < comps.length; i++) {
88          String comp = comps[i];
89          char c = comp.charAt(0);
90          if (truncate && Character.isUpperCase(c)) {
91            truncate = false;
92          }
93          if (truncate) {
94            comps[i] = Character.toString(c);
95          }
96        }
97        result = join(comps, '.');
98      }
99  
100     return result;
101   }
102 
103   /***
104    * join
105    * 
106    * @param elements
107    * @param c
108    */
109   private static String join(String[] elements, char c) {
110     if (elements == null) { return null; }
111     StringBuilder sb = new StringBuilder();
112     for (String s : elements) {
113       sb.append(s).append(c);
114     }
115     return sb.length() > 0 ? sb.substring(0, sb.length() - 1) : "";
116   }
117 }