Example usage for org.jfree.chart JFreeChart getAntiAlias

List of usage examples for org.jfree.chart JFreeChart getAntiAlias

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getAntiAlias.

Prototype

public boolean getAntiAlias() 

Source Link

Document

Returns a flag that indicates whether or not anti-aliasing is used when the chart is drawn.

Usage

From source file:daylightchart.options.chart.ChartOptions.java

/**
 * {@inheritDoc}//w w w.  jav  a  2  s  .co  m
 *
 * @see BaseChartOptions#copyFromChart(org.jfree.chart.JFreeChart)
 */
@Override
public void copyFromChart(final JFreeChart chart) {
    antiAlias = chart.getAntiAlias();
    backgroundPaint = chart.getBackgroundPaint();
    //
    plotOptions.copyFromChart(chart);
    titleOptions.copyFromChart(chart);
}

From source file:electroStaticUI.Save.java

/**
  * Save chart as SVG file.//from   w ww .  ja  va2s  . c  om
  * Required libs: Apache Batik (batik-svggen.jar, batik-dom.jar, dom.jar).
  *
  * @param chart JFreeChart to save.
  * @param fileName Name of file to save chart in.
  * @param width Width of chart graphic.
  * @param height Height of chart graphic.
  * @return Final file name used.
  * @throws IOException if failed.
  * 
  * To Do: Add a save/open method for saving a file native to this application. It should save the users current charge distribution 
  * to be re-loaded at a later time.
  */

static public final String saveChartToSVG(final JFreeChart chart, String fileName, final int width,
        final int height) throws IOException {
    String result = null;

    if (chart != null) {
        if (fileName == null) {
            final String chartTitle = chart.getTitle().getText();
            if (chartTitle != null) {
                fileName = chartTitle;
            } else {
                fileName = "chart";
            }
        }
        result = fileName + ".svg";

        final DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
        final Document document = domImpl.createDocument(null, "svg", null);
        final SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

        //            svgGenerator.getGeneratorContext().setEmbeddedFontsOn(true); //embed fonts

        //set anti-aliasing bug fix for SVG generator:
        //setting rendering hints of svgGenerator doesn't help as it seems to use the rendering hints from the chart
        final boolean antiAlias = chart.getAntiAlias();
        final RenderingHints rh = chart.getRenderingHints();

        if (antiAlias) {
            rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); //fix
        } else {
            rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
            rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); //fix
        }

        //            svgGenerator.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        //            svgGenerator.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        //            svgGenerator.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        //            svgGenerator.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        //            svgGenerator.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        //            svgGenerator.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);

        chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), new ChartRenderingInfo());

        //undo anti-aliasing bugfix settings for chart to use correct settings:
        if (antiAlias) {
            rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        } else {
            rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
            rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        }

        final boolean useCSS = true;
        Writer out = null;
        try {
            out = new OutputStreamWriter(
                    new BufferedOutputStream(new FileOutputStream(new File(result), false)), "iso-8859-1"); //UTF-8
            svgGenerator.stream(out, useCSS);
        } finally {
            svgGenerator.dispose();
            IOUtils.closeQuietly(out);
        }
    } //else: input unavailable

    return result;
}

From source file:org.jfree.experimental.chart.swt.editor.SWTOtherEditor.java

/**
 * Creates a new instance.//  www.ja va 2s . c om
 * 
 * @param parent  the parent.
 * @param style  the style.
 * @param chart  the chart.
 */
public SWTOtherEditor(Composite parent, int style, JFreeChart chart) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));

    // row 1: antialiasing
    this.antialias = new Button(general, SWT.CHECK);
    this.antialias.setText(localizationResources.getString("Draw_anti-aliased"));
    this.antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    this.antialias.setSelection(chart.getAntiAlias());

    //row 2: background paint for the chart
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTOtherEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTOtherEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
}

From source file:com.rcp.wbw.demo.editor.SWTOtherEditor.java

/**
 * Creates a new instance.//from w  w  w .  j a  va2  s .  com
 * 
 * @param parent
 *            the parent.
 * @param style
 *            the style.
 * @param chart
 *            the chart.
 */
public SWTOtherEditor(Composite parent, int style, JFreeChart chart) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    general.setLayout(new GridLayout(3, false));
    general.setText(localizationResources.getString("General"));

    // row 1: antialiasing
    this.antialias = new Button(general, SWT.CHECK);
    this.antialias.setText(localizationResources.getString("Draw_anti-aliased"));
    this.antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    this.antialias.setSelection(chart.getAntiAlias());

    // row 2: background paint for the chart
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTOtherEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTOtherEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
}

From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java

public void saveChartProperties(Report report) {
    JFreeChart chart = chartComposite.getChart();
    if (chart != null) {
        Map<String, Object> properties = new HashMap<>();
        TextTitle title = chart.getTitle();
        if (title != null) {
            properties.put(TITLE, title.getText());
            properties.put(TITLEFONT, title.getFont());
            properties.put(TITLECOLOR, title.getPaint());
        }/*w  ww. j a  v a2s . c om*/
        Plot plot = chart.getPlot();
        properties.put(BGCOLOR, plot.getBackgroundPaint());
        properties.put(OUTLINEPAINT, plot.getOutlinePaint());
        properties.put(OUTLINESTROKE, plot.getOutlineStroke());
        Axis domainAxis = null;
        Axis rangeAxis = null;
        if (plot instanceof CategoryPlot) {
            CategoryPlot p = (CategoryPlot) plot;
            domainAxis = p.getDomainAxis();
            rangeAxis = p.getRangeAxis();
            properties.put(ORIENTATION, p.getOrientation());
        } else if (plot instanceof XYPlot) {
            XYPlot p = (XYPlot) plot;
            domainAxis = p.getDomainAxis();
            rangeAxis = p.getRangeAxis();
            properties.put(ORIENTATION, p.getOrientation());
        }
        if (domainAxis != null)
            saveAxisProperties(domainAxis, "x", properties); //$NON-NLS-1$
        if (rangeAxis != null)
            saveAxisProperties(rangeAxis, "y", properties); //$NON-NLS-1$
        properties.put(ANTIALIAS, chart.getAntiAlias());
        properties.put(CANVASPAINT, chart.getBackgroundPaint());
        report.setProperties(properties);
    }
}