]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagInfoBuilder.java
Fixed multiple issues causing dangling references to discarded queries
[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.Font;
15 import java.awt.Shape;
16 import java.awt.geom.Rectangle2D;
17
18 import org.simantics.diagram.flag.IFlagType.FlagInfo;
19 import org.simantics.g2d.elementclass.FlagClass.Type;
20 import org.simantics.g2d.utils.Alignment;
21
22 /**
23  * A builder for {@link FlagInfoImpl} instances.
24  * 
25  * @author Tuukka Lehtonen
26  */
27 public class FlagInfoBuilder {
28
29     private static final String[] NO_TEXT = {};
30
31     private Shape       shape;
32     private String[]    text = NO_TEXT;
33     private Type        type;
34     private Rectangle2D textArea;
35     private Alignment   horizontalAlignment = Alignment.LEADING;
36     private Alignment   verticalAlignment = Alignment.CENTER;
37     private Font        font;
38
39     public static FlagInfoBuilder fill(Type type) {
40         return new FlagInfoBuilder().type(type);
41     }
42
43     public FlagInfoBuilder() {
44     }
45
46     public FlagInfo create() {
47         return new FlagInfoImpl(shape, text, type, textArea, horizontalAlignment, verticalAlignment, font);
48     }
49
50     public Shape shape() {
51         return shape;
52     }
53
54     public String[] text() {
55         return text;
56     }
57
58     public Font font() {
59         return font;
60     }
61     
62     public Type type() {
63         return type;
64     }
65
66     public Rectangle2D textArea() {
67         return textArea;
68     }
69
70     public Alignment horizontalAlignment() {
71         return horizontalAlignment;
72     }
73
74     public Alignment verticalAlignment() {
75         return verticalAlignment;
76     }
77
78     public FlagInfoBuilder shape(Shape shape) {
79         this.shape = shape;
80         return this;
81     }
82
83     public FlagInfoBuilder text(String[] text) {
84         this.text = text;
85         return this;
86     }
87     
88     public FlagInfoBuilder font(Font font) {
89         this.font = font;
90         return this;
91     }
92
93     public FlagInfoBuilder type(Type type) {
94         this.type = type;
95         return this;
96     }
97
98     public FlagInfoBuilder textArea(Rectangle2D textArea) {
99         this.textArea = textArea;
100         return this;
101     }
102
103     public FlagInfoBuilder horizontalAlignment(Alignment align) {
104         this.horizontalAlignment = align;
105         return this;
106     }
107
108     public FlagInfoBuilder verticalAlignment(Alignment align) {
109         this.verticalAlignment = align;
110         return this;
111     }
112
113 }