forked from fanruan/design
zheng
6 years ago
10 changed files with 417 additions and 13 deletions
@ -0,0 +1,21 @@
|
||||
package com.fr.design.chartx; |
||||
|
||||
import com.fr.design.chartx.fields.diff.MultiPieCellDataFieldsPane; |
||||
import com.fr.design.chartx.fields.diff.MultiPieDataSetFieldsPane; |
||||
import com.fr.design.chartx.single.SingleDataPane; |
||||
import com.fr.design.gui.frpane.AttributeChangeListener; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/18. |
||||
*/ |
||||
public class MultiPieChartDataPane extends MultiCategoryChartDataPane { |
||||
|
||||
public MultiPieChartDataPane(AttributeChangeListener listener) { |
||||
super(listener); |
||||
} |
||||
|
||||
@Override |
||||
protected SingleDataPane createSingleDataPane() { |
||||
return new SingleDataPane(new MultiPieDataSetFieldsPane(), new MultiPieCellDataFieldsPane()); |
||||
} |
||||
} |
@ -0,0 +1,150 @@
|
||||
package com.fr.design.chartx.component; |
||||
|
||||
import com.fr.chartx.data.field.ColumnField; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.gui.ispinner.UISpinner; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.layout.TableLayoutHelper; |
||||
import com.fr.design.mainframe.chart.gui.ChartDataPane; |
||||
|
||||
import javax.swing.JComponent; |
||||
import javax.swing.JPanel; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Component; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/18. |
||||
* 一列组件<T extends JComponent> 可增可删,通过UISpinner增删。 |
||||
*/ |
||||
public abstract class AbstractMultiComponentPaneWithUISpinner<T extends JComponent> extends JPanel { |
||||
|
||||
private UISpinner levelNumSpinner; |
||||
|
||||
private List<T> levelComponentList = new ArrayList<T>(); |
||||
|
||||
private JPanel levelPane; |
||||
|
||||
private int currentNum = 3; |
||||
|
||||
public AbstractMultiComponentPaneWithUISpinner() { |
||||
initComps(); |
||||
} |
||||
|
||||
public List<T> getComponentList() { |
||||
return levelComponentList; |
||||
} |
||||
|
||||
protected abstract T createJComponent(); |
||||
|
||||
protected abstract void populateField(T component, ColumnField field); |
||||
|
||||
protected abstract void updateField(T component, ColumnField field); |
||||
|
||||
protected void initComps() { |
||||
|
||||
this.setLayout(new BorderLayout(0, 6)); |
||||
|
||||
levelNumSpinner = new UISpinner(1, 15, 1, currentNum) { |
||||
@Override |
||||
protected void fireStateChanged() { |
||||
//先处理自身的空间布局
|
||||
refreshLevelPane(); |
||||
//然后更新数据
|
||||
super.fireStateChanged(); |
||||
} |
||||
|
||||
@Override |
||||
public void setTextFieldValue(double value) { |
||||
//如果为0,则没有改变值
|
||||
if (value == 0) { |
||||
return; |
||||
} |
||||
super.setTextFieldValue(value); |
||||
} |
||||
}; |
||||
|
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Level_Number")), levelNumSpinner}, |
||||
}; |
||||
|
||||
JPanel northPane = TableLayoutHelper.createGapTableLayoutPane(components, new double[]{TableLayout.PREFERRED}, new double[]{ChartDataPane.LABEL_WIDTH, 122}, 0, 6); |
||||
|
||||
this.add(northPane, BorderLayout.NORTH); |
||||
|
||||
initLevelPane(); |
||||
} |
||||
|
||||
private void initLevelPane() { |
||||
double[] rows = new double[currentNum]; |
||||
|
||||
Component[][] components = new Component[currentNum][2]; |
||||
|
||||
List<T> newList = new ArrayList<T>(); |
||||
|
||||
int maxSize = levelComponentList.size(); |
||||
for (int i = 0; i < currentNum; i++) { |
||||
rows[i] = TableLayout.PREFERRED; |
||||
T component = i < maxSize ? levelComponentList.get(i) : createJComponent(); |
||||
newList.add(component); |
||||
|
||||
components[i] = new Component[]{ |
||||
new UILabel(Toolkit.i18nText("Fine-Design_Chart_Level") + String.valueOf(i + 1)), |
||||
component |
||||
}; |
||||
} |
||||
|
||||
levelComponentList = newList; |
||||
|
||||
levelPane = TableLayoutHelper.createGapTableLayoutPane(components, rows, new double[]{ChartDataPane.LABEL_WIDTH, 122}, 0, 6); |
||||
|
||||
this.add(levelPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
private void refreshLevelPane() { |
||||
if (levelNumSpinner == null) { |
||||
return; |
||||
} |
||||
|
||||
int newNum = (int) levelNumSpinner.getValue(); |
||||
|
||||
if (newNum != currentNum) { |
||||
currentNum = newNum; |
||||
this.remove(levelPane); |
||||
this.initLevelPane(); |
||||
} |
||||
|
||||
refreshPane(); |
||||
} |
||||
|
||||
private void refreshPane() { |
||||
this.validate(); |
||||
this.repaint(); |
||||
this.revalidate(); |
||||
} |
||||
|
||||
public void populate(List<ColumnField> categoryList) { |
||||
int len = categoryList.size(); |
||||
levelNumSpinner.setValue(len); |
||||
|
||||
refreshLevelPane(); |
||||
|
||||
for (int i = 0; i < len; i++) { |
||||
ColumnField columnField = categoryList.get(i); |
||||
T component = levelComponentList.get(i); |
||||
populateField(component, columnField); |
||||
} |
||||
} |
||||
|
||||
public void update(List<ColumnField> categoryList) { |
||||
categoryList.clear(); |
||||
|
||||
for (T comboBox : levelComponentList) { |
||||
ColumnField temp = new ColumnField(); |
||||
categoryList.add(temp); |
||||
updateField(comboBox, temp); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.fr.design.chartx.component; |
||||
|
||||
import com.fr.chartx.data.field.ColumnField; |
||||
import com.fr.design.chartx.fields.AbstractDataSetFieldsPane; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/18. |
||||
*/ |
||||
public class MultiComboBoxPaneWithUISpinner extends AbstractMultiComponentPaneWithUISpinner<UIComboBox> { |
||||
private List currentBoxList = new ArrayList(); |
||||
|
||||
@Override |
||||
protected void initComps() { |
||||
currentBoxList = new ArrayList(); |
||||
super.initComps(); |
||||
} |
||||
|
||||
public void setCurrentBoxList(List currentBoxList) { |
||||
this.currentBoxList = currentBoxList; |
||||
} |
||||
|
||||
@Override |
||||
protected UIComboBox createJComponent() { |
||||
return new UIComboBox(currentBoxList.toArray(new Object[currentBoxList.size()])); |
||||
} |
||||
|
||||
@Override |
||||
protected void populateField(UIComboBox component, ColumnField field) { |
||||
AbstractDataSetFieldsPane.populateField(component, field); |
||||
} |
||||
|
||||
@Override |
||||
protected void updateField(UIComboBox component, ColumnField field) { |
||||
AbstractDataSetFieldsPane.updateField(component, field); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.design.chartx.component; |
||||
|
||||
import com.fr.chartx.data.field.ColumnField; |
||||
import com.fr.design.chartx.fields.AbstractCellDataFieldsPane; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/19. |
||||
*/ |
||||
public class MultiTinyFormulaPaneWithUISpinner extends AbstractMultiComponentPaneWithUISpinner<TinyFormulaPane> { |
||||
@Override |
||||
protected TinyFormulaPane createJComponent() { |
||||
return new TinyFormulaPane(); |
||||
} |
||||
|
||||
@Override |
||||
protected void populateField(TinyFormulaPane component, ColumnField field) { |
||||
AbstractCellDataFieldsPane.populateField(component, field); |
||||
} |
||||
|
||||
@Override |
||||
protected void updateField(TinyFormulaPane component, ColumnField field) { |
||||
AbstractCellDataFieldsPane.updateField(component, field); |
||||
} |
||||
} |
@ -0,0 +1,67 @@
|
||||
package com.fr.design.chartx.fields.diff; |
||||
|
||||
import com.fr.chartx.data.field.diff.MultiPieColumnFieldCollection; |
||||
import com.fr.design.chartx.component.MultiTinyFormulaPaneWithUISpinner; |
||||
import com.fr.design.chartx.fields.AbstractCellDataFieldsPane; |
||||
import com.fr.design.formula.TinyFormulaPane; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.i18n.Toolkit; |
||||
|
||||
import javax.swing.JPanel; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/18. |
||||
*/ |
||||
public class MultiPieCellDataFieldsPane extends AbstractCellDataFieldsPane<MultiPieColumnFieldCollection> { |
||||
|
||||
private UITextField nameField;//指标名称
|
||||
|
||||
private MultiTinyFormulaPaneWithUISpinner levelPane; |
||||
|
||||
private TinyFormulaPane value; |
||||
|
||||
@Override |
||||
protected void initComponents() { |
||||
nameField = new UITextField(); |
||||
levelPane = new MultiTinyFormulaPaneWithUISpinner(); |
||||
value = new TinyFormulaPane(); |
||||
super.initComponents(); |
||||
} |
||||
|
||||
@Override |
||||
protected JPanel createNorthPane() { |
||||
return levelPane; |
||||
} |
||||
|
||||
@Override |
||||
protected String[] fieldLabels() { |
||||
return new String[]{ |
||||
Toolkit.i18nText("Fine-Design_Chart_Use_Value"), |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
protected TinyFormulaPane[] formulaPanes() { |
||||
return new TinyFormulaPane[]{ |
||||
value |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(MultiPieColumnFieldCollection ob) { |
||||
nameField.setText(ob.getTargetName()); |
||||
levelPane.populate(ob.getLevels()); |
||||
populateField(value, ob.getValue()); |
||||
} |
||||
|
||||
@Override |
||||
public MultiPieColumnFieldCollection updateBean() { |
||||
MultiPieColumnFieldCollection result = new MultiPieColumnFieldCollection(); |
||||
|
||||
result.setTargetName(nameField.getText()); |
||||
levelPane.update(result.getLevels()); |
||||
updateField(value, result.getValue()); |
||||
|
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,94 @@
|
||||
package com.fr.design.chartx.fields.diff; |
||||
|
||||
import com.fr.chartx.data.field.diff.MultiPieColumnFieldCollection; |
||||
import com.fr.design.chartx.component.MultiComboBoxPaneWithUISpinner; |
||||
import com.fr.design.chartx.fields.AbstractDataSetFieldsPane; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.itextfield.UITextField; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.mainframe.chart.gui.data.CalculateComboBox; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.Component; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Created by shine on 2019/6/18. |
||||
*/ |
||||
public class MultiPieDataSetFieldsPane extends AbstractDataSetFieldsPane<MultiPieColumnFieldCollection> { |
||||
private UITextField nameField; |
||||
|
||||
private MultiComboBoxPaneWithUISpinner levelComboBoxPane; |
||||
|
||||
private UIComboBox value; |
||||
|
||||
private CalculateComboBox function; |
||||
|
||||
@Override |
||||
protected void initComponents() { |
||||
nameField = new UITextField(); |
||||
levelComboBoxPane = new MultiComboBoxPaneWithUISpinner(); |
||||
value = new UIComboBox(); |
||||
function = new CalculateComboBox(); |
||||
super.initComponents(); |
||||
} |
||||
|
||||
@Override |
||||
protected JPanel createNorthPane() { |
||||
return levelComboBoxPane; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected String[] fieldLabels() { |
||||
return new String[]{ |
||||
Toolkit.i18nText("Fine-Design_Chart_Use_Value"), |
||||
Toolkit.i18nText("Fine-Design_Chart_Summary_Method") |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
protected Component[] fieldComponents() { |
||||
return new UIComboBox[]{ |
||||
value, |
||||
function |
||||
}; |
||||
} |
||||
|
||||
@Override |
||||
protected UIComboBox[] filedComboBoxes() { |
||||
List<UIComboBox> list = levelComboBoxPane.getComponentList(); |
||||
|
||||
int len = list.size(); |
||||
UIComboBox[] result = new UIComboBox[len + 1]; |
||||
for (int i = 0; i < len; i++) { |
||||
result[i] = list.get(i); |
||||
} |
||||
result[len] = value; |
||||
|
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public void refreshBoxListWithSelectTableData(List columnNameList) { |
||||
super.refreshBoxListWithSelectTableData(columnNameList); |
||||
levelComboBoxPane.setCurrentBoxList(columnNameList); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(MultiPieColumnFieldCollection ob) { |
||||
levelComboBoxPane.populate(ob.getLevels()); |
||||
populateFunctionField(value, function, ob.getValue()); |
||||
} |
||||
|
||||
@Override |
||||
public MultiPieColumnFieldCollection updateBean() { |
||||
MultiPieColumnFieldCollection result = new MultiPieColumnFieldCollection(); |
||||
|
||||
levelComboBoxPane.update(result.getLevels()); |
||||
|
||||
updateFunctionField(value, function, result.getValue()); |
||||
|
||||
return result; |
||||
} |
||||
} |
Loading…
Reference in new issue