Browse Source

CHART-11708 插入图表国际化

feature/big-screen
白岳 4 years ago
parent
commit
18cf8fc5ed
  1. 66
      designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java
  2. 89
      designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java
  3. 22
      designer-chart/src/main/java/com/fr/design/chart/ChartTypePane.java

66
designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java

@ -1,85 +1,29 @@
package com.fr.design.chart;
import com.fr.base.chart.BaseChartPainter;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.base.chart.result.WebChartIDInfo;
import com.fr.chart.chartattr.Chart;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.design.ChartTypeInterfaceManager;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.script.Calculator;
import javax.swing.Icon;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-05-29
*/
public class AutoChartIcon implements Icon {
public class AutoChartIcon extends ChartIcon {
private static final int WIDTH = 500;
private static final int HEIGHT = 281;
private ChartCollection chartCollection;
private CallbackEvent callbackEvent;
private String chartName;
public AutoChartIcon(ChartCollection chartCollection) {
this.chartCollection = chartCollection;
initChartName();
}
public ChartCollection getChartCollection() {
return chartCollection;
super(chartCollection);
}
public String getChartName() {
return chartName;
}
private void initChartName() {
Chart chart = chartCollection.getSelectedChart(Chart.class);
String[] subName = ChartTypeInterfaceManager.getInstance().getSubName(chart.getPlot().getPlotID());
chartName = subName[0];
}
public void registerCallBackEvent(CallbackEvent callbackEvent) {
this.callbackEvent = callbackEvent;
}
/**
* 画出缩略图Icon
*
* @param g 图形的上下文
* @param c 所在的Component
* @param x 缩略图的起始坐标x
* @param y 缩略图的起始坐标y
*/
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(),
protected BaseChartPainter getChartPainter() {
BaseChartPainter painter = getChartCollection().createResultChartPainterWithOutDealFormula(Calculator.createCalculator(),
WebChartIDInfo.createAutoTypeInfo(), getIconWidth(), getIconHeight());
int resolution = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getJTemplateResolution();
Graphics2D g2d = (Graphics2D) g;
Paint oldPaint = g2d.getPaint();
g.translate(x, y);
g2d.setPaint(Color.white);
g2d.fillRect(0, 0, getIconWidth(), getIconHeight());
painter.paint(g2d, getIconWidth(), getIconHeight(), resolution, null, callbackEvent);
g.translate(-x, -y);
g2d.setPaint(oldPaint);
return painter;
}
/**

89
designer-chart/src/main/java/com/fr/design/chart/ChartIcon.java

@ -1,8 +1,13 @@
package com.fr.design.chart;
import com.fr.base.GraphHelper;
import com.fr.general.IOUtils;
import com.fr.stable.Constants;
import com.fr.base.chart.BaseChartPainter;
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.base.chart.result.WebChartIDInfo;
import com.fr.chart.chartattr.Chart;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.design.ChartTypeInterfaceManager;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.script.Calculator;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLable;
import com.fr.stable.xml.XMLableReader;
@ -13,7 +18,6 @@ import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.image.BufferedImage;
/**
* 图表的缩略图Icon, 在选择图表类型界面 用到.
@ -21,21 +25,47 @@ import java.awt.image.BufferedImage;
public class ChartIcon implements Icon, XMLable {
private static final int WIDTH = 400;
private static final int HEIGHT = 225;
/**
* 缩略图中的图片路径
*/
private String imagePath;
private ChartCollection chartCollection;
private CallbackEvent callbackEvent;
private String chartName;
/**
* 构造Chart的缩略图Icon
*/
public ChartIcon(String imagePath, String chartName) {
this.imagePath = imagePath;
public ChartIcon(ChartCollection chartCollection) {
this.chartCollection = chartCollection;
initChartName();
}
public ChartCollection getChartCollection() {
return chartCollection;
}
public String getChartName() {
return chartName;
}
public void setChartCollection(ChartCollection chartCollection) {
this.chartCollection = chartCollection;
}
public void setChartName(String chartName) {
this.chartName = chartName;
}
private void initChartName() {
Chart chart = chartCollection.getSelectedChart(Chart.class);
String[] subName = ChartTypeInterfaceManager.getInstance().getSubName(chart.getPlot().getPlotID());
chartName = subName[0];
}
public void registerCallBackEvent(CallbackEvent callbackEvent) {
this.callbackEvent = callbackEvent;
}
/**
* 画出缩略图Icon
*
@ -47,21 +77,29 @@ public class ChartIcon implements Icon, XMLable {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2d = (Graphics2D) g;
BaseChartPainter chartPainter = getChartPainter();
Paint oldPaint = g2d.getPaint();
int resolution = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getJTemplateResolution();
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);
chartPainter.paint(g2d, getIconWidth(), getIconHeight(), resolution, null, callbackEvent);
g.translate(-x, -y);
g2d.setPaint(oldPaint);
}
protected BaseChartPainter getChartPainter() {
BaseChartPainter painter = chartCollection.createResultChartPainterWithOutDealFormula(Calculator.createCalculator(),
WebChartIDInfo.createEmptyDesignerInfo(), getIconWidth(), getIconHeight());
return painter;
}
/**
* 返回缩略图的宽度
*
@ -83,20 +121,6 @@ public class ChartIcon implements Icon, XMLable {
}
/**
* 返回缩略图中的图片路径
*
* @return 缩略图中的图片路径
*/
public String getImagePath() {
return imagePath;
}
public String getChartName() {
return chartName;
}
@Override
public void readXML(XMLableReader reader) {
//do nothing
@ -114,8 +138,11 @@ public class ChartIcon implements Icon, XMLable {
@Override
public Object clone() throws CloneNotSupportedException {
ChartIcon cloned = (ChartIcon) super.clone();
cloned.imagePath = this.imagePath;
cloned.chartName = this.chartName;
if (getChartCollection() != null) {
cloned.setChartCollection(this.getChartCollection());
}
cloned.setChartName(this.getChartName());
;
return cloned;
}

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

@ -3,6 +3,7 @@ package com.fr.design.chart;
* the Pane of the Chart
*/
import com.fr.base.chart.chartdata.CallbackEvent;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.charttypes.ChartTypeManager;
import com.fr.chartx.attr.ChartProvider;
@ -12,7 +13,6 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.chart.info.ChartInfoCollector;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
@ -26,7 +26,7 @@ import javax.swing.event.ListSelectionListener;
import java.awt.Color;
import java.awt.Component;
public class ChartTypePane extends ChartCommonWizardPane {
public class ChartTypePane extends ChartCommonWizardPane implements CallbackEvent {
private static final long serialVersionUID = -1175602484968520546L;
private String[] chartIDs = ChartTypeManager.getInstanceWithCheck().getAllChartIDs();
@ -96,14 +96,17 @@ public class ChartTypePane extends ChartCommonWizardPane {
int main_index = mainTypeList.getSelectedIndex();
String id = ChartTypePane.this.chartIDs[main_index];
String[] demoImagePath = ChartTypeInterfaceManager.getInstance().getDemoImagePath(id);
ChartProvider[] charts = ChartTypeManager.getInstance().getCharts(id);
String[] subName = ChartTypeInterfaceManager.getInstance().getSubName(id);
ChartTypePane.this.iconListModel.clear();
for (int i = 0, len = subName.length; i < len; i++) {
String ImagePath = demoImagePath.length > i ? demoImagePath[i] : StringUtils.EMPTY;
String chartName = subName[i];
ChartTypePane.this.iconListModel.addElement(new ChartIcon(ImagePath, chartName));
for (int i = 0, len = charts.length; i < len; i++) {
ChartProvider chart = charts[i];
ChartCollection chartCollection = new ChartCollection(chart);
ChartIcon chartIcon = new ChartIcon(chartCollection);
chartIcon.setChartName(subName[i]);
chartIcon.registerCallBackEvent(ChartTypePane.this);
ChartTypePane.this.iconListModel.addElement(chartIcon);
}
iconViewList.setSelectedIndex(0);
}
@ -144,4 +147,9 @@ public class ChartTypePane extends ChartCommonWizardPane {
update(chart4Update);
}
@Override
public void callback() {
this.repaint();
}
}
Loading…
Cancel
Save