List of usage examples for org.jfree.chart.title Title getPosition
public RectangleEdge getPosition()
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) { // g2.setPaint(Color.white); // g2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight())); // if (getChart() != null) { //// Image chartImage = getChart().createBufferedImage((int) area.getWidth(), //// (int) area.getHeight()); //// g2.drawImage(chartImage, (int) area.getMinX(), (int) area.getMinY(), //// this); // getChart().draw(g2, area, getAnchor(), null); // ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), maskList, // null, getChart()); // }//w ww . j a v a 2 s . co m double widthRatio = area.getWidth() / getWidth(); double heightRatio = area.getHeight() / getHeight(); double overallRatio = 1; overallRatio = widthRatio < heightRatio ? widthRatio : heightRatio; XYPlot plot = (XYPlot) getChart().getPlot(); Font domainFont = plot.getDomainAxis().getLabelFont(); int domainSize = domainFont.getSize(); Font rangeFont = plot.getRangeAxis().getLabelFont(); int rangeSize = rangeFont.getSize(); TextTitle titleBlock = getChart().getTitle(); Font titleFont = null; int titleSize = 0; if (titleBlock != null) { titleFont = titleBlock.getFont(); titleSize = titleFont.getSize(); getChart().getTitle().setFont(titleFont.deriveFont((float) (titleSize * overallRatio))); } Font domainScaleFont = plot.getDomainAxis().getTickLabelFont(); int domainScaleSize = domainScaleFont.getSize(); Font rangeScaleFont = plot.getRangeAxis().getTickLabelFont(); int rangeScaleSize = rangeScaleFont.getSize(); plot.getDomainAxis().setLabelFont(domainFont.deriveFont((float) (domainSize * overallRatio))); plot.getRangeAxis().setLabelFont(rangeFont.deriveFont((float) (rangeSize * overallRatio))); plot.getDomainAxis().setTickLabelFont(domainScaleFont.deriveFont((float) (domainScaleSize * overallRatio))); plot.getRangeAxis().setTickLabelFont(rangeScaleFont.deriveFont((float) (rangeScaleSize * overallRatio))); LegendTitle legend = getChart().getLegend(); Font legendFont = null; int legendFontSize = 0; if (legend != null) { legendFont = legend.getItemFont(); legendFontSize = legendFont.getSize(); legend.setItemFont(legendFont.deriveFont((float) (legendFontSize * overallRatio))); } Rectangle2D chartArea = (Rectangle2D) area.clone(); getChart().getPadding().trim(chartArea); if (titleBlock != null) { AxisUtilities.trimTitle(chartArea, g2, titleBlock, titleBlock.getPosition()); } Axis scaleAxis = null; Font scaleAxisFont = null; int scaleAxisFontSize = 0; for (Object object : getChart().getSubtitles()) { Title title = (Title) object; if (title instanceof PaintScaleLegend) { scaleAxis = ((PaintScaleLegend) title).getAxis(); scaleAxisFont = scaleAxis.getTickLabelFont(); scaleAxisFontSize = scaleAxisFont.getSize(); scaleAxis.setTickLabelFont(scaleAxisFont.deriveFont((float) (scaleAxisFontSize * overallRatio))); } AxisUtilities.trimTitle(chartArea, g2, title, title.getPosition()); } AxisSpace axisSpace = AxisUtilities.calculateAxisSpace(getChart().getXYPlot(), g2, chartArea); Rectangle2D dataArea = axisSpace.shrink(chartArea, null); getChart().getXYPlot().getInsets().trim(dataArea); getChart().getXYPlot().getAxisOffset().trim(dataArea); // Rectangle2D screenArea = getScreenDataArea(); // Rectangle2D visibleArea = getVisibleRect(); // Rectangle2D printScreenArea = new Rectangle2D.Double(screenArea.getMinX() * overallRatio + x, // screenArea.getMinY() * overallRatio + y, // printArea.getWidth() - visibleArea.getWidth() + screenArea.getWidth(), // printArea.getHeight() - visibleArea.getHeight() + screenArea.getHeight()); getChart().draw(g2, area, getAnchor(), null); ChartMaskingUtilities.drawMasks(g2, dataArea, maskList, null, getChart(), overallRatio); ChartMaskingUtilities.drawShapes(g2, dataArea, shapeMap, getChart()); ChartMaskingUtilities.drawText(g2, dataArea, textContentMap, getChart()); plot.getDomainAxis().setLabelFont(domainFont); plot.getRangeAxis().setLabelFont(rangeFont); if (titleBlock != null) { titleBlock.setFont(titleFont); } if (legend != null) { legend.setItemFont(legendFont); } plot.getDomainAxis().setTickLabelFont(domainScaleFont); plot.getRangeAxis().setTickLabelFont(rangeScaleFont); if (scaleAxis != null) { scaleAxis.setTickLabelFont(scaleAxisFont); } // System.out.println("print " + titleBlock.getText() + // " at [" + area.getX() + ", " + area.getY() + ", " + // area.getWidth() + ", " + area.getHeight() + "]"); }