1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ddmuilib.log.event; 18 19 import org.jfree.chart.axis.ValueAxis; 20 import org.jfree.chart.plot.CrosshairState; 21 import org.jfree.chart.plot.PlotOrientation; 22 import org.jfree.chart.plot.PlotRenderingInfo; 23 import org.jfree.chart.plot.XYPlot; 24 import org.jfree.chart.renderer.xy.XYItemRendererState; 25 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 26 import org.jfree.data.time.TimeSeriesCollection; 27 import org.jfree.data.xy.XYDataset; 28 import org.jfree.ui.RectangleEdge; 29 30 import java.awt.Graphics2D; 31 import java.awt.Paint; 32 import java.awt.Stroke; 33 import java.awt.geom.Line2D; 34 import java.awt.geom.Rectangle2D; 35 36 /** 37 * Custom renderer to render event occurrence. This rendered ignores the y value, and simply 38 * draws a line from min to max at the time of the item. 39 */ 40 public class OccurrenceRenderer extends XYLineAndShapeRenderer { 41 42 private static final long serialVersionUID = 1L; 43 44 @Override drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass)45 public void drawItem(Graphics2D g2, 46 XYItemRendererState state, 47 Rectangle2D dataArea, 48 PlotRenderingInfo info, 49 XYPlot plot, 50 ValueAxis domainAxis, 51 ValueAxis rangeAxis, 52 XYDataset dataset, 53 int series, 54 int item, 55 CrosshairState crosshairState, 56 int pass) { 57 TimeSeriesCollection timeDataSet = (TimeSeriesCollection)dataset; 58 59 // get the x value for the series/item. 60 double x = timeDataSet.getX(series, item).doubleValue(); 61 62 // get the min/max of the range axis 63 double yMin = rangeAxis.getLowerBound(); 64 double yMax = rangeAxis.getUpperBound(); 65 66 RectangleEdge domainEdge = plot.getDomainAxisEdge(); 67 RectangleEdge rangeEdge = plot.getRangeAxisEdge(); 68 69 // convert the coordinates to java2d. 70 double x2D = domainAxis.valueToJava2D(x, dataArea, domainEdge); 71 double yMin2D = rangeAxis.valueToJava2D(yMin, dataArea, rangeEdge); 72 double yMax2D = rangeAxis.valueToJava2D(yMax, dataArea, rangeEdge); 73 74 // get the paint information for the series/item 75 Paint p = getItemPaint(series, item); 76 Stroke s = getItemStroke(series, item); 77 78 Line2D line = null; 79 PlotOrientation orientation = plot.getOrientation(); 80 if (orientation == PlotOrientation.HORIZONTAL) { 81 line = new Line2D.Double(yMin2D, x2D, yMax2D, x2D); 82 } 83 else if (orientation == PlotOrientation.VERTICAL) { 84 line = new Line2D.Double(x2D, yMin2D, x2D, yMax2D); 85 } 86 g2.setPaint(p); 87 g2.setStroke(s); 88 g2.draw(line); 89 } 90 } 91