diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/style/label/VanChartGaugeLabelDetailPane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/style/label/VanChartGaugeLabelDetailPane.java index 86d140f1d..8c672bab6 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/style/label/VanChartGaugeLabelDetailPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/style/label/VanChartGaugeLabelDetailPane.java @@ -10,7 +10,6 @@ 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.mainframe.chart.gui.style.ChartTextAttrPaneWithAuto; -import com.fr.general.ComparatorUtils; import com.fr.plugin.chart.base.AttrLabelDetail; import com.fr.plugin.chart.gauge.VanChartGaugePlot; import com.fr.plugin.chart.type.FontAutoType; @@ -50,7 +49,7 @@ public class VanChartGaugeLabelDetailPane extends VanChartPlotLabelDetailPane { } public GaugeStyle getGaugeStyle() { - return ((VanChartGaugePlot)this.getPlot()).getGaugeStyle(); + return ((VanChartGaugePlot) this.getPlot()).getGaugeStyle(); } public void setGaugeStyle(GaugeStyle gaugeStyle) { @@ -127,15 +126,13 @@ public class VanChartGaugeLabelDetailPane extends VanChartPlotLabelDetailPane { protected Component[][] getLabelPaneComponents(Plot plot, double p, double[] columnSize) { if (hasLabelAlignPane()) { - return new Component[][]{ new Component[]{getDataLabelContentPane(), null}, - new Component[]{createLabelPositionPane(Toolkit.i18nText("Fine-Design_Chart_Layout_Vertical"), plot), null}, - new Component[]{createLabelAlignPane(Toolkit.i18nText("Fine-Design_Chart_Layout_Horizontal")), null}, + new Component[]{createLabelPositionPane(getVerticalTitle(), plot), null}, + new Component[]{createLabelAlignPane(), null}, new Component[]{createLabelStylePane(getLabelStyleRowSize(p), columnSize, plot), null}, }; } else { - return new Component[][]{ new Component[]{getDataLabelContentPane(), null}, new Component[]{createLabelStylePane(getLabelStyleRowSize(p), columnSize, plot), null}, @@ -143,50 +140,37 @@ public class VanChartGaugeLabelDetailPane extends VanChartPlotLabelDetailPane { } } - private JPanel createLabelAlignPane(String title) { - JPanel panel = new JPanel(new BorderLayout()); - - alignPane = new JPanel(); - checkAlignPane(title); - panel.add(alignPane, BorderLayout.CENTER); - - return panel; + private JPanel createLabelAlignPane() { + alignPane = new JPanel(new BorderLayout()); + checkAlignPane(); + return alignPane; } - protected void checkAlignPane(String title) { - if (alignPane == null && !hasLabelAlign(getPlot())) { + protected void checkAlignPane() { + if (!hasLabelAlignPane()) { return; } - if (alignPane != null && !hasLabelAlign(getPlot())) { - oldAlignValues = null; + if (!hasLabelAlign()) { alignPane.removeAll(); return; } - if (alignPane == null && hasLabelAlign(getPlot())) { - alignPane = new JPanel(); + + if (alignPane.getComponents().length > 0) { + return; } TwoTuple result = getAlignNamesAndValues(); - String[] names = result.getFirst(); Integer[] values = result.getSecond(); - if (ComparatorUtils.equals(values, oldAlignValues)) { - return; - } - - oldAlignValues = values; - - align = new UIButtonGroup(names, values); + align = new UIButtonGroup<>(names, values); Component[][] comps = new Component[2][2]; comps[0] = new Component[]{null, null}; - comps[1] = new Component[]{new UILabel(title, SwingConstants.LEFT), align}; + comps[1] = new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Layout_Horizontal"), SwingConstants.LEFT), align}; double[] row = new double[]{TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED}; double[] col = new double[]{TableLayout.FILL, TableLayout4VanChartHelper.EDIT_AREA_WIDTH}; - alignPane.removeAll(); - alignPane.setLayout(new BorderLayout()); alignPane.add(getLabelPositionPane(comps, row, col), BorderLayout.CENTER); if (getParentPane() != null) { @@ -214,12 +198,16 @@ public class VanChartGaugeLabelDetailPane extends VanChartPlotLabelDetailPane { } protected void checkPane() { - String verticalTitle = hasLabelAlign(getPlot()) - ? Toolkit.i18nText("Fine-Design_Chart_Layout_Vertical") - : Toolkit.i18nText("Fine-Design_Chart_Layout_Position"); + String verticalTitle = getVerticalTitle(); checkPositionPane(verticalTitle); - checkAlignPane(Toolkit.i18nText("Fine-Design_Chart_Layout_Horizontal")); + checkAlignPane(); + } + + private String getVerticalTitle() { + return hasLabelAlign() + ? Toolkit.i18nText("Fine-Design_Chart_Layout_Vertical") + : Toolkit.i18nText("Fine-Design_Chart_Layout_Position"); } protected void checkStyleUse() { @@ -227,8 +215,8 @@ public class VanChartGaugeLabelDetailPane extends VanChartPlotLabelDetailPane { textFontPane.setPreferredSize(new Dimension(0, TEXT_FONT_PANE_HEIGHT)); } - protected boolean hasLabelAlign(Plot plot) { - return getGaugeStyle() == GaugeStyle.THERMOMETER && !((VanChartGaugePlot) plot).getGaugeDetailStyle().isHorizontalLayout(); + protected boolean hasLabelAlign() { + return getGaugeStyle() == GaugeStyle.THERMOMETER && !((VanChartGaugePlot) getPlot()).getGaugeDetailStyle().isHorizontalLayout(); } protected boolean hasLabelAlignPane() { @@ -240,7 +228,7 @@ public class VanChartGaugeLabelDetailPane extends VanChartPlotLabelDetailPane { style.setSelectedIndex(1); textFontPane.populate(detail.getTextAttr()); - if (hasLabelAlign(this.getPlot()) && align != null) { + if (hasLabelAlign() && align != null) { align.setSelectedItem(detail.getAlign()); }