mirror of https://github.com/FreeCol/freecol.git
The WrapLayout can now make every child component have the same size as the largest child.
This commit is contained in:
parent
dd23a7c3ac
commit
7dfa486570
|
@ -97,6 +97,7 @@ public class WrapLayout implements LayoutManager {
|
||||||
private LayoutStyle layoutStyle = LayoutStyle.BALANCED;
|
private LayoutStyle layoutStyle = LayoutStyle.BALANCED;
|
||||||
private HorizontalGap horizontalGap = HorizontalGap.AUTO;
|
private HorizontalGap horizontalGap = HorizontalGap.AUTO;
|
||||||
private Dimension forceComponentSize = null;
|
private Dimension forceComponentSize = null;
|
||||||
|
private boolean allComponentsWithTheSameSize = false;
|
||||||
|
|
||||||
private int minHorizontalGap = 0;
|
private int minHorizontalGap = 0;
|
||||||
private int minVerticalGap = 0;
|
private int minVerticalGap = 0;
|
||||||
|
@ -176,6 +177,20 @@ public class WrapLayout implements LayoutManager {
|
||||||
*/
|
*/
|
||||||
public WrapLayout withForceComponentSize(Dimension forceComponentSize) {
|
public WrapLayout withForceComponentSize(Dimension forceComponentSize) {
|
||||||
this.forceComponentSize = forceComponentSize;
|
this.forceComponentSize = forceComponentSize;
|
||||||
|
this.allComponentsWithTheSameSize = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses the biggest preferred/minimum size for all child components.
|
||||||
|
*
|
||||||
|
* @param allComponentsWithTheSameSize {@code true} if all components should
|
||||||
|
* get the same same.
|
||||||
|
* @return This object, in order to support method chaining.
|
||||||
|
*/
|
||||||
|
public WrapLayout withAllComponentsWithTheSameSize(boolean allComponentsWithTheSameSize) {
|
||||||
|
this.allComponentsWithTheSameSize = allComponentsWithTheSameSize;
|
||||||
|
this.forceComponentSize = null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,12 +282,28 @@ public class WrapLayout implements LayoutManager {
|
||||||
final List<Row> rows = new ArrayList<>();
|
final List<Row> rows = new ArrayList<>();
|
||||||
final Dimension currentLayoutSize = new Dimension(0, 0);
|
final Dimension currentLayoutSize = new Dimension(0, 0);
|
||||||
|
|
||||||
|
Dimension sharedComponentSize = forceComponentSize;
|
||||||
|
if (allComponentsWithTheSameSize) {
|
||||||
|
sharedComponentSize = new Dimension(0, 0);
|
||||||
|
for (Component component : getVisibleComponents(target, layoutBottomToTop)) {
|
||||||
|
final Dimension d = preferred ? component.getPreferredSize() : component.getMinimumSize();
|
||||||
|
if (d.width > sharedComponentSize.width) {
|
||||||
|
sharedComponentSize.width = d.width;
|
||||||
|
}
|
||||||
|
if (d.height > sharedComponentSize.height) {
|
||||||
|
sharedComponentSize.height = d.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<Child> currentChildren = new ArrayList<>();
|
List<Child> currentChildren = new ArrayList<>();
|
||||||
Dimension currentRowSize = new Dimension(0, 0);
|
Dimension currentRowSize = new Dimension(0, 0);
|
||||||
for (Component component : getVisibleComponents(target, layoutBottomToTop)) {
|
for (Component component : getVisibleComponents(target, layoutBottomToTop)) {
|
||||||
Dimension d = preferred ? component.getPreferredSize() : component.getMinimumSize();
|
final Dimension d;
|
||||||
if (forceComponentSize != null) {
|
if (sharedComponentSize != null) {
|
||||||
d = forceComponentSize;
|
d = sharedComponentSize;
|
||||||
|
} else {
|
||||||
|
d = preferred ? component.getPreferredSize() : component.getMinimumSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't add the component to current row. Start a new row.
|
// Can't add the component to current row. Start a new row.
|
||||||
|
|
Loading…
Reference in New Issue