Example usage for org.jfree.chart.event ChartChangeListener ChartChangeListener

List of usage examples for org.jfree.chart.event ChartChangeListener ChartChangeListener

Introduction

In this page you can find the example usage for org.jfree.chart.event ChartChangeListener ChartChangeListener.

Prototype

ChartChangeListener

Source Link

Usage

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

private void createChart() {
    chart = ChartFactory.createTimeSeriesChart(null, "Time", null, null, false, false, false);
    cp = new ChartPanel(chart);
    // avoid stretching fonts and such
    cp.setMaximumDrawWidth(Integer.MAX_VALUE);
    cp.setMaximumDrawHeight(Integer.MAX_VALUE);
    XYPlot plot = chart.getXYPlot();/* w w  w  .  j a v a2 s.c  om*/
    plot.setBackgroundPaint(UIManager.getColor("TextField.background"));
    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(false);
    cp.addChartMouseListener(this);
    cp.setLayout(new DummyLayoutManager());
    cp.add(toolTip = new JToolTip());
    toolTip.setVisible(false);

    cp.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseExited(MouseEvent e) {
            disableToolTip();
        }
    });
    chart.addChangeListener(new ChartChangeListener() {
        @Override
        public void chartChanged(ChartChangeEvent e) {
            if (e.getType() == ChartChangeEventType.DATASET_UPDATED) {
                updateMaxRange();
                updateToolTipLocation();
            }
        }
    });

    for (String s : enabled) {
        addSeries(sampler.getSeries(s));
    }

    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(cp, BorderLayout.CENTER);
    legend = new JPanel();
    legend.setLayout(new FlowLayout());

    rebuildLegend();

    this.add(p, BorderLayout.CENTER);
    this.add(legend, BorderLayout.SOUTH);
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowChartJDialog.java

private void addChangeListener(ChartPanel chartPanel) {
    chartPanel.getChart().addChangeListener(new ChartChangeListener() {
        @Override/*from www  . j a va 2 s.c  o m*/
        public void chartChanged(ChartChangeEvent event) {
            if (event.getType() == ChartChangeEventType.GENERAL) {
                // Sequence is important. We will use invest information box as master.
                // ROI information box will be adjusted accordingly.
                investmentFlowLayerUI.updateInvestPoint();
                investmentFlowLayerUI.updateROIPoint();
            }
        }
    });
}

From source file:com.android.ddmuilib.log.event.EventDisplay.java

Control createCompositeChart(final Composite parent, EventLogParser logParser, String title) {
    mChart = ChartFactory.createTimeSeriesChart(null, null /* timeAxisLabel */, null /* valueAxisLabel */,
            null, /* dataset. set below */
            true /* legend */, false /* tooltips */, false /* urls */);

    // get the font to make a proper title. We need to convert the swt font,
    // into an awt font.
    Font f = parent.getFont();//w ww  .j ava 2  s  .  c o m
    FontData[] fData = f.getFontData();

    // event though on Mac OS there could be more than one fontData, we'll only use
    // the first one.
    FontData firstFontData = fData[0];

    java.awt.Font awtFont = SWTUtils.toAwtFont(parent.getDisplay(), firstFontData, true /* ensureSameSize */);

    mChart.setTitle(new TextTitle(title, awtFont));

    final XYPlot xyPlot = mChart.getXYPlot();
    xyPlot.setRangeCrosshairVisible(true);
    xyPlot.setRangeCrosshairLockedOnData(true);
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setDomainCrosshairLockedOnData(true);

    mChart.addChangeListener(new ChartChangeListener() {
        @Override
        public void chartChanged(ChartChangeEvent event) {
            ChartChangeEventType type = event.getType();
            if (type == ChartChangeEventType.GENERAL) {
                // because the value we need (rangeCrosshair and domainCrosshair) are
                // updated on the draw, but the notification happens before the draw,
                // we process the click in a future runnable!
                parent.getDisplay().asyncExec(new Runnable() {
                    @Override
                    public void run() {
                        processClick(xyPlot);
                    }
                });
            }
        }
    });

    mChartComposite = new ChartComposite(parent, SWT.BORDER, mChart, ChartComposite.DEFAULT_WIDTH,
            ChartComposite.DEFAULT_HEIGHT, ChartComposite.DEFAULT_MINIMUM_DRAW_WIDTH,
            ChartComposite.DEFAULT_MINIMUM_DRAW_HEIGHT, 3000, // max draw width. We don't want it to zoom, so we put a big number
            3000, // max draw height. We don't want it to zoom, so we put a big number
            true, // off-screen buffer
            true, // properties
            true, // save
            true, // print
            true, // zoom
            true); // tooltips

    mChartComposite.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            mValueTypeDataSetMap.clear();
            mDataSetCount = 0;
            mOccurrenceDataSet = null;
            mChart = null;
            mChartComposite = null;
            mValueDescriptorSeriesMap.clear();
            mOcurrenceDescriptorSeriesMap.clear();
        }
    });

    return mChartComposite;

}

From source file:org.mwc.cmap.xyplot.views.XYPlotView.java

@SuppressWarnings("deprecation")
private void fillThePlot(final String title, final String units, final formattingOperation theFormatter,
        final AbstractSeriesDataset dataset) {

    final StepControl _theStepper = null;

    // the working variables we rely on later
    _thePlotArea = null;/* w ww  . ja va2 s.  c o  m*/
    ValueAxis xAxis = null;

    XYToolTipGenerator tooltipGenerator = null;

    // the y axis is common to hi & lo res. Format it here
    final NumberAxis yAxis = new NumberAxis(units);
    final Font tickFont = new Font("SansSerif", Font.PLAIN, 14);
    Font labelFont = new Font("SansSerif", Font.PLAIN, 16);
    yAxis.setLabelFont(labelFont);
    yAxis.setTickLabelFont(tickFont);

    // hmm, see if we are in hi-res mode. If we are, don't use a formatted
    // y-axis, just use the plain long microseconds
    // value
    if (HiResDate.inHiResProcessingMode()) {

        // final SimpleDateFormat _secFormat = new SimpleDateFormat("ss");

        // ok, simple enough for us...
        final NumberAxis nAxis = new NumberAxis("time (secs.micros)") {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            // public String getTickLabel(double currentTickValue)
            // {
            // long time = (long) currentTickValue;
            // Date dtg = new HiResDate(0, time).getDate();
            // String res = _secFormat.format(dtg) + "."
            // + DebriefFormatDateTime.formatMicros(new HiResDate(0, time));
            // return res;
            // }
        };
        nAxis.setAutoRangeIncludesZero(false);
        xAxis = nAxis;

        // just show the raw data values
        tooltipGenerator = new StandardXYToolTipGenerator();
    } else {
        // create a date-formatting axis
        final DateAxis dAxis = new RelativeDateAxis();
        dAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits());
        xAxis = dAxis;

        // also create the date-knowledgable tooltip writer
        tooltipGenerator = new DatedToolTipGenerator();
    }

    xAxis.setTickLabelFont(tickFont);
    xAxis.setLabelFont(labelFont);

    // create the special stepper plot
    final ColourStandardXYItemRenderer theRenderer = new ColourStandardXYItemRenderer(tooltipGenerator, null,
            null);
    _thePlot = new StepperXYPlot(null, (RelativeDateAxis) xAxis, yAxis, _theStepper, theRenderer);
    theRenderer.setPlot(_thePlot);
    theRenderer.setStroke(new BasicStroke(3.0f));

    _thePlot.setRangeGridlineStroke(new BasicStroke(1f));
    _thePlot.setDomainGridlineStroke(new BasicStroke(1f));
    _thePlot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    xAxis.setTickMarkStroke(new BasicStroke(1f));
    yAxis.setTickMarkStroke(new BasicStroke(1f));
    _thePlot.setOutlineStroke(new BasicStroke(2f));

    // loop through the datasets, setting the color of each series to the first
    // color in that series
    if (dataset instanceof TimeSeriesCollection) {
        Color seriesCol = null;
        final TimeSeriesCollection tsc = (TimeSeriesCollection) dataset;
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            final TimeSeries ts = tsc.getSeries(i);
            if (ts.getItemCount() > 0) {
                final TimeSeriesDataItem dataItem = ts.getDataItem(0);
                if (dataItem instanceof ColouredDataItem) {
                    final ColouredDataItem cd = (ColouredDataItem) dataItem;
                    seriesCol = cd.getColor();
                    _thePlot.getRenderer().setSeriesPaint(i, seriesCol);
                }
            }
        }
    }

    // apply any formatting for this choice
    if (theFormatter != null) {
        theFormatter.format(_thePlot);
    }

    boolean createLegend = dataset.getSeriesCount() > 1;
    _thePlotArea = new NewFormattedJFreeChart(title, null, _thePlot, createLegend, _theStepper);

    // set the color of the area surrounding the plot
    // - naah, don't bother. leave it in the application background color.
    _thePlotArea.setBackgroundPaint(Color.white);

    // ////////////////////////////////////////////////
    // put the holder into one of our special items
    // ////////////////////////////////////////////////
    _chartInPanel = new StepperChartPanel(_thePlotArea, true, _theStepper);

    // ok - we need to fire time-changes to the chart
    setupFiringChangesToChart();

    // format the chart
    _chartInPanel.setName(title);
    _chartInPanel.setMouseZoomable(true, true);

    // and insert into the composite
    _plotControl.setChart(_thePlotArea);

    // get the cross hairs ready
    _thePlot.setDomainCrosshairVisible(true);
    _thePlot.setRangeCrosshairVisible(true);
    _thePlot.setDomainCrosshairPaint(Color.GRAY);
    _thePlot.setRangeCrosshairPaint(Color.GRAY);
    _thePlot.setDomainCrosshairStroke(new BasicStroke(2));
    _thePlot.setRangeCrosshairStroke(new BasicStroke(2));

    // and the plot object to display the cross hair value
    _crosshairValueText = new XYTextAnnotation(" ", 0, 0);
    _crosshairValueText.setTextAnchor(TextAnchor.TOP_LEFT);
    _crosshairValueText.setFont(new Font("SansSerif", Font.BOLD, 15));
    _crosshairValueText.setPaint(Color.black);
    _crosshairValueText.setBackgroundPaint(Color.white);
    _thePlot.addAnnotation(_crosshairValueText);

    _thePlotArea.addChangeListener(new ChartChangeListener() {

        @Override
        public void chartChanged(ChartChangeEvent event) {
            if (_showSymbols.isShowSymbols() != _thePlotArea.isShowSymbols()) {
                _showSymbols.updateAction();
            }
        }
    });
    _showSymbols.updateAction();
    _thePlotArea.addProgressListener(new ChartProgressListener() {
        public void chartProgress(final ChartProgressEvent cpe) {
            if (cpe.getType() != ChartProgressEvent.DRAWING_FINISHED)
                return;

            // double-check our label is still in the right place
            final double xVal = _thePlot.getRangeAxis().getUpperBound();
            final double yVal = _thePlot.getDomainAxis().getLowerBound();

            boolean annotChanged = false;
            if (_crosshairValueText.getX() != yVal) {
                _crosshairValueText.setX(yVal);
                annotChanged = true;
            }
            if (_crosshairValueText.getY() != xVal) {
                _crosshairValueText.setY(xVal);
                annotChanged = true;
            }

            // and write the text
            final String numA = MWC.Utilities.TextFormatting.GeneralFormat
                    .formatOneDecimalPlace(_thePlot.getRangeCrosshairValue());
            final Date newDate = new Date((long) _thePlot.getDomainCrosshairValue());
            final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss");
            _df.setTimeZone(TimeZone.getTimeZone("GMT"));
            final String dateVal = _df.format(newDate);
            final String theMessage = " [" + dateVal + "," + numA + "]";
            if (!theMessage.equals(_crosshairValueText.getText())) {
                _crosshairValueText.setText(theMessage);
                annotChanged = true;
            }

            if (annotChanged) {
                _plotControl.getChart().setNotify(true);
            }
        }
    });

    // ////////////////////////////////////////////////////
    // put the time series into the plot
    // ////////////////////////////////////////////////////
    _thePlot.setDataset((XYDataset) dataset);
}

From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java

/**
 * Returns chart change listener, which will be responsible for handling
 * zooming event./*from  ww w  .  j a v a2s . c  o  m*/
 *
 * @return chart change listener, which will be responsible for handling
 * zooming event
 */
private ChartChangeListener getChartChangeListner() {
    return new ChartChangeListener() {
        @Override
        public void chartChanged(ChartChangeEvent event) {
            // Is weird. This works well for zoom-in. When we add new CCI or
            // RIS. This event function will be triggered too. However, the
            // returned draw area will always be the old draw area, unless
            // you move your move over.
            // Even I try to capture event.getType() == ChartChangeEventType.NEW_DATASET
            // also doesn't work.
            if (event.getType() == ChartChangeEventType.GENERAL) {
                ChartJDialog.this.chartLayerUI.updateTraceInfos();
                // Re-calculating high low value.
                ChartJDialog.this.updateHighLowJLabels();
            }
        }
    };
}