You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

190 lines
6.8 KiB

package com.fr.plugin.pielinecomb.ui;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.pielinecomb.PieLineCombChart;
import com.fr.plugin.pielinecomb.vo.CustomJsonObject;
import com.fr.plugin.pielinecomb.vo.SeriesAxisRelaJson;
import com.fr.van.chart.designer.AbstractVanChartScrollPane;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author duan.jingliang
*/
public class SeriesAxisRelaCondCreator extends AbstractVanChartScrollPane<CustomJsonObject> {
private UITextField seriesName;
private UIComboBox axisYName;
private PieLineCombChart chart;
private UITextArea condition;
public SeriesAxisRelaCondCreator() {
}
public SeriesAxisRelaCondCreator(PieLineCombChart chart) {
this.chart = chart;
}
@Override
protected JPanel createContentPane() {
return new ContentPane();
}
@Override
public void populateBean(CustomJsonObject json) {
JSONObject chartConf = null;
if (null != json) {
chartConf = json.get();
}
if (null != chartConf) {
//this.seriesName.setText(chartConf.getString("seriesName"));
this.condition.setText(chartConf.getString("condition"));
JSONArray axisYList = null;
if (null != chart) {
axisYList = chart.getAxisConf().getJSONArray("axisY");
}
if (null != axisYList && axisYList.size() > 0) {
java.util.List<String> axisYArr = new java.util.ArrayList<>();
for (int i = 0; i < axisYList.size(); i++) {
axisYArr.add(axisYList.getJSONObject(i).getString("axisName"));
}
this.axisYName.refreshBoxItems(axisYArr);
}
this.axisYName.setSelectedItem(chartConf.getString("axisYName"));
}
}
@Override
public CustomJsonObject updateBean() {
JSONObject chartConf = JSONObject.create();
//chartConf.put("seriesName", this.seriesName.getText());
chartConf.put("condition", this.condition.getText());
chartConf.put("axisYName", this.axisYName.getSelectedItem());
SeriesAxisRelaJson json = new SeriesAxisRelaJson();
chartConf.put("title", json.getTilte());
json.put(chartConf);
return json;
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Plugin-Pielinecomb-condition");
}
protected class ContentPane extends JPanel {
public ContentPane() {
initComponents();
}
private void initComponents() {
this.setLayout(new BorderLayout());
JPanel linePane = createLinePane();
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
double[] columnSize = {f};
double[] rowSize = {p, p, p};
Component[][] acomponents = new Component[][]{
new Component[]{linePane}
};
JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents, rowSize, columnSize);
this.add(panel, BorderLayout.CENTER);
this.setVisible(true);
}
}
private JPanel createLinePane() {
java.util.List<String> axisYArr = new java.util.ArrayList<>();
if (null != this.chart) {
JSONArray axisYList = chart.getAxisConf().getJSONArray("axisY");
if (null != axisYList && axisYList.size() > 0) {
for (int i = 0; i < axisYList.size(); i++) {
axisYArr.add(axisYList.getJSONObject(i).getString("axisName"));
}
this.axisYName.refreshBoxItems(axisYArr);
}
}
if (axisYArr.isEmpty()) {
axisYArr.add("Y轴");
}
//this.seriesName = new UITextField();
this.axisYName = new UIComboBox(axisYArr.toArray(new String[axisYArr.size()]));
//this.axisYPane = new JPanel(new BorderLayout());
//this.axisYPane.add(this.axisYName, BorderLayout.CENTER);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] components = new Component[][]{
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-StyleAxisTitle")), this.axisYName}
};
JPanel yPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, new double[]{p, p, p}, new double[]{p, f});
condition = new UITextArea(3, 6);
final UITextField value = new UITextField();
final UIComboBox filed = new UIComboBox(new String[]{"系列序号", "系列名称"});
final UIComboBox cond = new UIComboBox(new String[]{"==", ">", "<"});
UIButton add = new UIButton(Toolkit.i18nText("Plugin-Pielinecomb-Cond-AddCondtion"));
UIButton clear = new UIButton(Toolkit.i18nText("Plugin-Pielinecomb-Cond-clearButton"));
Component[][] compc = new Component[][]{
new Component[]{filed, cond, value, add, clear}
};
JPanel condPane = TableLayout4VanChartHelper.createGapTableLayoutPane(compc, new double[]{p, p}, new double[]{p, p, f, p, p});
Component[][] comp1 = new Component[][]{
new Component[]{condition}
};
JPanel areaPane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp1, new double[]{p}, new double[]{f});
Component[][] comp = new Component[][]{
new Component[]{yPane},
new Component[]{condPane},
new Component[]{areaPane}
};
JPanel sumPane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p, p}, new double[]{f});
add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String srcStr = condition.getText();
if (null != srcStr && !"".equals(srcStr)) {
srcStr += " && ";
}
String condstr = "'{" + filed.getSelectedItem() + "}' " + cond.getSelectedItem() + " '" + value.getText() + "'";
condition.setText(srcStr + condstr);
}
});
clear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
condition.setText("");
}
});
return sumPane;
}
}