// License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.tools; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Insets; import java.util.function.Function; /** * This is an extension of the flow layout that preferes wrapping the text instead of increasing the component width * when there is not enough space. *
* This allows for a better preffered size computation. * It should be used in all places where a flow layout fills the full width of the parent container. *
* This does not support baseline alignment.
* @author Michael Zangl
* @since 10622
*/
public class MultiLineFlowLayout extends FlowLayout {
/**
* Same as {@link FlowLayout#FlowLayout()}
*/
public MultiLineFlowLayout() {
super();
}
/**
* Same as {@link FlowLayout#FlowLayout(int, int, int)}
* @param align Alignment
* @param hgap horizontal gap
* @param vgap vertical gap
*/
public MultiLineFlowLayout(int align, int hgap, int vgap) {
super(align, hgap, vgap);
}
/**
* Same as {@link FlowLayout#FlowLayout(int)}
* @param align Alignment
*/
public MultiLineFlowLayout(int align) {
super(align);
}
@Override
public Dimension preferredLayoutSize(Container target) {
return getLayoutSize(target, Component::getPreferredSize);
}
@Override
public Dimension minimumLayoutSize(Container target) {
return getLayoutSize(target, Component::getMinimumSize);
}
private Dimension getLayoutSize(Container target, Function