package jetbrains.mps.editor.contextActionsTool.pluginSolution.plugin;
/*Generated by MPS */
import java.awt.FlowLayout;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.Component;
/**
* When using a component with a normal FlowLayout at the North or South
* position of a BorderLayout, some components are not displayed, when they do
* not fit into one row.
* This is because FlowLayout.preferredLayoutSize expects that only one row is
* used, but FlowLayout.layoutComponent uses multiple rows, when there is not
* enough space for all components in one row.
* This class fixes this behavior with the result that the North/South regions
* of a BorderLayout are resized to show all components even with multiple rows.
*/
public class ExpandingFlowLayout extends FlowLayout {
public ExpandingFlowLayout() {
this(FlowLayout.LEFT, 0, 0);
}
public ExpandingFlowLayout(int align, int hgap, int vgap) {
super(align, hgap, vgap);
}
@Override
public Dimension preferredLayoutSize(Container target) {
layoutContainer(target);
int width = 0;
int height = 0;
for (Component c : target.getComponents()) {
int compRight = c.getX() + c.getWidth();
int compBottom = c.getY() + c.getHeight();
width = Math.max(width, compRight);
height = Math.max(height, compBottom);
}
return new Dimension(width, height);
}
}