Skip to content
Snippets Groups Projects
Commit 12423507 authored by Tim Molter's avatar Tim Molter
Browse files

title font

parent 57dee0f3
Branches
No related tags found
No related merge requests found
Showing
with 78 additions and 40 deletions
......@@ -76,10 +76,10 @@ public class Example9 implements ExampleChart {
chart.setYAxisTitle("Y");
chart.setForegroundColor(ChartColor.getAWTColor(ChartColor.GREY));
chart.setGridLinesColor(new Color(255, 255, 255));
chart.getStyleManager().setBackgroundColor(Color.WHITE);
chart.getStyleManager().setChartBackgroundColor(Color.WHITE);
chart.setLegendBackgroundColor(Color.PINK);
chart.getStyleManager().setBordersColor(Color.GREEN);
chart.getStyleManager().setFontColor(Color.MAGENTA);
chart.getStyleManager().setChartBordersColor(Color.GREEN);
chart.getStyleManager().setChartFontColor(Color.MAGENTA);
chart.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));
......
......@@ -104,7 +104,7 @@ public class Chart {
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint
g.setColor(styleManager.getBackgroundColor());
g.setColor(styleManager.getChartBackgroundColor());
g.fillRect(0, 0, width, height);
chartTitle.paint(g);
......@@ -378,7 +378,7 @@ public class Chart {
*/
public void setTitleFont(Font font) {
this.chartTitle.font = font;
styleManager.setTitleFont(font);
}
/**
......
......@@ -60,7 +60,7 @@ public class AxisTickLabels implements IChartPart {
bounds = new Rectangle();
g.setFont(font);
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getFontColor());
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartFontColor());
if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis
......
......@@ -60,7 +60,7 @@ public class AxisTickMarks implements IChartPart {
bounds = new Rectangle();
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getBordersColor());
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor());
if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis
......@@ -72,7 +72,7 @@ public class AxisTickMarks implements IChartPart {
int tickLocation = axisTick.tickLocations.get(i);
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getBordersColor());
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor());
g.setStroke(stroke);
g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + TICK_LENGTH, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation));
......@@ -96,7 +96,7 @@ public class AxisTickMarks implements IChartPart {
int tickLocation = axisTick.tickLocations.get(i);
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getBordersColor());
g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getChartBordersColor());
g.setStroke(stroke);
g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - TICK_LENGTH);
......
......@@ -100,7 +100,7 @@ public class AxisTitle implements IChartPart, IHideable {
bounds = new Rectangle();
g.setColor(axis.axisPair.chart.getStyleManager().getFontColor());
g.setColor(axis.axisPair.chart.getStyleManager().getChartFontColor());
g.setFont(font);
if (axis.direction == Axis.Direction.Y) {
......
......@@ -15,7 +15,6 @@
*/
package com.xeiam.xchart.internal.chartpart;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.font.FontRenderContext;
......@@ -39,9 +38,6 @@ public class ChartTitle implements IChartPart, IHideable {
/** the visibility state of title */
protected boolean isVisible = false; // default to false
/** the font */
public Font font;
/** the bounds */
private Rectangle bounds;
......@@ -53,7 +49,6 @@ public class ChartTitle implements IChartPart, IHideable {
public ChartTitle(Chart chart) {
this.chart = chart;
font = new Font(Font.SANS_SERIF, Font.BOLD, 14); // default font
}
public void setText(String text) {
......@@ -76,12 +71,12 @@ public class ChartTitle implements IChartPart, IHideable {
public void paint(Graphics2D g) {
bounds = new Rectangle();
g.setFont(font);
g.setFont(chart.getStyleManager().getChartTitleFont());
if (isVisible) {
FontRenderContext frc = g.getFontRenderContext();
TextLayout textLayout = new TextLayout(text, font, frc);
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));
......@@ -90,7 +85,7 @@ public class ChartTitle implements IChartPart, IHideable {
// g.setColor(Color.green);
// g.draw(bounds);
g.setColor(chart.getStyleManager().getFontColor());
g.setColor(chart.getStyleManager().getChartFontColor());
textLayout.draw(g, xOffset, yOffset);
}
......
......@@ -111,7 +111,7 @@ public class Legend implements IChartPart, IHideable {
int xOffset = chart.width - legendBoxWidth - Chart.CHART_PADDING;
int yOffset = (int) ((chart.height - legendBoxHeight) / 2.0 + chart.chartTitle.getBounds().getY() + chart.chartTitle.getBounds().getHeight());
g.setColor(chart.getStyleManager().getBordersColor());
g.setColor(chart.getStyleManager().getChartBordersColor());
g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight);
g.setColor(backgroundColor);
g.fillRect(xOffset + 1, yOffset + 1, legendBoxWidth - 1, legendBoxHeight - 1);
......@@ -134,7 +134,7 @@ public class Legend implements IChartPart, IHideable {
}
// paint series name
g.setColor(chart.getStyleManager().getFontColor());
g.setColor(chart.getStyleManager().getChartFontColor());
TextLayout layout = new TextLayout(series.name, font, new FontRenderContext(null, true, false));
layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + LEGEND_PADDING), (starty + Marker.SIZE));
starty = starty + legendTextContentMaxHeight + LEGEND_PADDING;
......
......@@ -145,7 +145,7 @@ public class PlotContent implements IChartPart {
// paint errorbar
if (errorBars != null) {
g.setColor(plot.chart.getStyleManager().getBordersColor());
g.setColor(plot.chart.getStyleManager().getChartBordersColor());
g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
int bottom = (int) (-1 * bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue()));
int top = (int) (bounds.getHeight() * eb / (yMax.subtract(yMin).doubleValue()));
......
......@@ -74,7 +74,7 @@ public class PlotSurface implements IChartPart, IHideable {
g.setColor(foregroundColor);
g.fill(backgroundRectangle);
Rectangle borderRectangle = new Rectangle((int) bounds.getX() - 1, (int) bounds.getY(), (int) (bounds.getWidth()), (int) bounds.getHeight());
g.setColor(plot.chart.getStyleManager().getBordersColor());
g.setColor(plot.chart.getStyleManager().getChartBordersColor());
g.draw(borderRectangle);
// paint grid lines
......
......@@ -22,6 +22,7 @@
package com.xeiam.xchart.style;
import java.awt.Color;
import java.awt.Font;
import com.xeiam.xchart.style.theme.Theme;
import com.xeiam.xchart.style.theme.XChartTheme;
......@@ -31,20 +32,29 @@ import com.xeiam.xchart.style.theme.XChartTheme;
*/
public class StyleManager {
/** the default Theme */
private Theme theme = new XChartTheme();
private Color backgroundColor;
public Color bordersColor;
public Color fontColor;
private Color chartBackgroundColor;
public Color chartBordersColor;
public Color chartFontColor;
private Font chartTitleFont;
/**
* Constructor
*/
public StyleManager() {
backgroundColor = theme.getChartBackgroundColor();
bordersColor = theme.getChartBordersColor();
fontColor = theme.getChartFontColor();
setAllStyles();
}
private void setAllStyles() {
chartBackgroundColor = theme.getChartBackgroundColor();
chartBordersColor = theme.getChartBordersColor();
chartFontColor = theme.getChartFontColor();
chartTitleFont = theme.getChartTitleFont();
}
/**
......@@ -55,16 +65,24 @@ public class StyleManager {
public void setTheme(Theme theme) {
this.theme = theme;
setAllStyles();
}
// Chart Style ///////////////////////////////
/**
* Set the chart background color - the part around the edge of the chart
*
* @param color
*/
public void setBackgroundColor(Color backgroundColor) {
public void setChartBackgroundColor(Color color) {
this.chartBackgroundColor = color;
}
public Color getChartBackgroundColor() {
this.backgroundColor = backgroundColor;
return chartBackgroundColor;
}
/**
......@@ -72,9 +90,14 @@ public class StyleManager {
*
* @param color
*/
public void setBordersColor(Color bordersColor) {
public void setChartBordersColor(Color color) {
this.bordersColor = bordersColor;
this.chartBordersColor = color;
}
public Color getChartBordersColor() {
return chartBordersColor;
}
/**
......@@ -82,24 +105,34 @@ public class StyleManager {
*
* @param color
*/
public void setFontColor(Color fontColor) {
public void setChartFontColor(Color color) {
this.fontColor = fontColor;
this.chartFontColor = color;
}
public Color getBackgroundColor() {
public Color getChartFontColor() {
return backgroundColor;
return chartFontColor;
}
public Color getBordersColor() {
// Chart Title ///////////////////////////////
/**
* Set the chart title font
*
* @param font
*/
public void setTitleFont(Font font) {
return bordersColor;
this.chartTitleFont = font;
}
public Color getFontColor() {
public Font getChartTitleFont() {
return fontColor;
return chartTitleFont;
}
// Chart Legend ///////////////////////////////
// Chart Title ///////////////////////////////
}
......@@ -22,6 +22,7 @@
package com.xeiam.xchart.style.theme;
import java.awt.Color;
import java.awt.Font;
/**
* @author timmolter
......@@ -34,4 +35,6 @@ public interface Theme {
public Color getChartFontColor();
public Font getChartTitleFont();
}
......@@ -22,6 +22,7 @@
package com.xeiam.xchart.style.theme;
import java.awt.Color;
import java.awt.Font;
import com.xeiam.xchart.style.ChartColor;
......@@ -48,4 +49,10 @@ public class XChartTheme implements Theme {
return ChartColor.getAWTColor(ChartColor.BLACK);
}
@Override
public Font getChartTitleFont() {
return new Font(Font.SANS_SERIF, Font.BOLD, 14);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment