Java源码示例:org.jfree.chart.block.BlockFrame
示例1
/**
* Draws the block within the specified area.
*
* @param g2 the graphics device.
* @param area the area.
* @param params ignored (<code>null</code> permitted).
*
* @return An {@link org.jfree.chart.block.EntityBlockResult} or
* <code>null</code>.
*/
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
Rectangle2D target = (Rectangle2D) area.clone();
target = trimMargin(target);
if (this.backgroundPaint != null) {
g2.setPaint(this.backgroundPaint);
g2.fill(target);
}
BlockFrame border = getFrame();
border.draw(g2, target);
border.getInsets().trim(target);
BlockContainer container = this.wrapper;
if (container == null) {
container = this.items;
}
target = trimPadding(target);
return container.draw(g2, target, params);
}
示例2
@Override
public BlockFrame getBlockFrame()
{
RectangleInsets borderInsets = insets == null ? new RectangleInsets(1.0, 1.0, 1.0, 1.0) : insets;
Stroke borderStroke = lineStroke == null ? new BasicStroke(1.0f) : lineStroke;
Paint borderPaint = paint == null ? null : paint.getPaint();
if (borderPaint == null)
{
borderPaint = Color.BLACK;
}
return new LineBorder(borderPaint, borderStroke, borderInsets);
}
示例3
protected void setChartLegend(JFreeChart jfreeChart, Integer baseFontSize)
{
//The legend visibility is already taken into account in the jfreeChart object's constructor
LegendTitle legend = jfreeChart.getLegend();
if (legend != null)
{
Font themeLegendFont = getFont((JRFont)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FONT), getChart().getLegendFont(), baseFontSize);
legend.setItemFont(themeLegendFont);
Color legendForecolor = getChart().getOwnLegendColor() != null ?
getChart().getOwnLegendColor() :
(getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) != null ?
(Color)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FORECOLOR) :
getChart().getLegendColor());
if (legendForecolor != null)
legend.setItemPaint(legendForecolor);
Color legendBackcolor = getChart().getOwnLegendBackgroundColor() != null ?
getChart().getOwnLegendBackgroundColor() :
(getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) != null ?
(Color)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_BACKCOLOR) :
getChart().getLegendBackgroundColor());
if (legendBackcolor != null)
legend.setBackgroundPaint(legendBackcolor);
BlockFrame frame = (BlockFrame)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_FRAME);
if (frame != null)
legend.setFrame(frame);
HorizontalAlignment defaultLegendHAlignment = (HorizontalAlignment)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_HORIZONTAL_ALIGNMENT);
if (defaultLegendHAlignment != null)
legend.setHorizontalAlignment(defaultLegendHAlignment);
VerticalAlignment defaultLegendVAlignment = (VerticalAlignment)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_VERTICAL_ALIGNMENT);
if (defaultLegendVAlignment != null)
legend.setVerticalAlignment(defaultLegendVAlignment);
RectangleInsets defaultLegendPadding = (RectangleInsets)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_PADDING);
RectangleInsets legendPadding = legend.getPadding() != null ? legend.getPadding() : defaultLegendPadding;
if (legendPadding != null)
legend.setPadding(legendPadding);
RectangleEdge defaultLegendPosition = (RectangleEdge)getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.LEGEND_POSITION);
if (getEdge(getChart().getLegendPositionValue(), defaultLegendPosition) != null)
legend.setPosition(getEdge(getChart().getLegendPositionValue(), defaultLegendPosition));
}
}
示例4
public BlockFrameWrapper(BlockFrame blockFrame)
{
this.blockFrame = blockFrame;
}
示例5
@Override
public BlockFrame getBlockFrame()
{
return blockFrame;
}
示例6
public void setBlockFrame(BlockFrame blockFrame)
{
this.blockFrame = blockFrame;
}
示例7
/**
* @return the blockFrame
*/
public BlockFrame getBlockFrame() {
return frame == null ? null : frame.getBlockFrame();
}
示例8
/**
* @param blockFrame the blockFrame to set
* @deprecated replaced by {@link #setFrame(BlockFrameProvider)}
*/
@Deprecated
public void setBlockFrame(BlockFrame blockFrame) {
BlockFrameWrapper frameProvider = new BlockFrameWrapper(blockFrame);
setFrame(frameProvider);
}
示例9
protected void setChartLegend(JFreeChart jfreeChart)
{
//The legend visibility is already taken into account in the jfreeChart object's constructor
LegendTitle legend = jfreeChart.getLegend();
if (legend != null)
{
LegendSettings legendSettings = getLegendSettings();
JRBaseFont font = new JRBaseFont();
FontUtil.copyNonNullOwnProperties(legendSettings.getFont(), font);
FontUtil.copyNonNullOwnProperties(getChart().getLegendFont(), font);
font = new JRBaseFont(getChart(), font);
legend.setItemFont(getFontUtil().getAwtFont(font, getLocale()));
Paint forePaint = getChart().getOwnLegendColor();
if (forePaint == null && legendSettings.getForegroundPaint() != null)
{
forePaint = legendSettings.getForegroundPaint().getPaint();
}
if (forePaint == null)
{
forePaint = getChart().getLegendColor();
}
if (forePaint != null)
legend.setItemPaint(forePaint);
Paint backPaint = getChart().getOwnLegendBackgroundColor();
if (backPaint == null && legendSettings.getBackgroundPaint() != null)
{
backPaint = legendSettings.getBackgroundPaint().getPaint();
}
if (backPaint == null)
{
backPaint = getChart().getLegendBackgroundColor();
}
if (backPaint != null)
legend.setBackgroundPaint(backPaint);
BlockFrame blockFrame = legendSettings.getBlockFrame();
if (blockFrame != null)
legend.setFrame(blockFrame);
HorizontalAlignment hAlign = legendSettings.getHorizontalAlignment();
if (hAlign != null)
legend.setHorizontalAlignment(hAlign);
VerticalAlignment vAlign = legendSettings.getVerticalAlignment();
if (vAlign != null)
legend.setVerticalAlignment(vAlign);
RectangleInsets padding = legendSettings.getPadding();
if (padding != null)
legend.setPadding(padding);
legend.setPosition(
getEdge(
getChart().getLegendPositionValue(),
getEdge(
legendSettings.getPositionValue() ,
RectangleEdge.BOTTOM
)
)
);
}
}
示例10
/**
* Writes the current chart to the specified file in PDF format. This
* will only work when the OrsonPDF library is found on the classpath.
* Reflection is used to ensure there is no compile-time dependency on
* OrsonPDF (which is non-free software).
*
* @param file
* the output file ({@code null} not permitted).
* @param params
* formating parameters.
*/
public void export(final File file, final Parameters params) {
ArgChecks.nullNotPermitted(file, "file");
final int w;
final int h;
if (params != null) {
w = Integer.parseInt(params.getAttribute("width"));
h = Integer.parseInt(params.getAttribute("height"));
} else {
w = this.getWidth();
h = this.getHeight();
}
// Chart formating
final TextTitle chartTitle = this.getChart().getTitle();
this.getChart().setTitle((String) null);
final BlockFrame legendFrame = this.getChart().getLegend().getFrame();
this.getChart().getLegend().setFrame(BlockBorder.NONE);
try {
// Export to pdf
final Class<?> pdfDocClass = Class.forName("com.orsonpdf.PDFDocument4Jamel");
final Object pdfDoc = pdfDocClass.newInstance();
final Method m = pdfDocClass.getMethod("createPage", Rectangle2D.class);
final Rectangle2D rect = new Rectangle(w, h);
final Object page = m.invoke(pdfDoc, rect);
final Method m2 = page.getClass().getMethod("getGraphics2D");
final Graphics2D g2 = (Graphics2D) m2.invoke(page);
g2.setRenderingHint(JFreeChart.KEY_SUPPRESS_SHADOW_GENERATION, true);
final Rectangle2D drawArea = new Rectangle2D.Double(0, 0, w, h);
this.getChart().draw(g2, drawArea);
final Method m3 = pdfDocClass.getMethod("setAuthor", String.class);
m3.invoke(pdfDoc, "Pascal Seppecher");
final Method m4 = pdfDocClass.getMethod("setCreator", String.class);
m4.invoke(pdfDoc, "Jamel v" + Jamel.getVersion());
final Method m5 = pdfDocClass.getMethod("setTitle", String.class);
m5.invoke(pdfDoc, chartTitle.getText());
final Method m6 = pdfDocClass.getMethod("writeToFile", File.class);
m6.invoke(pdfDoc, file);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException ex) {
throw new RuntimeException(ex);
}
// Chart unformating
this.getChart().setTitle(chartTitle);
this.getChart().getLegend().setFrame(legendFrame);
}
示例11
BlockFrame getBlockFrame();