@Override
	public Dimension maximumLayoutSize(Container parent) {
		long height = 0;
		long width = (mColumns - 1) * mHGap;

		synchronized (parent.getTreeLock()) {
			Insets insets = parent.getInsets();
			int compCount = parent.getComponentCount();
			int[] widths = new int[mColumns];
			int rows = 1 + (compCount - 1) / mColumns;
			int i;

			width += insets.left + insets.right;

			for (int y = 0; y < rows; y++) {
				int rowHeight = 0;

				for (int x = 0; x < mColumns; x++) {
					i = y * mColumns + x;
					if (i < compCount) {
						Dimension size = parent.getComponent(i).getMaximumSize();

						if (size.height > rowHeight) {
							rowHeight = size.height;
						}
						if (size.width > widths[x]) {
							widths[x] = size.width;
						}
					}
				}
				height += rowHeight;
			}
			height += insets.top + insets.bottom;
			if (rows > 0) {
				height += (rows - 1) * mVGap;
			}

			for (i = 0; i < mColumns; i++) {
				width += widths[i];
			}
		}

		if (width > LayoutSize.MAXIMUM_SIZE) {
			width = LayoutSize.MAXIMUM_SIZE;
		}
		if (height > LayoutSize.MAXIMUM_SIZE) {
			height = LayoutSize.MAXIMUM_SIZE;
		}

		return new Dimension((int) width, (int) height);
	}