From 7f24cc91e5f36582340c55ed2bd8a75df3e061f4 Mon Sep 17 00:00:00 2001
From: Tim Molter <tim.molter@gmail.com>
Date: Mon, 4 Mar 2013 23:17:42 +0100
Subject: [PATCH] addressed a chart title box issue

---
 .../xchart/demo/charts/line/LineChart03.java  |  7 +--
 .../java/com/xeiam/xchart/StyleManager.java   | 49 +++++++++++++------
 .../xchart/internal/chartpart/ChartTitle.java | 20 +++++---
 .../xchart/internal/style/GGPlot2Theme.java   | 10 +++-
 .../xeiam/xchart/internal/style/Theme.java    |  6 ++-
 .../xchart/internal/style/XChartTheme.java    | 10 +++-
 6 files changed, 69 insertions(+), 33 deletions(-)

diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java
index 4c45430f..5dc34019 100644
--- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java
+++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java
@@ -31,8 +31,8 @@ import com.xeiam.xchart.Series;
 import com.xeiam.xchart.SeriesColor;
 import com.xeiam.xchart.SeriesLineStyle;
 import com.xeiam.xchart.SeriesMarker;
-import com.xeiam.xchart.SwingWrapper;
 import com.xeiam.xchart.StyleManager.LegendPosition;
+import com.xeiam.xchart.SwingWrapper;
 import com.xeiam.xchart.demo.charts.ExampleChart;
 
 /**
@@ -79,7 +79,9 @@ public class LineChart03 implements ExampleChart {
     chart.getStyleManager().setChartBackgroundColor(Color.WHITE);
     chart.getStyleManager().setLegendBackgroundColor(Color.PINK);
     chart.getStyleManager().setChartFontColor(Color.MAGENTA);
-    chart.getStyleManager().setChartTitleBackgroundColor(new Color(0, 222, 0));
+    chart.getStyleManager().setChartTitleBoxBackgroundColor(new Color(0, 222, 0));
+    chart.getStyleManager().setChartTitleBoxVisible(true);
+    chart.getStyleManager().setChartTitleBoxBorderColor(Color.BLACK);
     chart.getStyleManager().setPlotGridLinesVisible(false);
     chart.getStyleManager().setAxisTickPadding(20);
     chart.getStyleManager().setAxisTickMarkLength(15);
@@ -101,5 +103,4 @@ public class LineChart03 implements ExampleChart {
 
     return chart;
   }
-
 }
diff --git a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java
index 12c53692..d712b24f 100644
--- a/xchart/src/main/java/com/xeiam/xchart/StyleManager.java
+++ b/xchart/src/main/java/com/xeiam/xchart/StyleManager.java
@@ -63,8 +63,9 @@ public class StyleManager {
   // Chart Title ///////////////////////////////
   private Font chartTitleFont;
   private boolean isChartTitleVisible;
-  private Color chartTitleBackgroundColor;
-  private Color chartTitleBorderColor;
+  private boolean isChartTitleBoxVisible;
+  private Color chartTitleBoxBackgroundColor;
+  private Color chartTitleBoxBorderColor;
   private int chartTitlePadding;
 
   // Chart Legend ///////////////////////////////
@@ -134,8 +135,9 @@ public class StyleManager {
     // Chart Title ///////////////////////////////
     chartTitleFont = theme.getChartTitleFont();
     isChartTitleVisible = theme.isChartTitleVisible();
-    chartTitleBackgroundColor = theme.getChartTitleBackgroundColor();
-    chartTitleBorderColor = theme.getChartTitleBorderColor();
+    isChartTitleBoxVisible = theme.isChartTitleBoxVisible();
+    chartTitleBoxBackgroundColor = theme.getChartTitleBoxBackgroundColor();
+    chartTitleBoxBorderColor = theme.getChartTitleBoxBorderColor();
     chartTitlePadding = theme.getChartTitlePadding();
 
     // legend
@@ -312,33 +314,48 @@ public class StyleManager {
   }
 
   /**
-   * set the chart title background color
+   * Set the chart title box visibility
    * 
-   * @param chartTitleBackgroundColor
+   * @param isChartTitleBoxVisible
    */
-  public void setChartTitleBackgroundColor(Color chartTitleBackgroundColor) {
+  public void setChartTitleBoxVisible(boolean isChartTitleBoxVisible) {
 
-    this.chartTitleBackgroundColor = chartTitleBackgroundColor;
+    this.isChartTitleBoxVisible = isChartTitleBoxVisible;
   }
 
-  public Color getChartTitleBackgroundColor() {
+  public boolean isChartTitleBoxVisible() {
 
-    return chartTitleBackgroundColor;
+    return isChartTitleBoxVisible;
   }
 
   /**
-   * set the chart title border color
+   * set the chart title box background color
    * 
-   * @param chartTitleBorderColor
+   * @param chartTitleBoxBackgroundColor
    */
-  public void setChartTitleBorderColor(Color chartTitleBorderColor) {
+  public void setChartTitleBoxBackgroundColor(Color chartTitleBoxBackgroundColor) {
 
-    this.chartTitleBorderColor = chartTitleBorderColor;
+    this.chartTitleBoxBackgroundColor = chartTitleBoxBackgroundColor;
   }
 
-  public Color getChartTitleBorderColor() {
+  public Color getChartTitleBoxBackgroundColor() {
 
-    return chartTitleBorderColor;
+    return chartTitleBoxBackgroundColor;
+  }
+
+  /**
+   * set the chart title box border color
+   * 
+   * @param chartTitleBoxBorderColor
+   */
+  public void setChartTitleBoxBorderColor(Color chartTitleBoxBorderColor) {
+
+    this.chartTitleBoxBorderColor = chartTitleBoxBorderColor;
+  }
+
+  public Color getChartTitleBoxBorderColor() {
+
+    return chartTitleBoxBorderColor;
   }
 
   /**
diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java
index bc1ccbfa..395e47ae 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/ChartTitle.java
@@ -91,17 +91,21 @@ public class ChartTitle implements ChartPart {
       TextLayout textLayout = new TextLayout(text, chartPainter.getStyleManager().getChartTitleFont(), frc);
       Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0);
 
-      // paint the chart title box
-      int chartTitleBoxWidth = (int) chartPainter.getPlot().getBounds().getWidth();
-      int chartTitleBoxHeight = (int) (rectangle.getHeight() + 2 * chartPainter.getStyleManager().getChartTitlePadding());
       int xOffset = (int) chartPainter.getPlot().getBounds().getX();
       int yOffset = chartPainter.getStyleManager().getChartPadding();
 
-      g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
-      g.setColor(chartPainter.getStyleManager().getChartTitleBorderColor());
-      g.drawRect(xOffset - 1, yOffset, chartTitleBoxWidth - 1, chartTitleBoxHeight - 1);
-      g.setColor(chartPainter.getStyleManager().getChartTitleBackgroundColor());
-      g.fillRect(xOffset - 1, yOffset + 1, chartTitleBoxWidth, chartTitleBoxHeight - 1);
+      if (chartPainter.getStyleManager().isChartTitleBoxVisible()) {
+
+        // paint the chart title box
+        int chartTitleBoxWidth = (int) chartPainter.getPlot().getBounds().getWidth();
+        int chartTitleBoxHeight = (int) (rectangle.getHeight() + 2 * chartPainter.getStyleManager().getChartTitlePadding());
+
+        g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
+        g.setColor(chartPainter.getStyleManager().getChartTitleBoxBorderColor());
+        g.drawRect(xOffset - 1, yOffset, chartTitleBoxWidth, chartTitleBoxHeight);
+        g.setColor(chartPainter.getStyleManager().getChartTitleBoxBackgroundColor());
+        g.fillRect(xOffset, yOffset + 1, chartTitleBoxWidth - 1, chartTitleBoxHeight - 1);
+      }
 
       // paint title
       xOffset = (int) (chartPainter.getPlot().getBounds().getX() + (chartPainter.getPlot().getBounds().getWidth() - rectangle.getWidth()) / 2.0);
diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java
index ead2c0ad..207d55be 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/GGPlot2Theme.java
@@ -69,13 +69,19 @@ public class GGPlot2Theme implements Theme {
   }
 
   @Override
-  public Color getChartTitleBackgroundColor() {
+  public boolean isChartTitleBoxVisible() {
+
+    return true;
+  }
+
+  @Override
+  public Color getChartTitleBoxBackgroundColor() {
 
     return ChartColor.getAWTColor(ChartColor.GREY);
   }
 
   @Override
-  public Color getChartTitleBorderColor() {
+  public Color getChartTitleBoxBorderColor() {
 
     return ChartColor.getAWTColor(ChartColor.GREY);
   }
diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java
index 85edec3e..c6fdc4f0 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/Theme.java
@@ -46,9 +46,11 @@ public interface Theme {
 
   public boolean isChartTitleVisible();
 
-  public Color getChartTitleBackgroundColor();
+  public boolean isChartTitleBoxVisible();
 
-  public Color getChartTitleBorderColor();
+  public Color getChartTitleBoxBackgroundColor();
+
+  public Color getChartTitleBoxBorderColor();
 
   public int getChartTitlePadding();
 
diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java b/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java
index d660fdf2..5d9b542b 100644
--- a/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java
+++ b/xchart/src/main/java/com/xeiam/xchart/internal/style/XChartTheme.java
@@ -69,13 +69,19 @@ public class XChartTheme implements Theme {
   }
 
   @Override
-  public Color getChartTitleBackgroundColor() {
+  public boolean isChartTitleBoxVisible() {
+
+    return false;
+  }
+
+  @Override
+  public Color getChartTitleBoxBackgroundColor() {
 
     return ChartColor.getAWTColor(ChartColor.GREY);
   }
 
   @Override
-  public Color getChartTitleBorderColor() {
+  public Color getChartTitleBoxBorderColor() {
 
     return ChartColor.getAWTColor(ChartColor.GREY);
   }
-- 
GitLab