⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jfreechartdemo.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ======================================
 * JFreeChart : a free Java chart library
 * ======================================
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 * Project Lead:  David Gilbert (david.gilbert@object-refinery.com);
 *
 * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * -------------------
 * JFreeChartDemo.java
 * -------------------
 * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   Andrzej Porebski;
 *                   Matthew Wright;
 *                   Serge V. Grachov;
 *                   Bill Kelemen;
 *                   Achilleus Mantzios;
 *                   Bryan Scott;
 *
 * $Id: JFreeChartDemo.java,v 1.4 2003/06/12 16:54:03 mungady Exp $
 *
 * Changes (from 22-Jun-2001)
 * --------------------------
 * 22-Jun-2001 : Modified to use new title code (DG);
 * 23-Jun-2001 : Added null data source chart (DG);
 * 24-Aug-2001 : Fixed DOS encoding problem (DG);
 * 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG);
 * 19-Oct-2001 : Implemented new ChartFactory class (DG);
 * 22-Oct-2001 : Added panes for stacked bar charts and a scatter plot (DG);
 *               Renamed DataSource.java --> Dataset.java etc. (DG);
 * 31-Oct-2001 : Added some negative values to the sample CategoryDataset (DG);
 *               Added 3D-effect bar plots by Serge V. Grachov (DG);
 * 07-Nov-2001 : Separated the JCommon Class Library classes, JFreeChart now
 *               requires jcommon.jar (DG);
 *               New flag in ChartFactory to control whether or not a legend is
 *               added to the chart (DG);
 * 15-Nov-2001 : Changed TimeSeriesDataset to TimeSeriesCollection (DG);
 * 17-Nov-2001 : For pie chart, changed dataset from CategoryDataset to PieDataset (DG);
 * 26-Nov-2001 : Moved property editing, saving and printing to the JFreeChartPanel class (DG);
 * 05-Dec-2001 : Added combined charts contributed by Bill Kelemen (DG);
 * 10-Dec-2001 : Updated exchange rate demo data, and included a demo chart that shows multiple
 *               time series together on one chart.  Removed some redundant code (DG);
 * 12-Dec-2001 : Added Candlestick chart (DG);
 * 23-Jan-2002 : Added a test chart for single series bar charts (DG);
 * 06-Feb-2002 : Added sample wind plot (DG);
 * 15-Mar-2002 : Now using ResourceBundle to fetch strings and other items displayed to the
 *               user.  This will allow for localisation (DG);
 * 09-Apr-2002 : Changed horizontal bar chart to use integer tick units (DG);
 * 19-Apr-2002 : Renamed JRefineryUtilities-->RefineryUtilities (DG);
 * 11-Jun-2002 : Changed createHorizontalStackedBarChart()
 *               --> createStackedHorizontalBarChart() for consistency (DG);
 * 25-Jun-2002 : Removed redundant code (DG);
 * 02-Jul-2002 : Added Gantt chart demo, based on GanttDemo (BRS)
 * 02-Jul-2002 : Added support for usage (null, All, Swing) in resource (BRS).
 * 27-Jul-2002 : Made Resourceclass string public (BRS).
 * 27-Jul-2002 : Move chart creation methods to JFreeChartDemoBase class to allow sharing
 *               with servlet.  Servlet cannot share this class as a number of headless
 *               exceptions are generated. (BRS).
 * 10-Oct-2002 : Fixed errors reported by Checkstyle (DG);
 *
 */

package org.jfree.chart.demo;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.layout.LCBLayout;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.about.AboutFrame;

/**
 * The main frame in the chart demonstration application.
 *
 * @author David Gilbert
 */
public class JFreeChartDemo extends JFrame implements ActionListener, WindowListener {

    /** Exit action command. */
    public static final String EXIT_COMMAND = "EXIT";

    /** About action command. */
    public static final String ABOUT_COMMAND = "ABOUT";

    /** The base demo class. */
    private static final JFreeChartDemoBase DEMO = new JFreeChartDemoBase();

    /** An array of chart commands. */
    private static final String[][] CHART_COMMANDS = JFreeChartDemoBase.CHART_COMMANDS;

    /** Localised resources. */
    private ResourceBundle resources;

    /** Chart frames. */
    private ChartFrame[] frame = new ChartFrame[CHART_COMMANDS.length];

    /** Panels. */
    private JPanel[] panels = null;

    /** The preferred size for the frame. */
    public static final Dimension PREFERRED_SIZE = new Dimension(780, 400);

    /** A frame for displaying information about the application. */
    private AboutFrame aboutFrame;

    /**
     * Constructs a demonstration application for the JFreeChart Class Library.
     */
    public JFreeChartDemo() {
        super(JFreeChart.INFO.getName() + " " + JFreeChart.INFO.getVersion() + " Demo");
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                dispose();
                System.exit(0);
            }
        });
        resources = DEMO.getResources();
        // set up the menu
        JMenuBar menuBar = createMenuBar(resources);
        setJMenuBar(menuBar);

        JPanel content = new JPanel(new BorderLayout());
        content.add(createTabbedPane(resources));
        setContentPane(content);

    }

    /**
     * Returns the preferred size for the frame.
     *
     * @return the preferred size.
     */
    public Dimension getPreferredSize() {
        return PREFERRED_SIZE;
    }

    /**
     * Handles menu selections by passing control to an appropriate method.
     *
     * @param event  the event.
     */
    public void actionPerformed(ActionEvent event) {

        String command = event.getActionCommand();
        if (command.equals(EXIT_COMMAND)) {
            attemptExit();
        }
        else if (command.equals(ABOUT_COMMAND)) {
            about();
        }
        else {
            /// Loop through available commands to find index to current command.
            int chartnum = -1;
            int i = CHART_COMMANDS.length;
            while (i > 0) {
                --i;
                if (command.equals(CHART_COMMANDS[i][0])) {
                    chartnum = i;
                    i = 0;
                }
            }

            /// check our index is valid
            if ((chartnum >= 0) && (chartnum < frame.length)) {
                /// Check we have not already created chart.
                if (frame[chartnum] == null) {
                    // setup the chart.
                    DEMO.getChart(chartnum);

                    // present it in a frame...
                    String str = resources.getString(CHART_COMMANDS[chartnum][2] + ".title");
                    frame[chartnum] = new ChartFrame(str, DEMO.getChart(chartnum));
                    frame[chartnum].getChartPanel().setPreferredSize(
                                                        new java.awt.Dimension(500, 270));
                    frame[chartnum].pack();
                    RefineryUtilities.positionFrameRandomly(frame[chartnum]);

                    /// Set panel to zoomable if required
                    try {
                        str = resources.getString(CHART_COMMANDS[chartnum][2] + ".zoom");
                        if ((str != null) && (str.toLowerCase().equals("true"))) {
                            ChartPanel panel =  frame[chartnum].getChartPanel();
                            panel.setMouseZoomable(true);
                            panel.setHorizontalAxisTrace(true);
                            panel.setVerticalAxisTrace(true);
                        }
                    }
                    catch (Exception ex) {
                        /// Filter out messages which for charts which do not have zoom
                        /// specified.
                        if (ex.getMessage().indexOf("MissingResourceException") == 0) {
                            ex.printStackTrace();
                        }
                    }

                    frame[chartnum].show();

                }
                else {
                    frame[chartnum].show();
                    frame[chartnum].requestFocus();
                }
            }
        }
    }

    /**
     * Exits the application, but only if the user agrees.
     */
    private void attemptExit() {

        String title = resources.getString("dialog.exit.title");
        String message = resources.getString("dialog.exit.message");
        int result = JOptionPane.showConfirmDialog(this, message, title,
                                                   JOptionPane.YES_NO_OPTION,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -