Browse Source

新老图表都做插件

master
Fangjie Hu 8 years ago
parent
commit
29cbdf4b56
  1. 18
      designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java
  2. 50
      designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java
  3. 128
      designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java
  4. 95
      designer_chart/src/com/fr/design/mainframe/chart/gui/item/FlexibleComboBox.java
  5. 37
      designer_chart/src/com/fr/design/mainframe/chart/gui/item/ItemEvenType.java

18
designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java

@ -203,6 +203,24 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh
}
/**
* 把chartID的pane加到list里
*
* @param chartID 图表类型
* @param paneList pane容器
*/
public void addPlotTypePaneList(List<FurtherBasicBeanPane<? extends Chart>> paneList, String chartID) {
///////////////////////////待更改///////////////////////////////
Iterator iterator = chartTypeInterfaces.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
IndependentChartUIProvider creator = (IndependentChartUIProvider) entry.getValue();
paneList.add(creator.getPlotTypePane());
}
}
public ChartDataPane getChartDataPane(String plotID, AttributeChangeListener listener) {
return chartTypeInterfaces.get(plotID).getChartDataPane(listener);
}

50
designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java

@ -35,7 +35,6 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
private static final int B_H = 20;
private static final int COL_COUNT = 3;
private ChartTypePane parent;
private UIButton addButton;
private ArrayList<ChartChangeButton> indexList = new ArrayList<ChartChangeButton>();
@ -45,6 +44,8 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
private ComboBoxPane editChartType;
private UITextField currentEditingEditor = null;
private ChartTypePane parent = null;
private boolean mouseOnChartTypeButtonPane = false;
/**
@ -70,6 +71,11 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> 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"));
@ -91,11 +97,6 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK);
}
public ChartTypeButtonPane(ChartTypePane parent){
this();
this.parent = parent;
}
ActionListener addListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -108,40 +109,26 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
indexList.add(button);
if (editingCollection != null) {
//这个地方应该判断是clone VanChart还是clone Chart
Chart[] clonedChart = null;
if (editingCollection.getState() == SwitchState.NEW) {
}else {
clonedChart = ColumnIndependentChart.columnChartTypes;
}
//点击添加按钮,则会触发切换状态
Chart chart = editingCollection.getChangeStateNewChart();
try {
Chart newChart = (Chart) clonedChart[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(state, editingCollection);
}
}
layoutPane(buttonPane);
//刷新下拉框
refreshChangeMode();
}
};
private void refreshChangeMode() {
//判断当前编辑的图表,对否开启多图表切换模式
boolean stateChange = editingCollection.setMultiChartMode();
//只有状态切换了才会重构下拉选项
if (parent != null && stateChange){
parent.fireReactor(editingCollection);
}
}
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
@ -281,9 +268,9 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
//新建一个collection
if(editingCollection != null && editingCollection.getChartCount() == 1){
//vanChart 不支持图表切换 目前
/*if(!ComparatorUtils.equals(editingCollection.getSelectedChart().getClass(), Chart.class)){
if(!ComparatorUtils.equals(editingCollection.getSelectedChart().getClass(), Chart.class)){
addButton.setVisible(false);
}*/
}
}
}
@ -399,9 +386,8 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
}
}
}
relayoutPane();
refreshChangeMode();
relayoutPane();
}
private void relayoutPane() {

128
designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java

@ -4,24 +4,19 @@ 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.mainframe.chart.gui.item.FlexibleComboBox;
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.ItemEvenType;
import com.fr.design.mainframe.chart.gui.type.AbstractChartTypePane;
import com.fr.general.Inter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.List;
@ -35,6 +30,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
private ChartTypeButtonPane buttonPane;
private ChartEditPane editPane;
private ChartCollection editingCollection;
@Override
protected JPanel createContentPane() {
JPanel content = new JPanel(new BorderLayout());
@ -71,6 +67,10 @@ public class ChartTypePane extends AbstractChartAttrPane{
return content;
}
public void reactorChartTypePane(SwitchState state, ChartCollection collection){
}
/**
* 界面做为按钮时的图片位置. design_base
*/
@ -90,7 +90,12 @@ public class ChartTypePane extends AbstractChartAttrPane{
@Override
protected List<FurtherBasicBeanPane<? extends Chart>> initPaneList() {
List<FurtherBasicBeanPane<? extends Chart>> paneList = new ArrayList<FurtherBasicBeanPane<? extends Chart>>();
if (editingCollection.getState() == SwitchState.DEFAULT) {
ChartTypeInterfaceManager.getInstance().addPlotTypePaneList(paneList);
}else {
Chart chart = editingCollection.getSelectedChart();
ChartTypeInterfaceManager.getInstance().addPlotTypePaneList(paneList, chart.getChartID());
}
return paneList;
}
@ -101,10 +106,9 @@ public class ChartTypePane extends AbstractChartAttrPane{
public void updateBean(Chart chart) {
int lastSelectIndex = editPane.getSelectedChartIndex(chart);
FlexibleComboBox fcb = (FlexibleComboBox)jcb;
try{
Chart newDefaultChart = (Chart)((AbstractChartTypePane)cards.get(fcb.getRelatedSelectedIndex())).getDefaultChart().clone();
Chart newDefaultChart = (Chart)((AbstractChartTypePane)cards.get(jcb.getSelectedIndex())).getDefaultChart().clone();
if(!chart.accept(newDefaultChart.getClass())){
//vanChart 和 chart 之间切换
editingCollection.removeNameObject(editingCollection.getSelectedIndex());
@ -116,7 +120,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
}
//这一步会替换plot
((AbstractChartTypePane) cards.get(fcb.getRelatedSelectedIndex())).updateBean(chart);
((AbstractChartTypePane) cards.get(jcb.getSelectedIndex())).updateBean(chart);
Plot plot = chart.getPlot();
@ -131,115 +135,11 @@ public class ChartTypePane extends AbstractChartAttrPane{
boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(plotID);
if(editPane.isDefaultPane() != isUseDefault || (!isUseDefault && lastSelectIndex != fcb.getRelatedSelectedIndex())){
if(editPane.isDefaultPane() != isUseDefault || (!isUseDefault && lastSelectIndex != jcb.getSelectedIndex())){
editPane.reLayout(chart);
}
}
}
@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);
((FlexibleComboBox)jcb).setRelatedSelectedIndex(i);
return;
}
}
}
@Override
protected UIComboBox createComboBox() {
FlexibleComboBox comboBox = new FlexibleComboBox();
//初始化分界线
int partition = 0;
for (int i = 0; i < this.cards.size(); i++) {
String name = cards.get(i).title4PopupWindow();
if (name.contains(Inter.getLocText("Plugin-ChartF_NewChart"))) {
partition++;
}
}
comboBox.setPartition(partition);
return comboBox;
}
/**
* 下拉框重构条件
* 1从None->Default(multiMode)
* 2从None->New(multiMode)
* 3从Default->None(singleMode)
* 4从New->None(singleMode)
* @param is2MultiMode
* @param isVanChart
*/
private void reactorComboBoxItem(boolean is2MultiMode, boolean isVanChart){
if (jcb == null){
return;
}
//重构下拉选项
FlexibleComboBox fcb = (FlexibleComboBox)jcb;
//重构前,保存相对下标
int relativeIndex = is2MultiMode ? fcb.getSelectedIndex() : fcb.getRelatedSelectedIndex();
//多图表切换模式
fcb.setMultiMode(is2MultiMode);
//设置当前切换是新图表还是老图表
fcb.setBottom(!isVanChart);
//重构下拉框选项
fcb.setItemEvenType(ItemEvenType.REACTOR);
jcb.removeAllItems();
for (int i = 0; i < this.cards.size(); i++) {
String name = cards.get(i).title4PopupWindow();
if (is2MultiMode && (name.contains(Inter.getLocText("Plugin-ChartF_NewChart")) && isVanChart)) {
jcb.addItem(cards.get(i).title4PopupWindow());
} else if (is2MultiMode && (!name.contains(Inter.getLocText("Plugin-ChartF_NewChart")) && !isVanChart)) {
jcb.addItem(cards.get(i).title4PopupWindow());
}else if (!is2MultiMode){
jcb.addItem(cards.get(i).title4PopupWindow());
}
}
//重置选择项
fcb.setRelatedSelectedIndex(relativeIndex);
//重构完成
fcb.setItemEvenType(ItemEvenType.DEFAULT);
}
@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[((FlexibleComboBox)jcb).getRelatedSelectedIndex()]);
}
});
}
}
public void fireReactor(ChartCollection collection) {
switch (collection.getState()){
case NEW:{
this.chartTypePane.reactorComboBoxItem(true, true);
break;
}
case DEFAULT:{
this.chartTypePane.reactorComboBoxItem(true, false);
break;
}
case NONE:{
this.chartTypePane.reactorComboBoxItem(false, false);
break;
}
default:this.chartTypePane.reactorComboBoxItem(false, false);
}
}
/**

95
designer_chart/src/com/fr/design/mainframe/chart/gui/item/FlexibleComboBox.java

@ -1,95 +0,0 @@
package com.fr.design.mainframe.chart.gui.item;
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 int partition = 0;
//分界线上还是分界线下
private boolean bottom = true;
//图表是否开启切换模式
private boolean multiMode = false;
//当前下拉框处理的事件类型
private ItemEvenType itemEvenType = ItemEvenType.DEFAULT;
public boolean isReactor(){
return itemEvenType == ItemEvenType.REACTOR;
}
public int getPartition() {
return partition;
}
public void setPartition(int partition) {
this.partition = partition;
}
public boolean isBottom() {
return bottom;
}
public void setBottom(boolean bottom) {
this.bottom = bottom;
}
public boolean isMultiMode() {
return multiMode;
}
public void setMultiMode(boolean multiMode) {
this.multiMode = multiMode;
}
public ItemEvenType getItemEvenType() {
return itemEvenType;
}
public void setItemEvenType(ItemEvenType itemEvenType) {
this.itemEvenType = itemEvenType;
}
public int getRelatedSelectedIndex(){
return isMultiMode() && isBottom() ? (super.getSelectedIndex() + partition) : super.getSelectedIndex();
}
public void setRelatedSelectedIndex(int index){
if (isMultiMode() && isBottom()){
super.setSelectedIndex(index - partition);
}else {
super.setSelectedIndex(index);
}
}
@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();
}
}
});
}
}
}

37
designer_chart/src/com/fr/design/mainframe/chart/gui/item/ItemEvenType.java

@ -1,37 +0,0 @@
package com.fr.design.mainframe.chart.gui.item;
import com.fr.general.ComparatorUtils;
/**
* Created by hufan on 2016/10/11.
*/
public enum ItemEvenType {
REACTOR("reactor"),//重构选项
DEFAULT("default")//默认选项操作
;
//这个String会存起来的,不能随意更改。
private String type;
private ItemEvenType(String type){
this.type = type;
}
public String getType() {
return this.type;
}
private static ItemEvenType[] types;
public static ItemEvenType parse(String type){
if(types == null){
types = ItemEvenType.values();
}
for(ItemEvenType itemEvenType : types){
if(ComparatorUtils.equals(itemEvenType.getType(), type)){
return itemEvenType;
}
}
return DEFAULT;
}
}
Loading…
Cancel
Save