From 897c9cbd2e6d05117175cf2e56077425162ce01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B2=B3?= <445798420@qq.com> Date: Fri, 10 Apr 2020 11:04:31 +0800 Subject: [PATCH] =?UTF-8?q?CHART-13390=20&&=20CHART-13384=20=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../combobox/ColorSchemeComboBox.java | 12 ++++++++---- .../component/VanChartFillStylePane.java | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java b/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java index 9fcbeb2b69..4358a728dd 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java @@ -177,6 +177,8 @@ public class ColorSchemeComboBox extends UIComboBox { private static final int MAX_COUNT = 5; + private static final int BLANK = 1; + @Override public Dimension getPreferredSize() { Dimension preferredSize = super.getPreferredSize(); @@ -198,7 +200,8 @@ public class ColorSchemeComboBox extends UIComboBox { comp.setText(BLANK_SPACE + schemeName); } else { FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont()); - double width = (HEIGHT - 2 * Y) * MAX_COUNT; + //宽度是5倍的高加上4倍的留白 + double width = (HEIGHT - 2 * Y) * MAX_COUNT + BLANK * (MAX_COUNT - 1); String fill = BLANK_SPACE; //图形和文字之间留的宽度大于3倍的X while (fontMetrics.stringWidth(fill) < width + 3 * X) { @@ -228,7 +231,7 @@ public class ColorSchemeComboBox extends UIComboBox { private void drawGradient(Graphics2D g2d, List colors) { //上下留4px,宽度等于5倍高 double height = HEIGHT - 2 * Y; - double width = height * MAX_COUNT; + double width = height * MAX_COUNT + BLANK * (MAX_COUNT - 1); LinearGradientPaint linearGradientPaint = new LinearGradientPaint((float) X, (float) Y, (float) (X + width), (float) Y, new float[]{0f, 1f}, colors.toArray(new Color[colors.size()])); g2d.setPaint(linearGradientPaint); Rectangle2D rec = new Rectangle2D.Double(X, Y, width, height); @@ -238,10 +241,11 @@ public class ColorSchemeComboBox extends UIComboBox { private void drawCombineColor(Graphics2D g2d, List colors) { int size = Math.min(colors.size(), MAX_COUNT); double height = HEIGHT - 2 * Y; - double width = height * MAX_COUNT / size; + //加上1px留白 + double width = ((height + BLANK) * MAX_COUNT - size) / size; for (int i = 0; i < size; i++) { g2d.setPaint(colors.get(i)); - Rectangle2D rec = new Rectangle2D.Double(X + width * i, Y, width, height); + Rectangle2D rec = new Rectangle2D.Double(X + (width + BLANK) * i, Y, width, height); g2d.fill(rec); } } diff --git a/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java b/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java index c662627965..63c24a221b 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/designer/component/VanChartFillStylePane.java @@ -52,7 +52,15 @@ public class VanChartFillStylePane extends BasicBeanPane { this.setLayout(new BorderLayout()); styleSelectBox = new ColorSchemeComboBox(); - customPane = new JPanel(FRGUIPaneFactory.createBorderLayout()); + customPane = new JPanel(FRGUIPaneFactory.createBorderLayout()) { + @Override + public Dimension getPreferredSize() { + if (!gradientSelect) { + return colorAdjustPane.getPreferredSize(); + } + return colorGradient.getPreferredSize(); + } + }; changeColorSetPane = new JPanel(cardLayout = new CardLayout()); changeColorSetPane.add(colorGradient = new FixedGradientBar(4, 130), "gradient"); @@ -119,18 +127,11 @@ public class VanChartFillStylePane extends BasicBeanPane { } protected void initLayout() { + this.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); this.setLayout(new BorderLayout()); this.add(getContentPane(), BorderLayout.CENTER); } - @Override - public Dimension getPreferredSize() { - if (gradientSelect) { - return new Dimension(225, 80); - } - return super.getPreferredSize(); - } - protected JPanel getContentPane() { double p = TableLayout.PREFERRED; double f = TableLayout.FILL;