001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
006     *
007     * Project Info:  http://www.jfree.org/jfreechart/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it 
010     * under the terms of the GNU Lesser General Public License as published by 
011     * the Free Software Foundation; either version 2.1 of the License, or 
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but 
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022     * USA.  
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025     * in the United States and other countries.]
026     *
027     * ---------------------
028     * SWTPieChartDemo1.java
029     * ---------------------
030     * (C) Copyright 2006, by Object Refinery Limited and Contributors.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):
034     *
035     * Changes
036     * -------
037     * 23-Aug-2006 : New class (DG);
038     * 
039     */
040    
041    package org.jfree.experimental.chart.swt.demo;
042    
043    import java.awt.Font;
044    
045    import org.eclipse.swt.SWT;
046    import org.eclipse.swt.layout.FillLayout;
047    import org.eclipse.swt.widgets.Display;
048    import org.eclipse.swt.widgets.Shell;
049    import org.jfree.chart.ChartFactory;
050    import org.jfree.chart.JFreeChart;
051    import org.jfree.chart.plot.PiePlot;
052    import org.jfree.data.general.DefaultPieDataset;
053    import org.jfree.data.general.PieDataset;
054    import org.jfree.experimental.chart.swt.ChartComposite;
055    
056    /**
057     * This demo shows a time series chart that has multiple range axes.
058     */
059    public class SWTPieChartDemo1 {
060        
061        /**
062         * Creates a sample dataset.
063         * 
064         * @return A sample dataset.
065         */
066        private static PieDataset createDataset() {
067            DefaultPieDataset dataset = new DefaultPieDataset();
068            dataset.setValue("One", new Double(43.2));
069            dataset.setValue("Two", new Double(10.0));
070            dataset.setValue("Three", new Double(27.5));
071            dataset.setValue("Four", new Double(17.5));
072            dataset.setValue("Five", new Double(11.0));
073            dataset.setValue("Six", new Double(19.4));
074            return dataset;        
075        }
076        
077        /**
078         * Creates a chart.
079         * 
080         * @param dataset  the dataset.
081         * 
082         * @return A chart.
083         */
084        private static JFreeChart createChart(PieDataset dataset) {
085            
086            JFreeChart chart = ChartFactory.createPieChart(
087                "Pie Chart Demo 1",  // chart title
088                dataset,             // data
089                true,               // include legend
090                true,
091                false
092            );
093    
094            PiePlot plot = (PiePlot) chart.getPlot();
095            plot.setSectionOutlinesVisible(false);
096            plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
097            plot.setNoDataMessage("No data available");
098            plot.setCircular(false);
099            plot.setLabelGap(0.02);
100            return chart;
101            
102        }
103        
104        /**
105         * Starting point for the demonstration application.
106         *
107         * @param args  ignored.
108         */
109        public static void main( String[] args ) 
110        {
111            JFreeChart chart = createChart(createDataset());
112            Display display = new Display();
113            Shell shell = new Shell(display);
114            shell.setSize(600, 400);
115            shell.setLayout(new FillLayout());
116            shell.setText("Test for jfreechart running with SWT");
117            final ChartComposite frame = new ChartComposite(shell, SWT.NONE, chart, true);
118            //frame.setDisplayToolTips(false);
119            frame.pack();
120            shell.open();
121            while (!shell.isDisposed()) {
122                if (!display.readAndDispatch())
123                    display.sleep();
124            }
125        }
126    
127    }
128