Skip to content
Snippets Groups Projects
Commit 74caf0e3 authored by ruX[Ruslan Zaharov]'s avatar ruX[Ruslan Zaharov]
Browse files

Chart constructor with custom theme

parent 6b99e929
No related branches found
No related tags found
No related merge requests found
......@@ -15,18 +15,16 @@
*/
package com.xeiam.xchart;
import java.awt.Graphics2D;
import com.xeiam.xchart.StyleManager.ChartTheme;
import com.xeiam.xchart.internal.chartpart.ChartPainter;
import com.xeiam.xchart.internal.style.Theme;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import com.xeiam.xchart.StyleManager.ChartTheme;
import com.xeiam.xchart.internal.chartpart.ChartPainter;
import com.xeiam.xchart.internal.style.GGPlot2Theme;
import com.xeiam.xchart.internal.style.MatlabTheme;
import com.xeiam.xchart.internal.style.XChartTheme;
/**
* An XChart Chart
*
......@@ -56,18 +54,20 @@ public class Chart {
* @param chartTheme
*/
public Chart(int width, int height, ChartTheme chartTheme) {
this(width, height, chartTheme.newInstance(chartTheme));
}
chartPainter = new ChartPainter(width, height);
/**
* Constructor
*
* @param width
* @param height
* @param theme instance of Theme class
*/
public Chart(int width, int height, Theme theme) {
if (chartTheme == ChartTheme.XChart) {
chartPainter.getStyleManager().setTheme(new XChartTheme());
}
else if (chartTheme == ChartTheme.GGPlot2) {
chartPainter.getStyleManager().setTheme(new GGPlot2Theme());
}
else if (chartTheme == ChartTheme.Matlab) {
chartPainter.getStyleManager().setTheme(new MatlabTheme());
}
chartPainter = new ChartPainter(width, height);
chartPainter.getStyleManager().setTheme(theme);
}
/**
......
......@@ -15,15 +15,15 @@
*/
package com.xeiam.xchart;
import java.awt.Color;
import java.awt.Font;
import java.awt.Stroke;
import java.util.Locale;
import java.util.TimeZone;
import com.xeiam.xchart.internal.style.GGPlot2Theme;
import com.xeiam.xchart.internal.style.MatlabTheme;
import com.xeiam.xchart.internal.style.Theme;
import com.xeiam.xchart.internal.style.XChartTheme;
import java.awt.*;
import java.util.Locale;
import java.util.TimeZone;
/**
* The StyleManager is used to manage all things related to styling of the vast number of Chart components
*
......@@ -46,7 +46,22 @@ public class StyleManager {
public enum ChartTheme {
XChart, GGPlot2, Matlab
XChart, GGPlot2, Matlab;
public Theme newInstance(ChartTheme chartTheme) {
switch (chartTheme) {
case GGPlot2:
return new GGPlot2Theme();
case Matlab:
return new MatlabTheme();
case XChart:
default:
return new XChartTheme();
}
}
}
/** the default Theme */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment