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

added style manager

parent b5c0f129
Branches
No related tags found
No related merge requests found
Showing
with 149 additions and 76 deletions
...@@ -19,9 +19,9 @@ import java.util.Arrays; ...@@ -19,9 +19,9 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SeriesMarker;
import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.appearance.SeriesMarker;
/** /**
* Manual Data * Manual Data
......
...@@ -16,11 +16,11 @@ ...@@ -16,11 +16,11 @@
package com.xeiam.xchart.demo.charts; package com.xeiam.xchart.demo.charts;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
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.SwingWrapper;
import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.appearance.SeriesColor;
import com.xeiam.xchart.appearance.SeriesLineStyle;
import com.xeiam.xchart.appearance.SeriesMarker;
/** /**
* Plots Hundreds of Series on One Plot * Plots Hundreds of Series on One Plot
......
...@@ -19,11 +19,11 @@ import java.util.ArrayList; ...@@ -19,11 +19,11 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
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.SwingWrapper;
import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.appearance.SeriesColor;
import com.xeiam.xchart.appearance.SeriesLineStyle;
import com.xeiam.xchart.appearance.SeriesMarker;
/** /**
* Sine wave with customized series style * Sine wave with customized series style
......
...@@ -24,8 +24,8 @@ import java.util.Date; ...@@ -24,8 +24,8 @@ import java.util.Date;
import java.util.TimeZone; import java.util.TimeZone;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series;
import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.SwingWrapper;
import com.xeiam.xchart.appearance.Series;
/** /**
* Date Axis * Date Axis
......
...@@ -19,11 +19,11 @@ import java.util.ArrayList; ...@@ -19,11 +19,11 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
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.SwingWrapper;
import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.appearance.SeriesColor;
import com.xeiam.xchart.appearance.SeriesLineStyle;
import com.xeiam.xchart.appearance.SeriesMarker;
/** /**
* Error bars * Error bars
......
...@@ -26,12 +26,12 @@ import java.util.Date; ...@@ -26,12 +26,12 @@ import java.util.Date;
import java.util.Locale; import java.util.Locale;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartColor;
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.SwingWrapper;
import com.xeiam.xchart.appearance.ChartColor;
import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.appearance.SeriesColor;
import com.xeiam.xchart.appearance.SeriesLineStyle;
import com.xeiam.xchart.appearance.SeriesMarker;
/** /**
* Extensive chart customization * Extensive chart customization
...@@ -76,10 +76,10 @@ public class Example9 implements ExampleChart { ...@@ -76,10 +76,10 @@ public class Example9 implements ExampleChart {
chart.setYAxisTitle("Y"); chart.setYAxisTitle("Y");
chart.setForegroundColor(ChartColor.getAWTColor(ChartColor.GREY)); chart.setForegroundColor(ChartColor.getAWTColor(ChartColor.GREY));
chart.setGridLinesColor(new Color(255, 255, 255)); chart.setGridLinesColor(new Color(255, 255, 255));
chart.setBackgroundColor(Color.WHITE); chart.getStyleManager().setBackgroundColor(Color.WHITE);
chart.setLegendBackgroundColor(Color.PINK); chart.setLegendBackgroundColor(Color.PINK);
chart.setLinesColor(Color.GREEN); chart.getStyleManager().setBordersColor(Color.GREEN);
chart.setFontColor(Color.MAGENTA); chart.getStyleManager().setFontColor(Color.MAGENTA);
chart.setTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); chart.setTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24));
chart.setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); chart.setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18));
chart.setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18));
......
...@@ -25,6 +25,8 @@ import java.util.Date; ...@@ -25,6 +25,8 @@ import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.appearance.StyleManager;
import com.xeiam.xchart.internal.chartpart.AxisPair; import com.xeiam.xchart.internal.chartpart.AxisPair;
import com.xeiam.xchart.internal.chartpart.ChartTitle; import com.xeiam.xchart.internal.chartpart.ChartTitle;
import com.xeiam.xchart.internal.chartpart.Legend; import com.xeiam.xchart.internal.chartpart.Legend;
...@@ -39,12 +41,12 @@ public class Chart { ...@@ -39,12 +41,12 @@ public class Chart {
public int width; public int width;
public int height; public int height;
private Color backgroundColor;
public Color bordersColor; private StyleManager styleManager = new StyleManager();
public Color fontColor;
public final static int CHART_PADDING = 10; public final static int CHART_PADDING = 10;
// Chart Parts
public ChartTitle chartTitle = new ChartTitle(this); public ChartTitle chartTitle = new ChartTitle(this);
public Legend chartLegend = new Legend(this); public Legend chartLegend = new Legend(this);
public AxisPair axisPair = new AxisPair(this); public AxisPair axisPair = new AxisPair(this);
...@@ -60,9 +62,7 @@ public class Chart { ...@@ -60,9 +62,7 @@ public class Chart {
this.width = width; this.width = width;
this.height = height; this.height = height;
backgroundColor = ChartColor.getAWTColor(ChartColor.GREY);
bordersColor = ChartColor.getAWTColor(ChartColor.DARK_GREY);
fontColor = ChartColor.getAWTColor(ChartColor.BLACK);
} }
/** /**
...@@ -103,7 +103,7 @@ public class Chart { ...@@ -103,7 +103,7 @@ public class Chart {
} }
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // global rendering hint
g.setColor(backgroundColor); g.setColor(styleManager.getBackgroundColor());
g.fillRect(0, 0, width, height); g.fillRect(0, 0, width, height);
chartTitle.paint(g); chartTitle.paint(g);
...@@ -340,16 +340,6 @@ public class Chart { ...@@ -340,16 +340,6 @@ public class Chart {
this.plot.plotSurface.setVisible(isVisible); this.plot.plotSurface.setVisible(isVisible);
} }
/**
* Set the chart background color - the part around the edge of the chart
*
* @param color
*/
public void setBackgroundColor(Color color) {
this.backgroundColor = color;
}
/** /**
* Set the chart foreground color - the part the series are drawn on * Set the chart foreground color - the part the series are drawn on
* *
...@@ -380,26 +370,6 @@ public class Chart { ...@@ -380,26 +370,6 @@ public class Chart {
this.chartLegend.backgroundColor = color; this.chartLegend.backgroundColor = color;
} }
/**
* Sets the color of the plot border, legend border, tick marks, and error bars
*
* @param color
*/
public void setLinesColor(Color color) {
this.bordersColor = color;
}
/**
* Set the chart font color
*
* @param color
*/
public void setFontColor(Color color) {
this.fontColor = color;
}
/** /**
* Set the chart title font * Set the chart title font
* *
...@@ -496,4 +466,14 @@ public class Chart { ...@@ -496,4 +466,14 @@ public class Chart {
this.axisPair.yAxis.axisTick.timezone = timezone; this.axisPair.yAxis.axisTick.timezone = timezone;
} }
/**
* Gets the Chart's style manager, which can be used to customize the Chart's appearance
*
* @return the style manager
*/
public StyleManager getStyleManager() {
return styleManager;
}
} }
...@@ -17,6 +17,9 @@ package com.xeiam.xchart; ...@@ -17,6 +17,9 @@ package com.xeiam.xchart;
import java.util.Collection; import java.util.Collection;
import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.appearance.SeriesMarker;
/** /**
* A convenience class for making Charts with one line of code * A convenience class for making Charts with one line of code
* *
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.xeiam.xchart; package com.xeiam.xchart.appearance;
import java.awt.Color; import java.awt.Color;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.xeiam.xchart; package com.xeiam.xchart.appearance;
import java.awt.BasicStroke; import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.xeiam.xchart; package com.xeiam.xchart.appearance;
import java.awt.Color; import java.awt.Color;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.xeiam.xchart; package com.xeiam.xchart.appearance;
import java.awt.BasicStroke; import java.awt.BasicStroke;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.xeiam.xchart; package com.xeiam.xchart.appearance;
import com.xeiam.xchart.internal.markers.Circle; import com.xeiam.xchart.internal.markers.Circle;
import com.xeiam.xchart.internal.markers.Diamond; import com.xeiam.xchart.internal.markers.Diamond;
......
/**
* Copyright (C) 2013 Xeiam LLC http://xeiam.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.xeiam.xchart.appearance;
import java.awt.Color;
/**
* @author timmolter
*/
public class StyleManager {
private Color backgroundColor;
public Color bordersColor;
public Color fontColor;
/**
* Constructor
*/
public StyleManager() {
backgroundColor = ChartColor.getAWTColor(ChartColor.GREY);
bordersColor = ChartColor.getAWTColor(ChartColor.DARK_GREY);
fontColor = ChartColor.getAWTColor(ChartColor.BLACK);
}
/**
* Set the chart background color - the part around the edge of the chart
*
* @param color
*/
public void setBackgroundColor(Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
/**
* Sets the color of the plot border, legend border, tick marks, and error bars
*
* @param color
*/
public void setBordersColor(Color bordersColor) {
this.bordersColor = bordersColor;
}
/**
* Set the chart font color
*
* @param color
*/
public void setFontColor(Color fontColor) {
this.fontColor = fontColor;
}
public Color getBackgroundColor() {
return backgroundColor;
}
public Color getBordersColor() {
return bordersColor;
}
public Color getFontColor() {
return fontColor;
}
}
...@@ -25,7 +25,7 @@ import java.util.LinkedHashMap; ...@@ -25,7 +25,7 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.Series; import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.internal.chartpart.Axis.AxisType;
import com.xeiam.xchart.internal.interfaces.IChartPart; import com.xeiam.xchart.internal.interfaces.IChartPart;
import com.xeiam.xchart.internal.misc.SeriesColorMarkerLineStyleCycler; import com.xeiam.xchart.internal.misc.SeriesColorMarkerLineStyleCycler;
......
...@@ -60,7 +60,7 @@ public class AxisTickLabels implements IChartPart { ...@@ -60,7 +60,7 @@ public class AxisTickLabels implements IChartPart {
bounds = new Rectangle(); bounds = new Rectangle();
g.setFont(font); g.setFont(font);
g.setColor(axisTick.axis.axisPair.chart.fontColor); g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getFontColor());
if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis
......
...@@ -60,7 +60,7 @@ public class AxisTickMarks implements IChartPart { ...@@ -60,7 +60,7 @@ public class AxisTickMarks implements IChartPart {
bounds = new Rectangle(); bounds = new Rectangle();
g.setColor(axisTick.axis.axisPair.chart.bordersColor); g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getBordersColor());
if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis if (axisTick.axis.direction == Axis.Direction.Y) { // Y-Axis
...@@ -72,7 +72,7 @@ public class AxisTickMarks implements IChartPart { ...@@ -72,7 +72,7 @@ public class AxisTickMarks implements IChartPart {
int tickLocation = axisTick.tickLocations.get(i); int tickLocation = axisTick.tickLocations.get(i);
g.setColor(axisTick.axis.axisPair.chart.bordersColor); g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getBordersColor());
g.setStroke(stroke); g.setStroke(stroke);
g.drawLine(xOffset, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation), xOffset + TICK_LENGTH, yOffset + (int) (axisTick.axis.getPaintZone().getHeight() - tickLocation)); 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 { ...@@ -96,7 +96,7 @@ public class AxisTickMarks implements IChartPart {
int tickLocation = axisTick.tickLocations.get(i); int tickLocation = axisTick.tickLocations.get(i);
g.setColor(axisTick.axis.axisPair.chart.bordersColor); g.setColor(axisTick.axis.axisPair.chart.getStyleManager().getBordersColor());
g.setStroke(stroke); g.setStroke(stroke);
g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - TICK_LENGTH); g.drawLine(xOffset + tickLocation, yOffset, xOffset + tickLocation, yOffset - TICK_LENGTH);
......
...@@ -100,7 +100,7 @@ public class AxisTitle implements IChartPart, IHideable { ...@@ -100,7 +100,7 @@ public class AxisTitle implements IChartPart, IHideable {
bounds = new Rectangle(); bounds = new Rectangle();
g.setColor(axis.axisPair.chart.fontColor); g.setColor(axis.axisPair.chart.getStyleManager().getFontColor());
g.setFont(font); g.setFont(font);
if (axis.direction == Axis.Direction.Y) { if (axis.direction == Axis.Direction.Y) {
......
...@@ -90,7 +90,7 @@ public class ChartTitle implements IChartPart, IHideable { ...@@ -90,7 +90,7 @@ public class ChartTitle implements IChartPart, IHideable {
// g.setColor(Color.green); // g.setColor(Color.green);
// g.draw(bounds); // g.draw(bounds);
g.setColor(chart.fontColor); g.setColor(chart.getStyleManager().getFontColor());
textLayout.draw(g, xOffset, yOffset); textLayout.draw(g, xOffset, yOffset);
} }
......
...@@ -24,8 +24,8 @@ import java.awt.font.TextLayout; ...@@ -24,8 +24,8 @@ import java.awt.font.TextLayout;
import java.util.Map; import java.util.Map;
import com.xeiam.xchart.Chart; import com.xeiam.xchart.Chart;
import com.xeiam.xchart.ChartColor; import com.xeiam.xchart.appearance.ChartColor;
import com.xeiam.xchart.Series; import com.xeiam.xchart.appearance.Series;
import com.xeiam.xchart.internal.interfaces.IChartPart; import com.xeiam.xchart.internal.interfaces.IChartPart;
import com.xeiam.xchart.internal.interfaces.IHideable; import com.xeiam.xchart.internal.interfaces.IHideable;
import com.xeiam.xchart.internal.markers.Marker; import com.xeiam.xchart.internal.markers.Marker;
...@@ -111,7 +111,7 @@ public class Legend implements IChartPart, IHideable { ...@@ -111,7 +111,7 @@ public class Legend implements IChartPart, IHideable {
int xOffset = chart.width - legendBoxWidth - Chart.CHART_PADDING; int xOffset = chart.width - legendBoxWidth - Chart.CHART_PADDING;
int yOffset = (int) ((chart.height - legendBoxHeight) / 2.0 + chart.chartTitle.getBounds().getY() + chart.chartTitle.getBounds().getHeight()); int yOffset = (int) ((chart.height - legendBoxHeight) / 2.0 + chart.chartTitle.getBounds().getY() + chart.chartTitle.getBounds().getHeight());
g.setColor(chart.bordersColor); g.setColor(chart.getStyleManager().getBordersColor());
g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight); g.drawRect(xOffset, yOffset, legendBoxWidth, legendBoxHeight);
g.setColor(backgroundColor); g.setColor(backgroundColor);
g.fillRect(xOffset + 1, yOffset + 1, legendBoxWidth - 1, legendBoxHeight - 1); g.fillRect(xOffset + 1, yOffset + 1, legendBoxWidth - 1, legendBoxHeight - 1);
...@@ -134,7 +134,7 @@ public class Legend implements IChartPart, IHideable { ...@@ -134,7 +134,7 @@ public class Legend implements IChartPart, IHideable {
} }
// paint series name // paint series name
g.setColor(chart.fontColor); g.setColor(chart.getStyleManager().getFontColor());
TextLayout layout = new TextLayout(series.name, font, new FontRenderContext(null, true, false)); 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)); layout.draw(g, (float) (startx + Marker.SIZE + (Marker.SIZE * 1.5) + LEGEND_PADDING), (starty + Marker.SIZE));
starty = starty + legendTextContentMaxHeight + LEGEND_PADDING; starty = starty + legendTextContentMaxHeight + LEGEND_PADDING;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment