Initialize
[sdk/ide/product.git] / org.eclipse.jst.pagedesigner / src / org / eclipse / jst / pagedesigner / css2 / layout / DisplayToLayout.java
1 /*******************************************************************************\r
2  * Copyright (c) 2006 Sybase, Inc. and others.\r
3  *\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     Sybase, Inc. - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.eclipse.jst.pagedesigner.css2.layout;\r
13 \r
14 import org.eclipse.draw2d.LayoutManager;\r
15 import org.eclipse.jst.pagedesigner.css2.ICSSStyle;\r
16 import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTRGroupLayout;\r
17 import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTRLayout;\r
18 import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableCaptionLayout;\r
19 import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableCellLayout;\r
20 import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableLayout2;\r
21 import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID;\r
22 import org.eclipse.jst.pagedesigner.css2.property.PositionMeta;\r
23 \r
24 /**\r
25  * @author mengbo\r
26  */\r
27 public final class DisplayToLayout {\r
28         /**\r
29          * @param figure\r
30          * @param display\r
31          * @param old\r
32          * @return the layout\r
33          */\r
34         public static CSSLayout displayToLayout(CSSFigure figure, String display,\r
35                         LayoutManager old) {\r
36                 if ("block".equalsIgnoreCase(display)) //$NON-NLS-1$\r
37                 {\r
38                         return new CSSBlockFlowLayout(figure);\r
39                 } else if ("inline".equalsIgnoreCase(display)) //$NON-NLS-1$\r
40                 {\r
41                         return new CSSInlineFlowLayout(figure);\r
42                 } else if ("table".equalsIgnoreCase(display) || "inline-table".equalsIgnoreCase(display)) //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$\r
43                 {\r
44                         return new CSSTableLayout2(figure);\r
45                 } else if ("table-row".equalsIgnoreCase(display)) //$NON-NLS-1$\r
46                 {\r
47                         return new CSSTRLayout(figure);\r
48                 } else if ("table-row-group".equalsIgnoreCase(display) //$NON-NLS-1$\r
49                                 || "table-header-group".equalsIgnoreCase(display) //$NON-NLS-1$\r
50                                 || "table-footer-group".equalsIgnoreCase(display)) //$NON-NLS-1$\r
51                 {\r
52                         return new CSSTRGroupLayout(figure);\r
53                 } else if ("table-cell".equalsIgnoreCase(display)) //$NON-NLS-1$\r
54                 {\r
55                         return new CSSTableCellLayout(figure);\r
56                 } else if (display.equalsIgnoreCase("table-caption")) //$NON-NLS-1$\r
57                 {\r
58                         return new CSSTableCaptionLayout(figure);\r
59                 } else if ("inline-block".equalsIgnoreCase(display)) //$NON-NLS-1$\r
60                 {\r
61                         return new CSSBlockFlowLayout(figure) {\r
62                                 /*\r
63                                  * (non-Javadoc)\r
64                                  * \r
65                                  * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#isInlineBlock()\r
66                                  */\r
67                                 public boolean isInlineBlock() {\r
68                                         return true;\r
69                                 }\r
70                         };\r
71                 } else if (ICSSPropertyID.VAL_LIST_ITEM.equalsIgnoreCase(display)) {\r
72                         return new CSSListItemLayout(figure);\r
73                 }\r
74                 return null;\r
75         }\r
76 \r
77         /**\r
78          * @param display \r
79          * @return true if is inline\r
80          */\r
81         public static boolean isInline(String display) {\r
82                 return "inline".equalsIgnoreCase(display) //$NON-NLS-1$\r
83                                 || "inline-block".equalsIgnoreCase(display); //$NON-NLS-1$\r
84         }\r
85 \r
86         /**\r
87          * @param style\r
88          * @return true if is positioned\r
89          */\r
90         public static boolean isPositioned(ICSSStyle style) {\r
91                 Object position = style.getStyleProperty(ICSSPropertyID.ATTR_POSITION);\r
92                 if (PositionMeta.STATIC.equalsIgnoreCase((String) position)) {\r
93                         return false;\r
94                 }\r
95         return true;\r
96         }\r
97         \r
98         private DisplayToLayout()\r
99         {\r
100             // util class, no instantiation\r
101         }\r
102 }\r