001: /***********************************************************************************************
002: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003: *
004: * Redistribution and use of this software and associated documentation ("Software"), with or
005: * without modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain copyright statements and notices.
008: * Redistributions must also contain a copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011: * conditions and the following disclaimer in the documentation and/or other materials
012: * provided with the distribution.
013: *
014: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015: * products derived from this Software without prior written permission of Nathaniel G.
016: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
017: *
018: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020: * registered trademark of Nathaniel G. Auvil.
021: *
022: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023: *
024: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033: ************************************************************************************************/package org.krysalis.jcharts.demo.swing;
034:
035: import org.krysalis.jcharts.chartData.ChartDataException;
036: import org.krysalis.jcharts.chartData.PieChartDataSet;
037: import org.krysalis.jcharts.properties.PropertyException;
038: import org.krysalis.jcharts.properties.PieChart2DProperties;
039: import org.krysalis.jcharts.properties.ChartProperties;
040: import org.krysalis.jcharts.properties.LegendProperties;
041: import org.krysalis.jcharts.nonAxisChart.PieChart2D;
042:
043: import javax.swing.*;
044: import java.awt.*;
045: import java.awt.event.WindowEvent;
046:
047: /*************************************************************************************
048: *
049: * @author Nathaniel Auvil
050: * @version $Id: SwingDemo.java,v 1.2 2003/08/14 00:26:21 nathaniel_auvil Exp $
051: ************************************************************************************/
052: public class SwingDemo extends JFrame {
053: private JPanel panel;
054:
055: private PieChart2DProperties pieChart2DProperties;
056: private LegendProperties legendProperties;
057: private ChartProperties chartProperties;
058:
059: /*******************************************************************************
060: *
061: ********************************************************************************/
062: public SwingDemo() throws ChartDataException, PropertyException {
063: initComponents();
064: }
065:
066: /*******************************************************************************
067: *
068: ********************************************************************************/
069: private void initComponents() {
070: this .setSize(500, 500);
071: this .panel = new JPanel(true);
072: this .panel.setSize(500, 500);
073: this .getContentPane().add(this .panel);
074:
075: this .pieChart2DProperties = new PieChart2DProperties();
076: this .legendProperties = new LegendProperties();
077: this .chartProperties = new ChartProperties();
078:
079: this .setVisible(true);
080:
081: addWindowListener(new java.awt.event.WindowAdapter() {
082: public void windowClosing(WindowEvent windowEvent) {
083: exitForm(windowEvent);
084: }
085: });
086: }
087:
088: /*********************************************************************************
089: *
090: * @param graphics
091: ********************************************************************************/
092: public void paint(Graphics graphics) {
093: try {
094: String[] labels = { "BMW", "Audi", "Lexus" };
095: String title = "Cars that Own";
096: Paint[] paints = { Color.blue, Color.gray, Color.red };
097: double[] data = { 50d, 30d, 20d };
098: PieChartDataSet pieChartDataSet = new PieChartDataSet(
099: title, data, labels, paints,
100: this .pieChart2DProperties);
101:
102: Dimension dimension = this .panel.getSize();
103: PieChart2D pieChart2D = new PieChart2D(pieChartDataSet,
104: this .legendProperties, this .chartProperties,
105: (int) dimension.getWidth(), (int) dimension
106: .getHeight());
107: pieChart2D.setGraphics2D((Graphics2D) this .panel
108: .getGraphics());
109: pieChart2D.render();
110: } catch (ChartDataException chartDataException) {
111: chartDataException.printStackTrace();
112: } catch (PropertyException propertyException) {
113: propertyException.printStackTrace();
114: }
115: }
116:
117: /*******************************************************************************
118: * Exit the Application
119: *
120: * @param windowEvent
121: ******************************************************************************/
122: private void exitForm(WindowEvent windowEvent) {
123: System.exit(0);
124: }
125:
126: /******************************************************************************
127: *
128: ******************************************************************************/
129: public static void main(String args[]) throws ChartDataException,
130: PropertyException {
131: new SwingDemo();
132: }
133:
134: }
|