Пример #1
0
  /**
   * Draw a legend for this data set
   *
   * @param g Graphics context
   * @param w Data Window
   */
  protected void draw_legend(Graphics g, Rectangle w) {
    Color c = g.getColor();
    Markers m = null;

    if (legend_text == null) return;
    if (legend_text.isNull()) return;

    if (legend_ix == 0 && legend_iy == 0) {
      legend_ix = (int) (w.x + ((legend_dx - xmin) / xrange) * w.width);
      legend_iy = (int) (w.y + (1.0 - (legend_dy - ymin) / yrange) * w.height);
    }

    if (linestyle != DataSet.NOLINE) {
      if (linecolor != null) g.setColor(linecolor);
      g.drawLine(legend_ix, legend_iy, legend_ix + legend_length, legend_iy);
    }

    if (marker > 0) {
      m = g2d.getMarkers();
      if (m != null) {
        if (markercolor != null) g.setColor(markercolor);
        else g.setColor(c);

        m.draw(g, marker, 1.0, legend_ix + legend_length / 2, legend_iy);
      }
    }

    legend_text.draw(
        g,
        legend_ix + legend_length + legend_text.charWidth(g, ' '),
        legend_iy + legend_text.getAscent(g) / 3);

    g.setColor(c);
  }
Пример #2
0
 /**
  * Define a data legend in the graph window
  *
  * @param x data position of the legend.
  * @param y data position of the legend.
  * @param text text to display in the legend
  */
 public void legend(double x, double y, String text) {
   if (text == null) {
     legend_text = null;
     return;
   }
   if (legend_text == null) legend_text = new TextLine(text);
   else legend_text.setText(text);
   legend_text.setJustification(TextLine.LEFT);
   legend_dx = x;
   legend_dy = y;
   legend_ix = 0;
   legend_iy = 0;
 }
Пример #3
0
  /**
   * Copy the state of the parsed Textline into the existing object.
   *
   * @param t The TextLine to get the state information from.
   */
  public void copyState(TextLine t) {
    if (t == null) return;

    font = t.getFont();
    color = t.getColor();
    justification = t.getJustification();

    if (font == null) return;
    fontname = font.getName();
    fontstyle = font.getStyle();
    fontsize = font.getSize();

    parse = true;
  }
Пример #4
0
 /**
  * A hook into the Graph2D.paint method. This is called after everything has been drawn. The
  * rectangle passed is the dimension of the data window.
  *
  * @params g Graphics state
  * @params r Rectangle containing the data
  */
 public void paintLast(Graphics g, Rectangle r) {
   if (lastText != null) {
     lastText.draw(g, r.width / 2, r.height / 2, TextLine.CENTER);
   }
 }
Пример #5
0
  /**
   * Set the color for the legend text
   *
   * @param c color
   */
  public void legendColor(Color c) {
    if (c == null) return;
    if (legend_text == null) legend_text = new TextLine();

    legend_text.setColor(c);
  }
Пример #6
0
  /**
   * Set the font to be used in the legend
   *
   * @param f font
   */
  public void legendFont(Font f) {
    if (f == null) return;
    if (legend_text == null) legend_text = new TextLine();

    legend_text.setFont(f);
  }
Пример #7
0
  /**
   * Draw a legend for this Vector set
   *
   * @param g Graphics context
   * @param w Data Window
   */
  protected void draw_legend(Graphics g, Rectangle w) {
    Color c = g.getColor();
    TextLine value = new TextLine();
    double dx;
    int ix, iy;
    int length;

    if (!drawlegend) return;
    /*
     ** Calculate the vector magnitude of a line legend_length
     ** pixels long. This will be our standard vector
     */

    dx = xrange * ((double) legend_length) / ((double) w.width) / getScaleFactor();

    value.parseDouble(dx, 3);
    /*
     ** Calculate the length of the legend
     */
    length = legend_length + value.getWidth(g) + value.charWidth(g, ' ');
    /*
     ** Calculate the position of the legend if needed.
     */

    if (legend_ix == 0 && legend_iy == 0) {
      legend_ix = (int) (w.x + ((legend_dx - xmin) / xrange) * w.width);
      legend_iy = (int) (w.y + (1.0 - (legend_dy - ymin) / yrange) * w.height);
    } else if (legend_ix == -1 && legend_iy == -1) {
      legend_ix = w.x + w.width / 2 - length / 2;
      legend_iy = w.y - value.getAscent(g) / 2;
    }

    /*
     ** In what follows the vector tail is the zero point. It is on
     ** the right - the vector points to the left
     */
    if (linecolor != null) g.setColor(linecolor);
    /*
     ** Draw the standard vector
     */

    g.drawLine(legend_ix, legend_iy, legend_ix + legend_length, legend_iy);

    ix = legend_ix + (int) (0.25 * (double) legend_length + 0.5);
    iy = legend_iy - (int) (0.25 * (double) legend_length + 0.5);

    g.drawLine(legend_ix, legend_iy, ix, iy);

    ix = legend_ix + (int) (0.25 * (double) legend_length + 0.5);
    iy = legend_iy + (int) (0.25 * (double) legend_length + 0.5);

    g.drawLine(legend_ix, legend_iy, ix, iy);
    /*
     ** Add the value of the standard vector. To the right of the vector
     */
    value.draw(g, legend_ix + legend_length + value.charWidth(g, ' '), iy, TextLine.LEFT);
    /*
     ** Add any legend text (above the vector) that might have been
     ** defined.
     */

    g.setColor(c);

    if (legend_text != null && !legend_text.isNull()) {

      legend_text.draw(
          g,
          legend_ix + length / 2,
          iy - value.getAscent(g) - legend_text.getDescent(g) - legend_text.getLeading(g),
          TextLine.CENTER);
    }
  }