Skip to main content
summaryrefslogtreecommitdiffstats
blob: 27d15717c1f9161e2bc627bff6050a0f35d25424 (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
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
 * 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.table;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.LayoutManager;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jst.pagedesigner.css2.layout.CSSFigure;

/**
 * @author mengbo
 * @version 1.5
 */
public class CSSTableCaptionLayout extends CachedTableCellLayout {
	private CSSTableLayout2 _tableLayout;

	private TableCaptionInfo _caption;

	/**
	 * @param cssfigure
	 */
	public CSSTableCaptionLayout(CSSFigure cssfigure) {
		super(cssfigure);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#invalidate()
	 */
	public void invalidate() {
		super.invalidate();

		_tableLayout = null;
		_caption = null;
	}

	public Rectangle getCellRect() {
		int x = 0;

		int[] rowHeights = _tableLayout.getRowHeights();
		int vspacing = _tableLayout.getVSpacing();
		int y = vspacing;
		if (_caption != null && "bottom".equalsIgnoreCase(_caption.getAlign())) //$NON-NLS-1$
		{
			for (int row = 0; row < rowHeights.length; row++) {
				y += rowHeights[row];
				y += vspacing;
			}
		}

		int height = 0;
		height = _tableLayout.getCaptionSize().height;
		int width = _tableLayout.getCaptionSize().width;
		Rectangle rect = new Rectangle(x, y, width, height);
		return rect;
	}

	/**
	 * the parent figure of TRGroup should be table figure. If so, return the
	 * corresponding table layout.
	 * 
	 * @return
	 */
	public CSSTableLayout2 getTableLayoutContext() {
		IFigure parent = getCSSFigure().getParent();
		if (parent != null) {
			LayoutManager parentLayout = parent.getLayoutManager();
			if (parentLayout instanceof CSSTableLayout2) {
				return (CSSTableLayout2) parentLayout;
			}
		}
		return null;
	}

	/**
	 * @return
	 */
	public boolean initializeTableInfo() {
		_caption = null;
		_tableLayout = getTableLayoutContext();
		if (_tableLayout != null) {
			_caption = _tableLayout.getCaptionInfo();
			return _caption != null;
		}
		return false;
	}

	public CSSTableLayout2 getTableLayout() {
		return _tableLayout;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#isCalculatingMaxWidth()
	 */
	public boolean isCalculatingMaxWidth() {
		return false;
	}
}

Back to the top