Checkstyle.

This commit is contained in:
Doublestrike
2012-02-16 11:00:46 +00:00
parent 4f2a4004e3
commit 130ed2a67a

View File

@@ -12,16 +12,13 @@ import javax.swing.SwingUtilities;
/**
* FlowLayout subclass that fully supports wrapping of components.
*/
public class WrapLayout extends FlowLayout
{
private Dimension preferredLayoutSize;
@SuppressWarnings("serial")
public class WrapLayout extends FlowLayout {
/**
* Constructs a new <code>WrapLayout</code> with a left
* alignment and a default 5-unit horizontal and vertical gap.
*/
public WrapLayout()
{
public WrapLayout() {
super();
}
@@ -33,8 +30,7 @@ public class WrapLayout extends FlowLayout
* or <code>WrapLayout</code>.
* @param align the alignment value
*/
public WrapLayout(int align)
{
public WrapLayout(int align) {
super(align);
}
@@ -49,8 +45,7 @@ public class WrapLayout extends FlowLayout
* @param hgap the horizontal gap between components
* @param vgap the vertical gap between components
*/
public WrapLayout(int align, int hgap, int vgap)
{
public WrapLayout(int align, int hgap, int vgap) {
super(align, hgap, vgap);
}
@@ -62,8 +57,7 @@ public class WrapLayout extends FlowLayout
* subcomponents of the specified container
*/
@Override
public Dimension preferredLayoutSize(Container target)
{
public Dimension preferredLayoutSize(Container target) {
return layoutSize(target, true);
}
@@ -75,33 +69,31 @@ public class WrapLayout extends FlowLayout
* subcomponents of the specified container
*/
@Override
public Dimension minimumLayoutSize(Container target)
{
public Dimension minimumLayoutSize(Container target) {
Dimension minimum = layoutSize(target, false);
minimum.width -= (getHgap() + 1);
return minimum;
}
/**
* Returns the minimum or preferred dimension needed to layout the target
* container.
*
* @param target target to get layout size for
* @param preferred should preferred size be calculated
* @return the dimension to layout the target container
*/
private Dimension layoutSize(Container target, boolean preferred)
{
synchronized (target.getTreeLock())
{
/**
* Returns the minimum or preferred dimension needed to layout the target
* container.
*
* @param target target to get layout size for
* @param preferred should preferred size be calculated
* @return the dimension to layout the target container
*/
private Dimension layoutSize(Container target, boolean preferred) {
synchronized (target.getTreeLock()) {
// Each row must fit with the width allocated to the containter.
// When the container width = 0, the preferred width of the container
// has not yet been calculated so lets ask for the maximum.
int targetWidth = target.getSize().width;
if (targetWidth == 0)
if (targetWidth == 0) {
targetWidth = Integer.MAX_VALUE;
}
int hgap = getHgap();
int vgap = getVgap();
@@ -117,27 +109,21 @@ public class WrapLayout extends FlowLayout
int nmembers = target.getComponentCount();
for (int i = 0; i < nmembers; i++)
{
for (int i = 0; i < nmembers; i++) {
Component m = target.getComponent(i);
if (m.isVisible())
{
if (m.isVisible()) {
Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
// Can't add the component to current row. Start a new row.
if (rowWidth + d.width > maxWidth)
{
if (rowWidth + d.width > maxWidth) {
addRow(dim, rowWidth, rowHeight);
rowWidth = 0;
rowHeight = 0;
}
// Add a horizontal gap for all components after the first
if (rowWidth != 0)
{
if (rowWidth != 0) {
rowWidth += hgap;
}
@@ -151,23 +137,22 @@ public class WrapLayout extends FlowLayout
dim.width += horizontalInsetsAndGap;
dim.height += insets.top + insets.bottom + vgap * 2;
// When using a scroll pane or the DecoratedLookAndFeel we need to
//When using a scroll pane or the DecoratedLookAndFeel we need to
// make sure the preferred size is less than the size of the
// target containter so shrinking the container size works
// correctly. Removing the horizontal gap is an easy way to do this.
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null)
{
if (scrollPane != null) {
dim.width -= (hgap + 1);
}
return dim;
}
}
}
/*
/*
* A new row has been completed. Use the dimensions of this row
* to update the preferred size for the container.
*
@@ -175,12 +160,10 @@ public class WrapLayout extends FlowLayout
* @param rowWidth the width of the row to add
* @param rowHeight the height of the row to add
*/
private void addRow(Dimension dim, int rowWidth, int rowHeight)
{
private void addRow(Dimension dim, int rowWidth, int rowHeight) {
dim.width = Math.max(dim.width, rowWidth);
if (dim.height > 0)
{
if (dim.height > 0) {
dim.height += getVgap();
}