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.
 
 

208 lines
8.3 KiB

package com.fr.plugin.pielinecomb.ui;
import com.fr.chart.base.TextAttr;
import com.fr.design.gui.frpane.UINumberDragPane;
import com.fr.design.gui.ibutton.UIButtonGroup;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea;
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.style.ChartTextAttrPane;
import com.fr.design.style.color.ColorSelectBox;
import com.fr.general.FRFont;
import com.fr.json.JSONObject;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
/**
* @author duan.jingliang
* @date 2022/10/22
*/
public class PieLineTipsPane extends JPanel {
private UIButtonGroup<Integer> valueType;
private JPanel cardPane;
private UICheckBox showTip;
private UICheckBox showCategory;
private UICheckBox showSeries;
private UICheckBox showValue;
private UITextArea jsPane;
private ChartTextAttrPane textAttrPane;
private ColorSelectBox bgColor;
private UINumberDragPane bgOpacity;
public PieLineTipsPane() {
initComponents();
}
public void populateBean(JSONObject chartConf) {
this.showTip.setSelected(chartConf.getBoolean("showTip"));
this.valueType.setSelectedItem(chartConf.getInt("valueType"));
this.showCategory.setSelected(chartConf.getBoolean("showCategory"));
this.showSeries.setSelected(chartConf.getBoolean("showSeries"));
this.showValue.setSelected(chartConf.getBoolean("showValue"));
this.jsPane.setText(chartConf.getString("jsPane"));
FRFont textFont = FRFont.getInstance(chartConf.getString("tipfamily"),
chartConf.getInt("tipstyle"),
chartConf.getInt("tipsize"),
MapUtil.toColor(chartConf.getString("tipcolor")));
this.textAttrPane.populate(textFont);
this.bgColor.setSelectObject(MapUtil.toColor(chartConf.getString("bgColor")));
this.bgOpacity.populateBean(chartConf.getDouble("bgOpacity"));
if (chartConf.getInt("valueType") == 2) {
((CardLayout)cardPane.getLayout()).show(cardPane, "piejs");
} else {
((CardLayout)cardPane.getLayout()).show(cardPane, "piecheck");
}
}
public JSONObject update() {
JSONObject chartConf = JSONObject.create();
chartConf.put("showTip", this.showTip.isSelected());
chartConf.put("valueType", this.valueType.getSelectedItem());
chartConf.put("showCategory", this.showCategory.isSelected());
chartConf.put("showSeries", this.showSeries.isSelected());
chartConf.put("showValue", this.showValue.isSelected());
chartConf.put("jsPane", this.jsPane.getText());
TextAttr textAttr = this.textAttrPane.update();
chartConf.put("tipsize", textAttr.getFRFont().getSize());
chartConf.put("tipstyle", textAttr.getFRFont().getStyle());
chartConf.put("tipfamily", textAttr.getFRFont().getFamily());
chartConf.put("tipcolor", MapUtil.toHex(textAttr.getFRFont().getForeground()));
chartConf.put("bgColor", MapUtil.toHex(this.bgColor.getSelectObject()));
chartConf.put("bgOpacity", this.bgOpacity.updateBean());
return chartConf;
}
private void initComponents() {
this.setLayout(new BorderLayout());
JPanel mainPane = createPieLabelPane();
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] acomponents = new Component[][]{
new Component[]{mainPane}
};
JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents, new double[]{p, p}, new double[]{f});
this.add(panel,BorderLayout.CENTER);
this.setVisible(true);
}
private JPanel createPieLabelPane() {
valueType = new UIButtonGroup<Integer>(new String[]{
com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-general"),
com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-custom")
},
new Integer[]{1, 2}
);
valueType.setSelectedItem(1);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] comp = new Component[][]{
{null},
new Component[]{this.valueType}
};
JPanel pieValueTypePane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{f});
showTip = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieTip"));
showCategory = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieCategory"));
showSeries = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieSeries"));
showValue = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieValue"));
Component[][] compCheck = new Component[][]{
new Component[]{showCategory},
new Component[]{showSeries},
new Component[]{showValue}
};
final JPanel checkPane = TableLayout4VanChartHelper.createGapTableLayoutPane(compCheck, new double[]{p, p, p, p}, new double[]{f});
jsPane = new UITextArea(6, 6);
cardPane = new JPanel(new CardLayout()){
@Override
public Dimension getPreferredSize() {
if (null != valueType.getSelectedItem() && valueType.getSelectedItem() == 2) {
return jsPane.getPreferredSize();
} else {
return checkPane.getPreferredSize();
}
}
};
cardPane.add(checkPane, "piecheck");
cardPane.add(jsPane, "piejs");
((CardLayout)cardPane.getLayout()).show(cardPane, "piecheck");
valueType.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent var1x) {
CardLayout card = (CardLayout)cardPane.getLayout();
if (valueType.getSelectedItem() == 1) {
card.show(cardPane, "piecheck");
} else {
card.show(cardPane, "piejs");
}
}
});
Component[][] contentComp = new Component[][]{
new Component[]{pieValueTypePane},
new Component[]{cardPane}
};
JPanel contentCompPane = TableLayout4VanChartHelper.createGapTableLayoutPane(contentComp, new double[]{p, p, p}, new double[]{f});
JPanel contentPane = TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-TitleText"), contentCompPane);
JPanel stylePane = createPieTextPane();
JPanel bgPane = createPieBgPane();
Component[][] comps = new Component[][]{
new Component[]{showTip},
new Component[]{contentPane},
new Component[]{stylePane},
new Component[]{bgPane}
};
return TableLayout4VanChartHelper.createGapTableLayoutPane(comps, new double[]{p, p, p, p, p}, new double[]{f});
}
private JPanel createPieTextPane() {
this.textAttrPane = new ChartTextAttrPane();
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-TitleStyle"), this.textAttrPane);
}
private JPanel createPieBgPane() {
this.bgColor = new ColorSelectBox(100);
this.bgOpacity = new UINumberDragPane(0, 100);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] comp = new Component[][]{
{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-titleBgColor")), this.bgColor},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-titleBgOpacity")), this.bgOpacity}
};
JPanel pane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p}, new double[]{p, f});
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-bgExpand"), pane);
}
}