From a6feb0d1ded3047189b8e2787eea880d28c593e8 Mon Sep 17 00:00:00 2001 From: shine Date: Wed, 19 Aug 2020 14:56:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCustomFieldComboBoxPane.java | 121 +++++++++--------- .../SeriesValueFieldComboBoxPane.java | 12 +- .../design/chartx/data/DataLayoutHelper.java | 69 ++++++++++ .../data/map/AbstractAreaLngLatPane.java | 15 +-- .../chartx/data/map/MapChartDataPane.java | 8 +- .../fields/AbstractCellDataFieldsPane.java | 15 +-- .../fields/AbstractDataSetFieldsPane.java | 15 +-- .../fields/diff/MapDataSetFieldsPane.java | 7 +- .../fr/design/chartx/single/CellDataPane.java | 2 + .../fr/design/chartx/single/DataSetPane.java | 30 ++--- .../design/chartx/single/SingleDataPane.java | 22 +--- .../ExtendedCustomFieldComboBoxPane.java | 12 +- 12 files changed, 176 insertions(+), 152 deletions(-) create mode 100644 designer-chart/src/main/java/com/fr/design/chartx/data/DataLayoutHelper.java diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/AbstractCustomFieldComboBoxPane.java b/designer-chart/src/main/java/com/fr/design/chartx/component/AbstractCustomFieldComboBoxPane.java index e93900ea6..e4e27b7f4 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/component/AbstractCustomFieldComboBoxPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/AbstractCustomFieldComboBoxPane.java @@ -1,19 +1,18 @@ package com.fr.design.chartx.component; import com.fr.data.util.function.AbstractDataFunction; +import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.FurtherBasicBeanPane; import com.fr.design.chartx.component.correlation.AbstractCorrelationPane; import com.fr.design.chartx.component.correlation.CalculateComboBoxEditorComponent; import com.fr.design.chartx.component.correlation.FieldEditorComponentWrapper; import com.fr.design.chartx.component.correlation.UIComboBoxEditorComponent; import com.fr.design.chartx.component.correlation.UITextFieldEditorComponent; -import com.fr.design.gui.frpane.UIComboBoxPane; +import com.fr.design.chartx.data.DataLayoutHelper; +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.i18n.Toolkit; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.mainframe.chart.gui.ChartDataPane; import com.fr.design.mainframe.chart.gui.data.CalculateComboBox; import com.fr.design.mainframe.chart.gui.data.table.DataPaneHelper; import com.fr.extended.chart.UIComboBoxWithNone; @@ -22,19 +21,25 @@ import com.fr.stable.StringUtils; import javax.swing.JPanel; import javax.swing.SwingConstants; -import java.util.ArrayList; -import java.util.List; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import java.awt.BorderLayout; +import java.awt.CardLayout; import java.awt.Component; -import java.awt.Dimension; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; /** * Created by shine on 2018/9/12. * 系列名使用字段名or字段值的抽象的pane 支持多种属性结构的存取 */ -public abstract class AbstractCustomFieldComboBoxPane extends UIComboBoxPane { +public abstract class AbstractCustomFieldComboBoxPane extends BasicBeanPane { + + private UIButtonGroup nameOrValue; + private JPanel cardPane; + private CardLayout cardLayout; private AbstractUseFieldValuePane useFieldValuePane; @@ -42,73 +47,43 @@ public abstract class AbstractCustomFieldComboBoxPane extends UIComboBoxPane< private List fieldList = new ArrayList(); - @Override - protected void initLayout() { - this.setLayout(new BorderLayout(0, 6)); - JPanel northPane = new JPanel(new BorderLayout()); - northPane.add(jcb, BorderLayout.CENTER); - UILabel label = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Series_Name_From")); - label.setPreferredSize(new Dimension(ChartDataPane.LABEL_WIDTH, 20)); - northPane.add(label, BorderLayout.WEST); - this.add(northPane, BorderLayout.NORTH); - this.add(cardPane, BorderLayout.CENTER); - } + public AbstractCustomFieldComboBoxPane() { - @Override - protected List> initPaneList() { useFieldValuePane = createUseFieldValuePane(); customFieldNamePane = createCustomFieldNamePane(); - List> list = new ArrayList>(); - list.add(useFieldValuePane); - list.add(paneWrapper()); - return list; - } - private FurtherBasicBeanPane paneWrapper() { - FurtherBasicBeanPane pane = new FurtherBasicBeanPane() { + nameOrValue = new UIButtonGroup( + new String[]{useFieldValuePane.title4PopupWindow(), customFieldNamePane.title4PopupWindow()}, + new Boolean[]{false, true}); + nameOrValue.setSelectedItem(false); + nameOrValue.addChangeListener(new ChangeListener() { @Override - public String title4PopupWindow() { - return Toolkit.i18nText("Fine-Design_Chart_Enable_Field_Name"); + public void stateChanged(ChangeEvent e) { + checkCardPane(); } + }); + JPanel northPane = DataLayoutHelper.createDataLayoutPane(Toolkit.i18nText("Fine-Design_Chart_Series_Name_From"), nameOrValue); - @Override - public boolean accept(Object ob) { - return false; - } - - @Override - public void reset() { - } + cardLayout = new CardLayout(); + cardPane = new JPanel(cardLayout); + cardPane.add(useFieldValuePane, useFieldValuePane.title4PopupWindow()); + cardPane.add(customFieldNamePane, customFieldNamePane.title4PopupWindow()); - @Override - public void populateBean(Object ob) { - } - - @Override - public Object updateBean() { - return null; - } - }; - pane.setLayout(new BorderLayout(0, 6)); - pane.add(customFieldNamePane, BorderLayout.CENTER); - return pane; + this.setLayout(new BorderLayout(0, 6)); + this.add(northPane, BorderLayout.NORTH); + this.add(cardPane, BorderLayout.CENTER); } protected abstract AbstractUseFieldValuePane createUseFieldValuePane(); protected abstract AbstractCustomFieldNamePane createCustomFieldNamePane(); - @Override - protected String title4PopupWindow() { - return StringUtils.EMPTY; - } - protected boolean valueComboBoxHasNone() { return false; } public void checkBoxUse(boolean hasUse) { - jcb.setEnabled(hasUse); + nameOrValue.setEnabled(hasUse); useFieldValuePane.checkBoxUse(hasUse); } @@ -122,6 +97,19 @@ public abstract class AbstractCustomFieldComboBoxPane extends UIComboBoxPane< fieldList = columnNameList; } + private void checkCardPane() { + cardLayout.show(cardPane, nameOrValue.getSelectedItem() ? customFieldNamePane.title4PopupWindow() : useFieldValuePane.title4PopupWindow()); + } + + protected void populateNameOrValue(boolean b) { + nameOrValue.setSelectedItem(b); + checkCardPane(); + } + + protected boolean updateNameOrValue() { + return nameOrValue.getSelectedItem(); + } + protected void populateCustomFieldNamePane(T t) { customFieldNamePane.populateBean(t); } @@ -138,6 +126,16 @@ public abstract class AbstractCustomFieldComboBoxPane extends UIComboBoxPane< useFieldValuePane.updateBean(t); } + @Override + public T updateBean() { + return null; + } + + @Override + protected String title4PopupWindow() { + return null; + } + protected abstract class AbstractUseFieldValuePane extends FurtherBasicBeanPane { private UIComboBox series; private UIComboBox value; @@ -169,11 +167,7 @@ public abstract class AbstractCustomFieldComboBoxPane extends UIComboBoxPane< new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Summary_Method"), SwingConstants.LEFT), function}, }; - double p = TableLayout.PREFERRED; - double[] columnSize = {78, 122}; - double[] rowSize = {p, p, p}; - - JPanel panel = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + JPanel panel = DataLayoutHelper.createDataLayoutPane(components); this.setLayout(new BorderLayout(0, 6)); this.add(panel, BorderLayout.CENTER); @@ -258,5 +252,10 @@ public abstract class AbstractCustomFieldComboBoxPane extends UIComboBoxPane< protected Object[] createLine() { return new String[]{StringUtils.EMPTY, StringUtils.EMPTY, Toolkit.i18nText("Fine-Design_Chart_Use_None")}; } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Chart_Enable_Field_Name"); + } } } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/SeriesValueFieldComboBoxPane.java b/designer-chart/src/main/java/com/fr/design/chartx/component/SeriesValueFieldComboBoxPane.java index 4372cf0db..e38b3965d 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/component/SeriesValueFieldComboBoxPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/SeriesValueFieldComboBoxPane.java @@ -27,23 +27,21 @@ public class SeriesValueFieldComboBoxPane extends AbstractCustomFieldComboBoxPan @Override public void populateBean(SeriesValueCorrelationDefinition ob) { + populateNameOrValue(ob.isCustomFieldValue()); if (ob.isCustomFieldValue()) { populateCustomFieldNamePane(ob); - jcb.setSelectedIndex(1); } else { populateUseFieldValuePane(ob); - jcb.setSelectedIndex(0); } } @Override public void updateBean(SeriesValueCorrelationDefinition ob) { - if (jcb.getSelectedIndex() == 0) { - ob.setCustomFieldValue(false); - updateUseFieldValuePane(ob); - } else { - ob.setCustomFieldValue(true); + ob.setCustomFieldValue(updateNameOrValue()); + if (ob.isCustomFieldValue()) { updateCustomFieldNamePane(ob); + } else { + updateUseFieldValuePane(ob); } } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/data/DataLayoutHelper.java b/designer-chart/src/main/java/com/fr/design/chartx/data/DataLayoutHelper.java new file mode 100644 index 000000000..98ae28085 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/data/DataLayoutHelper.java @@ -0,0 +1,69 @@ +package com.fr.design.chartx.data; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; + +import javax.swing.BorderFactory; +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import java.awt.Component; +import java.util.Arrays; + +/** + * @author shine + * @version 10.0 + * Created by shine on 2020/7/22 + */ +public class DataLayoutHelper { + + public static int WIDTH = 150; + public static int LABEL_HEIGHT = 20; + public static int LABEL_WIDTH = 65; + + public static int LEFT_GAP = 15; + public static int RIGHT_GAP = 10; + + public static void setWIDTH(int WIDTH) { + DataLayoutHelper.WIDTH = WIDTH; + } + + public static void setLabelHeight(int labelHeight) { + LABEL_HEIGHT = labelHeight; + } + + public static void setLabelWidth(int labelWidth) { + LABEL_WIDTH = labelWidth; + } + + public static void setLeftGap(int leftGap) { + LEFT_GAP = leftGap; + } + + public static void setRightGap(int rightGap) { + RIGHT_GAP = rightGap; + } + + public static JPanel createDataLayoutPane(Component[][] components) { + int len = components.length; + double p = TableLayout.PREFERRED; + double[] columnSize = {DataLayoutHelper.LABEL_WIDTH, DataLayoutHelper.WIDTH}; + double[] rowSize = new double[len]; + Arrays.fill(rowSize, p); + + return TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + } + + public static JPanel createDataLayoutPane(String label, Component component) { + Component[][] components = new Component[][]{ + new Component[]{new UILabel(label, SwingConstants.LEFT), component} + }; + + return createDataLayoutPane(components); + } + + public static void addNormalBorder(JComponent component) { + component.setBorder(BorderFactory.createEmptyBorder(0, DataLayoutHelper.LEFT_GAP, 0, DataLayoutHelper.RIGHT_GAP)); + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/data/map/AbstractAreaLngLatPane.java b/designer-chart/src/main/java/com/fr/design/chartx/data/map/AbstractAreaLngLatPane.java index 09393918a..53c1cde75 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/data/map/AbstractAreaLngLatPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/data/map/AbstractAreaLngLatPane.java @@ -1,18 +1,15 @@ package com.fr.design.chartx.data.map; +import com.fr.design.chartx.data.DataLayoutHelper; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.ilable.UILabel; 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.ChartDataPane; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.util.Arrays; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Component; @@ -67,8 +64,10 @@ public abstract class AbstractAreaLngLatPane extends JPanel { locationType.setSelectedIndex(0); + JPanel northPane = DataLayoutHelper.createDataLayoutPane(Toolkit.i18nText("FR-Plugin_Design_Geographic_Location"), locationType); + this.setLayout(new BorderLayout(0, 6)); - this.add(locationType, BorderLayout.NORTH); + this.add(northPane, BorderLayout.NORTH); this.add(centerPane, BorderLayout.CENTER); } @@ -103,12 +102,8 @@ public abstract class AbstractAreaLngLatPane extends JPanel { for (int i = 0; i < len; i++) { components[i] = new Component[]{new UILabel(labels[i], SwingConstants.LEFT), fieldComponents[i]}; } - double p = TableLayout.PREFERRED; - double[] columnSize = {ChartDataPane.LABEL_WIDTH, 122}; - double[] rowSize = new double[len]; - Arrays.fill(rowSize, p); - return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 0, 6); + return DataLayoutHelper.createDataLayoutPane(components); } } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/data/map/MapChartDataPane.java b/designer-chart/src/main/java/com/fr/design/chartx/data/map/MapChartDataPane.java index fd4790d57..c6686dece 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/data/map/MapChartDataPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/data/map/MapChartDataPane.java @@ -10,7 +10,6 @@ import com.fr.design.chartx.fields.diff.PointMapCellDataFieldsPane; import com.fr.design.chartx.fields.diff.PointMapDataSetFieldsPane; import com.fr.design.chartx.single.SingleDataPane; import com.fr.design.gui.frpane.AttributeChangeListener; -import com.fr.plugin.chart.map.VanChartMapPlot; import com.fr.plugin.chart.type.MapType; import com.fr.van.chart.map.designer.VanMapAreaPointAndLineGroupPane; @@ -33,11 +32,8 @@ public class MapChartDataPane extends AbstractChartDataPane { this.setLayout(new BorderLayout()); this.add(cellDataFieldsPane, BorderLayout.CENTER); + DataLayoutHelper.addNormalBorder(this); } @Override diff --git a/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java b/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java index cfb9a2c18..3df0d3d6d 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java @@ -3,25 +3,20 @@ package com.fr.design.chartx.single; import com.fr.chartx.data.DataSetDefinition; import com.fr.data.impl.NameTableData; import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.chartx.data.DataLayoutHelper; import com.fr.design.chartx.fields.AbstractDataSetFieldsPane; import com.fr.design.data.tabledata.wrapper.TableDataWrapper; -import com.fr.design.gui.ilable.BoldFontTextLabel; -import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; -import com.fr.design.mainframe.chart.gui.ChartDataPane; import com.fr.design.mainframe.chart.gui.data.DatabaseTableDataPane; -import com.fr.design.utils.gui.UIComponentUtils; -import java.util.List; +import javax.swing.JPanel; import java.awt.BorderLayout; -import java.awt.Dimension; +import java.util.List; /** * Created by shine on 2019/5/21. */ public class DataSetPane extends FurtherBasicBeanPane { - private static final int TABLE_DATA_LABEL_LINE_WRAP_WIDTH = 65; - private static final int TABLE_DATA_PANE_WIDTH = 246; private DatabaseTableDataPane tableDataPane; @@ -32,24 +27,27 @@ public class DataSetPane extends FurtherBasicBeanPane { } private void initComps(AbstractDataSetFieldsPane dataSetFieldsPane) { - UILabel label = new BoldFontTextLabel(Toolkit.i18nText("Fine-Design_Chart_Table_Data")); - UIComponentUtils.setLineWrap(label, TABLE_DATA_LABEL_LINE_WRAP_WIDTH); - UIComponentUtils.setPreferedWidth(label, ChartDataPane.LABEL_WIDTH); - - tableDataPane = new DatabaseTableDataPane(label) { + tableDataPane = new DatabaseTableDataPane(null) { @Override protected void userEvent() { refreshBoxListAndTableName(); checkBoxUse(); } + + @Override + protected void setBorder() { + } + }; - tableDataPane.setPreferredSize(new Dimension(TABLE_DATA_PANE_WIDTH, tableDataPane.getPreferredSize().height)); + this.dataSetFieldsPane = dataSetFieldsPane; - this.setLayout(new BorderLayout()); - this.add(tableDataPane, BorderLayout.NORTH); + JPanel northPane = DataLayoutHelper.createDataLayoutPane(Toolkit.i18nText("Fine-Design_Chart_Table_Data"), tableDataPane); + this.setLayout(new BorderLayout(0, 6)); + this.add(northPane, BorderLayout.NORTH); this.add(dataSetFieldsPane, BorderLayout.CENTER); + DataLayoutHelper.addNormalBorder(this); checkBoxUse(); } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/single/SingleDataPane.java b/designer-chart/src/main/java/com/fr/design/chartx/single/SingleDataPane.java index dc4dfc65a..06ed06649 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/single/SingleDataPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/single/SingleDataPane.java @@ -3,28 +3,22 @@ package com.fr.design.chartx.single; import com.fr.chartx.data.AbstractDataDefinition; import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.FurtherBasicBeanPane; +import com.fr.design.chartx.data.DataLayoutHelper; import com.fr.design.chartx.fields.AbstractCellDataFieldsPane; import com.fr.design.chartx.fields.AbstractDataSetFieldsPane; -import com.fr.design.constants.LayoutConstants; import com.fr.design.gui.frpane.UIComboBoxPane; -import com.fr.design.gui.ilable.BoldFontTextLabel; -import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; -import com.fr.design.utils.gui.UIComponentUtils; -import javax.swing.BorderFactory; import javax.swing.JPanel; +import java.awt.BorderLayout; import java.util.ArrayList; import java.util.List; -import java.awt.BorderLayout; /** * Created by shine on 2019/5/21. */ public class SingleDataPane extends BasicBeanPane { - private static final int TABLE_DATA_LABEL_LINE_WIDTH = 81; - private UIComboBoxPane comboBoxPane; private DataSetPane dataSetPane; @@ -50,18 +44,12 @@ public class SingleDataPane extends BasicBeanPane { } protected void initLayout() { - this.setLayout(new BorderLayout(LayoutConstants.HGAP_LARGE, 6)); - JPanel northPane = new JPanel(new BorderLayout(LayoutConstants.HGAP_LARGE, 0)); + this.setLayout(new BorderLayout(0, 6)); + JPanel northPane = DataLayoutHelper.createDataLayoutPane(Toolkit.i18nText("Fine-Design_Chart_Data_Source"), jcb); + DataLayoutHelper.addNormalBorder(northPane); - UILabel label = new BoldFontTextLabel(Toolkit.i18nText("Fine-Design_Chart_Data_Source")); - UIComponentUtils.setPreferedWidth(label, TABLE_DATA_LABEL_LINE_WIDTH); - northPane.add(label,BorderLayout.WEST); - northPane.add(jcb, BorderLayout.CENTER); - - northPane.setBorder(BorderFactory.createEmptyBorder(5,24,0,15)); this.add(northPane, BorderLayout.NORTH); this.add(cardPane, BorderLayout.CENTER); - } @Override diff --git a/designer-chart/src/main/java/com/fr/extended/chart/ExtendedCustomFieldComboBoxPane.java b/designer-chart/src/main/java/com/fr/extended/chart/ExtendedCustomFieldComboBoxPane.java index 108d4b605..119d73bda 100644 --- a/designer-chart/src/main/java/com/fr/extended/chart/ExtendedCustomFieldComboBoxPane.java +++ b/designer-chart/src/main/java/com/fr/extended/chart/ExtendedCustomFieldComboBoxPane.java @@ -27,21 +27,19 @@ public class ExtendedCustomFieldComboBoxPane extends AbstractCustomFieldComboBox public void populateBean(AbstractDataConfig ob) { if (ob.isCustomName()) { populateCustomFieldNamePane(ob); - jcb.setSelectedIndex(1); } else { populateUseFieldValuePane(ob); - jcb.setSelectedIndex(0); } + populateNameOrValue(ob.isCustomName()); } @Override public void updateBean(AbstractDataConfig ob) { - if (jcb.getSelectedIndex() == 0) { - ob.setCustomName(false); - updateUseFieldValuePane(ob); - } else { - ob.setCustomName(true); + ob.setCustomName(updateNameOrValue()); + if (ob.isCustomName()) { updateCustomFieldNamePane(ob); + } else { + updateUseFieldValuePane(ob); } }