From d5926c4328bf6335b4f32993e28373e41057f212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Fri, 23 Aug 2019 10:27:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?CHART-10247=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E9=80=89=E6=8B=A9=E7=95=8C=E9=9D=A2=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/design/chart/ChartTypePane.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java index 257fb8826e..046cd1960c 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java @@ -1,7 +1,6 @@ package com.fr.design.chart; /** * the Pane of the Chart - * */ import com.fr.chart.base.ChartInternationalNameContentBean; @@ -120,15 +119,16 @@ public class ChartTypePane extends ChartCommonWizardPane { ChartProvider[] sub_charts = ChartTypePane.this.charts4Icon[main_index]; ChartTypePane.this.iconListModel.clear(); for (int i = 0; i < sub_charts.length; i++) { - ChartTypePane.this.iconListModel.addElement(new ChartIcon(sub_charts[i])); + String ImagePath = sub_charts[i].demoImagePath(); + String chartName = sub_charts[i].getChartName(); + ChartTypePane.this.iconListModel.addElement(new ChartIcon(ImagePath, chartName)); } iconViewList.setSelectedIndex(0); } }; public String getChartName(ChartIcon chartIcon) { - ChartProvider chart = chartIcon.getChart(); - return ChartTypeManager.getInstanceWithCheck().getChartName(chart.getID()); + return chartIcon.getChartName(); } public void populate(ChartProvider chart) { @@ -146,10 +146,10 @@ public class ChartTypePane extends ChartCommonWizardPane { if (chart4Update == null) { String plotID = typeName[mainTypeList.getSelectedIndex()].getChartID(); ChartProvider chart = ChartTypeManager.getInstance().getChartTypes(plotID)[iconViewList.getSelectedIndex()]; - try{ + try { chart4Update = (ChartProvider) chart.clone(); cc.addChart(chart4Update); - }catch (CloneNotSupportedException ex){ + } catch (CloneNotSupportedException ex) { FineLoggerFactory.getLogger().error(ex.getMessage(), ex); } } From 924a8db115552f1aec84751c52515aa72f979c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Fri, 23 Aug 2019 11:14:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?CHART-10247=20ChartIcon=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0design?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/chart/ChartIcon.java | 116 ++++++++++++++++++ .../com/fr/design/chart/ChartTypePane.java | 1 - 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java b/designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java new file mode 100644 index 0000000000..7485d57973 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java @@ -0,0 +1,116 @@ +package com.fr.design.chart; + +import com.fr.base.GraphHelper; +import com.fr.general.IOUtils; +import com.fr.stable.Constants; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLable; +import com.fr.stable.xml.XMLableReader; + +import javax.swing.Icon; +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Paint; +import java.awt.image.BufferedImage; + +/** + * 图表的缩略图Icon, 在选择图表类型界面 用到. + */ +public class ChartIcon implements Icon, XMLable { + private static final int WIDTH = 400; + private static final int HEIGHT = 225; + /** + * 缩略图中的图片路径 + */ + private String imagePath; + + private String chartName; + + /** + * 构造Chart的缩略图Icon + */ + public ChartIcon(String imagePath, String chartName) { + this.imagePath = imagePath; + this.chartName = chartName; + } + + /** + * 画出缩略图Icon + * + * @param g 图形的上下文 + * @param c 所在的Component + * @param x 缩略图的起始坐标x + * @param y 缩略图的起始坐标y + */ + public void paintIcon(Component c, Graphics g, int x, int y) { + + Graphics2D g2d = (Graphics2D) g; + + Paint oldPaint = g2d.getPaint(); + + g.translate(x, y); + g2d.setPaint(Color.white); + + g2d.fillRect(0, 0, getIconWidth(), getIconHeight()); + BufferedImage demoImage = IOUtils.readImageWithCache(imagePath); + GraphHelper.paintImage(g, getIconWidth(), getIconHeight(), demoImage, Constants.IMAGE_ADJUST, Constants.NULL, Constants.NULL, -1, -1); + + g.translate(-x, -y); + g2d.setPaint(oldPaint); + } + + /** + * 返回缩略图的宽度 + * + * @return int 缩略图宽度 + */ + public int getIconWidth() { + return WIDTH; + } + + /** + * 返回缩略图的高度 + * + * @return int 缩略图高度 + */ + public int getIconHeight() { + return HEIGHT; + } + + + /** + * 返回缩略图中的图片路径 + * + * @return 缩略图中的图片路径 + */ + public String getImagePath() { + return imagePath; + } + + public String getChartName() { + return chartName; + } + + + public void readXML(XMLableReader reader) { + + } + + public void writeXML(XMLPrintWriter writer) { + + } + + /** + * @return 克隆后的对象 + * @throws CloneNotSupportedException 如果克隆失败则抛出此异常 + */ + public Object clone() throws CloneNotSupportedException { + ChartIcon cloned = (ChartIcon) super.clone(); + cloned.imagePath = this.imagePath; + cloned.chartName = this.chartName; + return cloned; + } + +} \ No newline at end of file diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java index 046cd1960c..599a70915f 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java @@ -5,7 +5,6 @@ package com.fr.design.chart; import com.fr.chart.base.ChartInternationalNameContentBean; import com.fr.chart.chartattr.ChartCollection; -import com.fr.chart.chartattr.ChartIcon; import com.fr.chart.charttypes.ChartTypeManager; import com.fr.chartx.attr.ChartProvider; import com.fr.design.gui.ilable.UILabel;