diff --git a/designer_base/src/com/fr/design/extra/PluginHelper.java b/designer_base/src/com/fr/design/extra/PluginHelper.java index 5d0c9fa1a9..f510646f84 100644 --- a/designer_base/src/com/fr/design/extra/PluginHelper.java +++ b/designer_base/src/com/fr/design/extra/PluginHelper.java @@ -153,7 +153,6 @@ public class PluginHelper { installDependenceOnline(currentID, needInstallDependence); } - /** * 构造一个下载UI * @param currentID diff --git a/designer_base/src/com/fr/design/gui/frpane/UIComboBoxPane.java b/designer_base/src/com/fr/design/gui/frpane/UIComboBoxPane.java index 9d31cd4f35..e903aa95a0 100644 --- a/designer_base/src/com/fr/design/gui/frpane/UIComboBoxPane.java +++ b/designer_base/src/com/fr/design/gui/frpane/UIComboBoxPane.java @@ -25,7 +25,7 @@ public abstract class UIComboBoxPane extends BasicBeanPane { protected JPanel cardPane; protected List> cards; - private String[] cardNames; + protected String[] cardNames; public UIComboBoxPane() { cards = initPaneList(); @@ -49,6 +49,19 @@ public abstract class UIComboBoxPane extends BasicBeanPane { addComboBoxItem(cards, i); } + addItemChangeEvent(); + + initLayout(); + + jcb.setSelectedIndex(0); + } + + public FurtherBasicBeanPane getSelectedPane(){ + return cards.get(jcb.getSelectedIndex()); + } + + + protected void addItemChangeEvent() { jcb.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { @@ -57,10 +70,6 @@ public abstract class UIComboBoxPane extends BasicBeanPane { cl.show(cardPane, cardNames[jcb.getSelectedIndex()]); } }); - - initLayout(); - - jcb.setSelectedIndex(0); } protected UIComboBox createComboBox() { @@ -117,6 +126,8 @@ public abstract class UIComboBoxPane extends BasicBeanPane { } } + + @Override public T updateBean() { return cards.get(jcb.getSelectedIndex()).updateBean(); diff --git a/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java b/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java index 90944c4496..d6d1496746 100644 --- a/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java +++ b/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java @@ -37,7 +37,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser private static final int SIZE5 = 5; - private UIObserverListener uiObserverListener; + protected UIObserverListener uiObserverListener; private String comboBoxName = ""; @@ -71,7 +71,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser initListener(); } - private void initListener() { + protected void initListener() { if (shouldResponseChangeListener()) { this.addFocusListener(new FocusAdapter() { @Override @@ -94,7 +94,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser } } - private void fireSetGlobalName() { + protected void fireSetGlobalName() { if (globalNameListener != null && shouldResponseNameListener()) { globalNameListener.setGlobalName(comboBoxName); } diff --git a/designer_base/src/com/fr/design/images/buttonicon/config.png b/designer_base/src/com/fr/design/images/buttonicon/config.png new file mode 100644 index 0000000000..377bb9247d Binary files /dev/null and b/designer_base/src/com/fr/design/images/buttonicon/config.png differ diff --git a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java index 2dfb2b8cdd..d9574a09c4 100644 --- a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java +++ b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java @@ -38,10 +38,7 @@ import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; import javax.swing.*; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Created by eason on 14/12/29. @@ -54,8 +51,8 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh private static ClassLoader loader = Thread.currentThread().getContextClassLoader(); private static ChartTypeInterfaceManager classManager = null; - - private static LinkedHashMap chartTypeInterfaces = new LinkedHashMap(); + private static LinkedHashMap> chartTypeInterfaces = new LinkedHashMap>(); + //private static LinkedHashMap chartTypeInterfaces = new LinkedHashMap(); public synchronized static ChartTypeInterfaceManager getInstance() { if (classManager == null) { @@ -77,7 +74,9 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh GeneralContext.addPluginReadListener(new PluginReadListener() { @Override public void success() { - ChartTypeInterfaceManager.getInstance().readDefault(); + if (chartTypeInterfaces.size() == 0) { + ChartTypeInterfaceManager.getInstance().readDefault(); + } //重新注册designModuleFactory DesignModuleFactory.registerExtraWidgetOptions(initWidgetOption()); } @@ -118,36 +117,64 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh } private static void readDefault() { - chartTypeInterfaces.put(ChartConstants.COLUMN_CHART, new ColumnIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.LINE_CHART, new LineIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.BAR_CHART, new BarIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.PIE_CHART, new PieIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.AREA_CHART, new AreaIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.SCATTER_CHART, new XYScatterIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.BUBBLE_CHART, new BubbleIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.RADAR_CHART, new RadarIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.STOCK_CHART, new StockIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.METER_CHART, new MeterIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.RANGE_CHART, new RangeIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.CUSTOM_CHART, new CustomIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.GANTT_CHART, new GanttIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.DONUT_CHART, new DonutIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.MAP_CHART, new MapIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.GIS_CHAER, new GisMapIndependentChartInterface()); - chartTypeInterfaces.put(ChartConstants.FUNNEL_CHART, new FunnelIndependentChartInterface()); + LinkedHashMap chartUIList = new LinkedHashMap(); + chartUIList.put(ChartConstants.COLUMN_CHART, new ColumnIndependentChartInterface()); + chartUIList.put(ChartConstants.LINE_CHART, new LineIndependentChartInterface()); + chartUIList.put(ChartConstants.BAR_CHART, new BarIndependentChartInterface()); + chartUIList.put(ChartConstants.PIE_CHART, new PieIndependentChartInterface()); + chartUIList.put(ChartConstants.AREA_CHART, new AreaIndependentChartInterface()); + chartUIList.put(ChartConstants.SCATTER_CHART, new XYScatterIndependentChartInterface()); + chartUIList.put(ChartConstants.BUBBLE_CHART, new BubbleIndependentChartInterface()); + chartUIList.put(ChartConstants.RADAR_CHART, new RadarIndependentChartInterface()); + chartUIList.put(ChartConstants.STOCK_CHART, new StockIndependentChartInterface()); + chartUIList.put(ChartConstants.METER_CHART, new MeterIndependentChartInterface()); + chartUIList.put(ChartConstants.RANGE_CHART, new RangeIndependentChartInterface()); + chartUIList.put(ChartConstants.CUSTOM_CHART, new CustomIndependentChartInterface()); + chartUIList.put(ChartConstants.GANTT_CHART, new GanttIndependentChartInterface()); + chartUIList.put(ChartConstants.DONUT_CHART, new DonutIndependentChartInterface()); + chartUIList.put(ChartConstants.MAP_CHART, new MapIndependentChartInterface()); + chartUIList.put(ChartConstants.GIS_CHAER, new GisMapIndependentChartInterface()); + chartUIList.put(ChartConstants.FUNNEL_CHART, new FunnelIndependentChartInterface()); + + chartTypeInterfaces.put(ChartConstants.CHART_ID, chartUIList); } public String getIconPath(String plotID) { - if (chartTypeInterfaces.get(plotID) != null) { - return chartTypeInterfaces.get(plotID).getIconPath(); + if (chartTypeInterfaces != null) { + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + String imagePath = getIconPath(chartID, plotID); + if (!StringUtils.isEmpty(imagePath)) { + return imagePath; + } + } + } + return StringUtils.EMPTY; + } + + private String getIconPath(String chartID, String plotID) { + if (chartTypeInterfaces.get(chartID) != null && chartTypeInterfaces.get(chartID).get(plotID) != null) { + return chartTypeInterfaces.get(chartID).get(plotID).getIconPath(); }else { return StringUtils.EMPTY; } } - public static void addChartTypeInterface(IndependentChartUIProvider provider, String plotID) { - if (chartTypeInterfaces != null && !chartTypeInterfaces.containsKey(plotID)) { - chartTypeInterfaces.put(plotID, provider); + public static void addChartTypeInterface(IndependentChartUIProvider provider, String chartID, String plotID) { + if (chartTypeInterfaces != null){ + if (!chartTypeInterfaces.containsKey(chartID)){ + //新建一个具体图表列表 + LinkedHashMap chartUIList = new LinkedHashMap(); + chartUIList.put(plotID, provider); + chartTypeInterfaces.put(chartID, chartUIList); + }else { + LinkedHashMap chartUIList = chartTypeInterfaces.get(chartID); + if (!chartUIList.containsKey(plotID)) { + chartUIList.put(plotID, provider); + } + } } } @@ -157,7 +184,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh * @param className 类名 * @param plotID 标志ID */ - public void addChartInterface(String className, String plotID, PluginSimplify simplify) { + public void addChartInterface(String className, String chartID, String plotID, PluginSimplify simplify) { if (StringUtils.isNotBlank(className)) { try { Class clazz = Class.forName(className); @@ -169,7 +196,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh if (PluginCollector.getCollector().isError(provider, IndependentChartUIProvider.CURRENT_API_LEVEL, simplify.getPluginName()) || !containsChart(plotID)) { PluginMessage.remindUpdate(className); } else { - ChartTypeInterfaceManager.getInstance().addChartTypeInterface(provider, plotID); + ChartTypeInterfaceManager.getInstance().addChartTypeInterface(provider, chartID, plotID); } } catch (ClassNotFoundException e) { FRLogger.getLogger().error("class not found:" + e.getMessage()); @@ -190,38 +217,165 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh * @param paneList pane容器 */ public void addPlotTypePaneList(List> paneList) { - Iterator iterator = chartTypeInterfaces.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry) iterator.next(); - IndependentChartUIProvider creator = (IndependentChartUIProvider) entry.getValue(); - paneList.add(creator.getPlotTypePane()); + String chartID = (String) entry.getKey(); + Iterator chartUIIterator = chartTypeInterfaces.get(chartID).entrySet().iterator(); + while (chartUIIterator.hasNext()) { + Map.Entry chartUIEntry = (Map.Entry) chartUIIterator.next(); + IndependentChartUIProvider provider = (IndependentChartUIProvider) chartUIEntry.getValue(); + paneList.add(provider.getPlotTypePane()); + } + } + } + + public String[] getTitle4PopupWindow(String chartID){ + if (chartID.isEmpty()){ + return getTitle4PopupWindow(); + } + String[] names = new String[getChartSize(chartID)]; + if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(chartID)){ + HashMap chartUIList = chartTypeInterfaces.get(chartID); + Iterator iterator = chartUIList.entrySet().iterator(); + int i = 0; + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + IndependentChartUIProvider provider = (IndependentChartUIProvider) entry.getValue(); + names[i++] = provider.getPlotTypePane().title4PopupWindow(); + } + return names; + } + return new String[0]; + } + + private String[] getTitle4PopupWindow(){ + int size = 0; + if (chartTypeInterfaces != null){ + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + size += getChartSize(chartID); + } + String[] names = new String[size]; + + int index = 0; + + Iterator i = chartTypeInterfaces.entrySet().iterator(); + while (i.hasNext()){ + Map.Entry entry = (Map.Entry) i.next(); + String chartID = (String) entry.getKey(); + Iterator chartUI = chartTypeInterfaces.get(chartID).entrySet().iterator(); + while (chartUI.hasNext()){ + Map.Entry chartUIEntry = (Map.Entry) chartUI.next(); + IndependentChartUIProvider provider = (IndependentChartUIProvider) chartUIEntry.getValue(); + names[index++] = provider.getPlotTypePane().title4PopupWindow(); + } + } + return names; } + return new String[0]; } public ChartDataPane getChartDataPane(String plotID, AttributeChangeListener listener) { - return chartTypeInterfaces.get(plotID).getChartDataPane(listener); + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + return getChartDataPane(chartID, plotID, listener); + } + return getChartDataPane(ChartConstants.DEFAULT_CHART_ID, plotID, listener); + } + + private ChartDataPane getChartDataPane(String chartID, String plotID, AttributeChangeListener listener) { + return chartTypeInterfaces.get(chartID).get(plotID).getChartDataPane(listener); + } + + /** + * 获取对应ID的图表数量 + * @param chartID + * @return + */ + private int getChartSize(String chartID){ + if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(chartID)){ + return chartTypeInterfaces.get(chartID).size(); + } + return 0; } public AbstractChartAttrPane[] getAttrPaneArray(String plotID, AttributeChangeListener listener) { - return chartTypeInterfaces.get(plotID).getAttrPaneArray(listener); + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + return getAttrPaneArray(chartID, plotID, listener); + } + return getAttrPaneArray(ChartConstants.DEFAULT_CHART_ID, plotID, listener); + } + + private AbstractChartAttrPane[] getAttrPaneArray(String chartID, String plotID, AttributeChangeListener listener) { + return chartTypeInterfaces.get(chartID).get(plotID).getAttrPaneArray(listener); } public AbstractTableDataContentPane getTableDataSourcePane(Plot plot, ChartDataPane parent) { - return chartTypeInterfaces.get(plot.getPlotID()).getTableDataSourcePane(plot, parent); + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + return getTableDataSourcePane(chartID, plot, parent); + } + return getTableDataSourcePane(ChartConstants.DEFAULT_CHART_ID, plot, parent); + } + + private AbstractTableDataContentPane getTableDataSourcePane(String chartID, Plot plot, ChartDataPane parent) { + return chartTypeInterfaces.get(chartID).get(plot.getPlotID()).getTableDataSourcePane(plot, parent); } + public AbstractReportDataContentPane getReportDataSourcePane(Plot plot, ChartDataPane parent) { - return chartTypeInterfaces.get(plot.getPlotID()).getReportDataSourcePane(plot, parent); + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + return getReportDataSourcePane(chartID, plot, parent); + } + return getReportDataSourcePane(ChartConstants.DEFAULT_CHART_ID, plot, parent); + } + + private AbstractReportDataContentPane getReportDataSourcePane(String chartID, Plot plot, ChartDataPane parent) { + return chartTypeInterfaces.get(chartID).get(plot.getPlotID()).getReportDataSourcePane(plot, parent); } + public ConditionAttributesPane getPlotConditionPane(Plot plot) { - return chartTypeInterfaces.get(plot.getPlotID()).getPlotConditionPane(plot); + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + return getPlotConditionPane(chartID, plot); + } + return getPlotConditionPane(ChartConstants.DEFAULT_CHART_ID, plot); + } + + private ConditionAttributesPane getPlotConditionPane(String chartID, Plot plot) { + return chartTypeInterfaces.get(chartID).get(plot.getPlotID()).getPlotConditionPane(plot); } + public BasicBeanPane getPlotSeriesPane(ChartStylePane parent, Plot plot) { - return chartTypeInterfaces.get(plot.getPlotID()).getPlotSeriesPane(parent, plot); + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + return getPlotSeriesPane(chartID, parent, plot); + } + return getPlotSeriesPane(ChartConstants.DEFAULT_CHART_ID, parent, plot); + } + + private BasicBeanPane getPlotSeriesPane(String chartID, ChartStylePane parent, Plot plot) { + return chartTypeInterfaces.get(chartID).get(plot.getPlotID()).getPlotSeriesPane(parent, plot); } /** @@ -231,9 +385,22 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh * @return 是否使用默认的界面 */ public boolean isUseDefaultPane(String plotID) { + Iterator iterator = chartTypeInterfaces.entrySet().iterator(); + while (iterator.hasNext()){ + Map.Entry entry = (Map.Entry) iterator.next(); + String chartID = (String) entry.getKey(); + if (chartTypeInterfaces.get(chartID).containsKey(plotID)){ + return isUseDefaultPane(chartID, plotID); + } + } + + return true; + } + + private boolean isUseDefaultPane(String chartID, String plotID){ - if (chartTypeInterfaces.containsKey(plotID)) { - return chartTypeInterfaces.get(plotID).isUseDefaultPane(); + if (chartTypeInterfaces.containsKey(chartID) && chartTypeInterfaces.get(chartID).containsKey(plotID)) { + return chartTypeInterfaces.get(chartID).get(plotID).isUseDefaultPane(); } return true; @@ -251,7 +418,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh extraChartDesignInterfaceList.add(tagName); } if (IndependentChartUIProvider.XML_TAG.equals(tagName)) { - addChartInterface(reader.getAttrAsString("class", ""), reader.getAttrAsString("plotID", ""), simplify); + addChartInterface(reader.getAttrAsString("class", ""), reader.getAttrAsString("chartID", ChartConstants.DEFAULT_CHART_ID),reader.getAttrAsString("plotID", ""), simplify); } } } diff --git a/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java b/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java index ffe91cd0d0..6c7ba66d80 100644 --- a/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java +++ b/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java @@ -15,7 +15,7 @@ import com.fr.general.ComparatorUtils; * Created by Mitisky on 16/3/7. */ public abstract class AbstractIndependentChartUIWithAPILevel implements IndependentChartUIProvider { - private static final int OLD_PLUGIN_LEVEL = -2; + private static final int OLD_PLUGIN_LEVEL = 3; @Override //以前的插件没有覆写这个方法,所以始终获取到-2,比当前level低,提示更新. diff --git a/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java b/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java index d898640feb..6aa05925e4 100644 --- a/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java +++ b/designer_chart/src/com/fr/design/chart/gui/ChartComponent.java @@ -5,6 +5,7 @@ import com.fr.base.ScreenResolution; import com.fr.base.chart.BaseChart; import com.fr.base.chart.BaseChartCollection; import com.fr.base.chart.BaseChartGlyph; +import com.fr.base.chart.chartdata.ChartDataEvent; import com.fr.chart.base.ChartConstants; import com.fr.chart.chartattr.Axis; import com.fr.chart.chartattr.Chart; @@ -31,7 +32,7 @@ import java.util.List; * 类说明: 事件说明: 工具栏编辑--> 是刷新ChartComponent 然后响应整个设计块的改变事件 右键编辑 ---> 刷新ChartCompment 刷新对应的工具栏(加入事件) 然后响应整个设计块的改变事件 */ -public class ChartComponent extends MiddleChartComponent implements MouseListener, MouseMotionListener { +public class ChartComponent extends MiddleChartComponent implements MouseListener, MouseMotionListener, ChartDataEvent { private static final long serialVersionUID = 744164838619052097L; private final List listeners = new ArrayList(); private ChartCollection chartCollection4Design; @@ -309,13 +310,24 @@ public class ChartComponent extends MiddleChartComponent implements MouseListene } else { chartGlyph.setBounds(new Rectangle2D.Double(0, 0, chartWidth, chartHeight)); } - // chartGlyph.draw(g2d, ScreenResolution.getScreenResolution()); + //不直接画chartGlyph而画image的原因是表单的柱形图会溢出表单 //其他图都ok,其实感觉应该是柱形图画的不对,应该也可以改那边 + //注册获取图片后续事件 + registerChartDataEvent(chartGlyph); Image chartImage = chartGlyph.toImage(chartWidth,chartHeight,ScreenResolution.getScreenResolution()); g2d.drawImage(chartImage, 0, 0, null); } } + @Override + public void registerChartDataEvent(BaseChartGlyph glyph) { + glyph.addChartDataEvent(this); + } + + @Override + public void fire() { + this.repaint(); + } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java index 0d6891050f..8833e5269d 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java @@ -3,6 +3,7 @@ package com.fr.design.mainframe.chart.gui; import com.fr.base.BaseUtils; import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.ChartCollection; +import com.fr.chart.chartattr.SwitchState; import com.fr.chart.charttypes.ColumnIndependentChart; import com.fr.design.beans.BasicBeanPane; import com.fr.design.event.UIObserver; @@ -35,6 +36,7 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen private static final int COL_COUNT = 3; private UIButton addButton; + private UIButton configButton; private ArrayList indexList = new ArrayList(); private JPanel buttonPane; @@ -43,6 +45,8 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen private ComboBoxPane editChartType; private UITextField currentEditingEditor = null; + private ChartTypePane parent = null; + private boolean mouseOnChartTypeButtonPane = false; /** @@ -68,9 +72,15 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen } }; + public ChartTypeButtonPane(ChartTypePane chartTypePane){ + this(); + parent = chartTypePane; + } + public ChartTypeButtonPane() { this.setLayout(new BorderLayout()); addButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/add.png")); + configButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/config.png")); buttonPane = new JPanel(); this.add(buttonPane, BorderLayout.CENTER); @@ -80,8 +90,13 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen eastPane.setLayout(new BorderLayout()); - eastPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 20)); - eastPane.add(addButton, BorderLayout.NORTH); + eastPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 15)); + JPanel button = new JPanel(); + button.setPreferredSize(new Dimension(45, 20)); + button.setLayout(new GridLayout(1, 2, 5, 0)); + button.add(addButton); + button.add(configButton); + eastPane.add(button, BorderLayout.NORTH); addButton.setPreferredSize(new Dimension(20, 20)); addButton.addActionListener(addListener); @@ -101,14 +116,20 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen indexList.add(button); if (editingCollection != null) { - Chart[] barChart = ColumnIndependentChart.columnChartTypes; + //点击添加按钮,则会触发切换状态 + Chart chart = editingCollection.getChangeStateNewChart(); try { - Chart newChart = (Chart) barChart[0].clone(); + Chart newChart = (Chart) chart.clone(); editingCollection.addNamedChart(name, newChart); editingCollection.addFunctionRecord(newChart); } catch (CloneNotSupportedException e1) { FRLogger.getLogger().error("Error in Clone"); } + //获取图表收集器的状态 + SwitchState state = editingCollection.calculateMultiChartMode(); + if (SwitchState.isDynamicState(state) && parent != null){ + parent.reactorChartTypePane(editingCollection); + } } layoutPane(buttonPane); @@ -246,17 +267,15 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen } layoutPane(buttonPane); - checkAddButtonVisible(); + checkConfigButtonVisible(); } - private void checkAddButtonVisible() { + private void checkConfigButtonVisible() { addButton.setVisible(true); //新建一个collection - if(editingCollection != null && editingCollection.getChartCount() == 1){ - //vanChart 不支持图表切换 目前 - if(!ComparatorUtils.equals(editingCollection.getSelectedChart().getClass(), Chart.class)){ - addButton.setVisible(false); - } + if(editingCollection.getState() == SwitchState.DEFAULT){ + //Chart 不支持图表切换 + configButton.setVisible(editingCollection.getSelectedChart().supportChange()); } } @@ -367,12 +386,21 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen for (int i = 0; i < count; i++) { if (ComparatorUtils.equals(getButtonName(), editingCollection.getChartName(i))) { editingCollection.removeNameObject(i); + if (i <= editingCollection.getSelectedIndex()){ + editingCollection.setSelectedIndex(editingCollection.getSelectedIndex()-1); + } break; } } } } + //获取图表收集器的状态 + SwitchState state = editingCollection.calculateMultiChartMode(); + if (SwitchState.isDynamicState(state) && parent != null){ + parent.reactorChartTypePane(editingCollection); + } + relayoutPane(); } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java index 2203f4963b..84cfbd52ba 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java @@ -4,18 +4,26 @@ import com.fr.base.FRContext; import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.Plot; +import com.fr.chart.chartattr.SwitchState; import com.fr.chart.charttypes.ChartTypeManager; import com.fr.design.ChartTypeInterfaceManager; import com.fr.design.beans.FurtherBasicBeanPane; import com.fr.design.dialog.BasicScrollPane; import com.fr.design.gui.frpane.UIComboBoxPane; +import com.fr.design.gui.icombobox.UIComboBox; 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.general.ComparatorUtils; +import com.fr.stable.StringUtils; import javax.swing.*; import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.util.ArrayList; import java.util.List; @@ -34,7 +42,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ protected JPanel createContentPane() { JPanel content = new JPanel(new BorderLayout()); - buttonPane = new ChartTypeButtonPane(); + buttonPane = new ChartTypeButtonPane(this); content.add(buttonPane, BorderLayout.NORTH); chartTypePane = new ComboBoxPane(); @@ -46,6 +54,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ @Override protected void layoutContentPane() { + leftcontentPane = createContentPane(); this.add(leftcontentPane); } @@ -98,7 +107,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ int lastSelectIndex = editPane.getSelectedChartIndex(chart); try{ - Chart newDefaultChart = (Chart)((AbstractChartTypePane)cards.get(jcb.getSelectedIndex())).getDefaultChart().clone(); + Chart newDefaultChart = (Chart)((AbstractChartTypePane)getSelectedPane()).getDefaultChart().clone(); if(!chart.accept(newDefaultChart.getClass())){ //vanChart 和 chart 之间切换 editingCollection.removeNameObject(editingCollection.getSelectedIndex()); @@ -110,7 +119,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ } //这一步会替换plot - ((AbstractChartTypePane) cards.get(jcb.getSelectedIndex())).updateBean(chart); + ((AbstractChartTypePane)getSelectedPane()).updateBean(chart); Plot plot = chart.getPlot(); @@ -130,6 +139,88 @@ public class ChartTypePane extends AbstractChartAttrPane{ } } } + + 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()]); + } + }); + } + + public void reactor(ChartCollection collection){ + //重构前存储所选择的下拉选项 + Object item = jcb.getSelectedItem(); + //重构需要重构下拉框选项和cardNames + Chart chart = collection.getSelectedChart(); + String chartID = chart.getChartID(); + if (collection.getState() == SwitchState.DEFAULT){ + chartID = StringUtils.EMPTY; + } + //第一步就是重构cardNames + cardNames = ChartTypeInterfaceManager.getInstance().getTitle4PopupWindow(chartID); + //重构下拉框选项 + FlexibleComboBox fcb = (FlexibleComboBox)jcb; + fcb.setItemEvenType(ItemEventType.REACTOR); + fcb.removeAllItems(); + for (int i = 0; i < this.cardNames.length; i++) { + fcb.addItem(cardNames[i]); + } + //重新选择选中的下拉项 + jcb.setSelectedItem(item); + fcb.setItemEvenType(ItemEventType.DEFAULT); + } + + @Override + public void populateBean(Chart 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 Chart 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); + } + + } + + + public void reactorChartTypePane(ChartCollection collection){ + chartTypePane.reactor(collection); } /** diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/item/FlexibleComboBox.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/item/FlexibleComboBox.java new file mode 100644 index 0000000000..991858a9a5 --- /dev/null +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/item/FlexibleComboBox.java @@ -0,0 +1,54 @@ +package com.fr.design.mainframe.chart.gui.item; + +import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.gui.icombobox.UIComboBox; + +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** + * Created by hufan on 2016/10/11. + */ +public class FlexibleComboBox extends UIComboBox { + //当前下拉框处理的事件类型 + private ItemEventType itemEvenType = ItemEventType.DEFAULT; + + public boolean isReactor(){ + return itemEvenType == ItemEventType.REACTOR; + } + + public ItemEventType getItemEvenType() { + return itemEvenType; + } + + public void setItemEvenType(ItemEventType itemEvenType) { + this.itemEvenType = itemEvenType; + } + + @Override + protected void initListener() { + if (shouldResponseChangeListener()) { + this.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + fireSetGlobalName(); + } + }); + this.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (uiObserverListener == null) { + return; + } + fireSetGlobalName(); + //只有不在重构状态才会触发下拉框选择时的改变事件 + if (e.getStateChange() == ItemEvent.SELECTED && !isReactor()) { + uiObserverListener.doChange(); + } + } + }); + } + } +} \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/item/ItemEventType.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/item/ItemEventType.java new file mode 100644 index 0000000000..4a7332d537 --- /dev/null +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/item/ItemEventType.java @@ -0,0 +1,37 @@ +package com.fr.design.mainframe.chart.gui.item; + +import com.fr.general.ComparatorUtils; + +/** + * Created by hufan on 2016/10/11. + */ +public enum ItemEventType { + REACTOR("reactor"),//重构选项 + DEFAULT("default")//默认选项操作 + ; + + //这个String会存起来的,不能随意更改。 + private String type; + + private ItemEventType(String type){ + this.type = type; + } + + public String getType() { + return this.type; + } + + private static ItemEventType[] types; + + public static ItemEventType parse(String type){ + if(types == null){ + types = ItemEventType.values(); + } + for(ItemEventType itemEventType : types){ + if(ComparatorUtils.equals(itemEventType.getType(), type)){ + return itemEventType; + } + } + return DEFAULT; + } +} \ No newline at end of file