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

📄 chartcomposite.java

📁 提供JFreechart图表功能, 提供JFreechart图表功能,提供JFreechart图表功能
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *      * @return The zoom in factor.     *      * @see #setZoomInFactor(double)     */    public double getZoomInFactor() {        return this.zoomInFactor;       }        /**     * Sets the zoom in factor.     *      * @param factor  the factor.     *      * @see #getZoomInFactor()     */    public void setZoomInFactor(double factor) {        this.zoomInFactor = factor;    }        /**     * Returns the zoom out factor.     *      * @return The zoom out factor.     *      * @see #setZoomOutFactor(double)     */    public double getZoomOutFactor() {        return this.zoomOutFactor;       }        /**     * Sets the zoom out factor.     *      * @param factor  the factor.     *      * @see #getZoomOutFactor()     */    public void setZoomOutFactor(double factor) {        this.zoomOutFactor = factor;    }        /**     * Displays a dialog that allows the user to edit the properties for the     * current chart.     */    private void attemptEditChartProperties() {        SWTChartEditor editor = new SWTChartEditor(this.canvas.getDisplay(),                 this.chart);        //ChartEditorManager.getChartEditor(canvas.getDisplay(), this.chart);        editor.open();    }    /**     * Returns <code>true</code> if file extensions should be enforced, and      * <code>false</code> otherwise.     *     * @return The flag.     */    public boolean isEnforceFileExtensions() {        return this.enforceFileExtensions;    }    /**     * Sets a flag that controls whether or not file extensions are enforced.     *     * @param enforce  the new flag value.     */    public void setEnforceFileExtensions(boolean enforce) {        this.enforceFileExtensions = enforce;    }    /**     * Opens a file chooser and gives the user an opportunity to save the chart     * in PNG format.     *     * @throws IOException if there is an I/O error.     */    public void doSaveAs() throws IOException {        FileDialog fileDialog = new FileDialog(this.canvas.getShell(),                 SWT.SAVE);        String[] extensions = { "*.png" };        fileDialog.setFilterExtensions(extensions);        String filename = fileDialog.open();        if (filename != null) {            if (isEnforceFileExtensions()) {                if (!filename.endsWith(".png")) {                    filename = filename + ".png";                }            }            //TODO replace getSize by getBounds ?            ChartUtilities.saveChartAsPNG(new File(filename), this.chart,                     this.canvas.getSize().x, this.canvas.getSize().y);        }    }    /**     * Returns a point based on (x, y) but constrained to be within the bounds     * of the given rectangle.  This method could be moved to JCommon.     *      * @param x  the x-coordinate.     * @param y  the y-coordinate.     * @param area  the rectangle (<code>null</code> not permitted).     *      * @return A point within the rectangle.     */    private org.eclipse.swt.graphics.Point getPointInRectangle(int x, int y,             Rectangle area) {        x = Math.max(area.x, Math.min(x, area.x + area.width));           y = Math.max(area.y, Math.min(y, area.y + area.height));        return new org.eclipse.swt.graphics.Point(x, y);    }    /**     * Zooms in on an anchor point (specified in screen coordinate space).     *     * @param x  the x value (in screen coordinates).     * @param y  the y value (in screen coordinates).     */    public void zoomInBoth(double x, double y) {        zoomInDomain(x, y);        zoomInRange(x, y);    }    /**     * Decreases the length of the domain axis, centered about the given     * coordinate on the screen.  The length of the domain axis is reduced     * by the value of {@link #getZoomInFactor()}.     *     * @param x  the x coordinate (in screen coordinates).     * @param y  the y-coordinate (in screen coordinates).     */    public void zoomInDomain(double x, double y) {        Plot p = this.chart.getPlot();        if (p instanceof Zoomable)         {            Zoomable plot = (Zoomable) p;            plot.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(),                     translateScreenToJava2D(new Point((int) x, (int) y)));        }    }    /**     * Decreases the length of the range axis, centered about the given     * coordinate on the screen.  The length of the range axis is reduced by     * the value of {@link #getZoomInFactor()}.     *     * @param x  the x-coordinate (in screen coordinates).     * @param y  the y coordinate (in screen coordinates).     */    public void zoomInRange(double x, double y) {        Plot p = this.chart.getPlot();        if (p instanceof Zoomable) {            Zoomable z = (Zoomable) p;            z.zoomRangeAxes(this.zoomInFactor, this.info.getPlotInfo(),                     translateScreenToJava2D(new Point((int) x, (int) y)));        }    }    /**     * Zooms out on an anchor point (specified in screen coordinate space).     *     * @param x  the x value (in screen coordinates).     * @param y  the y value (in screen coordinates).     */    public void zoomOutBoth(double x, double y) {        zoomOutDomain(x, y);        zoomOutRange(x, y);    }    /**     * Increases the length of the domain axis, centered about the given     * coordinate on the screen.  The length of the domain axis is increased     * by the value of {@link #getZoomOutFactor()}.     *     * @param x  the x coordinate (in screen coordinates).     * @param y  the y-coordinate (in screen coordinates).     */    public void zoomOutDomain(double x, double y) {        Plot p = this.chart.getPlot();        if (p instanceof Zoomable) {            Zoomable z = (Zoomable) p;            z.zoomDomainAxes(this.zoomOutFactor, this.info.getPlotInfo(),                     translateScreenToJava2D(new Point((int) x, (int) y)));        }    }    /**     * Increases the length the range axis, centered about the given     * coordinate on the screen.  The length of the range axis is increased     * by the value of {@link #getZoomOutFactor()}.     *     * @param x  the x coordinate (in screen coordinates).     * @param y  the y-coordinate (in screen coordinates).     */    public void zoomOutRange(double x, double y) {        Plot p = this.chart.getPlot();        if (p instanceof Zoomable) {            Zoomable z = (Zoomable) p;            z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(),                     translateScreenToJava2D(new Point((int) x, (int) y)));        }    }    /**     * Zooms in on a selected region.     *     * @param selection  the selected region.     */    public void zoom(Rectangle selection) {        // get the origin of the zoom selection in the Java2D space used for        // drawing the chart (that is, before any scaling to fit the panel)        Point2D selectOrigin = translateScreenToJava2D(                new Point(selection.x, selection.y));        PlotRenderingInfo plotInfo = this.info.getPlotInfo();        Rectangle scaledDataArea = getScreenDataArea(                (selection.x + selection.width / 2),                 (selection.y + selection.height/2));        if ((selection.height > 0) && (selection.width > 0)) {            double hLower = (selection.x - scaledDataArea.x)                 / (double) scaledDataArea.width;            double hUpper = (selection.x + selection.width - scaledDataArea.x)                 / (double) scaledDataArea.width;            double vLower = (scaledDataArea.y + scaledDataArea.height                     - selection.y - selection.height)                     / (double) scaledDataArea.height;            double vUpper = (scaledDataArea.y + scaledDataArea.height                     - selection.y) / (double) scaledDataArea.height;            Plot p = this.chart.getPlot();            if (p instanceof Zoomable) {                Zoomable z = (Zoomable) p;                if (z.getOrientation() == PlotOrientation.HORIZONTAL) {                    z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);                    z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);                }                else {                    z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);                    z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);                }            }        }    }    /**     * Receives notification of changes to the chart, and redraws the chart.     *     * @param event  details of the chart change event.     */    public void chartChanged(ChartChangeEvent event) {        this.refreshBuffer = true;        Plot plot = this.chart.getPlot();        if (plot instanceof Zoomable) {            Zoomable z = (Zoomable) plot;            this.orientation = z.getOrientation();        }        this.canvas.redraw();    }    /**     * Forces a redraw of the canvas by invoking a new PaintEvent.     */    public void forceRedraw() {        Event ev = new Event();        ev.gc = new GC(this.canvas);        ev.x = 0;        ev.y = 0;        ev.width = this.canvas.getBounds().width;        ev.height = this.canvas.getBounds().height;        ev.count = 0;        this.canvas.notifyListeners(SWT.Paint, ev);        ev.gc.dispose();    }        /**     * Adds a listener to the list of objects listening for chart mouse events.     *     * @param listener  the listener (<code>null</code> not permitted).     */    public void addChartMouseListener(ChartMouseListener listener) {        this.chartMouseListeners.add(ChartMouseListener.class, listener);    }        /**     * Removes a listener from the list of objects listening for chart mouse      * events.     *     * @param listener  the listener.     */    public void removeChartMouseListener(ChartMouseListener listener) {        this.chartMouseListeners.remove(ChartMouseListener.class, listener);    }        /**     * Receives notification of a chart progress event.     *     * @param event  the event.     */    public void chartProgress(ChartProgressEvent event) {        // does nothing - override if necessary    }    /**     * Restores the auto-range calculation on both axes.     */    public void restoreAutoBounds() {        restoreAutoDomainBounds();        restoreAutoRangeBounds();    }    /**     * Restores the auto-range calculation on the domain axis.     */    public void restoreAutoDomainBounds() {        Plot p = this.chart.getPlot();        if (p instanceof Zoomable) {            Zoomable z = (Zoomable) p;            // we need to guard against this.zoomPoint being null            org.eclipse.swt.graphics.Point zp =                 (this.zoomPoint != null ? this.zoomPoint :                     new org.eclipse.swt.graphics.Point(0,0));            z.zoomDomainAxes(0.0, this.info.getPlotInfo(),                     SWTUtils.toAwtPoint(zp));        }    }    /**     * Restores the auto-range calculation on the range axis.     */    public void restoreAutoRangeBounds() {        Plot p = this.chart.getPlot();        if (p instanceof ValueAxisPlot) {            Zoomable z = (Zoomable) p;            // we need to guard against this.zoomPoint being null            org.eclipse.swt.graphics.Point zp =                 (this.zoomPoint != null ? this.zoomPoint :                     new org.eclipse.swt.graphics.Point(0,0));            z.zoomRangeAxes(0.0, this.info.getPlotInfo(),                     SWTUtils.toAwtPoint(zp));         }    }    /**     * Applies any scaling that is in effect for the chart drawing to the     * given rectangle.     *       * @param rect  the rectangle.     *      * @return A new scaled rectangle.     */    public Rectangle scale(Rectangle2D rect) {        Rectangle insets = this.getClientArea();

⌨️ 快捷键说明

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