package net.oryanmat.gui.util.layout;

import javax.swing.*;
import java.awt.*;

@SuppressWarnings("UnusedDeclaration")
public class BoxLayoutBuilder<T extends JPanel> {
	private T panel;
	private int gap = 0;

	protected BoxLayoutBuilder(T panel, int axis, int gap) {
		this(panel, axis);
		this.gap = gap;
	}

	@SuppressWarnings("MagicConstant")
	protected BoxLayoutBuilder(T panel, int axis) {
		this.panel = panel;
		this.panel.setLayout(new BoxLayout(this.panel, axis));
	}

	public T getPanel() {
		return this.panel;
	}

	public BoxLayoutBuilder<T> setGap(int gap) {
		this.gap = gap;
		return this;
	}

	public BoxLayoutBuilder<T> add(Component... components) {
		for (Component component : components) {
			if (gap > 0) panel.add(createRigidArea(gap));
			this.panel.add(component);
		}

		if (gap > 0) panel.add(createRigidArea(gap));

		return this;
	}

	private static Component createRigidArea(int gap) {
		return Box.createRigidArea(new Dimension(gap, gap));
	}
}

@@ -157,14 +157,17 @@
 nds 
-JPanel
+Container
 %3E %7B%0A
@@ -177,21 +177,25 @@
 ivate T 
-panel
+container
 ;%0A%09priva
@@ -233,37 +233,41 @@
 LayoutBuilder(T 
-panel
+container
 , int axis, int 
@@ -280,21 +280,25 @@
 %0A%09%09this(
-panel
+container
 , axis);
@@ -386,21 +386,25 @@
 ilder(T 
-panel
+container
 , int ax
@@ -420,21 +420,29 @@
 his.
-panel = panel
+container = container
 ;%0A%09%09
@@ -446,21 +446,25 @@
 %0A%09%09this.
-panel
+container
 .setLayo
@@ -485,21 +485,25 @@
 ut(this.
-panel
+container
 , axis))
@@ -525,13 +525,17 @@
  get
-Panel
+Container
 () %7B
@@ -549,21 +549,25 @@
 rn this.
-panel
+container
 ;%0A%09%7D%0A%0A%09p
@@ -757,37 +757,41 @@
 %09%09%09if (gap %3E 0) 
-panel
+container
 .add(createRigid
@@ -810,21 +810,25 @@
 %09%09%09this.
-panel
+container
 .add(com
@@ -860,13 +860,17 @@
  0) 
-panel
+container
 .add

replace JPanel with Container