aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui/widgets/GCBuilder.java
blob: 0590cc10b7eadffadd816c5d065dd32c05779722 (plain)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
package ui.widgets;

import java.awt.*;

/**
 * A builder for {@link GridBagConstraints}.
 */
public class GCBuilder {
    /**
     * Grix X and Y, defaults to {@link GridBagConstraints#RELATIVE}
     */
    private int gridX = GridBagConstraints.RELATIVE;

    private int gridY = GridBagConstraints.RELATIVE;

    /**
     * Weight X and Y, [0.0, 1.0], defaults to 0.0
     */
    private double weightX = 0.0;

    private double weightY = 0.0;

    /**
     * Anchor, defaults to {@link GridBagConstraints#CENTER}
     */
    private int anchor = GridBagConstraints.CENTER;

    /**
     * How to stretch the component, defaults to {@link GridBagConstraints#NONE}
     */
    private int fill = GridBagConstraints.NONE;

    /**
     * Insects in pixels.
     */
    private int insectTop = 0;

    private int insectLeft = 0;

    private int insectRight = 0;

    private int insectBottom = 0;

    /**
     * EFFECTS: Build the {@link GridBagConstraints} based on parameters.
     * Grid width, grid height, ipad X, ipad Y will be 1, 1, 0, 0.
     */
    public GridBagConstraints build() {
        return new GridBagConstraints(gridX, gridY,
                1, 1,
                weightX, weightY,
                anchor, fill,
                new Insets(insectTop, insectLeft, insectBottom, insectRight),
                0, 0);
    }

    /**
     * EFFECTS: Set grid X and Y.
     * REQUIRES: > 0
     * MODIFIES: this
     */
    public GCBuilder gridXY(int gridX, int gridY) {
        return this.gridX(gridX).gridY(gridY);
    }

    /**
     * EFFECTS: Set grid X.
     * REQUIRES: > 0
     * MODIFIES: this
     */
    public GCBuilder gridX(int gridX) {
        this.gridX = gridX;
        return this;
    }

    /**
     * EFFECTS: Set grid Y.
     * REQUIRES: > 0
     * MODIFIES: this
     */
    public GCBuilder gridY(int gridY) {
        this.gridY = gridY;
        return this;
    }

    /**
     * EFFECTS: Set weight X and Y.
     * REQUIRES: [0.0, 1.0]
     * MODIFIES: this
     */
    public GCBuilder weightXY(double weightX, double weightY) {
        return this.weightX(weightX).weightY(weightY);
    }

    /**
     * EFFECTS: Set weight X and Y to 1.0
     * MODIFIES: this
     */
    public GCBuilder expandXY() {
        return this.expandX().expandY();
    }

    /**
     * EFFECTS: Set weight X to 1.0
     * MODIFIES: this
     */
    public GCBuilder expandX() {
        return this.weightX(1.0);
    }

    /**
     * EFFECTS: Set weight X to 1.0
     * MODIFIES: this
     */
    public GCBuilder weightX(double weightX) {
        this.weightX = weightX;
        return this;
    }

    /**
     * EFFECTS: Set weight Y to 1.0
     * MODIFIES: this
     */
    public GCBuilder expandY() {
        return this.weightY(1.0);
    }

    /**
     * EFFECTS: Set weight X to 1.0
     * MODIFIES: this
     */
    public GCBuilder weightY(double weightY) {
        this.weightY = weightY;
        return this;
    }

    /**
     * EFFECTS: Set anchor.
     * REQUIRES: anchor in {@link GridBagConstraints} constants.
     * MODIFIES: this
     */
    public GCBuilder anchor(int anchor) {
        this.anchor = anchor;
        return this;
    }

    /**
     * EFFECTS: Set fill.
     * REQUIRES: fill in {@link GridBagConstraints} constants.
     * MODIFIES: this
     */
    public GCBuilder fill(int fill) {
        this.fill = fill;
        return this;
    }

    /**
     * EFFECTS: Set insects to be 8, 8, 8, 8
     * MODIFIES: this
     */
    public GCBuilder marginInsects() {
        return this.insects(8, 8, 8, 8);
    }

    /**
     * EFFECTS: Set insects.
     * REQUIRES: >= 0
     * MODIFIES: this
     */
    public GCBuilder insects(int top, int left, int bottom, int right) {
        return this.insectTop(top).insectLeft(left).insectBottom(bottom).insectRight(right);
    }

    /**
     * EFFECTS: Set top insect
     * REQUIRES: >= 0
     * MODIFIES: this
     */
    public GCBuilder insectTop(int insectTop) {
        this.insectTop = insectTop;
        return this;
    }

    /**
     * EFFECTS: Set left insect
     * REQUIRES: >= 0
     * MODIFIES: this
     */
    public GCBuilder insectLeft(int insectLeft) {
        this.insectLeft = insectLeft;
        return this;
    }

    /**
     * EFFECTS: Set right insect
     * REQUIRES: >= 0
     * MODIFIES: this
     */
    public GCBuilder insectRight(int insectRight) {
        this.insectRight = insectRight;
        return this;
    }

    /**
     * EFFECTS: Set bottom insect
     * REQUIRES: >= 0
     * MODIFIES: this
     */
    public GCBuilder insectBottom(int insectBottom) {
        this.insectBottom = insectBottom;
        return this;
    }
}