diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java index b0b57f29c..ec5da8bca 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UICheckListPopup.java @@ -11,6 +11,10 @@ import com.fr.general.IOUtils; import javax.swing.JCheckBox; import javax.swing.JPanel; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -22,10 +26,6 @@ import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; public class UICheckListPopup extends UIPopupMenu { private List listeners = new ArrayList(); @@ -53,7 +53,7 @@ public class UICheckListPopup extends UIPopupMenu { public void setMaxDisplayNumber(int maxDisplayNumber) { this.maxDisplayNumber = maxDisplayNumber; - addCheckboxValues(values); + addCheckboxValues(); } private void initComponent() { @@ -65,16 +65,21 @@ public class UICheckListPopup extends UIPopupMenu { this.setLayout(new BorderLayout()); this.add(jScrollPane, BorderLayout.CENTER); - addCheckboxValues(values); + addCheckboxValues(); + } + + public void refreshCheckboxValues(Object[] values){ + this.values = values; + addCheckboxValues(); } - public void addCheckboxValues(Object[] value) { + private void addCheckboxValues() { checkboxPane.removeAll(); checkBoxList.clear(); //全选加在第一个位置 addOneCheckValue(SELECT_ALL); - for (Object checkValue : value) { + for (Object checkValue : values) { addOneCheckValue(checkValue); } addSelectListener(); diff --git a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java index 0652f9cf8..d2479ae04 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombocheckbox/UIComboCheckBox.java @@ -17,6 +17,9 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -29,9 +32,6 @@ import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; /** * 设计器下拉复选框组件 @@ -198,7 +198,8 @@ public class UIComboCheckBox extends JComponent implements UIObserver, GlobalNam */ public void refreshCombo(Object[] value) { this.values = value; - this.popup.addCheckboxValues(value); + //CHART-13666 控件之前的刷新有bug,没有刷新popup中values的值,导致数组越界 + this.popup.refreshCheckboxValues(value); } /** diff --git a/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java b/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java index 9669b7cf9..5881132b3 100644 --- a/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java +++ b/designer-base/src/main/java/com/fr/design/module/DesignModuleFactory.java @@ -19,11 +19,10 @@ import com.fr.plugin.solution.sandbox.collection.PluginSandboxCollections; import com.fr.stable.StableUtils; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Constructor; import java.awt.Dialog; import java.awt.Frame; import java.awt.Window; -import java.lang.reflect.Constructor; -import java.util.ArrayList; /** * Created by IntelliJ IDEA. @@ -45,6 +44,7 @@ public class DesignModuleFactory { private Class chartEditorClass; private Class chartComponentClass; private Class chartDialogClass; + private Class autoChartDialogClass; private Class chartPropertyPaneClass; private Class newFormAction; private Class formParaDesigner; @@ -100,6 +100,10 @@ public class DesignModuleFactory { instance.chartDialogClass = cd; } + public static void registerAutoChartDialogClass(Class autoChartDialogClass) { + instance.autoChartDialogClass = autoChartDialogClass; + } + public static void registerChartPropertyPaneClass(Class p) { instance.chartPropertyPaneClass = p; } @@ -205,6 +209,26 @@ public class DesignModuleFactory { return null; } + /** + * 初始化图表向导对话框, 调用静态方法showWindow, 参数window. + * + * @return 返回调出的图表自动推荐AutoChartDialog + */ + public static MiddleChartDialog getAutoChartDialog(Window window) { + try { + Constructor c; + if (window instanceof Frame) { + c = instance.autoChartDialogClass.getConstructor(Frame.class); + } else { + c = instance.autoChartDialogClass.getConstructor(Dialog.class); + } + return c.newInstance(window); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return null; + } + /** * kunsnat: 获取图表属性界面 * diff --git a/designer-base/src/main/resources/com/fr/design/images/m_insert/auto_chart.png b/designer-base/src/main/resources/com/fr/design/images/m_insert/auto_chart.png new file mode 100644 index 000000000..c6de0fe5e Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/m_insert/auto_chart.png differ diff --git a/designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java b/designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java index 4eb725834..014778cac 100644 --- a/designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java +++ b/designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java @@ -164,6 +164,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr String[] chartIDs = ChartTypeManager.getInstance().getAllChartIDs(); ChartWidgetOption[] child = new ChartWidgetOption[chartIDs.length]; int index = 0; + for (String chartID : chartIDs) { ChartProvider[] rowChart = ChartTypeManager.getInstance().getCharts(chartID); if (ArrayUtils.isEmpty(rowChart) && !ChartTypeManager.innerChart(chartID)) { diff --git a/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java b/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java new file mode 100644 index 000000000..3bd54c27c --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java @@ -0,0 +1,69 @@ +package com.fr.design.chart; + +import com.fr.base.chart.BaseChartCollection; +import com.fr.base.chart.chartdata.TopDefinitionProvider; +import com.fr.chart.chartattr.ChartCollection; +import com.fr.plugin.chart.vanchart.VanChart; + +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-05-28 + */ +public class AutoChartDialog extends ChartDialog { + + private AutoChartTypePane autoChartTypePane; + + public AutoChartDialog(Frame owner) { + super(owner); + } + + public AutoChartDialog(Dialog owner) { + super(owner); + } + + protected Component initCenterPane() { + autoChartTypePane = new AutoChartTypePane(); + + return autoChartTypePane; + } + + protected ActionListener getActionListener() { + return new ActionListener() { + public void actionPerformed(ActionEvent e) { + ChartCollection chartCollection = (ChartCollection) getChartCollection(); + autoChartTypePane.update(chartCollection); + if (chartCollection.getChartCount() > 0) { + doOK(); + } else { + doCancel(); + } + } + }; + } + + /** + * 更新新建的图表 ChartCollection + */ + public void populate(BaseChartCollection cc) { + super.populate(cc); + ChartCollection chartCollection = (ChartCollection) getChartCollection(); + VanChart vanChart = chartCollection.getSelectedChartProvider(VanChart.class); + if (vanChart == null) { + return; + } + TopDefinitionProvider filterDefinition = vanChart.getFilterDefinition(); + if (filterDefinition == null) { + return; + } + String tableName = vanChart.getFilterDefinition().getTableName(); + String[] dataFields = vanChart.getFilterDefinition().getDataFields(); + autoChartTypePane.populate(tableName, dataFields); + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java b/designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java new file mode 100644 index 000000000..b85e2194c --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chart/AutoChartIcon.java @@ -0,0 +1,104 @@ +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 { + + 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; + } + + 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(), + WebChartIDInfo.createEmptyDesignerInfo(), 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 int 缩略图宽度 + */ + @Override + public int getIconWidth() { + return WIDTH; + } + + /** + * 返回缩略图的高度 + * + * @return int 缩略图高度 + */ + @Override + public int getIconHeight() { + return HEIGHT; + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java b/designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java new file mode 100644 index 000000000..b546a330b --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chart/AutoChartTypePane.java @@ -0,0 +1,199 @@ +package com.fr.design.chart; + +import com.fr.base.chart.chartdata.CallbackEvent; +import com.fr.chart.chartattr.ChartCollection; +import com.fr.chartx.attr.ChartProvider; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.TableDataComboBox; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombocheckbox.UIComboCheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.GUICoreUtils; + +import javax.swing.BorderFactory; +import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.ListCellRenderer; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-05-29 + */ +public class AutoChartTypePane extends ChartWizardPane implements CallbackEvent { + + private JList chartViewList; + private DefaultListModel chartResultModel; + private UIButton refreshButton; + + private TableDataComboBox tableNameComboBox; + private UIComboCheckBox dataFieldBox; + + public AutoChartTypePane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + initButtonGroup(); + initRefreshLabel(); + initDataFiledBox(); + JPanel contentPane = createContentPane(); + + chartViewList = new JList(); + + chartResultModel = new DefaultListModel(); + chartViewList.setModel(chartResultModel); + chartViewList.setVisibleRowCount(0); + chartViewList.setLayoutOrientation(JList.HORIZONTAL_WRAP); + chartViewList.setCellRenderer(iconCellRenderer); + + JScrollPane subListPane = new JScrollPane(chartViewList); + + JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, contentPane, subListPane); + splitPane.setDividerLocation(60); + splitPane.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Chart_M_Popup_Auto_Chart_Type"))); + this.add(splitPane); + } + + ListCellRenderer iconCellRenderer = new DefaultListCellRenderer() { + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + this.setText(""); + + AutoChartIcon chartIcon = (AutoChartIcon) value; + this.setIcon(chartIcon); + setHorizontalAlignment(UILabel.CENTER); + if (isSelected) { + // 深蓝色. + this.setBackground(new Color(57, 107, 181)); + this.setBorder(GUICoreUtils.createTitledBorder(chartIcon.getChartName(), Color.WHITE)); + } else { + this.setBorder(GUICoreUtils.createTitledBorder(chartIcon.getChartName())); + } + return this; + } + }; + + private JPanel createContentPane() { + JPanel panel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + + JPanel tableDataPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + panel.add(tableDataPane); + tableDataPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Table_Data") + ":")); + tableNameComboBox.setPreferredSize(new Dimension(96, 20)); + tableDataPane.add(tableNameComboBox); + + JPanel areaNamePane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + panel.add(areaNamePane); + areaNamePane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Data_Field") + ":")); + areaNamePane.add(dataFieldBox); + panel.add(refreshButton); + return panel; + } + + private void initButtonGroup() { + dataFieldBox = new UIComboCheckBox(new Object[0]); + dataFieldBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + checkButtonState(); + } + }); + } + + private void initDataFiledBox() { + tableNameComboBox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); + tableNameComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + refreshBox(); + checkButtonState(); + } + } + }); + } + + private void checkButtonState() { + if (tableNameComboBox.getSelectedItem() != null && dataFieldBox.getSelectedValues().length > 0) { + refreshButton.setEnabled(true); + } else { + refreshButton.setEnabled(false); + } + } + + private void refreshBox() { + TableDataWrapper dataWrap = tableNameComboBox.getSelectedItem(); + + if (dataWrap == null) { + return; + } + dataFieldBox.clearText(); + + List columnNameList = dataWrap.calculateColumnNameList(); + + dataFieldBox.refreshCombo(columnNameList.toArray()); + } + + private void initRefreshLabel() { + refreshButton = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Recommend")); + refreshButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + calculateAutoChart(); + } + }); + refreshButton.setEnabled(false); + } + + private void calculateAutoChart() { + chartResultModel.clear(); + } + + @Override + public void populate(ChartCollection cc) { + + } + + @Override + public void update(ChartCollection cc) { + if (chartViewList.getSelectedIndex() < 0) { + return; + } + AutoChartIcon chartIcon = (AutoChartIcon) chartViewList.getSelectedValue(); + ChartProvider chartProvider = chartIcon.getChartCollection().getSelectedChartProvider(ChartProvider.class); + if (cc.getChartCount() > 0) { + cc.setSelectChart(chartProvider); + } else { + cc.addChart(chartProvider); + } + } + + public void populate(String tableName, String[] dataFields) { + tableNameComboBox.setSelectedTableDataByName(tableName); + Map map = new HashMap(); + for (String dataField : dataFields) { + map.put(dataField, true); + } + dataFieldBox.setSelectedValues(map); + } + + @Override + public void callback() { + this.repaint(); + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartDesignerActivator.java b/designer-chart/src/main/java/com/fr/design/chart/ChartDesignerActivator.java index 65d6abd64..098b965d0 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartDesignerActivator.java +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartDesignerActivator.java @@ -39,6 +39,7 @@ public class ChartDesignerActivator extends Activator implements Prepare { DesignModuleFactory.registerChartComponentClass(ChartComponent.class); DesignModuleFactory.registerChartDialogClass(ChartDialog.class); + DesignModuleFactory.registerAutoChartDialogClass(AutoChartDialog.class); DesignModuleFactory.registerChartPropertyPaneClass(ChartPropertyPane.class); diff --git a/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java b/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java index 623271873..9c2b730ab 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java +++ b/designer-chart/src/main/java/com/fr/design/chart/ChartDialog.java @@ -10,6 +10,7 @@ import com.fr.third.joda.time.DateTime; import javax.swing.JPanel; import java.awt.BorderLayout; +import java.awt.Component; import java.awt.Dialog; import java.awt.FlowLayout; import java.awt.Frame; @@ -18,15 +19,18 @@ import java.awt.event.ActionListener; /** * 封装一层 图表新建的对话框, 配合属性表确定: 先单独只要一种图表类型的对话框. + * * @author kunsnat E-mail:kunsnat@gmail.com * @version 创建时间:2013-1-7 下午07:29:15 */ public class ChartDialog extends MiddleChartDialog { - - private BaseChartCollection cc; - - private UIButton ok; - private UIButton cancel; + + private BaseChartCollection cc; + + private UIButton ok; + private UIButton cancel; + private ChartTypePane chartTypePane; + private String createTime; public ChartDialog(Frame owner) { super(owner); @@ -37,57 +41,62 @@ public class ChartDialog extends MiddleChartDialog { super(owner); initComponent(); } - - private void initComponent() { - final String createTime = DateTime.now().toString("yyyy-MM-dd HH:mm:ss"); - this.setModal(true); - this.setLayout(new BorderLayout()); - final ChartTypePane chartTypePane = new ChartTypePane(); - setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_M_Popup_Chart_Type")); + private void initComponent() { + createTime = DateTime.now().toString("yyyy-MM-dd HH:mm:ss"); + this.setModal(true); + this.setLayout(new BorderLayout()); + setTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_M_Popup_Chart_Type")); this.applyClosingAction(); this.applyEscapeAction(); - this.setBasicDialogSize(BasicDialog.DEFAULT); - this.add(chartTypePane, BorderLayout.CENTER); - - JPanel buttonPane = new JPanel(); - buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); - - this.add(buttonPane, BorderLayout.SOUTH); - - ok = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_OK")); - cancel = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel")); - - buttonPane.add(ok); - buttonPane.add(cancel); - - ok.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - chartTypePane.update((ChartCollection)cc, createTime); - doOK(); - } - }); - - cancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - doCancel(); - } - }); - - GUICoreUtils.setWindowCenter(getOwner(), this); + this.setBasicDialogSize(BasicDialog.DEFAULT); + this.add(initCenterPane(), BorderLayout.CENTER); + + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + this.add(buttonPane, BorderLayout.SOUTH); + + ok = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_OK")); + cancel = new UIButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Cancel")); + + ok.addActionListener(getActionListener()); + cancel.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doCancel(); + } + }); + + buttonPane.add(ok); + buttonPane.add(cancel); + + GUICoreUtils.setWindowCenter(getOwner(), this); + } + + protected Component initCenterPane() { + chartTypePane = new ChartTypePane(); + return chartTypePane; + } + + protected ActionListener getActionListener() { + return new ActionListener() { + public void actionPerformed(ActionEvent e) { + chartTypePane.update((ChartCollection) cc, createTime); + doOK(); + } + }; } /** * 不处理 */ - public void checkValid() throws Exception { - - } - - /** - * 更新新建的图表 ChartCollection - */ + public void checkValid() throws Exception { + + } + + /** + * 更新新建的图表 ChartCollection + */ public void populate(BaseChartCollection cc) { if (cc == null) { return; diff --git a/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java b/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java index aa7f9107b..85b13aef7 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java +++ b/designer-chart/src/main/java/com/fr/design/chart/gui/ChartComponent.java @@ -140,6 +140,9 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene public void paintComponent(Graphics g) { // super.paintComponent(g); + if(chartCollection4Design.getChartCount() == 0) { + return; + } Graphics2D g2d = (Graphics2D) g; diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java index 6c7edc2d2..6719401bb 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/ChartTypePane.java @@ -6,28 +6,36 @@ import com.fr.chartx.attr.ChartProvider; import com.fr.design.ChartTypeInterfaceManager; import com.fr.design.beans.FurtherBasicBeanPane; import com.fr.design.dialog.BasicScrollPane; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.chart.MiddleChartDialog; import com.fr.design.gui.frpane.UIComboBoxPane; +import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.chart.AbstractChartAttrPane; import com.fr.design.mainframe.chart.ChartEditPane; import com.fr.design.mainframe.chart.PaneTitleConstants; import com.fr.design.mainframe.chart.gui.item.FlexibleComboBox; import com.fr.design.mainframe.chart.gui.item.ItemEventType; import com.fr.design.mainframe.chart.gui.type.AbstractChartTypePane; +import com.fr.design.module.DesignModuleFactory; import com.fr.general.ComparatorUtils; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; import javax.swing.JPanel; -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; /** * 图表 属性表, 类型选择 界面. @@ -39,11 +47,12 @@ public class ChartTypePane extends AbstractChartAttrPane{ private ChartTypeButtonPane buttonPane; private ChartEditPane editPane; private ChartCollection editingCollection; + private UIButton autoButton; @Override protected JPanel createContentPane() { JPanel content = new JPanel(new BorderLayout()); - + buttonPane = new ChartTypeButtonPane(this); content.add(buttonPane, BorderLayout.NORTH); @@ -76,9 +85,14 @@ public class ChartTypePane extends AbstractChartAttrPane{ } }; content.add(scrollPane, BorderLayout.CENTER); - + buttonPane.setEditingChartPane(chartTypeComBox); - + + if(ChartTypeManager.AUTO_CHART) { + initAutoButton(); + content.add(autoButton, BorderLayout.SOUTH); + } + return content; } @@ -97,6 +111,25 @@ public class ChartTypePane extends AbstractChartAttrPane{ return PaneTitleConstants.CHART_TYPE_TITLE; } + private void initAutoButton(){ + //TODO @Bjorn 视觉样式优化 + autoButton = new UIButton(Toolkit.i18nText("Fine-Design_Chart_M_Popup_Auto_Chart_Type")); + autoButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final MiddleChartDialog autoChartDialog = DesignModuleFactory.getAutoChartDialog(DesignerContext.getDesignerFrame()); + autoChartDialog.populate(editingCollection); + autoChartDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + populate(editingCollection); + } + }); + autoChartDialog.setVisible(true); + } + }); + } + class ComboBoxPane extends UIComboBoxPane { private Map>> allChartTypePane; diff --git a/designer-chart/src/main/resources/com/fr/design/images/form/toolbar/auto_chart.png b/designer-chart/src/main/resources/com/fr/design/images/form/toolbar/auto_chart.png new file mode 100644 index 000000000..e07ad0583 Binary files /dev/null and b/designer-chart/src/main/resources/com/fr/design/images/form/toolbar/auto_chart.png differ diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java new file mode 100644 index 000000000..81d0d6609 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XAutoChartCreator.java @@ -0,0 +1,113 @@ +package com.fr.design.designer.creator; + +import com.fr.base.GraphHelper; +import com.fr.base.chart.BaseChartCollection; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.gui.chart.MiddleChartComponent; +import com.fr.design.gui.chart.MiddleChartDialog; +import com.fr.design.mainframe.BaseJForm; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.EditingMouseListener; +import com.fr.design.mainframe.FormDesigner; +import com.fr.design.module.DesignModuleFactory; +import com.fr.form.ui.ChartAutoEditor; +import com.fr.stable.bridge.StableFactory; + +import javax.swing.JComponent; +import javax.swing.JPanel; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Rectangle; +import java.awt.event.MouseEvent; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-05-26 + */ +public class XAutoChartCreator extends XChartEditor { + + private MiddleChartDialog autoChartDialog; + + private EditingMouseListener editingMouseListener; + + public XAutoChartCreator(ChartAutoEditor editor, Dimension size) { + super(editor, size); + } + + /** + * 返回组件默认名 + * + * @return 组件类名(小写) + */ + public String createDefaultName() { + return "auto_chart"; + } + + @Override + public ChartAutoEditor toData() { + return (ChartAutoEditor) data; + } + + + /** + * 点击选中的时候, 刷新界面 + * 右键 reset之后, 触发事件 populate此方法 + * + * @param jform 表单 + * @param formDesigner 表单设计器 + * @return 控件. + */ + public JComponent createToolPane(final BaseJForm jform, final FormDesigner formDesigner) { + if (toData().isChartSelect()) { + return super.createToolPane(jform, formDesigner); + } + if (isEditing) { + if (autoChartDialog != null && autoChartDialog.isVisible()) { + return new JPanel(); + } + final BaseChartCollection chartCollection = (BaseChartCollection) StableFactory.createXmlObject(BaseChartCollection.XML_TAG); + autoChartDialog = DesignModuleFactory.getAutoChartDialog(DesignerContext.getDesignerFrame()); + autoChartDialog.populate(chartCollection); + autoChartDialog.addDialogActionListener(new DialogActionAdapter() { + @Override + public void doOk() { + initChart(autoChartDialog.getChartCollection()); + formDesigner.fireTargetModified(); + } + @Override + public void doCancel() { + editingMouseListener.stopEditing(); + } + }); + autoChartDialog.setVisible(true); + } + return toData().isChartSelect() ? super.createToolPane(jform, formDesigner) : new JPanel(); + } + + /** + * 响应点击事件 + * + * @param editingMouseListener 鼠标点击,位置处理器 + * @param e 鼠标点击事件 + */ + public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e) { + this.editingMouseListener = editingMouseListener; + super.respondClick(editingMouseListener, e); + } + + + public void paint(Graphics g) { + //TODO @Bjorn 视觉样式优化 + g.setColor(Color.RED); + GraphHelper.fill(g, new Rectangle(0, 0, getWidth(), getHeight())); + super.paint(g); + } + + private void initChart(BaseChartCollection chartCollection) { + ((MiddleChartComponent) getDesignerEditor().getEditorTarget()).populate(chartCollection); + this.toData().resetChangeChartCollection(chartCollection); + this.toData().setChartSelect(true); + } +} diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java index ecf623477..b0f6e1158 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XChartEditor.java @@ -28,328 +28,333 @@ import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import java.beans.IntrospectionException; import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.event.MouseEvent; -import java.beans.IntrospectionException; /** * form中的图表按钮弹出的控件, 创建初始化图表内容. * * @author kunsnat E-mail:kunsnat@gmail.com * @version 创建时间:2013-7-5 上午10:28:30 - * 类说明 + * 类说明 */ public class XChartEditor extends XBorderStyleWidgetCreator { - private static final long serialVersionUID = -7009439442104836657L; - private static final int BORDER_WIDTH = 2; - //具体来说是DesignerEditor - private DesignerEditor designerEditor; - // private DesignerEditor designerEditor; - //marro:无奈的属性,暂时想不出好办法 - private boolean isRefreshing = false; - - private boolean isEditing = false; - - private boolean isHovering = false; - private static final Color OUTER_BORDER_COLOR = new Color(65, 155, 249, 30); - private static final Color INNER_BORDER_COLOR = new Color(65, 155, 249); - - public XChartEditor(BaseChartEditor editor) { - this(editor, new Dimension(250, 150)); - } - - public XChartEditor(BaseChartEditor editor, Dimension size) { - super((Widget)editor, size); - } - - @Override - public String getIconPath() { - return super.getIconPath(); - } - - - @Override - protected String getIconName() { - return "Chart.png"; - } - - /** - * 返回组件默认名 - * @return 组件类名(小写) - */ - public String createDefaultName() { - return "chart"; - } - - /** - * 是否支持设置标题 - * @return 是返回true - */ - public boolean hasTitleStyle() { - return true; - } - - @Override - public void stopEditing() { - isEditing = false; - } - - /** - * 得到属性名 - * @return 属性名 - * @throws java.beans.IntrospectionException - */ - public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { - return new CRPropertyDescriptor[] { - new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Toolkit.i18nText("Fine-Design_Form_Form_Widget_Name")), - new CRPropertyDescriptor("visible", this.data.getClass()).setI18NName( - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Visible")).setPropertyChangeListener(new PropertyChangeAdapter() { - - @Override - public void propertyChange() { - makeVisible(toData().isVisible());} - }), - new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass( - WLayoutBorderStyleEditor.class).setI18NName( - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced") - .setPropertyChangeListener(new PropertyChangeAdapter() { - - @Override - public void propertyChange() { - initStyle(); - } - }), - }; - } - - /** - * 该组件是否可以拖入参数面板 - * @return 是则返回true - */ - public boolean canEnterIntoParaPane(){ - return false; - } - - - /** - * 编辑状态的时候需要重新绘制下边框 - * - */ - @Override - public void paintBorder(Graphics g, Rectangle bounds){ - if(isEditing){ - g.setColor(OUTER_BORDER_COLOR); - GraphHelper.draw(g, new Rectangle(bounds.x - BORDER_WIDTH, bounds.y - BORDER_WIDTH, bounds.width + BORDER_WIDTH + 1, bounds.height + BORDER_WIDTH + 1), Constants.LINE_LARGE); - }else if(!isHovering){ - super.paintBorder(g, bounds); - } - } - - - /** - * 返回设计器的Editor - */ - public DesignerEditor getDesignerEditor() { - return designerEditor; - } - - @Override - protected void initXCreatorProperties() { - super.initXCreatorProperties(); - initBorderStyle(); - BaseChartCollection collection = ((BaseChartEditor) data).getChartCollection(); - isRefreshing = true; - ((MiddleChartComponent) designerEditor.getEditorTarget()).populate(collection); - isRefreshing = false; - } - - /** - * 点击选中的时候, 刷新界面 - * 右键 reset之后, 触发事件 populate此方法 - * - * @param jform 表单 - * @param formDesigner 表单设计器 - * @return 控件. - */ - public JComponent createToolPane(final BaseJForm jform, final FormDesigner formDesigner) { - MiddleChartComponent middleChartComponent = getDesignerEditorTarget(); - if (null != middleChartComponent) { - middleChartComponent.addStopEditingListener(new PropertyChangeAdapter() { - public void propertyChange() { - JComponent pane = jform.getEditingPane(); - if (pane instanceof BaseChartPropertyPane) { - ((BaseChartPropertyPane) pane).setSupportCellData(true); - MiddleChartComponent middleChartComponent = getDesignerEditorTarget(); - if (null != middleChartComponent) { - ((BaseChartPropertyPane) pane).populateChartPropertyPane(middleChartComponent.update(), formDesigner); - } - } - } - }); - } - if (isEditing){ - final BaseChartPropertyPane propertyPane = DesignModuleFactory.getChartPropertyPane(); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - if (getDesignerEditor().getEditorTarget() != null) { - propertyPane.setSupportCellData(true); - MiddleChartComponent middleChartComponent = getDesignerEditorTarget(); - if (null != middleChartComponent) { - propertyPane.populateChartPropertyPane(middleChartComponent.update(), formDesigner); - } - } - } - }); - return (JComponent)propertyPane; - } - else{ - return (JComponent)DesignModuleFactory.getWidgetPropertyPane(formDesigner); - } - } - - private MiddleChartComponent getDesignerEditorTarget() { - MiddleChartComponent bcc = null; - if (getDesignerEditor().getEditorTarget() instanceof MiddleChartComponent) { - bcc = (MiddleChartComponent) getDesignerEditor().getEditorTarget(); - } - return bcc; - } - - /** - * 渲染Painter - */ - public void paint(Graphics g) { - designerEditor.paintEditor(g, this.getSize()); - super.paint(g); - if(isEditing){ - g.setColor(INNER_BORDER_COLOR); - GraphHelper.draw(g, new Rectangle(0, 0, getWidth(), getHeight()), Constants.LINE_MEDIUM); - } - } - - /** - * 初始化Editor大小. - * - * @return 返回大小. - */ - public Dimension initEditorSize() { - return BORDER_PREFERRED_SIZE; - } - - /** - * 响应点击事件 - * - * @param editingMouseListener 鼠标点击,位置处理器 - * @param e 鼠标点击事件 - */ - public void respondClick(EditingMouseListener editingMouseListener,MouseEvent e){ - FormDesigner designer = editingMouseListener.getDesigner(); - SelectionModel selectionModel = editingMouseListener.getSelectionModel(); - isEditing = e.getButton() == MouseEvent.BUTTON1 && - (e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR); - displayCoverPane(!isEditing); - selectionModel.selectACreatorAtMouseEvent(e); - - if (editingMouseListener.stopEditing()) { - if (this != (XCreator)designer.getRootComponent()) { - ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); - editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter); - } - } - HelpDialogManager.getInstance().setPane(coverPanel); - if (this.isHelpBtnOnFocus()) { - coverPanel.setMsgDisplay(e); - } - } - - @Override - protected JComponent initEditor() { - if (designerEditor == null) { - final MiddleChartComponent chartComponent = DesignModuleFactory.getChartComponent(((BaseChartEditor) data).getChartCollection()); - if (chartComponent != null) { - JComponent jChart = chartComponent; - jChart.setBorder(BorderFactory.createLineBorder(Color.lightGray)); - designerEditor = new DesignerEditor(jChart); - chartComponent.addStopEditingListener(designerEditor); - designerEditor.addPropertyChangeListener(new PropertyChangeAdapter() { - public void propertyChange() { - if (!isRefreshing) { - ((BaseChartEditor) data).resetChangeChartCollection(chartComponent.update()); - } - } - }); - } - } - - if (editor == null) { - setBorder(DEFALUTBORDER); - editor = new JPanel(); - editor.setBackground(null); - editor.setLayout(null); - editor.setOpaque(false); - - coverPanel = new CoverReportPane(); - coverPanel.setPreferredSize(this.getPreferredSize()); - coverPanel.setBounds(this.getBounds()); - - editor.add(coverPanel); - coverPanel.setVisible(false); - } - return editor; - } - - /** - * 是否展现覆盖的pane - * @param display 是否 - */ - public void displayCoverPane(boolean display){ - isHovering = display; - coverPanel.setVisible(display); - coverPanel.setPreferredSize(editor.getPreferredSize()); - coverPanel.setBounds(editor.getBounds()); - editor.repaint(); - } - - public JComponent getCoverPane(){ - return coverPanel; - } - - /** - * 是否支持设置可用 - * return boolean - */ - public boolean supportSetEnable(){ - return false; - } - - /** - * data属性改变触发其他操作 - * - */ - public void firePropertyChange(){ - initStyle(); - } - - @Override - public WidgetPropertyUIProvider[] getWidgetPropertyUIProviders() { - return new WidgetPropertyUIProvider[]{ new ChartEditorPropertyUI(this)}; - } - - /** - * 是否支持共享-现只支持报表块、图表、tab块、绝对布局 - * @return - */ - public boolean isSupportShared() { - return true; - } - - @Override - public boolean supportMobileStyle() { - return false; - } + private static final long serialVersionUID = -7009439442104836657L; + private static final int BORDER_WIDTH = 2; + //具体来说是DesignerEditor + private DesignerEditor designerEditor; + // private DesignerEditor designerEditor; + //marro:无奈的属性,暂时想不出好办法 + private boolean isRefreshing = false; + + protected boolean isEditing = false; + + private boolean isHovering = false; + private static final Color OUTER_BORDER_COLOR = new Color(65, 155, 249, 30); + private static final Color INNER_BORDER_COLOR = new Color(65, 155, 249); + + public XChartEditor(BaseChartEditor editor) { + this(editor, new Dimension(250, 150)); + } + + public XChartEditor(BaseChartEditor editor, Dimension size) { + super((Widget) editor, size); + } + + @Override + public String getIconPath() { + return super.getIconPath(); + } + + + @Override + protected String getIconName() { + return "Chart.png"; + } + + /** + * 返回组件默认名 + * + * @return 组件类名(小写) + */ + public String createDefaultName() { + return "chart"; + } + + /** + * 是否支持设置标题 + * + * @return 是返回true + */ + public boolean hasTitleStyle() { + return true; + } + + @Override + public void stopEditing() { + isEditing = false; + } + + + /** + * 得到属性名 + * + * @return 属性名 + * @throws java.beans.IntrospectionException + */ + public CRPropertyDescriptor[] supportedDescriptor() throws IntrospectionException { + return new CRPropertyDescriptor[]{ + new CRPropertyDescriptor("widgetName", this.data.getClass()).setI18NName(Toolkit.i18nText("Fine-Design_Form_Form_Widget_Name")), + new CRPropertyDescriptor("visible", this.data.getClass()).setI18NName( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Visible")).setPropertyChangeListener(new PropertyChangeAdapter() { + + @Override + public void propertyChange() { + makeVisible(toData().isVisible()); + } + }), + new CRPropertyDescriptor("borderStyle", this.data.getClass()).setEditorClass( + WLayoutBorderStyleEditor.class).setI18NName( + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Style")).putKeyValue(XCreatorConstants.PROPERTY_CATEGORY, "Fine-Design_Basic_Advanced") + .setPropertyChangeListener(new PropertyChangeAdapter() { + + @Override + public void propertyChange() { + initStyle(); + } + }), + }; + } + + /** + * 该组件是否可以拖入参数面板 + * + * @return 是则返回true + */ + public boolean canEnterIntoParaPane() { + return false; + } + + + /** + * 编辑状态的时候需要重新绘制下边框 + */ + @Override + public void paintBorder(Graphics g, Rectangle bounds) { + if (isEditing) { + g.setColor(OUTER_BORDER_COLOR); + GraphHelper.draw(g, new Rectangle(bounds.x - BORDER_WIDTH, bounds.y - BORDER_WIDTH, bounds.width + BORDER_WIDTH + 1, bounds.height + BORDER_WIDTH + 1), Constants.LINE_LARGE); + } else if (!isHovering) { + super.paintBorder(g, bounds); + } + } + + + /** + * 返回设计器的Editor + */ + public DesignerEditor getDesignerEditor() { + return designerEditor; + } + + @Override + protected void initXCreatorProperties() { + super.initXCreatorProperties(); + initBorderStyle(); + BaseChartCollection collection = ((BaseChartEditor) data).getChartCollection(); + isRefreshing = true; + ((MiddleChartComponent) designerEditor.getEditorTarget()).populate(collection); + isRefreshing = false; + } + + /** + * 点击选中的时候, 刷新界面 + * 右键 reset之后, 触发事件 populate此方法 + * + * @param jform 表单 + * @param formDesigner 表单设计器 + * @return 控件. + */ + public JComponent createToolPane(final BaseJForm jform, final FormDesigner formDesigner) { + MiddleChartComponent middleChartComponent = getDesignerEditorTarget(); + if (null != middleChartComponent) { + middleChartComponent.addStopEditingListener(new PropertyChangeAdapter() { + public void propertyChange() { + JComponent pane = jform.getEditingPane(); + if (pane instanceof BaseChartPropertyPane) { + ((BaseChartPropertyPane) pane).setSupportCellData(true); + MiddleChartComponent middleChartComponent = getDesignerEditorTarget(); + if (null != middleChartComponent) { + ((BaseChartPropertyPane) pane).populateChartPropertyPane(middleChartComponent.update(), formDesigner); + } + } + } + }); + } + if (isEditing) { + final BaseChartPropertyPane propertyPane = DesignModuleFactory.getChartPropertyPane(); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (getDesignerEditor().getEditorTarget() != null) { + propertyPane.setSupportCellData(true); + MiddleChartComponent middleChartComponent = getDesignerEditorTarget(); + if (null != middleChartComponent) { + propertyPane.populateChartPropertyPane(middleChartComponent.update(), formDesigner); + } + } + } + }); + return (JComponent) propertyPane; + } else { + return (JComponent) DesignModuleFactory.getWidgetPropertyPane(formDesigner); + } + } + + private MiddleChartComponent getDesignerEditorTarget() { + MiddleChartComponent bcc = null; + if (getDesignerEditor().getEditorTarget() instanceof MiddleChartComponent) { + bcc = (MiddleChartComponent) getDesignerEditor().getEditorTarget(); + } + return bcc; + } + + /** + * 渲染Painter + */ + public void paint(Graphics g) { + designerEditor.paintEditor(g, this.getSize()); + super.paint(g); + if (isEditing) { + g.setColor(INNER_BORDER_COLOR); + GraphHelper.draw(g, new Rectangle(0, 0, getWidth(), getHeight()), Constants.LINE_MEDIUM); + } + } + + /** + * 初始化Editor大小. + * + * @return 返回大小. + */ + public Dimension initEditorSize() { + return BORDER_PREFERRED_SIZE; + } + + /** + * 响应点击事件 + * + * @param editingMouseListener 鼠标点击,位置处理器 + * @param e 鼠标点击事件 + */ + public void respondClick(EditingMouseListener editingMouseListener, MouseEvent e) { + FormDesigner designer = editingMouseListener.getDesigner(); + SelectionModel selectionModel = editingMouseListener.getSelectionModel(); + isEditing = e.getButton() == MouseEvent.BUTTON1 && + (e.getClickCount() == 2 || designer.getCursor().getType() == Cursor.HAND_CURSOR); + displayCoverPane(!isEditing); + selectionModel.selectACreatorAtMouseEvent(e); + + if (editingMouseListener.stopEditing()) { + if (this != (XCreator) designer.getRootComponent()) { + ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this); + editingMouseListener.startEditing(this, isEditing ? adapter.getDesignerEditor() : null, adapter); + } + } + HelpDialogManager.getInstance().setPane(coverPanel); + if (this.isHelpBtnOnFocus()) { + coverPanel.setMsgDisplay(e); + } + } + + @Override + protected JComponent initEditor() { + if (designerEditor == null) { + final MiddleChartComponent chartComponent = DesignModuleFactory.getChartComponent(((BaseChartEditor) data).getChartCollection()); + if (chartComponent != null) { + JComponent jChart = chartComponent; + jChart.setBorder(BorderFactory.createLineBorder(Color.lightGray)); + designerEditor = new DesignerEditor(jChart); + chartComponent.addStopEditingListener(designerEditor); + designerEditor.addPropertyChangeListener(new PropertyChangeAdapter() { + public void propertyChange() { + if (!isRefreshing) { + ((BaseChartEditor) data).resetChangeChartCollection(chartComponent.update()); + } + } + }); + } + } + + if (editor == null) { + setBorder(DEFALUTBORDER); + editor = new JPanel(); + editor.setBackground(null); + editor.setLayout(null); + editor.setOpaque(false); + + coverPanel = new CoverReportPane(); + coverPanel.setPreferredSize(this.getPreferredSize()); + coverPanel.setBounds(this.getBounds()); + + editor.add(coverPanel); + coverPanel.setVisible(false); + } + return editor; + } + + /** + * 是否展现覆盖的pane + * + * @param display 是否 + */ + public void displayCoverPane(boolean display) { + isHovering = display; + coverPanel.setVisible(display); + coverPanel.setPreferredSize(editor.getPreferredSize()); + coverPanel.setBounds(editor.getBounds()); + editor.repaint(); + } + + public JComponent getCoverPane() { + return coverPanel; + } + + /** + * 是否支持设置可用 + * return boolean + */ + public boolean supportSetEnable() { + return false; + } + + /** + * data属性改变触发其他操作 + */ + public void firePropertyChange() { + initStyle(); + } + + @Override + public WidgetPropertyUIProvider[] getWidgetPropertyUIProviders() { + return new WidgetPropertyUIProvider[]{new ChartEditorPropertyUI(this)}; + } + + /** + * 是否支持共享-现只支持报表块、图表、tab块、绝对布局 + * + * @return + */ + public boolean isSupportShared() { + return true; + } + + @Override + public boolean supportMobileStyle() { + return false; + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java index d14780054..1a2df828c 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java @@ -19,6 +19,7 @@ import com.fr.form.parameter.FormSubmitButton; import com.fr.form.ui.Button; import com.fr.form.ui.CardAddButton; import com.fr.form.ui.CardSwitchButton; +import com.fr.form.ui.ChartAutoEditor; import com.fr.form.ui.CheckBox; import com.fr.form.ui.CheckBoxGroup; import com.fr.form.ui.ComboBox; @@ -174,6 +175,7 @@ public class XCreatorUtils { private static void putExtraEditor() { if (DesignModuleFactory.getChartEditorClass() != null) { objectMap.put(DesignModuleFactory.getChartEditorClass(), XChartEditor.class); + objectMap.put(ChartAutoEditor.class, XAutoChartCreator.class); } } diff --git a/designer-realize/src/main/java/com/fr/design/actions/insert/cell/AutoChartCellAction.java b/designer-realize/src/main/java/com/fr/design/actions/insert/cell/AutoChartCellAction.java new file mode 100644 index 000000000..6ee1a74c4 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/insert/cell/AutoChartCellAction.java @@ -0,0 +1,58 @@ +package com.fr.design.actions.insert.cell; + +import com.fr.base.BaseUtils; +import com.fr.chart.chartattr.AutoChartCollection; +import com.fr.design.actions.core.WorkBookSupportable; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; + +import javax.swing.KeyStroke; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-05-28 + */ +public class AutoChartCellAction extends AbstractCellAction implements WorkBookSupportable { + + public AutoChartCellAction() { + initAction(); + } + + public AutoChartCellAction(ElementCasePane t) { + super(t); + initAction(); + } + + private void initAction() { + this.setMenuKeySet(INSERT_AUTO_CHART); + this.setName(getMenuKeySet().getMenuKeySetName() + "..."); + this.setMnemonic(getMenuKeySet().getMnemonic()); + //TODO @Bjorn 视觉样式优化icon + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/auto_chart.png")); + } + + public static final MenuKeySet INSERT_AUTO_CHART = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'M'; + } + + @Override + public String getMenuName() { + return Toolkit.i18nText("Fine-Design_Report_M_Insert_Auto_Chart"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + + @Override + public Class getCellValueClass() { + return AutoChartCollection.class; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/insert/flot/AutoChartFloatAction.java b/designer-realize/src/main/java/com/fr/design/actions/insert/flot/AutoChartFloatAction.java new file mode 100644 index 000000000..bb0389731 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/insert/flot/AutoChartFloatAction.java @@ -0,0 +1,54 @@ +package com.fr.design.actions.insert.flot; + +import com.fr.base.BaseUtils; +import com.fr.design.gui.chart.MiddleChartDialog; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.menu.MenuKeySet; +import com.fr.design.module.DesignModuleFactory; + +import javax.swing.KeyStroke; +import java.awt.Window; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-05-28 + */ +public class AutoChartFloatAction extends ChartFloatAction { + + /** + * 构造函数 图表插入悬浮元素 + */ + public AutoChartFloatAction(ElementCasePane t) { + super(t); + } + + protected void init() { + this.setMenuKeySet(FLOAT_INSERT_AUTO_CHART); + this.setName(getMenuKeySet().getMenuKeySetName()); + this.setMnemonic(getMenuKeySet().getMnemonic()); + this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/auto_chart.png")); + } + + public static final MenuKeySet FLOAT_INSERT_AUTO_CHART = new MenuKeySet() { + @Override + public char getMnemonic() { + return 'M'; + } + + @Override + public String getMenuName() { + return Toolkit.i18nText("Fine-Design_Report_M_Insert_Auto_Chart"); + } + + @Override + public KeyStroke getKeyStroke() { + return null; + } + }; + + protected MiddleChartDialog getMiddleChartDialog(Window window) { + return DesignModuleFactory.getAutoChartDialog(window); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/insert/flot/ChartFloatAction.java b/designer-realize/src/main/java/com/fr/design/actions/insert/flot/ChartFloatAction.java index 39b11d4c2..1d1e07c62 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/insert/flot/ChartFloatAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/insert/flot/ChartFloatAction.java @@ -27,6 +27,7 @@ import com.fr.stable.unit.OLDPIX; import javax.swing.KeyStroke; import java.awt.Color; +import java.awt.Window; /** * 图表插入悬浮元素的操作. @@ -40,6 +41,10 @@ public class ChartFloatAction extends ElementCaseAction { */ public ChartFloatAction(ElementCasePane t) { super(t); + init(); + } + + protected void init() { this.setMenuKeySet(FLOAT_INSERT_CHART); this.setName(getMenuKeySet().getMenuKeySetName()); this.setMnemonic(getMenuKeySet().getMnemonic()); @@ -78,7 +83,7 @@ public class ChartFloatAction extends ElementCaseAction { reportPane.stopEditing(); final BaseChartCollection cc = (BaseChartCollection) StableFactory.createXmlObject(BaseChartCollection.XML_TAG); - final MiddleChartDialog chartDialog = DesignModuleFactory.getChartDialog(DesignerContext.getDesignerFrame()); + final MiddleChartDialog chartDialog = getMiddleChartDialog(DesignerContext.getDesignerFrame()); chartDialog.populate(cc); chartDialog.addDialogActionListener(new DialogActionAdapter() { @Override @@ -124,4 +129,8 @@ public class ChartFloatAction extends ElementCaseAction { chartDialog.setVisible(true); return isRecordNeeded; } + + protected MiddleChartDialog getMiddleChartDialog(Window window) { + return DesignModuleFactory.getChartDialog(window); + } } diff --git a/designer-realize/src/main/java/com/fr/design/cell/editor/AutoChartCellEditor.java b/designer-realize/src/main/java/com/fr/design/cell/editor/AutoChartCellEditor.java new file mode 100644 index 000000000..410248766 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/cell/editor/AutoChartCellEditor.java @@ -0,0 +1,24 @@ +package com.fr.design.cell.editor; + +import com.fr.design.gui.chart.MiddleChartDialog; +import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.module.DesignModuleFactory; +import com.fr.report.elementcase.TemplateElementCase; + +import java.awt.Window; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-05-28 + */ +public class AutoChartCellEditor extends ChartCellEditor { + + public AutoChartCellEditor(ElementCasePane ePane) { + super(ePane); + } + + protected MiddleChartDialog getMiddleChartDialog(Window window) { + return DesignModuleFactory.getAutoChartDialog(window); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/cell/editor/AutoChartFloatEditor.java b/designer-realize/src/main/java/com/fr/design/cell/editor/AutoChartFloatEditor.java new file mode 100644 index 000000000..19c8788d0 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/cell/editor/AutoChartFloatEditor.java @@ -0,0 +1,18 @@ +package com.fr.design.cell.editor; + +import com.fr.design.gui.chart.MiddleChartDialog; +import com.fr.design.module.DesignModuleFactory; + +import java.awt.Window; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-05-28 + */ +public class AutoChartFloatEditor extends ChartFloatEditor { + + protected MiddleChartDialog getMiddleChartDialog(Window window) { + return DesignModuleFactory.getAutoChartDialog(window); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/cell/editor/ChartCellEditor.java b/designer-realize/src/main/java/com/fr/design/cell/editor/ChartCellEditor.java index 2774c8392..67ccc4876 100644 --- a/designer-realize/src/main/java/com/fr/design/cell/editor/ChartCellEditor.java +++ b/designer-realize/src/main/java/com/fr/design/cell/editor/ChartCellEditor.java @@ -1,21 +1,21 @@ package com.fr.design.cell.editor; -import java.awt.Component; - -import javax.swing.SwingUtilities; - import com.fr.base.chart.BaseChartCollection; +import com.fr.design.dialog.DialogActionListener; import com.fr.design.gui.chart.MiddleChartComponent; import com.fr.design.gui.chart.MiddleChartDialog; -import com.fr.design.module.DesignModuleFactory; -import com.fr.design.dialog.DialogActionListener; import com.fr.design.mainframe.ElementCasePane; +import com.fr.design.module.DesignModuleFactory; import com.fr.grid.Grid; import com.fr.report.cell.TemplateCellElement; import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.bridge.StableFactory; import com.fr.stable.core.PropertyChangeAdapter; +import javax.swing.SwingUtilities; +import java.awt.Component; +import java.awt.Window; + /** * CellEditor used to edit Chart object. */ @@ -67,7 +67,7 @@ public class ChartCellEditor extends AbstractCellEditor implements DialogActionL this.chartCellEditorDialog = null; return glyphComponent; } - this.chartCellEditorDialog = DesignModuleFactory.getChartDialog(SwingUtilities.getWindowAncestor(grid)); + this.chartCellEditorDialog = getMiddleChartDialog(SwingUtilities.getWindowAncestor(grid)); this.chartCellEditorDialog.addDialogActionListener(this); BaseChartCollection cc = (BaseChartCollection)StableFactory.createXmlObject(BaseChartCollection.XML_TAG); this.chartCellEditorDialog.populate(cc); @@ -84,4 +84,8 @@ public class ChartCellEditor extends AbstractCellEditor implements DialogActionL public void doCancel() { cancelCellEditing(); } + + protected MiddleChartDialog getMiddleChartDialog(Window window) { + return DesignModuleFactory.getChartDialog(window); + } } \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/cell/editor/ChartFloatEditor.java b/designer-realize/src/main/java/com/fr/design/cell/editor/ChartFloatEditor.java index 90adbb98d..5087ad4ae 100644 --- a/designer-realize/src/main/java/com/fr/design/cell/editor/ChartFloatEditor.java +++ b/designer-realize/src/main/java/com/fr/design/cell/editor/ChartFloatEditor.java @@ -1,20 +1,20 @@ package com.fr.design.cell.editor; -import java.awt.Component; - -import javax.swing.SwingUtilities; - import com.fr.base.chart.BaseChartCollection; +import com.fr.design.dialog.DialogActionListener; import com.fr.design.gui.chart.MiddleChartComponent; import com.fr.design.gui.chart.MiddleChartDialog; import com.fr.design.module.DesignModuleFactory; -import com.fr.design.dialog.DialogActionListener; import com.fr.grid.Grid; import com.fr.report.cell.FloatElement; import com.fr.stable.StringUtils; import com.fr.stable.bridge.StableFactory; import com.fr.stable.core.PropertyChangeAdapter; +import javax.swing.SwingUtilities; +import java.awt.Component; +import java.awt.Window; + public class ChartFloatEditor extends AbstractFloatEditor implements DialogActionListener { private MiddleChartDialog chartFloatEditorDialog = null; @@ -65,7 +65,7 @@ public class ChartFloatEditor extends AbstractFloatEditor implements DialogActio } return glyphComponent; } - this.chartFloatEditorDialog = DesignModuleFactory.getChartDialog(SwingUtilities.getWindowAncestor(grid)); + this.chartFloatEditorDialog = getMiddleChartDialog(SwingUtilities.getWindowAncestor(grid)); this.chartFloatEditorDialog.addDialogActionListener(this); BaseChartCollection cc = (BaseChartCollection)StableFactory.createXmlObject(BaseChartCollection.XML_TAG); this.chartFloatEditorDialog.populate(cc); @@ -82,4 +82,8 @@ public class ChartFloatEditor extends AbstractFloatEditor implements DialogActio public void doCancel() { cancelFloatEditing(); } + + protected MiddleChartDialog getMiddleChartDialog(Window window) { + return DesignModuleFactory.getChartDialog(window); + } } \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java index c9c906618..24178bcfd 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/ElementCasePane.java @@ -9,6 +9,7 @@ import com.fr.base.Formula; import com.fr.base.ScreenResolution; import com.fr.base.Style; import com.fr.base.vcs.DesignerMode; +import com.fr.chart.chartattr.AutoChartCollection; import com.fr.design.DesignState; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; @@ -52,6 +53,8 @@ import com.fr.design.cell.bar.DynamicScrollBar; import com.fr.design.cell.clipboard.CellElementsClip; import com.fr.design.cell.clipboard.ElementsTransferable; import com.fr.design.cell.clipboard.FloatElementsClip; +import com.fr.design.cell.editor.AutoChartCellEditor; +import com.fr.design.cell.editor.AutoChartFloatEditor; import com.fr.design.cell.editor.BiasTextPainterCellEditor; import com.fr.design.cell.editor.CellEditor; import com.fr.design.cell.editor.ChartCellEditor; @@ -118,6 +121,8 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollBar; import javax.swing.KeyStroke; +import java.lang.reflect.Constructor; +import java.util.Set; import java.awt.AWTEvent; import java.awt.Adjustable; import java.awt.Dimension; @@ -131,8 +136,6 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.lang.reflect.Constructor; -import java.util.Set; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; @@ -399,6 +402,9 @@ public abstract class ElementCasePane extends Tar grid.setDefaultFloatEditor(chartClass, new ChartFloatEditor()); } + grid.setDefaultCellEditor(AutoChartCollection.class, new AutoChartCellEditor(this)); + grid.setDefaultFloatEditor(AutoChartCollection.class, new AutoChartFloatEditor()); + addExtraCellEditor(grid); grid.setDefaultFloatEditor(Formula.class, new FormulaFloatEditor()); diff --git a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java index 38efb4c1f..c0a979d6e 100644 --- a/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java +++ b/designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java @@ -112,11 +112,11 @@ import com.fr.start.BBSGuestPaneProvider; import com.fr.task.Once; import com.fr.xml.ReportXMLUtils; -import java.awt.*; -import java.awt.image.*; import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.awt.Image; +import java.awt.image.BufferedImage; /** * Created by juhaoyu on 2018/1/31. @@ -240,6 +240,7 @@ public class DesignerActivator extends Activator { for (ElementUIProvider provider : providers) { classes.add(provider.actionForInsertFloatElement()); } + return ArrayUtils.addAll(new Class[]{ TextBoxFloatAction.class, FormulaFloatAction.class,