Browse Source

CHART-15510 标签和提示中插入BI的富文本编辑器

feature/big-screen
Qinghui.Liu 4 years ago
parent
commit
21d0422f02
  1. 78
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartRichEditorPane.java
  2. 194
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java
  3. 13
      designer-chart/src/main/java/com/fr/van/chart/designer/component/format/VanChartFormatPaneWithCheckBox.java

78
designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartRichEditorPane.java

@ -0,0 +1,78 @@
package com.fr.van.chart.designer.component;
import com.fr.design.ui.ModernUIPane;
import com.fr.plugin.chart.base.AttrTooltipRichEditor;
import com.fr.stable.StringUtils;
import java.util.Map;
public class VanChartRichEditorPane {
private static ModernUIPane<RichEditorModel> richEditorPane;
public static ModernUIPane<RichEditorModel> getInstance() {
if (richEditorPane == null) {
richEditorPane = new ModernUIPane.Builder<RichEditorModel>()
.withEMB("/com/fr/design/editor/rich_editor.html")
.namespace("Pool").build();
}
return richEditorPane;
}
public static RichEditorModel getRichEditorModel(AttrTooltipRichEditor richEditor) {
Map<String, String> paramsMap = richEditor.getParams();
StringBuilder paramsStr = new StringBuilder(StringUtils.EMPTY);
if (paramsMap != null) {
for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
paramsStr.append(entry.getKey()).append(":").append(entry.getValue());
paramsStr.append("-");
}
}
int len = paramsStr.length();
if (len > 0) {
paramsStr.deleteCharAt(len - 1);
}
return new RichEditorModel(richEditor.getContent(), richEditor.isAuto(), paramsStr.toString());
}
public static class RichEditorModel {
private String content;
private boolean auto;
private String params;
public RichEditorModel(String content, boolean auto, String params) {
this.content = content;
this.auto = auto;
this.params = params;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public boolean isAuto() {
return auto;
}
public void setAuto(boolean auto) {
this.auto = auto;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
}
}

194
designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java

@ -1,12 +1,23 @@
package com.fr.van.chart.designer.component;
import com.fr.design.DesignerEnvManager;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.gui.autocomplete.AutoCompletion;
import com.fr.design.gui.autocomplete.DefaultCompletionProvider;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.syntax.ui.rtextarea.RTextArea;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.ui.ModernUIPane;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.chart.base.AttrTooltipContent;
import com.fr.plugin.chart.base.AttrTooltipRichEditor;
import com.fr.plugin.chart.base.format.AttrTooltipFormat;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import com.fr.van.chart.designer.component.format.CategoryNameFormatPaneWithCheckBox;
import com.fr.van.chart.designer.component.format.ChangedPercentFormatPaneWithCheckBox;
@ -14,15 +25,23 @@ import com.fr.van.chart.designer.component.format.ChangedValueFormatPaneWithChec
import com.fr.van.chart.designer.component.format.PercentFormatPaneWithCheckBox;
import com.fr.van.chart.designer.component.format.SeriesNameFormatPaneWithCheckBox;
import com.fr.van.chart.designer.component.format.ValueFormatPaneWithCheckBox;
import com.fr.van.chart.designer.component.format.VanChartFormatPaneWithCheckBox;
import com.fr.van.chart.designer.style.VanChartStylePane;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* 内容界面 数据点提示
@ -43,22 +62,29 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
private JPanel centerPane;
private JPanel commonPanel;
private JPanel editorPane;
private RTextArea contentTextArea;
private VanChartHtmlLabelPane htmlLabelPane;
private VanChartStylePane parent;
private JPanel showOnPane;
private AttrTooltipRichEditor richEditor;
public VanChartTooltipContentPane(VanChartStylePane parent, JPanel showOnPane){
this.parent = parent;
this.showOnPane = showOnPane;
this.richEditor = new AttrTooltipRichEditor();
this.setLayout(new BorderLayout());
this.add(createLabelContentPane(),BorderLayout.CENTER);
}
private JPanel createLabelContentPane() {
content = new UIButtonGroup<Integer>(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Common"),
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Custom")});
content = new UIButtonGroup<>(new String[]{
Toolkit.i18nText("Fine-Design_Chart_Common"),
Toolkit.i18nText("Fine-Design_Chart_Custom")
});
initFormatPane(parent, showOnPane);
@ -80,8 +106,8 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
}
};
centerPane.add(htmlLabelPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Custom"));
centerPane.add(commonPanel,com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Common"));
centerPane.add(htmlLabelPane, Toolkit.i18nText("Fine-Design_Chart_Custom"));
centerPane.add(commonPanel, Toolkit.i18nText("Fine-Design_Chart_Common"));
double[] column = {f, e};
double[] row = {p,p,p};
@ -90,17 +116,28 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
new Component[]{new UILabel(getLabelContentTitle()),content},
new Component[]{null,centerPane},
};
initContentListener();
JPanel contentPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, row, column);
return getLabelContentPane(contentPane);
// editorPane = createRichEditorPanel();
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(contentPane, BorderLayout.CENTER);
// panel.add(editorPane, BorderLayout.SOUTH);
initContentListener();
return getLabelContentPane(panel);
}
protected String getLabelContentTitle () {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Text");
return Toolkit.i18nText("Fine-Design_Report_Text");
}
protected JPanel getLabelContentPane(JPanel contentPane) {
return createTableLayoutPaneWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Content"), contentPane);
return createTableLayoutPaneWithTitle(Toolkit.i18nText("Fine-Design_Chart_Content"), contentPane);
}
protected VanChartHtmlLabelPane createHtmlLabelPane() {
@ -117,6 +154,82 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
return TableLayoutHelper.createTableLayoutPane(getPaneComponents(), rowSize, columnSize);
}
private JPanel createRichEditorPanel() {
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH;
double[] columnSize = {f, e};
double[] rowSize = {p, p};
Component[][] components = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Content_Style")), createContentStylePane()}
};
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
}
private JComponent createContentStylePane() {
contentTextArea = new RTextArea();
contentTextArea.setLineWrap(true);
contentTextArea.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
fireRichEditor();
}
public void mousePressed(MouseEvent e) {
fireRichEditor();
}
});
DefaultCompletionProvider provider = new DefaultCompletionProvider();
AutoCompletion ac = new AutoCompletion(provider);
String shortCuts = DesignerEnvManager.getEnvManager().getAutoCompleteShortcuts();
ac.setTriggerKey(KeyStroke.getKeyStroke(shortCuts.replace("+", "pressed")));
ac.install(contentTextArea);
return new UIScrollPane(contentTextArea) {
public Dimension getPreferredSize() {
return new Dimension(super.getPreferredSize().width, 100);
}
};
}
private void fireRichEditor() {
final ModernUIPane<VanChartRichEditorPane.RichEditorModel> pane = VanChartRichEditorPane.getInstance();
BasicDialog dialog = pane.showWindow(new JFrame());
pane.populate(VanChartRichEditorPane.getRichEditorModel(richEditor));
dialog.addDialogActionListener(new DialogActionAdapter() {
public void doOk() {
VanChartRichEditorPane.RichEditorModel model = pane.update();
String content = model.getContent();
populateContentTextArea(content);
richEditor.setContent(content);
richEditor.setAuto(model.isAuto());
SwingUtilities.getWindowAncestor(pane).setVisible(false);
}
public void doCancel() {
SwingUtilities.getWindowAncestor(pane).setVisible(false);
}
});
dialog.setVisible(true);
if (parent != null) {
parent.attributeChanged();
}
}
protected void initFormatPane(VanChartStylePane parent, JPanel showOnPane){
categoryNameFormatPane = new CategoryNameFormatPaneWithCheckBox(parent, showOnPane);
seriesNameFormatPane = new SeriesNameFormatPaneWithCheckBox(parent, showOnPane);
@ -154,13 +267,17 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
private void checkCardPane() {
CardLayout cardLayout = (CardLayout) centerPane.getLayout();
if (content.getSelectedIndex() == 1) {
cardLayout.show(centerPane,com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Custom"));
cardLayout.show(centerPane, Toolkit.i18nText("Fine-Design_Chart_Custom"));
if(isDirty()){
setCustomFormatterText();
setDirty(false);
}
} else {
cardLayout.show(centerPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Common"));
cardLayout.show(centerPane, Toolkit.i18nText("Fine-Design_Chart_Common"));
}
if (editorPane != null) {
editorPane.setVisible(content.getSelectedIndex() == 0);
}
}
@ -211,16 +328,48 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
protected void populateFormatPane(AttrTooltipContent attrTooltipContent) {
categoryNameFormatPane.populate(attrTooltipContent.getCategoryFormat());
seriesNameFormatPane.populate(attrTooltipContent.getSeriesFormat());
valueFormatPane.populate(attrTooltipContent.getValueFormat());
percentFormatPane.populate(attrTooltipContent.getPercentFormat());
VanChartFormatPaneWithCheckBox[] formatPaneGroup = new VanChartFormatPaneWithCheckBox[]{
categoryNameFormatPane, seriesNameFormatPane, valueFormatPane, percentFormatPane,
changedValueFormatPane, changedPercentFormatPane
};
if (changedValueFormatPane != null) {
changedValueFormatPane.populate(attrTooltipContent.getChangedValueFormat());
AttrTooltipFormat[] formatGroup = new AttrTooltipFormat[]{
attrTooltipContent.getCategoryFormat(),
attrTooltipContent.getSeriesFormat(),
attrTooltipContent.getValueFormat(),
attrTooltipContent.getPercentFormat(),
attrTooltipContent.getChangedValueFormat(),
attrTooltipContent.getChangedPercentFormat()
};
for (int i = 0, len = formatPaneGroup.length; i < len; i++) {
VanChartFormatPaneWithCheckBox formatPane = formatPaneGroup[i];
AttrTooltipFormat format = formatGroup[i];
if (formatPane != null && format != null) {
formatPane.populate(format);
// 填充面板时,更新富文本编辑器参数
formatPane.updateFormatParams(richEditor.getParams(), format.getFormatJSONKey());
}
}
if (changedPercentFormatPane != null) {
changedPercentFormatPane.populate(attrTooltipContent.getChangedPercentFormat());
AttrTooltipRichEditor tooltipRichEditor = attrTooltipContent.getRichEditor();
if (tooltipRichEditor != null) {
populateContentTextArea(tooltipRichEditor.getContent());
}
}
private void populateContentTextArea(String content) {
try {
if (contentTextArea != null) {
Document document = contentTextArea.getDocument();
document.remove(0, document.getLength());
document.insertString(0, content, null);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
@ -230,6 +379,7 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
attrTooltipContent.setCommon(content.getSelectedIndex() == 0);
updateFormatPane(attrTooltipContent);
updateRichEditor(attrTooltipContent);
updateFormatsWithPaneWidth(attrTooltipContent);
@ -256,6 +406,12 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
}
private void updateRichEditor(AttrTooltipContent attrTooltipContent) {
if (attrTooltipContent != null) {
attrTooltipContent.setRichEditor(richEditor);
}
}
/**
* CHART-1295
* 通过格式的面板宽度来判断在自定义js代码中是否显示this.seriesName字符串

13
designer-chart/src/main/java/com/fr/van/chart/designer/component/format/VanChartFormatPaneWithCheckBox.java

@ -6,7 +6,7 @@ import com.fr.design.gui.frpane.UIBubbleFloatPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.style.FormatPane;
import com.fr.design.i18n.Toolkit;
import com.fr.plugin.chart.base.format.AttrTooltipFormat;
import com.fr.stable.Constants;
@ -17,6 +17,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.Format;
import java.util.Map;
/**
* Created by Mitisky on 16/2/23.
@ -41,7 +42,7 @@ public abstract class VanChartFormatPaneWithCheckBox extends JPanel{
this.setLayout(new BorderLayout());
isSelectedBox = new UICheckBox(getCheckBoxText());
formatButton = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Use_Format"));
formatButton = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Use_Format"));
this.add(isSelectedBox, BorderLayout.CENTER);
this.add(formatButton, BorderLayout.EAST);
@ -135,4 +136,12 @@ public abstract class VanChartFormatPaneWithCheckBox extends JPanel{
tooltipFormat.setFormat(format);
tooltipFormat.setEnable(isSelectedBox.isSelected());
}
public void updateFormatParams(Map<String, String> paramMap, String value) {
String key = this.getCheckBoxText();
if (paramMap != null && !paramMap.containsKey(key)) {
paramMap.put(key, value);
}
}
}

Loading…
Cancel
Save