示例#1
0
  /**
   * Draw the vectors at the data points. If this data has been attached to an Axis then scale the
   * data based on the axis maximum/minimum otherwise scale using the data's maximum/minimum
   *
   * @param g Graphics state
   * @param bounds The data window to draw into
   */
  public void draw_data(Graphics g, Rectangle bounds) {
    Color c;

    if (xaxis != null) {
      xmax = xaxis.maximum;
      xmin = xaxis.minimum;
    }

    if (yaxis != null) {
      ymax = yaxis.maximum;
      ymin = yaxis.minimum;
    }

    xrange = xmax - xmin;
    yrange = ymax - ymin;

    /*
     ** draw the legend before we clip the data window
     */
    draw_legend(g, bounds);
    /*
     ** Clip the data window
     */
    if (clipping) g.clipRect(bounds.x, bounds.y, bounds.width, bounds.height);

    c = g.getColor();

    if (linecolor != null) g.setColor(linecolor);
    else g.setColor(c);

    drawVectors(g, bounds);

    g.setColor(c);
  }
示例#2
0
  /*
   *  Draws a frame around the data area.
   */
  protected void drawFrame(Graphics g, int x, int y, int width, int height) {
    Color c = g.getColor();

    if (framecolor != null) g.setColor(framecolor);

    g.drawRect(x, y, width, height);

    g.setColor(c);
  }
示例#3
0
  /**
   * This paints the entire plot. It calls the draw methods of all the attached axis and data sets.
   * The order of drawing is - Axis first, data legends next, data last.
   *
   * @params g Graphics state.
   */
  public void paint(Graphics g) {
    int i;
    Graphics lg = g.create();
    Rectangle r = bounds();

    /* The r.x and r.y returned from bounds is relative to the
     ** parents space so set them equal to zero.
     */
    r.x = 0;
    r.y = 0;

    if (DefaultBackground == null) DefaultBackground = this.getBackground();
    if (DataBackground == null) DataBackground = this.getBackground();

    //        System.out.println("Graph2D paint method called!");

    if (!paintAll) return;

    r.x += borderLeft;
    r.y += borderTop;
    r.width -= borderLeft + borderRight;
    r.height -= borderBottom + borderTop;

    paintFirst(lg, r);

    if (!axis.isEmpty()) r = drawAxis(lg, r);
    else {
      if (clearAll) {
        Color c = g.getColor();
        g.setColor(DataBackground);
        g.fillRect(r.x, r.y, r.width, r.height);
        g.setColor(c);
      }
      drawFrame(lg, r.x, r.y, r.width, r.height);
    }

    paintBeforeData(lg, r);

    if (!dataset.isEmpty()) {

      datarect.x = r.x;
      datarect.y = r.y;
      datarect.width = r.width;
      datarect.height = r.height;

      for (i = 0; i < dataset.size(); i++) {
        ((DataSet) dataset.elementAt(i)).draw_data(lg, r);
      }
    }

    paintLast(lg, r);

    lg.dispose();
  }
示例#4
0
 public void drawBomb(Graphics g, int x, int y) {
   Color c = g.getColor();
   g.setColor(new Color(128, 128, 128));
   g.drawLine(x + 2, y + 7, x + 12, y + 7);
   g.drawLine(x + 7, y + 2, x + 7, y + 12);
   g.fillRect(x + 6, y + 4, 3, 7);
   g.fillRect(x + 4, y + 6, 7, 3);
   g.setColor(Color.black);
   g.fillRect(x + 5, y + 5, 5, 5);
   g.drawLine(x + 3, y + 7, x + 11, y + 7);
   g.drawLine(x + 7, y + 3, x + 7, y + 11);
   g.drawLine(x + 4, y + 4, x + 4, y + 4);
   g.drawLine(x + 4, y + 10, x + 4, y + 10);
   g.drawLine(x + 10, y + 4, x + 10, y + 4);
   g.drawLine(x + 10, y + 10, x + 10, y + 10);
   g.setColor(Color.white);
   g.drawLine(x + 6, y + 6, x + 6, y + 6);
   g.setColor(c);
 }
示例#5
0
  /**
   * This method is called via the Graph2D.repaint() method. All it does is blank the canvas (with
   * the background color) before calling paint.
   */
  public void update(Graphics g) {

    //          System.out.println("Graph2d update method called");
    if (clearAll) {
      Color c = g.getColor();
      /* The r.x and r.y returned from bounds is relative to the
       ** parents space so set them equal to zero
       */
      Rectangle r = bounds();

      r.x = 0;
      r.y = 0;

      g.setColor(getBackground());
      g.fillRect(r.x, r.y, r.width, r.height);
      g.setColor(c);
    }

    if (paintAll) paint(g);
  }
示例#6
0
  /**
   * Draw the Axis. As each axis is drawn and aligned less of the canvas is avaliable to plot the
   * data. The returned Rectangle is the canvas area that the data is plotted in.
   */
  protected Rectangle drawAxis(Graphics g, Rectangle r) {
    Axis a;
    int waxis;
    Rectangle dr;
    int x;
    int y;
    int width;
    int height;

    if (square) r = ForceSquare(g, r);

    dr = getDataRectangle(g, r);

    x = dr.x;
    y = dr.y;
    width = dr.width;
    height = dr.height;

    if (clearAll) {
      Color c = g.getColor();
      g.setColor(DataBackground);
      g.fillRect(x, y, width, height);
      g.setColor(c);
    }

    // Draw a frame around the data area (If requested)
    if (frame) drawFrame(g, x, y, width, height);

    // Now draw the axis in the order specified aligning them with the final
    // data area.
    for (int i = 0; i < axis.size(); i++) {
      a = ((Axis) axis.elementAt(i));

      a.data_window = new Dimension(width, height);

      switch (a.getAxisPos()) {
        case Axis.LEFT:
          r.x += a.width;
          r.width -= a.width;
          a.positionAxis(r.x, r.x, y, y + height);
          if (r.x == x) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
        case Axis.RIGHT:
          r.width -= a.width;
          a.positionAxis(r.x + r.width, r.x + r.width, y, y + height);
          if (r.x + r.width == x + width) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
        case Axis.TOP:
          r.y += a.width;
          r.height -= a.width;
          a.positionAxis(x, x + width, r.y, r.y);
          if (r.y == y) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
        case Axis.BOTTOM:
          r.height -= a.width;
          a.positionAxis(x, x + width, r.y + r.height, r.y + r.height);
          if (r.y + r.height == y + height) {
            a.gridcolor = gridcolor;
            a.drawgrid = drawgrid;
            a.zerocolor = zerocolor;
            a.drawzero = drawzero;
          }

          a.drawAxis(g);

          a.drawgrid = false;
          a.drawzero = false;

          break;
      }
    }

    return r;
  }
示例#7
0
 public void drawBlock(Graphics g, int r, int c, int mode) {
   Color curr = g.getColor();
   g.setColor(Color.black);
   int inc = 2;
   int xpos = inc + (c * wt), ypos = inc + (r * ht);
   switch (mode) {
     case 1:
       { // drawn on a square with an unclicked
         // bomb
         drawBomb(g, xpos, ypos);
         break;
       }
     case 2:
       { // draws a cell with a number on it
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
         if (field[r][c] > 0) {
           g.setFont(new Font("Serif", Font.BOLD, 12));
           g.setColor(list[field[r][c] - 1]);
           g.drawString(field[r][c] + "", xpos + 5, ypos + 12);
         }
       }
       break;
     case 3:
       { // drawn on the square where the bomb was clicked
         g.setColor(Color.red);
         g.fillRect(xpos, ypos, wt, ht);
         g.setColor(Color.black);
         drawBomb(g, xpos, ypos);
       }
       break;
     case 4:
       { // draws a plain unrevealed cell
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
       }
       break;
     case 5:
       { // a Flag.
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
         g.setColor(Color.red);
         g.fillRect(xpos + 4, ypos + 3, 4, 4);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 8, ypos + 3, xpos + 8, ypos + 6);
         g.drawLine(xpos + 8, ypos + 6, xpos + 5, ypos + 6);
         g.drawLine(xpos + 6, ypos + 5, xpos + 7, ypos + 5);
         g.drawLine(xpos + 7, ypos + 5, xpos + 7, ypos + 4);
         g.setColor(new Color(128, 128, 128));
         g.drawLine(xpos + 5, ypos + 12, xpos + 11, ypos + 12);
         g.drawLine(xpos + 7, ypos + 11, xpos + 9, ypos + 11);
         g.setColor(Color.black);
         g.drawLine(xpos + 8, ypos + 7, xpos + 8, ypos + 11);
         g.drawLine(xpos + 6, ypos + 12, xpos + 10, ypos + 12);
       }
       break;
     case 6:
       { // A red cross - flag over non mine block
         g.setColor(Color.red);
         g.drawLine(xpos + 3, ypos + 3, xpos + 11, ypos + 11);
         g.drawLine(xpos + 4, ypos + 3, xpos + 12, ypos + 11);
         g.drawLine(xpos + 12, ypos + 3, xpos + 4, ypos + 11);
         g.drawLine(xpos + 3, ypos + 11, xpos + 11, ypos + 3);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 3, ypos + 12, xpos + 4, ypos + 12);
         g.drawLine(xpos + 4, ypos + 12, xpos + 7, ypos + 9);
         g.drawLine(xpos + 8, ypos + 9, xpos + 11, ypos + 12);
         g.drawLine(xpos + 11, ypos + 12, xpos + 12, ypos + 12);
         g.drawLine(xpos + 3, ypos + 4, xpos + 6, ypos + 7);
         g.drawLine(xpos + 12, ypos + 4, xpos + 9, ypos + 7);
       }
       break;
     case 7:
       {
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
       }
       break;
   }
   g.setColor(curr);
 }
示例#8
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);
    }
  }