Browse Source

Pull request #5464: REPORT-51919 绘制预览图

Merge in DESIGN/design from ~KERRY/design_10.0:feature/x to feature/x

* commit 'a9599d6dad8daa35d0541b1f002f7f52713a17e3':
  REPORT-51919 绘制预览图
research/11.0
kerry 3 years ago
parent
commit
7e655b40ff
  1. 9
      designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java
  2. 7
      designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java
  3. 6
      designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeProfileDialog.java
  4. 36
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ComponentPreviewPane.java
  5. 160
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ECPreviewPane.java
  6. 87
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/FormThemePreviewPane.java
  7. 39
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java
  8. 19
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/UINoOpaquePanel.java
  9. 47
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/AbstractECPreviewPane.java
  10. 3
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECComponentPreviewPane.java
  11. 104
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECPreviewPane.java
  12. 126
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECReportPreviewPane.java
  13. 32
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/AbstractPreviewCell.java
  14. 33
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/CornerPreviewCell.java
  15. 25
      designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/PreviewCell.java
  16. 10
      designer-base/src/main/java/com/fr/design/style/color/ColorCell.java
  17. 10
      designer-base/src/main/java/com/fr/design/style/color/FineColorCell.java

9
designer-base/src/main/java/com/fr/design/layout/FRGUIPaneFactory.java

@ -591,6 +591,15 @@ public class FRGUIPaneFactory {
return jp;
}
public static JPanel createBorderLayout_NO_Opaque_Pane() {
JPanel jp = new JPanel();
jp.setOpaque(false);
jp.setBackground(null);
jp.setLayout(FRGUIPaneFactory.createBorderLayout());
return jp;
}
/**
* 创建卡片式布局
*

7
designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java

@ -67,7 +67,7 @@ public abstract class TemplateThemeProfilePane<T extends TemplateTheme> extends
public static final int PREVIEW_PANE_WIDTH = LEFT_TITLE_PANE_WIDTH - 10;
public static final int PREVIEW_PANE_HEIGHT = LEFT_TITLE_PANE_HEIGHT - TITLE_BORDER_FONT - 16;
public static final int RIGHT_PANE_WIDTH = 360;
public static final int RIGHT_PANE_WIDTH = 352;
public static final int RIGHT_PANE_HEIGHT = LEFT_TITLE_PANE_HEIGHT;
public static final int COLOR_SCHEME_TITLE_PANE_WIDTH = 298;
public static final int COLOR_SCHEME_TITLE_PANE_HEIGHT = 174 + TITLE_BORDER_FONT / 2;
@ -148,8 +148,7 @@ public abstract class TemplateThemeProfilePane<T extends TemplateTheme> extends
themePreviewPane = createThemePreviewPane();
themePreviewPane.setPreferredSize(new Dimension(PREVIEW_PANE_WIDTH, PREVIEW_PANE_HEIGHT));
themePreviewPane.setOpaque(true);
themePreviewPane.setBackground(Color.WHITE);
themePreviewPane.setPreferredSize(new Dimension(PREVIEW_PANE_WIDTH, PREVIEW_PANE_HEIGHT));
previewContainer.add(themePreviewPane, BorderLayout.CENTER);
@ -329,7 +328,7 @@ public abstract class TemplateThemeProfilePane<T extends TemplateTheme> extends
colorListPane.populate(theme.getColorScheme().getColors());
colorListExtendedPane.populate(colorListPane.update());
chartStyleSettingPane.populateBean(theme.getChartStyle());
themePreviewPane.refresh(theme);
isPopulating = false;
}

6
designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeProfileDialog.java

@ -19,12 +19,11 @@ import java.awt.event.ActionListener;
* Created by Starryi on 2021/8/13
*/
public class TemplateThemeProfileDialog<T extends TemplateTheme> extends TemplateThemeDialog {
public static final int CONTENT_WIDTH = 778;
public static final int CONTENT_HEIGHT = 558;
public static final int CONTENT_WIDTH = 900;
public static final int CONTENT_HEIGHT = 570;
public TemplateThemeProfileDialog(Window parent, TemplateThemeProfilePane<T> profilePane) {
super(parent, Toolkit.i18nText("Fine-Design_Template_Theme_Profile_Dialog_Title"), CONTENT_WIDTH, CONTENT_HEIGHT);
JPanel content = FRGUIPaneFactory.createBorderLayout_S_Pane();
content.setPreferredSize(new Dimension(CONTENT_WIDTH, CONTENT_HEIGHT));
content.add(profilePane, BorderLayout.CENTER);
@ -34,6 +33,7 @@ public class TemplateThemeProfileDialog<T extends TemplateTheme> extends Templat
profilePane.createSaveAsButton(this),
createCancelButton()
}));
}
private UIButton createCancelButton() {

36
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ComponentPreviewPane.java

@ -6,6 +6,7 @@ import com.fr.base.background.ImageBackground;
import com.fr.base.theme.FormTheme;
import com.fr.base.theme.settings.ThemedComponentStyle;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.form.ui.Label;
import com.fr.form.ui.LayoutBorderStyle;
@ -36,22 +37,26 @@ import java.awt.geom.RoundRectangle2D;
* @version 1.0
* Created by Starryi on 2021/8/13
*/
public abstract class ComponentPreviewPane extends JPanel implements ThemePreviewed<FormTheme> {
public abstract class ComponentPreviewPane extends UINoOpaquePanel implements ThemePreviewed<FormTheme> {
public static final int TITLE_HEIGHT = 35;
private final JPanel container;
private final TitleDemoPane titlePane;
private TitleDemoPane titlePane;
private BorderPacker style = new LayoutBorderStyle();
public ComponentPreviewPane(){
this(false);
}
public ComponentPreviewPane() {
container = FRGUIPaneFactory.createBorderLayout_S_Pane();
public ComponentPreviewPane(boolean showTitle) {
container = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane();
setLayout(new BorderLayout());
titlePane = new TitleDemoPane();
titlePane.setPreferredSize(new Dimension(titlePane.getPreferredSize().width, TITLE_HEIGHT));
container.add(titlePane, BorderLayout.NORTH);
if (showTitle) {
titlePane = new TitleDemoPane();
titlePane.setPreferredSize(new Dimension(517, TITLE_HEIGHT));
container.add(titlePane, BorderLayout.NORTH);
}
container.add(createContentPane(), BorderLayout.CENTER);
add(container, BorderLayout.CENTER);
}
@ -69,8 +74,10 @@ public abstract class ComponentPreviewPane extends JPanel implements ThemePrevie
int paddingLeft = componentStyle.getPaddingLeft();
int paddingRight = componentStyle.getPaddingRight();
container.setBorder(BorderFactory.createEmptyBorder(paddingTop, paddingLeft, paddingBottom, paddingRight));
if (titlePane != null) {
titlePane.refresh(componentStyle);
}
titlePane.refresh(componentStyle);
}
@Override
@ -83,16 +90,15 @@ public abstract class ComponentPreviewPane extends JPanel implements ThemePrevie
Utils.clipByRoundBorder(g2d, getWidth(), getHeight(), roundedBorder.getRoundedCorner(), roundedBorder.getThickness());
}
int titleHeight = titlePane.getHeight();
int titleHeight = titlePane == null ? 0 : titlePane.getHeight();
Utils.paintBackground(g2d, style.getBackground(), new Rectangle2D.Double(0, titleHeight, getWidth(), getHeight() - titleHeight), style.getAlpha());
Utils.paintBackground(g2d, style.getBorderImage(), new Rectangle2D.Double(0, 0, getWidth(), getHeight()), style.getBorderImageOpacity());
super.paint(g2d);
super.paintBorder(g2d);
super.paint(g);
}
private static class TitleDemoPane extends JPanel {
private static class TitleDemoPane extends UINoOpaquePanel {
private final Label data = new Label();
public void refresh(ThemedComponentStyle componentStyle) {
@ -137,10 +143,6 @@ public abstract class ComponentPreviewPane extends JPanel implements ThemePrevie
Constants.FR_PAINT_RESOLUTION);
}
@Override
public Dimension getPreferredSize() {
return getSize();
}
}
private static class Utils {

160
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ECPreviewPane.java

@ -1,160 +0,0 @@
package com.fr.design.mainframe.theme.preview;
import com.fr.base.ScreenResolution;
import com.fr.base.Style;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.settings.ThemedCellStyle;
import com.fr.base.theme.settings.ThemedCellStyleList;
import com.fr.design.i18n.Toolkit;
import com.fr.log.FineLoggerFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2021/8/13
*/
public class ECPreviewPane extends JPanel implements ThemePreviewed<TemplateTheme> {
private static final List<String[]> DATA_LIST = createDataList();
private static final String BLANK_CHAR = " ";
private final List<List<Cell>> grid = new ArrayList<>();
private static List<String[]> createDataList() {
String csv =
"城市 当月目标 当月实际完成 月度完成率\n" +
"南通市 324,646 324,646 100%\n" +
"合肥市 248,938 348,938 140%\n" +
"邵阳市 248,938 348,938 140%\n" +
"合计 1,071,460 1,371,460 128%";
List<String[]> data = new ArrayList<>();
try(BufferedReader reader = new BufferedReader(new StringReader(csv))) {
String textLine;
while ((textLine = reader.readLine()) != null) {
String[] texts = textLine.split(BLANK_CHAR);
data.add(texts);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return data;
}
public ECPreviewPane() {
setOpaque(false);
setBackground(null);
GridBagLayout gridBagLayout = new GridBagLayout();
setLayout(gridBagLayout);
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
for (int i = 0; i < DATA_LIST.size(); i++) {
String[] textLine = DATA_LIST.get(i);
List<Cell> row = new ArrayList<>();
for (int j = 0; j < textLine.length ; j++) {
String text = textLine[j];
constraints.gridx = j;
constraints.gridy = i;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
Cell cell = new Cell(text);
cell.setPreferredSize(new Dimension(50, 20));
gridBagLayout.setConstraints(cell, constraints);
add(cell);
row.add(cell);
}
grid.add(row);
}
}
@Override
public void refresh(TemplateTheme theme) {
ThemedCellStyleList cellStyleConfig = theme.getCellStyleList();
for (int i = 0; i < grid.size(); i++) {
Style style = getMainContentStyle(cellStyleConfig);
if (i == 0) {
style = getReportHeaderStyle(cellStyleConfig);
}
if (i == DATA_LIST.size() - 1) {
style = getHighLightStyle(cellStyleConfig);
}
List<Cell> row = grid.get(i);
for (Cell cell : row) {
cell.refresh(style);
}
}
}
private Style getReportHeaderStyle(ThemedCellStyleList cellStyleList) {
return getCellStyle(cellStyleList, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header"));
}
private Style getMainContentStyle(ThemedCellStyleList cellStyleList) {
return getCellStyle(cellStyleList, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Main_Text"));
}
private Style getHighLightStyle(ThemedCellStyleList cellStyleList) {
return getCellStyle(cellStyleList, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text"));
}
private Style getCellStyle(ThemedCellStyleList cellStyleList, String styleName) {
ThemedCellStyle cellStyle = cellStyleList.find(styleName);
if (cellStyle == null) {
return Style.DEFAULT_STYLE;
}
return cellStyle.getStyle();
}
private static class Cell extends JComponent {
private Style style = Style.DEFAULT_STYLE;
private final String value;
public Cell(String value) {
this.value = value;
}
public void refresh(Style style) {
this.style = style;
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int resolution = ScreenResolution.getScreenResolution();
if (style == Style.DEFAULT_STYLE) {
Style.paintContent(g2d, value, style, getWidth() - 3, getHeight() - 3, resolution);
return;
}
Style.paintBackground(g2d, style, getWidth(), getHeight());
Style.paintContent(g2d, value, style, getWidth() - 3, getHeight() - 3, resolution);
Style.paintBorder(g2d, style, getWidth() , getHeight() );
}
@Override
public Dimension getMinimumSize() {
return new Dimension(125, 30);
}
}
}

87
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/FormThemePreviewPane.java

@ -1,13 +1,21 @@
package com.fr.design.mainframe.theme.preview;
import com.fr.base.background.ColorBackground;
import com.fr.base.theme.FormTheme;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.theme.TemplateThemePreviewPane;
import com.fr.design.mainframe.theme.preview.ecpreview.ECComponentPreviewPane;
import com.fr.design.utils.ComponentUtils;
import com.fr.general.Background;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
/**
* @author Starryi
@ -15,60 +23,49 @@ import java.awt.GridBagLayout;
* Created by Starryi on 2021/8/13
*/
public class FormThemePreviewPane extends TemplateThemePreviewPane<FormTheme> {
private final ECComponentPreviewPane elementCasePane;
private final ChartComponentPreviewPane chart1Pane;
private final ChartComponentPreviewPane chart2Pane;
private final ChartComponentPreviewPane chart3Pane;
private ECComponentPreviewPane elementCasePane;
private Background background;
private ComponentPreviewPane testPreviewPane;
public FormThemePreviewPane() {
setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel content = new UINoOpaquePanel();
content.setLayout(new BorderLayout());
content.add(elementCasePane = new ECComponentPreviewPane(), BorderLayout.SOUTH);
JPanel northPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane();
JPanel content = new JPanel();
GridBagLayout gridBagLayout = new GridBagLayout();
content.setLayout(gridBagLayout);
northPane.add(testPreviewPane = new ComponentPreviewPane(true) {
@Override
protected Component createContentPane() {
return new UINoOpaquePanel();
}
}, BorderLayout.CENTER);
content.add(northPane, BorderLayout.CENTER);
add(content, BorderLayout.CENTER);
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridheight = 1;
constraints.weighty = 1.0;
elementCasePane = new ECComponentPreviewPane();
gridBagLayout.setConstraints(elementCasePane, constraints);
content.add(elementCasePane, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
chart1Pane = new ChartComponentPreviewPane();
// add(chart1Pane, constraints);
constraints.gridx = 0;
constraints.gridy = 2;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
chart2Pane = new ChartComponentPreviewPane();
// add(chart2Pane, constraints);
constraints.gridx = 1;
constraints.gridy = 2;
constraints.gridwidth = 1;
constraints.gridheight = 1;
chart3Pane = new ChartComponentPreviewPane();
// add(chart3Pane, constraints);
}
@Override
public void refresh(FormTheme theme) {
background = theme.getBodyStyle().getStyle().getBackground();
elementCasePane.refresh(theme);
chart1Pane.refresh(theme);
chart2Pane.refresh(theme);
chart3Pane.refresh(theme);
testPreviewPane.refresh(theme);
repaint();
}
public void paint(Graphics g) {
// 禁止双缓冲
ArrayList<JComponent> dbcomponents = new ArrayList<JComponent>();
if (background == null) {
background = ColorBackground.getInstance(Color.WHITE);
}
background.paint(g, new Rectangle2D.Double(0, 0, 517, 532));
paintChildren(g);
// 恢复双缓冲
ComponentUtils.resetBuffer(dbcomponents);
}
}

39
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java

@ -1,7 +1,21 @@
package com.fr.design.mainframe.theme.preview;
import com.fr.base.background.ColorBackground;
import com.fr.base.theme.ReportTheme;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.theme.TemplateThemePreviewPane;
import com.fr.design.mainframe.theme.preview.ecpreview.ECComponentPreviewPane;
import com.fr.design.mainframe.theme.preview.ecpreview.ECReportPreviewPane;
import com.fr.design.utils.ComponentUtils;
import com.fr.general.Background;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
/**
* @author Starryi
@ -9,9 +23,34 @@ import com.fr.design.mainframe.theme.TemplateThemePreviewPane;
* Created by Starryi on 2021/8/13
*/
public class ReportThemePreviewPane extends TemplateThemePreviewPane<ReportTheme> {
private Background background;
private final ECReportPreviewPane reportPreviewPane;
public ReportThemePreviewPane(){
setLayout(FRGUIPaneFactory.createBorderLayout());
reportPreviewPane = new ECReportPreviewPane();
this.add(new UINoOpaquePanel(), BorderLayout.CENTER);
this.add(reportPreviewPane, BorderLayout.SOUTH);
}
@Override
public void refresh(ReportTheme theme) {
background = theme.getBodyStyle().getBackground();
reportPreviewPane.refresh(theme);
repaint();
}
public void paint(Graphics g) {
// 禁止双缓冲
ArrayList<JComponent> dbcomponents = new ArrayList<JComponent>();
if (background == null) {
background = ColorBackground.getInstance(Color.WHITE);
}
background.paint(g, new Rectangle2D.Double(0, 0, 517, 532));
paintChildren(g);
// 恢复双缓冲
ComponentUtils.resetBuffer(dbcomponents);
}
}

19
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/UINoOpaquePanel.java

@ -0,0 +1,19 @@
package com.fr.design.mainframe.theme.preview;
import javax.swing.JPanel;
import java.awt.LayoutManager;
public class UINoOpaquePanel extends JPanel {
public UINoOpaquePanel(){
super();
this.setOpaque(false);
this.setBackground(null);
}
public UINoOpaquePanel(LayoutManager layout) {
super(layout, true);
this.setOpaque(false);
this.setBackground(null);
}
}

47
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/AbstractECPreviewPane.java

@ -0,0 +1,47 @@
package com.fr.design.mainframe.theme.preview.ecpreview;
import com.fr.base.Style;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.settings.ThemedCellStyle;
import com.fr.base.theme.settings.ThemedCellStyleList;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.theme.preview.ThemePreviewed;
import com.fr.design.mainframe.theme.preview.UINoOpaquePanel;
import com.fr.design.mainframe.theme.preview.ecpreview.cell.AbstractPreviewCell;
import com.fr.design.mainframe.theme.preview.ecpreview.cell.PreviewCell;
import javax.swing.JPanel;
import java.util.List;
public abstract class AbstractECPreviewPane extends UINoOpaquePanel implements ThemePreviewed<TemplateTheme> {
protected Style getReportHeaderStyle(ThemedCellStyleList cellStyleList) {
return getCellStyle(cellStyleList, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Header"));
}
protected Style getMainContentStyle(ThemedCellStyleList cellStyleList) {
return getCellStyle(cellStyleList, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Main_Text"));
}
protected Style getHighLightStyle(ThemedCellStyleList cellStyleList) {
return getCellStyle(cellStyleList, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Highlight_Text"));
}
protected Style getSmallTitleStyle(ThemedCellStyleList cellStyleList) {
return getCellStyle(cellStyleList, Toolkit.i18nText("Fine-Design_Basic_Predefined_Style_Small_Title"));
}
private Style getCellStyle(ThemedCellStyleList cellStyleList, String styleName) {
ThemedCellStyle cellStyle = cellStyleList.find(styleName);
if (cellStyle == null) {
return Style.DEFAULT_STYLE;
}
return cellStyle.getStyle();
}
protected void refresh(List<AbstractPreviewCell> list, Style style) {
for (AbstractPreviewCell cell : list) {
cell.refresh(style);
}
}
}

3
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ECComponentPreviewPane.java → designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECComponentPreviewPane.java

@ -1,6 +1,7 @@
package com.fr.design.mainframe.theme.preview;
package com.fr.design.mainframe.theme.preview.ecpreview;
import com.fr.base.theme.FormTheme;
import com.fr.design.mainframe.theme.preview.ComponentPreviewPane;
import java.awt.Component;

104
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECPreviewPane.java

@ -0,0 +1,104 @@
package com.fr.design.mainframe.theme.preview.ecpreview;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.settings.ThemedCellStyleList;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.theme.preview.UINoOpaquePanel;
import com.fr.design.mainframe.theme.preview.ecpreview.cell.AbstractPreviewCell;
import com.fr.design.mainframe.theme.preview.ecpreview.cell.PreviewCell;
import com.fr.log.FineLoggerFactory;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2021/8/13
*/
public class ECPreviewPane extends AbstractECPreviewPane {
private static String csv =
"城市 当月目标 当月实际完成 月度完成率 全年完成率\n" +
"南通市 324,646 324,646 100% 100%\n" +
"合肥市 248,938 348,938 140% 140%\n" +
"邵阳市 248,938 348,938 140% 140%\n" +
"合计 1,071,460 1,371,460 128% 128%";
private final List<String[]> DATA_LIST = createDataList();
private static final String BLANK_CHAR = " ";
private List<AbstractPreviewCell> headerCellList = new ArrayList<>();
private List<AbstractPreviewCell> contentCellList = new ArrayList<>();
private List<AbstractPreviewCell> hightLightCellList = new ArrayList<>();
private List<String[]> createDataList() {
List<String[]> data = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new StringReader(csv))) {
String textLine;
while ((textLine = reader.readLine()) != null) {
String[] texts = textLine.split(BLANK_CHAR);
data.add(texts);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return data;
}
public ECPreviewPane() {
this.setPreferredSize(new Dimension(517, 170));
this.setBorder(BorderFactory.createEmptyBorder(0, 1, 2, 1));
this.setLayout(FRGUIPaneFactory.createBorderLayout());
String[] titleArr = DATA_LIST.get(0);
String[] endArr = DATA_LIST.get(DATA_LIST.size() - 1);
JPanel titlePane = new UINoOpaquePanel(new GridLayout());
this.add(titlePane, BorderLayout.NORTH);
for (String title : titleArr) {
PreviewCell cell = new PreviewCell(title);
cell.setPreferredSize(new Dimension(103, 36));
titlePane.add(cell);
headerCellList.add(cell);
}
JPanel contentPane = new UINoOpaquePanel(new GridLayout(3, 5, 0, 0));
this.add(contentPane, BorderLayout.CENTER);
for (int i = 1; i < DATA_LIST.size() - 1; i++) {
String[] textLine = DATA_LIST.get(i);
for (int j = 0; j < textLine.length; j++) {
String text = textLine[j];
PreviewCell cell = new PreviewCell(text);
cell.setPreferredSize(new Dimension(103, 33));
contentPane.add(cell);
contentCellList.add(cell);
}
}
JPanel endPane = new UINoOpaquePanel(new GridLayout());
this.add(endPane, BorderLayout.SOUTH);
for (String text : endArr) {
PreviewCell cell = new PreviewCell(text);
cell.setPreferredSize(new Dimension(103, 33));
endPane.add(cell);
hightLightCellList.add(cell);
}
}
@Override
public void refresh(TemplateTheme theme) {
ThemedCellStyleList cellStyleConfig = theme.getCellStyleList();
refresh(headerCellList, getReportHeaderStyle(cellStyleConfig));
refresh(contentCellList, getMainContentStyle(cellStyleConfig));
refresh(hightLightCellList, getHighLightStyle(cellStyleConfig));
}
}

126
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/ECReportPreviewPane.java

@ -0,0 +1,126 @@
package com.fr.design.mainframe.theme.preview.ecpreview;
import com.fr.base.theme.ReportTheme;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.settings.ThemedCellStyleList;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.theme.preview.ThemePreviewed;
import com.fr.design.mainframe.theme.preview.UINoOpaquePanel;
import com.fr.design.mainframe.theme.preview.ecpreview.cell.AbstractPreviewCell;
import com.fr.design.mainframe.theme.preview.ecpreview.cell.CornerPreviewCell;
import com.fr.design.mainframe.theme.preview.ecpreview.cell.PreviewCell;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
public class ECReportPreviewPane extends UINoOpaquePanel implements ThemePreviewed<ReportTheme> {
private List<AbstractPreviewCell> headerCellList = new ArrayList<>();
private List<AbstractPreviewCell> titleCellList = new ArrayList<>();
private List<AbstractPreviewCell> contentCellList = new ArrayList<>();
private List<AbstractPreviewCell> highLightCellList = new ArrayList<>();
private PreviewPane previewPane;
public ECReportPreviewPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
previewPane = new PreviewPane();
this.add(previewPane, BorderLayout.CENTER);
}
@Override
public void refresh(ReportTheme theme) {
previewPane.refresh(theme);
}
class PreviewPane extends AbstractECPreviewPane {
public PreviewPane() {
this.setPreferredSize(new Dimension(517, 270));
this.setBorder(BorderFactory.createEmptyBorder(7, 10, 5, 10));
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel northPane = createNorthPane();
JPanel centerPane = createCenterPane();
this.add(northPane, BorderLayout.NORTH);
this.add(centerPane, BorderLayout.CENTER);
}
private JPanel createNorthPane() {
JPanel northPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane();
CornerPreviewCell cornerCell = new CornerPreviewCell(new String[]{"产品", "数据", "统计维度"}, new Point2D[]{new Point(132, 75), new Point(189, 53)});
cornerCell.setPreferredSize(new Dimension(189, 75));
headerCellList.add(cornerCell);
northPane.add(cornerCell, BorderLayout.WEST);
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane();
northPane.add(centerPane, BorderLayout.CENTER);
PreviewCell cell = new PreviewCell("按地区统计");
titleCellList.add(cell);
cell.setPreferredSize(new Dimension(308, 38));
centerPane.add(cell, BorderLayout.NORTH);
JPanel eastSouthPane = new UINoOpaquePanel(new GridLayout());
PreviewCell cell1 = new PreviewCell("华东");
PreviewCell cell2 = new PreviewCell("华南");
PreviewCell cell3 = new PreviewCell("小计");
headerCellList.add(cell1);
headerCellList.add(cell2);
headerCellList.add(cell3);
eastSouthPane.add(cell1);
eastSouthPane.add(cell2);
eastSouthPane.add(cell3);
centerPane.add(eastSouthPane, BorderLayout.CENTER);
return northPane;
}
private JPanel createCenterPane() {
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane();
JPanel westPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane();
centerPane.add(westPane, BorderLayout.WEST);
PreviewCell cell1 = new PreviewCell("饮料");
titleCellList.add(cell1);
cell1.setPreferredSize(new Dimension(94, 183));
westPane.add(cell1, BorderLayout.WEST);
JPanel gridPane = new UINoOpaquePanel(new GridLayout(6, 1));
for (int i = 0; i < 6; i++) {
PreviewCell cell = new PreviewCell("苹果汁");
cell.setPreferredSize(new Dimension(95, 31));
headerCellList.add(cell);
gridPane.add(cell);
}
westPane.add(gridPane, BorderLayout.CENTER);
JPanel innerCenterPane = new UINoOpaquePanel(new GridLayout(6, 3));
centerPane.add(innerCenterPane, BorderLayout.CENTER);
for (int i = 0; i < 18; i++) {
PreviewCell cell = new PreviewCell("35600");
cell.setPreferredSize(new Dimension(102, 31));
if ((i + 1) % 3 == 0) {
highLightCellList.add(cell);
} else {
contentCellList.add(cell);
}
innerCenterPane.add(cell);
}
return centerPane;
}
@Override
public void refresh(TemplateTheme theme) {
ThemedCellStyleList cellStyleConfig = theme.getCellStyleList();
refresh(headerCellList, getReportHeaderStyle(cellStyleConfig));
refresh(contentCellList, getMainContentStyle(cellStyleConfig));
refresh(titleCellList, getSmallTitleStyle(cellStyleConfig));
refresh(highLightCellList, getHighLightStyle(cellStyleConfig));
}
}
}

32
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/AbstractPreviewCell.java

@ -0,0 +1,32 @@
package com.fr.design.mainframe.theme.preview.ecpreview.cell;
import com.fr.base.ScreenResolution;
import com.fr.base.Style;
import javax.swing.JComponent;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
public abstract class AbstractPreviewCell extends JComponent {
protected Style style = Style.DEFAULT_STYLE;
public void refresh(Style style) {
this.style = style;
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
int resolution = ScreenResolution.getScreenResolution();
Style.paintBackground(g2d, style, getWidth(), getHeight());
paintContent(g2d, resolution);
Style.paintBorder(g2d, style, getWidth(), getHeight());
}
protected abstract void paintContent(Graphics2D g2d, int resolution);
@Override
public Dimension getMinimumSize() {
return new Dimension(125, 30);
}
}

33
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/CornerPreviewCell.java

@ -0,0 +1,33 @@
package com.fr.design.mainframe.theme.preview.ecpreview.cell;
import com.fr.general.FRFont;
import com.fr.stable.GraphDrawHelper;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
public class CornerPreviewCell extends AbstractPreviewCell {
private final String[] values;
private final Point2D[] point2DS;
public CornerPreviewCell(String[] values, Point2D[] point2DS) {
this.values = values;
this.point2DS = point2DS;
}
@Override
protected void paintContent(Graphics2D g2d, int resolution) {
FRFont frFont = style.getFRFont();
g2d.setPaint(frFont.getForeground());
g2d.drawString(values[0], 23, 53);
GraphDrawHelper.drawRotatedString(g2d, values[1], 104, 50, 30);
g2d.drawString(values[2], 128, 23);
//画分割线
for (int i = 0; i < point2DS.length; i++) {
g2d.draw(new Line2D.Double(0, 0, point2DS[i].getX(), point2DS[i].getY())); //画线
}
}
}

25
designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ecpreview/cell/PreviewCell.java

@ -0,0 +1,25 @@
package com.fr.design.mainframe.theme.preview.ecpreview.cell;
import com.fr.base.Style;
import java.awt.Dimension;
import java.awt.Graphics2D;
public class PreviewCell extends AbstractPreviewCell {
private final String value;
public PreviewCell(String value) {
this.value = value;
}
@Override
protected void paintContent(Graphics2D g2d, int resolution) {
Style.paintContent(g2d, value, style, getWidth() - 3, getHeight() - 3, resolution);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(125, 30);
}
}

10
designer-base/src/main/java/com/fr/design/style/color/ColorCell.java

@ -76,17 +76,21 @@ public class ColorCell extends JComponent implements ColorSelectable {
g.fillRect(b.left, b.top, right, bottom);
}
if (colorSelectable.getColor() != null
&& ComparatorUtils.equals(colorSelectable.getColor(), this.getColor())) {
if (isColorSelected(colorSelectable)) {
g.setColor(UIConstants.LINE_COLOR);
g.drawRect(b.left, b.top, right - 1, bottom - 1);
}
}
protected boolean isColorSelected(ColorSelectable colorSelectable){
return colorSelectable.getColor() != null
&& ComparatorUtils.equals(colorSelectable.getColor(), this.getColor());
}
/**
* 鼠标事件处理
* @param 鼠标事件
* @param e 鼠标事件
*/
public void processMouseEvent(MouseEvent e) {
if (!isEnabled()) {

10
designer-base/src/main/java/com/fr/design/style/color/FineColorCell.java

@ -1,6 +1,7 @@
package com.fr.design.style.color;
import com.fr.base.FineColor;
import com.fr.general.ComparatorUtils;
import java.awt.Color;
@ -25,4 +26,13 @@ public class FineColorCell extends ColorCell {
}
protected boolean isColorSelected(ColorSelectable colorSelectable) {
Color color = colorSelectable.getColor();
if (color instanceof FineColor) {
return super.isColorSelected(colorSelectable) && (x == ((FineColor) color).getHor()) && (y == ((FineColor) color).getVer());
}
return super.isColorSelected(colorSelectable);
}
}

Loading…
Cancel
Save