Browse Source

CHART-15510 完善内容样式界面交互

feature/big-screen
Qinghui.Liu 4 years ago
parent
commit
bf14ab15b7
  1. 67
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartRichEditorPane.java
  2. 163
      designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartTooltipContentPane.java
  3. 46
      designer-chart/src/main/java/com/fr/van/chart/designer/component/format/VanChartFormatPaneWithCheckBox.java

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

@ -1,27 +1,61 @@
package com.fr.van.chart.designer.component;
import com.fr.design.ui.ModernUIPane;
import com.fr.plugin.chart.base.AttrTooltipRichEditor;
import com.fr.plugin.chart.base.AttrTooltipRichText;
import com.fr.stable.StringUtils;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter;
import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class VanChartRichEditorPane {
private static final String namespace = "Pool";
private static final String variable = "data";
private static final String richEditorPath = "/com/fr/design/editor/rich_editor.html";
private static final String expression = "dispatch()";
private static ModernUIPane<RichEditorModel> richEditorPane;
private static Browser browser;
public static ModernUIPane<RichEditorModel> createRichEditorPane(AttrTooltipRichText richEditor) {
RichEditorModel model = getRichEditorModel(richEditor);
public static ModernUIPane<RichEditorModel> getInstance() {
if (richEditorPane == null) {
richEditorPane = new ModernUIPane.Builder<RichEditorModel>()
.withEMB("/com/fr/design/editor/rich_editor.html")
.namespace("Pool").build();
richEditorPane = initPane(model);
} else if (browser != null) {
updatePane(browser, model);
}
return richEditorPane;
}
public static RichEditorModel getRichEditorModel(AttrTooltipRichEditor richEditor) {
Map<String, String> paramsMap = richEditor.getParams();
public static ModernUIPane<RichEditorModel> initPane(RichEditorModel model) {
return new ModernUIPane.Builder<RichEditorModel>()
.prepare(new ScriptContextAdapter() {
public void onScriptContextCreated(ScriptContextEvent event) {
browser = event.getBrowser();
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace);
ns.asObject().setProperty(variable, model);
}
})
.withEMB(richEditorPath)
.namespace(namespace).build();
}
public static void updatePane(Browser browser, RichEditorModel model) {
JSValue ns = browser.executeJavaScriptAndReturnValue("window." + namespace);
ns.asObject().setProperty(variable, model);
browser.executeJavaScript("window." + namespace + "." + expression);
}
public static RichEditorModel getRichEditorModel(AttrTooltipRichText richText) {
Map<String, String> paramsMap = richText.getParams();
StringBuilder paramsStr = new StringBuilder(StringUtils.EMPTY);
if (paramsMap != null) {
@ -37,7 +71,24 @@ public class VanChartRichEditorPane {
paramsStr.deleteCharAt(len - 1);
}
return new RichEditorModel(richEditor.getContent(), richEditor.isAuto(), paramsStr.toString());
return new RichEditorModel(richText.getContent(), richText.isAuto(), paramsStr.toString());
}
public static List<String> richParamsParser(String content, Map<String, String> paramsMap) {
if (content == null || paramsMap == null) {
return null;
}
List<String> result = new ArrayList<>();
for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
String param = entry.getValue();
if (content.contains(param)) {
result.add(param);
}
}
return result;
}
public static class RichEditorModel {

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

@ -1,22 +1,19 @@
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.UIButton;
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.general.ComparatorUtils;
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.AttrTooltipRichText;
import com.fr.plugin.chart.base.format.AttrTooltipFormat;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import com.fr.van.chart.designer.component.format.CategoryNameFormatPaneWithCheckBox;
@ -31,9 +28,7 @@ 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;
@ -42,6 +37,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
/**
* 内容界面 数据点提示
@ -63,18 +59,17 @@ 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;
private AttrTooltipRichText richText;
public VanChartTooltipContentPane(VanChartStylePane parent, JPanel showOnPane){
this.parent = parent;
this.showOnPane = showOnPane;
this.richEditor = new AttrTooltipRichEditor();
this.richText = new AttrTooltipRichText();
this.setLayout(new BorderLayout());
this.add(createLabelContentPane(),BorderLayout.CENTER);
@ -164,44 +159,29 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
Component[][] components = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Content_Style")), createContentStylePane()}
new Component[]{null, createContentStylePane()}
};
return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize);
}
private JComponent createContentStylePane() {
contentTextArea = new RTextArea();
contentTextArea.setLineWrap(true);
UIButton contentTextArea = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Content_Style"));
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);
}
};
return contentTextArea;
}
private void fireRichEditor() {
final ModernUIPane<VanChartRichEditorPane.RichEditorModel> pane = VanChartRichEditorPane.getInstance();
final ModernUIPane<VanChartRichEditorPane.RichEditorModel> pane = VanChartRichEditorPane.createRichEditorPane(richText);
BasicDialog dialog = pane.showWindow(new JFrame());
pane.populate(VanChartRichEditorPane.getRichEditorModel(richEditor));
pane.populate(VanChartRichEditorPane.getRichEditorModel(richText));
dialog.addDialogActionListener(new DialogActionAdapter() {
@ -209,11 +189,9 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
VanChartRichEditorPane.RichEditorModel model = pane.update();
String content = model.getContent();
populateContentTextArea(content);
richEditor.setContent(content);
richEditor.setAuto(model.isAuto());
List<String> params = VanChartRichEditorPane.richParamsParser(content, richText.getParams());
populateFormatParams(params);
updateLocalRichText(content, model.isAuto());
SwingUtilities.getWindowAncestor(pane).setVisible(false);
}
@ -304,6 +282,59 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
}
protected VanChartFormatPaneWithCheckBox[] getFormatPaneGroup() {
return new VanChartFormatPaneWithCheckBox[]{
categoryNameFormatPane, seriesNameFormatPane,
valueFormatPane, percentFormatPane,
changedValueFormatPane, changedPercentFormatPane
};
}
protected VanChartFormatPaneWithCheckBox getTargetFormatPane(Object param) {
VanChartFormatPaneWithCheckBox[] formatPaneGroup = getFormatPaneGroup();
Object[] params = richText.getParams().values().toArray();
for (int i = 0, len = Math.min(params.length, formatPaneGroup.length); i < len; i++) {
if (ComparatorUtils.equals(params[i], param) && formatPaneGroup[i] != null) {
return formatPaneGroup[i];
}
}
return null;
}
private String getParamsRichText() {
VanChartFormatPaneWithCheckBox[] formatPaneGroup = getFormatPaneGroup();
// todo 获取参数对应的富文本字符串,正确的流程是:
// 在BI的富文本组件中,先清空content,然后addParam,最后读取最新的content,
// 但是当前接口还没开出来,暂时先在本地写死,模拟类似的效果
String[] richTextGroup = new String[]{
"<img alt=\"categoryFormat\" class=\"rich-editor-param\" style=\"background-color: rgba(54, 133, 242, 0.1);vertical-align: middle; margin: 0 1px; width:88.17578125px;height: 16px; max-width:88.17578125px;max-height: 16px; min-width:88.17578125px;min-height: 16px\" name=\"categoryFormat\"/>",
"<img alt=\"seriesFormat\" class=\"rich-editor-param\" style=\"background-color: rgba(54, 133, 242, 0.1);vertical-align: middle; margin: 0 1px; width:73.73828125px;height: 16px; max-width:73.73828125px;max-height: 16px; min-width:73.73828125px;min-height: 16px\" name=\"seriesFormat\"/>",
"<img alt=\"valueFormat\" class=\"rich-editor-param\" style=\"background-color: rgba(54, 133, 242, 0.1);vertical-align: middle; margin: 0 1px; width:71.4765625px;height: 16px; max-width:71.4765625px;max-height: 16px; min-width:71.4765625px;min-height: 16px\" name=\"valueFormat\"/>",
"<img alt=\"percentFormat\" class=\"rich-editor-param\" style=\"background-color: rgba(54, 133, 242, 0.1);vertical-align: middle; margin: 0 1px; width:83.388671875px;height: 16px; max-width:83.388671875px;max-height: 16px; min-width:83.388671875px;min-height: 16px\" name=\"percentFormat\"/>",
"<img alt=\"changedValueFormat\" class=\"rich-editor-param\" style=\"background-color: rgba(54, 133, 242, 0.1);vertical-align: middle; margin: 0 1px; width:117.888671875px;height: 16px; max-width:117.888671875px;max-height: 16px; min-width:117.888671875px;min-height: 16px\" name=\"changedValueFormat\"/>",
"<img alt=\"changedPercentFormat\" class=\"rich-editor-param\" style=\"background-color: rgba(54, 133, 242, 0.1);vertical-align: middle; margin: 0 1px; width:128.224609375px;height: 16px; max-width:128.224609375px;max-height: 16px; min-width:128.224609375px;min-height: 16px\" name=\"changedPercentFormat\"/>"
};
StringBuilder result = new StringBuilder("<p>");
for (int i = 0, len = formatPaneGroup.length; i < len; i++) {
VanChartFormatPaneWithCheckBox formatPane = formatPaneGroup[i];
String paramRichText = richTextGroup[i];
if (formatPane != null && formatPane.isSelected()) {
result.append(paramRichText);
}
}
result.append("</p>");
return result.toString();
}
@Override
protected String title4PopupWindow() {
return "";
@ -328,10 +359,7 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
protected void populateFormatPane(AttrTooltipContent attrTooltipContent) {
VanChartFormatPaneWithCheckBox[] formatPaneGroup = new VanChartFormatPaneWithCheckBox[]{
categoryNameFormatPane, seriesNameFormatPane, valueFormatPane, percentFormatPane,
changedValueFormatPane, changedPercentFormatPane
};
VanChartFormatPaneWithCheckBox[] formatPaneGroup = getFormatPaneGroup();
AttrTooltipFormat[] formatGroup = new AttrTooltipFormat[]{
attrTooltipContent.getCategoryFormat(),
@ -350,37 +378,45 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
formatPane.populate(format);
// 填充面板时,更新富文本编辑器参数
formatPane.updateFormatParams(richEditor.getParams(), format.getFormatJSONKey());
formatPane.updateFormatParams(richText.getParams(), format.getFormatJSONKey());
}
}
AttrTooltipRichEditor tooltipRichEditor = attrTooltipContent.getRichEditor();
AttrTooltipRichText tooltipRichText = attrTooltipContent.getRichText();
if (tooltipRichEditor != null) {
populateContentTextArea(tooltipRichEditor.getContent());
if (tooltipRichText != null) {
updateLocalRichText(tooltipRichText.getContent(), tooltipRichText.isAuto());
setDirty(false);
}
}
private void populateContentTextArea(String content) {
try {
if (contentTextArea != null) {
Document document = contentTextArea.getDocument();
document.remove(0, document.getLength());
document.insertString(0, content, null);
private void populateFormatParams(List<String> params) {
if (params == null) {
return;
}
for (String param : params) {
VanChartFormatPaneWithCheckBox formatPane = getTargetFormatPane(param);
if (formatPane != null) {
formatPane.setSelected(true);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
public AttrTooltipContent updateBean() {
AttrTooltipContent attrTooltipContent = createAttrTooltip();
attrTooltipContent.setCommon(content.getSelectedIndex() == 0);
boolean isCommon = content.getSelectedIndex() == 0;
updateFormatPane(attrTooltipContent);
updateRichEditor(attrTooltipContent);
attrTooltipContent.setCommon(isCommon);
if (isDirty() && isCommon) {
updateLocalRichText(getParamsRichText(), false);
setDirty(false);
}
updateFormatPane(attrTooltipContent);
updateTooltipRichText(attrTooltipContent);
updateFormatsWithPaneWidth(attrTooltipContent);
htmlLabelPane.update(attrTooltipContent.getHtmlLabel());
@ -406,9 +442,18 @@ public class VanChartTooltipContentPane extends BasicBeanPane<AttrTooltipContent
}
}
private void updateRichEditor(AttrTooltipContent attrTooltipContent) {
if (attrTooltipContent != null) {
attrTooltipContent.setRichEditor(richEditor);
private void updateLocalRichText(String content, boolean isAuto) {
richText.setContent(content);
richText.setAuto(isAuto);
}
private void updateTooltipRichText(AttrTooltipContent attrTooltipContent) {
try {
if (attrTooltipContent != null) {
attrTooltipContent.setRichText((AttrTooltipRichText) richText.clone());
}
} catch (Exception e){
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}

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

@ -15,7 +15,6 @@ import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.Format;
import java.util.Map;
@ -38,41 +37,22 @@ public abstract class VanChartFormatPaneWithCheckBox extends JPanel{
public VanChartFormatPaneWithCheckBox(AbstractAttrNoScrollPane parent, JPanel showOnPane) {
this.parent = parent;
this.showOnPane = showOnPane;
this.isDirty = true;
this.isDirty = false;
this.setLayout(new BorderLayout());
isSelectedBox = new UICheckBox(getCheckBoxText());
formatButton = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Use_Format"));
this.add(isSelectedBox, BorderLayout.CENTER);
this.add(formatButton, BorderLayout.EAST);
initFormatListener();
isSelectedBox.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
isSelectedBox = new UICheckBox(getCheckBoxText()) {
protected void attributeChange() {
isDirty = true;
super.attributeChange();
}
};
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
formatButton = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Use_Format"));
this.add(isSelectedBox, BorderLayout.CENTER);
this.add(formatButton, BorderLayout.EAST);
}
});
initFormatListener();
}
protected abstract String getCheckBoxText();
@ -127,6 +107,14 @@ public abstract class VanChartFormatPaneWithCheckBox extends JPanel{
this.isDirty = isDirty;
}
public boolean isSelected() {
return this.isSelectedBox.isSelected();
}
public void setSelected(boolean isSelected) {
this.isSelectedBox.setSelected(isSelected);
}
public void populate(AttrTooltipFormat tooltipFormat) {
this.isSelectedBox.setSelected(tooltipFormat.isEnable());
this.format = tooltipFormat.getFormat();

Loading…
Cancel
Save