From cd765589c6cc483d0ee8043b98384e2f9bc5a8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Mon, 23 Aug 2021 11:24:26 +0800 Subject: [PATCH] =?UTF-8?q?CHART-20117=20=E4=B8=BB=E9=A2=98=E9=85=8D?= =?UTF-8?q?=E8=89=B2=E7=95=8C=E9=9D=A2=E5=9B=BE=E8=A1=A8=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/TemplateThemeProfilePane.java | 14 +- .../edit/chart/ChartSeriesStylePane.java | 3 + .../preview/ChartComponentPreviewPane.java | 8 + .../theme/preview/ChartPreviewPane.java | 47 +++++- .../theme/preview/FormThemePreviewPane.java | 157 ++++++++++++++++-- .../theme/preview/ReportThemePreviewPane.java | 87 +++++++++- 6 files changed, 289 insertions(+), 27 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java index d7fb8e2cbd..edbe231515 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeProfilePane.java @@ -1,13 +1,11 @@ package com.fr.design.mainframe.theme; -import com.fr.base.Style; -import com.fr.base.background.ColorBackground; import com.fr.base.theme.FineColorManager; import com.fr.base.theme.TemplateTheme; import com.fr.base.theme.TemplateThemeConfig; import com.fr.base.theme.settings.ThemeThumbnail; -import com.fr.base.theme.settings.ThemedCellStyle; import com.fr.base.theme.settings.ThemedCellStyleList; +import com.fr.base.theme.settings.ThemedChartStyle; import com.fr.base.theme.settings.ThemedColorScheme; import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; import com.fr.design.gui.frpane.AttributeChangeListener; @@ -15,7 +13,6 @@ import com.fr.design.gui.frpane.UITabbedPane; 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.syntax.ui.rsyntaxtextarea.Theme; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; @@ -28,7 +25,6 @@ import com.fr.design.mainframe.theme.edit.ui.ColorListPane; import com.fr.design.mainframe.theme.edit.ui.LabelUtils; import com.fr.design.mainframe.theme.ui.BorderUtils; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.FRFont; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; @@ -40,6 +36,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import java.util.List; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -52,7 +49,6 @@ import java.awt.event.FocusEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; -import java.util.List; /** * @author Starryi @@ -304,9 +300,13 @@ public abstract class TemplateThemeProfilePane extends public void onColorSchemeChanged(List colors) { colorListExtendedPane.populate(colors); + FineColorManager.FineColorReplaceByColorScheme replaceByColorScheme = new FineColorManager.FineColorReplaceByColorScheme(colors); ThemedCellStyleList cellStyle = cellStyleSettingPane.updateBean(); - FineColorManager.traverse(cellStyle, new FineColorManager.FineColorReplaceByColorScheme(colors)); + FineColorManager.traverse(cellStyle, replaceByColorScheme); + ThemedChartStyle themedChartStyle = chartStyleSettingPane.updateBean(); + FineColorManager.traverse(themedChartStyle, replaceByColorScheme); + chartStyleSettingPane.populateBean(themedChartStyle); chartStyleSettingPane.populateGradientBar(colors); } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartSeriesStylePane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartSeriesStylePane.java index b1e944531f..c451117bd2 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartSeriesStylePane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/edit/chart/ChartSeriesStylePane.java @@ -4,6 +4,7 @@ import com.fr.base.theme.settings.ThemedChartStyle; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.theme.dialog.TemplateThemeProfileDialog; import com.fr.design.style.background.gradient.FixedGradientBarWithPopMenu; import java.util.List; @@ -63,7 +64,9 @@ public class ChartSeriesStylePane extends AbstractChartStylePane { public void populate(ThemedChartStyle chartStyle) { if (chartStyle.getThemedChartSeriesColor().isCombineColor()) { + List editingColorScheme = TemplateThemeProfileDialog.getEditingColorScheme(); colorTypeButton.setSelectedIndex(0); + gradientBar.updateColor(editingColorScheme.get(0), editingColorScheme.get(1)); } else { colorTypeButton.setSelectedIndex(1); gradientBar.updateColor(chartStyle.getThemedChartSeriesColor().getBeginColor(), chartStyle.getThemedChartSeriesColor().getEndColor()); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartComponentPreviewPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartComponentPreviewPane.java index 60283148de..261804b4b5 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartComponentPreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartComponentPreviewPane.java @@ -12,6 +12,10 @@ import java.awt.Component; public class ChartComponentPreviewPane extends ComponentPreviewPane implements ThemePreviewed { private ChartPreviewPane contentPane; + public ChartComponentPreviewPane(boolean showTitle) { + super(showTitle); + } + @Override protected Component createContentPane() { contentPane = new ChartPreviewPane(); @@ -23,4 +27,8 @@ public class ChartComponentPreviewPane extends ComponentPreviewPane implements T super.refresh(theme); contentPane.refresh(theme); } + + public ChartPreviewPane getContentPane() { + return contentPane; + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartPreviewPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartPreviewPane.java index e9945cddca..2029539aa8 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartPreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ChartPreviewPane.java @@ -1,10 +1,21 @@ package com.fr.design.mainframe.theme.preview; import com.fr.base.chart.BaseChartCollection; +import com.fr.base.chart.BaseChartPainter; +import com.fr.base.chart.chartdata.CallbackEvent; +import com.fr.base.chart.result.WebChartIDInfo; import com.fr.base.theme.TemplateTheme; +import com.fr.base.theme.TemplateThemeCompatible; +import com.fr.chart.chartattr.ChartCollection; import com.fr.design.gui.chart.MiddleChartComponent; +import com.fr.script.Calculator; import com.fr.stable.core.PropertyChangeListener; +import javax.swing.BorderFactory; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; + /** * @author Starryi * @version 1.0 @@ -12,14 +23,44 @@ import com.fr.stable.core.PropertyChangeListener; */ public class ChartPreviewPane extends MiddleChartComponent implements ThemePreviewed { + private ChartCollection chartCollection; + + private CallbackEvent callbackEvent; + + public ChartPreviewPane() { + this.setBorder(BorderFactory.createEmptyBorder(0, 1, 2, 1)); + } + + public void setCallbackEvent(CallbackEvent callbackEvent) { + this.callbackEvent = callbackEvent; + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + super.paintComponent(g); + if (chartCollection != null) { + drawChart(g2d); + } + drawChart(g2d); + } + + private void drawChart(Graphics2D g2d) { + Dimension d = getBounds().getSize(); + int chartWidth = d.width; + int chartHeight = d.height; + BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(), + WebChartIDInfo.createEmptyDesignerInfo(), chartWidth, chartHeight); + painter.paint(g2d, chartWidth, chartHeight, 0, null, callbackEvent); + } + @Override public void populate(BaseChartCollection cc) { - + this.chartCollection = (ChartCollection) cc; } @Override public BaseChartCollection update() { - return null; + return this.chartCollection; } @Override @@ -34,6 +75,6 @@ public class ChartPreviewPane extends MiddleChartComponent implements ThemePrevi @Override public void refresh(TemplateTheme style) { - + chartCollection.onTemplateUsingThemeChange(style, TemplateThemeCompatible.NONE); } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/FormThemePreviewPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/FormThemePreviewPane.java index e37d35c583..bca48fac73 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/FormThemePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/FormThemePreviewPane.java @@ -1,21 +1,38 @@ package com.fr.design.mainframe.theme.preview; +import com.fr.base.BaseFormula; import com.fr.base.background.ColorBackground; import com.fr.base.theme.FormTheme; +import com.fr.chart.base.ChartConstants; +import com.fr.chart.chartattr.ChartCollection; +import com.fr.chart.chartattr.Title; +import com.fr.chart.chartdata.NormalChartData; +import com.fr.chart.charttypes.ChartTypeManager; +import com.fr.design.i18n.Toolkit; 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 com.fr.log.FineLoggerFactory; +import com.fr.plugin.chart.PiePlot4VanChart; +import com.fr.plugin.chart.attr.axis.VanChartAxis; +import com.fr.plugin.chart.base.AttrLabel; +import com.fr.plugin.chart.base.VanChartTools; +import com.fr.plugin.chart.column.VanChartColumnPlot; +import com.fr.plugin.chart.type.RadiusType; +import com.fr.plugin.chart.vanchart.VanChart; +import com.fr.stable.Constants; +import com.fr.stable.StringUtils; import javax.swing.JComponent; import javax.swing.JPanel; +import java.util.ArrayList; import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; +import java.awt.Dimension; import java.awt.Graphics; import java.awt.geom.Rectangle2D; -import java.util.ArrayList; /** * @author Starryi @@ -23,33 +40,58 @@ import java.util.ArrayList; * Created by Starryi on 2021/8/13 */ public class FormThemePreviewPane extends TemplateThemePreviewPane { - private ECComponentPreviewPane elementCasePane; + private ECComponentPreviewPane elementCasePane; private Background background; - private ComponentPreviewPane testPreviewPane; + private ChartComponentPreviewPane columnChartPreviewPane; + private ChartComponentPreviewPane pieChartPreviewPane; public FormThemePreviewPane() { setLayout(FRGUIPaneFactory.createBorderLayout()); JPanel content = new UINoOpaquePanel(); content.setLayout(new BorderLayout()); + content.add(createChartContent(), BorderLayout.CENTER); content.add(elementCasePane = new ECComponentPreviewPane(), BorderLayout.SOUTH); - JPanel northPane = FRGUIPaneFactory.createBorderLayout_NO_Opaque_Pane(); + add(content, BorderLayout.CENTER); + } - northPane.add(testPreviewPane = new ComponentPreviewPane(true) { - @Override - protected Component createContentPane() { - return new UINoOpaquePanel(); + private JPanel createChartContent() { + JPanel chartContent = new UINoOpaquePanel(); + chartContent.setLayout(new BorderLayout()); + JPanel columnChartPanel = new UINoOpaquePanel() { + public Dimension getPreferredSize() { + return new Dimension(300, 368); } - }, BorderLayout.CENTER); - content.add(northPane, BorderLayout.CENTER); + }; + columnChartPanel.setLayout(new BorderLayout()); + columnChartPreviewPane = createChartPreviewPane(initColumnChart(), 300, 368); + columnChartPanel.add(columnChartPreviewPane, BorderLayout.CENTER); - add(content, BorderLayout.CENTER); + JPanel pieChartPanel = new UINoOpaquePanel() { + public Dimension getPreferredSize() { + return new Dimension(217, 368); + } + }; + pieChartPanel.setLayout(new BorderLayout()); + pieChartPreviewPane = createChartPreviewPane(initPieChart(), 300, 368); + pieChartPanel.add(pieChartPreviewPane, BorderLayout.CENTER); + chartContent.add(columnChartPanel, BorderLayout.WEST); + chartContent.add(pieChartPanel, BorderLayout.EAST); + return chartContent; + } + + private ChartComponentPreviewPane createChartPreviewPane(ChartCollection chartCollection, int width, int height) { + ChartComponentPreviewPane chartComponentPreviewPane = new ChartComponentPreviewPane(true); + chartComponentPreviewPane.getContentPane().populate(chartCollection); + chartComponentPreviewPane.getContentPane().setCallbackEvent(this); + return chartComponentPreviewPane; } @Override public void refresh(FormTheme theme) { background = theme.getBodyStyle().getStyle().getBackground(); elementCasePane.refresh(theme); - testPreviewPane.refresh(theme); + columnChartPreviewPane.refresh(theme); + pieChartPreviewPane.refresh(theme); repaint(); } @@ -68,4 +110,93 @@ public class FormThemePreviewPane extends TemplateThemePreviewPane { } + //柱形图 + private ChartCollection initColumnChart() { + try { + VanChart chart = (VanChart) ChartTypeManager.getInstance().getCharts(VanChartColumnPlot.VAN_CHART_COLUMN_PLOT_ID)[0].clone(); + chart.getTitle().setTitleVisible(false); + VanChartTools vanChartTools = chart.getVanChartTools(); + vanChartTools.setSort(false); + vanChartTools.setExport(false); + vanChartTools.setFullScreen(false); + + VanChartColumnPlot plot = chart.getPlot(); + AttrLabel defaultAttrLabel = plot.getDefaultAttrLabel(); + defaultAttrLabel.setEnable(true); + defaultAttrLabel.getAttrLabelDetail().getBorder().setBorderStyle(0); + defaultAttrLabel.getAttrLabelDetail().getBackground().setBackground(null); + plot.getConditionCollection().getDefaultAttr().addDataSeriesCondition(defaultAttrLabel); + + plot.getLegend().setPosition(Constants.TOP); + plot.setPlotStyle(ChartConstants.STYLE_NONE); + plot.setSeriesOverlapPercent(30); + plot.setCategoryIntervalPercent(30); + + VanChartAxis defaultYAxis = plot.getDefaultYAxis(); + Title title = new Title(); + title.setTextObject(Toolkit.i18nText("Fine-Design_Chart_Axis_Title")); + title.getTextAttr().setRotation(-90); + title.getTextAttr().setThemed(true); + defaultYAxis.setTitle(title); + defaultYAxis.setShowAxisTitle(true); + defaultYAxis.setCustomMaxValue(true); + defaultYAxis.setCustomMinValue(true); + defaultYAxis.setCustomMainUnit(true); + defaultYAxis.setMaxValue(BaseFormula.createFormulaBuilder().build("=600")); + defaultYAxis.setMinValue(BaseFormula.createFormulaBuilder().build("=0")); + defaultYAxis.setMainUnit(BaseFormula.createFormulaBuilder().build("=200")); + + Object[] category = { + Toolkit.i18nText("Fine-Design_Chart_Category") + "1", + Toolkit.i18nText("Fine-Design_Chart_Category") + "2", + Toolkit.i18nText("Fine-Design_Chart_Category") + "3", + Toolkit.i18nText("Fine-Design_Chart_Category") + "4" + }; + Object[] series = { + Toolkit.i18nText("Fine-Design_Chart_Series") + "1", + Toolkit.i18nText("Fine-Design_Chart_Series") + "2" + }; + Object[][] value = { + {"250", "540", "300", "410"}, + {"180", "190", "170", "100"}, + }; + NormalChartData normalChartData = new NormalChartData(category, series, value); + chart.setPreViewChartData(normalChartData); + ChartCollection chartCollection = new ChartCollection(chart); + return chartCollection; + } catch (Exception ex) { + FineLoggerFactory.getLogger().error(ex.getMessage(), ex); + } + return null; + } + + //饼图 + private ChartCollection initPieChart() { + try { + VanChart chart = (VanChart) ChartTypeManager.getInstance().getCharts(PiePlot4VanChart.VAN_CHART_PIE_PLOT)[0].clone(); + chart.getTitle().setTitleVisible(false); + VanChartTools vanChartTools = chart.getVanChartTools(); + vanChartTools.setSort(false); + vanChartTools.setExport(false); + vanChartTools.setFullScreen(false); + + PiePlot4VanChart plot = chart.getPlot(); + plot.getLegend().setPosition(Constants.BOTTOM); + plot.setPlotStyle(ChartConstants.STYLE_NONE); + plot.setInnerRadiusPercent(75); + plot.getRadius().setRadiusType(RadiusType.FIXED); + plot.getRadius().setRadius(80); + + Object[] category = {StringUtils.EMPTY}; + Object[] series = {"A1", "B1", "C1", "D1", "E1", "F1", "G1", "H1"}; + Object[][] value = {{45}, {24}, {12}, {8}, {5}, {3}, {2}, {1},}; + NormalChartData normalChartData = new NormalChartData(category, series, value); + chart.setPreViewChartData(normalChartData); + ChartCollection chartCollection = new ChartCollection(chart); + return chartCollection; + } catch (Exception ex) { + FineLoggerFactory.getLogger().error(ex.getMessage(), ex); + } + return null; + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java index 2994e3b889..71aad36eca 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/preview/ReportThemePreviewPane.java @@ -1,21 +1,32 @@ package com.fr.design.mainframe.theme.preview; +import com.fr.base.BaseFormula; import com.fr.base.background.ColorBackground; import com.fr.base.theme.ReportTheme; +import com.fr.chart.base.ChartConstants; +import com.fr.chart.chartattr.ChartCollection; +import com.fr.chart.chartattr.Title; +import com.fr.chart.chartdata.NormalChartData; +import com.fr.chart.charttypes.ChartTypeManager; +import com.fr.design.i18n.Toolkit; 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 com.fr.log.FineLoggerFactory; +import com.fr.plugin.chart.attr.axis.VanChartAxis; +import com.fr.plugin.chart.base.AttrLabel; +import com.fr.plugin.chart.base.VanChartTools; +import com.fr.plugin.chart.column.VanChartColumnPlot; +import com.fr.plugin.chart.vanchart.VanChart; import javax.swing.JComponent; -import javax.swing.JPanel; +import java.util.ArrayList; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; import java.awt.geom.Rectangle2D; -import java.util.ArrayList; /** * @author Starryi @@ -26,10 +37,16 @@ public class ReportThemePreviewPane extends TemplateThemePreviewPane