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

📄 chartcomposite.java

📁 JFreeChart它主要是用来制作各种各样的图表
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     */    public void widgetSelected(SelectionEvent e) {        String command = (String) ((MenuItem) e.getSource()).getData();        if (command.equals(PROPERTIES_COMMAND)) {            attemptEditChartProperties();        }        else if (command.equals(SAVE_COMMAND)) {            try {                doSaveAs();            }            catch (IOException ex) {                ex.printStackTrace();            }        }        else if (command.equals(PRINT_COMMAND)) {            createChartPrintJob();        }        /* in the next zoomPoint.x and y replace by e.x and y for now.         * this helps to handle the mouse events and besides,         * those values are unused AFAIK. */        else if (command.equals(ZOOM_IN_BOTH_COMMAND)) {            zoomInBoth(e.x, e.y);        }        else if (command.equals(ZOOM_IN_DOMAIN_COMMAND)) {            zoomInDomain(e.x, e.y);        }        else if (command.equals(ZOOM_IN_RANGE_COMMAND)) {            zoomInRange(e.x, e.y);        }        else if (command.equals(ZOOM_OUT_BOTH_COMMAND)) {            zoomOutBoth(e.x, e.y);        }        else if (command.equals(ZOOM_OUT_DOMAIN_COMMAND)) {            zoomOutDomain(e.x, e.y);        }        else if (command.equals(ZOOM_OUT_RANGE_COMMAND)) {            zoomOutRange(e.x, e.y);        }        else if (command.equals(ZOOM_RESET_BOTH_COMMAND)) {            restoreAutoBounds();        }        else if (command.equals(ZOOM_RESET_DOMAIN_COMMAND)) {            restoreAutoDomainBounds();        }        else if (command.equals(ZOOM_RESET_RANGE_COMMAND)) {            restoreAutoRangeBounds();        }        this.forceRedraw();    }    /**     * Not implemented.     *     * @param graphics  the graphics.     * @param pageFormat  the page format.     * @param pageIndex  the page index.     *     * @return ?.     *     * @throws PrinterException if there is a problem.     */    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)        throws PrinterException {        if (pageIndex != 0) {            return NO_SUCH_PAGE;        }        /*        CairoImage image = new CairoImage(                this.getBounds().width, this.getBounds().height);        Graphics2D g2 = image.createGraphics2D();        double x = pageFormat.getImageableX();        double y = pageFormat.getImageableY();        double w = pageFormat.getImageableWidth();        double h = pageFormat.getImageableHeight();        this.chart.draw(            g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null        );        */        return PAGE_EXISTS;    }    /**     * Hook an SWT listener on the canvas where the chart is drawn.     * The purpose of this method is to allow some degree of customization.     *     * @param listener The SWT listener to attach to the canvas.     */    public void addSWTListener(EventListener listener) {        if (listener instanceof ControlListener) {            this.canvas.addControlListener((ControlListener) listener);        }        else if (listener instanceof DisposeListener) {            this.canvas.addDisposeListener((DisposeListener) listener);//      }//      else if (listener instanceof DragDetectListener) {//          this.canvas.addDragDetectListener((DragDetectListener) listener);        }        else if (listener instanceof FocusListener) {            this.canvas.addFocusListener((FocusListener) listener);        }        else if (listener instanceof HelpListener) {            this.canvas.addHelpListener((HelpListener) listener);        }        else if (listener instanceof KeyListener) {            this.canvas.addKeyListener((KeyListener) listener);//      }//      else if (listener instanceof MenuDetectListener) {//          this.canvas.addMenuDetectListener((MenuDetectListener) listener);        }        else if (listener instanceof MouseListener) {            this.canvas.addMouseListener((MouseListener) listener);        }        else if (listener instanceof MouseMoveListener) {            this.canvas.addMouseMoveListener((MouseMoveListener) listener);        }        else if (listener instanceof MouseTrackListener) {            this.canvas.addMouseTrackListener((MouseTrackListener) listener);//      } else if (listener instanceof MouseWheelListener) {//          this.canvas.addMouseWheelListener((MouseWheelListener) listener);        }        else if (listener instanceof PaintListener) {            this.canvas.addPaintListener((PaintListener) listener);        }        else if (listener instanceof TraverseListener) {            this.canvas.addTraverseListener((TraverseListener) listener);        }    }    /**     * Does nothing - override if necessary.     *     * @param event  the mouse event.     */    public void mouseDoubleClick(MouseEvent event) {        // do nothing, override if necessary    }    /**     * Handles a mouse down event.     *     * @param event  the event.     */    public void mouseDown(MouseEvent event) {        Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);        if (scaledDataArea == null) return;        this.zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);        int x = (int) ((event.x - getClientArea().x) / this.scaleX);        int y = (int) ((event.y - getClientArea().y) / this.scaleY);        this.anchor = new Point2D.Double(x, y);        this.chart.setNotify(true);  // force a redraw        this.canvas.redraw();        // new entity code        ChartEntity entity = null;        if (this.info != null) {            EntityCollection entities = this.info.getEntityCollection();            if (entities != null) {                entity = entities.getEntity(x, y);            }        }        Object[] listeners = this.chartMouseListeners.getListeners(                ChartMouseListener.class);        if (listeners.length == 0) {            return;        }        // pass mouse down event if some ChartMouseListener are listening        java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);        ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(),                mouseEvent, entity);        for (int i = listeners.length - 1; i >= 0; i -= 1) {            ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);        }    }    /**     * Handles a mouse up event.     *     * @param event  the event.     */    public void mouseUp(MouseEvent event) {        boolean hZoom, vZoom;        if (this.zoomRectangle == null) {            Rectangle screenDataArea = getScreenDataArea(event.x, event.y);            if (screenDataArea != null) {                this.zoomPoint = getPointInRectangle(event.x, event.y,                        screenDataArea);            }            if (this.popup != null && event.button == 3) {                org.eclipse.swt.graphics.Point pt = this.canvas.toDisplay(                        event.x, event.y);                displayPopupMenu(pt.x, pt.y);            }        }        else {            hZoom = false;            vZoom = false;            if (this.orientation == PlotOrientation.HORIZONTAL) {                hZoom = this.rangeZoomable;                vZoom = this.domainZoomable;            }            else {                hZoom = this.domainZoomable;                vZoom = this.rangeZoomable;            }            boolean zoomTrigger1 = hZoom && Math.abs(this.zoomRectangle.width)                    >= this.zoomTriggerDistance;            boolean zoomTrigger2 = vZoom                    && Math.abs(this.zoomRectangle.height)                    >= this.zoomTriggerDistance;            if (zoomTrigger1 || zoomTrigger2) {                // if the box has been drawn backwards, restore the auto bounds                if ((hZoom && (this.zoomRectangle.x + this.zoomRectangle.width                        < this.zoomPoint.x)) || (vZoom && (this.zoomRectangle.y                        + this.zoomRectangle.height < this.zoomPoint.y)))                    restoreAutoBounds();                else {                    zoom(this.zoomRectangle);                }                this.canvas.redraw();            }        }        this.zoomPoint = null;        this.zoomRectangle = null;    }    /**     * Handles a mouse move event.     *     * @param event  the mouse event.     */    public void mouseMove(MouseEvent event) {        // handle axis trace        if (this.horizontalAxisTrace || this.verticalAxisTrace) {            this.horizontalTraceLineY = event.y;            this.verticalTraceLineX = event.x;            this.canvas.redraw();        }        // handle tool tips in a simple way        if (this.displayToolTips) {            String s = getToolTipText(event);            if (s == null && this.canvas.getToolTipText() != null                    || s != null && !s.equals(this.canvas.getToolTipText()))                this.canvas.setToolTipText(s);        }        // handle zoom box        boolean hZoom, vZoom;        if (this.zoomPoint != null) {            Rectangle scaledDataArea = getScreenDataArea(this.zoomPoint.x,                    this.zoomPoint.y);            org.eclipse.swt.graphics.Point movingPoint                    = getPointInRectangle(event.x, event.y, scaledDataArea);            if (this.orientation == PlotOrientation.HORIZONTAL) {                hZoom = this.rangeZoomable;                vZoom = this.domainZoomable;            }            else {                hZoom = this.domainZoomable;                vZoom = this.rangeZoomable;            }            if (hZoom && vZoom) {                // selected rectangle shouldn't extend outside the data area...                this.zoomRectangle = new Rectangle(this.zoomPoint.x,                        this.zoomPoint.y, movingPoint.x - this.zoomPoint.x,                        movingPoint.y - this.zoomPoint.y);            }            else if (hZoom) {                this.zoomRectangle = new Rectangle(this.zoomPoint.x,                        scaledDataArea.y, movingPoint.x - this.zoomPoint.x,                        scaledDataArea.height);            }            else if (vZoom) {                int ymax = Math.max(movingPoint.y, scaledDataArea.y);                this.zoomRectangle = new Rectangle(                        scaledDataArea.x, this.zoomPoint.y,                        scaledDataArea.width, ymax - this.zoomPoint.y);            }            this.canvas.redraw();        }        // new entity code        ChartEntity entity = null;        int x = (int) ((event.x - getClientArea().x) / this.scaleX);        int y = (int) ((event.y - getClientArea().y) / this.scaleY);        if (this.info != null) {            EntityCollection entities = this.info.getEntityCollection();            if (entities != null) {                entity = entities.getEntity(x, y);            }        }        Object[] listeners = this.chartMouseListeners.getListeners(                ChartMouseListener.class);        if (listeners.length == 0) {            return;        }        // pass mouse move event if some ChartMouseListener are listening        java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);        ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(),                mouseEvent, entity);        for (int i = listeners.length - 1; i >= 0; i -= 1) {            ((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent);        }    }    /**     * Paints the control.     *     * @param e  the paint event.     */    public void paintControl(PaintEvent e) {        // first determine the size of the chart rendering area...        // TODO workout insets for SWT        Rectangle available = getBounds();        // skip if chart is null        if (this.chart == null) {            this.canvas.drawBackground(e.gc, available.x, available.y,                    available.width, available.height);            return;        }        SWTGraphics2D sg2 = new SWTGraphics2D(e.gc);        // work out if scaling is required...        boolean scale = false;        int drawWidth = available.width;        int drawHeight = available.height;        if (drawWidth == 0.0 || drawHeight == 0.0) return;        this.scaleX = 1.0;        this.scaleY = 1.0;        if (drawWidth < this.minimumDrawWidth) {            this.scaleX = (double) drawWidth / this.minimumDrawWidth;            drawWidth = this.minimumDrawWidth;            scale = true;        }        else if (drawWidth > this.maximumDrawWidth) {            this.scaleX = (double) drawWidth / this.maximumDrawWidth;            drawWidth = this.maximumDrawWidth;            scale = true;        }        if (drawHeight < this.minimumDrawHeight) {            this.scaleY = (double) drawHeight / this.minimumDrawHeight;            drawHeight = this.minimumDrawHeight;            scale = true;        }        else if (drawHeight > this.maximumDrawHeight) {            this.scaleY = (double) drawHeight / this.maximumDrawHeight;            drawHeight = this.maximumDrawHeight;            scale = true;        }        // are we using the chart buffer?        if (this.useBuffer) {            //SwtGraphics2D sg2 = new SwtGraphics2D(e.gc);            this.chartBuffer = (org.eclipse.swt.gra

⌨️ 快捷键说明

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