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

📄 chartcomposite.java

📁 提供JFreechart图表功能, 提供JFreechart图表功能,提供JFreechart图表功能
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        int x = (int) Math.round(rect.getX() * getScaleX()) + insets.x;        int y = (int) Math.round(rect.getY() * this.getScaleY()) + insets.y;        int w = (int) Math.round(rect.getWidth() * this.getScaleX());        int h = (int) Math.round(rect.getHeight() * this.getScaleY());        return new Rectangle(x, y, w, h);    }    /**     * Returns the data area for the chart (the area inside the axes) with the     * current scaling applied (that is, the area as it appears on screen).     *     * @return The scaled data area.     */    public Rectangle getScreenDataArea() {        Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();        Rectangle clientArea = this.getClientArea();        int x = (int) (dataArea.getX() * this.scaleX + clientArea.x);        int y = (int) (dataArea.getY() * this.scaleY + clientArea.y);        int w = (int) (dataArea.getWidth() * this.scaleX);        int h = (int) (dataArea.getHeight() * this.scaleY);        return new Rectangle(x, y, w, h);    }        /**     * Returns the data area (the area inside the axes) for the plot or subplot,     * with the current scaling applied.     *     * @param x  the x-coordinate (for subplot selection).     * @param y  the y-coordinate (for subplot selection).     *      * @return The scaled data area.     */    public Rectangle getScreenDataArea(int x, int y) {        PlotRenderingInfo plotInfo = this.info.getPlotInfo();        Rectangle result;        if (plotInfo.getSubplotCount() == 0)            result = getScreenDataArea();        else {            // 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(x, y));            int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);            if (subplotIndex == -1) {                return null;            }            result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());        }        return result;    }    /**     * Translates a Java2D point on the chart to a screen location.     *     * @param java2DPoint  the Java2D point.     *     * @return The screen location.     */    public Point translateJava2DToScreen(Point2D java2DPoint) {        Rectangle insets = this.getClientArea();        int x = (int) (java2DPoint.getX() * this.scaleX + insets.x);        int y = (int) (java2DPoint.getY() * this.scaleY + insets.y);        return new Point(x, y);    }    /**     * Translates a screen location to a Java SWT point.     *     * @param screenPoint  the screen location.     *     * @return The Java2D coordinates.     */    public Point translateScreenToJavaSWT(Point screenPoint) {        Rectangle insets = this.getClientArea();        int x = (int) ((screenPoint.x - insets.x) / this.scaleX);        int y = (int) ((screenPoint.y - insets.y) / this.scaleY);        return new Point(x, y);    }    /**     * Translates a screen location to a Java2D point.     *     * @param screenPoint  the screen location.     *     * @return The Java2D coordinates.     */    public Point2D translateScreenToJava2D(Point screenPoint) {        Rectangle insets = this.getClientArea();        int x = (int) ((screenPoint.x - insets.x) / this.scaleX);        int y = (int) ((screenPoint.y - insets.y) / this.scaleY);        return new Point2D.Double(x, y);    }    /**     * Returns the flag that controls whether or not a horizontal axis trace     * line is drawn over the plot area at the current mouse location.     *      * @return A boolean.     */    public boolean getHorizontalAxisTrace() {        return this.horizontalAxisTrace;        }        /**     * A flag that controls trace lines on the horizontal axis.     *     * @param flag  <code>true</code> enables trace lines for the mouse     *      pointer on the horizontal axis.     */    public void setHorizontalAxisTrace(boolean flag) {        this.horizontalAxisTrace = flag;    }        /**     * Returns the flag that controls whether or not a vertical axis trace     * line is drawn over the plot area at the current mouse location.     *      * @return A boolean.     */    public boolean getVerticalAxisTrace() {        return this.verticalAxisTrace;        }        /**     * A flag that controls trace lines on the vertical axis.     *     * @param flag  <code>true</code> enables trace lines for the mouse     *              pointer on the vertical axis.     */    public void setVerticalAxisTrace(boolean flag) {        this.verticalAxisTrace = flag;    }    /**     * @param displayToolTips the displayToolTips to set     */    public void setDisplayToolTips( boolean displayToolTips ) {        this.displayToolTips = displayToolTips;    }    /**     * Returns a string for the tooltip.     *     * @param e  the mouse event.     *     * @return A tool tip or <code>null</code> if no tooltip is available.     */    public String getToolTipText(org.eclipse.swt.events.MouseEvent e) {        String result = null;        if (this.info != null) {            EntityCollection entities = this.info.getEntityCollection();            if (entities != null) {                Rectangle insets = getClientArea();                ChartEntity entity = entities.getEntity(                        (int) ((e.x - insets.x) / this.scaleX),                        (int) ((e.y - insets.y) / this.scaleY));                if (entity != null) {                    result = entity.getToolTipText();                }            }        }        return result;    }    /**     * The idea is to modify the zooming options depending on the type of chart      * being displayed by the panel.     *     * @param x  horizontal position of the popup.     * @param y  vertical position of the popup.     */    protected void displayPopupMenu(int x, int y) {        if (this.popup != null) {            // go through each zoom menu item and decide whether or not to             // enable it...            Plot plot = this.chart.getPlot();            boolean isDomainZoomable = false;            boolean isRangeZoomable = false;            if (plot instanceof Zoomable) {                Zoomable z = (Zoomable) plot;                isDomainZoomable = z.isDomainZoomable();                isRangeZoomable = z.isRangeZoomable();            }            if (this.zoomInDomainMenuItem != null) {                this.zoomInDomainMenuItem.setEnabled(isDomainZoomable);            }            if (this.zoomOutDomainMenuItem != null) {                this.zoomOutDomainMenuItem.setEnabled(isDomainZoomable);            }             if (this.zoomResetDomainMenuItem != null) {                this.zoomResetDomainMenuItem.setEnabled(isDomainZoomable);            }            if (this.zoomInRangeMenuItem != null) {                this.zoomInRangeMenuItem.setEnabled(isRangeZoomable);            }            if (this.zoomOutRangeMenuItem != null) {                this.zoomOutRangeMenuItem.setEnabled(isRangeZoomable);            }            if (this.zoomResetRangeMenuItem != null) {                this.zoomResetRangeMenuItem.setEnabled(isRangeZoomable);            }            if (this.zoomInBothMenuItem != null) {                this.zoomInBothMenuItem.setEnabled(                    isDomainZoomable & isRangeZoomable                );            }            if (this.zoomOutBothMenuItem != null) {                this.zoomOutBothMenuItem.setEnabled(isDomainZoomable                         & isRangeZoomable);            }            if (this.zoomResetBothMenuItem != null) {                this.zoomResetBothMenuItem.setEnabled(isDomainZoomable                         & isRangeZoomable);            }            this.popup.setLocation(x, y);            this.popup.setVisible(true);        }    }    /**     * Creates a print job for the chart.     */    public void createChartPrintJob() {        //FIXME try to replace swing print stuff by swt        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) {                    MessageBox messageBox = new MessageBox(                             this.canvas.getShell(), SWT.OK | SWT.ICON_ERROR );                    messageBox.setMessage( e.getMessage() );                    messageBox.open();                }            }        }    }    /**     * Creates a popup menu for the canvas.     *     * @param properties  include a menu item for the chart property editor.     * @param save  include a menu item for saving the chart.     * @param print  include a menu item for printing the chart.     * @param zoom  include menu items for zooming.     *     * @return The popup menu.     */    protected Menu createPopupMenu(boolean properties, boolean save,             boolean print, boolean zoom) {                Menu result = new Menu(this);        boolean separator = false;        if (properties) {            MenuItem propertiesItem = new MenuItem(result, SWT.PUSH);            propertiesItem.setText(localizationResources.getString(                    "Properties..."));            propertiesItem.setData(PROPERTIES_COMMAND);            propertiesItem.addSelectionListener(this);            separator = true;        }        if (save) {            if (separator) {                new MenuItem(result, SWT.SEPARATOR);                separator = false;            }            MenuItem saveItem = new MenuItem(result, SWT.NONE);            saveItem.setText(localizationResources.getString("Save_as..."));            saveItem.setData(SAVE_COMMAND);            saveItem.addSelectionListener(this);            separator = true;        }        if (print) {            if (separator) {                new MenuItem(result, SWT.SEPARATOR);                separator = false;            }            MenuItem printItem = new MenuItem(result, SWT.NONE);            printItem.setText(localizationResources.getString("Print..."));            printItem.setData(PRINT_COMMAND);            printItem.addSelectionListener(this);            separator = true;        }        if (zoom) {            if (separator) {                new MenuItem(result, SWT.SEPARATOR);                separator = false;            }            Menu zoomInMenu = new Menu(result);            MenuItem zoomInMenuItem = new MenuItem(result, SWT.CASCADE);            zoomInMenuItem.setText(localizationResources.getString("Zoom_In"));            zoomInMenuItem.setMenu(zoomInMenu);            this.zoomInBothMenuItem = new MenuItem(zoomInMenu, SWT.PUSH);            this.zoomInBothMenuItem.setText(localizationResources.getString(                    "All_Axes"));            this.zoomInBothMenuItem.setData(ZOOM_IN_BOTH_COMMAND);            this.zoomInBothMenuItem.addSelectionListener(this);            new MenuItem(zoomInMenu, SWT.SEPARATOR);            this.zoomInDomainMenuItem = new MenuItem(zoomInMenu, SWT.PUSH);            this.zoomInDomainMenuItem.setText(localizationResources.getString(                    "Domain_Axis"));            this.zoomInDomainMenuItem.setData(ZOOM_IN_DOMAIN_COMMAND);            this.zoomInDomainMenuItem.addSelectionListener(this);            this.zoomInRangeMenuItem = new MenuItem(zoomInMenu, SWT.PUSH);            this.zoomInRangeMenuItem.setText(localizationResources.getString(                    "Range_Axis"));            this.zoomInRangeMenuItem.setData(ZOOM_IN_RANGE_COMMAND);            this.zoomInRangeMenuItem.addSelectionListener(this);            Menu zoomOutMenu = new Menu(result);            MenuItem zoomOutMenuItem = new MenuItem(result, SWT.CASCADE);            zoomOutMenuItem.setText(localizationResources.getString(                    "Zoom_Out"));            zoomOutMenuItem.setMenu(zoomOutMenu);            this.zoomOutBothMenuItem = new MenuItem(zoomOutMenu, SWT.PUSH);            this.zoomOutBothMenuItem.setText(localizationResources.getString(                    "All_Axes"));            this.zoomOutBothMenuItem.setData(ZOOM_OUT_BOTH_COMMAND);            this.zoomOutBothMenuItem.addSelectionListener(this);                        new MenuItem(zoomOutMenu, SWT.SEPARATOR);            this.zoomOutDomainMenuItem = new MenuItem(zoomOutMenu, SWT.PUSH);            this.zoomOutDomainMenuItem.setText(localizationResources.getString(                    "Domain_Axis"));            this.zoomOutDomainMenuItem.setData(ZOOM_OUT_DOMAIN_COMMAND);            this.zoomOutDomainMenuItem.addSelectionListener(this);            this.zoomOutRangeMenuItem = new MenuItem(zoomOutMenu, SWT.PUSH);            this.zoomOutRangeMenuItem.setText(                    localizationResources.getString("Range_Axis"));            this.zoomOutRangeMenuItem.setData(ZOOM_OUT_RANGE_COMMAND);            this.zoomOutRangeMenuItem.addSelectionListener(this);            Menu autoRangeMenu = new Menu(result);            MenuItem autoRangeMenuItem = new MenuItem(result, SWT.CASCADE);            autoRangeMenuItem.setText(localizationResources.getString(                    "Auto_Range"));

⌨️ 快捷键说明

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