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.uruma.renderer.layout;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.eclipse.swt.layout.FillLayout;
22  import org.eclipse.swt.layout.GridData;
23  import org.eclipse.swt.layout.GridLayout;
24  import org.eclipse.swt.layout.RowData;
25  import org.eclipse.swt.layout.RowLayout;
26  import org.seasar.uruma.component.LayoutInfo;
27  import org.seasar.uruma.component.jface.FillLayoutInfo;
28  import org.seasar.uruma.component.jface.GridLayoutInfo;
29  import org.seasar.uruma.component.jface.RowLayoutInfo;
30  import org.seasar.uruma.renderer.layout.impl.GenericLayoutSupport;
31  
32  /**
33   * {@link LayoutSupport} の実装クラスを取得するためのファクトリです。</br>
34   * 
35   * @author y-komori
36   */
37  public class LayoutSupportFactory {
38      private static final Map<Class<? extends LayoutInfo<?>>, LayoutSupport> LAYOUT_SUPPORT_MAP = new HashMap<Class<? extends LayoutInfo<?>>, LayoutSupport>();
39  
40      static {
41          addLayoutSupport(FillLayoutInfo.class, new GenericLayoutSupport(
42                  FillLayout.class, null));
43          addLayoutSupport(RowLayoutInfo.class, new GenericLayoutSupport(
44                  RowLayout.class, RowData.class));
45          addLayoutSupport(GridLayoutInfo.class, new GenericLayoutSupport(
46                  GridLayout.class, GridData.class));
47      }
48  
49      /**
50       * {@link LayoutInfo} クラスをキーにして、レイアウトサポートクラスを取得します。<br />
51       * 
52       * @param layoutInfo
53       *            {@link LayoutInfo} クラス。
54       * @return レイアウトサポートクラス。見つからない場合は <code>null</code>
55       */
56      public static LayoutSupport getLayoutSupport(
57              final Class<? extends LayoutInfo<?>> layoutInfo) {
58          return LAYOUT_SUPPORT_MAP.get(layoutInfo);
59      }
60  
61      /**
62       * レイアウトサポートクラスを追加します</br>
63       * 
64       * @param layoutSupport
65       *            レイアウトサポートクラス
66       */
67      public static void addLayoutSupport(
68              final Class<? extends LayoutInfo<?>> layoutInfo,
69              final LayoutSupport layoutSupport) {
70          LAYOUT_SUPPORT_MAP.put(layoutInfo, layoutSupport);
71      }
72  }