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

📄 chartcomposite.java

📁 提供JFreechart图表功能, 提供JFreechart图表功能,提供JFreechart图表功能
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. * * Project Info:  http://www.jfree.org/jfreechart/index.html * * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,  * USA.   * * [Java is a trademark or registered trademark of Sun Microsystems, Inc.  * in the United States and other countries.] * * ------------------- * ChartComposite.java * ------------------- * (C) Copyright 2006, 2007, by Henry Proudhon and Contributors. * * Original Author:  Henry Proudhon (henry.proudhon AT ensmp.fr); * Contributor(s):   David Gilbert (for Object Refinery Limited); *                   Cedric Chabanois (cchabanois AT no-log.org); *                   Christoph Beck; * * Changes * ------- * 19-Jun-2006 : New class (HP); * 06-Nov-2006 : Added accessor methods for zoomInFactor and zoomOutFactor (DG); * 28-Nov-2006 : Added support for trace lines (HP); * 30-Nov-2006 : Improved zoom box handling (HP); * 06-Dec-2006 : Added (simplified) tool tip support (HP); * 11-Dec-2006 : Fixed popup menu location by fgiust, bug 1612770 (HP); * 31-Jan-2007 : Fixed some issues with the trace lines, fixed cross hair not  *               being drawn, added getter and setter methods for the trace  *               lines (HP);  * 07-Apr-2007 : Changed this.redraw() into canvas.redraw() to fix redraw  *               problems (HP); * 19-May-2007 : Small fix in paintControl to check for null charts, bug  *               1719260 (HP); * 19-May-2007 : Corrected bug with scaling when the drawing region is larger  *               than maximum draw width/height (HP); * 23-May-2007 : Added some dispose call to free SWT resources, patch sent by  *               Cédric Chabanois (CC); * 06-Jun-2007 : Fixed minor issues with tooltips. bug reported and fix  *               proposed by Christoph Beck, bug 1726404 (HP); * 22-Oct-2007 : Added addChartMouseListener and removeChartMouseListener  *               methods as suggested by Christoph Beck, bug 1742002 (HP); * 22-Oct-2007 : Fixed bug in zooming with multiple plots (HP); * 22-Oct-2007 : Check for null zoom point when restoring auto range and domain *               bounds (HP); * 22-Oct-2007 : Pass mouse moved events to listening ChartMouseListeners (HP); * 22-Oct-2007 : Refactored class, now implements PaintListener, MouseListener,  *               MouseMoveListener. Made the chart field be private again and  *               added new method addSWTListener to allow custom behavior. * 14-Nov-2007 : Create canvas with SWT.DOUBLE_BUFFER, added  *               getChartRenderingInfo(), is/setDomainZoomable() and  *               is/setRangeZoomable() as per feature request (DG); */package org.jfree.experimental.chart.swt;import java.awt.Graphics;import java.awt.Point;import java.awt.RenderingHints;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.awt.print.PageFormat;import java.awt.print.Printable;import java.awt.print.PrinterException;import java.awt.print.PrinterJob;import java.io.File;import java.io.IOException;import java.util.ResourceBundle;import javax.swing.event.EventListenerList;import org.eclipse.swt.SWT;import org.eclipse.swt.events.ControlListener;import org.eclipse.swt.events.DisposeListener;import org.eclipse.swt.events.FocusListener;import org.eclipse.swt.events.HelpListener;import org.eclipse.swt.events.KeyListener;import org.eclipse.swt.events.MouseEvent;import org.eclipse.swt.events.MouseListener;import org.eclipse.swt.events.MouseMoveListener;import org.eclipse.swt.events.MouseTrackListener;import org.eclipse.swt.events.PaintEvent;import org.eclipse.swt.events.PaintListener;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.events.SelectionListener;import org.eclipse.swt.events.TraverseListener;import org.eclipse.swt.graphics.GC;import org.eclipse.swt.graphics.Rectangle;import org.eclipse.swt.internal.SWTEventListener;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.widgets.Canvas;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Event;import org.eclipse.swt.widgets.FileDialog;import org.eclipse.swt.widgets.Menu;import org.eclipse.swt.widgets.MenuItem;import org.eclipse.swt.widgets.MessageBox;import org.jfree.chart.ChartMouseEvent;import org.jfree.chart.ChartMouseListener;import org.jfree.chart.ChartRenderingInfo;import org.jfree.chart.ChartUtilities;import org.jfree.chart.JFreeChart;import org.jfree.chart.entity.ChartEntity;import org.jfree.chart.entity.EntityCollection;import org.jfree.chart.event.ChartChangeEvent;import org.jfree.chart.event.ChartChangeListener;import org.jfree.chart.event.ChartProgressEvent;import org.jfree.chart.event.ChartProgressListener;import org.jfree.chart.plot.Plot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.plot.PlotRenderingInfo;import org.jfree.chart.plot.ValueAxisPlot;import org.jfree.chart.plot.Zoomable;import org.jfree.experimental.chart.swt.editor.SWTChartEditor;import org.jfree.experimental.swt.SWTGraphics2D;import org.jfree.experimental.swt.SWTUtils;/** * A SWT GUI composite for displaying a {@link JFreeChart} object. * <p> * The composite listens to the chart to receive notification of changes to any * component of the chart.  The chart is redrawn automatically whenever this  * notification is received. */public class ChartComposite extends Composite implements ChartChangeListener,                                                         ChartProgressListener,                                                         PaintListener,                                                         SelectionListener,                                                         MouseListener,                                                         MouseMoveListener,                                                         Printable{    /** Default setting for buffer usage. */    public static final boolean DEFAULT_BUFFER_USED = false;    /** The default panel width. */    public static final int DEFAULT_WIDTH = 680;    /** The default panel height. */    public static final int DEFAULT_HEIGHT = 420;    /** The default limit below which chart scaling kicks in. */    public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;    /** The default limit below which chart scaling kicks in. */    public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;    /** The default limit below which chart scaling kicks in. */    public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;    /** The default limit below which chart scaling kicks in. */    public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;    /** The minimum size required to perform a zoom on a rectangle */    public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;    /** Properties action command. */    public static final String PROPERTIES_COMMAND = "PROPERTIES";    /** Save action command. */    public static final String SAVE_COMMAND = "SAVE";    /** Print action command. */    public static final String PRINT_COMMAND = "PRINT";    /** Zoom in (both axes) action command. */    public static final String ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";    /** Zoom in (domain axis only) action command. */    public static final String ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";    /** Zoom in (range axis only) action command. */    public static final String ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";    /** Zoom out (both axes) action command. */    public static final String ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";    /** Zoom out (domain axis only) action command. */    public static final String ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";    /** Zoom out (range axis only) action command. */    public static final String ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";    /** Zoom reset (both axes) action command. */    public static final String ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";    /** Zoom reset (domain axis only) action command. */    public static final String ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";    /** Zoom reset (range axis only) action command. */    public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";    /** The chart that is displayed in the panel. */    private JFreeChart chart;    /** The canvas to display the chart. */    private Canvas canvas;        /** Storage for registered (chart) mouse listeners. */    private EventListenerList chartMouseListeners;    /** A flag that controls whether or not the off-screen buffer is used. */    private boolean useBuffer;    /** A flag that indicates that the buffer should be refreshed. */    private boolean refreshBuffer;    /** A flag that indicates that the tooltips should be displayed. */    private boolean displayToolTips;    /** A buffer for the rendered chart. */    private org.eclipse.swt.graphics.Image chartBuffer;    /** The height of the chart buffer. */    private int chartBufferHeight;    /** The width of the chart buffer. */    private int chartBufferWidth;    /**      * The minimum width for drawing a chart (uses scaling for smaller widths).      */    private int minimumDrawWidth;    /**      * The minimum height for drawing a chart (uses scaling for smaller      * heights).      */    private int minimumDrawHeight;    /**      * The maximum width for drawing a chart (uses scaling for bigger      * widths).      */    private int maximumDrawWidth;    /**      * The maximum height for drawing a chart (uses scaling for bigger      * heights).      */    private int maximumDrawHeight;    /** The popup menu for the frame. */    private Menu popup;    /** The drawing info collected the last time the chart was drawn. */    private ChartRenderingInfo info;        /** The chart anchor point. */    private Point2D anchor;    /** The scale factor used to draw the chart. */    private double scaleX;    /** The scale factor used to draw the chart. */    private double scaleY;    /** The plot orientation. */    private PlotOrientation orientation = PlotOrientation.VERTICAL;        /** A flag that controls whether or not domain zooming is enabled. */    private boolean domainZoomable = false;    /** A flag that controls whether or not range zooming is enabled. */    private boolean rangeZoomable = false;    /**      * The zoom rectangle starting point (selected by the user with a mouse      * click).  This is a point on the screen, not the chart (which may have     * been scaled up or down to fit the panel).       */    private org.eclipse.swt.graphics.Point zoomPoint = null;    /** The zoom rectangle (selected by the user with the mouse). */    private transient Rectangle zoomRectangle = null;    /** Controls if the zoom rectangle is drawn as an outline or filled. */    //TODO private boolean fillZoomRectangle = true;    /** The minimum distance required to drag the mouse to trigger a zoom. */    private int zoomTriggerDistance;        /** A flag that controls whether or not horizontal tracing is enabled. */    private boolean horizontalAxisTrace = false;    /** A flag that controls whether or not vertical tracing is enabled. */    private boolean verticalAxisTrace = false;    /** A vertical trace line. */    private transient int verticalTraceLineX;    /** A horizontal trace line. */    private transient int horizontalTraceLineY;    /** Menu item for zooming in on a chart (both axes). */    private MenuItem zoomInBothMenuItem;    /** Menu item for zooming in on a chart (domain axis). */    private MenuItem zoomInDomainMenuItem;    /** Menu item for zooming in on a chart (range axis). */    private MenuItem zoomInRangeMenuItem;    /** Menu item for zooming out on a chart. */    private MenuItem zoomOutBothMenuItem;    /** Menu item for zooming out on a chart (domain axis). */    private MenuItem zoomOutDomainMenuItem;    /** Menu item for zooming out on a chart (range axis). */    private MenuItem zoomOutRangeMenuItem;    /** Menu item for resetting the zoom (both axes). */    private MenuItem zoomResetBothMenuItem;    /** Menu item for resetting the zoom (domain axis only). */    private MenuItem zoomResetDomainMenuItem;    /** Menu item for resetting the zoom (range axis only). */    private MenuItem zoomResetRangeMenuItem;    /** A flag that controls whether or not file extensions are enforced. */    private boolean enforceFileExtensions;    /** The factor used to zoom in on an axis range. */    private double zoomInFactor = 0.5;        /** The factor used to zoom out on an axis range. */    private double zoomOutFactor = 2.0;        /** The resourceBundle for the localization. */    protected static ResourceBundle localizationResources         = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");    /**     * Create a new chart composite with a default FillLayout.      * This way, when drawn, the chart will fill all the space.     * @param comp The parent.

⌨️ 快捷键说明

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