Browse Source
Merge in DESIGN/design from ~LEVY.XIE/design:newui to newui * commit '462452de1a3dd750797c32d05045364e518b2ad1': REPORT-113994 【NewUI】设计器样式翻新-图表newui
Levy.Xie-解安森
4 months ago
54 changed files with 785 additions and 1121 deletions
@ -0,0 +1,155 @@ |
|||||||
|
package com.fine.theme.utils; |
||||||
|
|
||||||
|
import com.fine.swing.ui.layout.Column; |
||||||
|
import com.fine.swing.ui.layout.Layouts; |
||||||
|
import com.fine.swing.ui.layout.Row; |
||||||
|
import com.fine.swing.ui.layout.Spacer; |
||||||
|
import com.fr.design.foldablepane.UIExpandablePane; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.collections.combination.Pair; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Component; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.List; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
import java.util.stream.IntStream; |
||||||
|
|
||||||
|
import static com.fine.swing.ui.layout.Layouts.cell; |
||||||
|
|
||||||
|
/** |
||||||
|
* 设计器典型布局构建器 |
||||||
|
* |
||||||
|
* @author Levy.Xie |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2024/05/08 |
||||||
|
*/ |
||||||
|
public class FineLayoutBuilder { |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建标准行列表格布局,行内元素均匀分布 |
||||||
|
* |
||||||
|
* @param elePerRow 每行元素数 |
||||||
|
* @param rowSpacing 行内间距 |
||||||
|
* @param colSpacing 列内间距 |
||||||
|
* @param componentList 组件 |
||||||
|
* @return 表格面板 |
||||||
|
*/ |
||||||
|
public static Column createCommonTableLayout(int elePerRow, int rowSpacing, int colSpacing, List<? extends Component> componentList) { |
||||||
|
int rowNum = componentList.size() / elePerRow + 1; |
||||||
|
Iterator<? extends Component> iterator = componentList.iterator(); |
||||||
|
|
||||||
|
Column column = new Column(); |
||||||
|
column.setSpacing(colSpacing); |
||||||
|
|
||||||
|
Row currentRow; |
||||||
|
for (int i = 0; i < rowNum; i++) { |
||||||
|
currentRow = new Row(); |
||||||
|
currentRow.setSpacing(rowSpacing); |
||||||
|
for (int j = 0; j < elePerRow; j++) { |
||||||
|
Layouts.populate(currentRow, cell( |
||||||
|
iterator.hasNext() ? iterator.next() : new Spacer(1) |
||||||
|
).weight(1)); |
||||||
|
} |
||||||
|
column.add(currentRow); |
||||||
|
} |
||||||
|
return column; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 兼容TableLayout配置项,生成网格布局面板 |
||||||
|
* |
||||||
|
* @param colSpacing 间距 |
||||||
|
* @param components 组件二维数组,内部每个一维数组均为行内组件,一维数组元素需与weight严格对应 |
||||||
|
* @param weight 行内权重列表,形如[0.4,0.6] 即首个元素占比0.4,第二个元素占比0.6 |
||||||
|
* @return 面板 |
||||||
|
*/ |
||||||
|
public static JPanel compatibleTableLayout(int colSpacing, Component[][] components, double[] weight) { |
||||||
|
Column column = new Column(); |
||||||
|
column.setSpacing(colSpacing); |
||||||
|
try { |
||||||
|
for (Component[] componentArray : components) { |
||||||
|
Row row = new Row(); |
||||||
|
List<Component> visibleComponents = Arrays.stream(componentArray) |
||||||
|
.filter(com -> com != null && com.isVisible()).collect(Collectors.toList()); |
||||||
|
if (visibleComponents.size() >= 1) { |
||||||
|
// 仅当存在可见组件时处理布局
|
||||||
|
dealWithVisibleComponents(weight, column, componentArray, row, visibleComponents); |
||||||
|
} |
||||||
|
} |
||||||
|
return asBorderLayoutWrapped(column); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e, "[Designer] create layout failed."); |
||||||
|
} |
||||||
|
return new JPanel(); |
||||||
|
} |
||||||
|
|
||||||
|
private static void dealWithVisibleComponents(double[] weight, Column column, Component[] value, Row row, List<Component> components) { |
||||||
|
if (components.size() == 1 && value[0] != null) { |
||||||
|
// 仅存在首个元素,则该元素自适应占满整行
|
||||||
|
Layouts.populate(row, cell(components.get(0)).weight(1)); |
||||||
|
} else { |
||||||
|
// 其他场景,按权重分配布局,以适配原TableLayout形式
|
||||||
|
for (int j = 0; j < value.length; j++) { |
||||||
|
Component component = value[j]; |
||||||
|
if (component == null) { |
||||||
|
component = new Spacer(1); |
||||||
|
} |
||||||
|
Layouts.populate(row, cell(component).weight(weight[j])); |
||||||
|
} |
||||||
|
} |
||||||
|
column.add(row); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建竖向排列的扩展面板列表 |
||||||
|
* |
||||||
|
* @param spacing 间距 |
||||||
|
* @param elements 面板元素,含标题、面板 |
||||||
|
* @return 竖向排列面板 |
||||||
|
*/ |
||||||
|
@SafeVarargs |
||||||
|
public static Column createVerticalExpandPaneLayout(int spacing, Pair<String, JPanel>... elements) { |
||||||
|
UIExpandablePane[] panes = IntStream.range(0, elements.length) |
||||||
|
.mapToObj(i -> { |
||||||
|
Pair<String, JPanel> pair = elements[i]; |
||||||
|
if (i != elements.length - 1) { |
||||||
|
return new UIExpandablePane(pair.getFirst(), pair.getSecond(), true); |
||||||
|
} |
||||||
|
return new UIExpandablePane(pair.getFirst(), pair.getSecond()); |
||||||
|
}) |
||||||
|
.toArray(UIExpandablePane[]::new); |
||||||
|
return createVerticalLayout(spacing, panes); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建垂直布局面板 |
||||||
|
* |
||||||
|
* @param spacing 间距 |
||||||
|
* @param elements 面板元素 |
||||||
|
* @return 面板 |
||||||
|
*/ |
||||||
|
public static Column createVerticalLayout(int spacing, JPanel... elements) { |
||||||
|
Column column = new Column(); |
||||||
|
column.setSpacing(spacing); |
||||||
|
for (JPanel element : elements) { |
||||||
|
column.add(element); |
||||||
|
} |
||||||
|
return column; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 组件包装于BorderLayout中 |
||||||
|
* |
||||||
|
* @param component 组件 |
||||||
|
* @return 包装后的面板 |
||||||
|
*/ |
||||||
|
public static JPanel asBorderLayoutWrapped(Component component) { |
||||||
|
JPanel panel = new JPanel(new BorderLayout()); |
||||||
|
panel.add(component); |
||||||
|
return panel; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -1,47 +1,28 @@ |
|||||||
package com.fr.van.chart.designer.component.format; |
package com.fr.van.chart.designer.component.format; |
||||||
|
|
||||||
|
import com.fine.theme.utils.FineLayoutBuilder; |
||||||
import com.fr.design.gui.ilable.UILabel; |
import com.fr.design.gui.ilable.UILabel; |
||||||
import com.fr.design.gui.style.FormatPane; |
import com.fr.design.gui.style.FormatPane; |
||||||
import com.fr.design.layout.TableLayout; |
|
||||||
|
|
||||||
import com.fr.van.chart.designer.TableLayout4VanChartHelper; |
|
||||||
|
|
||||||
import javax.swing.BorderFactory; |
|
||||||
import javax.swing.JPanel; |
import javax.swing.JPanel; |
||||||
import javax.swing.SwingConstants; |
|
||||||
import java.awt.Component; |
import java.awt.Component; |
||||||
import java.awt.Dimension; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* Created by mengao on 2017/8/28. |
* Created by mengao on 2017/8/28. |
||||||
* 只有文本格式设置,没有字体设置 |
* 只有文本格式设置,没有字体设置 |
||||||
*/ |
*/ |
||||||
public class FormatPaneWithOutFont extends FormatPane { |
public class FormatPaneWithOutFont extends FormatPane { |
||||||
private static final int HEIGHT = 30; |
|
||||||
|
|
||||||
protected JPanel createContentPane(Component[][] components) { |
protected JPanel createContentPane(Component[][] components) { |
||||||
double f = TableLayout.FILL; |
return FineLayoutBuilder.compatibleTableLayout(10, components, new double[]{1.2, 3}); |
||||||
double p = TableLayout.PREFERRED; |
|
||||||
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH; |
|
||||||
double[] rowSize = {p, p, p}; |
|
||||||
double[] columnSize = {f, e}; |
|
||||||
return TableLayout4VanChartHelper.createGapTableLayoutPane(components, rowSize, columnSize); |
|
||||||
} |
} |
||||||
|
|
||||||
protected Component[][] getComponent (JPanel fontPane, JPanel centerPane, JPanel typePane) { |
protected Component[][] getComponent (JPanel fontPane, JPanel centerPane, JPanel typePane) { |
||||||
typePane.setBorder(BorderFactory.createEmptyBorder()); |
|
||||||
return new Component[][]{ |
return new Component[][]{ |
||||||
new Component[]{null, null}, |
new Component[]{null, null}, |
||||||
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Format"), SwingConstants.LEFT), typePane}, |
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Format")), typePane}, |
||||||
new Component[]{null, centerPane}, |
new Component[]{null, centerPane}, |
||||||
}; |
}; |
||||||
} |
} |
||||||
|
|
||||||
public Dimension getPreferredSize() { |
|
||||||
//todo @mango
|
|
||||||
if (getTypeComboBox().getSelectedIndex() == 0) { |
|
||||||
return new Dimension((int)getTypeComboBox().getPreferredSize().getWidth(), HEIGHT); |
|
||||||
} |
|
||||||
return new Dimension((int)super.getPreferredSize().getWidth(), (int)super.getPreferredSize().getHeight()); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue