]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagInfoBuilder.java
Some enhancements to GraphLayer-related utilities for Diagram layers
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / flag / FlagInfoBuilder.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.flag;
13
14 import java.awt.Shape;
15 import java.awt.geom.Rectangle2D;
16
17 import org.simantics.diagram.flag.IFlagType.FlagInfo;
18 import org.simantics.g2d.elementclass.FlagClass.Type;
19 import org.simantics.g2d.utils.Alignment;
20
21 /**
22  * A builder for {@link FlagInfoImpl} instances.
23  * 
24  * @author Tuukka Lehtonen
25  */
26 public class FlagInfoBuilder {
27
28     private static final String[] NO_TEXT = {};
29
30     private Shape       shape;
31     private String[]    text = NO_TEXT;
32     private Type        type;
33     private Rectangle2D textArea;
34     private Alignment   horizontalAlignment = Alignment.LEADING;
35     private Alignment   verticalAlignment = Alignment.CENTER;
36
37     public static FlagInfoBuilder fill(Type type) {
38         return new FlagInfoBuilder().type(type);
39     }
40
41     public FlagInfoBuilder() {
42     }
43
44     public FlagInfo create() {
45         return new FlagInfoImpl(shape, text, type, textArea, horizontalAlignment, verticalAlignment);
46     }
47
48     public Shape shape() {
49         return shape;
50     }
51
52     public String[] text() {
53         return text;
54     }
55
56     public Type type() {
57         return type;
58     }
59
60     public Rectangle2D textArea() {
61         return textArea;
62     }
63
64     public Alignment horizontalAlignment() {
65         return horizontalAlignment;
66     }
67
68     public Alignment verticalAlignment() {
69         return verticalAlignment;
70     }
71
72     public FlagInfoBuilder shape(Shape shape) {
73         this.shape = shape;
74         return this;
75     }
76
77     public FlagInfoBuilder text(String[] text) {
78         this.text = text;
79         return this;
80     }
81
82     public FlagInfoBuilder type(Type type) {
83         this.type = type;
84         return this;
85     }
86
87     public FlagInfoBuilder textArea(Rectangle2D textArea) {
88         this.textArea = textArea;
89         return this;
90     }
91
92     public FlagInfoBuilder horizontalAlignment(Alignment align) {
93         this.horizontalAlignment = align;
94         return this;
95     }
96
97     public FlagInfoBuilder verticalAlignment(Alignment align) {
98         this.verticalAlignment = align;
99         return this;
100     }
101
102 }