aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui/gui/widgets/GCBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/ui/gui/widgets/GCBuilder.java')
-rw-r--r--src/main/ui/gui/widgets/GCBuilder.java213
1 files changed, 213 insertions, 0 deletions
diff --git a/src/main/ui/gui/widgets/GCBuilder.java b/src/main/ui/gui/widgets/GCBuilder.java
new file mode 100644
index 0000000..a571aab
--- /dev/null
+++ b/src/main/ui/gui/widgets/GCBuilder.java
@@ -0,0 +1,213 @@
+package ui.gui.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;
+ }
+}