private static LegendTitle createLegend(String legend1Text, String legend2Text) {
   final LegendItemCollection legendItems = new LegendItemCollection();
   FontRenderContext frc = new FontRenderContext(null, true, true);
   Font legenfont = new Font(Font.SANS_SERIF, Font.BOLD, 12);
   GlyphVector gv = legenfont.createGlyphVector(frc, new char[] {'X', 'X'});
   Shape shape = gv.getVisualBounds();
   Rectangle2D bounds = shape.getBounds2D();
   HatchedRectangle hatchShape =
       new HatchedRectangle(
           bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 5, 5);
   {
     LegendItem li = new LegendItem(legend1Text, null, null, null, hatchShape, Color.black);
     li.setLabelFont(legenfont);
     legendItems.add(li);
   }
   {
     LegendItem li = new LegendItem(legend2Text, null, null, null, shape, Color.black);
     li.setLabelFont(legenfont);
     legendItems.add(li);
   }
   LegendTitle legend =
       new LegendTitle(
           new LegendItemSource() {
             @Override
             public LegendItemCollection getLegendItems() {
               return legendItems;
             }
           });
   legend.setPosition(RectangleEdge.BOTTOM);
   legend.setMargin(new RectangleInsets(0, 30, 0, 0));
   legend.setPadding(RectangleInsets.ZERO_INSETS);
   legend.setLegendItemGraphicPadding(new RectangleInsets(0, 20, 0, 0));
   return legend;
 }
  /**
   * Creates a title item (i.e. bold font etc.) with the given string. Simply gets the default font
   * from the plotConfig and sets it style to bold.
   *
   * @return The created legend item.
   */
  private LegendItem createTitleLegendItem(
      String titleString, PlotConfiguration plotConfiguration) {
    LegendItem titleItem =
        new LegendItem(
            titleString,
            "",
            "",
            "",
            false,
            new Rectangle(),
            false,
            Color.WHITE,
            false,
            Color.WHITE,
            new BasicStroke(),
            false,
            new Rectangle(),
            new BasicStroke(),
            Color.WHITE);
    Font titleFont = titleItem.getLabelFont();

    if (titleFont == null) {
      titleFont = plotConfiguration.getLegendConfiguration().getLegendFont();
    }
    titleItem.setLabelFont(titleFont.deriveFont(Font.BOLD));
    return titleItem;
  }
  /**
   * Returns a legend item for the specified series. The default method is overridden so that the
   * legend displays circles for all series.
   *
   * @param datasetIndex the dataset index (zero-based).
   * @param series the series index (zero-based).
   * @return A legend item for the series.
   */
  public LegendItem getLegendItem(int datasetIndex, int series) {
    LegendItem result = null;
    XYPlot plot = getPlot();
    if (plot == null) {
      return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset != null) {
      if (getItemVisible(series, 0)) {
        String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
        String description = label;
        String toolTipText = null;
        if (getLegendItemToolTipGenerator() != null) {
          toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
        }
        String urlText = null;
        if (getLegendItemURLGenerator() != null) {
          urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
        }
        Shape shape = lookupLegendShape(series);
        Paint paint = lookupSeriesPaint(series);
        Paint outlinePaint = lookupSeriesOutlinePaint(series);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        result =
            new LegendItem(
                label,
                description,
                toolTipText,
                urlText,
                shape,
                paint,
                outlineStroke,
                outlinePaint);
        result.setLabelFont(lookupLegendTextFont(series));
        Paint labelPaint = lookupLegendTextPaint(series);
        if (labelPaint != null) {
          result.setLabelPaint(labelPaint);
        }
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
        result.setSeriesKey(dataset.getSeriesKey(series));
        result.setSeriesIndex(series);
      }
    }
    return result;
  }
예제 #4
0
 /**
  * Returns a default legend item for the specified series. Subclasses should override this method
  * to generate customised items.
  *
  * @param datasetIndex the dataset index (zero-based).
  * @param series the series index (zero-based).
  * @return A legend item for the series.
  */
 @Override
 public LegendItem getLegendItem(int datasetIndex, int series) {
   XYPlot xyplot = getPlot();
   if (xyplot == null) {
     return null;
   }
   XYDataset dataset = xyplot.getDataset(datasetIndex);
   if (dataset == null) {
     return null;
   }
   LegendItem result;
   XYSeriesLabelGenerator lg = getLegendItemLabelGenerator();
   String label = lg.generateLabel(dataset, series);
   String description = label;
   String toolTipText = null;
   if (getLegendItemToolTipGenerator() != null) {
     toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
   }
   String urlText = null;
   if (getLegendItemURLGenerator() != null) {
     urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
   }
   Shape shape = this.legendBar;
   Paint paint = lookupSeriesPaint(series);
   Paint outlinePaint = lookupSeriesOutlinePaint(series);
   Stroke outlineStroke = lookupSeriesOutlineStroke(series);
   if (this.drawBarOutline) {
     result =
         new LegendItem(
             label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
   } else {
     result = new LegendItem(label, description, toolTipText, urlText, shape, paint);
   }
   result.setLabelFont(lookupLegendTextFont(series));
   Paint labelPaint = lookupLegendTextPaint(series);
   if (labelPaint != null) {
     result.setLabelPaint(labelPaint);
   }
   result.setDataset(dataset);
   result.setDatasetIndex(datasetIndex);
   result.setSeriesKey(dataset.getSeriesKey(series));
   result.setSeriesIndex(series);
   if (getGradientPaintTransformer() != null) {
     result.setFillPaintTransformer(getGradientPaintTransformer());
   }
   return result;
 }
예제 #5
0
  /**
   * Returns a legend item for a series.
   *
   * @param datasetIndex the dataset index (zero-based).
   * @param series the series index (zero-based).
   * @return The legend item.
   */
  @Override
  public LegendItem getLegendItem(int datasetIndex, int series) {

    // if there is no plot, there is no dataset to access...
    CategoryPlot cp = getPlot();
    if (cp == null) {
      return null;
    }

    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
      return null;
    }

    CategoryDataset dataset = cp.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
      toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
      urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);

    LegendItem result =
        new LegendItem(
            label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
      result.setLabelPaint(labelPaint);
    }
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);
    result.setSeriesKey(dataset.getRowKey(series));
    result.setSeriesIndex(series);
    return result;
  }
  /**
   * Returns a legend item for a series.
   *
   * @param datasetIndex the dataset index (zero-based).
   * @param series the series index (zero-based).
   * @return The legend item.
   */
  public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot p = getPlot();
    if (p == null) {
      return null;
    }

    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
      return null;
    }

    CategoryDataset dataset = p.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
      toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
      urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);

    LegendItem item = new LegendItem(label, description, toolTipText, urlText, shape, paint);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
      item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getRowKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);
    return item;
  }
예제 #7
0
  /**
   * Returns a legend item for the specified series.
   *
   * @param datasetIndex the dataset index (zero-based).
   * @param series the series index (zero-based).
   * @return A legend item for the series (possibly {@code null}).
   */
  @Override
  public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot plot = getPlot();
    if (plot == null) {
      return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
      return null;
    }

    if (!getItemVisible(series, 0)) {
      return null;
    }
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
      toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
      urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    boolean shapeIsVisible = getItemShapeVisible(series, 0);
    Shape shape = lookupLegendShape(series);
    boolean shapeIsFilled = getItemShapeFilled(series, 0);
    Paint fillPaint =
        (this.useFillPaint ? lookupSeriesFillPaint(series) : lookupSeriesPaint(series));
    boolean shapeOutlineVisible = this.drawOutlines;
    Paint outlinePaint =
        (this.useOutlinePaint ? lookupSeriesOutlinePaint(series) : lookupSeriesPaint(series));
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    boolean lineVisible = getItemLineVisible(series, 0);
    Stroke lineStroke = lookupSeriesStroke(series);
    Paint linePaint = lookupSeriesPaint(series);
    LegendItem result =
        new LegendItem(
            label,
            description,
            toolTipText,
            urlText,
            shapeIsVisible,
            shape,
            shapeIsFilled,
            fillPaint,
            shapeOutlineVisible,
            outlinePaint,
            outlineStroke,
            lineVisible,
            this.legendLine,
            lineStroke,
            linePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
      result.setLabelPaint(labelPaint);
    }
    result.setSeriesKey(dataset.getSeriesKey(series));
    result.setSeriesIndex(series);
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);

    return result;
  }