forked from fanruan/finekit
白岳
5 years ago
14 changed files with 340 additions and 109 deletions
@ -1,78 +0,0 @@
|
||||
package com.fanruan.api.design.chart.field; |
||||
|
||||
import com.fanruan.api.design.ui.component.UIComboBox; |
||||
import com.fanruan.api.engine.chart.field.ColumnFieldCollection; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.Component; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2019-09-17 |
||||
*/ |
||||
public abstract class AbstractDataSetFieldsPane<T extends ColumnFieldCollection> extends com.fr.design.chartx.fields.AbstractDataSetFieldsPane<T> { |
||||
/** |
||||
* 初始化面板布局,默认会加载北部、中部和南部的面板 |
||||
*/ |
||||
@Override |
||||
protected void initComponents() { |
||||
super.initComponents(); |
||||
} |
||||
|
||||
/** |
||||
* 创建中部位置的面板,默认会通过所有的组件和组件名称生成面板。 |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
@Override |
||||
protected JPanel createCenterPane() { |
||||
return super.createCenterPane(); |
||||
} |
||||
|
||||
/** |
||||
* 创建北部位置的面板,默认生成空面板 |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
@Override |
||||
protected JPanel createNorthPane() { |
||||
return super.createNorthPane(); |
||||
} |
||||
|
||||
/** |
||||
* 创建南部位置的面板,默认生成空面板 |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
@Override |
||||
protected JPanel createSouthPane() { |
||||
return super.createSouthPane(); |
||||
} |
||||
|
||||
/** |
||||
* 面板中所有组件,默认会去获取所有下拉框组件 |
||||
* |
||||
* @return 所有组件的集合 |
||||
*/ |
||||
@Override |
||||
protected Component[] fieldComponents() { |
||||
return super.fieldComponents(); |
||||
} |
||||
|
||||
/** |
||||
* 面板中所有组件的名称 |
||||
* |
||||
* @return 所有组件的名称集合 |
||||
*/ |
||||
@Override |
||||
protected abstract String[] fieldLabels(); |
||||
|
||||
/** |
||||
* 面板中的下拉框组件 |
||||
* |
||||
* @return 下拉框组件的集合 |
||||
*/ |
||||
@Override |
||||
protected abstract UIComboBox[] filedComboBoxes(); |
||||
} |
@ -0,0 +1,118 @@
|
||||
package com.fanruan.api.design.chart.field; |
||||
|
||||
import com.fanruan.api.design.ui.component.UIComboBox; |
||||
import com.fanruan.api.design.ui.component.chart.CalculateComboBox; |
||||
import com.fanruan.api.engine.chart.field.BaseColumnFieldCollection; |
||||
import com.fr.chartx.data.field.ColumnField; |
||||
import com.fr.design.chartx.fields.AbstractDataSetFieldsPane; |
||||
import com.fr.general.GeneralUtils; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.Component; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2019-09-17 |
||||
*/ |
||||
public abstract class BaseDataSetFieldsPane<T extends BaseColumnFieldCollection> extends AbstractDataSetFieldsPane<T> { |
||||
/** |
||||
* 初始化面板布局,默认会加载北部、中部和南部的面板 |
||||
*/ |
||||
@Override |
||||
protected void initComponents() { |
||||
super.initComponents(); |
||||
} |
||||
|
||||
/** |
||||
* 创建中部位置的面板,默认会通过所有的组件和组件名称生成面板。 |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
@Override |
||||
protected JPanel createCenterPane() { |
||||
return super.createCenterPane(); |
||||
} |
||||
|
||||
/** |
||||
* 创建北部位置的面板,默认生成空面板 |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
@Override |
||||
protected JPanel createNorthPane() { |
||||
return super.createNorthPane(); |
||||
} |
||||
|
||||
/** |
||||
* 创建南部位置的面板,默认生成空面板 |
||||
* |
||||
* @return 面板 |
||||
*/ |
||||
@Override |
||||
protected JPanel createSouthPane() { |
||||
return super.createSouthPane(); |
||||
} |
||||
|
||||
/** |
||||
* 面板中所有组件,默认会去获取所有下拉框组件 |
||||
* |
||||
* @return 所有组件的集合 |
||||
*/ |
||||
@Override |
||||
protected Component[] fieldComponents() { |
||||
return super.fieldComponents(); |
||||
} |
||||
|
||||
/** |
||||
* 面板中所有组件的名称 |
||||
* |
||||
* @return 所有组件的名称集合 |
||||
*/ |
||||
@Override |
||||
protected abstract String[] fieldLabels(); |
||||
|
||||
/** |
||||
* 面板中的下拉框组件 |
||||
* |
||||
* @return 下拉框组件的集合 |
||||
*/ |
||||
@Override |
||||
protected abstract UIComboBox[] filedComboBoxes(); |
||||
|
||||
/** |
||||
* 根据字段对象的属性,更新下拉选择组件的值 |
||||
*/ |
||||
protected void populateField(UIComboBox comboBox, ColumnField field) { |
||||
AbstractDataSetFieldsPane.populateField(comboBox, field); |
||||
} |
||||
|
||||
/** |
||||
* 根据下拉选择组件的值,更新字段对象的属性 |
||||
*/ |
||||
protected void updateField(UIComboBox comboBox, ColumnField field) { |
||||
AbstractDataSetFieldsPane.updateField(comboBox, field); |
||||
} |
||||
|
||||
/** |
||||
* 根据字段对象的属性,更新下拉选择组件和汇总方式选择组件的值 |
||||
*/ |
||||
protected void populateFunctionField(UIComboBox comboBox, CalculateComboBox calculateComboBox, ColumnField field) { |
||||
comboBox.setSelectedItem(field.getFieldName()); |
||||
if (calculateComboBox != null) { |
||||
calculateComboBox.populateBean(field.getDataFunction()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据下拉选择组件和汇总方式选择组件的值,更新字段对象的属性 |
||||
*/ |
||||
protected void updateFunctionField(UIComboBox comboBox, CalculateComboBox calculateComboBox, ColumnField field) { |
||||
field.setFieldName(GeneralUtils.objectToString(comboBox.getSelectedItem())); |
||||
if (calculateComboBox != null) { |
||||
field.setDataFunction(calculateComboBox.updateBean()); |
||||
} else { |
||||
field.setDataFunction(null); |
||||
} |
||||
} |
||||
} |
@ -1,9 +1,59 @@
|
||||
package com.fanruan.api.design.ui.component.chart; |
||||
|
||||
import com.fanruan.api.design.ui.component.UIComboBox; |
||||
import com.fr.data.util.function.DataFunction; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.log.FineLoggerFactory; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2019-09-23 |
||||
*/ |
||||
public class CalculateComboBox extends com.fr.design.mainframe.chart.gui.data.CalculateComboBox { |
||||
public class CalculateComboBox extends UIComboBox { |
||||
|
||||
private static String[] functionName = initItem(); |
||||
|
||||
private static String[] initItem() { |
||||
String[] functionLocaleNames = DataFunctionType.getFunctionLocaleNames(); |
||||
for (int i = 0; i < functionLocaleNames.length; i++) { |
||||
functionLocaleNames[i] = Toolkit.i18nText(functionLocaleNames[i]); |
||||
} |
||||
return functionLocaleNames; |
||||
} |
||||
|
||||
public CalculateComboBox() { |
||||
super(functionName); |
||||
setSelectedIndex(0); |
||||
} |
||||
|
||||
public void reset() { |
||||
this.setSelectedItem(0); |
||||
} |
||||
|
||||
/** |
||||
* 通过公式对象,更新界面的公式选择 |
||||
*/ |
||||
public void populateBean(DataFunction function) { |
||||
int index = DataFunctionType.getIndexByFunction(function); |
||||
if (index > 0) { |
||||
this.setSelectedIndex(index); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据界面选择的公式,返回公式对象 |
||||
*/ |
||||
public DataFunction updateBean() { |
||||
try { |
||||
int selectIndex = getSelectedIndex(); |
||||
DataFunction functionByIndex = DataFunctionType.getFunctionByIndex(selectIndex); |
||||
return functionByIndex; |
||||
} catch (InstantiationException e) { |
||||
FineLoggerFactory.getLogger().error("Function Error"); |
||||
} catch (IllegalAccessException e) { |
||||
FineLoggerFactory.getLogger().error("Function Error"); |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,65 @@
|
||||
package com.fanruan.api.design.ui.component.chart; |
||||
|
||||
import com.fr.data.util.function.AverageFunction; |
||||
import com.fr.data.util.function.CountFunction; |
||||
import com.fr.data.util.function.DataFunction; |
||||
import com.fr.data.util.function.MaxFunction; |
||||
import com.fr.data.util.function.MinFunction; |
||||
import com.fr.data.util.function.NoneFunction; |
||||
import com.fr.data.util.function.SumFunction; |
||||
import com.fr.general.ComparatorUtils; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2019-09-24 |
||||
*/ |
||||
public enum DataFunctionType { |
||||
|
||||
NONE_FUNCTION("Fine-Design_Chart_Data_Function_None", NoneFunction.class), |
||||
SUM_FUNCTION("Fine-Design_Chart_Data_Function_Sum", SumFunction.class), |
||||
AVERAGE_FUNCTION("Fine-Design_Chart_Data_Function_Average", AverageFunction.class), |
||||
MAX_FUNCTION("Fine-Design_Chart_Data_Function_Max", MaxFunction.class), |
||||
MIN_FUNCTION("Fine-Design_Chart_Data_Function_Min", MinFunction.class), |
||||
COUNT_FUNCTION("Fine-Design_Chart_Data_Function_Count", CountFunction.class); |
||||
|
||||
String functionLocaleName; |
||||
|
||||
Class functionClass; |
||||
|
||||
public static final int NONE_FUNCTION_INDEX = 0; |
||||
|
||||
DataFunctionType(String functionLocaleName, Class functionClass) { |
||||
this.functionLocaleName = functionLocaleName; |
||||
this.functionClass = functionClass; |
||||
} |
||||
|
||||
public static int getIndexByFunction(DataFunction function) { |
||||
if (function == null) { |
||||
return NONE_FUNCTION_INDEX; |
||||
} |
||||
for (DataFunctionType dataFunctionType : DataFunctionType.values()) { |
||||
if (ComparatorUtils.equals(dataFunctionType.functionClass, function.getClass())) { |
||||
return dataFunctionType.ordinal(); |
||||
} |
||||
} |
||||
return NONE_FUNCTION_INDEX; |
||||
} |
||||
|
||||
public static DataFunction getFunctionByIndex(int index) throws IllegalAccessException, InstantiationException { |
||||
DataFunctionType[] values = DataFunctionType.values(); |
||||
if (index < values.length) { |
||||
return (DataFunction) values[index].functionClass.newInstance(); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static String[] getFunctionLocaleNames() { |
||||
DataFunctionType[] values = DataFunctionType.values(); |
||||
String[] functionLocaleNames = new String[values.length]; |
||||
for (int i = 0; i < values.length; i++) { |
||||
functionLocaleNames[i] = values[i].functionLocaleName; |
||||
} |
||||
return functionLocaleNames; |
||||
} |
||||
} |
Loading…
Reference in new issue