001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
006     *
007     * Project Info:  http://www.jfree.org/jfreechart/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it
010     * under the terms of the GNU Lesser General Public License as published by
011     * the Free Software Foundation; either version 2.1 of the License, or
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022     * USA.
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025     * in the United States and other countries.]
026     *
027     * ------------------
028     * BarRenderer3D.java
029     * ------------------
030     * (C) Copyright 2001-2008, by Serge V. Grachov and Contributors.
031     *
032     * Original Author:  Serge V. Grachov;
033     * Contributor(s):   David Gilbert (for Object Refinery Limited);
034     *                   Tin Luu;
035     *                   Milo Simpson;
036     *                   Richard Atkinson;
037     *                   Rich Unger;
038     *                   Christian W. Zuckschwerdt;
039     *
040     * Changes
041     * -------
042     * 31-Oct-2001 : First version, contributed by Serge V. Grachov (DG);
043     * 15-Nov-2001 : Modified to allow for null data values (DG);
044     * 13-Dec-2001 : Added tooltips (DG);
045     * 16-Jan-2002 : Added fix for single category or single series datasets,
046     *               pointed out by Taoufik Romdhane (DG);
047     * 24-May-2002 : Incorporated tooltips into chart entities (DG);
048     * 11-Jun-2002 : Added check for (permitted) null info object, bug and fix
049     *               reported by David Basten.  Also updated Javadocs. (DG);
050     * 19-Jun-2002 : Added code to draw labels on bars (TL);
051     * 26-Jun-2002 : Added bar clipping to avoid PRExceptions (DG);
052     * 05-Aug-2002 : Small modification to drawCategoryItem method to support URLs
053     *               for HTML image maps (RA);
054     * 06-Aug-2002 : Value labels now use number formatter, thanks to Milo
055     *               Simpson (DG);
056     * 08-Aug-2002 : Applied fixed in bug id 592218 (DG);
057     * 20-Sep-2002 : Added fix for categoryPaint by Rich Unger, and fixed errors
058     *               reported by Checkstyle (DG);
059     * 24-Oct-2002 : Amendments for changes in CategoryDataset interface and
060     *               CategoryToolTipGenerator interface (DG);
061     * 05-Nov-2002 : Replaced references to CategoryDataset with TableDataset (DG);
062     * 06-Nov-2002 : Moved to the com.jrefinery.chart.renderer package (DG);
063     * 28-Jan-2003 : Added an attribute to control the shading of the left and
064     *               bottom walls in the plot background (DG);
065     * 25-Mar-2003 : Implemented Serializable (DG);
066     * 10-Apr-2003 : Removed category paint usage (DG);
067     * 13-May-2003 : Renamed VerticalBarRenderer3D --> BarRenderer3D and merged with
068     *               HorizontalBarRenderer3D (DG);
069     * 30-Jul-2003 : Modified entity constructor (CZ);
070     * 19-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
071     * 07-Oct-2003 : Added renderer state (DG);
072     * 08-Oct-2003 : Removed clipping (replaced with flag in CategoryPlot to
073     *               control order in which the data items are processed) (DG);
074     * 20-Oct-2003 : Fixed bug (outline stroke not being used for bar
075     *               outlines) (DG);
076     * 21-Oct-2003 : Bar width moved into CategoryItemRendererState (DG);
077     * 24-Nov-2003 : Fixed bug 846324 (item labels not showing) (DG);
078     * 27-Nov-2003 : Added code to respect maxBarWidth setting (DG);
079     * 02-Feb-2004 : Fixed bug where 'drawBarOutline' flag is not respected (DG);
080     * 10-Feb-2004 : Small change to drawItem() method to make cut-and-paste
081     *               overriding easier (DG);
082     * 04-Oct-2004 : Fixed bug with item label positioning when plot alignment is
083     *               horizontal (DG);
084     * 05-Nov-2004 : Modified drawItem() signature (DG);
085     * 20-Apr-2005 : Renamed CategoryLabelGenerator
086     *               --> CategoryItemLabelGenerator (DG);
087     * 25-Apr-2005 : Override initialise() method to fix bug 1189642 (DG);
088     * 09-Jun-2005 : Use addEntityItem from super class (DG);
089     * ------------- JFREECHART 1.0.x ---------------------------------------------
090     * 07-Dec-2006 : Implemented equals() override (DG);
091     * 17-Jan-2007 : Fixed bug in drawDomainGridline() method (DG);
092     * 03-Apr-2007 : Fixed bugs in drawBackground() method (DG);
093     * 16-Oct-2007 : Fixed bug in range marker drawing (DG);
094     *
095     */
096    
097    package org.jfree.chart.renderer.category;
098    
099    import java.awt.AlphaComposite;
100    import java.awt.Color;
101    import java.awt.Composite;
102    import java.awt.Font;
103    import java.awt.Graphics2D;
104    import java.awt.Image;
105    import java.awt.Paint;
106    import java.awt.Stroke;
107    import java.awt.geom.GeneralPath;
108    import java.awt.geom.Line2D;
109    import java.awt.geom.Point2D;
110    import java.awt.geom.Rectangle2D;
111    import java.io.IOException;
112    import java.io.ObjectInputStream;
113    import java.io.ObjectOutputStream;
114    import java.io.Serializable;
115    
116    import org.jfree.chart.Effect3D;
117    import org.jfree.chart.axis.CategoryAxis;
118    import org.jfree.chart.axis.ValueAxis;
119    import org.jfree.chart.entity.EntityCollection;
120    import org.jfree.chart.event.RendererChangeEvent;
121    import org.jfree.chart.labels.CategoryItemLabelGenerator;
122    import org.jfree.chart.labels.ItemLabelAnchor;
123    import org.jfree.chart.labels.ItemLabelPosition;
124    import org.jfree.chart.plot.CategoryPlot;
125    import org.jfree.chart.plot.Marker;
126    import org.jfree.chart.plot.Plot;
127    import org.jfree.chart.plot.PlotOrientation;
128    import org.jfree.chart.plot.PlotRenderingInfo;
129    import org.jfree.chart.plot.ValueMarker;
130    import org.jfree.data.Range;
131    import org.jfree.data.category.CategoryDataset;
132    import org.jfree.io.SerialUtilities;
133    import org.jfree.text.TextUtilities;
134    import org.jfree.ui.LengthAdjustmentType;
135    import org.jfree.ui.RectangleAnchor;
136    import org.jfree.ui.RectangleEdge;
137    import org.jfree.ui.TextAnchor;
138    import org.jfree.util.PaintUtilities;
139    import org.jfree.util.PublicCloneable;
140    
141    /**
142     * A renderer for bars with a 3D effect, for use with the
143     * {@link CategoryPlot} class.  The example shown here is generated
144     * by the <code>BarChart3DDemo1.java</code> program included in the JFreeChart
145     * Demo Collection:
146     * <br><br>
147     * <img src="../../../../../images/BarRenderer3DSample.png"
148     * alt="BarRenderer3DSample.png" />
149     */
150    public class BarRenderer3D extends BarRenderer
151            implements Effect3D, Cloneable, PublicCloneable, Serializable {
152    
153        /** For serialization. */
154        private static final long serialVersionUID = 7686976503536003636L;
155    
156        /** The default x-offset for the 3D effect. */
157        public static final double DEFAULT_X_OFFSET = 12.0;
158    
159        /** The default y-offset for the 3D effect. */
160        public static final double DEFAULT_Y_OFFSET = 8.0;
161    
162        /** The default wall paint. */
163        public static final Paint DEFAULT_WALL_PAINT = new Color(0xDD, 0xDD, 0xDD);
164    
165        /** The size of x-offset for the 3D effect. */
166        private double xOffset;
167    
168        /** The size of y-offset for the 3D effect. */
169        private double yOffset;
170    
171        /** The paint used to shade the left and lower 3D wall. */
172        private transient Paint wallPaint;
173    
174        /**
175         * Default constructor, creates a renderer with a default '3D effect'.
176         */
177        public BarRenderer3D() {
178            this(DEFAULT_X_OFFSET, DEFAULT_Y_OFFSET);
179        }
180    
181        /**
182         * Constructs a new renderer with the specified '3D effect'.
183         *
184         * @param xOffset  the x-offset for the 3D effect.
185         * @param yOffset  the y-offset for the 3D effect.
186         */
187        public BarRenderer3D(double xOffset, double yOffset) {
188    
189            super();
190            this.xOffset = xOffset;
191            this.yOffset = yOffset;
192            this.wallPaint = DEFAULT_WALL_PAINT;
193            // set the default item label positions
194            ItemLabelPosition p1 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
195                    TextAnchor.TOP_CENTER);
196            setBasePositiveItemLabelPosition(p1);
197            ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.INSIDE12,
198                    TextAnchor.TOP_CENTER);
199            setBaseNegativeItemLabelPosition(p2);
200    
201        }
202    
203        /**
204         * Returns the x-offset for the 3D effect.
205         *
206         * @return The 3D effect.
207         *
208         * @see #getYOffset()
209         */
210        public double getXOffset() {
211            return this.xOffset;
212        }
213    
214        /**
215         * Returns the y-offset for the 3D effect.
216         *
217         * @return The 3D effect.
218         */
219        public double getYOffset() {
220            return this.yOffset;
221        }
222    
223        /**
224         * Returns the paint used to highlight the left and bottom wall in the plot
225         * background.
226         *
227         * @return The paint.
228         *
229         * @see #setWallPaint(Paint)
230         */
231        public Paint getWallPaint() {
232            return this.wallPaint;
233        }
234    
235        /**
236         * Sets the paint used to hightlight the left and bottom walls in the plot
237         * background, and sends a {@link RendererChangeEvent} to all registered
238         * listeners.
239         *
240         * @param paint  the paint (<code>null</code> not permitted).
241         *
242         * @see #getWallPaint()
243         */
244        public void setWallPaint(Paint paint) {
245            if (paint == null) {
246                throw new IllegalArgumentException("Null 'paint' argument.");
247            }
248            this.wallPaint = paint;
249            fireChangeEvent();
250        }
251    
252    
253        /**
254         * Initialises the renderer and returns a state object that will be passed
255         * to subsequent calls to the drawItem method.  This method gets called
256         * once at the start of the process of drawing a chart.
257         *
258         * @param g2  the graphics device.
259         * @param dataArea  the area in which the data is to be plotted.
260         * @param plot  the plot.
261         * @param rendererIndex  the renderer index.
262         * @param info  collects chart rendering information for return to caller.
263         *
264         * @return The renderer state.
265         */
266        public CategoryItemRendererState initialise(Graphics2D g2,
267                                                    Rectangle2D dataArea,
268                                                    CategoryPlot plot,
269                                                    int rendererIndex,
270                                                    PlotRenderingInfo info) {
271    
272            Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(),
273                    dataArea.getY() + getYOffset(), dataArea.getWidth()
274                    - getXOffset(), dataArea.getHeight() - getYOffset());
275            CategoryItemRendererState state = super.initialise(g2, adjusted, plot,
276                    rendererIndex, info);
277            return state;
278    
279        }
280    
281        /**
282         * Draws the background for the plot.
283         *
284         * @param g2  the graphics device.
285         * @param plot  the plot.
286         * @param dataArea  the area inside the axes.
287         */
288        public void drawBackground(Graphics2D g2, CategoryPlot plot,
289                                   Rectangle2D dataArea) {
290    
291            float x0 = (float) dataArea.getX();
292            float x1 = x0 + (float) Math.abs(this.xOffset);
293            float x3 = (float) dataArea.getMaxX();
294            float x2 = x3 - (float) Math.abs(this.xOffset);
295    
296            float y0 = (float) dataArea.getMaxY();
297            float y1 = y0 - (float) Math.abs(this.yOffset);
298            float y3 = (float) dataArea.getMinY();
299            float y2 = y3 + (float) Math.abs(this.yOffset);
300    
301            GeneralPath clip = new GeneralPath();
302            clip.moveTo(x0, y0);
303            clip.lineTo(x0, y2);
304            clip.lineTo(x1, y3);
305            clip.lineTo(x3, y3);
306            clip.lineTo(x3, y1);
307            clip.lineTo(x2, y0);
308            clip.closePath();
309    
310            Composite originalComposite = g2.getComposite();
311            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
312                    plot.getBackgroundAlpha()));
313    
314            // fill background...
315            Paint backgroundPaint = plot.getBackgroundPaint();
316            if (backgroundPaint != null) {
317                g2.setPaint(backgroundPaint);
318                g2.fill(clip);
319            }
320    
321            GeneralPath leftWall = new GeneralPath();
322            leftWall.moveTo(x0, y0);
323            leftWall.lineTo(x0, y2);
324            leftWall.lineTo(x1, y3);
325            leftWall.lineTo(x1, y1);
326            leftWall.closePath();
327            g2.setPaint(getWallPaint());
328            g2.fill(leftWall);
329    
330            GeneralPath bottomWall = new GeneralPath();
331            bottomWall.moveTo(x0, y0);
332            bottomWall.lineTo(x1, y1);
333            bottomWall.lineTo(x3, y1);
334            bottomWall.lineTo(x2, y0);
335            bottomWall.closePath();
336            g2.setPaint(getWallPaint());
337            g2.fill(bottomWall);
338    
339            // highlight the background corners...
340            g2.setPaint(Color.lightGray);
341            Line2D corner = new Line2D.Double(x0, y0, x1, y1);
342            g2.draw(corner);
343            corner.setLine(x1, y1, x1, y3);
344            g2.draw(corner);
345            corner.setLine(x1, y1, x3, y1);
346            g2.draw(corner);
347    
348            // draw background image, if there is one...
349            Image backgroundImage = plot.getBackgroundImage();
350            if (backgroundImage != null) {
351                Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX()
352                        + getXOffset(), dataArea.getY(),
353                        dataArea.getWidth() - getXOffset(),
354                        dataArea.getHeight() - getYOffset());
355                plot.drawBackgroundImage(g2, adjusted);
356            }
357    
358            g2.setComposite(originalComposite);
359    
360        }
361    
362        /**
363         * Draws the outline for the plot.
364         *
365         * @param g2  the graphics device.
366         * @param plot  the plot.
367         * @param dataArea  the area inside the axes.
368         */
369        public void drawOutline(Graphics2D g2, CategoryPlot plot,
370                                Rectangle2D dataArea) {
371    
372            float x0 = (float) dataArea.getX();
373            float x1 = x0 + (float) Math.abs(this.xOffset);
374            float x3 = (float) dataArea.getMaxX();
375            float x2 = x3 - (float) Math.abs(this.xOffset);
376    
377            float y0 = (float) dataArea.getMaxY();
378            float y1 = y0 - (float) Math.abs(this.yOffset);
379            float y3 = (float) dataArea.getMinY();
380            float y2 = y3 + (float) Math.abs(this.yOffset);
381    
382            GeneralPath clip = new GeneralPath();
383            clip.moveTo(x0, y0);
384            clip.lineTo(x0, y2);
385            clip.lineTo(x1, y3);
386            clip.lineTo(x3, y3);
387            clip.lineTo(x3, y1);
388            clip.lineTo(x2, y0);
389            clip.closePath();
390    
391            // put an outline around the data area...
392            Stroke outlineStroke = plot.getOutlineStroke();
393            Paint outlinePaint = plot.getOutlinePaint();
394            if ((outlineStroke != null) && (outlinePaint != null)) {
395                g2.setStroke(outlineStroke);
396                g2.setPaint(outlinePaint);
397                g2.draw(clip);
398            }
399    
400        }
401    
402        /**
403         * Draws a grid line against the domain axis.
404         *
405         * @param g2  the graphics device.
406         * @param plot  the plot.
407         * @param dataArea  the area for plotting data (not yet adjusted for any
408         *                  3D effect).
409         * @param value  the Java2D value at which the grid line should be drawn.
410         *
411         */
412        public void drawDomainGridline(Graphics2D g2,
413                                       CategoryPlot plot,
414                                       Rectangle2D dataArea,
415                                       double value) {
416    
417            Line2D line1 = null;
418            Line2D line2 = null;
419            PlotOrientation orientation = plot.getOrientation();
420            if (orientation == PlotOrientation.HORIZONTAL) {
421                double y0 = value;
422                double y1 = value - getYOffset();
423                double x0 = dataArea.getMinX();
424                double x1 = x0 + getXOffset();
425                double x2 = dataArea.getMaxX();
426                line1 = new Line2D.Double(x0, y0, x1, y1);
427                line2 = new Line2D.Double(x1, y1, x2, y1);
428            }
429            else if (orientation == PlotOrientation.VERTICAL) {
430                double x0 = value;
431                double x1 = value + getXOffset();
432                double y0 = dataArea.getMaxY();
433                double y1 = y0 - getYOffset();
434                double y2 = dataArea.getMinY();
435                line1 = new Line2D.Double(x0, y0, x1, y1);
436                line2 = new Line2D.Double(x1, y1, x1, y2);
437            }
438            Paint paint = plot.getDomainGridlinePaint();
439            Stroke stroke = plot.getDomainGridlineStroke();
440            g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
441            g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
442            g2.draw(line1);
443            g2.draw(line2);
444    
445        }
446    
447        /**
448         * Draws a grid line against the range axis.
449         *
450         * @param g2  the graphics device.
451         * @param plot  the plot.
452         * @param axis  the value axis.
453         * @param dataArea  the area for plotting data (not yet adjusted for any
454         *                  3D effect).
455         * @param value  the value at which the grid line should be drawn.
456         *
457         */
458        public void drawRangeGridline(Graphics2D g2,
459                                      CategoryPlot plot,
460                                      ValueAxis axis,
461                                      Rectangle2D dataArea,
462                                      double value) {
463    
464            Range range = axis.getRange();
465    
466            if (!range.contains(value)) {
467                return;
468            }
469    
470            Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(),
471                    dataArea.getY() + getYOffset(), dataArea.getWidth()
472                    - getXOffset(), dataArea.getHeight() - getYOffset());
473    
474            Line2D line1 = null;
475            Line2D line2 = null;
476            PlotOrientation orientation = plot.getOrientation();
477            if (orientation == PlotOrientation.HORIZONTAL) {
478                double x0 = axis.valueToJava2D(value, adjusted,
479                        plot.getRangeAxisEdge());
480                double x1 = x0 + getXOffset();
481                double y0 = dataArea.getMaxY();
482                double y1 = y0 - getYOffset();
483                double y2 = dataArea.getMinY();
484                line1 = new Line2D.Double(x0, y0, x1, y1);
485                line2 = new Line2D.Double(x1, y1, x1, y2);
486            }
487            else if (orientation == PlotOrientation.VERTICAL) {
488                double y0 = axis.valueToJava2D(value, adjusted,
489                        plot.getRangeAxisEdge());
490                double y1 = y0 - getYOffset();
491                double x0 = dataArea.getMinX();
492                double x1 = x0 + getXOffset();
493                double x2 = dataArea.getMaxX();
494                line1 = new Line2D.Double(x0, y0, x1, y1);
495                line2 = new Line2D.Double(x1, y1, x2, y1);
496            }
497            Paint paint = plot.getRangeGridlinePaint();
498            Stroke stroke = plot.getRangeGridlineStroke();
499            g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT);
500            g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE);
501            g2.draw(line1);
502            g2.draw(line2);
503    
504        }
505    
506        /**
507         * Draws a range marker.
508         *
509         * @param g2  the graphics device.
510         * @param plot  the plot.
511         * @param axis  the value axis.
512         * @param marker  the marker.
513         * @param dataArea  the area for plotting data (not including 3D effect).
514         */
515        public void drawRangeMarker(Graphics2D g2,
516                                    CategoryPlot plot,
517                                    ValueAxis axis,
518                                    Marker marker,
519                                    Rectangle2D dataArea) {
520    
521    
522            Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(),
523                    dataArea.getY() + getYOffset(), dataArea.getWidth()
524                    - getXOffset(), dataArea.getHeight() - getYOffset());
525            if (marker instanceof ValueMarker) {
526                ValueMarker vm = (ValueMarker) marker;
527                double value = vm.getValue();
528                Range range = axis.getRange();
529                if (!range.contains(value)) {
530                    return;
531                }
532    
533                GeneralPath path = null;
534                PlotOrientation orientation = plot.getOrientation();
535                if (orientation == PlotOrientation.HORIZONTAL) {
536                    float x = (float) axis.valueToJava2D(value, adjusted,
537                            plot.getRangeAxisEdge());
538                    float y = (float) adjusted.getMaxY();
539                    path = new GeneralPath();
540                    path.moveTo(x, y);
541                    path.lineTo((float) (x + getXOffset()),
542                            y - (float) getYOffset());
543                    path.lineTo((float) (x + getXOffset()),
544                            (float) (adjusted.getMinY() - getYOffset()));
545                    path.lineTo(x, (float) adjusted.getMinY());
546                    path.closePath();
547                }
548                else if (orientation == PlotOrientation.VERTICAL) {
549                    float y = (float) axis.valueToJava2D(value, adjusted,
550                            plot.getRangeAxisEdge());
551                    float x = (float) dataArea.getX();
552                    path = new GeneralPath();
553                    path.moveTo(x, y);
554                    path.lineTo(x + (float) this.xOffset, y - (float) this.yOffset);
555                    path.lineTo((float) (adjusted.getMaxX() + this.xOffset),
556                            y - (float) this.yOffset);
557                    path.lineTo((float) (adjusted.getMaxX()), y);
558                    path.closePath();
559                }
560                g2.setPaint(marker.getPaint());
561                g2.fill(path);
562                g2.setPaint(marker.getOutlinePaint());
563                g2.draw(path);
564    
565                String label = marker.getLabel();
566                RectangleAnchor anchor = marker.getLabelAnchor();
567                if (label != null) {
568                    Font labelFont = marker.getLabelFont();
569                    g2.setFont(labelFont);
570                    g2.setPaint(marker.getLabelPaint());
571                    Point2D coordinates = calculateRangeMarkerTextAnchorPoint(
572                            g2, orientation, dataArea, path.getBounds2D(),
573                            marker.getLabelOffset(), LengthAdjustmentType.EXPAND,
574                            anchor);
575                    TextUtilities.drawAlignedString(label, g2,
576                            (float) coordinates.getX(), (float) coordinates.getY(),
577                            marker.getLabelTextAnchor());
578                }
579    
580            }
581            else {
582                super.drawRangeMarker(g2, plot, axis, marker, adjusted);
583                // TODO: draw the interval marker with a 3D effect
584            }
585        }
586    
587        /**
588         * Draws a 3D bar to represent one data item.
589         *
590         * @param g2  the graphics device.
591         * @param state  the renderer state.
592         * @param dataArea  the area for plotting the data.
593         * @param plot  the plot.
594         * @param domainAxis  the domain axis.
595         * @param rangeAxis  the range axis.
596         * @param dataset  the dataset.
597         * @param row  the row index (zero-based).
598         * @param column  the column index (zero-based).
599         * @param pass  the pass index.
600         */
601        public void drawItem(Graphics2D g2,
602                             CategoryItemRendererState state,
603                             Rectangle2D dataArea,
604                             CategoryPlot plot,
605                             CategoryAxis domainAxis,
606                             ValueAxis rangeAxis,
607                             CategoryDataset dataset,
608                             int row,
609                             int column,
610                             int pass) {
611    
612            // check the value we are plotting...
613            Number dataValue = dataset.getValue(row, column);
614            if (dataValue == null) {
615                return;
616            }
617    
618            double value = dataValue.doubleValue();
619    
620            Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(),
621                    dataArea.getY() + getYOffset(),
622                    dataArea.getWidth() - getXOffset(),
623                    dataArea.getHeight() - getYOffset());
624    
625            PlotOrientation orientation = plot.getOrientation();
626    
627            double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis,
628                    state, row, column);
629            double[] barL0L1 = calculateBarL0L1(value);
630            if (barL0L1 == null) {
631                return;  // the bar is not visible
632            }
633    
634            RectangleEdge edge = plot.getRangeAxisEdge();
635            double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge);
636            double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge);
637            double barL0 = Math.min(transL0, transL1);
638            double barLength = Math.abs(transL1 - transL0);
639    
640            // draw the bar...
641            Rectangle2D bar = null;
642            if (orientation == PlotOrientation.HORIZONTAL) {
643                bar = new Rectangle2D.Double(barL0, barW0, barLength,
644                        state.getBarWidth());
645            }
646            else {
647                bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(),
648                        barLength);
649            }
650            Paint itemPaint = getItemPaint(row, column);
651            g2.setPaint(itemPaint);
652            g2.fill(bar);
653    
654            double x0 = bar.getMinX();
655            double x1 = x0 + getXOffset();
656            double x2 = bar.getMaxX();
657            double x3 = x2 + getXOffset();
658    
659            double y0 = bar.getMinY() - getYOffset();
660            double y1 = bar.getMinY();
661            double y2 = bar.getMaxY() - getYOffset();
662            double y3 = bar.getMaxY();
663    
664            GeneralPath bar3dRight = null;
665            GeneralPath bar3dTop = null;
666            if (barLength > 0.0) {
667                bar3dRight = new GeneralPath();
668                bar3dRight.moveTo((float) x2, (float) y3);
669                bar3dRight.lineTo((float) x2, (float) y1);
670                bar3dRight.lineTo((float) x3, (float) y0);
671                bar3dRight.lineTo((float) x3, (float) y2);
672                bar3dRight.closePath();
673    
674                if (itemPaint instanceof Color) {
675                    g2.setPaint(((Color) itemPaint).darker());
676                }
677                g2.fill(bar3dRight);
678            }
679    
680            bar3dTop = new GeneralPath();
681            bar3dTop.moveTo((float) x0, (float) y1);
682            bar3dTop.lineTo((float) x1, (float) y0);
683            bar3dTop.lineTo((float) x3, (float) y0);
684            bar3dTop.lineTo((float) x2, (float) y1);
685            bar3dTop.closePath();
686            g2.fill(bar3dTop);
687    
688            if (isDrawBarOutline()
689                    && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
690                g2.setStroke(getItemOutlineStroke(row, column));
691                g2.setPaint(getItemOutlinePaint(row, column));
692                g2.draw(bar);
693                if (bar3dRight != null) {
694                    g2.draw(bar3dRight);
695                }
696                if (bar3dTop != null) {
697                    g2.draw(bar3dTop);
698                }
699            }
700    
701            CategoryItemLabelGenerator generator
702                = getItemLabelGenerator(row, column);
703            if (generator != null && isItemLabelVisible(row, column)) {
704                drawItemLabel(g2, dataset, row, column, plot, generator, bar,
705                        (value < 0.0));
706            }
707    
708            // add an item entity, if this information is being collected
709            EntityCollection entities = state.getEntityCollection();
710            if (entities != null) {
711                GeneralPath barOutline = new GeneralPath();
712                barOutline.moveTo((float) x0, (float) y3);
713                barOutline.lineTo((float) x0, (float) y1);
714                barOutline.lineTo((float) x1, (float) y0);
715                barOutline.lineTo((float) x3, (float) y0);
716                barOutline.lineTo((float) x3, (float) y2);
717                barOutline.lineTo((float) x2, (float) y3);
718                barOutline.closePath();
719                addItemEntity(entities, dataset, row, column, barOutline);
720            }
721    
722        }
723    
724        /**
725         * Tests this renderer for equality with an arbitrary object.
726         *
727         * @param obj  the object (<code>null</code> permitted).
728         *
729         * @return A boolean.
730         */
731        public boolean equals(Object obj) {
732            if (obj == this) {
733                return true;
734            }
735            if (!(obj instanceof BarRenderer3D)) {
736                return false;
737            }
738            BarRenderer3D that = (BarRenderer3D) obj;
739            if (this.xOffset != that.xOffset) {
740                return false;
741            }
742            if (this.yOffset != that.yOffset) {
743                return false;
744            }
745            if (!PaintUtilities.equal(this.wallPaint, that.wallPaint)) {
746                return false;
747            }
748            return super.equals(obj);
749        }
750    
751        /**
752         * Provides serialization support.
753         *
754         * @param stream  the output stream.
755         *
756         * @throws IOException  if there is an I/O error.
757         */
758        private void writeObject(ObjectOutputStream stream) throws IOException {
759            stream.defaultWriteObject();
760            SerialUtilities.writePaint(this.wallPaint, stream);
761        }
762    
763        /**
764         * Provides serialization support.
765         *
766         * @param stream  the input stream.
767         *
768         * @throws IOException  if there is an I/O error.
769         * @throws ClassNotFoundException  if there is a classpath problem.
770         */
771        private void readObject(ObjectInputStream stream)
772            throws IOException, ClassNotFoundException {
773            stream.defaultReadObject();
774            this.wallPaint = SerialUtilities.readPaint(stream);
775        }
776    
777    }