/** * Draws the annotation. This method is called by the drawing code in the {@link XYPlot} class, * you don't normally need to call this method directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation); float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } xx = xx - this.image.getWidth(null) / 2.0f; yy = yy - this.image.getHeight(null) / 2.0f; g2.drawImage(this.image, (int) xx, (int) yy, null); }
@Test public void testAxisLocationIndices() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); CategoryAxis xAxis2 = new CategoryAxis("X2"); NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setDomainAxis(99, xAxis2); plot.setRangeAxis(99, yAxis2); plot.setDomainAxisLocation(99, AxisLocation.BOTTOM_OR_RIGHT); assertEquals(AxisLocation.BOTTOM_OR_RIGHT, plot.getDomainAxisLocation(99)); plot.setRangeAxisLocation(99, AxisLocation.BOTTOM_OR_LEFT); assertEquals(AxisLocation.BOTTOM_OR_LEFT, plot.getRangeAxisLocation(99)); }
/** * Creates a new instance. * * @param scale the scale (<code>null</code> not permitted). * @param axis the axis (<code>null</code> not permitted). */ public PaintScaleLegend(PaintScale scale, ValueAxis axis) { ParamChecks.nullNotPermitted(axis, "axis"); this.scale = scale; this.axis = axis; this.axis.addChangeListener(this); this.axisLocation = AxisLocation.BOTTOM_OR_LEFT; this.axisOffset = 0.0; this.axis.setRange(scale.getLowerBound(), scale.getUpperBound()); this.stripWidth = 15.0; this.stripOutlineVisible = true; this.stripOutlinePaint = Color.gray; this.stripOutlineStroke = new BasicStroke(0.5f); this.backgroundPaint = Color.white; this.subdivisions = 100; }
/** * Creates a new instance. * * @param scale the scale ({@code null} not permitted). * @param axis the axis ({@code null} not permitted). */ public PaintScaleLegend(PaintScale scale, ValueAxis axis) { Args.nullNotPermitted(axis, "axis"); this.scale = scale; this.axis = axis; this.axis.addChangeListener(this); this.axisLocation = AxisLocation.BOTTOM_OR_LEFT; this.axisOffset = 0.0; this.axis.setRange(scale.getLowerBound(), scale.getUpperBound()); this.stripWidth = 15.0; this.stripOutlineVisible = true; this.stripOutlinePaint = Color.GRAY; this.stripOutlineStroke = new BasicStroke(0.5f); this.backgroundPaint = Color.WHITE; this.subdivisions = 100; }
@Test public void testAxisLocationIndices() { XYDataset dataset = new XYSeriesCollection(); NumberAxis xAxis = new NumberAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); XYItemRenderer renderer = new DefaultXYItemRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); NumberAxis xAxis2 = new NumberAxis("X2"); NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setDomainAxis(99, xAxis2); plot.setRangeAxis(99, yAxis2); plot.setDomainAxisLocation(99, AxisLocation.BOTTOM_OR_RIGHT); assertEquals(AxisLocation.BOTTOM_OR_RIGHT, plot.getDomainAxisLocation(99)); plot.setRangeAxisLocation(99, AxisLocation.BOTTOM_OR_LEFT); assertEquals(AxisLocation.BOTTOM_OR_LEFT, plot.getRangeAxisLocation(99)); }
/** * Specifies the axis location. * It has to be overridden for child themes with another default axis location */ protected AxisLocation getChartAxisLocation(JRChartAxis chartAxis) { if (chartAxis.getPositionValue() != null) { switch (chartAxis.getPositionValue()) { case RIGHT_OR_BOTTOM : return AxisLocation.BOTTOM_OR_RIGHT; default: return AxisLocation.TOP_OR_LEFT; } } else { return (AxisLocation)getDefaultValue(defaultAxisPropertiesMap, ChartThemesConstants.AXIS_LOCATION); } }
@Override public Object convertUponSet(Object value) { if (value == null) { return null; } return AxisLocation.BOTTOM_OR_LEFT.toString().equals(value) ? AxisLocation.BOTTOM_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT.toString().equals(value) ? AxisLocation.BOTTOM_OR_RIGHT : AxisLocation.TOP_OR_LEFT.toString().equals(value) ? AxisLocation.TOP_OR_LEFT : AxisLocation.TOP_OR_RIGHT.toString().equals(value) ? AxisLocation.TOP_OR_RIGHT : null; }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedDomainXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedRangeXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Range")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
/** * Sets the location of the domain axis and, if requested, sends a {@link PlotChangeEvent} to * all registered listeners. * * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? */ public void setDomainAxisLocation(AxisLocation location, boolean notify) { if (location == null) { throw new IllegalArgumentException("Null 'location' argument."); } this.domainAxisLocations.set(0, location); if (notify) { notifyListeners(new PlotChangeEvent(this)); } }
/** * Returns the edge for a domain axis. * * @param index the axis index. * * @return The edge. */ public RectangleEdge getDomainAxisEdge(int index) { AxisLocation location = getDomainAxisLocation(index); RectangleEdge result = Plot.resolveDomainAxisLocation(location, this.orientation); if (result == null) { result = RectangleEdge.opposite(getDomainAxisEdge()); } return result; }
/** * Sets the location of the primary range axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? */ public void setRangeAxisLocation(AxisLocation location, boolean notify) { if (location == null) { throw new IllegalArgumentException("Null 'location' argument."); } this.rangeAxisLocations.set(0, location); if (notify) { notifyListeners(new PlotChangeEvent(this)); } }
/** * Returns the edge for a range axis. * * @param index the axis index. * * @return The edge. */ public RectangleEdge getRangeAxisEdge(int index) { AxisLocation location = getRangeAxisLocation(index); RectangleEdge result = Plot.resolveRangeAxisLocation(location, this.orientation); if (result == null) { result = RectangleEdge.opposite(getRangeAxisEdge()); } return result; }
/** * Sets the location of the domain axis. * * @param location the axis location (<code>null</code> not permitted). * @param notify a flag that controls whether listeners are notified. */ public void setDomainAxisLocation(AxisLocation location, boolean notify) { if (location == null) { throw new IllegalArgumentException("Null 'location' argument."); } setDomainAxisLocation(0, location); }
/** * Returns the edge for a domain axis. * * @param index the axis index. * * @return The edge (never <code>null</code>). */ public RectangleEdge getDomainAxisEdge(int index) { RectangleEdge result = null; AxisLocation location = getDomainAxisLocation(index); if (location != null) { result = Plot.resolveDomainAxisLocation(location, this.orientation); } else { result = RectangleEdge.opposite(getDomainAxisEdge(0)); } return result; }
/** * Returns the edge for a range axis. * * @param index the axis index. * * @return The edge. */ public RectangleEdge getRangeAxisEdge(int index) { AxisLocation location = getRangeAxisLocation(index); RectangleEdge result = Plot.resolveRangeAxisLocation(location, this.orientation); if (result == null) { result = RectangleEdge.opposite(getRangeAxisEdge(0)); } return result; }
/** * Problem equals method. */ public void testEquals() { assertEquals(AxisLocation.TOP_OR_RIGHT, AxisLocation.TOP_OR_RIGHT); assertEquals(AxisLocation.BOTTOM_OR_RIGHT, AxisLocation.BOTTOM_OR_RIGHT); assertEquals(AxisLocation.TOP_OR_LEFT, AxisLocation.TOP_OR_LEFT); assertEquals(AxisLocation.BOTTOM_OR_LEFT, AxisLocation.BOTTOM_OR_LEFT); }
/** * Some checks for the equals() method. */ public void testEquals() { assertEquals(AxisLocation.TOP_OR_RIGHT, AxisLocation.TOP_OR_RIGHT); assertEquals( AxisLocation.BOTTOM_OR_RIGHT, AxisLocation.BOTTOM_OR_RIGHT ); assertEquals(AxisLocation.TOP_OR_LEFT, AxisLocation.TOP_OR_LEFT); assertEquals(AxisLocation.BOTTOM_OR_LEFT, AxisLocation.BOTTOM_OR_LEFT); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { AxisLocation a1 = AxisLocation.TOP_OR_RIGHT; AxisLocation a2 = AxisLocation.TOP_OR_RIGHT; assertTrue(a1.equals(a2)); int h1 = a1.hashCode(); int h2 = a2.hashCode(); assertEquals(h1, h2); }
/** * Creates a new instance. * * @param scale the scale (<code>null</code> not permitted). * @param axis the axis (<code>null</code> not permitted). */ public PaintScaleLegend(PaintScale scale, ValueAxis axis) { if (axis == null) { throw new IllegalArgumentException("Null 'axis' argument."); } this.scale = scale; this.axis = axis; this.axisLocation = AxisLocation.BOTTOM_OR_LEFT; this.axisOffset = 0.0; this.stripWidth = 15.0; this.stripOutlineVisible = false; this.stripOutlinePaint = Color.gray; this.stripOutlineStroke = new BasicStroke(0.5f); this.backgroundPaint = Color.white; }
/** * Returns the edge for a domain axis. * * @param index the axis index. * * @return The edge. * * @see #getRangeAxisEdge(int) */ public RectangleEdge getDomainAxisEdge(int index) { AxisLocation location = getDomainAxisLocation(index); RectangleEdge result = Plot.resolveDomainAxisLocation(location, this.orientation); if (result == null) { result = RectangleEdge.opposite(getDomainAxisEdge()); } return result; }
/** * Sets the location for a range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. * @param notify notify listeners? * * @see #getRangeAxisLocation(int) * @see #setDomainAxisLocation(int, AxisLocation, boolean) */ public void setRangeAxisLocation(int index, AxisLocation location, boolean notify) { if (index == 0 && location == null) { throw new IllegalArgumentException( "Null 'location' for index 0 not permitted."); } this.rangeAxisLocations.set(index, location); if (notify) { notifyListeners(new PlotChangeEvent(this)); } }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedDomainXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedDomainXYPlot plot = new CombinedDomainXYPlot( new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
/** * This test covers a flaw in the ObjectList equals() method. */ @Test public void testEquals_ObjectList2() { CategoryPlot p1 = new CategoryPlot(); p1.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryPlot p2 = new CategoryPlot(); p2.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); assertEquals(p1, p2); p2.setDomainAxisLocation(1, AxisLocation.TOP_OR_LEFT); assertNotEquals(p1, p2); }
/** * This test covers a flaw in the ObjectList equals() method. */ @Test public void testEquals_ObjectList4() { CategoryPlot p1 = new CategoryPlot(); p1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); CategoryPlot p2 = new CategoryPlot(); p2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); assertEquals(p1, p2); p2.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT); assertNotEquals(p1, p2); }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedRangeXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis xAxis1 = new NumberAxis("X1"); XYPlot subplot1 = new XYPlot(data1, xAxis1, null, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis xAxis2 = new NumberAxis("X2"); xAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, xAxis2, null, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis( "Range")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
/** * This test covers a flaw in the ObjectList equals() method. */ @Test public void testEquals_ObjectList2() { XYPlot p1 = new XYPlot(); p1.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); XYPlot p2 = new XYPlot(); p2.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); assertEquals(p1, p2); p2.setDomainAxisLocation(1, AxisLocation.TOP_OR_LEFT); assertNotEquals(p1, p2); }
/** * This test covers a flaw in the ObjectList equals() method. */ @Test public void testEquals_ObjectList4() { XYPlot p1 = new XYPlot(); p1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); XYPlot p2 = new XYPlot(); p2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); assertEquals(p1, p2); p2.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT); assertNotEquals(p1, p2); }
/** * Returns the edge for a domain axis. * * @param index the axis index. * * @return The edge (never <code>null</code>). */ public RectangleEdge getDomainAxisEdge(int index) { RectangleEdge result; AxisLocation location = getDomainAxisLocation(index); if (location != null) { result = Plot.resolveDomainAxisLocation(location, this.orientation); } else { result = RectangleEdge.opposite(getDomainAxisEdge(0)); } return result; }
/** * Sets the location for a range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. * @param notify notify listeners? * * @see #getRangeAxisLocation(int) * @see #setDomainAxisLocation(int, AxisLocation, boolean) */ public void setRangeAxisLocation(int index, AxisLocation location, boolean notify) { if (index == 0 && location == null) { throw new IllegalArgumentException( "Null 'location' for index 0 not permitted."); } this.rangeAxisLocations.put(index, location); if (notify) { fireChangeEvent(); } }