Skip to main content
summaryrefslogtreecommitdiffstats
blob: de2eaa8d92af32863e14c320a89fe8df7e1d83cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.layout;

import org.eclipse.draw2d.LayoutManager;
import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTRGroupLayout;
import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTRLayout;
import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableCaptionLayout;
import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableCellLayout;
import org.eclipse.jst.pagedesigner.css2.layout.table.CSSTableLayout2;
import org.eclipse.jst.pagedesigner.css2.property.ICSSPropertyID;
import org.eclipse.jst.pagedesigner.css2.property.PositionMeta;

/**
 * @author mengbo
 */
public class DisplayToLayout {
	/**
	 * @param figure
	 * @param display
	 * @param old
	 * @return
	 */
	public static CSSLayout displayToLayout(CSSFigure figure, String display,
			LayoutManager old) {
		if ("block".equalsIgnoreCase(display)) //$NON-NLS-1$
		{
			return new CSSBlockFlowLayout(figure);
		} else if ("inline".equalsIgnoreCase(display)) //$NON-NLS-1$
		{
			return new CSSInlineFlowLayout(figure);
		} else if ("table".equalsIgnoreCase(display) || "inline-table".equalsIgnoreCase(display)) //$NON-NLS-1$ $NON-NLS-2$
		{
			return new CSSTableLayout2(figure);
		} else if ("table-row".equalsIgnoreCase(display)) //$NON-NLS-1$
		{
			return new CSSTRLayout(figure);
		} else if ("table-row-group".equalsIgnoreCase(display) //$NON-NLS-1$
				|| "table-header-group".equalsIgnoreCase(display) //$NON-NLS-1$
				|| "table-footer-group".equalsIgnoreCase(display)) //$NON-NLS-1$
		{
			return new CSSTRGroupLayout(figure);
		} else if ("table-cell".equalsIgnoreCase(display)) //$NON-NLS-1$
		{
			return new CSSTableCellLayout(figure);
		} else if (display.equalsIgnoreCase("table-caption")) //$NON-NLS-1$
		{
			return new CSSTableCaptionLayout(figure);
		} else if ("inline-block".equalsIgnoreCase(display)) //$NON-NLS-1$
		{
			return new CSSBlockFlowLayout(figure) {
				/*
				 * (non-Javadoc)
				 * 
				 * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#isInlineBlock()
				 */
				public boolean isInlineBlock() {
					return true;
				}
			};
		} else if (ICSSPropertyID.VAL_LIST_ITEM.equalsIgnoreCase(display)) {
			return new CSSListItemLayout(figure);
		}
		return null;
	}

	/**
	 * @param figure
	 * @param display
	 * @param old
	 * @return
	 */
	public static boolean isInline(String display) {
		return "inline".equalsIgnoreCase(display) //$NON-NLS-1$
				|| "inline-block".equalsIgnoreCase(display); //$NON-NLS-1$
	}

	/**
	 * @param style
	 * @return
	 */
	public static boolean isPositioned(ICSSStyle style) {
		Object position = style.getStyleProperty(ICSSPropertyID.ATTR_POSITION);
		if (PositionMeta.STATIC.equalsIgnoreCase((String) position)) {
			return false;
		} else {
			return true;
		}
	}
}

Back to the top