📄 formatlayout.java
字号:
synchronized (parent.getTreeLock()) {
Insets insets = parent.getInsets();
int componentIndex = 0;
int rowCount = rowHeights.length;
for (int i = 0; i < columnWidths.length; i++) {
columnWidths[i] = 0;
}
columns1and2Width = 0;
columns4and5Width = 0;
columns1to4Width = 0;
columns1to5Width = 0;
columns0to5Width = 0;
int totalHeight = 0;
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
int format = rowFormats[rowIndex % rowFormats.length];
switch (format) {
case FormatLayout.C:
c0 = parent.getComponent(componentIndex);
this.columns0to5Width = Math.max(columns0to5Width,
c0.getMinimumSize().width);
componentIndex = componentIndex + 1;
break;
case FormatLayout.LC:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
updateLC(rowIndex,
c0.getMinimumSize(),
c1.getMinimumSize());
componentIndex = componentIndex + 2;
break;
case FormatLayout.LCB:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
updateLCB(rowIndex,
c0.getMinimumSize(),
c1.getMinimumSize(),
c2.getMinimumSize());
componentIndex = componentIndex + 3;
break;
case FormatLayout.LCLC:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
updateLCLC(rowIndex,
c0.getMinimumSize(),
c1.getMinimumSize(),
c2.getMinimumSize(),
c3.getMinimumSize());
componentIndex = componentIndex + 3;
break;
case FormatLayout.LCBLC:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
c4 = parent.getComponent(componentIndex + 4);
updateLCBLC(rowIndex,
c0.getMinimumSize(),
c1.getMinimumSize(),
c2.getMinimumSize(),
c3.getMinimumSize(),
c4.getMinimumSize());
componentIndex = componentIndex + 4;
break;
case FormatLayout.LCLCB:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
c4 = parent.getComponent(componentIndex + 4);
updateLCLCB(rowIndex,
c0.getMinimumSize(),
c1.getMinimumSize(),
c2.getMinimumSize(),
c3.getMinimumSize(),
c4.getMinimumSize());
componentIndex = componentIndex + 4;
break;
case FormatLayout.LCBLCB:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
c4 = parent.getComponent(componentIndex + 4);
c5 = parent.getComponent(componentIndex + 5);
updateLCBLCB(rowIndex,
c0.getMinimumSize(),
c1.getMinimumSize(),
c2.getMinimumSize(),
c3.getMinimumSize(),
c4.getMinimumSize(),
c5.getMinimumSize());
componentIndex = componentIndex + 5;
break;
}
}
complete();
return new Dimension(totalWidth + insets.left + insets.right,
totalHeight + (rowCount - 1) * rowGap
+ insets.top + insets.bottom);
}
}
/**
* Performs the layout of the container.
*
* @param parent the parent.
*/
public void layoutContainer(Container parent) {
Component c0, c1, c2, c3, c4, c5;
synchronized (parent.getTreeLock()) {
Insets insets = parent.getInsets();
int componentIndex = 0;
int rowCount = rowHeights.length;
for (int i = 0; i < columnWidths.length; i++) {
columnWidths[i] = 0;
}
columns1and2Width = 0;
columns4and5Width = 0;
columns1to4Width = 0;
columns1to5Width = 0;
columns0to5Width = parent.getBounds().width - insets.left - insets.right;
totalHeight = 0;
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
int format = rowFormats[rowIndex % rowFormats.length];
switch (format) {
case FormatLayout.C:
c0 = parent.getComponent(componentIndex);
updateC(rowIndex, c0.getPreferredSize());
componentIndex = componentIndex + 1;
break;
case FormatLayout.LC:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
updateLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize());
componentIndex = componentIndex + 2;
break;
case FormatLayout.LCB:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
updateLCB(rowIndex,
c0.getPreferredSize(),
c1.getPreferredSize(),
c2.getPreferredSize());
componentIndex = componentIndex + 3;
break;
case FormatLayout.LCLC:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
updateLCLC(rowIndex,
c0.getPreferredSize(),
c1.getPreferredSize(),
c2.getPreferredSize(),
c3.getPreferredSize());
componentIndex = componentIndex + 4;
break;
case FormatLayout.LCBLC:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
c4 = parent.getComponent(componentIndex + 4);
updateLCBLC(rowIndex,
c0.getPreferredSize(),
c1.getPreferredSize(),
c2.getPreferredSize(),
c3.getPreferredSize(),
c4.getPreferredSize());
componentIndex = componentIndex + 5;
break;
case FormatLayout.LCLCB:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
c4 = parent.getComponent(componentIndex + 4);
updateLCLCB(rowIndex,
c0.getPreferredSize(),
c1.getPreferredSize(),
c2.getPreferredSize(),
c3.getPreferredSize(),
c4.getPreferredSize());
componentIndex = componentIndex + 5;
break;
case FormatLayout.LCBLCB:
c0 = parent.getComponent(componentIndex);
c1 = parent.getComponent(componentIndex + 1);
c2 = parent.getComponent(componentIndex + 2);
c3 = parent.getComponent(componentIndex + 3);
c4 = parent.getComponent(componentIndex + 4);
c5 = parent.getComponent(componentIndex + 5);
updateLCBLCB(rowIndex,
c0.getPreferredSize(),
c1.getPreferredSize(),
c2.getPreferredSize(),
c3.getPreferredSize(),
c4.getPreferredSize(),
c5.getPreferredSize());
componentIndex = componentIndex + 6;
break;
}
}
complete();
componentIndex = 0;
int rowY = insets.top;
int[] rowX = new int[6];
rowX[0] = insets.left;
rowX[1] = rowX[0] + columnWidths[0] + columnGaps[0];
rowX[2] = rowX[1] + columnWidths[1] + columnGaps[1];
rowX[3] = rowX[2] + columnWidths[2] + columnGaps[2];
rowX[4] = rowX[3] + columnWidths[3] + columnGaps[3];
rowX[5] = rowX[4] + columnWidths[4] + columnGaps[4];
int w1to2 = columnWidths[1] + columnGaps[1] + columnWidths[2];
int w4to5 = columnWidths[4] + columnGaps[4] + columnWidths[5];
int w1to4 = w1to2 + columnGaps[2] + columnWidths[3] + columnGaps[3] + columnWidths[4];
int w1to5 = w1to4 + columnGaps[4] + columnWidths[5];
int w0to5 = w1to5 + columnWidths[0] + columnGaps[0];
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
int format = rowFormats[rowIndex % rowFormats.length];
switch (format) {
case FormatLayout.C:
c0 = parent.getComponent(componentIndex);
c0.setBounds(rowX[0], rowY, w0to5, c0.getPreferredSize().height);
componentIndex = componentIndex + 1;
break;
case FormatLayout.LC:
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,
w1to5, c1.getPreferredSize().height);
componentIndex = componentIndex + 2;
break;
case FormatLayout.LCB:
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,
w1to4, c1.getPreferredSize().height);
c2 = parent.getComponent(componentIndex + 2);
c2.setBounds(rowX[5],
rowY + (rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
columnWidths[5], c2.getPreferredSize().height);
componentIndex = componentIndex + 3;
break;
case FormatLayout.LCLC:
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,
w4to5, c3.getPreferredSize().height);
componentIndex = componentIndex + 4;
break;
case FormatLayout.LCBLC:
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,
w4to5, c4.getPreferredSize().height);
componentIndex = componentIndex + 5;
break;
case FormatLayout.LCLCB:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -