diff options
Diffstat (limited to 'enigma-swing/src/main/java')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/util/GridBagConstraintsBuilder.java | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GridBagConstraintsBuilder.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GridBagConstraintsBuilder.java new file mode 100644 index 0000000..9c12eaf --- /dev/null +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GridBagConstraintsBuilder.java | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | package cuchaz.enigma.gui.util; | ||
| 2 | |||
| 3 | import java.awt.GridBagConstraints; | ||
| 4 | |||
| 5 | public class GridBagConstraintsBuilder { | ||
| 6 | |||
| 7 | private final GridBagConstraints inner; | ||
| 8 | |||
| 9 | private GridBagConstraintsBuilder(GridBagConstraints inner) { | ||
| 10 | this.inner = inner; | ||
| 11 | } | ||
| 12 | |||
| 13 | public static GridBagConstraintsBuilder create() { | ||
| 14 | return new GridBagConstraintsBuilder(new GridBagConstraints()); | ||
| 15 | } | ||
| 16 | |||
| 17 | public GridBagConstraintsBuilder pos(int x, int y) { | ||
| 18 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 19 | copy.inner.gridx = x; | ||
| 20 | copy.inner.gridy = y; | ||
| 21 | return copy; | ||
| 22 | } | ||
| 23 | |||
| 24 | public GridBagConstraintsBuilder size(int width, int height) { | ||
| 25 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 26 | copy.inner.gridwidth = width; | ||
| 27 | copy.inner.gridheight = height; | ||
| 28 | return copy; | ||
| 29 | } | ||
| 30 | |||
| 31 | public GridBagConstraintsBuilder width(int width) { | ||
| 32 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 33 | copy.inner.gridwidth = width; | ||
| 34 | return copy; | ||
| 35 | } | ||
| 36 | |||
| 37 | public GridBagConstraintsBuilder height(int height) { | ||
| 38 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 39 | copy.inner.gridheight = height; | ||
| 40 | return copy; | ||
| 41 | } | ||
| 42 | |||
| 43 | public GridBagConstraintsBuilder dimensions(int x, int y, int width, int height) { | ||
| 44 | return this.pos(x, y).size(width, height); | ||
| 45 | } | ||
| 46 | |||
| 47 | public GridBagConstraintsBuilder weight(double x, double y) { | ||
| 48 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 49 | copy.inner.weightx = x; | ||
| 50 | copy.inner.weighty = y; | ||
| 51 | return copy; | ||
| 52 | } | ||
| 53 | |||
| 54 | public GridBagConstraintsBuilder weightX(double x) { | ||
| 55 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 56 | copy.inner.weightx = x; | ||
| 57 | return copy; | ||
| 58 | } | ||
| 59 | |||
| 60 | public GridBagConstraintsBuilder weightY(double y) { | ||
| 61 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 62 | copy.inner.weighty = y; | ||
| 63 | return copy; | ||
| 64 | } | ||
| 65 | |||
| 66 | public GridBagConstraintsBuilder anchor(int anchor) { | ||
| 67 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 68 | copy.inner.anchor = anchor; | ||
| 69 | return copy; | ||
| 70 | } | ||
| 71 | |||
| 72 | public GridBagConstraintsBuilder fill(int fill) { | ||
| 73 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 74 | copy.inner.fill = fill; | ||
| 75 | return copy; | ||
| 76 | } | ||
| 77 | |||
| 78 | public GridBagConstraintsBuilder insets(int all) { | ||
| 79 | return this.insets(all, all, all, all); | ||
| 80 | } | ||
| 81 | |||
| 82 | public GridBagConstraintsBuilder insets(int vertical, int horizontal) { | ||
| 83 | return this.insets(vertical, horizontal, vertical, horizontal); | ||
| 84 | } | ||
| 85 | |||
| 86 | public GridBagConstraintsBuilder insets(int top, int horizontal, int bottom) { | ||
| 87 | return this.insets(top, horizontal, bottom, horizontal); | ||
| 88 | } | ||
| 89 | |||
| 90 | public GridBagConstraintsBuilder insets(int top, int right, int bottom, int left) { | ||
| 91 | GridBagConstraintsBuilder copy = this.copy(); | ||
| 92 | copy.inner.insets.set(top, left, bottom, right); | ||
| 93 | return copy; | ||
| 94 | } | ||
| 95 | |||
| 96 | public GridBagConstraintsBuilder copy() { | ||
| 97 | GridBagConstraints c = (GridBagConstraints) this.inner.clone(); | ||
| 98 | return new GridBagConstraintsBuilder(c); | ||
| 99 | } | ||
| 100 | |||
| 101 | public GridBagConstraints build() { | ||
| 102 | return (GridBagConstraints) this.inner.clone(); | ||
| 103 | } | ||
| 104 | |||
| 105 | } | ||