KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > BarRenderer


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ----------------
23  * BarRenderer.java
24  * ----------------
25  * (C) Copyright 2002, 2003 by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Christian W. Zuckschwerdt;
29  *
30  * $Id: BarRenderer.java,v 1.31 2003/11/27 11:46:06 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 14-Mar-2002 : Version 1 (DG);
35  * 23-May-2002 : Added tooltip generator to renderer (DG);
36  * 29-May-2002 : Moved tooltip generator to abstract super-class (DG);
37  * 25-Jun-2002 : Changed constructor to protected and removed redundant code (DG);
38  * 26-Jun-2002 : Added axis to initialise method, and record upper and lower clip values (DG);
39  * 24-Sep-2002 : Added getLegendItem(...) method (DG);
40  * 09-Oct-2002 : Modified constructor to include URL generator (DG);
41  * 05-Nov-2002 : Base dataset is now TableDataset not CategoryDataset (DG);
42  * 10-Jan-2003 : Moved get/setItemMargin() method up from subclasses (DG);
43  * 17-Jan-2003 : Moved plot classes into a separate package (DG);
44  * 25-Mar-2003 : Implemented Serializable (DG);
45  * 01-May-2003 : Modified clipping to allow for dual axes and datasets (DG);
46  * 12-May-2003 : Merged horizontal and vertical bar renderers (DG);
47  * 12-Jun-2003 : Updates for item labels (DG);
48  * 30-Jul-2003 : Modified entity constructor (CZ);
49  * 02-Sep-2003 : Changed initialise method to fix bug 790407 (DG);
50  * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
51  * 07-Oct-2003 : Added renderer state (DG);
52  * 27-Oct-2003 : Merged drawHorizontalItem(...) and drawVerticalItem(...) methods (DG);
53  * 28-Oct-2003 : Added support for gradient paint on bars (DG);
54  * 14-Nov-2003 : Added 'maxBarWidth' attribute (DG);
55  *
56  */

57
58 package org.jfree.chart.renderer;
59
60 import java.awt.Font JavaDoc;
61 import java.awt.GradientPaint JavaDoc;
62 import java.awt.Graphics2D JavaDoc;
63 import java.awt.Paint JavaDoc;
64 import java.awt.Shape JavaDoc;
65 import java.awt.Stroke JavaDoc;
66 import java.awt.geom.Point2D JavaDoc;
67 import java.awt.geom.Rectangle2D JavaDoc;
68 import java.io.Serializable JavaDoc;
69
70 import org.jfree.chart.axis.CategoryAxis;
71 import org.jfree.chart.axis.ValueAxis;
72 import org.jfree.chart.entity.CategoryItemEntity;
73 import org.jfree.chart.entity.EntityCollection;
74 import org.jfree.chart.event.RendererChangeEvent;
75 import org.jfree.chart.labels.CategoryItemLabelGenerator;
76 import org.jfree.chart.plot.CategoryPlot;
77 import org.jfree.chart.plot.PlotOrientation;
78 import org.jfree.chart.plot.PlotRenderingInfo;
79 import org.jfree.data.CategoryDataset;
80 import org.jfree.ui.GradientPaintTransformer;
81 import org.jfree.ui.RectangleEdge;
82 import org.jfree.ui.RefineryUtilities;
83 import org.jfree.ui.StandardGradientPaintTransformer;
84 import org.jfree.util.PublicCloneable;
85
86 /**
87  * A {@link CategoryItemRenderer} that draws individual data items as bars.
88  *
89  * @author David Gilbert
90  */

91 public class BarRenderer extends AbstractCategoryItemRenderer
92                          implements Cloneable JavaDoc, PublicCloneable, Serializable JavaDoc {
93
94     /** The default item margin percentage. */
95     public static final double DEFAULT_ITEM_MARGIN = 0.20;
96
97     /** Constant that controls the minimum width before a bar has an outline drawn. */
98     public static final double BAR_OUTLINE_WIDTH_THRESHOLD = 3.0;
99
100     /** The margin between items (bars) within a category. */
101     private double itemMargin;
102
103     /** A flag that controls whether or not bar outlines are drawn. */
104     private boolean drawBarOutline;
105     
106     /** The maximum bar width as a percentage of the available space. */
107     private double maxBarWidth;
108     
109     /** The minimum bar length (in Java2D units). */
110     private double minimumBarLength;
111     
112     /** An optional class used to transform gradient paint objects to fit each bar. */
113     private GradientPaintTransformer gradientPaintTransformer;
114     
115     /** The fallback position if a positive item label doesn't fit inside the bar. */
116     private ItemLabelPosition positiveItemLabelPositionFallback;
117     
118     /** The fallback position if a negative item label doesn't fit inside the bar. */
119     private ItemLabelPosition negativeItemLabelPositionFallback;
120     
121     /** The upper clip (axis) value for the axis. */
122     private double upperClip;
123
124     /** The lower clip (axis) value for the axis. */
125     private double lowerClip;
126
127     /**
128      * Creates a new bar renderer with default settings.
129      */

130     public BarRenderer() {
131         super();
132         this.itemMargin = DEFAULT_ITEM_MARGIN;
133         this.drawBarOutline = true;
134         this.maxBarWidth = 1.0; // 100 percent, so it will not apply unless changed
135
this.positiveItemLabelPositionFallback = null;
136         this.negativeItemLabelPositionFallback = null;
137         this.gradientPaintTransformer = new StandardGradientPaintTransformer();
138         this.minimumBarLength = 0.0;
139     }
140
141     /**
142      * Returns the item margin.
143      *
144      * @return The margin.
145      */

146     public double getItemMargin() {
147         return this.itemMargin;
148     }
149
150     /**
151      * Sets the item margin. The value is expressed as a percentage of the available width for
152      * plotting all the bars, with the resulting amount to be distributed between all the bars
153      * evenly.
154      *
155      * @param percent the new margin.
156      */

157     public void setItemMargin(double percent) {
158         this.itemMargin = percent;
159         firePropertyChanged("ItemMargin", null, null);
160     }
161
162     /**
163      * Returns a flag that controls whether or not bar outlines are drawn.
164      *
165      * @return A boolean.
166      */

167     public boolean isDrawBarOutline() {
168         return this.drawBarOutline;
169     }
170     
171     /**
172      * Sets the flag that controls whether or not bar outlines are drawn.
173      *
174      * @param draw the new flag value.
175      */

176     public void setDrawBarOutline(boolean draw) {
177         this.drawBarOutline = draw;
178         firePropertyChanged("DrawBarOutline", null, null);
179     }
180     
181     /**
182      * Returns the maximum bar width, as a percentage of the available drawing space.
183      *
184      * @return the maximum bar width.
185      */

186     public double getMaxBarWidth() {
187         return this.maxBarWidth;
188     }
189     
190     /**
191      * Sets the maximum bar width, which is specified as a percentage of the available space
192      * for all bars, and sends a {@link RendererChangeEvent} to all registered listeners.
193      *
194      * @param percent the percent.
195      */

196     public void setMaxBarWidth(double percent) {
197         this.maxBarWidth = percent;
198         notifyListeners(new RendererChangeEvent(this));
199     }
200
201     public double getMinimumBarLength() {
202         return this.minimumBarLength;
203     }
204     
205     public void setMinimumBarLength(double min) {
206         this.minimumBarLength = min;
207         notifyListeners(new RendererChangeEvent(this));
208     }
209     
210     /**
211      * Returns the gradient paint transformer (an object used to transform gradient paint objects
212      * to fit each bar.
213      *
214      * @return A transformer (<code>null</code> possible).
215      */

216     public GradientPaintTransformer getGradientPaintTransformer() {
217         return this.gradientPaintTransformer;
218     }
219     
220     /**
221      * Sets the gradient paint transformer and sends a {@link RendererChangeEvent} to all registered
222      * listeners.
223      *
224      * @param transformer the transformer (<code>null</code> permitted).
225      */

226     public void setGradientPaintTransformer(GradientPaintTransformer transformer) {
227         this.gradientPaintTransformer = transformer;
228         notifyListeners(new RendererChangeEvent(this));
229     }
230     
231     /**
232      * Returns the fallback position for positive item labels that don't fit within a bar.
233      *
234      * @return The fallback position (<code>null</code> possible).
235      */

236     public ItemLabelPosition getPositiveItemLabelPositionFallback() {
237         return this.positiveItemLabelPositionFallback;
238     }
239     
240     /**
241      * Sets the fallback position for positive item labels that don't fit within a bar, and sends
242      * a {@link RendererChangeEvent} to all registered listeners.
243      *
244      * @param position the position.
245      */

246     public void setPositiveItemLabelPositionFallback(ItemLabelPosition position) {
247         this.positiveItemLabelPositionFallback = position;
248         notifyListeners(new RendererChangeEvent(this));
249     }
250     
251     /**
252      * Returns the fallback position for negative item labels that don't fit within a bar.
253      *
254      * @return The fallback position (<code>null</code> possible).
255      */

256     public ItemLabelPosition getNegativeItemLabelPositionFallback() {
257         return this.negativeItemLabelPositionFallback;
258     }
259     
260     /**
261      * Sets the fallback position for negative item labels that don't fit within a bar, and sends
262      * a {@link RendererChangeEvent} to all registered listeners.
263      *
264      * @param position the position.
265      */

266     public void setNegativeItemLabelPositionFallback(ItemLabelPosition position) {
267         this.negativeItemLabelPositionFallback = position;
268         notifyListeners(new RendererChangeEvent(this));
269     }
270     
271     /**
272      * Returns the lower clip value.
273      * <P>
274      * This value is recalculated in the initialise() method.
275      *
276      * @return The value.
277      */

278     public double getLowerClip() {
279         return this.lowerClip;
280     }
281
282     /**
283      * Returns the upper clip value.
284      * <P>
285      * This value is recalculated in the initialise() method.
286      *
287      * @return The value.
288      */

289     public double getUpperClip() {
290         return this.upperClip;
291     }
292
293     /**
294      * Initialises the renderer and returns a state object that will be passed to subsequent calls
295      * to the drawItem method.
296      * <p>
297      * This method gets called once at the start of the process of drawing a chart.
298      *
299      * @param g2 the graphics device.
300      * @param dataArea the area in which the data is to be plotted.
301      * @param plot the plot.
302      * @param rendererIndex the renderer index (<code>null</code> for the primary renderer).
303      * @param info collects chart rendering information for return to caller.
304      *
305      * @return The renderer state.
306      *
307      */

308     public CategoryItemRendererState initialise(Graphics2D JavaDoc g2,
309                                                 Rectangle2D JavaDoc dataArea,
310                                                 CategoryPlot plot,
311                                                 Integer JavaDoc rendererIndex,
312                                                 PlotRenderingInfo info) {
313
314         CategoryItemRendererState state = super.initialise(g2, dataArea, plot, rendererIndex, info);
315
316         // get the clipping values...
317
ValueAxis rangeAxis = getRangeAxis(plot, rendererIndex);
318         this.lowerClip = rangeAxis.getRange().getLowerBound();
319         this.upperClip = rangeAxis.getRange().getUpperBound();
320
321         // calculate the bar width
322
calculateBarWidth(plot, dataArea, rendererIndex, state);
323
324         return state;
325         
326     }
327     
328     /**
329      * Calculates the bar width and stores it in the renderer state.
330      *
331      * @param plot the plot.
332      * @param dataArea the data area.
333      * @param rendererIndex the renderer index.
334      * @param state the renderer state.
335      */

336     protected void calculateBarWidth(CategoryPlot plot,
337                                      Rectangle2D JavaDoc dataArea,
338                                      Integer JavaDoc rendererIndex,
339                                      CategoryItemRendererState state) {
340                                          
341         CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);
342         CategoryDataset dataset = getDataset(plot, rendererIndex);
343         if (dataset != null) {
344             int columns = dataset.getColumnCount();
345             int rows = dataset.getRowCount();
346             double space = 0.0;
347             PlotOrientation orientation = plot.getOrientation();
348             if (orientation == PlotOrientation.HORIZONTAL) {
349                 space = dataArea.getHeight();
350             }
351             else if (orientation == PlotOrientation.VERTICAL) {
352                 space = dataArea.getWidth();
353             }
354             double maxWidth = space * getMaxBarWidth();
355             double categoryMargin = 0.0;
356             double currentItemMargin = 0.0;
357             if (columns > 1) {
358                 categoryMargin = domainAxis.getCategoryMargin();
359             }
360             if (rows > 1) {
361                 currentItemMargin = getItemMargin();
362             }
363             double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin()
364                                      - categoryMargin - currentItemMargin);
365             if ((rows * columns) > 0) {
366                 state.setBarWidth(Math.min(used / (rows * columns), maxWidth));
367             }
368             else {
369                 state.setBarWidth(Math.min(used, maxWidth));
370             }
371         }
372     }
373
374     /**
375      * Calculates the coordinate of the first "side" of a bar. This will be the minimum
376      * x-coordinate for a vertical bar, and the minimum y-coordinate for a horizontal bar.
377      *
378      * @param plot the plot.
379      * @param orientation the plot orientation.
380      * @param dataArea the data area.
381      * @param domainAxis the domain axis.
382      * @param state the renderer state (has the bar width precalculated).
383      * @param row the row index.
384      * @param column the column index.
385      *
386      * @return the coordinate.
387      */

388     protected double calculateBarW0(CategoryPlot plot,
389                                     PlotOrientation orientation,
390                                     Rectangle2D JavaDoc dataArea,
391                                     CategoryAxis domainAxis,
392                                     CategoryItemRendererState state,
393                                     int row,
394                                     int column) {
395         // calculate bar width...
396
double space = 0.0;
397         if (orientation == PlotOrientation.HORIZONTAL) {
398             space = dataArea.getHeight();
399         }
400         else {
401             space = dataArea.getWidth();
402         }
403         double barW0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea,
404                                                    plot.getDomainAxisEdge());
405         int seriesCount = getRowCount();
406         int categoryCount = getColumnCount();
407         if (seriesCount > 1) {
408             double seriesGap = space * getItemMargin() / (categoryCount * (seriesCount - 1));
409             double seriesW = calculateSeriesWidth(space, domainAxis, categoryCount, seriesCount);
410             barW0 = barW0 + row * (seriesW + seriesGap)
411                           + (seriesW / 2.0) - (state.getBarWidth() / 2.0);
412         }
413         else {
414             barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea,
415                                                  plot.getDomainAxisEdge())
416                     - state.getBarWidth() / 2.0;
417         }
418         return barW0;
419     }
420     
421     /**
422      * Calculates the coordinates for the length of a single bar.
423      *
424      * @param value the value represented by the bar.
425      *
426      * @return the coordinates for each end of the bar (or <code>null</code> if the bar is not
427      * visible for the current axis range).
428      */

429     protected double[] calculateBarL0L1(double value) {
430
431         double base = 0.0;
432         double lclip = getLowerClip();
433         double uclip = getUpperClip();
434         if (uclip <= 0.0) { // cases 1, 2, 3 and 4
435
if (value >= uclip) {
436                 return null; // bar is not visible
437
}
438             base = uclip;
439             if (value <= lclip) {
440                 value = lclip;
441             }
442         }
443         else if (lclip <= 0.0) { // cases 5, 6, 7 and 8
444
if (value >= uclip) {
445                 value = uclip;
446             }
447             else {
448                 if (value <= lclip) {
449                     value = lclip;
450                 }
451             }
452         }
453         else { // cases 9, 10, 11 and 12
454
if (value <= lclip) {
455                 return null; // bar is not visible
456
}
457             base = lclip;
458             if (value >= uclip) {
459                 value = uclip;
460             }
461         }
462         return new double[] {base, value};
463     }
464
465     /**
466      * Draws the bar for a single (series, category) data item.
467      *
468      * @param g2 the graphics device.
469      * @param state the renderer state.
470      * @param dataArea the data area.
471      * @param plot the plot.
472      * @param domainAxis the domain axis.
473      * @param rangeAxis the range axis.
474      * @param dataset the dataset.
475      * @param row the row index (zero-based).
476      * @param column the column index (zero-based).
477      */

478     public void drawItem(Graphics2D JavaDoc g2,
479                          CategoryItemRendererState state,
480                          Rectangle2D JavaDoc dataArea,
481                          CategoryPlot plot,
482                          CategoryAxis domainAxis,
483                          ValueAxis rangeAxis,
484                          CategoryDataset dataset,
485                          int row,
486                          int column) {
487
488         // nothing is drawn for null values...
489
Number JavaDoc dataValue = dataset.getValue(row, column);
490         if (dataValue == null) {
491             return;
492         }
493         
494         double value = dataValue.doubleValue();
495         
496         PlotOrientation orientation = plot.getOrientation();
497         double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column);
498         double[] barL0L1 = calculateBarL0L1(value);
499         if (barL0L1 == null) {
500             return; // the bar is not visible
501
}
502         
503         RectangleEdge edge = plot.getRangeAxisEdge();
504         double transL0 = rangeAxis.translateValueToJava2D(barL0L1[0], dataArea, edge);
505         double transL1 = rangeAxis.translateValueToJava2D(barL0L1[1], dataArea, edge);
506         double barL0 = Math.min(transL0, transL1);
507         double barLength = Math.max(Math.abs(transL1 - transL0), this.minimumBarLength);
508
509         // draw the bar...
510
Rectangle2D JavaDoc bar = null;
511         if (orientation == PlotOrientation.HORIZONTAL) {
512             bar = new Rectangle2D.Double JavaDoc(barL0, barW0, barLength, state.getBarWidth());
513         }
514         else {
515             bar = new Rectangle2D.Double JavaDoc(barW0, barL0, state.getBarWidth(), barLength);
516         }
517         Paint JavaDoc itemPaint = getItemPaint(row, column);
518         if (this.gradientPaintTransformer != null && itemPaint instanceof GradientPaint JavaDoc) {
519             GradientPaint JavaDoc gp = (GradientPaint JavaDoc) itemPaint;
520             itemPaint = this.gradientPaintTransformer.transform(gp, bar);
521         }
522         g2.setPaint(itemPaint);
523         g2.fill(bar);
524
525         // draw the outline...
526
if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
527             Stroke JavaDoc stroke = getItemOutlineStroke(row, column);
528             Paint JavaDoc paint = getItemOutlinePaint(row, column);
529             if (stroke != null && paint != null) {
530                 g2.setStroke(stroke);
531                 g2.setPaint(paint);
532                 g2.draw(bar);
533             }
534         }
535
536         CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
537         if (generator != null && isItemLabelVisible(row, column)) {
538             drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0));
539         }
540                 
541         // collect entity and tool tip information...
542
if (state.getInfo() != null) {
543             EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
544             if (entities != null) {
545                 String JavaDoc tip = null;
546                 if (generator != null) {
547                     tip = generator.generateToolTip(dataset, row, column);
548                 }
549                 String JavaDoc url = null;
550                 if (getItemURLGenerator(row, column) != null) {
551                     url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
552                 }
553                 CategoryItemEntity entity = new CategoryItemEntity(
554                     bar, tip, url, dataset, row, dataset.getColumnKey(column), column
555                 );
556                 entities.addEntity(entity);
557             }
558
559         }
560
561     }
562
563     /**
564      * Calculates the available space for each series.
565      *
566      * @param space the space along the entire axis (in Java2D units).
567      * @param axis the category axis.
568      * @param categories the number of categories.
569      * @param series the number of series.
570      *
571      * @return the width of one series.
572      */

573     protected double calculateSeriesWidth(double space, CategoryAxis axis,
574                                           int categories, int series) {
575         double factor = 1.0 - getItemMargin() - axis.getLowerMargin() - axis.getUpperMargin();
576         if (categories > 1) {
577             factor = factor - axis.getCategoryMargin();
578         }
579         return (space * factor) / (categories * series);
580     }
581     
582     /**
583      * Draws an item label. This method is overridden so that the bar can be used
584      * to calculate the label anchor point.
585      *
586      * @param g2 the graphics device.
587      * @param data the dataset.
588      * @param row the row.
589      * @param column the column.
590      * @param plot the plot.
591      * @param generator the label generator.
592      * @param bar the bar.
593      * @param negative a flag indicating a negative value.
594      */

595     protected void drawItemLabel(Graphics2D JavaDoc g2,
596                                  CategoryDataset data,
597                                  int row,
598                                  int column,
599                                  CategoryPlot plot,
600                                  CategoryItemLabelGenerator generator,
601                                  Rectangle2D JavaDoc bar,
602                                  boolean negative) {
603                                      
604         // draw the item labels if there are any...
605
Font JavaDoc labelFont = getItemLabelFont(row, column);
606         g2.setFont(labelFont);
607         Paint JavaDoc paint = getItemLabelPaint(row, column);
608         g2.setPaint(paint);
609         String JavaDoc label = generator.generateItemLabel(data, row, column);
610
611         // find out where to place the label...
612
ItemLabelPosition position = null;
613         if (!negative) {
614             position = getPositiveItemLabelPosition(row, column);
615         }
616         else {
617             position = getNegativeItemLabelPosition(row, column);
618         }
619
620         // work out the label anchor point...
621
Point2D JavaDoc anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(),
622                                                         bar,
623                                                         plot.getOrientation());
624         
625         if (isInternalAnchor(position.getItemLabelAnchor())) {
626             Shape JavaDoc bounds = RefineryUtilities.calculateRotatedStringBounds(
627                 label, g2,
628                 (float) anchorPoint.getX(),
629                 (float) anchorPoint.getY(),
630                 position.getTextAnchor(),
631                 position.getRotationAnchor(),
632                 position.getAngle());
633         
634             if (!bar.contains(bounds.getBounds2D())) {
635                 if (!negative) {
636                     position = getPositiveItemLabelPositionFallback();
637                 }
638                 else {
639                     position = getNegativeItemLabelPositionFallback();
640                 }
641                 if (position != null) {
642                     anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(),
643                                                             bar,
644                                                             plot.getOrientation());
645                 }
646             }
647         
648         }
649         
650         if (position != null) {
651             RefineryUtilities.drawRotatedString(label, g2,
652                                                 (float) anchorPoint.getX(),
653                                                 (float) anchorPoint.getY(),
654                                                 position.getTextAnchor(),
655                                                 position.getRotationAnchor(),
656                                                 position.getAngle());
657         }
658     }
659     
660     /**
661      * Calculates the item label anchor point.
662      *
663      * @param anchor the anchor.
664      * @param bar the bar.
665      * @param orientation the plot orientation.
666      *
667      * @return The anchor point.
668      */

669     private Point2D JavaDoc calculateLabelAnchorPoint(ItemLabelAnchor anchor,
670                                               Rectangle2D JavaDoc bar, PlotOrientation orientation) {
671
672         Point2D JavaDoc result = null;
673         double offset = getItemLabelAnchorOffset();
674         double x0 = bar.getX() - offset;
675         double x1 = bar.getX();
676         double x2 = bar.getX() + offset;
677         double x3 = bar.getCenterX();
678         double x4 = bar.getMaxX() - offset;
679         double x5 = bar.getMaxX();
680         double x6 = bar.getMaxX() + offset;
681
682         double y0 = bar.getMaxY() + offset;
683         double y1 = bar.getMaxY();
684         double y2 = bar.getMaxY() - offset;
685         double y3 = bar.getCenterY();
686         double y4 = bar.getMinY() + offset;
687         double y5 = bar.getMinY();
688         double y6 = bar.getMinY() - offset;
689
690         if (anchor == ItemLabelAnchor.CENTER) {
691             result = new Point2D.Double JavaDoc(x3, y3);
692         }
693         else if (anchor == ItemLabelAnchor.INSIDE1) {
694             result = new Point2D.Double JavaDoc(x4, y4);
695         }
696         else if (anchor == ItemLabelAnchor.INSIDE2) {
697             result = new Point2D.Double JavaDoc(x4, y4);
698         }
699         else if (anchor == ItemLabelAnchor.INSIDE3) {
700             result = new Point2D.Double JavaDoc(x4, y3);
701         }
702         else if (anchor == ItemLabelAnchor.INSIDE4) {
703             result = new Point2D.Double JavaDoc(x4, y2);
704         }
705         else if (anchor == ItemLabelAnchor.INSIDE5) {
706             result = new Point2D.Double JavaDoc(x4, y2);
707         }
708         else if (anchor == ItemLabelAnchor.INSIDE6) {
709             result = new Point2D.Double JavaDoc(x3, y2);
710         }
711         else if (anchor == ItemLabelAnchor.INSIDE7) {
712             result = new Point2D.Double JavaDoc(x2, y2);
713         }
714         else if (anchor == ItemLabelAnchor.INSIDE8) {
715             result = new Point2D.Double JavaDoc(x2, y2);
716         }
717         else if (anchor == ItemLabelAnchor.INSIDE9) {
718             result = new Point2D.Double JavaDoc(x2, y3);
719         }
720         else if (anchor == ItemLabelAnchor.INSIDE10) {
721             result = new Point2D.Double JavaDoc(x2, y4);
722         }
723         else if (anchor == ItemLabelAnchor.INSIDE11) {
724             result = new Point2D.Double JavaDoc(x2, y4);
725         }
726         else if (anchor == ItemLabelAnchor.INSIDE12) {
727             result = new Point2D.Double JavaDoc(x3, y4);
728         }
729         else if (anchor == ItemLabelAnchor.OUTSIDE1) {
730             result = new Point2D.Double JavaDoc(x5, y6);
731         }
732         else if (anchor == ItemLabelAnchor.OUTSIDE2) {
733             result = new Point2D.Double JavaDoc(x6, y5);
734         }
735         else if (anchor == ItemLabelAnchor.OUTSIDE3) {
736             result = new Point2D.Double JavaDoc(x6, y3);
737         }
738         else if (anchor == ItemLabelAnchor.OUTSIDE4) {
739             result = new Point2D.Double JavaDoc(x6, y1);
740         }
741         else if (anchor == ItemLabelAnchor.OUTSIDE5) {
742             result = new Point2D.Double JavaDoc(x5, y0);
743         }
744         else if (anchor == ItemLabelAnchor.OUTSIDE6) {
745             result = new Point2D.Double JavaDoc(x3, y0);
746         }
747         else if (anchor == ItemLabelAnchor.OUTSIDE7) {
748             result = new Point2D.Double JavaDoc(x1, y0);
749         }
750         else if (anchor == ItemLabelAnchor.OUTSIDE8) {
751             result = new Point2D.Double JavaDoc(x0, y1);
752         }
753         else if (anchor == ItemLabelAnchor.OUTSIDE9) {
754             result = new Point2D.Double JavaDoc(x0, y3);
755         }
756         else if (anchor == ItemLabelAnchor.OUTSIDE10) {
757             result = new Point2D.Double JavaDoc(x0, y5);
758         }
759         else if (anchor == ItemLabelAnchor.OUTSIDE11) {
760             result = new Point2D.Double JavaDoc(x1, y6);
761         }
762         else if (anchor == ItemLabelAnchor.OUTSIDE12) {
763             result = new Point2D.Double JavaDoc(x3, y6);
764         }
765
766         return result;
767
768     }
769     
770     /**
771      * Returns <code>true</code> if the specified anchor point is inside a bar.
772      *
773      * @param anchor the anchor point.
774      *
775      * @return A boolean.
776      */

777     private boolean isInternalAnchor(ItemLabelAnchor anchor) {
778         return anchor == ItemLabelAnchor.CENTER
779                || anchor == ItemLabelAnchor.INSIDE1
780                || anchor == ItemLabelAnchor.INSIDE2
781                || anchor == ItemLabelAnchor.INSIDE3
782                || anchor == ItemLabelAnchor.INSIDE4
783                || anchor == ItemLabelAnchor.INSIDE5
784                || anchor == ItemLabelAnchor.INSIDE6
785                || anchor == ItemLabelAnchor.INSIDE7
786                || anchor == ItemLabelAnchor.INSIDE8
787                || anchor == ItemLabelAnchor.INSIDE9
788                || anchor == ItemLabelAnchor.INSIDE10
789                || anchor == ItemLabelAnchor.INSIDE11
790                || anchor == ItemLabelAnchor.INSIDE12;
791                
792     }
793     
794     /**
795      * Tests an object for equality with this instance.
796      *
797      * @param object the object.
798      *
799      * @return A boolean.
800      */

801     public boolean equals(Object JavaDoc object) {
802         
803         if (object == null) {
804             return false;
805         }
806         
807         if (object == this) {
808             return true;
809         }
810         
811         if (super.equals(object) && (object instanceof BarRenderer)) {
812
813             BarRenderer r = (BarRenderer) object;
814             boolean b0 = (this.itemMargin == r.itemMargin);
815             boolean b1 = (this.drawBarOutline == r.drawBarOutline);
816             return b0 && b1;
817         }
818         
819         return false;
820         
821     }
822
823 }
824
Popular Tags