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.
372 lines
16 KiB
372 lines
16 KiB
package com.fr.plugin.pielinecomb.ui; |
|
|
|
import com.fr.config.predefined.ColorFillStyle; |
|
import com.fr.design.gui.frpane.UINumberDragPaneWithPercent; |
|
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.ispinner.UISpinner; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.layout.TableLayout; |
|
import com.fr.design.layout.TableLayoutHelper; |
|
import com.fr.design.mainframe.backgroundpane.ColorBackgroundQuickPane; |
|
import com.fr.extended.chart.ExtendedScrollPane; |
|
import com.fr.json.JSONObject; |
|
import com.fr.plugin.chart.type.LineType; |
|
import com.fr.plugin.pielinecomb.PieLineCombChart; |
|
import com.fr.plugin.pielinecomb.comp.CustomChartFillStylePane; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.van.chart.designer.TableLayout4VanChartHelper; |
|
import com.fr.van.chart.designer.component.LineTypeComboBox; |
|
|
|
import javax.swing.*; |
|
import javax.swing.event.ChangeEvent; |
|
import javax.swing.event.ChangeListener; |
|
import java.awt.*; |
|
import java.awt.event.ActionEvent; |
|
import java.awt.event.ActionListener; |
|
|
|
public class PieLineCombStyleSeriesPane extends ExtendedScrollPane<PieLineCombChart> { |
|
|
|
private CustomChartFillStylePane fillStylePane; |
|
private UIButtonGroup<Integer> chartType; |
|
|
|
private CardLayout cardLayout; |
|
private JPanel cardPane; |
|
|
|
/** |
|
* 柱形图 |
|
* */ |
|
private UIButtonGroup<Integer> pieWidthType; |
|
private UISpinner pieFixWidth; |
|
private UINumberDragPaneWithPercent pieSeriesGapWidth; |
|
|
|
private SeriesAxisRelaCondListPane pieSeriesAxisRelaListPane; |
|
|
|
/** |
|
* 折线图 |
|
* */ |
|
private LineTypeComboBox lineType; |
|
private UISpinner lineWidth; |
|
private UIButtonGroup<Integer> lineCornerType; |
|
|
|
private UIComboBox lineCornerShape; |
|
private UIComboBox lineCornerColorType; |
|
private ColorBackgroundQuickPane lineCornerColor; |
|
private UISpinner lineCornerRadius; |
|
private SeriesAxisRelaCondListPane lineSeriesAxisRelaListPane; |
|
|
|
|
|
|
|
|
|
@Override |
|
protected JPanel createContentPane() { |
|
return new ContentPane(); |
|
} |
|
|
|
@Override |
|
public void populateBean(PieLineCombChart chart) { |
|
JSONObject chartConf = chart.getSeriesConf(); |
|
|
|
String colors = chartConf.getString("seriesColorList"); |
|
if (StringUtils.isNotEmpty(colors)) { |
|
java.util.List<Color> colorList = new java.util.ArrayList<Color>(); |
|
String[] colorArr = colors.split("\\|"); |
|
for (int i = 0; i < colorArr.length; i++) { |
|
colorList.add(MapUtil.toColor(colorArr[i])); |
|
} |
|
ColorFillStyle fillStyle = new ColorFillStyle(); |
|
fillStyle.setColorStyle(1); |
|
fillStyle.setColorList(colorList); |
|
fillStyle.setCustomFillStyle(chartConf.getBoolean("seriesColorCustom")); |
|
fillStyle.setFillStyleName(chartConf.getString("seriesColorName")); |
|
this.fillStylePane.populateBean(fillStyle); |
|
} |
|
|
|
this.chartType.setSelectedItem(chartConf.getInt("chartType")); |
|
if (chartConf.getInt("chartType") == 2) { |
|
this.cardLayout.show(cardPane, "line"); |
|
} |
|
|
|
pieWidthType.setSelectedItem(chartConf.getInt("pieWidthType")); |
|
pieFixWidth.setValue(chartConf.getDouble("pieFixWidth")); |
|
pieSeriesGapWidth.populateBean(chartConf.getDouble("pieSeriesGapWidth")); |
|
|
|
lineType.setSelectedItem(LineType.parse(chartConf.getString("lineType"))); |
|
lineWidth.setValue(chartConf.getDouble("lineWidth")); |
|
lineCornerType.setSelectedItem(chartConf.getInt("lineCornerType")); |
|
lineCornerShape.setSelectedItem(chartConf.getString("lineCornerShape")); |
|
lineCornerColorType.setSelectedItem(chartConf.getString("lineCornerColorType")); |
|
lineCornerColor.populateColor(MapUtil.toColor(chartConf.getString("lineCornerColor"))); |
|
lineCornerRadius.setValue(chartConf.getDouble("lineCornerRadius")); |
|
|
|
pieSeriesAxisRelaListPane.populateStyle(chart); |
|
lineSeriesAxisRelaListPane.populateStyle(chart); |
|
} |
|
|
|
@Override |
|
public void updateBean(PieLineCombChart chart) { |
|
JSONObject chartConf = new JSONObject(); |
|
|
|
ColorFillStyle fillStyle = this.fillStylePane.updateBean(); |
|
java.util.List<Color> colorList = fillStyle.getColorList(); |
|
StringBuffer colorStr = new StringBuffer(); |
|
for (int i = 0; i < colorList.size(); i++) { |
|
if (i > 0) { |
|
colorStr.append("|"); |
|
} |
|
String tmpColor = MapUtil.toHex(colorList.get(i)); |
|
colorStr.append(tmpColor); |
|
} |
|
chartConf.put("seriesColorList", colorStr.toString()); |
|
chartConf.put("seriesColorName", fillStyle.getFillStyleName()); |
|
chartConf.put("seriesColorCustom", fillStyle.isCustomFillStyle()); |
|
chartConf.put("chartType", chartType.getSelectedItem()); |
|
|
|
chartConf.put("pieWidthType", pieWidthType.getSelectedItem()); |
|
chartConf.put("pieFixWidth", pieFixWidth.getValue()); |
|
chartConf.put("pieSeriesGapWidth", pieSeriesGapWidth.updateBean()); |
|
|
|
chartConf.put("lineType", ((LineType)lineType.getSelectedItem()).getStringType()); |
|
chartConf.put("lineWidth", lineWidth.getValue()); |
|
chartConf.put("lineCornerType", lineCornerType.getSelectedItem()); |
|
chartConf.put("lineCornerShape", lineCornerShape.getSelectedItem()); |
|
chartConf.put("lineCornerColorType", lineCornerColorType.getSelectedItem()); |
|
chartConf.put("lineCornerColor", MapUtil.toHex(lineCornerColor.updateColor())); |
|
chartConf.put("lineCornerRadius", lineCornerRadius.getValue()); |
|
|
|
chart.setSeriesConf(chartConf); |
|
|
|
pieSeriesAxisRelaListPane.updateStyle(chart); |
|
lineSeriesAxisRelaListPane.updateStyle(chart); |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return Toolkit.i18nText("Plugin-Pielinecomb-StyleSeriesTitle"); |
|
} |
|
|
|
private class ContentPane extends JPanel { |
|
public ContentPane() { |
|
initComponents(); |
|
} |
|
|
|
private void initComponents() { |
|
this.setLayout(new BorderLayout()); |
|
|
|
JPanel chartTypePane = createChartTypePane(); |
|
JPanel mainPane = createMainPane(); |
|
|
|
double p = TableLayout.PREFERRED; |
|
double f = TableLayout.FILL; |
|
Component[][] acomponents = new Component[][]{ |
|
new Component[]{fillStylePane}, |
|
new Component[]{chartTypePane}, |
|
new Component[]{mainPane} |
|
}; |
|
|
|
JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents, new double[]{p, p, p, p}, new double[]{f}); |
|
|
|
this.add(panel,BorderLayout.CENTER); |
|
|
|
this.setVisible(true); |
|
|
|
} |
|
|
|
} |
|
|
|
private JPanel createMainPane() { |
|
fillStylePane = new CustomChartFillStylePane(); |
|
|
|
JPanel piePane = createPiePane(); |
|
JPanel linePane = createLinePane(); |
|
|
|
double p = TableLayout.PREFERRED; |
|
double f = TableLayout.FILL; |
|
cardPane = new JPanel(this.cardLayout = new CardLayout()){ |
|
@Override |
|
public Dimension getPreferredSize() { |
|
if (null != chartType.getSelectedItem() && chartType.getSelectedItem() == 2) { |
|
return linePane.getPreferredSize(); |
|
} else { |
|
return piePane.getPreferredSize(); |
|
} |
|
} |
|
}; |
|
cardPane.add(piePane, "pie"); |
|
cardPane.add(linePane, "line"); |
|
this.cardLayout.show(cardPane, "pie"); |
|
|
|
Component[][] comp = new Component[][]{ |
|
new Component[]{cardPane} |
|
}; |
|
return TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{f}); |
|
} |
|
|
|
private JPanel createLinePane() { |
|
double p = TableLayout.PREFERRED; |
|
double f = TableLayout.FILL; |
|
|
|
lineType = new LineTypeComboBox(new LineType[]{LineType.NONE, LineType.SOLID, LineType.DASHED}); |
|
lineWidth = new UISpinner(0, 100, 1, 1); |
|
lineCornerType = new UIButtonGroup<Integer>(new String[]{ |
|
Toolkit.i18nText("Plugin-Pielinecomb-brokenLine"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-smoothLine") |
|
}, |
|
new Integer[]{0, 1} |
|
); |
|
Component[][] comp = new Component[][]{ |
|
{null, null}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-lineType")), this.lineType}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-lineWidth")), this.lineWidth}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-lineCornerType")), this.lineCornerType} |
|
}; |
|
JPanel linePane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p, p}, new double[]{p, f}); |
|
JPanel linePaneTitle = TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-LineStyle"), linePane); |
|
|
|
lineCornerShape = new UIComboBox(new String[]{ |
|
Toolkit.i18nText("Plugin-Pielinecomb-Default"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-shapeCircle"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-shapeRect"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-shapeTriangle"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-shapeDiamond") |
|
}); |
|
lineCornerColorType = new UIComboBox(new String[]{ |
|
Toolkit.i18nText("Plugin-Pielinecomb-seriesColor"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-customColor") |
|
}); |
|
lineCornerColorType.addActionListener(new ActionListener() { |
|
@Override |
|
public void actionPerformed(ActionEvent e) { |
|
if (lineCornerColorType.getSelectedIndex() == 0) { |
|
lineCornerColor.setVisible(false); |
|
} else { |
|
lineCornerColor.setVisible(true); |
|
} |
|
} |
|
}); |
|
lineCornerColor = new ColorBackgroundQuickPane(); |
|
JPanel cornerColorPane = new JPanel(new BorderLayout()); |
|
cornerColorPane.add(lineCornerColor); |
|
lineCornerColor.setVisible(false); |
|
lineCornerRadius = new UISpinner(0, 100, 1, 6); |
|
|
|
comp = new Component[][]{ |
|
{null, null}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-lineCornerShape")), this.lineCornerShape}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-lineCornerColorType")), this.lineCornerColorType}, |
|
new Component[]{null, cornerColorPane}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-lineCornerRadius")), this.lineCornerRadius} |
|
}; |
|
JPanel cornerPane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p, p, p}, new double[]{p, f}); |
|
JPanel cornerPaneTitle = TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-CornerStyle"), cornerPane); |
|
|
|
lineSeriesAxisRelaListPane = new SeriesAxisRelaCondListPane("lineSeriesAxis"); |
|
JPanel lineSeriesAxisPaneTitle = TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-seriesAxisRela"), lineSeriesAxisRelaListPane); |
|
|
|
comp = new Component[][]{ |
|
new Component[]{linePaneTitle}, |
|
new Component[]{cornerPaneTitle}, |
|
new Component[]{lineSeriesAxisPaneTitle} |
|
}; |
|
return TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p, p}, new double[]{f}); |
|
} |
|
|
|
private JPanel createPiePane() { |
|
double p = TableLayout.PREFERRED; |
|
double f = TableLayout.FILL; |
|
|
|
pieWidthType = new UIButtonGroup<Integer>(new String[]{ |
|
Toolkit.i18nText("Plugin-Pielinecomb-auto"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-custom") |
|
}, |
|
new Integer[]{1, 2} |
|
); |
|
|
|
pieFixWidth = new UISpinner(0, 1000, 1, 15); |
|
pieSeriesGapWidth = new UINumberDragPaneWithPercent(0, 100); |
|
|
|
Component[][] comp = new Component[][]{ |
|
{null, null}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-seriesGapWidth")), this.pieSeriesGapWidth} |
|
}; |
|
final JPanel gapWidthPane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{p, f}); |
|
|
|
comp = new Component[][]{ |
|
{null, null}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-barWidth")), this.pieFixWidth} |
|
}; |
|
final JPanel fixWidthPane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{p, f}); |
|
|
|
JPanel widthPane = new JPanel(new BorderLayout()); |
|
widthPane.add(gapWidthPane, BorderLayout.NORTH); |
|
widthPane.add(fixWidthPane, BorderLayout.CENTER); |
|
fixWidthPane.setVisible(false); |
|
|
|
pieWidthType.addChangeListener(new ChangeListener() { |
|
@Override |
|
public void stateChanged(ChangeEvent var1x) { |
|
if (pieWidthType.getSelectedItem() == 1) { |
|
gapWidthPane.setVisible(true); |
|
fixWidthPane.setVisible(false); |
|
} else { |
|
gapWidthPane.setVisible(false); |
|
fixWidthPane.setVisible(true); |
|
} |
|
} |
|
}); |
|
|
|
comp = new Component[][]{ |
|
{null, null}, |
|
new Component[]{new UILabel(Toolkit.i18nText("Plugin-Pielinecomb-barWidthLabel")), this.pieWidthType} |
|
}; |
|
JPanel widthTypePane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{p, f}); |
|
|
|
pieSeriesAxisRelaListPane = new SeriesAxisRelaCondListPane("pieSeriesAxis"); |
|
JPanel pieSeriesAxisPaneTitle = TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-seriesAxisRela"), pieSeriesAxisRelaListPane); |
|
|
|
comp = new Component[][]{ |
|
{widthTypePane}, |
|
{widthPane} |
|
}; |
|
JPanel pane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p, p}, new double[]{f}); |
|
JPanel paneTitle = TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-Pielinecomb-TitleStyle"), pane); |
|
|
|
comp = new Component[][]{ |
|
{paneTitle}, |
|
{pieSeriesAxisPaneTitle} |
|
}; |
|
return TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p}, new double[]{f}); |
|
} |
|
|
|
private JPanel createChartTypePane() { |
|
|
|
chartType = new UIButtonGroup<Integer>(new String[]{ |
|
Toolkit.i18nText("Plugin-Pielinecomb-Typepie"), |
|
Toolkit.i18nText("Plugin-Pielinecomb-Typeline") |
|
}, |
|
new Integer[]{1, 2} |
|
); |
|
chartType.setSelectedItem(1); |
|
|
|
chartType.addChangeListener(new ChangeListener() { |
|
@Override |
|
public void stateChanged(ChangeEvent var1x) { |
|
if (chartType.getSelectedItem() == 1) { |
|
cardLayout.show(cardPane, "pie"); |
|
} else { |
|
cardLayout.show(cardPane, "line"); |
|
} |
|
} |
|
}); |
|
|
|
double p = TableLayout.PREFERRED; |
|
double f = TableLayout.FILL; |
|
Component[][] comp = new Component[][]{ |
|
{null}, |
|
new Component[]{this.chartType} |
|
}; |
|
return TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p}, new double[]{f}); |
|
} |
|
|
|
}
|
|
|