示例#1
0
  /**
   * Creates an image map element that complies with the XHTML 1.0 specification.
   *
   * @param name the map name (<code>null</code> not permitted).
   * @param info the chart rendering info (<code>null</code> not permitted).
   * @param toolTipTagFragmentGenerator a generator for the HTML fragment that will contain the
   *     tooltip text (<code>null</code> not permitted if <code>info</code> contains tooltip
   *     information).
   * @param urlTagFragmentGenerator a generator for the HTML fragment that will contain the URL
   *     reference (<code>null</code> not permitted if <code>info</code> contains URLs).
   * @return The map tag.
   */
  public static String getImageMap(
      String name,
      ChartRenderingInfo info,
      ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
      URLTagFragmentGenerator urlTagFragmentGenerator) {

    StringBuilder sb = new StringBuilder();
    sb.append("<map id=\"").append(htmlEscape(name));
    sb.append("\" name=\"").append(htmlEscape(name)).append("\">");
    sb.append(StringUtils.getLineSeparator());
    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
      int count = entities.getEntityCount();
      for (int i = count - 1; i >= 0; i--) {
        ChartEntity entity = entities.getEntity(i);
        if (entity.getToolTipText() != null || entity.getURLText() != null) {
          String area =
              entity.getImageMapAreaTag(toolTipTagFragmentGenerator, urlTagFragmentGenerator);
          if (area.length() > 0) {
            sb.append(area);
            sb.append(StringUtils.getLineSeparator());
          }
        }
      }
    }
    sb.append("</map>");
    return sb.toString();
  }
示例#2
0
    /* (non-Javadoc)
     * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
     */
    @Override
    public void paint(Graphics g) {
      super.paint(g);

      if (rect != null) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(Color.RED);

        adjustRect(rect);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setStroke(lineStroke);

        if (boundings == null) {
          boundings = new Rectangle[4];

          if (entities == null) {
            entities = new ArrayList<CategoryItemEntity>();
            EntityCollection entCol = chartPanel.getChartRenderingInfo().getEntityCollection();

            for (int i = 0; i < entCol.getEntityCount(); i++) {
              ChartEntity ce = (ChartEntity) entCol.getEntity(i);
              if (ce instanceof CategoryItemEntity) {
                CategoryItemEntity cie = (CategoryItemEntity) ce;
                Rectangle r = adjustRect(cie.getArea().getBounds());
                if (r.height > maxHeight) {
                  maxHeight = (int) cie.getArea().getBounds().getHeight();
                  maxY = r.y;
                }
                entities.add(cie);
              }
            }
          }

          int half = (entities.size() - 1) / 2;
          boundings[0] = getEntityPoint(entities, 0);
          boundings[1] = getEntityPoint(entities, half);
          boundings[2] = getEntityPoint(entities, half + 1);
          boundings[3] = getEntityPoint(entities, entities.size() - 1);

          int[] inxs = new int[] {0, half, half + 1, entities.size() - 1};
          currEntities = new CategoryItemEntity[4];
          for (int i = 0; i < inxs.length; i++) {
            currEntities[i] = entities.get(inxs[i]);
          }
        }

        for (Rectangle r : boundings) {
          g.drawImage(
              thumb.getImage(),
              r.x - (thumb.getIconWidth() / 2) + 2,
              r.y + r.height - thumb.getIconHeight(),
              null);
        }

        int x = (int) ((double) boundings[0].x * 1); // chartPanel.getScaleX());
        int w = (int) ((double) (boundings[1].x - boundings[0].x) * 1); // chartPanel.getScaleX());

        // int y = (int)((double)maxY * chartPanel.getScaleY());
        int h = (int) ((double) maxHeight * chartPanel.getScaleY());

        g2d.setColor(new Color(255, 255, 255, 64));
        g2d.fillRect(x + 2, maxY, w, h);

        x = (int) ((double) boundings[2].x * 1); // chartPanel.getScaleX());
        w = (int) ((double) (boundings[3].x - boundings[2].x) * 1); // chartPanel.getScaleX());

        g2d.setColor(new Color(255, 255, 255, 64));
        g2d.fillRect(x + 2, maxY, w, h);
      }
    }