Browse Source
Merge in DESIGN/design from ~VITO/c-design:newui to newui * commit '9d3a52475e47c84363e0536f6813fd7729893f6e': REPORT-99485 TableLayoutHelper 适配DPI缩放newui
vito-刘恒霖
10 months ago
3 changed files with 198 additions and 79 deletions
@ -0,0 +1,169 @@
|
||||
package com.fr.design.gui.storybook.components; |
||||
|
||||
import com.fine.swing.ui.layout.Layouts; |
||||
import com.fr.design.gui.ibutton.UIButton; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.gui.storybook.StoryBoard; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JPanel; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
|
||||
import static com.fine.swing.ui.layout.Layouts.cell; |
||||
import static com.fine.swing.ui.layout.Layouts.row; |
||||
import static com.fr.design.layout.TableLayoutHelper.createDiffVGapTableLayoutPane; |
||||
import static com.fr.design.layout.TableLayoutHelper.createGapTableLayoutPane; |
||||
import static com.fr.design.layout.TableLayoutHelper.createTableLayoutPane; |
||||
|
||||
/** |
||||
* 表格布局展示 |
||||
* <br/> |
||||
* TableLayout 来自开源项目 |
||||
* <a href="https://www.clearthought.info/sun/products/jfc/tsc/articles/tablelayout/index.html">TableLayout</a> |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/1/31 |
||||
*/ |
||||
public class TablelayoutStoryBoard extends StoryBoard { |
||||
|
||||
|
||||
private static final double P = TableLayout.PREFERRED; |
||||
private static final double F = TableLayout.FILL; |
||||
|
||||
public TablelayoutStoryBoard() { |
||||
|
||||
super("Tablelayout"); |
||||
add( |
||||
cell(new UILabel("简单布局")).with(this::h3), |
||||
layout1(), |
||||
|
||||
cell(new UILabel("TableLayoutHelper 快速创建")).with(this::h3), |
||||
row( |
||||
cell(createTableLayoutPane(createTestComponents("jp1"), TableLayoutHelper.FILL_NONE)) |
||||
.with(it -> it.setBorder(BorderFactory.createLineBorder(Color.red))).weight(1), |
||||
|
||||
cell(createGapTableLayoutPane(createTestComponents("jp2"), |
||||
TableLayoutHelper.FILL_LASTCOL_AND_ROW, 20, 20)) |
||||
.with(it -> it.setBorder(BorderFactory.createLineBorder(Color.red))).weight(1), |
||||
|
||||
cell(createGapTableLayoutPane(createTestComponents("jp3"), |
||||
new double[]{F, P, F, P}, new double[]{F, F}, 4, 4)) |
||||
.with(it -> it.setBorder(BorderFactory.createLineBorder(Color.red))).weight(1) |
||||
), |
||||
row( |
||||
cell(createGapTableLayoutPane(createTestComponents("jp4"), |
||||
new double[]{P, 50, P, P, P, P}, new double[]{P, F}, new int[][]{{1, 3}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}, 1, 5)) |
||||
.with(it -> it.setBorder(BorderFactory.createLineBorder(Color.red))).weight(1), |
||||
|
||||
cell(createDiffVGapTableLayoutPane(createTestComponents("jp5"), |
||||
new double[]{P, P, P, P, P}, new double[]{P, F}, 4, new double[]{4, 8, 14, 4})) |
||||
.with(it -> it.setBorder(BorderFactory.createLineBorder(Color.red))).weight(1) |
||||
) |
||||
|
||||
|
||||
); |
||||
} |
||||
|
||||
|
||||
private static Component[][] createTestComponents(String name) { |
||||
UILabel label1 = new UILabel(name + "laaaable1"); |
||||
UILabel label2 = new UILabel(name + "lable2"); |
||||
UILabel label3 = new UILabel(name + "lable3"); |
||||
UILabel label4 = new UILabel(name + "lable4"); |
||||
UILabel label5 = new UILabel(name + "lable5"); |
||||
UIButton button1 = new UIButton(name + "button1"); |
||||
UIButton button2 = new UIButton(name + "button2"); |
||||
label1.setSize(label1.getPreferredSize()); |
||||
label1.setBorder(BorderFactory.createLineBorder(Color.blue)); |
||||
label2.setSize(label2.getPreferredSize()); |
||||
label2.setBorder(BorderFactory.createLineBorder(Color.blue)); |
||||
label3.setSize(label3.getPreferredSize()); |
||||
label3.setBorder(BorderFactory.createLineBorder(Color.blue)); |
||||
label4.setSize(label4.getPreferredSize()); |
||||
label4.setBorder(BorderFactory.createLineBorder(Color.blue)); |
||||
label5.setSize(label5.getPreferredSize()); |
||||
label5.setBorder(BorderFactory.createLineBorder(Color.blue)); |
||||
button1.setSize(button1.getPreferredSize()); |
||||
button2.setSize(button2.getPreferredSize()); |
||||
return new Component[][]{ |
||||
new Component[]{label1, button1}, |
||||
new Component[]{label2, null}, |
||||
new Component[]{label3}, |
||||
new Component[]{null, label4}, |
||||
new Component[]{button2, label5} |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* 图示 {@link /com/fr/design/gui/storybook/components/Preferred.gif} |
||||
*/ |
||||
private Layouts.Cell<JPanel> layout1() { |
||||
|
||||
JPanel pane = getTableLayoutPanel(); |
||||
|
||||
// Create all controls
|
||||
UILabel labelName = new UILabel("Name"); |
||||
UILabel labelAddress = new UILabel("Address"); |
||||
UILabel labelCity = new UILabel("City"); |
||||
UILabel labelState = new UILabel("State"); |
||||
UILabel labelZip = new UILabel("Zip"); |
||||
|
||||
UITextField textfieldName = new UITextField(10); |
||||
UITextField textfieldAddress = new UITextField(20); |
||||
UITextField textfieldCity = new UITextField(10); |
||||
UITextField textfieldState = new UITextField(2); |
||||
UITextField textfieldZip = new UITextField(5); |
||||
|
||||
UIButton buttonOk = new UIButton("OK"); |
||||
UIButton buttonCancel = new UIButton("Cancel"); |
||||
JPanel panelButton = new JPanel(); |
||||
panelButton.add(buttonOk); |
||||
panelButton.add(buttonCancel); |
||||
|
||||
// Add all controls
|
||||
pane.add(labelName, "1, 1, 5, 1"); |
||||
pane.add(textfieldName, "1, 3, 5, 3"); |
||||
pane.add(labelAddress, "1, 5, 5, 5"); |
||||
pane.add(textfieldAddress, "1, 7, 5, 7"); |
||||
pane.add(labelCity, "1, 9"); |
||||
pane.add(textfieldCity, "1, 11"); |
||||
pane.add(labelState, "3, 9"); |
||||
pane.add(textfieldState, "3, 11"); |
||||
pane.add(labelZip, "5, 9"); |
||||
pane.add(textfieldZip, "5, 11"); |
||||
pane.add(panelButton, "1, 13, 5, 13"); |
||||
return cell(pane); |
||||
} |
||||
|
||||
@NotNull |
||||
private static JPanel getTableLayoutPanel() { |
||||
JPanel pane = new JPanel(); |
||||
// b - border
|
||||
// f - FILL
|
||||
// p - PREFERRED
|
||||
// vs - vertical space between labels and text fields
|
||||
// vg - vertical gap between form elements
|
||||
// hg - horizontal gap between form elements
|
||||
|
||||
double b = 10; |
||||
double f = TableLayout.FILL; |
||||
double p = TableLayout.PREFERRED; |
||||
double vs = 5; |
||||
double vg = 10; |
||||
double hg = 10; |
||||
|
||||
double[][] size = |
||||
{{b, f, hg, p, hg, p, b}, |
||||
{b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}}; |
||||
|
||||
TableLayout layout = new TableLayout(size); |
||||
pane.setLayout(layout); |
||||
return pane; |
||||
} |
||||
} |
After Width: | Height: | Size: 17 KiB |
Loading…
Reference in new issue