Skip to content

Commit

Permalink
Chart axis and legend labels are now given a font size of 16.
Browse files Browse the repository at this point in the history
git-svn-id: file:///mnt/fast/tau2git/svnroot/trunk/tau2@7178 a8e31b63-e6ca-409b-a01b-2eec1b506579
  • Loading branch information
wspear committed May 6, 2009
1 parent 4a572b3 commit 132f62f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tools/src/common/src/Utility.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package edu.uoregon.tau.common;

import java.awt.Color;
import java.awt.Font;
import java.net.URL;

import javax.swing.ImageIcon;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.Axis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.LegendTitle;

public class Utility {

Expand All @@ -33,22 +36,49 @@ public static URL getResource(String name) {
return url;
}

/**
* Applies default chart fonts and chart color settings
* @param chart
*/
public static void applyDefaultChartTheme(JFreeChart chart) {
chart.setBackgroundPaint(new Color(238, 238, 238));

//Set legend label font size to 16
LegendTitle l = chart.getLegend();
l.setItemFont(new Font(null, Font.PLAIN,16));

Plot plot = chart.getPlot();

plot.setBackgroundPaint(Color.white);
if (plot instanceof XYPlot) {
XYPlot xyplot = (XYPlot) plot;

setAxisFont(xyplot.getRangeAxis());
setAxisFont(xyplot.getDomainAxis());

xyplot.setDomainGridlinePaint(Color.gray);
xyplot.setDomainMinorGridlinePaint(Color.gray);
xyplot.setRangeGridlinePaint(Color.gray);
xyplot.setRangeMinorGridlinePaint(Color.gray);
} else if (plot instanceof CategoryPlot) {
CategoryPlot cplot = (CategoryPlot) plot;

setAxisFont(cplot.getRangeAxis());
setAxisFont(cplot.getDomainAxis());

cplot.setBackgroundPaint(Color.white);
cplot.setDomainGridlinePaint(Color.gray);
cplot.setRangeGridlinePaint(Color.gray);
}
}

/**
* Sets the font size for the given axis to 16
* @param axis
*/
private static void setAxisFont(Axis axis){
Font f = axis.getLabelFont();
f=f.deriveFont((float) 16.0);
axis.setLabelFont(f);
}
}

0 comments on commit 132f62f

Please sign in to comment.