Browse Source

Merge pull request #1041 in DESIGN/design from ~BJORN/design:feature/10.0 to feature/10.0

* commit '924a8db115552f1aec84751c52515aa72f979c45':
  CHART-10247 ChartIcon移动到design
  CHART-10247 设计器图表选择界面图片预览
research/11.0
eason 5 years ago
parent
commit
b62e7ab441
  1. 116
      designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java
  2. 13
      designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java

116
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;
}
}

13
designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java

@ -1,12 +1,10 @@
package com.fr.design.chart;
/**
* the Pane of the 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;
@ -120,15 +118,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 +145,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);
}
}

Loading…
Cancel
Save