📄 formatlayout.java
字号:
c0 = parent.getComponent(componentIndex);
c0.setBounds(rowX[0],
rowY + (rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
columnWidths[0], c0.getPreferredSize().height);
c1 = parent.getComponent(componentIndex + 1);
c1.setBounds(rowX[1],
rowY + (rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
w1to2, c1.getPreferredSize().height);
c2 = parent.getComponent(componentIndex + 2);
c2.setBounds(rowX[3],
rowY + (rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
columnWidths[3], c2.getPreferredSize().height);
c3 = parent.getComponent(componentIndex + 3);
c3.setBounds(rowX[4],
rowY + (rowHeights[rowIndex] - c3.getPreferredSize().height) / 2,
columnWidths[4], c3.getPreferredSize().height);
c4 = parent.getComponent(componentIndex + 4);
c4.setBounds(rowX[5],
rowY + (rowHeights[rowIndex] - c4.getPreferredSize().height) / 2,
columnWidths[5], c4.getPreferredSize().height);
componentIndex = componentIndex + 5;
break;
case FormatLayout.LCBLCB:
c0 = parent.getComponent(componentIndex);
c0.setBounds(rowX[0],
rowY + (rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
columnWidths[0], c0.getPreferredSize().height);
c1 = parent.getComponent(componentIndex + 1);
c1.setBounds(rowX[1],
rowY + (rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
columnWidths[1], c1.getPreferredSize().height);
c2 = parent.getComponent(componentIndex + 2);
c2.setBounds(rowX[2],
rowY + (rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
columnWidths[2], c2.getPreferredSize().height);
c3 = parent.getComponent(componentIndex + 3);
c3.setBounds(rowX[3],
rowY + (rowHeights[rowIndex] - c3.getPreferredSize().height) / 2,
columnWidths[3], c3.getPreferredSize().height);
c4 = parent.getComponent(componentIndex + 4);
c4.setBounds(rowX[4],
rowY + (rowHeights[rowIndex] - c4.getPreferredSize().height) / 2,
columnWidths[4], c4.getPreferredSize().height);
c5 = parent.getComponent(componentIndex + 5);
c5.setBounds(rowX[5],
rowY + (rowHeights[rowIndex] - c5.getPreferredSize().height) / 2,
columnWidths[5], c5.getPreferredSize().height);
componentIndex = componentIndex + 6;
break;
}
rowY = rowY + rowHeights[rowIndex] + rowGap;
}
}
}
/**
* Processes a row in 'C' format.
*
* @param rowIndex the row index.
* @param d0 dimension 0.
*/
protected void updateC(int rowIndex, Dimension d0) {
rowHeights[rowIndex] = d0.height;
totalHeight = totalHeight + rowHeights[rowIndex];
columns0to5Width = Math.max(columns0to5Width, d0.width);
}
/**
* Processes a row in 'LC' format.
*
* @param rowIndex the row index.
* @param d0 dimension 0.
* @param d1 dimension 1.
*/
protected void updateLC(int rowIndex, Dimension d0, Dimension d1) {
rowHeights[rowIndex] = Math.max(d0.height, d1.height);
totalHeight = totalHeight + rowHeights[rowIndex];
columnWidths[0] = Math.max(columnWidths[0], d0.width);
columns1to5Width = Math.max(columns1to5Width, d1.width);
}
/**
* Processes a row in 'LCB' format.
*
* @param rowIndex the row index.
* @param d0 dimension 0.
* @param d1 dimension 1.
* @param d2 dimension 2.
*/
protected void updateLCB(int rowIndex,
Dimension d0, Dimension d1, Dimension d2) {
rowHeights[rowIndex] = Math.max(d0.height, Math.max(d1.height, d2.height));
totalHeight = totalHeight + rowHeights[rowIndex];
columnWidths[0] = Math.max(columnWidths[0], d0.width);
columns1to4Width = Math.max(columns1to4Width, d1.width);
columnWidths[5] = Math.max(columnWidths[5], d2.width);
}
/**
* Processes a row in 'LCLC' format.
*
* @param rowIndex the row index.
* @param d0 dimension 0.
* @param d1 dimension 1.
* @param d2 dimension 2.
* @param d3 dimension 3.
*/
protected void updateLCLC(int rowIndex, Dimension d0, Dimension d1,
Dimension d2, Dimension d3) {
rowHeights[rowIndex] = Math.max(Math.max(d0.height, d1.height),
Math.max(d2.height, d3.height));
totalHeight = totalHeight + rowHeights[rowIndex];
columnWidths[0] = Math.max(columnWidths[0], d0.width);
columns1and2Width = Math.max(columns1and2Width, d1.width);
columnWidths[3] = Math.max(columnWidths[3], d2.width);
columns4and5Width = Math.max(columns4and5Width, d3.width);
}
/**
* Processes a row in 'LCBLC' format.
*
* @param rowIndex the row index.
* @param d0 dimension 0.
* @param d1 dimension 1.
* @param d2 dimension 2.
* @param d3 dimension 3.
* @param d4 dimension 4.
*/
protected void updateLCBLC(int rowIndex, Dimension d0, Dimension d1,
Dimension d2, Dimension d3, Dimension d4) {
rowHeights[rowIndex] = (Math.max(d0.height,
Math.max(Math.max(d1.height, d2.height),
Math.max(d3.height, d4.height))));
totalHeight = totalHeight + rowHeights[rowIndex];
columnWidths[0] = Math.max(columnWidths[0], d0.width);
columnWidths[1] = Math.max(columnWidths[1], d1.width);
columnWidths[2] = Math.max(columnWidths[2], d2.width);
columnWidths[3] = Math.max(columnWidths[3], d3.width);
columns4and5Width = Math.max(columns4and5Width, d4.width);
}
/**
* Processes a row in 'LCLCB' format.
*
* @param rowIndex the row index.
* @param d0 dimension 0.
* @param d1 dimension 1.
* @param d2 dimension 2.
* @param d3 dimension 3.
* @param d4 dimension 4.
*/
protected void updateLCLCB(int rowIndex, Dimension d0, Dimension d1, Dimension d2,
Dimension d3, Dimension d4) {
rowHeights[rowIndex] = (Math.max(d0.height,
Math.max(Math.max(d1.height, d2.height),
Math.max(d3.height, d4.height))));
totalHeight = totalHeight + rowHeights[rowIndex];
columnWidths[0] = Math.max(columnWidths[0], d0.width);
columns1and2Width = Math.max(columns1and2Width, d1.width);
columnWidths[3] = Math.max(columnWidths[3], d2.width);
columnWidths[4] = Math.max(columnWidths[4], d3.width);
columnWidths[5] = Math.max(columnWidths[5], d4.width);
}
/**
* Processes a row in 'LCBLCB' format.
*
* @param rowIndex the row index.
* @param d0 dimension 0.
* @param d1 dimension 1.
* @param d2 dimension 2.
* @param d3 dimension 3.
* @param d4 dimension 4.
* @param d5 dimension 5.
*/
protected void updateLCBLCB(int rowIndex,
Dimension d0, Dimension d1, Dimension d2,
Dimension d3, Dimension d4, Dimension d5) {
rowHeights[rowIndex] = Math.max(Math.max(d0.height, d1.height),
Math.max(Math.max(d2.height, d3.height),
Math.max(d4.height, d5.height)));
totalHeight = totalHeight + rowHeights[rowIndex];
columnWidths[0] = Math.max(columnWidths[0], d0.width);
columnWidths[1] = Math.max(columnWidths[1], d1.width);
columnWidths[2] = Math.max(columnWidths[2], d2.width);
columnWidths[3] = Math.max(columnWidths[3], d3.width);
columnWidths[4] = Math.max(columnWidths[4], d4.width);
columnWidths[5] = Math.max(columnWidths[5], d5.width);
}
/**
* Finishes of the processing.
*/
public void complete() {
columnWidths[1] = Math.max(columnWidths[1],
columns1and2Width - columnGaps[1] - columnWidths[2]);
columnWidths[4]
= Math.max(columnWidths[4],
Math.max(columns4and5Width - columnGaps[4] - columnWidths[5],
Math.max(columns1to4Width - columnGaps[1] - columnGaps[2] - columnGaps[3]
- columnWidths[1] - columnWidths[2] - columnWidths[3],
columns1to5Width - columnGaps[1] - columnGaps[2] - columnGaps[3]
- columnWidths[1] - columnWidths[2] - columnWidths[3]
- columnGaps[4])));
int leftWidth = columnWidths[0] + columnGaps[0]
+ columnWidths[1] + columnGaps[1] + columnWidths[2];
int rightWidth = columnWidths[3] + columnGaps[3]
+ columnWidths[4] + columnGaps[4] + columnWidths[5];
if (splitLayout()) {
if (leftWidth > rightWidth) {
int mismatch = leftWidth - rightWidth;
columnWidths[4] = columnWidths[4] + mismatch;
rightWidth = rightWidth + mismatch;
}
else {
int mismatch = rightWidth - leftWidth;
columnWidths[1] = columnWidths[1] + mismatch;
leftWidth = leftWidth + mismatch;
}
}
this.totalWidth = leftWidth + columnGaps[2] + rightWidth;
if (columns0to5Width > totalWidth) {
int spaceToAdd = (columns0to5Width - totalWidth);
if (splitLayout()) {
int halfSpaceToAdd = spaceToAdd / 2;
columnWidths[1] = columnWidths[1] + halfSpaceToAdd;
columnWidths[4] = columnWidths[4] + spaceToAdd - halfSpaceToAdd;
totalWidth = totalWidth + spaceToAdd;
}
else {
columnWidths[1] = columnWidths[1] + spaceToAdd;
totalWidth = totalWidth + spaceToAdd;
}
}
}
/**
* Returns true if this layout involves a split into two sections.
*
* @return <code>true</code> if this layout involves a split into two sections.
*/
private boolean splitLayout() {
for (int i = 0; i < this.rowFormats.length; i++) {
if (rowFormats[i] > FormatLayout.LCB) {
return true;
}
}
return false;
}
/**
* Not used.
*
* @param comp the component.
*/
public void addLayoutComponent(Component comp) {
}
/**
* Not used.
*
* @param comp the component.
*/
public void removeLayoutComponent(Component comp) {
}
/**
* Not used.
*
* @param name the component name.
* @param comp the component.
*/
public void addLayoutComponent(String name, Component comp) {
}
/**
* Not used.
*
* @param name the component name.
* @param comp the component.
*/
public void removeLayoutComponent(String name, Component comp) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -