Browse Source

Merge pull request #1072 in DESIGN/design from ~ZACK/design:feature/10.0 to feature/10.0

* commit 'b4c5815834a60a239690f6e4a9ee2a645078be22':
  REPORT-20318 sonar问题修复
research/11.0
zack 5 years ago
parent
commit
5c3f971dcf
  1. 39
      designer-base/src/main/java/com/fr/design/layout/TableLayout.java

39
designer-base/src/main/java/com/fr/design/layout/TableLayout.java

@ -1,6 +1,9 @@
package com.fr.design.layout; package com.fr.design.layout;
import com.fr.general.GeneralUtils;
import com.fr.stable.CommonUtils;
import java.awt.Component; import java.awt.Component;
import java.awt.ComponentOrientation; import java.awt.ComponentOrientation;
import java.awt.Container; import java.awt.Container;
@ -12,8 +15,6 @@ import java.lang.reflect.Method;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.ListIterator; import java.util.ListIterator;
import com.fr.general.GeneralUtils;
/** /**
* <p>TableLayout is a layout manager that is more powerful than GridBagLayout * <p>TableLayout is a layout manager that is more powerful than GridBagLayout
@ -853,9 +854,9 @@ public class TableLayout implements LayoutManager2, Serializable {
// Make sure row size is valid // Make sure row size is valid
if ((size < 0.0) && if ((size < 0.0) &&
(size != FILL) && (!CommonUtils.equals(size, FILL)) &&
(size != PREFERRED) && (!CommonUtils.equals(size, PREFERRED)) &&
(size != MINIMUM)) { (!CommonUtils.equals(size, MINIMUM))) {
size = 0.0; size = 0.0;
} }
@ -1177,7 +1178,7 @@ public class TableLayout implements LayoutManager2, Serializable {
int numCr = crSpec[z].length; int numCr = crSpec[z].length;
for (int counter = 0; counter < numCr; counter++) for (int counter = 0; counter < numCr; counter++)
if ((crSpec[z][counter] >= 1.0) || (crSpec[z][counter] == 0.0)) { if ((crSpec[z][counter] >= 1.0) || CommonUtils.equals(crSpec[z][counter], 0.0)) {
crSize[z][counter] = (int) (crSpec[z][counter] + 0.5); crSize[z][counter] = (int) (crSpec[z][counter] + 0.5);
availableSize -= crSize[z][counter]; availableSize -= crSize[z][counter];
} }
@ -1229,7 +1230,7 @@ public class TableLayout implements LayoutManager2, Serializable {
int numCr = crSpec[z].length; int numCr = crSpec[z].length;
for (int counter = 0; counter < numCr; counter++) for (int counter = 0; counter < numCr; counter++)
if (crSpec[z][counter] == FILL) if (CommonUtils.equals(crSpec[z][counter], FILL))
numFillSize++; numFillSize++;
// If numFillSize is zero, the if statement below will always evaluate to // If numFillSize is zero, the if statement below will always evaluate to
@ -1241,7 +1242,7 @@ public class TableLayout implements LayoutManager2, Serializable {
// Assign "fill" cells equal amounts of the remaining space // Assign "fill" cells equal amounts of the remaining space
for (int counter = 0; counter < numCr; counter++) for (int counter = 0; counter < numCr; counter++)
if (crSpec[z][counter] == FILL) { if (CommonUtils.equals(crSpec[z][counter], FILL)) {
crSize[z][counter] = availableSize / numFillSize; crSize[z][counter] = availableSize / numFillSize;
slackSize -= crSize[z][counter]; slackSize -= crSize[z][counter];
} }
@ -1249,7 +1250,7 @@ public class TableLayout implements LayoutManager2, Serializable {
// Assign one pixel of slack to each FILL cr, starting at the last one, // Assign one pixel of slack to each FILL cr, starting at the last one,
// until all slack has been consumed // until all slack has been consumed
for (int counter = numCr - 1; (counter >= 0) && (slackSize > 0); counter--) { for (int counter = numCr - 1; (counter >= 0) && (slackSize > 0); counter--) {
if (crSpec[z][counter] == FILL) { if (CommonUtils.equals(crSpec[z][counter], FILL)) {
crSize[z][counter]++; crSize[z][counter]++;
slackSize--; slackSize--;
} }
@ -1299,7 +1300,7 @@ public class TableLayout implements LayoutManager2, Serializable {
// Address every cr // Address every cr
for (int counter = 0; counter < numCr; counter++) for (int counter = 0; counter < numCr; counter++)
// Is the current cr a preferred/minimum (based on typeOfSize) size // Is the current cr a preferred/minimum (based on typeOfSize) size
if (crSpec[z][counter] == typeOfSize) { if (CommonUtils.equals(crSpec[z][counter], typeOfSize)) {
// Assume a maximum width of zero // Assume a maximum width of zero
int maxSize = 0; int maxSize = 0;
@ -1319,7 +1320,7 @@ public class TableLayout implements LayoutManager2, Serializable {
// the current component occupies // the current component occupies
if ((entry.cr1[z] <= counter) && (entry.cr2[z] >= counter)) { if ((entry.cr1[z] <= counter) && (entry.cr2[z] >= counter)) {
// Setup size and number of adjustable crs // Setup size and number of adjustable crs
Dimension p = (typeOfSize == PREFERRED) ? Dimension p = CommonUtils.equals(typeOfSize, PREFERRED) ?
entry.component.getPreferredSize() : entry.component.getPreferredSize() :
entry.component.getMinimumSize(); entry.component.getMinimumSize();
@ -1328,23 +1329,23 @@ public class TableLayout implements LayoutManager2, Serializable {
int numAdjustable = 0; int numAdjustable = 0;
// Calculate for preferred size // Calculate for preferred size
if (typeOfSize == PREFERRED) if (CommonUtils.equals(typeOfSize, PREFERRED))
// Consider all crs this component occupies // Consider all crs this component occupies
for (int entryCr = entry.cr1[z]; for (int entryCr = entry.cr1[z];
entryCr <= entry.cr2[z]; entryCr++) { entryCr <= entry.cr2[z]; entryCr++) {
// Subtract absolute, relative, and minumum cr // Subtract absolute, relative, and minumum cr
// sizes, which have already been calculated // sizes, which have already been calculated
if ((crSpec[z][entryCr] >= 0.0) || if ((crSpec[z][entryCr] >= 0.0) ||
(crSpec[z][entryCr] == MINIMUM)) { CommonUtils.equals(crSpec[z][entryCr], MINIMUM)) {
size -= crSize[z][entryCr]; size -= crSize[z][entryCr];
} }
// Count preferred/min width columns // Count preferred/min width columns
else if (crSpec[z][entryCr] == PREFERRED) else if (CommonUtils.equals(crSpec[z][entryCr], PREFERRED))
numAdjustable++; numAdjustable++;
// Skip any component that occupies a fill cr // Skip any component that occupies a fill cr
// because the fill should fulfill the size // because the fill should fulfill the size
// requirements // requirements
else if (crSpec[z][entryCr] == FILL) else if (CommonUtils.equals(crSpec[z][entryCr], FILL))
continue nextComponent; continue nextComponent;
} }
// Calculate for minimum size // Calculate for minimum size
@ -1357,14 +1358,14 @@ public class TableLayout implements LayoutManager2, Serializable {
if (crSpec[z][entryCr] >= 0.0) if (crSpec[z][entryCr] >= 0.0)
size -= crSize[z][entryCr]; size -= crSize[z][entryCr];
// Count preferred/min width columns // Count preferred/min width columns
else if ((crSpec[z][entryCr] == PREFERRED) || else if (CommonUtils.equals(crSpec[z][entryCr], PREFERRED) ||
(crSpec[z][entryCr] == MINIMUM)) { CommonUtils.equals(crSpec[z][entryCr], MINIMUM)) {
numAdjustable++; numAdjustable++;
} }
// Skip any component that occupies a fill cr // Skip any component that occupies a fill cr
// because the fill should fulfill the size // because the fill should fulfill the size
// requirements // requirements
else if (crSpec[z][entryCr] == FILL) else if (CommonUtils.equals(crSpec[z][entryCr], FILL))
continue nextComponent; continue nextComponent;
} }
@ -1692,7 +1693,7 @@ public class TableLayout implements LayoutManager2, Serializable {
Dimension prefMinSize[] = new Dimension[numEntry]; Dimension prefMinSize[] = new Dimension[numEntry];
for (int i = 0; i < numEntry; i++) for (int i = 0; i < numEntry; i++)
prefMinSize[i] = (typeOfSize == PREFERRED) ? prefMinSize[i] = CommonUtils.equals(typeOfSize, PREFERRED) ?
entryList[i].component.getPreferredSize() : entryList[i].component.getPreferredSize() :
entryList[i].component.getMinimumSize(); entryList[i].component.getMinimumSize();

Loading…
Cancel
Save