diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example1.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example1.java index a42d16ac4d38ea74dc742a68ef751e2de85eb840..40588fc699e9c0552a747eb10ec8a695c28af616 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example1.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example1.java @@ -75,7 +75,7 @@ public class Example1 implements ExampleChart { // Customize Chart chart.setTitle("Example1"); - chart.setTitleVisible(false); + chart.getStyleManager().setChartTitleVisible(false); chart.setLegendVisible(false); // Series 1 diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example2.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example2.java index cf6d62a66511c0b3e725fc1409af0f1882469097..9da85d2cf0147d0532f508042a37fc04b328afe9 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example2.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example2.java @@ -56,7 +56,7 @@ public class Example2 implements ExampleChart { Chart chart = new Chart(800, 600); // Customize Chart - chart.setTitleVisible(false); + chart.getStyleManager().setChartTitleVisible(false); chart.setLegendVisible(false); // Series 1 diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example8.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example8.java index 59a6550cbf7058f86b5d42317c0531cb62173829..b6d9036aced6fb4799eab05342bb3ecd743e374b 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example8.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example8.java @@ -57,7 +57,7 @@ public class Example8 implements ExampleChart { Chart chart = new Chart(800, 600); // Customize Chart - chart.setTitleVisible(false); + chart.getStyleManager().setChartTitleVisible(false); chart.setLegendVisible(false); chart.setAxisTitlesVisible(false); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example9.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example9.java index 41be965a1265d3e239d3dcc870fb4a8c6e672ec3..f53a8e148767b24e07e7ee0f013430490b14ad74 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example9.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/Example9.java @@ -80,7 +80,7 @@ public class Example9 implements ExampleChart { chart.setLegendBackgroundColor(Color.PINK); chart.getStyleManager().setChartBordersColor(Color.GREEN); chart.getStyleManager().setChartFontColor(Color.MAGENTA); - chart.setTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); + chart.getStyleManager().setTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); chart.setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); chart.setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.setTickLabelFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); diff --git a/xchart/src/main/java/com/xeiam/xchart/Chart.java b/xchart/src/main/java/com/xeiam/xchart/Chart.java index 6150980714594064b6e95619650dd817f7423f49..332a5e148cc174512b15c6ae01598f014f484711 100644 --- a/xchart/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart/src/main/java/com/xeiam/xchart/Chart.java @@ -249,16 +249,6 @@ public class Chart { // ChartPart visibility //////////////////////////////// - /** - * Set the chart title visibility - * - * @param isVisible - */ - public void setTitleVisible(boolean isVisible) { - - this.chartTitle.setVisible(isVisible); - } - /** * Set the x- and y-axis titles visibility * @@ -371,16 +361,6 @@ public class Chart { this.chartLegend.backgroundColor = color; } - /** - * Set the chart title font - * - * @param font - */ - public void setTitleFont(Font font) { - - styleManager.setTitleFont(font); - } - /** * Set the chart legend font * 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 ddf9ec7006637d1d6a3baec3aaa55d132feaaf77..649768c712a904935fafe82fea6d4855447792ca 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 @@ -35,9 +35,6 @@ public class ChartTitle implements IChartPart, IHideable { /** the title text */ protected String text = ""; // default to "" - /** the visibility state of title */ - protected boolean isVisible = false; // default to false - /** the bounds */ private Rectangle bounds; @@ -54,9 +51,9 @@ public class ChartTitle implements IChartPart, IHideable { public void setText(String text) { if (text.trim().equalsIgnoreCase("")) { - this.isVisible = false; + chart.getStyleManager().setChartTitleVisible(false); } else { - this.isVisible = true; + chart.getStyleManager().setChartTitleVisible(true); } this.text = text; } @@ -64,7 +61,6 @@ public class ChartTitle implements IChartPart, IHideable { @Override public void setVisible(boolean isVisible) { - this.isVisible = isVisible; } @Override @@ -73,15 +69,16 @@ public class ChartTitle implements IChartPart, IHideable { bounds = new Rectangle(); g.setFont(chart.getStyleManager().getChartTitleFont()); - if (isVisible) { + if (chart.getStyleManager().isChartTitleVisible()) { FontRenderContext frc = g.getFontRenderContext(); TextLayout textLayout = new TextLayout(text, chart.getStyleManager().getChartTitleFont(), frc); Rectangle rectangle = textLayout.getPixelBounds(null, 0, 0); int xOffset = (int) ((chart.width - rectangle.getWidth()) / 2.0); - int yOffset = (int) ((isVisible ? (Chart.CHART_PADDING - rectangle.getY()) : 0)); + int yOffset = (int) ((chart.getStyleManager().isChartTitleVisible() ? (Chart.CHART_PADDING - rectangle.getY()) : 0)); - bounds = new Rectangle(xOffset, yOffset + (isVisible ? (int) rectangle.getY() : 0), (int) rectangle.getWidth(), (int) (isVisible ? rectangle.getHeight() : 0)); + bounds = new Rectangle(xOffset, yOffset + (chart.getStyleManager().isChartTitleVisible() ? (int) rectangle.getY() : 0), (int) rectangle.getWidth(), (int) (chart.getStyleManager() + .isChartTitleVisible() ? rectangle.getHeight() : 0)); // g.setColor(Color.green); // g.draw(bounds); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/interfaces/IHideable.java b/xchart/src/main/java/com/xeiam/xchart/internal/interfaces/IHideable.java index b546fc47fbf4dda488b53b80828f5c3d924c1d72..9c4fb79108cdbee2c938d627a7ff4892bff553f4 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/interfaces/IHideable.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/interfaces/IHideable.java @@ -11,6 +11,7 @@ package com.xeiam.xchart.internal.interfaces; * * @author timmolter */ +// TODO get rid of this after theme refactor is done public interface IHideable extends IChartPart { public void setVisible(boolean isVisible); diff --git a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java index 2374e400b08710840719d812b6711b9ed4a22b88..b08bc3eac52fa2b430de0cbce3a9767805e8a5b9 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java @@ -41,6 +41,8 @@ public class StyleManager { private Font chartTitleFont; + private boolean isChartTitleVisible; + /** * Constructor */ @@ -55,6 +57,7 @@ public class StyleManager { chartBordersColor = theme.getChartBordersColor(); chartFontColor = theme.getChartFontColor(); chartTitleFont = theme.getChartTitleFont(); + isChartTitleVisible = theme.isChartTitleVisible(); } /** @@ -132,6 +135,21 @@ public class StyleManager { return chartTitleFont; } + /** + * Set the chart title visibility + * + * @param isVisible + */ + public void setChartTitleVisible(boolean isChartTitleVisible) { + + this.isChartTitleVisible = isChartTitleVisible; + } + + public boolean isChartTitleVisible() { + + return isChartTitleVisible; + } + // Chart Legend /////////////////////////////// // Chart Title /////////////////////////////// diff --git a/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java b/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java index 7170e1056a86e1a6d0ad831fbbe5fcf61262d032..f3388869e62ce860e415a091650be1a84a54ef1f 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/theme/Theme.java @@ -29,12 +29,18 @@ import java.awt.Font; */ public interface Theme { + // Chart Style /////////////////////////////// + public Color getChartBackgroundColor(); public Color getChartBordersColor(); public Color getChartFontColor(); + // Chart Title /////////////////////////////// + public Font getChartTitleFont(); + public boolean isChartTitleVisible(); + } diff --git a/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java b/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java index e266bb5025cd73b0b25f114a5ad69c4bb1b08908..f541f4f75eda4ec78ec368e035d41c2cedbb243f 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/theme/XChartTheme.java @@ -55,4 +55,10 @@ public class XChartTheme implements Theme { return new Font(Font.SANS_SERIF, Font.BOLD, 14); } + @Override + public boolean isChartTitleVisible() { + + return false; + } + }