mirror of https://github.com/FreeCol/freecol.git
WrapLayout can now force components to have a specific size. This allows the use of WrapLayout in many of the places we earlier had fixed column based layouts with GridLayout.
This commit is contained in:
parent
a45d17226a
commit
9d36d7ef4a
|
@ -96,6 +96,7 @@ public class WrapLayout implements LayoutManager {
|
|||
private HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER;
|
||||
private LayoutStyle layoutStyle = LayoutStyle.BALANCED;
|
||||
private HorizontalGap horizontalGap = HorizontalGap.AUTO;
|
||||
private Dimension forceComponentSize = null;
|
||||
|
||||
private int minHorizontalGap = 0;
|
||||
private int minVerticalGap = 0;
|
||||
|
@ -166,6 +167,17 @@ public class WrapLayout implements LayoutManager {
|
|||
this.maxHorizontalGap = maxHorizontalGap;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces all child components to have the given size.
|
||||
*
|
||||
* @param forceComponentSize The component size.
|
||||
* @return This object, in order to support method chaining.
|
||||
*/
|
||||
public WrapLayout withForceComponentSize(Dimension forceComponentSize) {
|
||||
this.forceComponentSize = forceComponentSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preferred dimensions for this layout given the <i>visible</i>
|
||||
|
@ -259,6 +271,9 @@ public class WrapLayout implements LayoutManager {
|
|||
Dimension currentRowSize = new Dimension(0, 0);
|
||||
for (Component component : getVisibleComponents(target, layoutBottomToTop)) {
|
||||
Dimension d = preferred ? component.getPreferredSize() : component.getMinimumSize();
|
||||
if (forceComponentSize != null) {
|
||||
d = forceComponentSize;
|
||||
}
|
||||
|
||||
// Can't add the component to current row. Start a new row.
|
||||
if (currentRowSize.width + d.width > maxWidth) {
|
||||
|
|
Loading…
Reference in New Issue