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

📄 chartcomposite.java

📁 java图形利器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        this(comp,                 style,                null,                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 that displays the specified chart.     *     * @param comp The parent.     * @param style The style of the composite.     * @param chart  the chart.     */    public ChartComposite(Composite comp, int style, JFreeChart chart) {        this(                 comp,                 style,                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 comp The parent.     * @param style The style of the composite.     * @param chart  the chart.     * @param useBuffer  a flag controlling whether or not an off-screen buffer     *                   is used.     */    public ChartComposite(Composite comp, int style, JFreeChart chart,             boolean useBuffer) {                this(comp, style, 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 comp The parent.     * @param style The style of the composite.     * @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 ChartComposite(            Composite comp,             int style,            JFreeChart chart,            boolean properties,            boolean save,            boolean print,            boolean zoom,            boolean tooltips) {        this(                comp,                style,                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 comp The parent.     * @param style The style of the composite.     * @param jfreechart  the chart.     * @param width  the preferred width of the panel.     * @param height  the preferred height of the panel.     * @param minimumDrawW  the minimum drawing width.     * @param minimumDrawH  the minimum drawing height.     * @param maximumDrawW  the maximum drawing width.     * @param maximumDrawH  the maximum drawing height.     * @param usingBuffer  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 ChartComposite(Composite comp,             int style,            JFreeChart jfreechart,            int width,            int height,            int minimumDrawW,            int minimumDrawH,            int maximumDrawW,            int maximumDrawH,            boolean usingBuffer,            boolean properties,            boolean save,            boolean print,            boolean zoom,            boolean tooltips) {        super(comp, style);        this.setChart(jfreechart);        this.chartMouseListeners = new EventListenerList();        this.setLayout(new FillLayout());        this.info = new ChartRenderingInfo();        this.useBuffer = usingBuffer;        this.refreshBuffer = false;        this.minimumDrawWidth = minimumDrawW;        this.minimumDrawHeight = minimumDrawH;        this.maximumDrawWidth = maximumDrawW;        this.maximumDrawHeight = maximumDrawH;        this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;        this.setDisplayToolTips(tooltips);        canvas = new Canvas(this, SWT.NO_BACKGROUND);        canvas.addPaintListener(new PaintListener() {                        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 (chart == null) {                    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;                scaleX = 1.0;                scaleY = 1.0;                if (drawWidth < minimumDrawWidth) {                    scaleX = (double) drawWidth / minimumDrawWidth;                    drawWidth = minimumDrawWidth;                    scale = true;                }                else if (drawWidth > maximumDrawWidth) {                    scaleX = (double) drawWidth / maximumDrawWidth;                    drawWidth = maximumDrawWidth;                    scale = true;                }                if (drawHeight < minimumDrawHeight) {                    scaleY = (double) drawHeight / minimumDrawHeight;                    drawHeight = minimumDrawHeight;                    scale = true;                }                else if (drawHeight > maximumDrawHeight) {                    scaleY = (double) drawHeight / maximumDrawHeight;                    drawHeight = maximumDrawHeight;                    scale = true;                }                // are we using the chart buffer?                if (useBuffer) {                    //SwtGraphics2D sg2 = new SwtGraphics2D( e.gc );                    chartBuffer = (org.eclipse.swt.graphics.Image)                             canvas.getData("double-buffer-image");                    // do we need to fill the buffer?                    if (chartBuffer == null                      || chartBufferWidth != available.width                      || chartBufferHeight != available.height ) {                        chartBufferWidth = available.width;                        chartBufferHeight = available.height;                        if (chartBuffer != null) {                            chartBuffer.dispose();                        }                        chartBuffer = new org.eclipse.swt.graphics.Image(                                   getDisplay(), chartBufferWidth,                                   chartBufferHeight);                        refreshBuffer = true;                    }                    // do we need to redraw the buffer?                    if (refreshBuffer) {                        // Performs the actual drawing here ...                        GC gci = new GC(chartBuffer);                        SWTGraphics2D sg2d = new SWTGraphics2D(gci);                        if (scale) {                            sg2d.scale(scaleX, scaleY);                            chart.draw(sg2d, new Rectangle2D.Double(0, 0,                         	    drawWidth, drawHeight), getAnchor(), info);                                                    } else {                            chart.draw(sg2d, new Rectangle2D.Double(0, 0,                         	    drawWidth, drawHeight), getAnchor(), info);                                                    }                        canvas.setData("double-buffer-image", chartBuffer);                        sg2d.dispose();                        gci.dispose();                        refreshBuffer = false;                    }                                        // zap the buffer onto the canvas...                    sg2.drawImage(chartBuffer, 0, 0);                }                // or redrawing the chart every time...                else {                    chart.draw(sg2, new Rectangle2D.Double(0, 0,                         getBounds().width, getBounds().height), getAnchor(), info);                }                Rectangle area = getScreenDataArea();                //TODO see if we need to apply some line color and style to the axis traces                if (verticalAxisTrace && area.x < verticalTraceLineX                         && area.x + area.width > verticalTraceLineX)                     e.gc.drawLine(verticalTraceLineX, area.y, verticalTraceLineX, area.y + area.height);                if (horizontalAxisTrace && area.y < horizontalTraceLineY                         && area.y + area.height > horizontalTraceLineY)                     e.gc.drawLine(area.x, horizontalTraceLineY, area.x + area.width, horizontalTraceLineY);                verticalTraceLineX = 0;                horizontalTraceLineY = 0;                if (zoomRectangle != null) e.gc.drawRectangle(zoomRectangle);                sg2.dispose();            }        } );        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();            }        }        // set up popup menu...        this.popup = null;        if (properties || save || print || zoom)            this.popup = createPopupMenu(properties, save, print, zoom);        Listener listener = new Listener() {            public void handleEvent (Event event) {                switch (event.type) {                    case SWT.MouseDown:                        Rectangle scaledDataArea = getScreenDataArea(event.x, event.y);                        zoomPoint = getPointInRectangle(event.x, event.y, scaledDataArea);                        Rectangle insets = getClientArea();                        int x = (int) ((event.x - insets.x) / scaleX);                        int y = (int) ((event.y - insets.y) / scaleY);                        anchor = new Point2D.Double(x, y);                        chart.setNotify(true);  // force a redraw                         canvas.redraw();                        // new entity code...                        Object[] listeners = chartMouseListeners.getListeners(                                ChartMouseListener.class);                        if (listeners.length == 0) {                            return;                        }                        ChartEntity entity = null;                        if (info != null)                         {                            EntityCollection entities                                     = info.getEntityCollection();                            if (entities != null) {                                entity = entities.getEntity(x, y);                            }                        }                        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);                        }                        break;

⌨️ 快捷键说明

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