Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4a9b8845454afd3f8a8415882628da6e97e06155 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*******************************************************************************
 * Copyright (c) 2014 Florian Thienel 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:
 * 		Florian Thienel - initial API and implementation
 *******************************************************************************/
package org.eclipse.vex.core.internal.boxes;

import java.net.URL;

import org.eclipse.vex.core.internal.boxes.NodeTag.Kind;
import org.eclipse.vex.core.internal.core.Color;
import org.eclipse.vex.core.internal.core.FontSpec;
import org.eclipse.vex.core.internal.core.TextAlign;
import org.eclipse.vex.core.provisional.dom.ContentRange;
import org.eclipse.vex.core.provisional.dom.IContent;
import org.eclipse.vex.core.provisional.dom.INode;

/**
 * This factory allows the conventient creation of box structures using nested method calls to factory methods.
 *
 * @author Florian Thienel
 */
public class BoxFactory {

	public static RootBox rootBox(final IStructuralBox... children) {
		final RootBox rootBox = new RootBox();
		for (final IStructuralBox child : children) {
			rootBox.appendChild(child);
		}
		return rootBox;
	}

	public static VerticalBlock verticalBlock(final IStructuralBox... children) {
		final VerticalBlock verticalBlock = new VerticalBlock();
		for (final IStructuralBox child : children) {
			verticalBlock.appendChild(child);
		}
		return verticalBlock;
	}

	public static StructuralFrame frame(final IStructuralBox component) {
		final StructuralFrame frame = new StructuralFrame();
		frame.setComponent(component);
		return frame;
	}

	public static StructuralFrame frame(final IStructuralBox component, final Margin margin, final Border border, final Padding padding, final Color backgroundColor) {
		final StructuralFrame frame = new StructuralFrame();
		frame.setComponent(component);
		frame.setMargin(margin);
		frame.setBorder(border);
		frame.setPadding(padding);
		frame.setBackgroundColor(backgroundColor);
		return frame;
	}

	public static InlineFrame frame(final IInlineBox component) {
		final InlineFrame frame = new InlineFrame();
		frame.setComponent(component);
		return frame;
	}

	public static InlineFrame frame(final IInlineBox component, final Margin margin, final Border border, final Padding padding, final Color backgroundColor) {
		final InlineFrame frame = new InlineFrame();
		frame.setComponent(component);
		frame.setMargin(margin);
		frame.setBorder(border);
		frame.setPadding(padding);
		frame.setBackgroundColor(backgroundColor);
		return frame;
	}

	public static StructuralNodeReference nodeReference(final INode node, final IStructuralBox component) {
		final StructuralNodeReference structuralNodeReference = new StructuralNodeReference();
		structuralNodeReference.setNode(node);
		structuralNodeReference.setComponent(component);
		return structuralNodeReference;
	}

	public static StructuralNodeReference nodeReferenceWithInlineContent(final INode node, final IStructuralBox component) {
		final StructuralNodeReference structuralNodeReference = new StructuralNodeReference();
		structuralNodeReference.setNode(node);
		structuralNodeReference.setContainsInlineContent(true);
		structuralNodeReference.setComponent(component);
		return structuralNodeReference;
	}

	public static StructuralNodeReference nodeReferenceWithText(final INode node, final IStructuralBox component) {
		final StructuralNodeReference structuralNodeReference = new StructuralNodeReference();
		structuralNodeReference.setNode(node);
		structuralNodeReference.setCanContainText(true);
		structuralNodeReference.setContainsInlineContent(true);
		structuralNodeReference.setComponent(component);
		return structuralNodeReference;
	}

	public static InlineNodeReference nodeReference(final INode node, final IInlineBox component) {
		final InlineNodeReference inlineNodeReference = new InlineNodeReference();
		inlineNodeReference.setNode(node);
		inlineNodeReference.setComponent(component);
		return inlineNodeReference;
	}

	public static InlineNodeReference nodeReferenceWithText(final INode node, final IInlineBox component) {
		final InlineNodeReference inlineNodeReference = new InlineNodeReference();
		inlineNodeReference.setNode(node);
		inlineNodeReference.setCanContainText(true);
		inlineNodeReference.setComponent(component);
		return inlineNodeReference;
	}

	public static HorizontalBar horizontalBar(final int height) {
		final HorizontalBar horizontalBar = new HorizontalBar();
		horizontalBar.setHeight(height);
		return horizontalBar;
	}

	public static HorizontalBar horizontalBar(final int height, final Color color) {
		final HorizontalBar horizontalBar = new HorizontalBar();
		horizontalBar.setHeight(height);
		horizontalBar.setColor(color);
		return horizontalBar;
	}

	public static Paragraph paragraph(final IInlineBox... children) {
		final Paragraph paragraph = new Paragraph();
		for (final IInlineBox child : children) {
			paragraph.appendChild(child);
		}
		return paragraph;
	}

	public static Paragraph paragraph(final TextAlign textAlign, final IInlineBox... children) {
		final Paragraph paragraph = new Paragraph();
		for (final IInlineBox child : children) {
			paragraph.appendChild(child);
		}
		paragraph.setTextAlign(textAlign);
		return paragraph;
	}

	public static InlineContainer inlineContainer(final IInlineBox... children) {
		final InlineContainer inlineContainer = new InlineContainer();
		for (final IInlineBox child : children) {
			inlineContainer.appendChild(child);
		}
		return inlineContainer;
	}

	public static TextContent textContent(final IContent content, final ContentRange range, final FontSpec font, final Color color) {
		final TextContent textContent = new TextContent();
		textContent.setContent(content, range);
		textContent.setFont(font);
		textContent.setColor(color);
		return textContent;
	}

	public static NodeEndOffsetPlaceholder endOffsetPlaceholder(final INode node, final FontSpec font) {
		final NodeEndOffsetPlaceholder contentPlaceholder = new NodeEndOffsetPlaceholder();
		contentPlaceholder.setNode(node);
		contentPlaceholder.setFont(font);
		return contentPlaceholder;
	}

	public static StaticText staticText(final String text, final FontSpec font, final Color color) {
		final StaticText staticText = new StaticText();
		staticText.setText(text);
		staticText.setFont(font);
		staticText.setColor(color);
		return staticText;
	}

	public static Image image(final URL imageUrl) {
		final Image image = new Image();
		image.setImageUrl(imageUrl);
		return image;
	}

	public static Square square(final int size, final Color color) {
		final Square square = new Square();
		square.setSize(size);
		square.setColor(color);
		return square;
	}

	public static NodeTag nodeTag(final Kind kind, final INode node, final Color foreground) {
		final NodeTag nodeTag = new NodeTag();
		nodeTag.setKind(kind);
		nodeTag.setNode(node);
		nodeTag.setColor(foreground);
		return nodeTag;
	}
}

Back to the top