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.
 
 

296 lines
12 KiB

package com.fr.plugin.pielinecomb.ui;
import com.fr.base.BaseUtils;
import com.fr.chart.base.TextAttr;
import com.fr.design.event.GlobalNameListener;
import com.fr.design.event.GlobalNameObserver;
import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener;
import com.fr.design.formula.TinyFormulaPane;
import com.fr.design.gui.frpane.AbstractAttrNoScrollPane;
import com.fr.design.gui.frpane.AttributeChangeListener;
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.extended.chart.ExtendedScrollPane;
import com.fr.general.FRFont;
import com.fr.json.JSONObject;
import com.fr.plugin.pielinecomb.comp.CustomFormatPane;
import com.fr.plugin.pielinecomb.comp.TextFormat;
import com.fr.van.chart.designer.TableLayout4VanChartHelper;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
public class PieLineCombStyleAxisXPane extends ExtendedScrollPane<JSONObject> {
private UICheckBox isTitleVisiable;
private TinyFormulaPane titleName;
private UIButtonGroup<Integer> titleAlignment;
private ChartTextAttrPane titleTextAttrPane;
private UINumberDragPane titleRotation;
private UICheckBox isLabelVisiable;
private ChartTextAttrPane labelTextAttrPane;
private UINumberDragPane labelRotation;
private UIButtonGroup<Integer> labelFormatType;
private CustomFormatPane formatPane;
private UITextArea labelJsPane;
private PieLineCombStylePane stylePane;
public PieLineCombStyleAxisXPane(PieLineCombStylePane stylePane) {
this.stylePane = stylePane;
}
@Override
protected JPanel createContentPane() {
return new ContentPane();
}
@Override
public void populateBean(JSONObject chartConf) {
this.isTitleVisiable.setSelected(chartConf.getBoolean("isTitleVisiable"));
this.titleName.populateBean(chartConf.getString("titleName"));
this.titleAlignment.setSelectedItem(chartConf.getInt("titleAlignment"));
FRFont textFont = FRFont.getInstance(chartConf.getString("titlefamily"),
chartConf.getInt("titlestyle"),
chartConf.getInt("titlesize"),
MapUtil.toColor(chartConf.getString("titlecolor")));
this.titleTextAttrPane.populate(textFont);
this.titleRotation.populateBean(chartConf.getDouble("titleRotation"));
this.isLabelVisiable.setSelected(chartConf.getBoolean("isLabelVisiable"));
textFont = FRFont.getInstance(chartConf.getString("labelfamily"),
chartConf.getInt("labelstyle"),
chartConf.getInt("labelsize"),
MapUtil.toColor(chartConf.getString("labelcolor")));
this.labelTextAttrPane.populate(textFont);
this.labelRotation.populateBean(chartConf.getDouble("labelRotation"));
this.labelFormatType.setSelectedItem(chartConf.getInt("labelFormatType"));
TextFormat format = new TextFormat();
format.setType(chartConf.getInt("xformattype"));
format.setFormatStr(chartConf.getString("xformatstr"));
this.formatPane.populateBean(format);
this.labelJsPane.setText(chartConf.getString("labelJsPane"));
}
@Override
public void updateBean(JSONObject jsonObject) {
}
public JSONObject update() {
JSONObject chartConf = new JSONObject();
chartConf.put("isTitleVisiable", isTitleVisiable.isSelected());
chartConf.put("titleName", titleName.updateBean());
chartConf.put("titleAlignment", titleAlignment.getSelectedItem());
TextAttr textAttr = this.titleTextAttrPane.update();
chartConf.put("titlesize", textAttr.getFRFont().getSize());
chartConf.put("titlestyle", textAttr.getFRFont().getStyle());
chartConf.put("titlefamily", textAttr.getFRFont().getFamily());
chartConf.put("titlecolor", MapUtil.toHex(textAttr.getFRFont().getForeground()));
chartConf.put("titleRotation", titleRotation.updateBean());
chartConf.put("isLabelVisiable", isLabelVisiable.isSelected());
textAttr = this.labelTextAttrPane.update();
chartConf.put("labelsize", textAttr.getFRFont().getSize());
chartConf.put("labelstyle", textAttr.getFRFont().getStyle());
chartConf.put("labelfamily", textAttr.getFRFont().getFamily());
chartConf.put("labelcolor", MapUtil.toHex(textAttr.getFRFont().getForeground()));
chartConf.put("labelRotation", labelRotation.updateBean());
chartConf.put("labelFormatType", labelFormatType.getSelectedItem());
TextFormat format = formatPane.updateBean();
chartConf.put("xformatstr", format.getFormatStr());
chartConf.put("xformattype", format.getType());
chartConf.put("labelJsPane", labelJsPane.getText());
return chartConf;
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Plugin-Pielinecomb-StyleAxisXTitle");
}
private class ContentPane extends JPanel {
public ContentPane() {
initComponents();
initListener(this);
}
private void initComponents() {
this.setLayout(new BorderLayout());
JPanel titlePane = createTitlePane();
JPanel labelPane = createLabelPane();
JPanel formatPane = createLabelFormatPane();
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] acomponents = new Component[][]{
new Component[]{titlePane},
new Component[]{labelPane},
new Component[]{formatPane}
};
JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents, new double[]{p, p, p, p}, new double[]{f});
this.add(panel,BorderLayout.CENTER);
this.setVisible(true);
}
public void initListener(Container var1) {
for(int var2 = 0; var2 < var1.getComponentCount(); ++var2) {
Component var3 = var1.getComponent(var2);
if (var3 instanceof Container) {
this.initListener((Container)var3);
}
if (var3 instanceof UIObserver) {
((UIObserver)var3).registerChangeListener(new UIObserverListener() {
@Override
public void doChange() {
PieLineCombStyleAxisXPane.this.stylePane.attributeChanged();
}
});
}
}
}
}
private JPanel createTitlePane() {
isTitleVisiable = new UICheckBox(Toolkit.i18nText("Plugin-Pielinecomb-isVisiableTitle"));
titleName = new TinyFormulaPane();
Icon[] titlePositonIcons = new Icon[]{BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")};
Integer[] titlePositionVal = new Integer[]{2, 0, 4};
this.titleAlignment = new UIButtonGroup(titlePositonIcons, titlePositionVal);
titleRotation = new UINumberDragPane(-90, 90);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] comps = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-TitleText")), this.titleName},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-TitlePosition")), this.titleAlignment},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-textRotation")), this.titleRotation}
};
JPanel panel = TableLayout4VanChartHelper.createGapTableLayoutPane(comps, new double[]{p, p, p, p, p}, new double[]{p, f});
titleTextAttrPane = new ChartTextAttrPane();
Component[][] sumComp = new Component[][]{
new Component[]{isTitleVisiable},
new Component[]{panel},
new Component[]{titleTextAttrPane}
};
JPanel sumPane = TableLayout4VanChartHelper.createGapTableLayoutPane(sumComp, new double[]{p, p, p}, new double[]{f});
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-TitleNameExpand"), sumPane);
}
private JPanel createLabelPane() {
isLabelVisiable = new UICheckBox(Toolkit.i18nText("Plugin-Pielinecomb-isLabelVisiable"));
labelTextAttrPane = new ChartTextAttrPane();
labelRotation = new UINumberDragPane(-90, 90);
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] comps = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-textRotation")), this.labelRotation}
};
JPanel rotatePane = TableLayout4VanChartHelper.createGapTableLayoutPane(comps, new double[]{p, p, p}, new double[]{p, f});
Component[][] sumComp = new Component[][]{
new Component[]{isLabelVisiable},
new Component[]{labelTextAttrPane},
new Component[]{rotatePane}
};
JPanel sumPane = TableLayout4VanChartHelper.createGapTableLayoutPane(sumComp, new double[]{p, p, p}, new double[]{f});
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-axisLabelTitle"), sumPane);
}
private JPanel createLabelFormatPane() {
labelFormatType = new UIButtonGroup<Integer>(new String[]{
Toolkit.i18nText("Plugin-Pielinecomb-general"),
Toolkit.i18nText("Plugin-Pielinecomb-custom")
}, new Integer[]{1, 2});
labelFormatType.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
checkFormatType();
}
});
double p = TableLayout.PREFERRED;
double f = TableLayout.FILL;
Component[][] comps = new Component[][]{
new Component[]{null, null},
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-labelFormatType")), this.labelFormatType}
};
JPanel typePane = TableLayout4VanChartHelper.createGapTableLayoutPane(comps, new double[]{p, p, p}, new double[]{p, f});
formatPane = new CustomFormatPane() {
@Override
protected Component[][] getComponent(JPanel var1, JPanel var2, JPanel var3) {
var3.setBorder(BorderFactory.createEmptyBorder());
return new Component[][]{{var3, null}, {var2, null}};
}
};
labelJsPane = new UITextArea(6, 6);
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.add(formatPane, BorderLayout.NORTH);
contentPane.add(labelJsPane, BorderLayout.CENTER);
labelJsPane.setVisible(false);
Component[][] comp = new Component[][]{
new Component[]{typePane},
new Component[]{contentPane}
};
JPanel compPane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p}, new double[]{f});
return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-format"), compPane);
}
private void checkFormatType() {
if (labelFormatType.getSelectedItem() == 1) {
formatPane.setVisible(true);
labelJsPane.setVisible(false);
} else {
formatPane.setVisible(false);
labelJsPane.setVisible(true);
}
}
}