From ec1201808f7a42e167cca38439c1ebb4ece9c409 Mon Sep 17 00:00:00 2001 From: Fangjie Hu Date: Tue, 18 Oct 2016 17:37:00 +0800 Subject: [PATCH] update --- .../fr/design/chart/gui/ChartComponent.java | 4 +- .../chartimage/ChartGlyphToImageEvent.java | 43 +++++++++++++++++++ .../chartimage/ChartGlyphToImageManager.java | 23 ++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageEvent.java create mode 100644 designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageManager.java diff --git a/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java b/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java index be31c1c38..69129ab7c 100644 --- a/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java +++ b/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java @@ -10,7 +10,7 @@ import com.fr.chart.chartattr.Axis; import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartglyph.AxisGlyph; -import com.fr.chart.chartimage.ChartGlyphToImageManager; +import com.fr.design.chart.gui.chartimage.ChartGlyphToImageManager; import com.fr.design.chart.gui.active.ActiveGlyph; import com.fr.design.chart.gui.active.ChartActiveGlyph; import com.fr.design.gui.chart.MiddleChartComponent; @@ -315,7 +315,7 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene //不直接画chartGlyph而画image的原因是表单的柱形图会溢出表单 //其他图都ok,其实感觉应该是柱形图画的不对,应该也可以改那边 //处理画图事件 - Image chartImage = ChartGlyphToImageManager.toImage(g2d, chartGlyph, chartWidth, chartHeight, ScreenResolution.getScreenResolution()); + Image chartImage = ChartGlyphToImageManager.toImage(this, chartGlyph, chartWidth, chartHeight, ScreenResolution.getScreenResolution()); //Image chartImage = chartGlyph.toImage(chartWidth,chartHeight,ScreenResolution.getScreenResolution()); g2d.drawImage(chartImage, 0, 0, null); } diff --git a/designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageEvent.java b/designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageEvent.java new file mode 100644 index 000000000..01eb49a19 --- /dev/null +++ b/designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageEvent.java @@ -0,0 +1,43 @@ +package com.fr.design.chart.gui.chartimage; +import com.fr.base.chart.BaseChartGlyph; +import com.fr.base.chart.chartdata.CallbackEvent; + +import java.awt.*; + +/** + * Created by hufan on 2016/10/18. + */ +public class ChartGlyphToImageEvent implements CallbackEvent { + private Component painter; + private BaseChartGlyph glyph; + private int width; + private int height; + private int resolution; + + private Image image; + + public ChartGlyphToImageEvent() { + } + + public ChartGlyphToImageEvent(Component painter) { + this.painter = painter; + } + + public ChartGlyphToImageEvent setImageArgs(BaseChartGlyph glyph, int width, int height, int resolution){ + this.glyph = glyph; + this.width = width; + this.height = height; + this.resolution = resolution; + return this; + } + + public Image run() { + glyph.addChartDataEvent(this); + this.image = glyph.toImage(width, height, resolution); + return image; + } + + public void callback() { + painter.repaint(); + } +} diff --git a/designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageManager.java b/designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageManager.java new file mode 100644 index 000000000..464d345dc --- /dev/null +++ b/designer_chart/src/com/fr/design/chart/gui/chartimage/ChartGlyphToImageManager.java @@ -0,0 +1,23 @@ +package com.fr.design.chart.gui.chartimage; + +import com.fr.base.chart.BaseChartGlyph; + +import java.awt.*; + +/** + * Created by hufan on 2016/10/18. + */ +public class ChartGlyphToImageManager { + private static ChartGlyphToImageManager toImageManager = new ChartGlyphToImageManager(); + + public static Image toImage(Component listener, BaseChartGlyph glyph, int width, int height, int resolution){ + //初始化新的图片处理 + ChartGlyphToImageEvent imageEvent = toImageManager.initImageEvent(listener); + //获取图片 + return imageEvent.setImageArgs(glyph, width, height, resolution).run(); + } + + private ChartGlyphToImageEvent initImageEvent(Component listener){ + return new ChartGlyphToImageEvent(listener); + } +}