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.

194 lines
6.9 KiB

2 years ago
package com.fr.plugin.pielinecomb.ui;
import com.fr.design.gui.ibutton.UIButton;
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.design.style.color.ColorSelectBox;
import com.fr.json.JSONObject;
import com.fr.plugin.pielinecomb.vo.CustomJsonObject;
import com.fr.plugin.pielinecomb.vo.ItemColorJson;
import com.fr.plugin.pielinecomb.vo.ItemLabelJson;
import com.fr.plugin.pielinecomb.vo.ItemTipsJson;
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 PieLineCombLabelCondCreator extends AbstractVanChartScrollPane<CustomJsonObject> {
private UITextArea condition;
private ColorSelectBox bgcolor;
@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.bgcolor.setSelectObject(MapUtil.toColor(chartConf.getString("bgcolor", "#ffffff")));
this.condition.setText(chartConf.getString("condition"));
}
}
@Override
public CustomJsonObject updateBean() {
JSONObject chartConf = JSONObject.create();
chartConf.put("bgcolor", MapUtil.toHex(this.bgcolor.getSelectObject()));
chartConf.put("condition", this.condition.getText());
CustomJsonObject json = new CustomJsonObject();
json.put(chartConf);
return json;
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Plugin-BmwGantt-Cond-condTaskBgTitle");
}
protected class ContentPane extends JPanel {
public ContentPane() {
initComponents();
}
private void initComponents() {
this.setLayout(new BorderLayout());
JPanel condPane = createConditionPane();
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[]{condPane},
new Component[]{linePane}
};
JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents, rowSize, columnSize);
this.add(panel, BorderLayout.CENTER);
this.setVisible(true);
}
}
private JPanel createLinePane() {
this.bgcolor = new ColorSelectBox(100);
Component[][] components = new Component[][]{
{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-BmwGantt-Cond-bgcolor")), this.bgcolor}
};
double p = TableLayout.PREFERRED;
double[] columnSize = {TableLayout.PREFERRED, TableLayout.FILL};
double[] rowSize = {p, p, p};
JPanel panel = TableLayout4VanChartHelper.createGapTableLayoutPane(components, rowSize, columnSize);
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-BmwGantt-Cond-BgStyleExpand"), panel);
}
private JPanel createConditionPane() {
condition = new UITextArea(3, 6);
final UITextField value = new UITextField();
final UIComboBox cond = new UIComboBox(new String[]{"==", "!="});
UILabel name = new UILabel(Toolkit.i18nText("Plugin-BmwGantt-Cond-groupNameLabel"));
UIButton add = new UIButton(Toolkit.i18nText("Plugin-BmwGantt-Cond-addButton"));
UIButton clear = new UIButton(Toolkit.i18nText("Plugin-BmwGantt-Cond-clearButton"));
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] components = new Component[][]{
new Component[]{name, cond, value, add, clear}
};
JPanel condPane = TableLayout4VanChartHelper.createGapTableLayoutPane(components, 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[]{condPane},
new Component[]{areaPane}
};
JPanel sumPane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{f});
condition.setEnabled(false);
add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String srcStr = condition.getText();
if (null != srcStr && !"".equals(srcStr)) {
srcStr += " && ";
}
String condstr = "'{分组名}' " + cond.getSelectedItem() + " '" + value.getText() + "'";
condition.setText(srcStr + condstr);
}
});
clear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
condition.setText("");
}
});
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-BmwGantt-Cond-condTaskBgTitle"), sumPane);
}
public static class PieLineCombStyleColorCondCreator extends PieLineCombLabelCondCreator {
@Override
public CustomJsonObject updateBean() {
ItemColorJson json = new ItemColorJson();
CustomJsonObject srcObj = super.updateBean();
srcObj.get().put("title", json.getTilte());
json.put(srcObj.get());
return json;
}
}
public static class PieLineCombStyleLabelCondCreator extends PieLineCombLabelCondCreator {
@Override
public CustomJsonObject updateBean() {
ItemLabelJson json = new ItemLabelJson();
CustomJsonObject srcObj = super.updateBean();
srcObj.get().put("title", json.getTilte());
json.put(srcObj.get());
return json;
}
}
public static class PieLineCombStyleTipsCondCreator extends PieLineCombLabelCondCreator {
@Override
public CustomJsonObject updateBean() {
ItemTipsJson json = new ItemTipsJson();
CustomJsonObject srcObj = super.updateBean();
srcObj.get().put("title", json.getTilte());
json.put(srcObj.get());
return json;
}
}
}