Browse Source

图表切换-未完成

master
Fangjie Hu 8 years ago
parent
commit
583ce08dc9
  1. 14
      designer_base/src/com/fr/design/gui/frpane/UIComboBoxPane.java
  2. 6
      designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java
  3. 31
      designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java
  4. 137
      designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java
  5. 95
      designer_chart/src/com/fr/design/mainframe/chart/gui/item/FlexibleComboBox.java
  6. 37
      designer_chart/src/com/fr/design/mainframe/chart/gui/item/ItemEvenType.java

14
designer_base/src/com/fr/design/gui/frpane/UIComboBoxPane.java

@ -25,7 +25,7 @@ public abstract class UIComboBoxPane<T> extends BasicBeanPane<T> {
protected JPanel cardPane; protected JPanel cardPane;
protected List<FurtherBasicBeanPane<? extends T>> cards; protected List<FurtherBasicBeanPane<? extends T>> cards;
private String[] cardNames; protected String[] cardNames;
public UIComboBoxPane() { public UIComboBoxPane() {
cards = initPaneList(); cards = initPaneList();
@ -49,6 +49,14 @@ public abstract class UIComboBoxPane<T> extends BasicBeanPane<T> {
addComboBoxItem(cards, i); addComboBoxItem(cards, i);
} }
addItemChangeEvent();
initLayout();
jcb.setSelectedIndex(0);
}
protected void addItemChangeEvent() {
jcb.addItemListener(new ItemListener() { jcb.addItemListener(new ItemListener() {
@Override @Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
@ -57,10 +65,6 @@ public abstract class UIComboBoxPane<T> extends BasicBeanPane<T> {
cl.show(cardPane, cardNames[jcb.getSelectedIndex()]); cl.show(cardPane, cardNames[jcb.getSelectedIndex()]);
} }
}); });
initLayout();
jcb.setSelectedIndex(0);
} }
protected UIComboBox createComboBox() { protected UIComboBox createComboBox() {

6
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 static final int SIZE5 = 5;
private UIObserverListener uiObserverListener; protected UIObserverListener uiObserverListener;
private String comboBoxName = ""; private String comboBoxName = "";
@ -71,7 +71,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
initListener(); initListener();
} }
private void initListener() { protected void initListener() {
if (shouldResponseChangeListener()) { if (shouldResponseChangeListener()) {
this.addFocusListener(new FocusAdapter() { this.addFocusListener(new FocusAdapter() {
@Override @Override
@ -94,7 +94,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser
} }
} }
private void fireSetGlobalName() { protected void fireSetGlobalName() {
if (globalNameListener != null && shouldResponseNameListener()) { if (globalNameListener != null && shouldResponseNameListener()) {
globalNameListener.setGlobalName(comboBoxName); globalNameListener.setGlobalName(comboBoxName);
} }

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

@ -12,7 +12,6 @@ import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIToggleButton; import com.fr.design.gui.ibutton.UIToggleButton;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.mainframe.chart.AbstractChartAttrPane;
import com.fr.design.mainframe.chart.gui.ChartTypePane.ComboBoxPane; import com.fr.design.mainframe.chart.gui.ChartTypePane.ComboBoxPane;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
@ -36,7 +35,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
private static final int B_H = 20; private static final int B_H = 20;
private static final int COL_COUNT = 3; private static final int COL_COUNT = 3;
private AbstractChartAttrPane parent; private ChartTypePane parent;
private UIButton addButton; private UIButton addButton;
private ArrayList<ChartChangeButton> indexList = new ArrayList<ChartChangeButton>(); private ArrayList<ChartChangeButton> indexList = new ArrayList<ChartChangeButton>();
@ -92,7 +91,7 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK);
} }
public ChartTypeButtonPane(AbstractChartAttrPane parent){ public ChartTypeButtonPane(ChartTypePane parent){
this(); this();
this.parent = parent; this.parent = parent;
} }
@ -109,13 +108,6 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
indexList.add(button); indexList.add(button);
if (editingCollection != null) { if (editingCollection != null) {
//判断当前编辑的图表类型
if(!ComparatorUtils.equals(editingCollection.getSelectedChart().getClass(), Chart.class)){
editingCollection.setState(SwitchState.NEW);
}else {
editingCollection.setState(SwitchState.DEFAULT);
}
Chart[] barChart = ColumnIndependentChart.columnChartTypes; Chart[] barChart = ColumnIndependentChart.columnChartTypes;
try { try {
Chart newChart = (Chart) barChart[0].clone(); Chart newChart = (Chart) barChart[0].clone();
@ -128,12 +120,22 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
} }
layoutPane(buttonPane); layoutPane(buttonPane);
if (parent != null){ //刷新下拉框
parent.populate(editingCollection); refreshChangeMode();
}
} }
}; };
private void refreshChangeMode() {
//判断当前编辑的图表,对否开启多图表切换模式
boolean stateChange = editingCollection.setMultiChartMode();
//只有状态切换了才会重构下拉选项
if (parent != null && stateChange){
parent.fireReactor(editingCollection);
}
}
MouseListener mouseListener = new MouseAdapter() { MouseListener mouseListener = new MouseAdapter() {
@Override @Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
@ -391,8 +393,9 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
} }
} }
} }
relayoutPane(); relayoutPane();
refreshChangeMode();
} }
private void relayoutPane() { private void relayoutPane() {

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

@ -4,22 +4,24 @@ import com.fr.base.FRContext;
import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.Chart;
import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.chartattr.Plot; import com.fr.chart.chartattr.Plot;
import com.fr.chart.chartattr.SwitchState;
import com.fr.chart.charttypes.ChartTypeManager; import com.fr.chart.charttypes.ChartTypeManager;
import com.fr.design.ChartTypeInterfaceManager; import com.fr.design.ChartTypeInterfaceManager;
import com.fr.design.beans.FurtherBasicBeanPane; import com.fr.design.beans.FurtherBasicBeanPane;
import com.fr.design.dialog.BasicScrollPane; import com.fr.design.dialog.BasicScrollPane;
import com.fr.design.gui.frpane.UIComboBoxPane; 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.gui.icombobox.UIComboBox;
import com.fr.design.mainframe.chart.AbstractChartAttrPane; import com.fr.design.mainframe.chart.AbstractChartAttrPane;
import com.fr.design.mainframe.chart.ChartEditPane; import com.fr.design.mainframe.chart.ChartEditPane;
import com.fr.design.mainframe.chart.PaneTitleConstants; 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.design.mainframe.chart.gui.type.AbstractChartTypePane;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,7 +35,6 @@ public class ChartTypePane extends AbstractChartAttrPane{
private ChartTypeButtonPane buttonPane; private ChartTypeButtonPane buttonPane;
private ChartEditPane editPane; private ChartEditPane editPane;
private ChartCollection editingCollection; private ChartCollection editingCollection;
@Override @Override
protected JPanel createContentPane() { protected JPanel createContentPane() {
JPanel content = new JPanel(new BorderLayout()); JPanel content = new JPanel(new BorderLayout());
@ -100,9 +101,10 @@ public class ChartTypePane extends AbstractChartAttrPane{
public void updateBean(Chart chart) { public void updateBean(Chart chart) {
int lastSelectIndex = editPane.getSelectedChartIndex(chart); int lastSelectIndex = editPane.getSelectedChartIndex(chart);
FlexibleComboBox fcb = (FlexibleComboBox)jcb;
try{ try{
Chart newDefaultChart = (Chart)((AbstractChartTypePane)cards.get(jcb.getSelectedIndex())).getDefaultChart().clone(); Chart newDefaultChart = (Chart)((AbstractChartTypePane)cards.get(fcb.getRelatedSelectedIndex())).getDefaultChart().clone();
if(!chart.accept(newDefaultChart.getClass())){ if(!chart.accept(newDefaultChart.getClass())){
//vanChart 和 chart 之间切换 //vanChart 和 chart 之间切换
editingCollection.removeNameObject(editingCollection.getSelectedIndex()); editingCollection.removeNameObject(editingCollection.getSelectedIndex());
@ -114,7 +116,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
} }
//这一步会替换plot //这一步会替换plot
((AbstractChartTypePane) cards.get(jcb.getSelectedIndex())).updateBean(chart); ((AbstractChartTypePane) cards.get(fcb.getRelatedSelectedIndex())).updateBean(chart);
Plot plot = chart.getPlot(); Plot plot = chart.getPlot();
@ -129,77 +131,122 @@ public class ChartTypePane extends AbstractChartAttrPane{
boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(plotID); boolean isUseDefault = ChartTypeInterfaceManager.getInstance().isUseDefaultPane(plotID);
if(editPane.isDefaultPane() != isUseDefault || (!isUseDefault && lastSelectIndex != jcb.getSelectedIndex())){ if(editPane.isDefaultPane() != isUseDefault || (!isUseDefault && lastSelectIndex != fcb.getRelatedSelectedIndex())){
editPane.reLayout(chart); editPane.reLayout(chart);
} }
} }
} }
public void populateBean(ChartCollection collection) { @Override
Chart chart = collection.getSelectedChart(); public void populateBean(Chart ob) {
switch (collection.getState()){ for (int i = 0; i < this.cards.size(); i++) {
case NEW:{ FurtherBasicBeanPane pane = cards.get(i);
reactorComboBoxItem(chart, true); if (pane.accept(ob)) {
break; pane.populateBean(ob);
} ((FlexibleComboBox)jcb).setRelatedSelectedIndex(i);
case DEFAULT:{ return;
reactorComboBoxItem(chart, false);
break;
}
case NONE:{
populateBean(chart);
break;
} }
default:{ }
populateBean(chart); }
@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;
} }
private void reactorComboBoxItem(Chart chart, boolean isVanChart){
//重构下拉选项 /**
if (jcb != null) { * 下拉框重构条件
jcb.removeAllItems(); * 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++) { for (int i = 0; i < this.cards.size(); i++) {
String name = cards.get(i).title4PopupWindow(); String name = cards.get(i).title4PopupWindow();
if (name.contains(Inter.getLocText("Plugin-ChartF_NewChart")) && isVanChart){ if (is2MultiMode && (name.contains(Inter.getLocText("Plugin-ChartF_NewChart")) && isVanChart)) {
jcb.addItem(cards.get(i).title4PopupWindow()); jcb.addItem(cards.get(i).title4PopupWindow());
}else if (!name.contains(Inter.getLocText("Plugin-ChartF_NewChart")) && !isVanChart) { } 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()); jcb.addItem(cards.get(i).title4PopupWindow());
} }
} }
//重构完成
fcb.setItemEvenType(ItemEvenType.DEFAULT);
//重置选择项
fcb.setRelatedSelectedIndex(relativeIndex);
}
for (int i = 0; i < this.cards.size(); i++) { @Override
FurtherBasicBeanPane pane = cards.get(i); protected void addItemChangeEvent() {
if (pane.accept(chart)) { jcb.addItemListener(new ItemListener() {
pane.populateBean(chart); @Override
int index = getJcbIndex(pane, jcb); public void itemStateChanged(ItemEvent e) {
jcb.setSelectedIndex(index); //如果是在进行重构,则不触发状态改变事件
return; FlexibleComboBox fcb = (FlexibleComboBox)jcb;
if (fcb.isReactor()){
return;
}
comboBoxItemStateChanged();
CardLayout cl = (CardLayout)cardPane.getLayout();
cl.show(cardPane, cardNames[((FlexibleComboBox)jcb).getRelatedSelectedIndex()]);
} }
} });
} }
}
private int getJcbIndex(FurtherBasicBeanPane pane, UIComboBox jcb) { public void fireReactor(ChartCollection collection) {
String name = pane.title4PopupWindow(); switch (collection.getState()){
for (int i = 0; i < jcb.getItemCount(); i++){ case NEW:{
if (ComparatorUtils.equals(name, jcb.getItemAt(i))){ this.chartTypePane.reactorComboBoxItem(true, true);
return i; break;
}
} }
return 0; case DEFAULT:{
this.chartTypePane.reactorComboBoxItem(true, false);
break;
}
case NONE:{
this.chartTypePane.reactorComboBoxItem(false, false);
break;
}
default:this.chartTypePane.reactorComboBoxItem(false, false);
} }
} }
/** /**
* 更新界面属性 用于展示 * 更新界面属性 用于展示
*/ */
public void populate(ChartCollection collection) { public void populate(ChartCollection collection) {
Chart chart = collection.getSelectedChart(); Chart chart = collection.getSelectedChart();
chartTypePane.populateBean(collection); chartTypePane.populateBean(chart);
buttonPane.populateBean(collection); buttonPane.populateBean(collection);
} }

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

@ -0,0 +1,95 @@
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

@ -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 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