forked from fanruan/design
Browse Source
* commit '868e95047dd04dc45486f38372b4867a01937779': REPORT-8125 水印 设计器配置界面与实时预览=>完善国际化 REPORT-8125 水印 设计器配置界面与实 时预览=>核心功能完成 REPORT-8125 水印 设计器配置界面与实时预览=>完成基本框架master
superman
7 years ago
13 changed files with 443 additions and 10 deletions
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 558 B |
@ -0,0 +1,170 @@ |
|||||||
|
package com.fr.design.report; |
||||||
|
|
||||||
|
import com.fr.base.Watermark; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.formula.TinyFormulaPane; |
||||||
|
import com.fr.design.gui.icombobox.UIComboBox; |
||||||
|
import com.fr.design.gui.icontainer.UIScrollPane; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.gui.style.FRFontPane; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.layout.TableLayout; |
||||||
|
import com.fr.design.layout.TableLayoutHelper; |
||||||
|
import com.fr.design.style.color.NewColorSelectPane; |
||||||
|
import com.fr.design.utils.gui.GUICoreUtils; |
||||||
|
import com.fr.general.Inter; |
||||||
|
|
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import javax.swing.event.ChangeEvent; |
||||||
|
import javax.swing.event.ChangeListener; |
||||||
|
import javax.swing.event.DocumentEvent; |
||||||
|
import javax.swing.event.DocumentListener; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.event.ItemEvent; |
||||||
|
import java.awt.event.ItemListener; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by plough on 2018/5/15. |
||||||
|
*/ |
||||||
|
public class WatermarkPane extends BasicPane { |
||||||
|
|
||||||
|
private static final int MAX_WIDTH = 160; |
||||||
|
|
||||||
|
// 水印预览面板
|
||||||
|
private WatermarkPreviewPane watermarkPreviewPane; |
||||||
|
// 文字
|
||||||
|
private TinyFormulaPane formulaPane; |
||||||
|
// 字号
|
||||||
|
private UIComboBox fontSizeComboBox; |
||||||
|
// 文字颜色
|
||||||
|
private NewColorSelectPane colorPane; |
||||||
|
|
||||||
|
public WatermarkPane() { |
||||||
|
initComponents(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initComponents() { |
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
|
||||||
|
JPanel contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
this.add(contentPane, BorderLayout.CENTER); |
||||||
|
|
||||||
|
// 预览
|
||||||
|
JPanel leftPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
contentPane.add(leftPane, BorderLayout.CENTER); |
||||||
|
leftPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("FR-Designer-Widget-Style_Preview"), null)); |
||||||
|
JPanel previewPaneWrapper = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
leftPane.add(previewPaneWrapper, BorderLayout.CENTER); |
||||||
|
previewPaneWrapper.setBorder(BorderFactory.createEmptyBorder(2, 8, 4, 8)); |
||||||
|
watermarkPreviewPane = new WatermarkPreviewPane(); |
||||||
|
previewPaneWrapper.add(watermarkPreviewPane, BorderLayout.CENTER); |
||||||
|
|
||||||
|
// 设置
|
||||||
|
JPanel rightPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
contentPane.add(rightPane, BorderLayout.EAST); |
||||||
|
rightPane.add(initRightPane(), BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
public void populate(Watermark watermark) { |
||||||
|
populateFourmula(watermark.getText()); |
||||||
|
populateFontSize(watermark.getFontSize()); |
||||||
|
populateColor(watermark.getColor()); |
||||||
|
paintPreviewPane(); |
||||||
|
} |
||||||
|
|
||||||
|
public Watermark update() { |
||||||
|
Watermark watermark = new Watermark(); |
||||||
|
watermark.setText(formulaPane.getUITextField().getText()); |
||||||
|
watermark.setFontSize((int)fontSizeComboBox.getSelectedItem()); |
||||||
|
watermark.setColor(colorPane.getColor()); |
||||||
|
return watermark; |
||||||
|
} |
||||||
|
|
||||||
|
public TinyFormulaPane getFormulaPane() { |
||||||
|
return formulaPane; |
||||||
|
} |
||||||
|
|
||||||
|
public void setFormulaPane(TinyFormulaPane formulaPane) { |
||||||
|
this.formulaPane = formulaPane; |
||||||
|
} |
||||||
|
|
||||||
|
protected UIScrollPane initRightPane(){ |
||||||
|
formulaPane = new TinyFormulaPane(); |
||||||
|
fontSizeComboBox = new UIComboBox(FRFontPane.FONT_SIZES); |
||||||
|
JPanel fontSizeTypePane = new JPanel(new BorderLayout(10,0)); |
||||||
|
fontSizeTypePane.add(fontSizeComboBox, BorderLayout.CENTER); |
||||||
|
|
||||||
|
colorPane = new NewColorSelectPane(); |
||||||
|
JPanel colorLabelPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
||||||
|
colorLabelPane.add(new UILabel(Inter.getLocText("FR-Designer_Text_Color")), BorderLayout.NORTH); |
||||||
|
|
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double[] rowSize = {p,p,p}; |
||||||
|
double[] columnSize = { p, MAX_WIDTH}; |
||||||
|
|
||||||
|
JPanel rightContentPane = TableLayoutHelper.createCommonTableLayoutPane( new JComponent[][]{ |
||||||
|
{new UILabel(Inter.getLocText("FR-Designer_Watermark_Text")), formulaPane}, |
||||||
|
{new UILabel(Inter.getLocText("FR-Designer_Font_Size")), fontSizeTypePane}, |
||||||
|
{colorLabelPane, colorPane}, |
||||||
|
}, rowSize, columnSize, 10); |
||||||
|
rightContentPane.setBorder(BorderFactory.createEmptyBorder(15, 12, 10, 12)); |
||||||
|
|
||||||
|
UIScrollPane configPane = new UIScrollPane(rightContentPane); |
||||||
|
configPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("FR-Designer_Config"),null)); |
||||||
|
return configPane; |
||||||
|
} |
||||||
|
|
||||||
|
protected void populateFontSize(int fontSize){ |
||||||
|
this.fontSizeComboBox.setSelectedItem(fontSize); |
||||||
|
this.fontSizeComboBox.addItemListener(new ItemListener() { |
||||||
|
@Override |
||||||
|
public void itemStateChanged(ItemEvent e) { |
||||||
|
paintPreviewPane(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
protected void paintPreviewPane(){ |
||||||
|
watermarkPreviewPane.repaint(update()); |
||||||
|
} |
||||||
|
|
||||||
|
private void populateFourmula(String formula) { |
||||||
|
this.formulaPane.populateBean(formula); |
||||||
|
this.formulaPane.getUITextField().getDocument() |
||||||
|
.addDocumentListener(new DocumentListener() { |
||||||
|
@Override |
||||||
|
public void insertUpdate(DocumentEvent e) { |
||||||
|
paintPreviewPane(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void removeUpdate(DocumentEvent e) { |
||||||
|
paintPreviewPane(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void changedUpdate(DocumentEvent e) { |
||||||
|
paintPreviewPane(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
private void populateColor(Color color) { |
||||||
|
colorPane.setColor(color); |
||||||
|
colorPane.addChangeListener(new ChangeListener() { |
||||||
|
@Override |
||||||
|
public void stateChanged(ChangeEvent e) { |
||||||
|
paintPreviewPane(); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return Inter.getLocText("FR-Designer_WaterMark"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,84 @@ |
|||||||
|
package com.fr.design.report; |
||||||
|
|
||||||
|
import com.fr.base.Watermark; |
||||||
|
import com.fr.design.constants.UIConstants; |
||||||
|
import com.fr.general.FRFont; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.FontMetrics; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Image; |
||||||
|
import java.awt.image.BufferedImage; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by plough on 2018/5/15. |
||||||
|
*/ |
||||||
|
public class WatermarkPreviewPane extends JPanel { |
||||||
|
private static final double SCALE_FACTOR = 3; // 水印层的放大比例
|
||||||
|
private static final int ROTATE_DEGREE = -20; // 旋转角度
|
||||||
|
// 绘制水印层的坐标,用来控制图层偏移
|
||||||
|
private static final int MARK_X = 0; |
||||||
|
private static final int MARK_Y = -120; |
||||||
|
|
||||||
|
private int horizontalGap = 20; // 水平间隔(一个中文字符宽度)
|
||||||
|
private int verticalGap = 40; // 垂直间隔(两个中文字符宽度)
|
||||||
|
private Watermark watermark; |
||||||
|
|
||||||
|
|
||||||
|
public WatermarkPreviewPane() { |
||||||
|
this.watermark = new Watermark(); |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 重新画 |
||||||
|
*/ |
||||||
|
public void repaint(Watermark watermark){ |
||||||
|
this.watermark = watermark; |
||||||
|
super.repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
private void updateGap(FontMetrics fontMetrics) { |
||||||
|
horizontalGap = fontMetrics.stringWidth("帆"); // 任意一个中文字符
|
||||||
|
verticalGap = horizontalGap * 2; |
||||||
|
} |
||||||
|
|
||||||
|
private int getLineHeight() { |
||||||
|
return horizontalGap; |
||||||
|
} |
||||||
|
|
||||||
|
private BufferedImage paintWatermark() { |
||||||
|
int width = (int)(this.getWidth() * SCALE_FACTOR); |
||||||
|
int height = (int)(this.getHeight() * SCALE_FACTOR); |
||||||
|
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
||||||
|
Graphics g = image.getGraphics(); |
||||||
|
g.setColor(watermark.getColor()); |
||||||
|
g.setFont(FRFont.getInstance().applySize(watermark.getFontSize())); |
||||||
|
updateGap(g.getFontMetrics()); |
||||||
|
for (int y = getLineHeight(); y < height; y += verticalGap) { |
||||||
|
for (int x = 0; x < width; x += horizontalGap) { |
||||||
|
g.drawString(watermark.getText(), x, y); |
||||||
|
x += g.getFontMetrics().stringWidth(watermark.getText()); |
||||||
|
} |
||||||
|
y += getLineHeight(); |
||||||
|
} |
||||||
|
return image; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paint(Graphics g) { |
||||||
|
super.paint(g); |
||||||
|
Graphics2D g2d = (Graphics2D)g; |
||||||
|
g2d.drawImage(UIConstants.WATERMARK_BACKGROUND, 0, 0, this.getWidth(), this.getHeight(), null); |
||||||
|
BufferedImage markImage = paintWatermark(); |
||||||
|
g2d.rotate( |
||||||
|
Math.toRadians(ROTATE_DEGREE), |
||||||
|
(double) markImage.getWidth() / 2, |
||||||
|
(double) markImage.getHeight() / 2 |
||||||
|
); |
||||||
|
g.drawImage(markImage, MARK_X, MARK_Y, null); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
package com.fr.design.mainframe.widget.accessibles; |
||||||
|
|
||||||
|
import com.fr.base.Watermark; |
||||||
|
import com.fr.design.dialog.BasicDialog; |
||||||
|
import com.fr.design.dialog.DialogActionAdapter; |
||||||
|
import com.fr.design.mainframe.widget.editors.ITextComponent; |
||||||
|
import com.fr.design.mainframe.widget.renderer.WatermarkRenderer; |
||||||
|
import com.fr.design.mainframe.widget.wrappers.WatermarkWrapper; |
||||||
|
import com.fr.design.report.WatermarkPane; |
||||||
|
|
||||||
|
import javax.swing.SwingUtilities; |
||||||
|
import java.awt.Dimension; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by plough on 2018/5/15. |
||||||
|
*/ |
||||||
|
|
||||||
|
public class AccessibleBodyWatermarkEditor extends UneditableAccessibleEditor { |
||||||
|
private WatermarkPane watermarkPane; |
||||||
|
|
||||||
|
public AccessibleBodyWatermarkEditor() { |
||||||
|
super(new WatermarkWrapper()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected ITextComponent createTextField() { |
||||||
|
return new RendererField(new WatermarkRenderer()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void showEditorPane() { |
||||||
|
if (watermarkPane == null) { |
||||||
|
watermarkPane = new WatermarkPane(); |
||||||
|
watermarkPane.setPreferredSize(new Dimension(600, 400)); |
||||||
|
} |
||||||
|
BasicDialog dlg = watermarkPane.showWindow(SwingUtilities.getWindowAncestor(this)); |
||||||
|
dlg.addDialogActionListener(new DialogActionAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void doOk() { |
||||||
|
setValue(watermarkPane.update()); |
||||||
|
fireStateChanged(); |
||||||
|
} |
||||||
|
}); |
||||||
|
watermarkPane.populate((Watermark) getValue()); |
||||||
|
dlg.setVisible(true); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package com.fr.design.mainframe.widget.renderer; |
||||||
|
|
||||||
|
import com.fr.design.mainframe.widget.wrappers.WatermarkWrapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by plough on 2018/5/15. |
||||||
|
*/ |
||||||
|
public class WatermarkRenderer extends EncoderCellRenderer { |
||||||
|
|
||||||
|
public WatermarkRenderer() { |
||||||
|
super(new WatermarkWrapper()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
package com.fr.design.mainframe.widget.wrappers; |
||||||
|
|
||||||
|
import com.fr.base.Watermark; |
||||||
|
import com.fr.design.Exception.ValidationException; |
||||||
|
import com.fr.design.designer.properties.Decoder; |
||||||
|
import com.fr.design.designer.properties.Encoder; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by plough on 2018/5/15. |
||||||
|
*/ |
||||||
|
public class WatermarkWrapper implements Encoder, Decoder { |
||||||
|
@Override |
||||||
|
public Object decode(String txt) { |
||||||
|
return new Watermark(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void validate(String txt) throws ValidationException { |
||||||
|
// do nothing
|
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String encode(Object v) { |
||||||
|
return ((Watermark)v).getText(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
package com.fr.design.actions.report; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.actions.ReportComponentAction; |
||||||
|
import com.fr.design.dialog.DialogActionAdapter; |
||||||
|
import com.fr.design.mainframe.DesignerContext; |
||||||
|
import com.fr.design.mainframe.ReportComponent; |
||||||
|
import com.fr.design.menu.KeySetUtils; |
||||||
|
import com.fr.design.report.WatermarkPane; |
||||||
|
import com.fr.report.core.ReportUtils; |
||||||
|
import com.fr.report.stable.ReportSettings; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created by plough on 2018/5/15. |
||||||
|
*/ |
||||||
|
public class ReportWatermarkAction extends ReportComponentAction<ReportComponent> { |
||||||
|
|
||||||
|
public ReportWatermarkAction(ReportComponent rc) { |
||||||
|
super(rc); |
||||||
|
this.setMenuKeySet(KeySetUtils.REPORT_WATERMARK); |
||||||
|
this.setName(getMenuKeySet().getMenuKeySetName() + "..."); |
||||||
|
this.setMnemonic(getMenuKeySet().getMnemonic()); |
||||||
|
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/watermark.png")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 执行动作 |
||||||
|
* @return 是否执行成功 |
||||||
|
*/ |
||||||
|
public boolean executeActionReturnUndoRecordNeeded() { |
||||||
|
final ReportComponent reportPane = this.getEditingComponent(); |
||||||
|
if (reportPane == null) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
final WatermarkPane watermarkPane = new WatermarkPane(); |
||||||
|
ReportSettings reportSettings = (ReportSettings) ReportUtils.getReportSettings(reportPane.getTemplateReport()); |
||||||
|
watermarkPane.populate(reportSettings.getWatermark()); |
||||||
|
watermarkPane.showWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { |
||||||
|
@Override |
||||||
|
public void doOk() { |
||||||
|
reportSettings.setWatermark(watermarkPane.update()); |
||||||
|
reportPane.fireTargetModified(); |
||||||
|
} |
||||||
|
}).setVisible(true); |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue