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 3c274a82f..aaf4dc833 100644 --- a/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java +++ b/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java @@ -5,7 +5,6 @@ import com.fr.base.ScreenResolution; import com.fr.base.chart.BaseChart; import com.fr.base.chart.BaseChartCollection; import com.fr.base.chart.BaseChartGlyph; -import com.fr.base.chart.chartdata.ChartDataEvent; import com.fr.chart.base.ChartConstants; import com.fr.chart.chartattr.Axis; import com.fr.chart.chartattr.Chart; @@ -32,7 +31,7 @@ import java.util.List; * 类说明: 事件说明: 工具栏编辑--> 是刷新ChartComponent 然后响应整个设计块的改变事件 右键编辑 ---> 刷新ChartCompment 刷新对应的工具栏(加入事件) 然后响应整个设计块的改变事件 */ -public class ChartComponent extends MiddleChartComponent implements MouseListener, MouseMotionListener, ChartDataEvent { +public class ChartComponent extends MiddleChartComponent implements MouseListener, MouseMotionListener{ private static final long serialVersionUID = 744164838619052097L; private final List listeners = new ArrayList(); private ChartCollection chartCollection4Design; @@ -46,6 +45,8 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene private boolean supportEdit = true; + private ChartGlyphDrawEvent glyphDrawEvent = null; + private final int[] resizeCursors = new int[]{ Cursor.NW_RESIZE_CURSOR, Cursor.N_RESIZE_CURSOR, Cursor.NE_RESIZE_CURSOR, Cursor.E_RESIZE_CURSOR, Cursor.W_RESIZE_CURSOR, @@ -182,8 +183,9 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene // 反锯齿 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - drawChartGlyph(g2d); - + //画图 + drawImage(g2d); + ActiveGlyph ag = this.getActiveGlyph(); if (ag != null) { ag.paint4ActiveGlyph(g2d, chartGlyph); @@ -197,6 +199,13 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, lastHint); } + /** + * 事件结束后,释放事件 + */ + public void deleteDrawEvent(){ + glyphDrawEvent = null; + } + /* * ChartGlyph改变大小的时候做的操作 */ @@ -205,6 +214,7 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene this.editingChart = this.chartCollection4Design.getSelectedChart();// kunsnat: 切换选中时 同步切换Plot if (editingChart != null) { this.chartGlyph = editingChart.createGlyph(editingChart.defaultChartData()); + //注册ChartData监听器 this.activeGlyph = ActiveGlyphFactory.createActiveGlyph(this, chartGlyph); } this.chartWidth = d.width - ChartConstants.PREGAP4BOUNDS; @@ -303,7 +313,16 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene return chartGlyph == null || chartWidth != this.getBounds().width || chartHeight != this.getBounds().height; } - private void drawChartGlyph(Graphics2D g2d) { + private void drawImage(Graphics2D g2d){ + //画图事件处理 + glyphDrawEvent = new ChartGlyphDrawEvent(this, g2d); + //注册事件执行者 + chartGlyph.addChartDataEvent(glyphDrawEvent); + //处理画图事件 + glyphDrawEvent.run(); + } + + public void drawChartGlyph(Graphics2D g2d) { if (chartGlyph != null) { if (chartGlyph.isRoundBorder()) { chartGlyph.setBounds(new RoundRectangle2D.Double(0, 0, chartWidth, chartHeight, 10, 10)); @@ -313,21 +332,8 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene // chartGlyph.draw(g2d, ScreenResolution.getScreenResolution()); //不直接画chartGlyph而画image的原因是表单的柱形图会溢出表单 //其他图都ok,其实感觉应该是柱形图画的不对,应该也可以改那边 - //注册获取图片后续事件 - registerChartDataEvent(chartGlyph); Image chartImage = chartGlyph.toImage(chartWidth,chartHeight,ScreenResolution.getScreenResolution()); g2d.drawImage(chartImage, 0, 0, null); } } - - - @Override - public void registerChartDataEvent(BaseChartGlyph glyph) { - glyph.addChartDataEvent(this); - } - - @Override - public void callback() { - this.repaint(); - } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/chart/gui/ChartGlyphDrawEvent.java b/designer_chart/src/com/fr/design/chart/gui/ChartGlyphDrawEvent.java new file mode 100644 index 000000000..c6acf9cf8 --- /dev/null +++ b/designer_chart/src/com/fr/design/chart/gui/ChartGlyphDrawEvent.java @@ -0,0 +1,31 @@ +package com.fr.design.chart.gui; +import com.fr.base.chart.chartdata.CallbackEvent; + +import java.awt.*; + +/** + * Created by hufan on 2016/10/18. + */ +public class ChartGlyphDrawEvent implements CallbackEvent { + private ChartComponent painter; + private Graphics2D g2d; + + public ChartGlyphDrawEvent() { + } + + public ChartGlyphDrawEvent(ChartComponent painter, Graphics2D g2d) { + this.painter = painter; + this.g2d = g2d; + } + + @Override + public void run() { + painter.drawChartGlyph(g2d); + } + + @Override + public void callback() { + painter.repaint(); + painter.deleteDrawEvent(); + } +}