updated hgap to horizontalGap and vgap to verticalGap

This commit is contained in:
Greg DiCristofaro 2020-04-16 07:47:32 -04:00
parent f1e2bd67f0
commit 9a423825ad

View File

@ -54,21 +54,19 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
* subcomponents as well as the spacing between subcomponents and the * subcomponents as well as the spacing between subcomponents and the
* borders of the target component. * borders of the target component.
* *
* @serial * @see #getHorizontalGap()
* @see #getHgap() * @see #setHorizontalGap(int)
* @see #setHgap(int)
*/ */
private int hgap = 0; private int horizontalGap = 0;
/** /**
* The vertical gap between neighboring rows as well as the spacing between * The vertical gap between neighboring rows as well as the spacing between
* rows and the borders of the target component. * rows and the borders of the target component.
* *
* @serial * @see #getVerticalGap()
* @see #getVgap() * @see #setVerticalGap(int)
* @see #setVgap(int)
*/ */
private int vgap = 0; private int verticalGap = 0;
/** /**
* If true, subcomponents will be aligned on their bottom edge. Otherwise, * If true, subcomponents will be aligned on their bottom edge. Otherwise,
@ -94,15 +92,16 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
/** /**
* Constructs a new <code>WrapLayout</code>. * Constructs a new <code>WrapLayout</code>.
* *
* @param vgap The vertical gap spacing between rows of subcomponents as * @param verticalGap The vertical gap spacing between rows of
* well as the spacing between the target component and rows. * subcomponents as well as the spacing between the
* @param hgap The horizontal gap spacing between neighboring subcomponents * target component and rows.
* as well as the spacing between the subcomponents and the * @param horizontalGap The horizontal gap spacing between neighboring
* target component's border. * subcomponents as well as the spacing between the
* subcomponents and the target component's border.
*/ */
public WrapLayout(int vgap, int hgap) { public WrapLayout(int verticalGap, int horizontalGap) {
this.vgap = vgap; this.verticalGap = verticalGap;
this.hgap = hgap; this.horizontalGap = horizontalGap;
} }
/** /**
@ -137,19 +136,20 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
* @return The horizontal gap between components and between the components * @return The horizontal gap between components and between the components
* and the borders of the <code>Container</code>. * and the borders of the <code>Container</code>.
*/ */
public int getHgap() { public int getHorizontalGap() {
return hgap; return horizontalGap;
} }
/** /**
* Sets the horizontal gap between neighboring subcomponents as well as the * Sets the horizontal gap between neighboring subcomponents as well as the
* spacing between subcomponents and the borders of the target component. * spacing between subcomponents and the borders of the target component.
* *
* @param hgap The horizontal gap between components and between the * @param horizontalGap The horizontal gap between components and between
* components and the borders of the <code>Container</code>. * the components and the borders of the
* <code>Container</code>.
*/ */
public void setHgap(int hgap) { public void setHorizontalGap(int horizontalGap) {
this.hgap = hgap; this.horizontalGap = horizontalGap;
} }
/** /**
@ -159,19 +159,20 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
* @return The vertical gap between components and between the components * @return The vertical gap between components and between the components
* and the borders of the <code>Container</code>. * and the borders of the <code>Container</code>.
*/ */
public int getVgap() { public int getVerticalGap() {
return vgap; return verticalGap;
} }
/** /**
* Sets the vertical gap between neighboring rows as well as the spacing * Sets the vertical gap between neighboring rows as well as the spacing
* between rows and the borders of the target component. * between rows and the borders of the target component.
* *
* @param vgap The vertical gap between components and between the * @param verticalGap The vertical gap between components and between the
* components and the borders of the <code>Container</code>. * components and the borders of the
* <code>Container</code>.
*/ */
public void setVgap(int vgap) { public void setVerticalGap(int verticalGap) {
this.vgap = vgap; this.verticalGap = verticalGap;
} }
/** /**
@ -296,9 +297,9 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
boolean ltr = target.getComponentOrientation().isLeftToRight(); boolean ltr = target.getComponentOrientation().isLeftToRight();
boolean useBaseline = getAlignOnBaseline(); boolean useBaseline = getAlignOnBaseline();
int rowY = targetDims.getInsets().top + getVgap(); int rowY = targetDims.getInsets().top + getVerticalGap();
int leftX = targetDims.getInsets().left + getHgap(); int leftX = targetDims.getInsets().left + getHorizontalGap();
int rightX = targetDims.getOuterWidth() - targetDims.getInsets().right - getHgap(); int rightX = targetDims.getOuterWidth() - targetDims.getInsets().right - getHorizontalGap();
for (WrapLayoutRow row : rows) { for (WrapLayoutRow row : rows) {
int rowHeight = row.getHeight(); int rowHeight = row.getHeight();
@ -306,7 +307,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
int curX = 0; int curX = 0;
if (row.getComponents() != null) { if (row.getComponents() != null) {
for (Component origComp : row.getComponents()) { for (Component origComp : row.getComponents()) {
curX += setComponentDims(origComp, useBaseline, ltr, rowY, rowHeight, leftX, rightX, curX) + getHgap(); curX += setComponentDims(origComp, useBaseline, ltr, rowY, rowHeight, leftX, rightX, curX) + getHorizontalGap();
} }
} }
@ -315,11 +316,11 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
// reverse opposite aligned for layout purposes since flipping ltr // reverse opposite aligned for layout purposes since flipping ltr
Collections.reverse(row.getOppositeAligned()); Collections.reverse(row.getOppositeAligned());
for (Component oppAlignedComp : row.getOppositeAligned()) { for (Component oppAlignedComp : row.getOppositeAligned()) {
curX += setComponentDims(oppAlignedComp, useBaseline, !ltr, rowY, rowHeight, leftX, rightX, curX) + getHgap(); curX += setComponentDims(oppAlignedComp, useBaseline, !ltr, rowY, rowHeight, leftX, rightX, curX) + getHorizontalGap();
} }
} }
rowY += rowHeight + getVgap(); rowY += rowHeight + getVerticalGap();
} }
} }
@ -331,7 +332,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
@Override @Override
public Dimension minimumLayoutSize(Container target) { public Dimension minimumLayoutSize(Container target) {
Dimension minimum = layoutSize(target, false); Dimension minimum = layoutSize(target, false);
minimum.width -= (getHgap() + 1); minimum.width -= (getHorizontalGap() + 1);
return minimum; return minimum;
} }
@ -408,7 +409,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
} }
Insets insets = container.getInsets(); Insets insets = container.getInsets();
int horizontalInsetsAndGap = insets.left + insets.right + (getHgap() * 2); int horizontalInsetsAndGap = insets.left + insets.right + (getHorizontalGap() * 2);
int maxWidth = targetWidth - horizontalInsetsAndGap; int maxWidth = targetWidth - horizontalInsetsAndGap;
return new ParentDimensions(targetWidth, maxWidth, insets); return new ParentDimensions(targetWidth, maxWidth, insets);
@ -431,13 +432,13 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
Integer containerHeight = rows.stream().map((r) -> r.getHeight()).reduce(0, Integer::sum); Integer containerHeight = rows.stream().map((r) -> r.getHeight()).reduce(0, Integer::sum);
// add in vertical gap between rows // add in vertical gap between rows
if (rows.size() > 1) { if (rows.size() > 1) {
containerHeight += (rows.size() - 1) * getVgap(); containerHeight += (rows.size() - 1) * getVerticalGap();
} }
containerHeight += targetDims.getInsets().top + targetDims.getInsets().bottom; containerHeight += targetDims.getInsets().top + targetDims.getInsets().bottom;
Integer containerWidth = rows.stream().map((r) -> r.getWidth()).reduce(0, Math::max); Integer containerWidth = rows.stream().map((r) -> r.getWidth()).reduce(0, Math::max);
containerWidth += targetDims.getInsets().left + targetDims.getInsets().right + (getHgap() * 2); containerWidth += targetDims.getInsets().left + targetDims.getInsets().right + (getHorizontalGap() * 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 // make sure the preferred size is less than the size of the
@ -446,7 +447,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target); Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
if (scrollPane != null && target.isValid()) { if (scrollPane != null && target.isValid()) {
containerWidth -= (getHgap() + 1); containerWidth -= (getHorizontalGap() + 1);
} }
return new Dimension(containerWidth, containerHeight); return new Dimension(containerWidth, containerHeight);
@ -473,7 +474,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
* @param height The maximum height of the row. * @param height The maximum height of the row.
* @param width The total width of the row. * @param width The total width of the row.
*/ */
WrapLayoutRow(List<Component> components, List<Component> oppositeAligned, WrapLayoutRow(List<Component> components, List<Component> oppositeAligned,
int height, int width) { int height, int width) {
this.components = components; this.components = components;
this.oppositeAligned = oppositeAligned; this.oppositeAligned = oppositeAligned;
@ -537,7 +538,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
* *
* @return The list of rows ordered from top to bottom. * @return The list of rows ordered from top to bottom.
*/ */
private List<WrapLayoutRow> getAllRows(List<Component> components, private List<WrapLayoutRow> getAllRows(List<Component> components,
boolean preferred, int maxWidth) { boolean preferred, int maxWidth) {
List<Component> originalComp List<Component> originalComp
= components = components
@ -572,7 +573,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
WrapLayoutRow lastOrig = originalRowSet.get(originalRowSet.size() - 1); WrapLayoutRow lastOrig = originalRowSet.get(originalRowSet.size() - 1);
WrapLayoutRow firstOpp = oppositeRowSet.get(0); WrapLayoutRow firstOpp = oppositeRowSet.get(0);
int proposedRowWidth = lastOrig.getWidth() + firstOpp.getWidth() + getHgap(); int proposedRowWidth = lastOrig.getWidth() + firstOpp.getWidth() + getHorizontalGap();
if (proposedRowWidth <= maxWidth) { if (proposedRowWidth <= maxWidth) {
WrapLayoutRow middleRow = new WrapLayoutRow(lastOrig.getComponents(), firstOpp.getOppositeAligned(), WrapLayoutRow middleRow = new WrapLayoutRow(lastOrig.getComponents(), firstOpp.getOppositeAligned(),
Math.max(lastOrig.getHeight(), firstOpp.getHeight()), proposedRowWidth); Math.max(lastOrig.getHeight(), firstOpp.getHeight()), proposedRowWidth);
@ -601,7 +602,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
* *
* @return The list of rows determined. * @return The list of rows determined.
*/ */
private List<WrapLayoutRow> getRowSet(List<Component> components, private List<WrapLayoutRow> getRowSet(List<Component> components,
boolean preferred, int maxWidth) { boolean preferred, int maxWidth) {
List<WrapLayoutRow> rows = new ArrayList<>(); List<WrapLayoutRow> rows = new ArrayList<>();
@ -623,7 +624,7 @@ public class WrapLayout implements LayoutManager, java.io.Serializable {
// Add a horizontal gap for all components after the first // Add a horizontal gap for all components after the first
if (rowWidth != 0) { if (rowWidth != 0) {
rowWidth += getHgap(); rowWidth += getHorizontalGap();
} }
rowComponents.add(m); rowComponents.add(m);