Ejemplo n.º 1
0
  /**
   * This method is to be called from the <code>paint(Graphics g)</code> method of the drawing
   * panel/canvas. It uses the graphical context of the drawing panel/canvas to construct the
   * commentary box on the drawing panel/canvas.
   *
   * @param g Graphical context from the <code>paint(Graphics g)</code> method of the drawing
   *     panel/canvas.
   * @see Graphics
   */
  public void draw(Graphics g) {
    if (str.length() < 1) return;
    g.setColor(bg);
    g.fillPolygon(xPts, yPts, nPts);

    g.setColor(Color.black);
    g.drawPolygon(xPts, yPts, nPts);

    g.setColor(fg);
    g.setFont(font);
    g.drawString(str, topLeft.x + 4, topLeft.y + height - 10);
  }
Ejemplo n.º 2
0
  public void Draw_Arrow(Graphics g) {
    double arrow_angle;
    int[] arrow_x = new int[3];
    int[] arrow_y = new int[3];
    int[] arrow_pt = new int[2];
    double gradient, constant;
    double distance, temp_dist;
    double mid_x_diff, mid_y_diff;
    double arrow_ratio;
    double trans_pts_x, trans_pts_y;

    trans_pts_x = 0.00;
    trans_pts_y = 0.00;
    arrow_ratio = 0.00;
    mid_x_diff = 0.00;
    mid_y_diff = 0.00;
    distance = 0.00;
    temp_dist = 0.00;
    gradient = 0.00;
    constant = 0.00;
    arrow_x[0] = 0;
    arrow_x[1] = 0;
    arrow_x[2] = 0;
    arrow_y[0] = 0;
    arrow_y[1] = 0;
    arrow_y[2] = 0;
    arrow_angle = 0.00;

    arrow_angle = (start_angle + arc_angle / 2) * Math.PI / 180;
    //		if (num_arcs != 1) {
    arrow_x[0] = (int) Math.round(img_mid_x + img_cir * Math.cos(arrow_angle));
    arrow_y[0] = (int) Math.round(img_mid_y - img_cir * Math.sin(arrow_angle));
    //			}
    //		else {
    //			arrow_x[0] = mid_pt_x;
    //			arrow_y[0] = mid_pt_y;
    //			g.drawString("1", (int)arrow_x[0], (int)arrow_y[0]);
    //		}
    /*calculate the distance between the midpt (on arc) and start node*/
    mid_x_diff = Math.abs(arrow_x[0] - start_x);
    mid_y_diff = Math.abs(arrow_y[0] - start_y);

    distance = Math.sqrt((mid_x_diff * mid_x_diff) + (mid_y_diff * mid_y_diff));

    temp_dist = distance - HEAD_DISTANCE;
    arrow_ratio = temp_dist / distance;
    arrow_x[1] = (int) ((arrow_x[0] - start_x) * arrow_ratio + start_x);
    arrow_y[1] = (int) ((arrow_y[0] - start_y) * arrow_ratio + start_y);

    // calculate the gradient of the tangent
    // equation of the circle is (x-c)^2 + (y-d)^2 = R^2
    // equation of the line is y = mx + c
    gradient = ((-1) * (arrow_x[0] - img_mid_x)) / (arrow_y[0] - img_mid_y);
    // find the constant value of the line
    constant = arrow_y[0] - gradient * arrow_x[0];

    arrow_pt = Translated_Point(constant, arrow_x, arrow_y, gradient);
    arrow_x[2] = arrow_pt[0];
    arrow_y[2] = arrow_pt[1];

    if (num_arcs == 1 && testcase != 10) {
      /*x and y distances between mid pts and arc mid pts */
      trans_pts_x = arrow_x[0] - mid_pt_x;
      trans_pts_y = arrow_y[0] - mid_pt_y;
      arrow_x[0] = mid_pt_x;
      arrow_y[0] = mid_pt_y;
      arrow_x[1] = arrow_x[1] - (int) trans_pts_x;
      arrow_y[1] = arrow_y[1] - (int) trans_pts_y;
      arrow_x[2] = arrow_x[2] - (int) trans_pts_x;
      arrow_y[2] = arrow_y[2] - (int) trans_pts_y;
    } else if (num_arcs == 1 && testcase == 10) {
      System.out.println("hello...");
      arrow_x[0] = (int) (start_x - diameter);
      arrow_y[0] = (int) start_y;
      arrow_x[1] = (int) (diameter / 4 + arrow_x[0]);
      arrow_y[1] = (int) (diameter / 6 - arrow_y[0]);
      arrow_x[2] = (int) (diameter / 4 - arrow_x[0]);
      arrow_y[2] = (int) (diameter / 6 - arrow_y[0]);
    }
    g.setColor(arrow_colour);
    g.fillPolygon(arrow_x, arrow_y, 3);
    if (value != 0) {
      g.setColor(value_colour);
      if (show_cost) {
        Display_Value(g, arrow_x, arrow_y);
      }
    }
  }