chartpanel.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,880 行 · 第 1/5 页

JAVA
1,880
字号
    /** A flag that controls whether or not file extensions are enforced. */    private boolean enforceFileExtensions;    /** A flag that indicates if original tooltip delays are changed. */    private boolean ownToolTipDelaysActive;          /** Original initial tooltip delay of ToolTipManager.sharedInstance(). */    private int originalToolTipInitialDelay;    /** Original reshow tooltip delay of ToolTipManager.sharedInstance(). */    private int originalToolTipReshowDelay;      /** Original dismiss tooltip delay of ToolTipManager.sharedInstance(). */    private int originalToolTipDismissDelay;    /** Own initial tooltip delay to be used in this chart panel. */    private int ownToolTipInitialDelay;        /** Own reshow tooltip delay to be used in this chart panel. */    private int ownToolTipReshowDelay;      /** Own dismiss tooltip delay to be used in this chart panel. */    private int ownToolTipDismissDelay;        /** 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");    /**     * Constructs a panel that displays the specified chart.     *     * @param chart  the chart.     */    public ChartPanel(JFreeChart chart) {        this(            chart,            DEFAULT_WIDTH,            DEFAULT_HEIGHT,            DEFAULT_MINIMUM_DRAW_WIDTH,            DEFAULT_MINIMUM_DRAW_HEIGHT,            DEFAULT_MAXIMUM_DRAW_WIDTH,            DEFAULT_MAXIMUM_DRAW_HEIGHT,            DEFAULT_BUFFER_USED,            true,  // properties            true,  // save            true,  // print            true,  // zoom            true   // tooltips        );    }    /**     * Constructs a panel containing a chart.     *     * @param chart  the chart.     * @param useBuffer  a flag controlling whether or not an off-screen buffer     *                   is used.     */    public ChartPanel(JFreeChart chart, boolean useBuffer) {        this(chart,             DEFAULT_WIDTH,             DEFAULT_HEIGHT,             DEFAULT_MINIMUM_DRAW_WIDTH,             DEFAULT_MINIMUM_DRAW_HEIGHT,             DEFAULT_MAXIMUM_DRAW_WIDTH,             DEFAULT_MAXIMUM_DRAW_HEIGHT,             useBuffer,             true,  // properties             true,  // save             true,  // print             true,  // zoom             true   // tooltips             );    }    /**     * Constructs a JFreeChart panel.     *     * @param chart  the chart.     * @param properties  a flag indicating whether or not the chart property     *                    editor should be available via the popup menu.     * @param save  a flag indicating whether or not save options should be     *              available via the popup menu.     * @param print  a flag indicating whether or not the print option     *               should be available via the popup menu.     * @param zoom  a flag indicating whether or not zoom options should     *              be added to the popup menu.     * @param tooltips  a flag indicating whether or not tooltips should be     *                  enabled for the chart.     */    public ChartPanel(JFreeChart chart,                      boolean properties,                      boolean save,                      boolean print,                      boolean zoom,                      boolean tooltips) {        this(chart,             DEFAULT_WIDTH,             DEFAULT_HEIGHT,             DEFAULT_MINIMUM_DRAW_WIDTH,             DEFAULT_MINIMUM_DRAW_HEIGHT,             DEFAULT_MAXIMUM_DRAW_WIDTH,             DEFAULT_MAXIMUM_DRAW_HEIGHT,             DEFAULT_BUFFER_USED,             properties,             save,             print,             zoom,             tooltips             );    }    /**     * Constructs a JFreeChart panel.     *     * @param chart  the chart.     * @param width  the preferred width of the panel.     * @param height  the preferred height of the panel.     * @param minimumDrawWidth  the minimum drawing width.     * @param minimumDrawHeight  the minimum drawing height.     * @param maximumDrawWidth  the maximum drawing width.     * @param maximumDrawHeight  the maximum drawing height.     * @param useBuffer  a flag that indicates whether to use the off-screen     *                   buffer to improve performance (at the expense of      *                   memory).     * @param properties  a flag indicating whether or not the chart property     *                    editor should be available via the popup menu.     * @param save  a flag indicating whether or not save options should be     *              available via the popup menu.     * @param print  a flag indicating whether or not the print option     *               should be available via the popup menu.     * @param zoom  a flag indicating whether or not zoom options should be      *              added to the popup menu.     * @param tooltips  a flag indicating whether or not tooltips should be      *                  enabled for the chart.     */    public ChartPanel(JFreeChart chart,                      int width,                      int height,                      int minimumDrawWidth,                      int minimumDrawHeight,                      int maximumDrawWidth,                      int maximumDrawHeight,                      boolean useBuffer,                      boolean properties,                      boolean save,                      boolean print,                      boolean zoom,                      boolean tooltips) {        this.chart = chart;        this.chartMouseListeners = new java.util.ArrayList();        if (chart != null) {            chart.addChangeListener(this);            Plot plot = chart.getPlot();            this.domainZoomable = false;            this.rangeZoomable = false;            if (plot instanceof Zoomable) {                Zoomable z = (Zoomable) plot;                this.domainZoomable = z.isDomainZoomable();                this.rangeZoomable = z.isRangeZoomable();                this.orientation = z.getOrientation();            }        }        this.info = new ChartRenderingInfo();        setPreferredSize(new Dimension(width, height));        this.useBuffer = useBuffer;        this.refreshBuffer = false;        this.minimumDrawWidth = minimumDrawWidth;        this.minimumDrawHeight = minimumDrawHeight;        this.maximumDrawWidth = maximumDrawWidth;        this.maximumDrawHeight = maximumDrawHeight;        this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;        // set up popup menu...        this.popup = null;        if (properties || save || print || zoom) {            this.popup = createPopupMenu(properties, save, print, zoom);        }        enableEvents(AWTEvent.MOUSE_EVENT_MASK);        enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);        setDisplayToolTips(tooltips);        addMouseListener(this);        addMouseMotionListener(this);        this.enforceFileExtensions = true;        // initialize ChartPanel-specific tool tip delays with        // values the from ToolTipManager.sharedInstance()        ToolTipManager ttm = ToolTipManager.sharedInstance();               this.ownToolTipInitialDelay = ttm.getInitialDelay();        this.ownToolTipDismissDelay = ttm.getDismissDelay();        this.ownToolTipReshowDelay = ttm.getReshowDelay();    }    /**     * Returns the chart contained in the panel.     *     * @return The chart (possibly <code>null</code>).     */    public JFreeChart getChart() {        return this.chart;    }    /**     * Sets the chart that is displayed in the panel.     *     * @param chart  the chart (<code>null</code> permitted).     */    public void setChart(JFreeChart chart) {        // stop listening for changes to the existing chart        if (this.chart != null) {            this.chart.removeChangeListener(this);            this.chart.removeProgressListener(this);        }        // add the new chart        this.chart = chart;        if (chart != null) {            this.chart.addChangeListener(this);            this.chart.addProgressListener(this);            Plot plot = chart.getPlot();            this.domainZoomable = false;            this.rangeZoomable = false;            if (plot instanceof Zoomable) {                Zoomable z = (Zoomable) plot;                this.domainZoomable = z.isDomainZoomable();                this.rangeZoomable = z.isRangeZoomable();                this.orientation = z.getOrientation();            }        }        else {            this.domainZoomable = false;            this.rangeZoomable = false;        }        if (this.useBuffer) {            this.refreshBuffer = true;        }        repaint();    }    /**     * Returns the minimum drawing width for charts.     * <P>     * If the width available on the panel is less than this, then the chart is     * drawn at the minimum width then scaled down to fit.     *     * @return The minimum drawing width.     */    public int getMinimumDrawWidth() {        return this.minimumDrawWidth;    }    /**     * Sets the minimum drawing width for the chart on this panel.     * <P>     * At the time the chart is drawn on the panel, if the available width is     * less than this amount, the chart will be drawn using the minimum width     * then scaled down to fit the available space.     *     * @param width  The width.     */    public void setMinimumDrawWidth(int width) {        this.minimumDrawWidth = width;    }    /**     * Returns the maximum drawing width for charts.     * <P>     * If the width available on the panel is greater than this, then the chart     * is drawn at the maximum width then scaled up to fit.     *     * @return The maximum drawing width.     */    public int getMaximumDrawWidth() {        return this.maximumDrawWidth;    }    /**     * Sets the maximum drawing width for the chart on this panel.     * <P>     * At the time the chart is drawn on the panel, if the available width is     * greater than this amount, the chart will be drawn using the maximum     * width then scaled up to fit the available space.     *     * @param width  The width.     */    public void setMaximumDrawWidth(int width) {        this.maximumDrawWidth = width;    }    /**     * Returns the minimum drawing height for charts.     * <P>     * If the height available on the panel is less than this, then the chart     * is drawn at the minimum height then scaled down to fit.     *     * @return The minimum drawing height.     */    public int getMinimumDrawHeight() {        return this.minimumDrawHeight;    }    /**     * Sets the minimum drawing height for the chart on this panel.     * <P>     * At the time the chart is drawn on the panel, if the available height is     * less than this amount, the chart will be drawn using the minimum height     * then scaled down to fit the available space.     *     * @param height  The height.     */    public void setMinimumDrawHeight(int height) {        this.minimumDrawHeight = height;    }    /**     * Returns the maximum drawing height for charts.     * <P>     * If the height available on the panel is greater than this, then the     * chart is drawn at the maximum height then scaled up to fit.     *     * @return The maximum drawing height.     */    public int getMaximumDrawHeight() {        return this.maximumDrawHeight;    }    /**     * Sets the maximum drawing height for the chart on this panel.     * <P>     * At the time the chart is drawn on the panel, if the available height is     * greater than this amount, the chart will be drawn using the maximum     * height then scaled up to fit the available space.     *     * @param height  The height.     */    public void setMaximumDrawHeight(int height) {        this.maximumDrawHeight = height;    }    /**     * Returns the X scale factor for the chart.  This will be 1.0 if no      * scaling has been used.     *      * @return The scale factor.     */    public double getScaleX() {        return this.scaleX;    }        /**     * Returns the Y scale factory for the chart.  This will be 1.0 if no      * scaling has been used.     *      * @return The scale factor.     */    public double getScaleY() {        return this.scaleY;    }

⌨️ 快捷键说明

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