package com.fr.plugin.heatpointmapbox.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.ispinner.UISpinner; 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.extended.chart.ExtendedScrollPane; import com.fr.general.FRFont; import com.fr.json.JSONObject; import com.fr.plugin.heatpointmapbox.HeatPointMapChart; import com.fr.van.chart.designer.TableLayout4VanChartHelper; import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; /** * @author xx */ public class HeatPointMapStyleLabelsPane extends ExtendedScrollPane { private UICheckBox showPointLabel; private ColorSelectBox labelBgColor; private UIButtonGroup labelType; private UICheckBox showLayerType; private UICheckBox showDataType; private UICheckBox showName; private UICheckBox showLng; private UICheckBox showLat; private UICheckBox showDesc; private UITextArea labelJsPane; private CardLayout cardLayout; private JPanel cardPane; private ChartTextAttrPane textAttrPane; private UISpinner showLabelZoom; @Override protected JPanel createContentPane() { return new ContentPane(); } @Override public void populateBean(HeatPointMapChart chart) { JSONObject labelConf = chart.getLabelConf(); this.showPointLabel.setSelected(labelConf.getBoolean("showPointLabel")); this.showLabelZoom.setValue(labelConf.getDouble("showLabelZoom")); this.labelBgColor.setSelectObject(MapUtil.toColor(labelConf.getString("labelBgColor"))); this.labelType.setSelectedItem(labelConf.getInt("labelType")); this.showLayerType.setSelected(labelConf.getBoolean("showLayerType")); this.showDataType.setSelected(labelConf.getBoolean("showDataType")); this.showName.setSelected(labelConf.getBoolean("showName")); this.showLng.setSelected(labelConf.getBoolean("showLng")); this.showLat.setSelected(labelConf.getBoolean("showLat")); this.showDesc.setSelected(labelConf.getBoolean("showDesc")); labelJsPane.setText(labelConf.getString("labelJsPane")); FRFont labelFont = FRFont.getInstance(labelConf.getString("labelfamily"), labelConf.getInt("labelstyle"), labelConf.getInt("labelsize"), MapUtil.toColor(labelConf.getString("labelcolor"))); this.textAttrPane.populate(labelFont); if (labelConf.getInt("labelType") == 2) { this.cardLayout.show(cardPane, "js"); } } @Override public void updateBean(HeatPointMapChart chart) { JSONObject labelConf = JSONObject.create(); labelConf.put("showPointLabel", this.showPointLabel.isSelected()); labelConf.put("showLabelZoom", this.showLabelZoom.getValue()); labelConf.put("labelBgColor", MapUtil.toHex(this.labelBgColor.getSelectObject())); labelConf.put("labelType", this.labelType.getSelectedItem()); labelConf.put("showLayerType", this.showLayerType.isSelected()); labelConf.put("showDataType", this.showDataType.isSelected()); labelConf.put("showName", this.showName.isSelected()); labelConf.put("showLng", this.showLng.isSelected()); labelConf.put("showLat", this.showLat.isSelected()); labelConf.put("showDesc", this.showDesc.isSelected()); labelConf.put("labelJsPane", this.labelJsPane.getText()); TextAttr labelAttr = this.textAttrPane.update(); labelConf.put("labelsize", labelAttr.getFRFont().getSize()); labelConf.put("labelstyle", labelAttr.getFRFont().getStyle()); labelConf.put("labelfamily", labelAttr.getFRFont().getFamily()); labelConf.put("labelcolor", MapUtil.toHex(labelAttr.getFRFont().getForeground())); chart.setLabelConf(labelConf); } @Override protected String title4PopupWindow() { return Toolkit.i18nText("Plugin-HeatPointMap-labelstitle"); } private class ContentPane extends JPanel { public ContentPane() { initComponents(); } private void initComponents() { this.setLayout(new BorderLayout()); JPanel toolContentPane = createLabelContentPane(); JPanel textStylePane = createLabelTextStylePane(); double p = TableLayout.PREFERRED; double f = TableLayout.FILL; double[] columnSize = {f}; double[] rowSize = {p, p, p, p}; Component[][] acomponents = new Component[][]{ new Component[]{showPointLabel}, new Component[]{toolContentPane}, new Component[]{textStylePane} }; JPanel panel = TableLayoutHelper.createTableLayoutPane(acomponents, rowSize, columnSize); this.add(panel, BorderLayout.CENTER); this.setVisible(true); } } private JPanel createLabelContentPane() { showPointLabel = new UICheckBox(Toolkit.i18nText("Plugin-HeatPointMap-showPointLabel")); labelBgColor = new ColorSelectBox(100); showLabelZoom = new UISpinner(0, 20, 1, 15); labelType = new UIButtonGroup(new String[]{ Toolkit.i18nText("Plugin-HeatPointMap-labelTypeCheck"), Toolkit.i18nText("Plugin-HeatPointMap-labelTypeJS") }, new Integer[]{1, 2} ); labelType.setSelectedItem(1); showLayerType = new UICheckBox(Toolkit.i18nText("Plugin-HeatPointMap-showLayerType")); showDataType = new UICheckBox(Toolkit.i18nText("Plugin-HeatPointMap-showDataType")); showName = new UICheckBox(Toolkit.i18nText("Plugin-HeatPointMap-showName")); showLng = new UICheckBox(Toolkit.i18nText("Plugin-HeatPointMap-showLng")); showLat = new UICheckBox(Toolkit.i18nText("Plugin-HeatPointMap-showLat")); showDesc = new UICheckBox(Toolkit.i18nText("Plugin-HeatPointMap-showDesc")); labelJsPane = new UITextArea(6, 6); double p = TableLayout.PREFERRED; double f = TableLayout.FILL; Component[][] compLabel = new Component[][]{ {null, null}, //new Component[]{new UILabel(Toolkit.i18nText("Plugin-HeatPointMap-showLabelZoom")), this.showLabelZoom}, new Component[]{new UILabel(Toolkit.i18nText("Plugin-HeatPointMap-labelBgColor")), this.labelBgColor}, new Component[]{new UILabel(Toolkit.i18nText("Plugin-HeatPointMap-labelType")), this.labelType} }; JPanel labelTypePane = TableLayout4VanChartHelper.createGapTableLayoutPane(compLabel, new double[]{p, p, p, p, p}, new double[]{p, f}); Component[][] compCheck = new Component[][]{ new Component[]{showDataType, showName}, new Component[]{showLng, showLat}, new Component[]{showDesc, null} }; final JPanel checkPane = TableLayout4VanChartHelper.createGapTableLayoutPane(compCheck, new double[]{p, p, p, p}, new double[]{p, f}); cardPane = new JPanel(this.cardLayout = new CardLayout()){ @Override public Dimension getPreferredSize() { if (null != labelType.getSelectedItem() && labelType.getSelectedItem() == 2) { return labelJsPane.getPreferredSize(); } else { return checkPane.getPreferredSize(); } } }; cardPane.add(checkPane, "check"); cardPane.add(labelJsPane, "js"); this.cardLayout.show(cardPane, "check"); labelType.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent var1x) { if (labelType.getSelectedItem() == 1) { cardLayout.show(cardPane, "check"); } else { cardLayout.show(cardPane, "js"); } } }); Component[][] comp = new Component[][]{ new Component[]{labelTypePane}, new Component[]{cardPane} }; JPanel pane = TableLayout4VanChartHelper.createGapTableLayoutPane(comp, new double[]{p, p, p}, new double[]{f}); return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-HeatPointMap-labelAlignExpand"), pane); } private JPanel createLabelTextStylePane() { this.textAttrPane = new ChartTextAttrPane(); return TableLayout4VanChartHelper.createExpandablePaneWithTitle(Toolkit.i18nText("Plugin-HeatPointMap-LabelsTextStyle"), this.textAttrPane); } }