diff --git a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java index 656a7a6a78..4aa48591fd 100644 --- a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java +++ b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java @@ -8,6 +8,7 @@ import com.fr.base.BaseUtils; import com.fr.common.annotations.Open; import com.fr.design.data.datapane.TableDataNameObjectCreator; import com.fr.design.fun.CellWidgetOptionProvider; +import com.fr.design.fun.ChartWidgetOptionProvider; import com.fr.design.fun.FormWidgetOptionProvider; import com.fr.design.fun.MobileWidgetStyleProvider; import com.fr.design.fun.ParameterWidgetOptionProvider; @@ -193,6 +194,42 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement return result.toArray(new WidgetOption[result.size()]); } + public Map, Class> getChartWidgetOptionsMap() { + Set set = getArray(ChartWidgetOptionProvider.XML_TAG); + Map, Class> map = new HashMap<>(); + for (ChartWidgetOptionProvider provider : set) { + map.put(provider.classForWidget(), provider.appearanceForWidget()); + } + return map; + } + + public WidgetOption[] getBeforeChartWidgetOptions() { + return getChartUnits(true); + } + + public WidgetOption[] getAfterChartWidgetOptions() { + return getChartUnits(false); + } + + private WidgetOption[] getChartUnits(boolean isBefore) { + Set set = getArray(ChartWidgetOptionProvider.XML_TAG); + if (set.isEmpty()) { + return new WidgetOption[0]; + } + Set result = new HashSet<>(); + for (ChartWidgetOptionProvider provider : set) { + if (provider.isBefore() == isBefore) { + WidgetOption option = WidgetOptionFactory.createByWidgetClass( + provider.nameForWidget(), + BaseUtils.readIcon(provider.iconPathForWidget()), + provider.classForWidget() + ); + result.add(option); + } + } + return result.toArray(new WidgetOption[result.size()]); + } + public WidgetOption[] getCellWidgetOptions() { Set set = getArray(CellWidgetOptionProvider.XML_TAG); diff --git a/designer-base/src/main/java/com/fr/design/fun/ChartWidgetOptionProvider.java b/designer-base/src/main/java/com/fr/design/fun/ChartWidgetOptionProvider.java new file mode 100644 index 0000000000..3deb9947b6 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/ChartWidgetOptionProvider.java @@ -0,0 +1,14 @@ +package com.fr.design.fun; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-06-12 + */ +public interface ChartWidgetOptionProvider extends ParameterWidgetOptionProvider { + + String XML_TAG = "ChartWidgetOptionProvider"; + + //在图表区域的开头还是结尾插入 + boolean isBefore(); +} diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractChartWidgetOptionProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractChartWidgetOptionProvider.java new file mode 100644 index 0000000000..6669d873aa --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractChartWidgetOptionProvider.java @@ -0,0 +1,30 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.ChartWidgetOptionProvider; +import com.fr.design.fun.FormWidgetOptionProvider; +import com.fr.stable.fun.impl.AbstractProvider; +import com.fr.stable.fun.mark.API; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2020-06-12 + */ +@API(level = FormWidgetOptionProvider.CURRENT_LEVEL) +public abstract class AbstractChartWidgetOptionProvider extends AbstractProvider implements ChartWidgetOptionProvider { + + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } + + @Override + public boolean isBefore() { + return false; + } + +} 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 index c6de0fe5e0..9413cf9397 100644 Binary files a/designer-base/src/main/resources/com/fr/design/images/m_insert/auto_chart.png 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 014778cac8..8480d24647 100644 --- a/designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java +++ b/designer-chart/src/main/java/com/fr/design/ChartTypeInterfaceManager.java @@ -104,6 +104,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.awt.event.ActionListener; import static com.fr.chart.charttypes.ChartTypeManager.DEFAULT_PRIORITY; import static com.fr.chart.charttypes.ChartTypeManager.DEPRECATED_CHART_PRIORITY; @@ -259,17 +260,21 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr * * @param paneList pane容器 */ - public void addPlotTypePaneList(List> paneList, Map>> allChartTypePane) { + public void addPlotTypePaneList(List> paneList, + Map>> allChartTypePane, + ActionListener autoButtonListener) { List priorityList = getPriorityInOrder(); for (Integer aPriorityList : priorityList) { String priority = String.valueOf(aPriorityList); - addPlotTypePaneList(priority, paneList, allChartTypePane); + addPlotTypePaneList(priority, paneList, allChartTypePane, autoButtonListener); } } - public void addPlotTypePaneList(String priority, List> paneList, Map>> allChartTypePane) { + public void addPlotTypePaneList(String priority, List> paneList, + Map>> allChartTypePane, + ActionListener autoButtonListener) { if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority)) { @@ -286,6 +291,7 @@ public class ChartTypeInterfaceManager implements ExtraChartDesignClassManagerPr continue; } pane.reLayout(plotID); + pane.registerButtonListener(autoButtonListener); paneList.add(pane); if (allChartTypePane.get(priority) == null) { 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 index 4f8a1d033d..583889da6b 100644 --- a/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java +++ b/designer-chart/src/main/java/com/fr/design/chart/AutoChartDialog.java @@ -1,7 +1,11 @@ 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.chartx.TwoTuple; +import com.fr.design.i18n.Toolkit; +import com.fr.plugin.chart.vanchart.VanChart; import java.awt.Component; import java.awt.Dialog; @@ -46,10 +50,30 @@ public class AutoChartDialog extends ChartDialog { }; } + protected String getDialogTitle() { + return Toolkit.i18nText("Fine-Design_Chart_M_Popup_Auto_Chart_Type"); + } + /** * 更新新建的图表 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; + } + TwoTuple tableNameAndDataFields = filterDefinition.getTableNameAndDataFields(); + if (tableNameAndDataFields == null) { + return; + } + String tableName = tableNameAndDataFields.getFirst(); + String[] dataFields = tableNameAndDataFields.getSecond(); + autoChartTypePane.populate(tableName, dataFields); } } 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 9c2b730ab0..9251bdbc88 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 @@ -5,6 +5,7 @@ import com.fr.chart.chartattr.ChartCollection; import com.fr.design.dialog.BasicDialog; import com.fr.design.gui.chart.MiddleChartDialog; import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.i18n.Toolkit; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.third.joda.time.DateTime; @@ -46,7 +47,7 @@ public class ChartDialog extends MiddleChartDialog { 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")); + setTitle(getDialogTitle()); this.applyClosingAction(); this.applyEscapeAction(); @@ -73,6 +74,10 @@ public class ChartDialog extends MiddleChartDialog { GUICoreUtils.setWindowCenter(getOwner(), this); } + protected String getDialogTitle() { + return Toolkit.i18nText("Fine-Design_Chart_M_Popup_Chart_Type"); + } + protected Component initCenterPane() { chartTypePane = new ChartTypePane(); return chartTypePane; 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 6719401bb2..b363dc5f6b 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 @@ -9,9 +9,7 @@ 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; @@ -39,364 +37,366 @@ import java.awt.event.ItemListener; /** * 图表 属性表, 类型选择 界面. -* @author kunsnat E-mail:kunsnat@gmail.com -* @version 创建时间:2012-12-26 上午10:56:51 + * + * @author kunsnat E-mail:kunsnat@gmail.com + * @version 创建时间:2012-12-26 上午10:56:51 */ -public class ChartTypePane extends AbstractChartAttrPane{ - private ComboBoxPane chartTypeComBox; - private ChartTypeButtonPane buttonPane; +public class ChartTypePane extends AbstractChartAttrPane { + private ComboBoxPane chartTypeComBox; + 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); - - if (editingCollection != null) { - relayoutChartTypePane(editingCollection); - }else { - chartTypeComBox = new ComboBoxPane(); - } - - BasicScrollPane scrollPane = new BasicScrollPane() { - @Override - protected JPanel createContentPane() { - return chartTypeComBox; - } - - @Override - protected void layoutContentPane() { - - leftcontentPane = createContentPane(); - this.add(leftcontentPane); - } - - @Override - public void populateBean(Object ob) { - } - - @Override - protected String title4PopupWindow() { - return null; - } - }; - content.add(scrollPane, BorderLayout.CENTER); - - buttonPane.setEditingChartPane(chartTypeComBox); - - if(ChartTypeManager.AUTO_CHART) { - initAutoButton(); - content.add(autoButton, BorderLayout.SOUTH); - } - - return content; - } - - /** - * 界面做为按钮时的图片位置. design_base - */ - public String getIconPath() { - return "com/fr/design/images/chart/ChartType.png"; - } - - /** - * 界面标题 + private ActionListener autoButtonListener; + + @Override + protected JPanel createContentPane() { + initButtonListener(); + JPanel content = new JPanel(new BorderLayout()); + + buttonPane = new ChartTypeButtonPane(this); + content.add(buttonPane, BorderLayout.NORTH); + + if (editingCollection != null) { + relayoutChartTypePane(editingCollection); + } else { + chartTypeComBox = new ComboBoxPane(); + } + + BasicScrollPane scrollPane = new BasicScrollPane() { + @Override + protected JPanel createContentPane() { + return chartTypeComBox; + } + + @Override + protected void layoutContentPane() { + + leftcontentPane = createContentPane(); + this.add(leftcontentPane); + } + + @Override + public void populateBean(Object ob) { + } + + @Override + protected String title4PopupWindow() { + return null; + } + }; + content.add(scrollPane, BorderLayout.CENTER); + + buttonPane.setEditingChartPane(chartTypeComBox); + + return content; + } + + /** + * 界面做为按钮时的图片位置. design_base + */ + public String getIconPath() { + return "com/fr/design/images/chart/ChartType.png"; + } + + /** + * 界面标题 + * * @return 界面标题 - */ - public String title4PopupWindow() { - 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; - - @Override - protected List> initPaneList() { - List> paneList = new ArrayList>(); - allChartTypePane = new LinkedHashMap>>(); - ChartTypeInterfaceManager.getInstance().addPlotTypePaneList(paneList, allChartTypePane); - return paneList; - } - - @Override - protected String title4PopupWindow() { - return null; - } - - /** - * 不同图表切换分同一个selected的不同图表切换和不同selected的不同图表切换 - * 如果是切换图表的某个图表发生变化,则collection的选择下标不会变 - * 如果是切换图表的不同图表之间切换,则collection的选择下标会改变 - * @param chart - */ - public void updateBean(ChartProvider chart) { - - String lastPlotID = chart.getID(); - - try{ - AbstractChartTypePane selectedPane = (AbstractChartTypePane) getSelectedPane(); - ChartProvider newDefaultChart =(ChartProvider) ChartTypeManager.getInstanceWithCheck().getCharts(selectedPane.getPlotID())[0].clone(); - if (!ComparatorUtils.equals(chart.getClass(), newDefaultChart.getClass())) { - //vanChart 和 chart 之间切换 - //不同chart之间切换 + */ + public String title4PopupWindow() { + return PaneTitleConstants.CHART_TYPE_TITLE; + } + + public void initButtonListener() { + autoButtonListener = 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; + + @Override + protected List> initPaneList() { + List> paneList = new ArrayList>(); + allChartTypePane = new LinkedHashMap>>(); + ChartTypeInterfaceManager.getInstance().addPlotTypePaneList(paneList, allChartTypePane, autoButtonListener); + return paneList; + } + + @Override + protected String title4PopupWindow() { + return null; + } + + /** + * 不同图表切换分同一个selected的不同图表切换和不同selected的不同图表切换 + * 如果是切换图表的某个图表发生变化,则collection的选择下标不会变 + * 如果是切换图表的不同图表之间切换,则collection的选择下标会改变 + * + * @param chart + */ + public void updateBean(ChartProvider chart) { + + String lastPlotID = chart.getID(); + + try { + AbstractChartTypePane selectedPane = (AbstractChartTypePane) getSelectedPane(); + ChartProvider newDefaultChart = (ChartProvider) ChartTypeManager.getInstanceWithCheck().getCharts(selectedPane.getPlotID())[0].clone(); + if (!ComparatorUtils.equals(chart.getClass(), newDefaultChart.getClass())) { + //vanChart 和 chart 之间切换 + //不同chart之间切换 editingCollection.removeNameObject(editingCollection.getSelectedIndex()); editingCollection.addChart(newDefaultChart); chart = newDefaultChart; } - }catch (CloneNotSupportedException e){ + } catch (CloneNotSupportedException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } - //这一步会替换plot - ((AbstractChartTypePane)getSelectedPane()).updateBean(chart); - - String chartID = chart.getID(); - - //chartID改变的话图表类型就算改变了 - if (StringUtils.isNotEmpty(chartID)) { - - boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(chartID); - - if (editPane.isDefaultPane() != isUseDefault || (!isUseDefault && !ComparatorUtils.equals(lastPlotID, chartID))) { - editPane.reLayout(chart); - } - } - } - - protected UIComboBox createComboBox() { - return new FlexibleComboBox(); - } - - @Override - protected void addItemChangeEvent() { - jcb.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - FlexibleComboBox fcb = (FlexibleComboBox)jcb; - if (fcb.isReactor()){ - return; - } - comboBoxItemStateChanged(); - CardLayout cl = (CardLayout)cardPane.getLayout(); - cl.show(cardPane, cardNames[jcb.getSelectedIndex()]); - } - }); - } - - private void addAllCards() { - Iterator iterator = allChartTypePane.keySet().iterator(); - - while (iterator.hasNext()) { - addOnePriorityCards(iterator.next(), false); - } - } - - private void addOnePriorityCards(String priority) { - addOnePriorityCards(priority, true); - } - - private void addOnePriorityCards(String priority, boolean ignore) { - - Map> map = allChartTypePane.get(priority); - - Iterator>> iterator = map.entrySet().iterator(); - - while (iterator.hasNext()) { - Map.Entry> entry = iterator.next(); - String plotID = entry.getKey(); - if (ignore || ChartTypeManager.enabledChart(plotID)) { - cards.add(entry.getValue()); - } - } - - } - - private void addOnePlotIDCards(String priority, String plotID) { - cards.add(allChartTypePane.get(priority).get(plotID)); - } - - //因为饼图(新特性)把(新特性)去掉了,和老的饼图同名,下拉框选项和typePane不能一一对应了 - //处理办法:这边除了重构 下拉项选项和cardNames 还需要把cards重构下(不需要init pane,只需要我需要的拿出来就好了) - private void relayout(ChartCollection collection){ - //重构需要重构下拉框选项和cardNames - ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); - String chartID = chart.getID(); - String priority = ChartTypeManager.getInstanceWithCheck().getPriority(chartID); - boolean enabledChart = ChartTypeManager.enabledChart(chartID); - String item = ChartTypeInterfaceManager.getInstance().getName(chartID); - - //第一步就是重构cards - cards.clear(); - if (enabledChart) { - if (collection.getChartCount() == 1) { - addAllCards(); - } else { - addOnePriorityCards(priority); - } - } else { - addOnePlotIDCards(priority, chartID); - } - - //下拉框重构开始。为了防止重构是触发update - ((FlexibleComboBox)jcb).setItemEvenType(ItemEventType.REACTOR); - //重构下拉框选项 - cardNames = new String[cards.size()]; - cardPane.removeAll(); - jcb.removeAllItems(); - for (int i = 0; i < this.cards.size(); i++) { - String name = this.cards.get(i).title4PopupWindow();// Name从各自的pane里面获取 - cardNames[i] = name; - cardPane.add(this.cards.get(i), cardNames[i]); - addComboBoxItem(cards, i); - } - //重新选择选中的下拉项 - jcb.setSelectedItem(item); - jcb.setEnabled(enabledChart); - //下拉框重构结束 - ((FlexibleComboBox)jcb).setItemEvenType(ItemEventType.DEFAULT); - //重新选中 - checkPlotPane(); - } - - private void checkPlotPane() { - CardLayout cl = (CardLayout)cardPane.getLayout(); - cl.show(cardPane, cardNames[jcb.getSelectedIndex()]); - } - - @Override - public void populateBean(ChartProvider ob) { - for (int i = 0; i < this.cards.size(); i++) { - FurtherBasicBeanPane pane = cards.get(i); - if (pane.accept(ob)) { - pane.populateBean(ob); - Object item = pane.title4PopupWindow(); - for (int j = 0; j < cardNames.length; j++) { - if (ComparatorUtils.equals(item, cardNames[j])) { - jcb.setSelectedIndex(j); - } - } - return; - } - } - } - - @Override - public ChartProvider updateBean() { - return getSelectedPane().updateBean(); - } - - @Override - public FurtherBasicBeanPane getSelectedPane() { - Object item = jcb.getSelectedItem(); - for (int i = 0; i < cards.size(); i++){ - if (ComparatorUtils.equals(item, cards.get(i).title4PopupWindow())){ - return cards.get(i); - } - } - return cards.get(0); - } - - } - - - /** - * 面板重构 - * @param lastPlotID - * @param collection - */ - public void reLayoutEditPane(String lastPlotID, ChartCollection collection){ - if (editPane == null) { - return; - } - ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); - String plotID = chart.getID(); - boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(plotID); - if (editPane.isDefaultPane() != isUseDefault || (!isUseDefault && !ComparatorUtils.equals(lastPlotID, plotID))) { - editPane.reLayout(chart); - } - } - - - public void relayoutChartTypePane(ChartCollection collection){ - chartTypeComBox.relayout(collection); - } - - /** - * 更新界面属性 用于展示 - */ - public void populate(ChartCollection collection) { - editingCollection = collection; - - ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); - this.remove(leftContentPane); - initContentPane(); - - buttonPane.populateBean(collection); - chartTypeComBox.populateBean(chart); - - buttonPane.setVisible(ChartTypeInterfaceManager.getInstance().needChartChangePane(chart)); - - this.initAllListeners(); - } - - /** - * 保存界面属性 - */ - public void update(ChartCollection collection) { + //这一步会替换plot + ((AbstractChartTypePane) getSelectedPane()).updateBean(chart); + + String chartID = chart.getID(); + + //chartID改变的话图表类型就算改变了 + if (StringUtils.isNotEmpty(chartID)) { + + boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(chartID); + + if (editPane.isDefaultPane() != isUseDefault || (!isUseDefault && !ComparatorUtils.equals(lastPlotID, chartID))) { + editPane.reLayout(chart); + } + } + } + + protected UIComboBox createComboBox() { + return new FlexibleComboBox(); + } + + @Override + protected void addItemChangeEvent() { + jcb.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + FlexibleComboBox fcb = (FlexibleComboBox) jcb; + if (fcb.isReactor()) { + return; + } + comboBoxItemStateChanged(); + CardLayout cl = (CardLayout) cardPane.getLayout(); + cl.show(cardPane, cardNames[jcb.getSelectedIndex()]); + } + }); + } + + private void addAllCards() { + Iterator iterator = allChartTypePane.keySet().iterator(); + + while (iterator.hasNext()) { + addOnePriorityCards(iterator.next(), false); + } + } + + private void addOnePriorityCards(String priority) { + addOnePriorityCards(priority, true); + } + + private void addOnePriorityCards(String priority, boolean ignore) { + + Map> map = allChartTypePane.get(priority); + + Iterator>> iterator = map.entrySet().iterator(); + + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + String plotID = entry.getKey(); + if (ignore || ChartTypeManager.enabledChart(plotID)) { + cards.add(entry.getValue()); + } + } + + } + + private void addOnePlotIDCards(String priority, String plotID) { + cards.add(allChartTypePane.get(priority).get(plotID)); + } + + //因为饼图(新特性)把(新特性)去掉了,和老的饼图同名,下拉框选项和typePane不能一一对应了 + //处理办法:这边除了重构 下拉项选项和cardNames 还需要把cards重构下(不需要init pane,只需要我需要的拿出来就好了) + private void relayout(ChartCollection collection) { + //重构需要重构下拉框选项和cardNames + ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); + String chartID = chart.getID(); + String priority = ChartTypeManager.getInstanceWithCheck().getPriority(chartID); + boolean enabledChart = ChartTypeManager.enabledChart(chartID); + String item = ChartTypeInterfaceManager.getInstance().getName(chartID); + + //第一步就是重构cards + cards.clear(); + if (enabledChart) { + if (collection.getChartCount() == 1) { + addAllCards(); + } else { + addOnePriorityCards(priority); + } + } else { + addOnePlotIDCards(priority, chartID); + } + + //下拉框重构开始。为了防止重构是触发update + ((FlexibleComboBox) jcb).setItemEvenType(ItemEventType.REACTOR); + //重构下拉框选项 + cardNames = new String[cards.size()]; + cardPane.removeAll(); + jcb.removeAllItems(); + for (int i = 0; i < this.cards.size(); i++) { + String name = this.cards.get(i).title4PopupWindow();// Name从各自的pane里面获取 + cardNames[i] = name; + cardPane.add(this.cards.get(i), cardNames[i]); + addComboBoxItem(cards, i); + } + //重新选择选中的下拉项 + jcb.setSelectedItem(item); + jcb.setEnabled(enabledChart); + //下拉框重构结束 + ((FlexibleComboBox) jcb).setItemEvenType(ItemEventType.DEFAULT); + //重新选中 + checkPlotPane(); + } + + private void checkPlotPane() { + CardLayout cl = (CardLayout) cardPane.getLayout(); + cl.show(cardPane, cardNames[jcb.getSelectedIndex()]); + } + + @Override + public void populateBean(ChartProvider ob) { + for (int i = 0; i < this.cards.size(); i++) { + FurtherBasicBeanPane pane = cards.get(i); + if (pane.accept(ob)) { + pane.populateBean(ob); + Object item = pane.title4PopupWindow(); + for (int j = 0; j < cardNames.length; j++) { + if (ComparatorUtils.equals(item, cardNames[j])) { + jcb.setSelectedIndex(j); + } + } + return; + } + } + } + + @Override + public ChartProvider updateBean() { + return getSelectedPane().updateBean(); + } + + @Override + public FurtherBasicBeanPane getSelectedPane() { + Object item = jcb.getSelectedItem(); + for (int i = 0; i < cards.size(); i++) { + if (ComparatorUtils.equals(item, cards.get(i).title4PopupWindow())) { + return cards.get(i); + } + } + return cards.get(0); + } + + } + + + /** + * 面板重构 + * + * @param lastPlotID + * @param collection + */ + public void reLayoutEditPane(String lastPlotID, ChartCollection collection) { + if (editPane == null) { + return; + } + ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); + String plotID = chart.getID(); + boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(plotID); + if (editPane.isDefaultPane() != isUseDefault || (!isUseDefault && !ComparatorUtils.equals(lastPlotID, plotID))) { + editPane.reLayout(chart); + } + } + + + public void relayoutChartTypePane(ChartCollection collection) { + chartTypeComBox.relayout(collection); + } + + /** + * 更新界面属性 用于展示 + */ + public void populate(ChartCollection collection) { + editingCollection = collection; + + ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); + this.remove(leftContentPane); + initContentPane(); + + buttonPane.populateBean(collection); + chartTypeComBox.populateBean(chart); + + buttonPane.setVisible(ChartTypeInterfaceManager.getInstance().needChartChangePane(chart)); + + this.initAllListeners(); + } + + /** + * 保存界面属性 + */ + public void update(ChartCollection collection) { editingCollection = collection; - buttonPane.update(collection);// 内部操作时 已经做过处理. - ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); - chartTypeComBox.updateBean(chart); - } + buttonPane.update(collection);// 内部操作时 已经做过处理. + ChartProvider chart = collection.getSelectedChartProvider(ChartProvider.class); + chartTypeComBox.updateBean(chart); + } /** * 所有图表的类型界面 + * * @return 类型界面 */ - public FurtherBasicBeanPane[] getPaneList(){ + public FurtherBasicBeanPane[] getPaneList() { return chartTypeComBox.getCards().toArray(new FurtherBasicBeanPane[0]); } /** * 当前选中的图表的index + * * @return 当前选中的图表的index */ - public int getSelectedIndex(){ + public int getSelectedIndex() { return chartTypeComBox.getSelectedIndex(); } /** * 返回选中的图表的index + * * @return 选中的图标的序号 */ - public int getSelectedChartIndex(){ + public int getSelectedChartIndex() { return chartTypeComBox.getSelectedIndex(); } /** * 设置下编辑的面板 + * * @param currentEditPane 设置下编辑的面板 */ public void registerChartEditPane(ChartEditPane currentEditPane) { diff --git a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java index eee0e322e6..4f3f025105 100644 --- a/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java @@ -22,6 +22,7 @@ import java.util.List; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.event.ActionListener; public abstract class AbstractChartTypePane extends FurtherBasicBeanPane { @@ -240,4 +241,8 @@ public abstract class AbstractChartTypePane extends Fur public ChartProvider getDefaultChart() { return BarIndependentChart.barChartTypes[0]; } + + public void registerButtonListener(ActionListener autoButtonListener) { + + } } \ No newline at end of file diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java b/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java index a4b43843e4..6bace5ef90 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/VanChartCustomPlotPane.java @@ -61,7 +61,8 @@ public class VanChartCustomPlotPane extends AbstractVanChartTypePane { return new Component[][]{ new Component[]{typePane}, new Component[]{stylePane}, - new Component[]{contentPane} + new Component[]{contentPane}, + new Component[]{buttonPane}, }; } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/type/AbstractVanChartTypePane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/type/AbstractVanChartTypePane.java index c2406e0d2c..577a04664c 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/type/AbstractVanChartTypePane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/type/AbstractVanChartTypePane.java @@ -1,5 +1,6 @@ package com.fr.van.chart.designer.type; +import com.fr.base.BaseUtils; import com.fr.chart.base.AttrFillStyle; import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.Legend; @@ -7,13 +8,16 @@ import com.fr.chart.chartattr.Plot; import com.fr.chart.chartglyph.ConditionAttr; import com.fr.chart.chartglyph.ConditionCollection; import com.fr.chart.chartglyph.DataSheet; +import com.fr.chart.charttypes.ChartTypeManager; import com.fr.chartx.data.AbstractDataDefinition; import com.fr.chartx.data.ChartDataDefinitionProvider; import com.fr.chartx.data.field.AbstractColumnFieldCollection; import com.fr.chartx.data.field.diff.MultiCategoryColumnFieldCollection; import com.fr.design.ChartTypeInterfaceManager; +import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.MultilineLabel; +import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.chart.gui.type.AbstractChartTypePane; import com.fr.design.mainframe.chart.gui.type.ChartImagePane; import com.fr.design.mainframe.chart.info.ChartInfoCollector; @@ -25,21 +29,53 @@ import com.fr.plugin.chart.base.VanChartTools; import com.fr.plugin.chart.base.VanChartZoom; import com.fr.plugin.chart.vanchart.VanChart; +import javax.swing.BorderFactory; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionListener; public abstract class AbstractVanChartTypePane extends AbstractChartTypePane { private static final long serialVersionUID = 7743244512351499265L; private UICheckBox largeModelCheckBox; + protected JPanel buttonPane; + + protected UIButton autoButton; + private boolean samePlot; protected boolean isSamePlot() { return samePlot; } + public AbstractVanChartTypePane() { + buttonPane = new JPanel(); + buttonPane.setLayout(new BorderLayout()); + if (ChartTypeManager.AUTO_CHART) { + autoButton = new UIButton(Toolkit.i18nText("Fine-Design_Chart_M_Popup_Auto_Chart_Type"), + BaseUtils.readIcon("/com/fr/design/images/m_insert/auto_chart.png")) { + @Override + public Dimension getPreferredSize() { + return new Dimension((int) super.getPreferredSize().getWidth(), 25); + } + }; + buttonPane.setBorder((BorderFactory.createEmptyBorder(5, 0, 0, 0))); + buttonPane.add(autoButton); + } + } + + @Override + protected Component[][] getPaneComponents(JPanel typePane) { + return new Component[][]{ + new Component[]{typePane}, + new Component[]{buttonPane}, + new Component[]{stylePane}, + }; + } + //新图表暂时还没有平面3d,渐变高光等布局。 @Override protected String[] getTypeLayoutPath() { @@ -66,7 +102,7 @@ public abstract class AbstractVanChartTypePane extends AbstractChartTypePane ePane) { 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 24178bcfd4..9fc0b7b521 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,7 +9,6 @@ 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; @@ -53,8 +52,6 @@ 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; @@ -402,8 +399,6 @@ 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); @@ -427,7 +422,7 @@ public abstract class ElementCasePane extends Tar editor = (CellEditor) c.newInstance(); } catch (NoSuchMethodException e) { try { - c = clazz.getConstructor(ElementCase.class); + c = clazz.getConstructor(ElementCasePane.class); editor = (CellEditor) c.newInstance(this); } catch (Exception e1) { FineLoggerFactory.getLogger().error(e1.getMessage(), e1); 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 c0a979d6eb..3f1aa26636 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 @@ -350,6 +350,9 @@ public class DesignerActivator extends Activator { Set providers = ExtraDesignClassManager.getInstance().getArray(ElementUIProvider.MARK_STRING); for (ElementUIProvider provider : providers) { try { + if (provider.quickEditor() == null) { + continue; + } ActionFactory.registerCellEditor(provider.targetObjectClass(), provider.quickEditor().newInstance()); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e);