Browse Source

Merge pull request #1073 in BA/design from ~YAOH.WU/a_design_0811:9.0release to 9.0release

* commit '09e98f1195335801d98393780e9e3fc95768570b':
  REPORT-3348 事件修改,避免查看数据列高级设置的时候也触发保存;修改TableLayout隐藏部分面板时 间距遗留的问题
master
superman 7 years ago
parent
commit
e1fd45adad
  1. 8
      designer/src/com/fr/design/dscolumn/ResultSetGroupDockingPane.java
  2. 2
      designer/src/com/fr/quickeditor/CellQuickEditor.java
  3. 65
      designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java
  4. 748
      designer_base/src/com/fr/design/layout/TableLayoutHelper.java

8
designer/src/com/fr/design/dscolumn/ResultSetGroupDockingPane.java

@ -34,6 +34,7 @@ public class ResultSetGroupDockingPane extends ResultSetGroupPane {
private UIButton advancedButton; private UIButton advancedButton;
private FunctionComboBox functionComboBox; private FunctionComboBox functionComboBox;
private JPanel contentPane;
private JPanel cardPane; private JPanel cardPane;
private CardLayout cardLayout; private CardLayout cardLayout;
private UIComboBox goBox; private UIComboBox goBox;
@ -48,9 +49,9 @@ public class ResultSetGroupDockingPane extends ResultSetGroupPane {
public void initComponents(ElementCasePane ePane) { public void initComponents(ElementCasePane ePane) {
goBox = new UIComboBox(new String[]{Inter.getLocText("BindColumn-Group"), Inter.getLocText("BindColumn-Select"), Inter.getLocText("BindColumn-Summary")}); goBox = new UIComboBox(new String[]{Inter.getLocText("BindColumn-Group"), Inter.getLocText("BindColumn-Select"), Inter.getLocText("BindColumn-Summary")});
initCardPane(); initCardPane();
JPanel pane = layoutPane(); contentPane = layoutPane();
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
this.add(pane, BorderLayout.CENTER); this.add(contentPane, BorderLayout.CENTER);
} }
private JPanel layoutPane() { private JPanel layoutPane() {
@ -70,12 +71,15 @@ public class ResultSetGroupDockingPane extends ResultSetGroupPane {
if (i == BIND_GROUP) { if (i == BIND_GROUP) {
cardLayout.show(cardPane, "groupPane"); cardLayout.show(cardPane, "groupPane");
cardPane.setPreferredSize(new Dimension(156, 20)); cardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane,2,10);
} else if (i == BIND_SELECTED) { } else if (i == BIND_SELECTED) {
cardLayout.show(cardPane, "listPane"); cardLayout.show(cardPane, "listPane");
cardPane.setPreferredSize(new Dimension(0, 0)); cardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane,2,0);
} else if (i == BIND_SUMMARY) { } else if (i == BIND_SUMMARY) {
cardLayout.show(cardPane, "summaryPane"); cardLayout.show(cardPane, "summaryPane");
cardPane.setPreferredSize(new Dimension(156, 20)); cardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane,2,10);
CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr(); CellExpandAttr cellExpandAttr = cellElement.getCellExpandAttr();
cellExpandAttr.setDirection(Constants.NONE); cellExpandAttr.setDirection(Constants.NONE);
} }

2
designer/src/com/fr/quickeditor/CellQuickEditor.java

@ -55,7 +55,7 @@ public abstract class CellQuickEditor extends QuickEditor<ElementCasePane> {
emptyLabel.setPreferredSize(new Dimension(60, 20)); emptyLabel.setPreferredSize(new Dimension(60, 20));
} }
protected static final int VGAP = 10, HGAP = 8; protected static final int VGAP = 10, HGAP = 8, VGAP_INNER = 3;
public CellQuickEditor() { public CellQuickEditor() {

65
designer/src/com/fr/quickeditor/cellquick/CellDSColumnEditor.java

@ -436,12 +436,6 @@ public class CellDSColumnEditor extends CellQuickEditor {
filterPane.update(cellElement); filterPane.update(cellElement);
fireTargetModified(); fireTargetModified();
} }
}, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterPane.update(cellElement);
fireTargetModified();
}
} }
); );
//自定义值显示 //自定义值显示
@ -489,6 +483,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
} }
}, new double[]{P}, new double[]{P, F}, HGAP, VGAP }, new double[]{P}, new double[]{P, F}, HGAP, VGAP
); );
multiPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
multiNumPane.add(multiPane); multiNumPane.add(multiPane);
useMultiplyNumCheckBox.addActionListener(new ActionListener() { useMultiplyNumCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -505,7 +500,6 @@ public class CellDSColumnEditor extends CellQuickEditor {
} }
}); });
double[] rowSize = {P, P, P, P, P, P}; double[] rowSize = {P, P, P, P, P, P};
double[] columnSize = {F}; double[] columnSize = {F};
@ -537,6 +531,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
* @see DSColumnAdvancedPane.SortPane * @see DSColumnAdvancedPane.SortPane
*/ */
public class ResultSetSortConfigPane extends JPanel { public class ResultSetSortConfigPane extends JPanel {
private JPanel contentPane;
//面板 //面板
private UIButtonGroup sortTypePane; private UIButtonGroup sortTypePane;
private JFormulaField formulaField; private JFormulaField formulaField;
@ -570,8 +565,10 @@ public class CellDSColumnEditor extends CellQuickEditor {
cardLayout.show(centerPane, noContent ? "none" : "content"); cardLayout.show(centerPane, noContent ? "none" : "content");
if (noContent) { if (noContent) {
centerPane.setPreferredSize(new Dimension(0, 0)); centerPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
} else { } else {
centerPane.setPreferredSize(new Dimension(165, 20)); centerPane.setPreferredSize(new Dimension(165, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
} }
} }
}); });
@ -582,9 +579,8 @@ public class CellDSColumnEditor extends CellQuickEditor {
}; };
double[] rowSize = {P, P}, columnSize = {P, F}; double[] rowSize = {P, P}, columnSize = {P, F};
this.add(TableLayoutHelper.createGapTableLayoutPane( contentPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, HGAP, VGAP);
components, rowSize, columnSize, HGAP, VGAP this.add(contentPane, BorderLayout.CENTER);
), BorderLayout.CENTER);
} }
@ -605,8 +601,10 @@ public class CellDSColumnEditor extends CellQuickEditor {
cardLayout.show(centerPane, noContent ? "none" : "content"); cardLayout.show(centerPane, noContent ? "none" : "content");
if (noContent) { if (noContent) {
centerPane.setPreferredSize(new Dimension(0, 0)); centerPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
} else { } else {
centerPane.setPreferredSize(new Dimension(156, 20)); centerPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
} }
String sortFormula = dSColumn.getSortFormula(); String sortFormula = dSColumn.getSortFormula();
if (sortFormula != null && sortFormula.length() >= 1) { if (sortFormula != null && sortFormula.length() >= 1) {
@ -650,7 +648,7 @@ public class CellDSColumnEditor extends CellQuickEditor {
* @see DSColumnAdvancedPane.SelectCountPane * @see DSColumnAdvancedPane.SelectCountPane
*/ */
public class ResultSetFilterConfigPane extends JPanel { public class ResultSetFilterConfigPane extends JPanel {
private JPanel contentPane;
private UIComboBox rsComboBox; private UIComboBox rsComboBox;
private JPanel setCardPane; private JPanel setCardPane;
private JPanel tipCardPane; private JPanel tipCardPane;
@ -681,44 +679,52 @@ public class CellDSColumnEditor extends CellQuickEditor {
tipCardPaneLayout.show(tipCardPane, FilterType.TOP.name()); tipCardPaneLayout.show(tipCardPane, FilterType.TOP.name());
//隐藏tip 显示set //隐藏tip 显示set
setCardPane.setPreferredSize(new Dimension(156, 20)); setCardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
tipCardPane.setPreferredSize(new Dimension(0, 0)); tipCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
} else if (selectIndex == 2) { } else if (selectIndex == 2) {
//后N个 //后N个
setCardPaneLayout.show(setCardPane, FilterType.BOTTOM.name()); setCardPaneLayout.show(setCardPane, FilterType.BOTTOM.name());
tipCardPaneLayout.show(tipCardPane, FilterType.BOTTOM.name()); tipCardPaneLayout.show(tipCardPane, FilterType.BOTTOM.name());
//隐藏tip 显示set //隐藏tip 显示set
setCardPane.setPreferredSize(new Dimension(156, 20)); setCardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
tipCardPane.setPreferredSize(new Dimension(0, 0)); tipCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
} else if (selectIndex == 3) { } else if (selectIndex == 3) {
//奇数 //奇数
setCardPaneLayout.show(setCardPane, FilterType.ODD.name()); setCardPaneLayout.show(setCardPane, FilterType.ODD.name());
tipCardPaneLayout.show(tipCardPane, FilterType.ODD.name()); tipCardPaneLayout.show(tipCardPane, FilterType.ODD.name());
//隐藏set 显示tip //隐藏set 显示tip
setCardPane.setPreferredSize(new Dimension(0, 0)); setCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
tipCardPane.setPreferredSize(new Dimension(224, 40)); tipCardPane.setPreferredSize(new Dimension(224, 40));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, VGAP_INNER);
} else if (selectIndex == 4) { } else if (selectIndex == 4) {
setCardPaneLayout.show(setCardPane, FilterType.EVEN.name()); setCardPaneLayout.show(setCardPane, FilterType.EVEN.name());
tipCardPaneLayout.show(tipCardPane, FilterType.EVEN.name()); tipCardPaneLayout.show(tipCardPane, FilterType.EVEN.name());
//隐藏set 显示tip //隐藏set 显示tip
setCardPane.setPreferredSize(new Dimension(0, 0)); setCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
tipCardPane.setPreferredSize(new Dimension(224, 40)); tipCardPane.setPreferredSize(new Dimension(224, 40));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, VGAP_INNER);
} else if (selectIndex == 5) { } else if (selectIndex == 5) {
setCardPaneLayout.show(setCardPane, FilterType.SPECIFY.name()); setCardPaneLayout.show(setCardPane, FilterType.SPECIFY.name());
tipCardPaneLayout.show(tipCardPane, FilterType.SPECIFY.name()); tipCardPaneLayout.show(tipCardPane, FilterType.SPECIFY.name());
//显示set和tip //显示set和tip
setCardPane.setPreferredSize(new Dimension(156, 20)); setCardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
tipCardPane.setPreferredSize(new Dimension(224, 40)); tipCardPane.setPreferredSize(new Dimension(224, 40));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, VGAP_INNER);
} else { } else {
setCardPaneLayout.show(setCardPane, FilterType.UNDEFINE.name()); setCardPaneLayout.show(setCardPane, FilterType.UNDEFINE.name());
tipCardPaneLayout.show(tipCardPane, FilterType.UNDEFINE.name()); tipCardPaneLayout.show(tipCardPane, FilterType.UNDEFINE.name());
//隐藏set和tip //隐藏set和tip
setCardPane.setPreferredSize(new Dimension(0, 0)); setCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
tipCardPane.setPreferredSize(new Dimension(0, 0)); tipCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
} }
setCardPane.revalidate();
tipCardPane.revalidate();
setCardPane.repaint();
tipCardPane.repaint();
} }
}); });
//配置展示CardLayout //配置展示CardLayout
@ -746,7 +752,6 @@ public class CellDSColumnEditor extends CellQuickEditor {
oddTip.setForeground(TIP_FONT_COLOR); oddTip.setForeground(TIP_FONT_COLOR);
tipCardPane.add(oddTip, FilterType.ODD.name()); tipCardPane.add(oddTip, FilterType.ODD.name());
//偶数 UILabel 占一行作为提示信息 //偶数 UILabel 占一行作为提示信息
setCardPane.add(new JPanel(), FilterType.EVEN.name()); setCardPane.add(new JPanel(), FilterType.EVEN.name());
MultilineLabel evenTip = new MultilineLabel(Inter.getLocText("FS-Designer_DS_Filter_Even_Tip")); MultilineLabel evenTip = new MultilineLabel(Inter.getLocText("FS-Designer_DS_Filter_Even_Tip"));
@ -759,12 +764,13 @@ public class CellDSColumnEditor extends CellQuickEditor {
MultilineLabel specifyTip = new MultilineLabel(Inter.getLocText("FS-Designer_DS_Filter_Specify_Tip")); MultilineLabel specifyTip = new MultilineLabel(Inter.getLocText("FS-Designer_DS_Filter_Specify_Tip"));
specifyTip.setForeground(TIP_FONT_COLOR); specifyTip.setForeground(TIP_FONT_COLOR);
tipCardPane.add(specifyTip, FilterType.SPECIFY.name()); tipCardPane.add(specifyTip, FilterType.SPECIFY.name());
contentPane = TableLayoutHelper.createDiffVGapTableLayoutPane(new Component[][]{
this.add(TableLayoutHelper.createGapTableLayoutPane(new Component[][]{
{filterLabel, rsComboBox}, {filterLabel, rsComboBox},
{null, setCardPane}, {null, setCardPane},
{tipCardPane, null} {tipCardPane, null}
}, new double[]{P, P, P}, new double[]{P, F}, HGAP, VGAP), BorderLayout.CENTER); }, new double[]{P, P, P}, new double[]{P, F}, HGAP, new double[]{VGAP, VGAP_INNER});
this.add(contentPane, BorderLayout.CENTER);
} }
public void populate(CellElement cellElement) { public void populate(CellElement cellElement) {
@ -783,39 +789,53 @@ public class CellDSColumnEditor extends CellQuickEditor {
this.topFormulaPane.populate(selectCount.getFormulaCount()); this.topFormulaPane.populate(selectCount.getFormulaCount());
//隐藏tip 显示set //隐藏tip 显示set
setCardPane.setPreferredSize(new Dimension(156, 20)); setCardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
tipCardPane.setPreferredSize(new Dimension(0, 0)); tipCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
break; break;
case SelectCount.BOTTOM: case SelectCount.BOTTOM:
this.bottomFormulaPane.populate(selectCount.getFormulaCount()); this.bottomFormulaPane.populate(selectCount.getFormulaCount());
//隐藏tip 显示set //隐藏tip 显示set
setCardPane.setPreferredSize(new Dimension(156, 20)); setCardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
tipCardPane.setPreferredSize(new Dimension(0, 0)); tipCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
break; break;
case SelectCount.SPECIFY: case SelectCount.SPECIFY:
this.serialTextField.setText(selectCount.getSerial()); this.serialTextField.setText(selectCount.getSerial());
//显示set和tip //显示set和tip
setCardPane.setPreferredSize(new Dimension(156, 20)); setCardPane.setPreferredSize(new Dimension(156, 20));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, VGAP);
tipCardPane.setPreferredSize(new Dimension(224, 40)); tipCardPane.setPreferredSize(new Dimension(224, 40));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, VGAP_INNER);
break; break;
case SelectCount.EVEN: case SelectCount.EVEN:
//隐藏set 显示tip //隐藏set 显示tip
setCardPane.setPreferredSize(new Dimension(0, 0)); setCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
tipCardPane.setPreferredSize(new Dimension(224, 40)); tipCardPane.setPreferredSize(new Dimension(224, 40));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, VGAP_INNER);
break; break;
case SelectCount.ODD: case SelectCount.ODD:
//隐藏set 显示tip //隐藏set 显示tip
setCardPane.setPreferredSize(new Dimension(0, 0)); setCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
tipCardPane.setPreferredSize(new Dimension(224, 40)); tipCardPane.setPreferredSize(new Dimension(224, 40));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, VGAP_INNER);
break; break;
default: default:
//隐藏set和tip //隐藏set和tip
setCardPane.setPreferredSize(new Dimension(0, 0)); setCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
tipCardPane.setPreferredSize(new Dimension(0, 0)); tipCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
} }
} else { } else {
//隐藏set和tip //隐藏set和tip
setCardPane.setPreferredSize(new Dimension(0, 0)); setCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 2, 0);
tipCardPane.setPreferredSize(new Dimension(0, 0)); tipCardPane.setPreferredSize(new Dimension(0, 0));
TableLayoutHelper.modifyTableLayoutIndexVGap(contentPane, 4, 0);
} }
} }
} }
@ -848,13 +868,12 @@ public class CellDSColumnEditor extends CellQuickEditor {
/** /**
* 添加事件监听器 * 添加事件监听器
* *
* @param formulaListener 公式输入框改动事件监听器 * @param formulaListener 输入框改动事件监听器
* @param actionListener 筛选类型下拉框改动事件监听器
*/ */
public void addListener(UIObserverListener formulaListener, ActionListener actionListener) { public void addListener(UIObserverListener formulaListener) {
topFormulaPane.addListener(formulaListener); topFormulaPane.addListener(formulaListener);
bottomFormulaPane.addListener(formulaListener); bottomFormulaPane.addListener(formulaListener);
rsComboBox.addActionListener(actionListener); rsComboBox.registerChangeListener(formulaListener);
} }
} }

748
designer_base/src/com/fr/design/layout/TableLayoutHelper.java

@ -1,324 +1,426 @@
package com.fr.design.layout; package com.fr.design.layout;
import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.LayoutConstants;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.general.Inter; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.Inter;
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.*;
public class TableLayoutHelper {
public class TableLayoutHelper { public static final int FILL_NONE = 0;
public static final int FILL_NONE = 0; public static final int FILL_LASTCOLUMN = 1;
public static final int FILL_LASTCOLUMN = 1; public static final int FILL_LASTROW = 2;
public static final int FILL_LASTROW = 2; public static final int FILL_LASTCOL_AND_ROW = 3;
public static final int FILL_LASTCOL_AND_ROW = 3; private static final int FIVE = 5;
private static final int FIVE = 5; private static final int TEN = 10;
private static final int TEN = 10;
private TableLayoutHelper() { private TableLayoutHelper() {
} }
/** /**
* <p>一个通用的TableLayoutPane生成方法<p> * <p>一个通用的TableLayoutPane生成方法<p>
* <p>rowSize为各行高度之间的比例<p> * <p>rowSize为各行高度之间的比例<p>
* <p>columnSize 为各列宽度之间的比例<p> * <p>columnSize 为各列宽度之间的比例<p>
* <p>Component[][] components = {<p> * <p>Component[][] components = {<p>
* <p>// column_1 column_2 column_3<p> * <p>// column_1 column_2 column_3<p>
* <p> {component11, component12, component13} // row_1<p> * <p> {component11, component12, component13} // row_1<p>
* <p> {component21, component22, component23} // row_2<p> * <p> {component21, component22, component23} // row_2<p>
* <p>}<p> * <p>}<p>
*/ */
/** /**
*最常用的最后一行列fill或者都是prefer的tablelayout * 最常用的最后一行列fill或者都是prefer的tablelayout
* @param components 组件 *
* @return * @param components 组件
*/ * @return
public static JPanel createTableLayoutPane(Component[][] components, int fillType){ */
return createGapTableLayoutPane(components, fillType, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); public static JPanel createTableLayoutPane(Component[][] components, int fillType) {
} return createGapTableLayoutPane(components, fillType, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM);
}
public static JPanel createTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize) {
return createCommonTableLayoutPane(components, rowSize, columnSize, LayoutConstants.VGAP_MEDIUM); public static JPanel createTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize) {
} return createCommonTableLayoutPane(components, rowSize, columnSize, LayoutConstants.VGAP_MEDIUM);
}
/**
* 标题布局(二级菜单距左边框46) /**
* @param title 标题 * 标题布局(二级菜单距左边框46)
* @param component 组件 *
* @return 布局好的组件 * @param title 标题
*/ * @param component 组件
public static JPanel createTableLayoutPaneWithTitle(String title, Component component){ * @return 布局好的组件
return createTitlePane(title, component, LayoutConstants.CHART_ATTR_TOMARGIN); */
} public static JPanel createTableLayoutPaneWithTitle(String title, Component component) {
return createTitlePane(title, component, LayoutConstants.CHART_ATTR_TOMARGIN);
public static JPanel createTitlePane(String title, Component component, int gap){ }
return createTitlePaneWithUILabel(new UILabel(title), component, gap);
} public static JPanel createTitlePane(String title, Component component, int gap) {
return createTitlePaneWithUILabel(new UILabel(title), component, gap);
/** }
* 标题布局指定gap
* @param label 标题label /**
* @param component 组件 * 标题布局指定gap
* @param gap 距左侧距离 *
* @return 布局好的组件 * @param label 标题label
*/ * @param component 组件
public static JPanel createTitlePaneWithUILabel(UILabel label, Component component, int gap){ * @param gap 距左侧距离
double p = TableLayout.PREFERRED; * @return 布局好的组件
double f = TableLayout.FILL; */
double[] columnSize = {gap, f}; public static JPanel createTitlePaneWithUILabel(UILabel label, Component component, int gap) {
double[] rowSize = {p, p}; double p = TableLayout.PREFERRED;
Component[][] components = new Component[][]{ double f = TableLayout.FILL;
new Component[]{label,null}, double[] columnSize = {gap, f};
new Component[]{null,component}, double[] rowSize = {p, p};
}; Component[][] components = new Component[][]{
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); new Component[]{label, null},
} new Component[]{null, component},
};
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
public static JPanel createCommonTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize, double gap) { }
return createGapTableLayoutPane(components, rowSize, columnSize, gap, gap);
} public static JPanel createCommonTableLayoutPane(Component[][] components, double[] rowSize, double[] columnSize, double gap) {
public static JPanel createGapTableLayoutPane(Component[][] components, int fillType, double horizontalGap, double verticalGap) { return createGapTableLayoutPane(components, rowSize, columnSize, gap, gap);
double p = TableLayout.PREFERRED; }
double f = TableLayout.FILL;
int maxColCount = 0; public static JPanel createGapTableLayoutPane(Component[][] components, int fillType, double horizontalGap, double verticalGap) {
for (int i = 0 ; i < components.length; i ++) { double p = TableLayout.PREFERRED;
if (components[i].length > maxColCount) { double f = TableLayout.FILL;
maxColCount = components[i].length; int maxColCount = 0;
} for (int i = 0; i < components.length; i++) {
} if (components[i].length > maxColCount) {
double[] rowSize = new double[components.length]; maxColCount = components[i].length;
for (int i = 0; i < components.length; i ++) { }
rowSize[i] = p; }
} double[] rowSize = new double[components.length];
double[] columnSize = new double[maxColCount]; for (int i = 0; i < components.length; i++) {
for (int i = 0; i < maxColCount; i ++) { rowSize[i] = p;
columnSize[i] = p; }
} double[] columnSize = new double[maxColCount];
if (fillType == FILL_LASTCOLUMN && columnSize.length > 0) { for (int i = 0; i < maxColCount; i++) {
columnSize[columnSize.length - 1] = f; columnSize[i] = p;
} }
if (fillType == FILL_LASTROW && rowSize.length > 0) { if (fillType == FILL_LASTCOLUMN && columnSize.length > 0) {
rowSize[rowSize.length - 1] = f; columnSize[columnSize.length - 1] = f;
} }
if (fillType == FILL_LASTCOL_AND_ROW ) { if (fillType == FILL_LASTROW && rowSize.length > 0) {
if (columnSize.length > 0) { rowSize[rowSize.length - 1] = f;
columnSize[columnSize.length - 1] = f; }
} if (fillType == FILL_LASTCOL_AND_ROW) {
if (rowSize.length > 0) { if (columnSize.length > 0) {
rowSize[rowSize.length - 1] = f; columnSize[columnSize.length - 1] = f;
} }
} if (rowSize.length > 0) {
return createGapTableLayoutPane(components, rowSize, columnSize, horizontalGap, verticalGap); rowSize[rowSize.length - 1] = f;
} }
}
public static JPanel createGapTableLayoutPane(Component[][] components, return createGapTableLayoutPane(components, rowSize, columnSize, horizontalGap, verticalGap);
double[] rowSize, double[] columnSize, double horizontalGap, double verticalGap) { }
JPanel resultPane = setPanelLayout(rowSize, columnSize, horizontalGap, verticalGap); public static JPanel createGapTableLayoutPane(Component[][] components,
double[] rowSize,
for (int i = 0; i < components.length; i++) { double[] columnSize,
if (i >= rowSize.length) { double horizontalGap,
break; double verticalGap) {
}
Component[] rowComponents = components[i]; JPanel resultPane = setPanelLayout(rowSize, columnSize, horizontalGap, verticalGap);
for (int j = 0; j < rowComponents.length && j < columnSize.length; j++) {
if (rowComponents[j] == null) { addComponent2ResultPane(components, rowSize, columnSize, resultPane);
continue;
} return resultPane;
}
if (isNextAllNull(rowComponents, j + 1)) {
resultPane.add(rowComponents[j], (2 * j + 1) + "," + (2 * i + 1) + "," + (2 * rowComponents.length - 1) + ",0");
} else { public static JPanel createDiffVGapTableLayoutPane(Component[][] components,
resultPane.add(rowComponents[j], (2 * j + 1) + "," + (2 * i + 1)); double[] rowSize,
} double[] columnSize,
} double horizontalGap,
} double[] verticalGap) {
JPanel resultPane = setPanelLayout(rowSize, columnSize, horizontalGap, verticalGap);
return resultPane; addComponent2ResultPane(components, rowSize, columnSize, resultPane);
} return resultPane;
}
public static JPanel createGapTableLayoutPane(Component[][] components,
double[] rowSize, double[] columnSize, int rowCount[][], double horizontalGap, double verticalGap) { public static JPanel createGapTableLayoutPane(Component[][] components,
double[] rowSize, double[] columnSize, int rowCount[][], double horizontalGap, double verticalGap) {
JPanel resultPane = setPanelLayout(rowSize, columnSize, horizontalGap, verticalGap);
JPanel resultPane = setPanelLayout(rowSize, columnSize, horizontalGap, verticalGap);
int k = components.length;
int[] row = new int[k]; //存放每组控件在第几行开始 int k = components.length;
int sumRow = 1; //存放一次递增的行的数目 int[] row = new int[k]; //存放每组控件在第几行开始
int sumRow = 1; //存放一次递增的行的数目
for (int i = 0; i < components.length; i++) {
row[i] = sumRow; for (int i = 0; i < components.length; i++) {
int maxRowCount = 1; row[i] = sumRow;
int maxRowCount = 1;
if (i >= rowSize.length) {
break; if (i >= rowSize.length) {
} break;
}
Component[] rowComponents = components[i];
for (int j = 0; j < rowComponents.length && j < columnSize.length; j++) { Component[] rowComponents = components[i];
if (rowComponents[j] == null) { for (int j = 0; j < rowComponents.length && j < columnSize.length; j++) {
continue; if (rowComponents[j] == null) {
} continue;
if (isNextAllNull(rowComponents, j + 1)) { }
if (rowCount[i][j] != 1) { if (isNextAllNull(rowComponents, j + 1)) {
resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i] + "," + (2 * rowComponents.length - 1) + "," + (row[i] + rowCount[i][j] - 1)); if (rowCount[i][j] != 1) {
if (rowCount[i][j] > maxRowCount) { resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i] + "," + (2 * rowComponents.length - 1) + "," + (row[i] + rowCount[i][j] - 1));
maxRowCount = rowCount[i][j]; if (rowCount[i][j] > maxRowCount) {
} maxRowCount = rowCount[i][j];
} else { }
} else {
resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i] + "," + (2 * rowComponents.length - 1) + "," + row[i]);
} resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i] + "," + (2 * rowComponents.length - 1) + "," + row[i]);
} else { }
} else {
if (rowCount[i][j] != 1) {
resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i] + "," + (2 * j + 1) + "," + (row[i] + rowCount[i][j] - 1)); if (rowCount[i][j] != 1) {
if (rowCount[i][j] > maxRowCount) { resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i] + "," + (2 * j + 1) + "," + (row[i] + rowCount[i][j] - 1));
maxRowCount = rowCount[i][j]; if (rowCount[i][j] > maxRowCount) {
} maxRowCount = rowCount[i][j];
} else { }
resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i]); } else {
} resultPane.add(rowComponents[j], (2 * j + 1) + "," + row[i]);
} }
} }
sumRow = row[i] + maxRowCount + 1; }
} sumRow = row[i] + maxRowCount + 1;
}
return resultPane;
} return resultPane;
}
private static boolean isNextAllNull(Component[] rowComponents, int currentIndex) { /**
for (int i = currentIndex; i < rowComponents.length; i++) { * 修改TableLayout布局的容器指定位置垂直间距的大小
if (rowComponents[i] != null) { *
return false; * @param container 容器
} * @param index vgap的索引ContainervGapA[ComponentA]vGapB[ComponentB]vGapC,vGapB index=2,
} * 详情见{@link TableLayout#setRow(int, double)}
return true; * @param vgap vgap的新值
} */
public static void modifyTableLayoutIndexVGap(Container container, int index, double vgap) {
private static JPanel setPanelLayout(double[] rowSize, double[] columnSize, double horizontalGap, double verticalGap) { TableLayout layout = (TableLayout) container.getLayout();
double layoutSize[][] = new double[2][]; layout.setRow(index, vgap);
double layoutColumnSize[] = new double[2 * columnSize.length]; layout.layoutContainer(container);
double layoutRowSize[] = new double[2 * rowSize.length]; container.repaint();
}
for (int i = 0; i < columnSize.length; i++) {
if (i == 0) { /**
layoutColumnSize[i * 2] = 0; * 修改TableLayout布局的容器指定位置水平间距的大小
} else { *
layoutColumnSize[i * 2] = horizontalGap; * @param container 容器
} * @param index hgap的索引ContainerhGapA[ComponentA]hGapB[ComponentB],hGapB index=2,
layoutColumnSize[i * 2 + 1] = columnSize[i]; * 详情见{@link TableLayout#setColumn(int, double)}
} * @param hgap hgap的新值
*/
for (int i = 0; i < rowSize.length; i++) { public static void modifyTableLayoutIndexHGap(Container container, int index, double hgap) {
if (i == 0) { TableLayout layout = (TableLayout) container.getLayout();
layoutRowSize[i * 2] = 0; layout.setColumn(index, hgap);
} else { layout.layoutContainer(container);
layoutRowSize[i * 2] = verticalGap; container.repaint();
} }
layoutRowSize[i * 2 + 1] = rowSize[i];
} private static void addComponent2ResultPane(Component[][] components, double[] rowSize, double[] columnSize, JPanel resultPane) {
layoutSize[0] = layoutColumnSize; for (int i = 0; i < components.length; i++) {
layoutSize[1] = layoutRowSize; if (i >= rowSize.length) {
break;
JPanel resultPane = new JPanel(); }
resultPane.setLayout(new TableLayout(layoutSize)); Component[] rowComponents = components[i];
for (int j = 0; j < rowComponents.length && j < columnSize.length; j++) {
return resultPane; if (rowComponents[j] == null) {
} continue;
}
/**
* 图表属性表用的比较多的一种布局第一行是title,下面的components相当于二级菜单 if (isNextAllNull(rowComponents, j + 1)) {
* 二级菜单和上层面板的间距在layoutconstants里定义 resultPane.add(rowComponents[j], (2 * j + 1) + "," + (2 * i + 1) + "," + (2 * rowComponents.length - 1) + ",0");
* @param title } else {
* @param components 二级菜单的内容 resultPane.add(rowComponents[j], (2 * j + 1) + "," + (2 * i + 1));
* @param rowSize 二级菜单的行数 }
* @param columnSize 二级菜单的列数 }
* @return }
*/
public static JPanel createTableLayoutPane4Chart(String[] title, Component[][] components, double[] rowSize, double[] columnSize){ }
JPanel secondMenu = createTableLayoutPane(components, rowSize, columnSize);
double p = TableLayout.PREFERRED; private static boolean isNextAllNull(Component[] rowComponents, int currentIndex) {
double f = TableLayout.FILL; for (int i = currentIndex; i < rowComponents.length; i++) {
double[] column = {LayoutConstants.CHART_ATTR_TOMARGIN, f}; if (rowComponents[i] != null) {
double[] row = { p,p}; return false;
Component[][] comp = new Component[][]{ }
new Component[]{new UILabel(Inter.getLocText(title)), null}, }
new Component[]{null, secondMenu}, return true;
}; }
return createTableLayoutPane(comp, row, column);
} private static JPanel setPanelLayout(double[] rowSize, double[] columnSize, double horizontalGap, double verticalGap) {
double layoutSize[][] = new double[2][];
public static void main (String[] args) { double layoutColumnSize[] = new double[2 * columnSize.length];
JFrame jf = new JFrame("test"); double layoutRowSize[] = new double[2 * rowSize.length];
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel content = (JPanel) jf.getContentPane(); for (int i = 0; i < columnSize.length; i++) {
content.setLayout(new GridLayout(2,2)); if (i == 0) {
double p = TableLayout.PREFERRED; layoutColumnSize[i * 2] = 0;
double f = TableLayout.FILL; } else {
JPanel jp1 = TableLayoutHelper.createTableLayoutPane(createTestComponents("jp1"), TableLayoutHelper.FILL_NONE); layoutColumnSize[i * 2] = horizontalGap;
JPanel jp2 = TableLayoutHelper.createGapTableLayoutPane(createTestComponents("jp2"), TableLayoutHelper.FILL_LASTCOL_AND_ROW, 2 * TEN, 2 * TEN); }
JPanel jp3 = TableLayoutHelper.createGapTableLayoutPane(createTestComponents("jp3"), layoutColumnSize[i * 2 + 1] = columnSize[i];
new double[] {f,p,f,p}, new double[] {f,f}, 4,4); }
JPanel jp4 = TableLayoutHelper.createGapTableLayoutPane(createTestComponents("jp4"),
new double[] {p,FIVE * TEN,p,p,p,p},new double[] {p, f}, new int[][] {{1,3},{1,1},{1,1},{1,1},{1,1}}, 1, FIVE); for (int i = 0; i < rowSize.length; i++) {
jp1.setBorder(BorderFactory.createLineBorder(Color.red)); if (i == 0) {
jp2.setBorder(BorderFactory.createLineBorder(Color.red)); layoutRowSize[i * 2] = 0;
jp3.setBorder(BorderFactory.createLineBorder(Color.red)); } else {
jp4.setBorder(BorderFactory.createLineBorder(Color.red)); layoutRowSize[i * 2] = verticalGap;
}
content.add(jp1); layoutRowSize[i * 2 + 1] = rowSize[i];
content.add(jp2); }
content.add(jp3);
content.add(jp4); layoutSize[0] = layoutColumnSize;
layoutSize[1] = layoutRowSize;
GUICoreUtils.centerWindow(jf);
jf.setSize(600, 600); JPanel resultPane = new JPanel();
jf.setVisible(true); resultPane.setLayout(new TableLayout(layoutSize));
}
return resultPane;
private static Component[][] createTestComponents (String name ) { }
UILabel label1 = new UILabel(name + "laaaable1");
UILabel label2 = new UILabel(name + "lable2"); /**
UILabel label3 = new UILabel(name + "lable3"); * 创建具有不同垂直间距的TableLayout面板
UILabel label4 = new UILabel(name + "lable4"); *
UILabel label5 = new UILabel(name + "lable5"); * @param rowSize
UIButton button1 = new UIButton(name + "button1"); * @param columnSize
UIButton button2 = new UIButton(name + "button2"); * @param horizontalGap 水平间距
label1.setSize(label1.getPreferredSize()); * @param verticalGap 不同的垂直间距
label1.setBorder(BorderFactory.createLineBorder(Color.blue)); * @return JPanel 具有不同垂直间距的TableLayout面板
label2.setSize(label2.getPreferredSize()); */
label2.setBorder(BorderFactory.createLineBorder(Color.blue)); private static JPanel setPanelLayout(double[] rowSize, double[] columnSize, double horizontalGap, double[] verticalGap) {
label3.setSize(label3.getPreferredSize()); double layoutSize[][] = new double[2][];
label3.setBorder(BorderFactory.createLineBorder(Color.blue)); double layoutColumnSize[] = new double[2 * columnSize.length];
label4.setSize(label4.getPreferredSize()); double layoutRowSize[] = new double[2 * rowSize.length];
label4.setBorder(BorderFactory.createLineBorder(Color.blue));
label5.setSize(label5.getPreferredSize()); for (int i = 0; i < columnSize.length; i++) {
label5.setBorder(BorderFactory.createLineBorder(Color.blue)); if (i == 0) {
button1.setSize(button1.getPreferredSize()); layoutColumnSize[i * 2] = 0;
button2.setSize(button2.getPreferredSize()); } else {
button1.setBackground(Color.darkGray); layoutColumnSize[i * 2] = horizontalGap;
button2.setBackground(Color.darkGray); }
Component[][] components = new Component[][] { layoutColumnSize[i * 2 + 1] = columnSize[i];
new Component[] {label1, button1}, }
new Component[] {label2, null},
new Component[] {label3}, for (int i = 0; i < rowSize.length; i++) {
new Component[] {null,label4}, if (i == 0) {
new Component[] {button2, label5} layoutRowSize[i * 2] = 0;
} ; } else {
return components; layoutRowSize[i * 2] = verticalGap[i - 1];
} }
layoutRowSize[i * 2 + 1] = rowSize[i];
}
layoutSize[0] = layoutColumnSize;
layoutSize[1] = layoutRowSize;
JPanel resultPane = new JPanel();
resultPane.setLayout(new TableLayout(layoutSize));
return resultPane;
}
/**
* 图表属性表用的比较多的一种布局第一行是title,下面的components相当于二级菜单
* 二级菜单和上层面板的间距在layoutconstants里定义
*
* @param title
* @param components 二级菜单的内容
* @param rowSize 二级菜单的行数
* @param columnSize 二级菜单的列数
* @return
*/
public static JPanel createTableLayoutPane4Chart(String[] title, Component[][] components, double[] rowSize, double[] columnSize) {
JPanel secondMenu = createTableLayoutPane(components, rowSize, columnSize);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] column = {LayoutConstants.CHART_ATTR_TOMARGIN, f};
double[] row = {p, p};
Component[][] comp = new Component[][]{
new Component[]{new UILabel(Inter.getLocText(title)), null},
new Component[]{null, secondMenu},
};
return createTableLayoutPane(comp, row, column);
}
public static void main(String[] args) {
JFrame jf = new JFrame("test");
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel content = (JPanel) jf.getContentPane();
content.setLayout(new GridLayout(2, 3));
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
JPanel jp1 = TableLayoutHelper.createTableLayoutPane(createTestComponents("jp1"), TableLayoutHelper.FILL_NONE);
JPanel jp2 = TableLayoutHelper.createGapTableLayoutPane(createTestComponents("jp2"), TableLayoutHelper.FILL_LASTCOL_AND_ROW, 2 * TEN, 2 * TEN);
JPanel jp3 = TableLayoutHelper.createGapTableLayoutPane(createTestComponents("jp3"),
new double[]{f, p, f, p}, new double[]{f, f}, 4, 4);
JPanel jp4 = TableLayoutHelper.createGapTableLayoutPane(createTestComponents("jp4"),
new double[]{p, FIVE * TEN, p, p, p, p}, new double[]{p, f}, new int[][]{{1, 3}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}, 1, FIVE);
JPanel jp5 = TableLayoutHelper.createDiffVGapTableLayoutPane(createTestComponents("jp5"),
new double[]{p, p, p, p, p}, new double[]{p, f}, 4, new double[]{4, 8, 14, 4});
JPanel jp6 = new JPanel();
jp1.setBorder(BorderFactory.createLineBorder(Color.red));
jp2.setBorder(BorderFactory.createLineBorder(Color.red));
jp3.setBorder(BorderFactory.createLineBorder(Color.red));
jp4.setBorder(BorderFactory.createLineBorder(Color.red));
jp5.setBorder(BorderFactory.createLineBorder(Color.red));
jp6.setBorder(BorderFactory.createLineBorder(Color.red));
content.add(jp1);
content.add(jp2);
content.add(jp3);
content.add(jp4);
content.add(jp5);
content.add(jp6);
GUICoreUtils.centerWindow(jf);
jf.setSize(900, 600);
jf.setVisible(true);
}
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());
button1.setBackground(Color.darkGray);
button2.setBackground(Color.darkGray);
return new Component[][]{
new Component[]{label1, button1},
new Component[]{label2, null},
new Component[]{label3},
new Component[]{null, label4},
new Component[]{button2, label5}
};
}
} }
Loading…
Cancel
Save