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

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.UIToggleButton;
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.general.ComparatorUtils;
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 COL_COUNT = 3;
private AbstractChartAttrPane parent;
private ChartTypePane parent;
private UIButton addButton;
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);
}
public ChartTypeButtonPane(AbstractChartAttrPane parent){
public ChartTypeButtonPane(ChartTypePane parent){
this();
this.parent = parent;
}
@ -109,13 +108,6 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
indexList.add(button);
if (editingCollection != null) {
//判断当前编辑的图表类型
if(!ComparatorUtils.equals(editingCollection.getSelectedChart().getClass(), Chart.class)){
editingCollection.setState(SwitchState.NEW);
}else {
editingCollection.setState(SwitchState.DEFAULT);
}
Chart[] barChart = ColumnIndependentChart.columnChartTypes;
try {
Chart newChart = (Chart) barChart[0].clone();
@ -128,12 +120,22 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
}
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() {
@Override
public void mouseExited(MouseEvent e) {
@ -391,8 +393,9 @@ public class ChartTypeButtonPane extends BasicBeanPane<ChartCollection> implemen
}
}
}
relayoutPane();
refreshChangeMode();
}
private void relayoutPane() {

139
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.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.ComparatorUtils;
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;
@ -33,7 +35,6 @@ public class ChartTypePane extends AbstractChartAttrPane{
private ChartTypeButtonPane buttonPane;
private ChartEditPane editPane;
private ChartCollection editingCollection;
@Override
protected JPanel createContentPane() {
JPanel content = new JPanel(new BorderLayout());
@ -84,7 +85,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
public String title4PopupWindow() {
return PaneTitleConstants.CHART_TYPE_TITLE;
}
class ComboBoxPane extends UIComboBoxPane<Chart>{
@Override
protected List<FurtherBasicBeanPane<? extends Chart>> initPaneList() {
@ -100,9 +101,10 @@ 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(jcb.getSelectedIndex())).getDefaultChart().clone();
Chart newDefaultChart = (Chart)((AbstractChartTypePane)cards.get(fcb.getRelatedSelectedIndex())).getDefaultChart().clone();
if(!chart.accept(newDefaultChart.getClass())){
//vanChart 和 chart 之间切换
editingCollection.removeNameObject(editingCollection.getSelectedIndex());
@ -114,7 +116,7 @@ public class ChartTypePane extends AbstractChartAttrPane{
}
//这一步会替换plot
((AbstractChartTypePane) cards.get(jcb.getSelectedIndex())).updateBean(chart);
((AbstractChartTypePane) cards.get(fcb.getRelatedSelectedIndex())).updateBean(chart);
Plot plot = chart.getPlot();
@ -129,77 +131,122 @@ public class ChartTypePane extends AbstractChartAttrPane{
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);
}
}
}
public void populateBean(ChartCollection collection) {
Chart chart = collection.getSelectedChart();
switch (collection.getState()){
case NEW:{
reactorComboBoxItem(chart, true);
break;
}
case DEFAULT:{
reactorComboBoxItem(chart, false);
break;
}
case NONE:{
populateBean(chart);
break;
@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;
}
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++) {
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());
}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());
}
}
//重构完成
fcb.setItemEvenType(ItemEvenType.DEFAULT);
//重置选择项
fcb.setRelatedSelectedIndex(relativeIndex);
}
for (int i = 0; i < this.cards.size(); i++) {
FurtherBasicBeanPane pane = cards.get(i);
if (pane.accept(chart)) {
pane.populateBean(chart);
int index = getJcbIndex(pane, jcb);
jcb.setSelectedIndex(index);
return;
@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()]);
}
}
});
}
}
private int getJcbIndex(FurtherBasicBeanPane pane, UIComboBox jcb) {
String name = pane.title4PopupWindow();
for (int i = 0; i < jcb.getItemCount(); i++){
if (ComparatorUtils.equals(name, jcb.getItemAt(i))){
return i;
}
public void fireReactor(ChartCollection collection) {
switch (collection.getState()){
case NEW:{
this.chartTypePane.reactorComboBoxItem(true, true);
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) {
Chart chart = collection.getSelectedChart();
chartTypePane.populateBean(collection);
chartTypePane.populateBean(chart);
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