summaryrefslogtreecommitdiff
path: root/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GridBagConstraintsBuilder.java
blob: 9c12eaff580fd2e79f2dd6d7234866510842213d (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
package cuchaz.enigma.gui.util;

import java.awt.GridBagConstraints;

public class GridBagConstraintsBuilder {

	private final GridBagConstraints inner;

	private GridBagConstraintsBuilder(GridBagConstraints inner) {
		this.inner = inner;
	}

	public static GridBagConstraintsBuilder create() {
		return new GridBagConstraintsBuilder(new GridBagConstraints());
	}

	public GridBagConstraintsBuilder pos(int x, int y) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.gridx = x;
		copy.inner.gridy = y;
		return copy;
	}

	public GridBagConstraintsBuilder size(int width, int height) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.gridwidth = width;
		copy.inner.gridheight = height;
		return copy;
	}

	public GridBagConstraintsBuilder width(int width) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.gridwidth = width;
		return copy;
	}

	public GridBagConstraintsBuilder height(int height) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.gridheight = height;
		return copy;
	}

	public GridBagConstraintsBuilder dimensions(int x, int y, int width, int height) {
		return this.pos(x, y).size(width, height);
	}

	public GridBagConstraintsBuilder weight(double x, double y) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.weightx = x;
		copy.inner.weighty = y;
		return copy;
	}

	public GridBagConstraintsBuilder weightX(double x) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.weightx = x;
		return copy;
	}

	public GridBagConstraintsBuilder weightY(double y) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.weighty = y;
		return copy;
	}

	public GridBagConstraintsBuilder anchor(int anchor) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.anchor = anchor;
		return copy;
	}

	public GridBagConstraintsBuilder fill(int fill) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.fill = fill;
		return copy;
	}

	public GridBagConstraintsBuilder insets(int all) {
		return this.insets(all, all, all, all);
	}

	public GridBagConstraintsBuilder insets(int vertical, int horizontal) {
		return this.insets(vertical, horizontal, vertical, horizontal);
	}

	public GridBagConstraintsBuilder insets(int top, int horizontal, int bottom) {
		return this.insets(top, horizontal, bottom, horizontal);
	}

	public GridBagConstraintsBuilder insets(int top, int right, int bottom, int left) {
		GridBagConstraintsBuilder copy = this.copy();
		copy.inner.insets.set(top, left, bottom, right);
		return copy;
	}

	public GridBagConstraintsBuilder copy() {
		GridBagConstraints c = (GridBagConstraints) this.inner.clone();
		return new GridBagConstraintsBuilder(c);
	}

	public GridBagConstraints build() {
		return (GridBagConstraints) this.inner.clone();
	}

}