View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.eclipse.common.util;
17  
18  import org.eclipse.jface.resource.FontRegistry;
19  import org.eclipse.swt.graphics.Font;
20  import org.eclipse.swt.graphics.FontData;
21  import org.eclipse.swt.widgets.Display;
22  
23  /**
24   * @author y-komori
25   * 
26   */
27  public class FontManager {
28      protected static final FontRegistry registry = new FontRegistry(Display
29              .getCurrent(), true);
30  
31      public static Font get(final String name, final int height, final int style) {
32          String descriptor = getDescriptor(name, height, style);
33          Font font;
34          if (registry.hasValueFor(descriptor)) {
35              font = registry.get(descriptor);
36          } else {
37              FontData fontData = new FontData(name, height, style);
38              font = new Font(Display.getCurrent(), fontData);
39              registry.put(descriptor, new FontData[] { fontData });
40          }
41          return font;
42      }
43  
44      protected static String getDescriptor(final String name, final int height,
45              final int style) {
46          return name + "_" + height + "_" + style;
47      }
48  }