Example usage for org.jfree.chart.axis NumberAxis setTickMarkStroke

List of usage examples for org.jfree.chart.axis NumberAxis setTickMarkStroke

Introduction

In this page you can find the example usage for org.jfree.chart.axis NumberAxis setTickMarkStroke.

Prototype

public void setTickMarkStroke(Stroke stroke) 

Source Link

Document

Sets the stroke used to draw tick marks and sends an AxisChangeEvent to all registered listeners.

Usage

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;// ww  w.j a  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);
}