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.
163 lines
5.5 KiB
163 lines
5.5 KiB
package com.fr.plugin.pielinecomb.ui; |
|
|
|
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.gui.frpane.AbstractAttrNoScrollPane; |
|
import com.fr.design.gui.frpane.AttributeChangeListener; |
|
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.extended.chart.ExtendedScrollPane; |
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONObject; |
|
import com.fr.plugin.pielinecomb.PieLineCombChart; |
|
import com.fr.plugin.pielinecomb.comp.CustomChartAxisButtonPane; |
|
|
|
import javax.swing.*; |
|
import java.awt.*; |
|
import java.util.HashMap; |
|
import java.util.Iterator; |
|
import java.util.LinkedHashMap; |
|
import java.util.Map; |
|
|
|
public class PieLineCombStyleAxisPane extends ExtendedScrollPane<PieLineCombChart> { |
|
|
|
private CustomChartAxisButtonPane axisButtonPane; |
|
|
|
private LinkedHashMap<String, JPanel> axisPaneMap = new LinkedHashMap<>();; |
|
private JPanel axisCardPane; |
|
|
|
private PieLineCombStylePane stylePane; |
|
|
|
public PieLineCombStyleAxisPane(PieLineCombStylePane stylePane) { |
|
this.stylePane = stylePane; |
|
} |
|
|
|
@Override |
|
protected JPanel createContentPane() { |
|
return new ContentPane(); |
|
} |
|
|
|
@Override |
|
public void populateBean(PieLineCombChart chart) { |
|
JSONObject chartConf = chart.getAxisConf(); |
|
|
|
if (null == axisPaneMap) { |
|
axisPaneMap = new LinkedHashMap<>(); |
|
} |
|
|
|
JSONObject axisX = chartConf.getJSONObject("axisX"); |
|
PieLineCombStyleAxisXPane axisXPane = new PieLineCombStyleAxisXPane(stylePane); |
|
axisXPane.populateBean(axisX); |
|
axisPaneMap.put(axisX.getString("axisName"), axisXPane); |
|
axisCardPane.add(axisXPane, axisX.getString("axisName")); |
|
|
|
JSONArray axisYList = chartConf.getJSONArray("axisY"); |
|
for (int i = 0; i < axisYList.size(); i++) { |
|
JSONObject axisY = axisYList.getJSONObject(i); |
|
PieLineCombStyleAxisYPane axisYPane = new PieLineCombStyleAxisYPane(stylePane); |
|
axisYPane.populateBean(axisY); |
|
|
|
axisPaneMap.put(axisY.getString("axisName"), axisYPane); |
|
axisCardPane.add(axisYPane, axisY.getString("axisName")); |
|
} |
|
|
|
axisButtonPane.populateBean(chartConf); |
|
} |
|
|
|
@Override |
|
public void updateBean(PieLineCombChart chart) { |
|
JSONObject chartConf = new JSONObject(); |
|
|
|
if (null != axisPaneMap && !axisPaneMap.isEmpty()) { |
|
Iterator<String> it = axisPaneMap.keySet().iterator(); |
|
JSONArray axisY = JSONArray.create(); |
|
while(it.hasNext()) { |
|
String name = it.next(); |
|
if (name.startsWith("X")) { |
|
PieLineCombStyleAxisXPane xPane = (PieLineCombStyleAxisXPane)axisPaneMap.get(name); |
|
JSONObject axisXTmp = xPane.update(); |
|
axisXTmp.put("axisName", name); |
|
chartConf.put("axisX", axisXTmp); |
|
} else if (name.startsWith("Y")) { |
|
PieLineCombStyleAxisYPane yPane = (PieLineCombStyleAxisYPane)axisPaneMap.get(name); |
|
JSONObject axisYTmp = yPane.update(); |
|
axisYTmp.put("axisName", name); |
|
axisY.put(axisYTmp); |
|
} |
|
} |
|
chartConf.put("axisY", axisY); |
|
} |
|
|
|
chart.setAxisConf(chartConf); |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return Toolkit.i18nText("Plugin-Pielinecomb-StyleAxisTitle"); |
|
} |
|
|
|
private class ContentPane extends JPanel { |
|
public ContentPane() { |
|
initComponents(); |
|
} |
|
|
|
private void initComponents() { |
|
this.setLayout(new BorderLayout()); |
|
|
|
JPanel mainPane = createMainPane(); |
|
JPanel axisPane = createAxisPane(); |
|
|
|
double p = TableLayout.PREFERRED; |
|
double f = TableLayout.FILL; |
|
Component[][] acomponents = new Component[][]{ |
|
new Component[]{mainPane}, |
|
new Component[]{axisPane} |
|
}; |
|
|
|
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() { |
|
axisButtonPane = new CustomChartAxisButtonPane(this); |
|
return axisButtonPane; |
|
} |
|
|
|
private JPanel createAxisPane() { |
|
axisCardPane = new JPanel(new CardLayout()); |
|
// axisPaneMap = new LinkedHashMap<>(); |
|
// axisPaneMap.put("X轴", new PieLineCombStyleAxisXPane()); |
|
// axisPaneMap.put("Y轴", new PieLineCombStyleAxisYPane()); |
|
// Iterator<String> it = axisPaneMap.keySet().iterator(); |
|
// while (it.hasNext()) { |
|
// String name = it.next(); |
|
// axisCardPane.add(axisPaneMap.get(name), name); |
|
// } |
|
((CardLayout)axisCardPane.getLayout()).show(axisCardPane, "X轴"); |
|
return axisCardPane; |
|
} |
|
|
|
public void addAxisPane(String name) { |
|
axisPaneMap.put(name, new PieLineCombStyleAxisYPane(stylePane)); |
|
axisCardPane.add(axisPaneMap.get(name), name); |
|
} |
|
|
|
public void delAxisPane(String name) { |
|
axisPaneMap.remove(name); |
|
stylePane.attributeChanged(); |
|
} |
|
|
|
public void changeAxisSelected(String name) { |
|
((CardLayout)axisCardPane.getLayout()).show(axisCardPane, name); |
|
} |
|
}
|
|
|