List of usage examples for org.jfree.chart.event ChartProgressListener ChartProgressListener
ChartProgressListener
From source file:tw.edu.sju.ee.eea.module.iepe.file.IepeVoltageElement.java
private JFreeChart createChart() { SampledChart sampledChart = new SampledChart("Voltage Oscillogram"); sampledChart.addData(0, SampledChart.createSampledSeriesCollection("Ch_0", info.getInputStream(), index, info.getSamplerate(), length)); sampledChart.addMarker(cursor);/*from ww w.j av a 2 s . c o m*/ sampledChart.addProgressListener(new ChartProgressListener() { @Override public void chartProgress(ChartProgressEvent event) { if (event.getType() == ChartProgressEvent.DRAWING_FINISHED) { if (chartMouseClicked) { info.getCursor().setTime((int) event.getChart().getXYPlot().getDomainCrosshairValue()); chartMouseClicked = false; } } } }); return sampledChart; }
From source file:com.intel.stl.ui.main.view.HealthHistoryView.java
public void setDataset(final IntervalXYDataset dataset) { JFreeChart chart = ComponentFactory.createStepAreaChart(dataset, new XYItemLabelGenerator() { @Override//from w ww .jav a 2 s . co m public String generateLabel(XYDataset dataset, int series, int item) { Number val = dataset.getY(series, item); return UIConstants.INTEGER.format(val.intValue()); } }); chart.addProgressListener(new ChartProgressListener() { @Override public void chartProgress(ChartProgressEvent event) { if (event.getType() == ChartProgressEvent.DRAWING_STARTED && currentValue != null) { currentValue.setText(scoreString); currentValue.setPaint(scoreColor); currentValue.setToolTipText(scoreTip); } } }); XYPlot plot = chart.getXYPlot(); plot.getRangeAxis().setRange(0, 105); plot.getRenderer().setSeriesPaint(0, UIConstants.INTEL_BLUE); currentValue = new TextTitle(scoreString, scoreFont); currentValue.setPaint(scoreColor); currentValue.setToolTipText(scoreTip); // currentValue.setBackgroundPaint(new Color(255, 255, 255, 128)); currentValue.setPosition(RectangleEdge.BOTTOM); XYTitleAnnotation xytitleannotation = new XYTitleAnnotation(0.49999999999999998D, 0.49999999999999998D, currentValue, RectangleAnchor.CENTER); // xytitleannotation.setMaxWidth(0.47999999999999998D); plot.addAnnotation(xytitleannotation); chartPanel.setChart(chart); }
From source file:org.mwc.debrief.track_shift.views.BaseStackedDotsView.java
/** * method to create a working plot (to contain our data) * /* ww w .j av a 2 s . c om*/ * @return the chart, in it's own panel */ @SuppressWarnings("deprecation") protected void createStackedPlot() { // first create the x (time) axis final SimpleDateFormat _df = new SimpleDateFormat("HHmm:ss"); _df.setTimeZone(TimeZone.getTimeZone("GMT")); final DateAxis xAxis = new CachedTickDateAxis(""); xAxis.setDateFormatOverride(_df); Font tickLabelFont = new Font("Courier", Font.PLAIN, 13); xAxis.setTickLabelFont(tickLabelFont); xAxis.setTickLabelPaint(Color.BLACK); xAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits()); xAxis.setAutoTickUnitSelection(true); // create the special stepper plot _dotPlot = new XYPlot(); NumberAxis errorAxis = new NumberAxis("Error (" + getUnits() + ")"); Font axisLabelFont = new Font("Courier", Font.PLAIN, 16); errorAxis.setLabelFont(axisLabelFont); errorAxis.setTickLabelFont(tickLabelFont); _dotPlot.setRangeAxis(errorAxis); _dotPlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); _dotPlot.setRenderer(new ColourStandardXYItemRenderer(null, null, _dotPlot)); _dotPlot.setRangeGridlinePaint(Color.LIGHT_GRAY); _dotPlot.setRangeGridlineStroke(new BasicStroke(2)); _dotPlot.setDomainGridlinePaint(Color.LIGHT_GRAY); _dotPlot.setDomainGridlineStroke(new BasicStroke(2)); // now try to do add a zero marker on the error bar final Paint thePaint = Color.DARK_GRAY; final Stroke theStroke = new BasicStroke(3); final ValueMarker zeroMarker = new ValueMarker(0.0, thePaint, theStroke); _dotPlot.addRangeMarker(zeroMarker); _linePlot = new XYPlot(); final NumberAxis absBrgAxis = new NumberAxis("Absolute (" + getUnits() + ")"); absBrgAxis.setLabelFont(axisLabelFont); absBrgAxis.setTickLabelFont(tickLabelFont); _linePlot.setRangeAxis(absBrgAxis); absBrgAxis.setAutoRangeIncludesZero(false); _linePlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); final DefaultXYItemRenderer lineRend = new ColourStandardXYItemRenderer(null, null, _linePlot); lineRend.setPaint(Color.DARK_GRAY); _linePlot.setRenderer(lineRend); _linePlot.setDomainCrosshairVisible(true); _linePlot.setRangeCrosshairVisible(true); _linePlot.setDomainCrosshairPaint(Color.GRAY); _linePlot.setRangeCrosshairPaint(Color.GRAY); _linePlot.setDomainCrosshairStroke(new BasicStroke(3.0f)); _linePlot.setRangeCrosshairStroke(new BasicStroke(3.0f)); _linePlot.setRangeGridlinePaint(Color.LIGHT_GRAY); _linePlot.setRangeGridlineStroke(new BasicStroke(2)); _linePlot.setDomainGridlinePaint(Color.LIGHT_GRAY); _linePlot.setDomainGridlineStroke(new BasicStroke(2)); // and the plot object to display the cross hair value final XYTextAnnotation annot = new XYTextAnnotation("-----", 2, 2); annot.setTextAnchor(TextAnchor.TOP_LEFT); Font annotationFont = new Font("Courier", Font.BOLD, 16); annot.setFont(annotationFont); annot.setPaint(Color.DARK_GRAY); annot.setBackgroundPaint(Color.white); _linePlot.addAnnotation(annot); // give them a high contrast backdrop _dotPlot.setBackgroundPaint(Color.white); _linePlot.setBackgroundPaint(Color.white); // set the y axes to autocalculate _dotPlot.getRangeAxis().setAutoRange(true); _linePlot.getRangeAxis().setAutoRange(true); _combined = new CombinedDomainXYPlot(xAxis); _combined.add(_linePlot); _combined.add(_dotPlot); _combined.setOrientation(PlotOrientation.HORIZONTAL); // put the plot into a chart _myChart = new JFreeChart(null, null, _combined, true); final LegendItemSource[] sources = { _linePlot }; _myChart.getLegend().setSources(sources); _myChart.addProgressListener(new ChartProgressListener() { public void chartProgress(final ChartProgressEvent cpe) { if (cpe.getType() != ChartProgressEvent.DRAWING_FINISHED) return; // is hte line plot visible? if (!_showLinePlot.isChecked()) return; // double-check our label is still in the right place final double xVal = _linePlot.getRangeAxis().getLowerBound(); final double yVal = _linePlot.getDomainAxis().getUpperBound(); boolean annotChanged = false; if (annot.getX() != yVal) { annot.setX(yVal); annotChanged = true; } if (annot.getY() != xVal) { annot.setY(xVal); annotChanged = true; } // and write the text final String numA = MWC.Utilities.TextFormatting.GeneralFormat .formatOneDecimalPlace(_linePlot.getRangeCrosshairValue()); final Date newDate = new Date((long) _linePlot.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(annot.getText())) { annot.setText(theMessage); annotChanged = true; } if (annotChanged) { _linePlot.removeAnnotation(annot); _linePlot.addAnnotation(annot); } } }); // and insert into the panel _holder.setChart(_myChart); // do a little tidying to reflect the memento settings if (!_showLinePlot.isChecked()) _combined.remove(_linePlot); if (!_showDotPlot.isChecked() && _showLinePlot.isChecked()) _combined.remove(_dotPlot); }
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;/*from ww w . j a va 2s . c om*/ 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:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java
/** * This is a callback that will allow us to create the viewer and initialize * it./*from ww w .ja v a2 s . com*/ */ public Composite initLegGraph(final Composite parent) { legChart = ChartFactory.createTimeSeriesChart("Ownship & Target Legs", // String "Time", // String timeAxisLabel null, // String valueAxisLabel, null, // XYDataset dataset, true, // include legend true, // tooltips false); // urls legPlot = (XYPlot) legChart.getPlot(); legPlot.setDomainCrosshairVisible(true); legPlot.setRangeCrosshairVisible(true); final DateAxis axis = (DateAxis) legPlot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); legPlot.setBackgroundPaint(java.awt.Color.WHITE); legPlot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); legPlot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); // format the cross hairs, when they're clicked legPlot.setDomainCrosshairVisible(true); legPlot.setRangeCrosshairVisible(true); legPlot.setDomainCrosshairPaint(java.awt.Color.GRAY); legPlot.setRangeCrosshairPaint(java.awt.Color.GRAY); legPlot.setDomainCrosshairStroke(new BasicStroke(1)); legPlot.setRangeCrosshairStroke(new BasicStroke(1)); // and the plot object to display the cross hair value final XYTextAnnotation annot = new XYTextAnnotation("-----", 0, 0); annot.setTextAnchor(TextAnchor.TOP_LEFT); annot.setPaint(java.awt.Color.black); annot.setBackgroundPaint(java.awt.Color.white); legPlot.addAnnotation(annot); legChart.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 = legPlot.getRangeAxis().getUpperBound(); final double yVal = legPlot.getDomainAxis().getLowerBound(); boolean annotChanged = false; if (annot.getX() != yVal) { annot.setX(yVal); annotChanged = true; } if (annot.getY() != xVal) { annot.setY(xVal); annotChanged = true; } // and write the text final NumberFormat _oneDPFormat = new DecimalFormat("0.0", new java.text.DecimalFormatSymbols(java.util.Locale.UK)); final String numA = _oneDPFormat.format(legPlot.getRangeCrosshairValue()); final Date newDate = new Date((long) legPlot.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(annot.getText())) { annot.setText(theMessage); annotChanged = true; } // aah, now we have to add and then remove the annotation in order // for the new text value to be displayed. Watch and learn... if (annotChanged) { legPlot.removeAnnotation(annot); legPlot.addAnnotation(annot); } } }); ChartComposite chartFrame = new ChartComposite(parent, SWT.NONE, legChart, true) { @Override public void mouseUp(MouseEvent event) { super.mouseUp(event); JFreeChart c = getChart(); if (c != null) { c.setNotify(true); // force redraw } } }; chartFrame.setDisplayToolTips(true); chartFrame.setHorizontalAxisTrace(false); chartFrame.setVerticalAxisTrace(false); return chartFrame; }