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.
 
 

215 lines
9.0 KiB

package com.fr.plugin.pielinecomb.ui;
import com.fr.chart.base.TextAttr;
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.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 PieLabelStylePane extends JPanel {
private UIButtonGroup<Integer> pieValueType;
private CardLayout pieCardLayout;
private JPanel pieCardPane;
private UICheckBox showPieLabel;
private UICheckBox showPieCategory;
private UICheckBox showPieSeries;
private UICheckBox showPieValue;
private UITextArea pieJsPane;
private ChartTextAttrPane pieTextAttrPane;
private UIButtonGroup<String> piePosition;
private UIButtonGroup<Integer> pieDirection;
public PieLabelStylePane() {
initComponents();
}
public void populateBean(JSONObject chartConf) {
this.showPieLabel.setSelected(chartConf.getBoolean("showPieLabel"));
this.pieValueType.setSelectedItem(chartConf.getInt("pieValueType"));
this.showPieCategory.setSelected(chartConf.getBoolean("showPieCategory"));
this.showPieSeries.setSelected(chartConf.getBoolean("showPieSeries"));
this.showPieValue.setSelected(chartConf.getBoolean("showPieValue"));
this.pieJsPane.setText(chartConf.getString("pieJsPane"));
this.piePosition.setSelectedItem(chartConf.getString("piePosition"));
this.pieDirection.setSelectedItem(chartConf.getInt("pieDirection"));
FRFont textFont = FRFont.getInstance(chartConf.getString("pielabelfamily"),
chartConf.getInt("pielabelstyle"),
chartConf.getInt("pielabelsize"),
MapUtil.toColor(chartConf.getString("pielabelcolor")));
this.pieTextAttrPane.populate(textFont);
if (chartConf.getInt("pieValueType") == 2) {
this.pieCardLayout.show(this.pieCardPane, "piejs");
} else {
this.pieCardLayout.show(this.pieCardPane, "piecheck");
}
}
public JSONObject update() {
JSONObject chartConf = JSONObject.create();
chartConf.put("showPieLabel", this.showPieLabel.isSelected());
chartConf.put("pieValueType", this.pieValueType.getSelectedItem());
chartConf.put("showPieCategory", this.showPieCategory.isSelected());
chartConf.put("showPieSeries", this.showPieSeries.isSelected());
chartConf.put("showPieValue", this.showPieValue.isSelected());
chartConf.put("pieJsPane", this.pieJsPane.getText());
chartConf.put("piePosition", this.piePosition.getSelectedItem());
chartConf.put("pieDirection", this.pieDirection.getSelectedItem());
TextAttr textAttr = this.pieTextAttrPane.update();
chartConf.put("pielabelsize", textAttr.getFRFont().getSize());
chartConf.put("pielabelstyle", textAttr.getFRFont().getStyle());
chartConf.put("pielabelfamily", textAttr.getFRFont().getFamily());
chartConf.put("pielabelcolor", MapUtil.toHex(textAttr.getFRFont().getForeground()));
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() {
pieValueType = 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}
);
pieValueType.setSelectedItem(1);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] comp = new Component[][]{
{null},
new Component[]{this.pieValueType}
};
JPanel pieValueTypePane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{f});
showPieLabel = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieLabel"));
showPieCategory = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieCategory"));
showPieSeries = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieSeries"));
showPieValue = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Plugin-Pielinecomb-showPieValue"));
Component[][] compCheck = new Component[][]{
new Component[]{showPieCategory},
new Component[]{showPieSeries},
new Component[]{showPieValue}
};
final JPanel checkPane = TableLayout4VanChartHelper.createGapTableLayoutPane(compCheck, new double[]{p, p, p, p}, new double[]{f});
pieJsPane = new UITextArea(6, 6);
pieCardPane = new JPanel(this.pieCardLayout = new CardLayout()){
@Override
public Dimension getPreferredSize() {
if (null != pieValueType.getSelectedItem() && pieValueType.getSelectedItem() == 2) {
return pieJsPane.getPreferredSize();
} else {
return checkPane.getPreferredSize();
}
}
};
pieCardPane.add(checkPane, "piecheck");
pieCardPane.add(pieJsPane, "piejs");
this.pieCardLayout.show(pieCardPane, "piecheck");
pieValueType.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent var1x) {
CardLayout card = (CardLayout)pieCardPane.getLayout();
if (pieValueType.getSelectedItem() == 1) {
card.show(pieCardPane, "piecheck");
} else {
card.show(pieCardPane, "piejs");
}
}
});
Component[][] contentComp = new Component[][]{
new Component[]{pieValueTypePane},
new Component[]{pieCardPane}
};
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 layoutPane = createPiePosition();
Component[][] comps = new Component[][]{
new Component[]{showPieLabel},
new Component[]{contentPane},
new Component[]{stylePane},
new Component[]{layoutPane}
};
return TableLayout4VanChartHelper.createGapTableLayoutPane(comps, new double[]{p, p, p, p, p}, new double[]{f});
}
private JPanel createPiePosition() {
this.piePosition = new UIButtonGroup<String>(new String[]{
Toolkit.i18nText("Plugin-Pielinecomb-posoutside"),
Toolkit.i18nText("Plugin-Pielinecomb-posinside"),
Toolkit.i18nText("Plugin-Pielinecomb-poscenter")
},
new String[]{"top", "insideTop", "inside"}
);
this.pieDirection = new UIButtonGroup<Integer>(new String[]{
Toolkit.i18nText("Plugin-Pielinecomb-DirectOrientation"),
Toolkit.i18nText("Plugin-Pielinecomb-DirectVertical")
},
new Integer[]{0, 90}
);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] comp = new Component[][]{
{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-TitlePosition")), this.piePosition},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-textDirection")), this.pieDirection}
};
JPanel pane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p}, new double[]{p, f});
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-layout"), pane);
}
private JPanel createPieTextPane() {
this.pieTextAttrPane = new ChartTextAttrPane();
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-TitleStyle"), this.pieTextAttrPane);
}
}