vito
3 years ago
5 changed files with 255 additions and 83 deletions
@ -1,77 +0,0 @@ |
|||||||
package com.fr.design.ui.util; |
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull; |
|
||||||
|
|
||||||
import java.awt.*; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* 图形渲染配置 |
|
||||||
* |
|
||||||
* @author vito |
|
||||||
* @version 10.0 |
|
||||||
* Created by vito on 2019/9/18 |
|
||||||
*/ |
|
||||||
public class GraphicsConfig { |
|
||||||
private final Graphics2D myG; |
|
||||||
private final Map myHints; |
|
||||||
private final Composite myComposite; |
|
||||||
private final Stroke myStroke; |
|
||||||
|
|
||||||
public GraphicsConfig(@NotNull Graphics g) { |
|
||||||
myG = (Graphics2D) g; |
|
||||||
myHints = (Map) myG.getRenderingHints().clone(); |
|
||||||
myComposite = myG.getComposite(); |
|
||||||
myStroke = myG.getStroke(); |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig setAntialiasing(boolean on) { |
|
||||||
myG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, on ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig setAlpha(float alpha) { |
|
||||||
myG.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig setRenderingHint(RenderingHints.Key hintKey, Object hintValue) { |
|
||||||
myG.setRenderingHint(hintKey, hintValue); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public Graphics2D getG() { |
|
||||||
return myG; |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig setComposite(Composite composite) { |
|
||||||
myG.setComposite(composite); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig setStroke(Stroke stroke) { |
|
||||||
myG.setStroke(stroke); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig setupAAPainting() { |
|
||||||
return setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) |
|
||||||
.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig disableAAPainting() { |
|
||||||
return setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF) |
|
||||||
.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); |
|
||||||
} |
|
||||||
|
|
||||||
public GraphicsConfig paintWithAlpha(float alpha) { |
|
||||||
assert 0.0f <= alpha && alpha <= 1.0f : "alpha should be in range 0.0f .. 1.0f"; |
|
||||||
return setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); |
|
||||||
} |
|
||||||
|
|
||||||
public void restore() { |
|
||||||
myG.setRenderingHints(myHints); |
|
||||||
myG.setComposite(myComposite); |
|
||||||
myG.setStroke(myStroke); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,242 @@ |
|||||||
|
package com.fr.design.report; |
||||||
|
|
||||||
|
import com.fr.base.extension.FileExtension; |
||||||
|
import com.fr.design.gui.ibutton.UIRadioButton; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.io.attr.ImageExportAttr; |
||||||
|
import com.fr.io.attr.ReportExportAttr; |
||||||
|
import com.fr.report.ReportConfigManager; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.ButtonGroup; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
|
||||||
|
/** |
||||||
|
* 导出图片配置 |
||||||
|
* |
||||||
|
* @author vito |
||||||
|
* @date 2015/7/6 0006 |
||||||
|
*/ |
||||||
|
public class ImageExportPane extends AbstractExportPane { |
||||||
|
|
||||||
|
private UIRadioButton globalResolutionBtnS; |
||||||
|
private UIRadioButton globalResolutionBtnM; |
||||||
|
private UIRadioButton globalResolutionBtnL; |
||||||
|
|
||||||
|
private UIRadioButton globalRenderSpeed; |
||||||
|
private UIRadioButton globalRenderQuality; |
||||||
|
|
||||||
|
private UIRadioButton globalFormatJpg; |
||||||
|
private UIRadioButton globalFormatPng; |
||||||
|
|
||||||
|
private UIRadioButton previewResolutionBtnS; |
||||||
|
private UIRadioButton previewResolutionBtnM; |
||||||
|
|
||||||
|
private UIRadioButton previewRenderSpeed; |
||||||
|
private UIRadioButton previewRenderQuality; |
||||||
|
|
||||||
|
private static final int RESOLUTION_S = 96; |
||||||
|
private static final int RESOLUTION_M = 192; |
||||||
|
private static final int RESOLUTION_L = 300; |
||||||
|
|
||||||
|
private static final int DPI_SCALE_S = 1; |
||||||
|
private static final int DPI_SCALE_M = 2; |
||||||
|
|
||||||
|
private static final int GAP = 20; |
||||||
|
|
||||||
|
public static final String GLOBAL_CONF = Toolkit.i18nText("Fine-Design_Image_Export_Global_Configuration"); |
||||||
|
|
||||||
|
|
||||||
|
private ReportExportAttr reportExportAttr; |
||||||
|
|
||||||
|
public ImageExportPane() { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
||||||
|
JPanel globalTitlePane = FRGUIPaneFactory.createTitledBorderPane(GLOBAL_CONF); |
||||||
|
JPanel previewSetting = FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Basic_Preview")); |
||||||
|
this.add(globalTitlePane, BorderLayout.NORTH); |
||||||
|
this.add(previewSetting, BorderLayout.CENTER); |
||||||
|
initGlobalSettings(); |
||||||
|
|
||||||
|
JPanel centerPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
JComponent[][] comps = { |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Image_Export_Resolution") + ":"), this.globalResolutionBtnS, this.globalResolutionBtnM, this.globalResolutionBtnL}, |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Report_Format") + ":"), this.globalFormatJpg, null, this.globalFormatPng}, |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Image_Export_Rendering_Quality") + ":"), this.globalRenderQuality, null, this.globalRenderSpeed}, |
||||||
|
}; |
||||||
|
centerPane.add( |
||||||
|
TableLayoutHelper.createCommonTableLayoutPane( |
||||||
|
comps, |
||||||
|
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL}, |
||||||
|
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL}, |
||||||
|
GAP), |
||||||
|
BorderLayout.CENTER); |
||||||
|
globalTitlePane.add(centerPane, BorderLayout.CENTER); |
||||||
|
JPanel templateCenterPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
JComponent[][] templateComps = { |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Report_Engine_Enlarge_Or_Reduce") + ":"), this.previewResolutionBtnS, this.previewResolutionBtnM}, |
||||||
|
{new UILabel(Toolkit.i18nText("Fine-Design_Image_Export_Rendering_Quality") + ":"), this.previewRenderQuality, this.previewRenderSpeed}, |
||||||
|
}; |
||||||
|
templateCenterPane.add( |
||||||
|
TableLayoutHelper.createCommonTableLayoutPane( |
||||||
|
templateComps, |
||||||
|
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL}, |
||||||
|
new double[]{TableLayout.FILL, TableLayout.FILL, TableLayout.FILL}, |
||||||
|
GAP), |
||||||
|
BorderLayout.CENTER); |
||||||
|
|
||||||
|
previewSetting.add(templateCenterPane, BorderLayout.CENTER); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private void initGlobalSettings() { |
||||||
|
globalResolutionBtnS = new UIRadioButton("96dpi", true); |
||||||
|
globalResolutionBtnM = new UIRadioButton("192dpi"); |
||||||
|
globalResolutionBtnL = new UIRadioButton("300dpi"); |
||||||
|
ButtonGroup globalResolutionBtnGroup = new ButtonGroup(); |
||||||
|
globalResolutionBtnGroup.add(globalResolutionBtnS); |
||||||
|
globalResolutionBtnGroup.add(globalResolutionBtnM); |
||||||
|
globalResolutionBtnGroup.add(globalResolutionBtnL); |
||||||
|
|
||||||
|
globalFormatJpg = new UIRadioButton("jpg", true); |
||||||
|
globalFormatPng = new UIRadioButton("png"); |
||||||
|
ButtonGroup globalFormatGroup = new ButtonGroup(); |
||||||
|
globalFormatGroup.add(globalFormatJpg); |
||||||
|
globalFormatGroup.add(globalFormatPng); |
||||||
|
|
||||||
|
globalRenderQuality = new UIRadioButton("Fine-Design_Image_Export_Quality_First", true); |
||||||
|
globalRenderSpeed = new UIRadioButton("Fine-Design_Image_Export_Speed_Priority"); |
||||||
|
ButtonGroup globalRenderGroup = new ButtonGroup(); |
||||||
|
globalRenderGroup.add(globalRenderQuality); |
||||||
|
globalRenderGroup.add(globalRenderSpeed); |
||||||
|
|
||||||
|
previewResolutionBtnS = new UIRadioButton("100%", true); |
||||||
|
previewResolutionBtnM = new UIRadioButton("200%"); |
||||||
|
ButtonGroup previewResolutionBtnGroup = new ButtonGroup(); |
||||||
|
previewResolutionBtnGroup.add(previewResolutionBtnS); |
||||||
|
previewResolutionBtnGroup.add(previewResolutionBtnM); |
||||||
|
|
||||||
|
previewRenderSpeed = new UIRadioButton("Fine-Design_Image_Export_Speed_Priority"); |
||||||
|
previewRenderQuality = new UIRadioButton("Fine-Design_Image_Export_Quality_First"); |
||||||
|
ButtonGroup previewRenderGroup = new ButtonGroup(); |
||||||
|
previewRenderGroup.add(previewRenderQuality); |
||||||
|
previewRenderGroup.add(previewRenderSpeed); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 展示界面 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void populate(Object exportAttr) { |
||||||
|
populateBean(exportAttr); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 提交数据 |
||||||
|
* |
||||||
|
* @return 界面上的更新数据 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void update(Object exportAttr) { |
||||||
|
updateBean(); |
||||||
|
} |
||||||
|
|
||||||
|
private ImageExportAttr getGlobalImageExportAttr() { |
||||||
|
return ReportConfigManager.getProviderInstance().getImageExportAttr(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 标题 |
||||||
|
* |
||||||
|
* @return 标题 |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return Toolkit.i18nText("Fine-Design_Image_Export_Export_Image_Setting"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void populateBean(Object exportAttr) { |
||||||
|
ImageExportAttr attr = getGlobalImageExportAttr(); |
||||||
|
switch (attr.getResolution()) { |
||||||
|
case 192: |
||||||
|
globalResolutionBtnM.setSelected(true); |
||||||
|
break; |
||||||
|
case 300: |
||||||
|
globalResolutionBtnL.setSelected(true); |
||||||
|
break; |
||||||
|
default: |
||||||
|
globalResolutionBtnS.setSelected(true); |
||||||
|
} |
||||||
|
if (FileExtension.PNG.getExtension().equals(attr.getFormat())) { |
||||||
|
globalFormatPng.setSelected(true); |
||||||
|
} else { |
||||||
|
globalFormatJpg.setSelected(true); |
||||||
|
} |
||||||
|
if (attr.getRenderQuality() == ImageExportAttr.RENDER_SPEED) { |
||||||
|
globalRenderSpeed.setSelected(true); |
||||||
|
} else { |
||||||
|
globalRenderQuality.setSelected(true); |
||||||
|
} |
||||||
|
|
||||||
|
if (attr.getPreviewRenderQuality() == ImageExportAttr.RENDER_SPEED) { |
||||||
|
previewRenderSpeed.setSelected(true); |
||||||
|
} else { |
||||||
|
previewRenderQuality.setSelected(true); |
||||||
|
} |
||||||
|
|
||||||
|
if (attr.getPreviewResolutionScale() == DPI_SCALE_S) { |
||||||
|
previewResolutionBtnS.setSelected(true); |
||||||
|
} else { |
||||||
|
previewResolutionBtnM.setSelected(true); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateBean(Object exportAttr) { |
||||||
|
ImageExportAttr attr = getGlobalImageExportAttr(); |
||||||
|
if (globalResolutionBtnS.isSelected()) { |
||||||
|
attr.setResolution(RESOLUTION_S); |
||||||
|
} else if (globalResolutionBtnM.isSelected()) { |
||||||
|
attr.setResolution(RESOLUTION_M); |
||||||
|
} else { |
||||||
|
attr.setResolution(RESOLUTION_L); |
||||||
|
} |
||||||
|
if (globalFormatPng.isSelected()) { |
||||||
|
attr.setFormat(FileExtension.PNG.getExtension()); |
||||||
|
} else { |
||||||
|
attr.setFormat(FileExtension.JPG.getExtension()); |
||||||
|
} |
||||||
|
if (globalRenderSpeed.isSelected()) { |
||||||
|
attr.setRenderQuality(ImageExportAttr.RENDER_SPEED); |
||||||
|
} else { |
||||||
|
attr.setRenderQuality(ImageExportAttr.RENDER_QUALITY); |
||||||
|
} |
||||||
|
|
||||||
|
if (previewRenderSpeed.isSelected()) { |
||||||
|
attr.setPreviewRenderQuality(ImageExportAttr.RENDER_SPEED); |
||||||
|
} else { |
||||||
|
attr.setPreviewRenderQuality(ImageExportAttr.RENDER_QUALITY); |
||||||
|
} |
||||||
|
if (previewResolutionBtnS.isSelected()) { |
||||||
|
attr.setPreviewResolutionScale(DPI_SCALE_S); |
||||||
|
} else { |
||||||
|
attr.setPreviewResolutionScale(DPI_SCALE_M); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getTitle() { |
||||||
|
return "Image"; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue