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

📄 chartpanel.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @param y  The y coordinate in Java2D space.
     */
    public void zoomInVertical(double y) {
        Plot p = this.chart.getPlot();
        if (p instanceof ValueAxisPlot) {
            ValueAxisPlot plot = (ValueAxisPlot) p;
            plot.zoomVerticalAxes(this.zoomInFactor);
        }
    }

    /**
     * Zooms out on an anchor point (measured in Java2D coordinates).
     *
     * @param x  The x value.
     * @param y  The y value.
     */
    public void zoomOutBoth(double x, double y) {
        zoomOutHorizontal(x);
        zoomOutVertical(y);
    }

    /**
     * Increases the range on the horizontal axis, centered about a Java2D
     * x coordinate.
     * <P>
     * The range on the x axis is doubled.
     *
     * @param x  The x coordinate in Java2D space.
     */
    public void zoomOutHorizontal(double x) {
        Plot p = this.chart.getPlot();
        if (p instanceof ValueAxisPlot) {
            ValueAxisPlot plot = (ValueAxisPlot) p;
            plot.zoomHorizontalAxes(this.zoomOutFactor);
        }
    }

    /**
     * Increases the range on the vertical axis, centered about a Java2D y coordinate.
     * <P>
     * The range on the y axis is doubled.
     *
     * @param y  the y coordinate in Java2D space.
     */
    public void zoomOutVertical(double y) {
        Plot p = this.chart.getPlot();
        if (p instanceof ValueAxisPlot) {
            ValueAxisPlot plot = (ValueAxisPlot) p;
            plot.zoomVerticalAxes(this.zoomOutFactor);
        }
    }

    /**
     * Zooms in on a selected region.
     *
     * @param selection  the selected region.
     */
    public void zoom(Rectangle2D selection) {

        double hLower = 0.0;
        double hUpper = 0.0;
        double vLower = 0.0;
        double vUpper = 0.0;
        
        if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

            Rectangle2D scaledDataArea = getScaledDataArea();
            hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
            hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
            vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
            vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

            LOGGER.debug("hLower = " + hLower);
            LOGGER.debug("hUpper = " + hUpper);
            LOGGER.debug("vLower = " + vLower);
            LOGGER.debug("vUpper = " + vUpper);
            Plot p = this.chart.getPlot();
            if (p instanceof ValueAxisPlot) {
                ValueAxisPlot plot = (ValueAxisPlot) p;
                plot.zoomHorizontalAxes(hLower, hUpper);
                plot.zoomVerticalAxes(vLower, vUpper);
            }

        }

    }

    /**
     * Restores the auto-range calculation on both axes.
     */
    public void autoRangeBoth() {
        autoRangeHorizontal();
        autoRangeVertical();
    }

    /**
     * Restores the auto-range calculation on the horizontal axis.
     */
    public void autoRangeHorizontal() {
        Plot p = this.chart.getPlot();
        if (p instanceof ValueAxisPlot) {
            ValueAxisPlot plot = (ValueAxisPlot) p;
            plot.zoomHorizontalAxes(0.0);
        }
    }

    /**
     * Restores the auto-range calculation on the vertical axis.
     */
    public void autoRangeVertical() {
        Plot p = this.chart.getPlot();
        if (p instanceof ValueAxisPlot) {
            ValueAxisPlot plot = (ValueAxisPlot) p;
            plot.zoomVerticalAxes(0.0);
        }
    }

    /**
     * Returns the data area for the chart (the area inside the axes) with the
     * current scaling applied.
     *
     * @return The scaled data area.
     */
    public Rectangle2D getScaledDataArea() {
        Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
        Insets insets = getInsets();
        double x = dataArea.getX() * this.scaleX + insets.left;
        double y = dataArea.getY() * this.scaleY + insets.top;
        double w = dataArea.getWidth() * this.scaleX;
        double h = dataArea.getHeight() * this.scaleY;
        return new Rectangle2D.Double(x, y, w, h);
    }
    
    /**
     * Returns the initial tooltip delay value used inside this chart panel.
     *
     * @return an integer representing the initial delay value, in milliseconds.
     * 
     * @see javax.swing.ToolTipManager#getInitialDelay()
     */
    public int getInitialDelay() {
        return this.ownToolTipInitialDelay;
    }
    
    /**
     * Returns the reshow tooltip delay value used inside this chart panel.
     *
     * @return an integer representing the reshow  delay value, in milliseconds.
     * 
     * @see javax.swing.ToolTipManager#getReshowDelay()
     */
    public int getReshowDelay() {
        return this.ownToolTipReshowDelay;  
    }

    /**
     * Returns the dismissal tooltip delay value used inside this chart panel.
     *
     * @return an integer representing the dismissal delay value, in milliseconds.
     * 
     * @see javax.swing.ToolTipManager#getDismissDelay()
     */
    public int getDismissDelay() {
        return this.ownToolTipDismissDelay; 
    }
    
    /**
     * Specifies the initial delay value for this chart panel.
     *
     * @param delay  the number of milliseconds to delay (after the cursor has paused) before 
     *               displaying. 
     * 
     * @see javax.swing.ToolTipManager#setInitialDelay(int)
     */
    public void setInitialDelay(int delay) {
        this.ownToolTipInitialDelay = delay;
    }
    
    /**
     * Specifies the amount of time before the user has to wait initialDelay milliseconds before a 
     * tooltip will be shown.
     *
     * @param delay  time in milliseconds
     * 
     * @see javax.swing.ToolTipManager#setReshowDelay(int)
     */
    public void setReshowDelay(int delay) {
        this.ownToolTipReshowDelay = delay;  
    }

    /**
     * Specifies the dismissal delay value for this chart panel.
     *
     * @param delay the number of milliseconds to delay before taking away the tooltip
     * 
     * @see javax.swing.ToolTipManager#setDismissDelay(int)
     */
    public void setDismissDelay(int delay) {
        this.ownToolTipDismissDelay = delay; 
    }
    
    /**
     * Returns the zoom in factor.
     * 
     * @return The zoom in factor.
     */
    public double getZoomInFactor() {
        return this.zoomInFactor;   
    }
    
    /**
     * Sets the zoom in factor.
     * 
     * @param factor  the factor.
     */
    public void setZoomInFactor(double factor) {
        this.zoomInFactor = factor;
    }
    
    /**
     * Returns the zoom out factor.
     * 
     * @return The zoom out factor.
     */
    public double getZoomOutFactor() {
        return this.zoomOutFactor;   
    }
    
    /**
     * Sets the zoom out factor.
     * 
     * @param factor  the factor.
     */
    public void setZoomOutFactor(double factor) {
        this.zoomOutFactor = factor;
    }
    
    /**
     * Draws a vertical line used to trace the mouse position to the horizontal axis.
     *
     * @param x  the x-coordinate of the trace line.
     */
    private void drawHorizontalAxisTrace(int x) {

        Graphics2D g2 = (Graphics2D) getGraphics();
        Rectangle2D dataArea = getScaledDataArea();

        g2.setXORMode(java.awt.Color.orange);
        if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {

            if (this.verticalTraceLine != null) {
                g2.draw(this.verticalTraceLine);
                this.verticalTraceLine.setLine(
                    x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()
                );
            }
            else {
                this.verticalTraceLine = new Line2D.Float(
                    x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()
                );
            }
            g2.draw(this.verticalTraceLine);
        }

    }

    /**
     * Draws a horizontal line used to trace the mouse position to the vertical axis.
     *
     * @param y  the y-coordinate of the trace line.
     */
    private void drawVerticalAxisTrace(int y) {

        Graphics2D g2 = (Graphics2D) getGraphics();
        Rectangle2D dataArea = getScaledDataArea();

        g2.setXORMode(java.awt.Color.orange);
        if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {

            if (this.horizontalTraceLine != null) {
                g2.draw(this.horizontalTraceLine);
                this.horizontalTraceLine.setLine(
                    (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y
                );
            }
            else {
                this.horizontalTraceLine = new Line2D.Float(
                    (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y
                );
            }
            g2.draw(this.horizontalTraceLine);
        }

    }

    /**
     * Displays a dialog that allows the user to edit the properties for the
     * current chart.
     */
    private void attemptEditChartProperties() {

        ChartPropertyEditPanel panel = new ChartPropertyEditPanel(this.chart);
        int result = 
            JOptionPane.showConfirmDialog(this, panel, 
                                          localizationResources.getString("Chart_Properties"),
                                          JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (result == JOptionPane.OK_OPTION) {
            panel.updateChartProperties(this.chart);
        }

    }

    /**
     * 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 {

        JFileChooser fileChooser = new JFileChooser();
        ExtensionFileFilter filter = 
            new ExtensionFileFilter(localizationResources.getString("PNG_Image_Files"), ".png");
        fileChooser.addChoosableFileFilter(filter);
        fileChooser.addChoosableFileFilter(new ExtensionFileFilter("All files", ""));

        int option = fileChooser.showSaveDialog(this);
        if (option == JFileChooser.APPROVE_OPTION) {
            String filename = fileChooser.getSelectedFile().getPath();
            if (isEnforceFileExtensions()) {
                if (!filename.endsWith(".png")) {
                    filename = filename + ".png";
                }
            }
            ChartUtilities.saveChartAsPNG(new File(filename), this.chart, getWidth(), getHeight());
        }

    }

    /**
     * Creates a print job for the chart.
     */
    public void createChartPrintJob() {

        PrinterJob job = PrinterJob.getPrinterJob();
        PageFormat pf = job.defaultPage();
        PageFormat pf2 = job.pageDialog(pf);
        if (pf2 != pf) {
            job.setPrintable(this, pf2);
            if (job.printDialog()) {
                try {
                    job.print();
                }
                catch (PrinterException e) {
                    JOptionPane.showMessageDialog(this, e);
                }
            }
        }

    }

    /**
     * Prints the chart on a single page.
     *
     * @param g  the graphics context.
     * @param pf  the page format to use.
     * @param pageIndex  the index of the page. If not <code>0</code>, nothing gets print.
     *
     * @return the result of printing.
     */
    public int print(Graphics g, PageFormat pf, int pageIndex) {

        if (pageIndex != 0) {
            return NO_SUCH_PAGE;

⌨️ 快捷键说明

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