Пример #1
0
  // ------------------------------------------------------------------------
  // SCREEN PAINTER
  // Put some function here to paint whatever you want over the screen before and after
  // all edges and nodes have been painted.
  public void PaintScreenBefore(Graphics g) {

    Dimension d = MainClass.mainFrame.GetGraphDisplayPanel().getSize();
    NodeInfo nodeInfo;
    int x = 0;
    int y = 0;
    int step = 10;

    for (; x < d.width; x += step) {
      for (y = 0; y < d.height; y += step) {
        double val = 0;
        double sum = 0;
        double total = 0;
        double min = 10000000;
        for (Enumeration nodes = proprietaryNodeInfo.elements(); nodes.hasMoreElements(); ) {
          nodeInfo = (NodeInfo) nodes.nextElement();
          double dist = distance(x, y, nodeInfo.centerX, nodeInfo.centerY);
          if (nodeInfo.value != -1 && nodeInfo.nodeNumber.intValue() != 1) { // 121
            if (dist < min) min = dist;
            val += ((double) nodeInfo.value) / dist / dist;
            sum += (1 / dist / dist);
          }
        }
        int reading = (int) (val / sum);
        reading = reading >> 2;
        if (reading > 255) reading = 255;
        g.setColor(new Color(reading, reading, reading));
        g.fillRect(x, y, step, step);
      }
    }
  }
Пример #2
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);
  }
Пример #3
0
  /**
   * @param g Graphics context.
   * @param ch The character.
   * @return the width of the character.
   */
  public int charWidth(Graphics g, char ch) {
    FontMetrics fm;
    if (g == null) return 0;

    if (font == null) fm = g.getFontMetrics();
    else fm = g.getFontMetrics(font);

    return fm.charWidth(ch);
  }
Пример #4
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);
  }
Пример #5
0
  protected void drawVectors(Graphics g, Rectangle w) {

    int ix0, iy0;
    int ix1, iy1;

    double x0, y0, x1, y1, dx, dy;

    //      Is there any data to draw? Sometimes the draw command will
    //      will be called before any data has been placed in the class.

    if (data == null || data.length < stride) return;

    //      Lets draw the vectors

    for (int i = 0; i < length; i += stride) {

      x0 = data[i];
      y0 = data[i + 1];
      dx = data[i + 2] * getScaleFactor();
      dy = data[i + 3] * getScaleFactor();

      x1 = x0 + dx;
      y1 = y0 + dy;

      if (inside(x0, y0) || inside(x1, y1)) {

        ix0 = (int) (w.x + ((x0 - xmin) / xrange) * w.width);
        iy0 = (int) (w.y + (1.0 - (y0 - ymin) / yrange) * w.height);

        ix1 = (int) (w.x + ((x1 - xmin) / xrange) * w.width);
        iy1 = (int) (w.y + (1.0 - (y1 - ymin) / yrange) * w.height);

        g.drawLine(ix0, iy0, ix1, iy1);

        /*
         ** Now draw the head of the vector. To avoid scaling problems
         ** the head is drawn using pixel units. This would not work
         ** if we had multiple output devices.
         */

        dx = (double) (ix1 - ix0);
        dy = (double) (iy1 - iy0);

        ix0 = ix1 - (int) (0.25 * (dx - dy) + 0.5);
        iy0 = iy1 - (int) (0.25 * (dx + dy) + 0.5);

        g.drawLine(ix0, iy0, ix1, iy1);

        ix0 = ix1 - (int) (0.25 * (dx + dy) + 0.5);
        iy0 = iy1 - (int) (0.25 * (-dx + dy) + 0.5);

        g.drawLine(ix0, iy0, ix1, iy1);
      }
    }
  }
Пример #6
0
 void drawBricks(Graphics g) {
   for (int x = 0; x < numBricksX; x++) {
     for (int y = 0; y < numBricksY; y++) {
       if (brickWall[x][y].notBroken()) {
         g.setColor(brickWall[x][y].colour());
         g.fillRect(
             brickWall[x][y].brickX(),
             brickWall[x][y].brickY(),
             brickWall[x][y].brickWidth(),
             brickWall[x][y].brickHeight());
       }
     }
   }
 }
Пример #7
0
 public void paint(Graphics g) {
   if (mainMenu) {
     drawTitleScreen(g);
   } else if (gamePlaying) {
     drawBricks(g);
     g.setColor(Color.green);
     g.fillRect(pad.x(), 590, pad.width(), 10);
     g.fillOval(
         ball.x_Pos() - ball.radius(),
         ball.y_Pos() - ball.radius(),
         ball.radius() * 2,
         ball.radius() * 2);
   }
 } // paint method
Пример #8
0
 /** Update - Method, implements double buffering */
 public void update(Graphics g) {
   // initialize buffer
   if (dbImage == null) {
     dbImage = createImage(this.getSize().width, this.getSize().height);
     dbg = dbImage.getGraphics();
   }
   // clear screen in background
   dbg.setColor(getBackground());
   dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
   // draw elements in background
   dbg.setColor(getForeground());
   paint(dbg);
   // draw image on the screen
   g.drawImage(dbImage, 0, 0, this);
 }
Пример #9
0
  public void paint(Graphics g) {
    Message("Copyright Feb, 2000 Weicon Conan Yuan.", "All Rights Reserved", 7);
    for (int i = 0; i < NUM_LOCATIONS; i++) {
      locs[i].draw(g, this);
      g.setColor(txtcolor);
      if (locs[i].ToDraw()) {
        g.drawString("" + i, locs[i].GetX(), locs[i].GetY() + 10);
      }
    }

    g.setColor(Color.red);
    g.drawRect(400, 200, 30, 30);
    g.fillRect(400, 200, 30, 30);
    Message("Cheat", 4);
  }
Пример #10
0
  /** end displaying message and force a graph repaint */
  public void end() {

    super.stop();

    g2d.clearAll = true;
    g2d.paintAll = true;

    if (lg != null) lg.dispose();

    g2d.repaint();
  }
Пример #11
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);
  }
Пример #12
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();
  }
Пример #13
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);
  }
Пример #14
0
    public void centerText(String s1, String s2, Graphics g, Color c, int x, int y, int w, int h) {
      // locs[0].centerText(s1, s2, this.getGraphics(),
      // Color.white, 400,0,200,50);
      // g.setXORMode(unselected_color);
      // centerText("pic" + im, null, g, Color.black, x, y, w, h);

      Font f = g.getFont();
      FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(f);
      int ascent = fm.getAscent();
      int height = fm.getHeight();
      int width1 = 0, width2 = 0, x0 = 0, x1 = 0, y0 = 0, y1 = 0;
      width1 = fm.stringWidth(s1);
      if (s2 != null) width2 = fm.stringWidth(s2);
      x0 = x + (w - width1) / 2;
      x0 = x + (w - width2) / 2;
      if (s2 == null) y0 = y + (h - height) / 2 + ascent;
      else {
        y0 = y + (h - (int) (height * 2.2)) / 2 + ascent;
        y1 = y0 + (int) (height * 1.2);
      }
      g.setColor(c);
      g.drawString(s1, x0, y0);
      if (s2 != null) g.drawString(s2, x1, y1);
    }
Пример #15
0
  private void Display_Value(Graphics g, int[] ax, int[] ay) {
    int pos_x, pos_y;

    pos_x = 0;
    pos_y = 0;

    switch (testcase) {
      case 1:
        pos_x = ax[2];
        pos_y = ay[2];
        break;
      case 2:
        pos_x = ax[2];
        pos_y = ay[2];
        break;
      case 3:
        pos_x = ax[0];
        pos_y = ay[0];
        break;
      case 4:
        pos_x = ax[1];
        pos_y = ay[1];
        break;
      case 5:
        pos_x = ax[1];
        pos_y = ay[1];
        break;
      case 6:
        pos_x = ax[2];
        pos_y = ay[2];
        break;
      case 7:
        pos_x = ax[2];
        pos_y = ay[2];
        break;
      case 8:
        pos_x = ax[2];
        pos_y = ay[2];
        break;
      case 10:
        pos_x = ax[2];
        pos_y = ay[2];
        break;
      default:
        break;
    }
    g.drawString("" + value, pos_x, pos_y);
  }
Пример #16
0
    public void draw(Graphics g, ImageObserver ob) {
      if (!todraw) {
        g.setColor(bgcolor);
        g.drawRect(x, y, w + 2 * border, h + 2 * border);
        g.fillRect(x, y, w + 2 * border, h + 2 * border);
        return;
      }

      if (selected) g.setColor(selected_color);
      else g.setColor(unselected_color);

      g.drawRect(x, y, w + 2 * border, h + 2 * border);
      g.fillRect(x, y, w + 2 * border, h + 2 * border);
      g.drawImage(image[im], x + border, y + border, ob);

      // g.setColor(Color.black);
      // g.drawString("" + im,x+5,y+5);
    }
Пример #17
0
  /** paints the Spinner */
  public void paint(Graphics g) {
    int start_angle = 90;
    int done_angle = (int) (percentDone * 360);

    g.setColor(getBackground());
    g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360);

    g.setColor(getForeground());
    g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, start_angle, done_angle);

    g.setColor(Color.black);
    g.drawArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360);
  }
Пример #18
0
  public void Message(String s1, String s2, int i) {
    Graphics g = getGraphics();

    if (s1 == null || s2 == null) {
      g.setColor(bgcolor);
      g.drawRect(400, 50 * i - 10, 200, 20);
      g.fillRect(400, 50 * i - 10, 200, 20);
      return;
    }
    /*
      g.setColor(Color.blue);
      g.drawRect(400,50 * i - 10,200,20);
      g.fillRect(400,50 * i - 10,200,20);
    */
    g.setColor(txtcolor);
    g.drawString(s1, 400, 50 * i);
    g.drawString(s2, 400, 50 * i + 10);
  }
  /**
   * This generates the sector image for the specific planet. Will generate from 10,10 on the sector
   * list .
   */
  public Graphics wantSmallPlanetFrame(Graphics g, int x, int y, int zoomFactor, JPanel p) {

    // p.getGraphics().drawImage(smallPlanets[planetType], x, y, zoomFactor*25, zoomFactor*25, p);
    // darkgray gray lightgrey orange pink blue red black white

    if (planetType == VERONIAN) {
      g.drawImage(
          Planets[0],
          x + 10 * zoomFactor,
          y + 10 * zoomFactor,
          20 * zoomFactor,
          20 * zoomFactor,
          p);
      //                 g.setColor(Color.orange);
      //               g.drawOval(x+10*zoomFactor, y+10*zoomFactor, 20*zoomFactor, 20*zoomFactor);
      //               g.fillOval(x+10*zoomFactor, y+10*zoomFactor, 20*zoomFactor, 20*zoomFactor);
      //   System.out.println("type" + planetType);
    }

    if (planetType == ERIS) {
      g.drawImage(
          Planets[1],
          x + 10 * zoomFactor,
          y + 10 * zoomFactor,
          20 * zoomFactor,
          20 * zoomFactor,
          p);
      //                g.setColor(Color.blue);
      //              g.drawOval(x+5*zoomFactor, y+5*zoomFactor, 14*zoomFactor, 14*zoomFactor);
      //              g.fillOval(x+5*zoomFactor, y+5*zoomFactor, 14*zoomFactor, 14*zoomFactor);
      //  System.out.println("type" + planetType);
    }

    if (planetType == TIERRAN) {
      g.drawImage(
          Planets[2],
          x + 10 * zoomFactor,
          y + 10 * zoomFactor,
          20 * zoomFactor,
          20 * zoomFactor,
          p);
      //                g.setColor(Color.red);
      //              g.drawOval(x+5*zoomFactor, y+5*zoomFactor, 23*zoomFactor, 23*zoomFactor);
      //              g.fillOval(x+5*zoomFactor, y+5*zoomFactor, 23*zoomFactor, 23*zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == ADONIS) {
      g.setColor(Color.green);
      g.drawOval(x + 5 * zoomFactor, y + 5 * zoomFactor, 20 * zoomFactor, 20 * zoomFactor);
      g.fillOval(x + 5 * zoomFactor, y + 5 * zoomFactor, 20 * zoomFactor, 20 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == THESBAN) {
      g.setColor(Color.magenta);
      g.drawOval(x + 8 * zoomFactor, y + 8 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      g.fillOval(x + 8 * zoomFactor, y + 8 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == TOMEKO) {
      g.setColor(Color.gray);
      g.drawOval(x + 2 * zoomFactor, y + 25 * zoomFactor, 22 * zoomFactor, 22 * zoomFactor);
      g.fillOval(x + 2 * zoomFactor, y + 25 * zoomFactor, 22 * zoomFactor, 22 * zoomFactor);
      g.setColor(Color.red);
      g.drawOval(x + 8 * zoomFactor, y + 32 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      g.fillOval(x + 8 * zoomFactor, y + 32 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      //  System.out.println("type" + planetType);
    }

    if (planetType == RING) {
      int moo = 1;
      // int moo = randy.nextInt(4)+1;
      if (moo == 1) {
        g.setColor(Color.blue);
      }
      if (moo == 0) {
        g.setColor(Color.green);
      }

      if (moo == 2) {
        g.setColor(Color.orange);
      }
      if (moo == 3) {
        g.setColor(Color.red);
      }

      g.drawOval(x + 25 * zoomFactor, y + 30 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);
      g.fillOval(x + 25 * zoomFactor, y + 30 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);

      moo = randy.nextInt(4) + 1;
      if (moo == 3) {
        g.setColor(Color.blue);
      }
      if (moo == 2) {
        g.setColor(Color.green);
      }

      if (moo == 1) {
        g.setColor(Color.orange);
      }
      if (moo == 0) {
        g.setColor(Color.red);
      }

      g.drawOval(x + 23 * zoomFactor, y + 28 * zoomFactor, 14 * zoomFactor, 14 * zoomFactor);
      //  System.out.println("type" + planetType);
    }

    if (planetType == CRACK) {
      int moo = randy.nextInt(4) + 1;

      if (moo == 1) {
        g.setColor(Color.blue);
      }
      if (moo == 0) {
        g.setColor(Color.green);
      }

      if (moo == 2) {
        g.setColor(Color.orange);
      }
      if (moo == 3) {
        g.setColor(Color.red);
      }
      g.drawOval(x + 2 * zoomFactor, y + 2 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.fillOval(x + 2 * zoomFactor, y + 2 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      moo = randy.nextInt(4) + 1;

      if (moo == 1) {
        g.setColor(Color.blue);
      }
      if (moo == 0) {
        g.setColor(Color.green);
      }

      if (moo == 2) {
        g.setColor(Color.orange);
      }
      if (moo == 3) {
        g.setColor(Color.red);
      }

      g.drawOval(x + 5 * zoomFactor, y + 5 * zoomFactor, 20 * zoomFactor, 20 * zoomFactor);
      moo = randy.nextInt(4) + 1;

      if (moo == 1) {
        g.setColor(Color.blue);
      }
      if (moo == 0) {
        g.setColor(Color.green);
      }

      if (moo == 2) {
        g.setColor(Color.orange);
      }
      if (moo == 3) {
        g.setColor(Color.red);
      }
      g.drawOval(x + 5 * zoomFactor, y + 5 * zoomFactor, 15 * zoomFactor, 15 * zoomFactor);
      moo = randy.nextInt(4) + 1;

      if (moo == 1) {
        g.setColor(Color.blue);
      }
      if (moo == 0) {
        g.setColor(Color.green);
      }

      if (moo == 2) {
        g.setColor(Color.orange);
      }
      if (moo == 3) {
        g.setColor(Color.red);
      }
      g.drawOval(x + 8 * zoomFactor, y + 8 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);

      moo = randy.nextInt(4) + 1;

      if (moo == 1) {
        g.setColor(Color.blue);
      }
      if (moo == 0) {
        g.setColor(Color.green);
      }

      if (moo == 2) {
        g.setColor(Color.orange);
      }
      if (moo == 3) {
        g.setColor(Color.red);
      }
      g.drawOval(x + 8 * zoomFactor, y + 8 * zoomFactor, 5 * zoomFactor, 5 * zoomFactor);
      //  System.out.println("type" + planetType);
    }

    if (planetType == TITAN) {
      g.setColor(Color.darkGray);
      g.drawOval(x + 22 * zoomFactor, y + 5 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.fillOval(x + 22 * zoomFactor, y + 5 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.setColor(Color.lightGray);
      g.drawOval(x + 28 * zoomFactor, y + 13 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == STEALTH) {
      g.setColor(Color.black);
      g.drawOval(x + 2 * zoomFactor, y + 2 * zoomFactor, 4 * zoomFactor, 4 * zoomFactor);
      g.fillOval(x + 2 * zoomFactor, y + 2 * zoomFactor, 4 * zoomFactor, 4 * zoomFactor);
      g.setColor(Color.white);
      g.drawOval(x + 4 * zoomFactor, y + 4 * zoomFactor, 2 * zoomFactor, 2 * zoomFactor);
      g.fillOval(x + 4 * zoomFactor, y + 4 * zoomFactor, 2 * zoomFactor, 2 * zoomFactor);
      //  System.out.println("type" + planetType);
    }

    if (planetType == SPARTAN) {
      g.setColor(Color.red);
      g.drawOval(x + 20 * zoomFactor, y + 20 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.fillOval(x + 20 * zoomFactor, y + 20 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.setColor(Color.orange);
      g.drawOval(x + 31 * zoomFactor, y + 31 * zoomFactor, 3 * zoomFactor, 3 * zoomFactor);
      g.fillOval(x + 31 * zoomFactor, y + 31 * zoomFactor, 3 * zoomFactor, 3 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == IONIS) {
      g.setColor(Color.lightGray);
      g.drawOval(x + 18 * zoomFactor, y + 25 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.fillOval(x + 18 * zoomFactor, y + 25 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == PEYO) {
      g.setColor(Color.blue);
      g.drawOval(x + 28 * zoomFactor, y + 16 * zoomFactor, 15 * zoomFactor, 15 * zoomFactor);
      g.fillOval(x + 28 * zoomFactor, y + 16 * zoomFactor, 15 * zoomFactor, 15 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == RIEHL) {
      g.setColor(Color.pink);
      g.drawOval(x + 5 * zoomFactor, y + 5 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.fillOval(x + 5 * zoomFactor, y + 5 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.setColor(Color.orange);
      g.drawOval(x + 9 * zoomFactor, y + 9 * zoomFactor, 17 * zoomFactor, 17 * zoomFactor);
      g.fillOval(x + 9 * zoomFactor, y + 9 * zoomFactor, 17 * zoomFactor, 17 * zoomFactor);
      g.setColor(Color.yellow);
      g.drawOval(x + 13 * zoomFactor, y + 13 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);
      g.fillOval(x + 13 * zoomFactor, y + 13 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);
      //  System.out.println("type" + planetType);
    }

    if (planetType == SARENA) {
      g.setColor(Color.orange);
      g.drawOval(x + 12 * zoomFactor, y + 12 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      g.fillOval(x + 12 * zoomFactor, y + 12 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == XIAN) {
      g.setColor(Color.red);
      g.drawOval(x + 35 * zoomFactor, y + 35 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);
      g.fillOval(x + 35 * zoomFactor, y + 35 * zoomFactor, 10 * zoomFactor, 10 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == BETHELLEN) {
      g.setColor(Color.white);
      g.drawOval(x + 30 * zoomFactor, y + 8 * zoomFactor, 15 * zoomFactor, 15 * zoomFactor);
      g.fillOval(x + 30 * zoomFactor, y + 8 * zoomFactor, 15 * zoomFactor, 15 * zoomFactor);
      g.setColor(Color.gray);
      g.drawOval(x + 13 * zoomFactor, y + 13 * zoomFactor, 6 * zoomFactor, 6 * zoomFactor);
      g.fillOval(x + 13 * zoomFactor, y + 13 * zoomFactor, 6 * zoomFactor, 6 * zoomFactor);
      //  System.out.println("type" + planetType);
    }

    if (planetType == MIRRIAN) {
      g.setColor(Color.cyan);
      g.drawOval(x + 20 * zoomFactor, y + 20 * zoomFactor, 20 * zoomFactor, 20 * zoomFactor);
      g.fillOval(x + 20 * zoomFactor, y + 20 * zoomFactor, 20 * zoomFactor, 20 * zoomFactor);
      // System.out.println("type" + planetType);
    }

    if (planetType == ADANMA) {
      g.setColor(Color.red);
      g.drawOval(x + 28 * zoomFactor, y + 28 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);
      g.fillOval(x + 28 * zoomFactor, y + 28 * zoomFactor, 25 * zoomFactor, 25 * zoomFactor);

      g.setColor(Color.green);
      g.drawOval(x + 10 * zoomFactor, y + 10 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      g.fillOval(x + 10 * zoomFactor, y + 10 * zoomFactor, 9 * zoomFactor, 9 * zoomFactor);
      //  System.out.println("type" + planetType);
    }

    //           g.setColor(color);
    //             g.drawOval(x+1*zoomFactor, y+1*zoomFactor, 7*zoomFactor, 7*zoomFactor);
    //               g.fillOval(x+1*zoomFactor, y+1*zoomFactor, 7*zoomFactor, 7*zoomFactor);

    return g;
  }
Пример #20
0
  /**
   * @param g Graphics context.
   * @return the Fontmetrics the class is using.
   */
  public FontMetrics getFM(Graphics g) {
    if (g == null) return null;

    if (font == null) return g.getFontMetrics();
    else return g.getFontMetrics(font);
  }
Пример #21
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;
  }
Пример #22
0
  /**
   * parse the text. When the text is parsed the width, height, leading are all calculated. The text
   * will only be truly parsed if the graphics context has changed or the text has changed or the
   * font has changed. Otherwise nothing is done when this method is called.
   *
   * @param g Graphics context.
   */
  public void parseText(Graphics g) {
    FontMetrics fm;
    TextState current = new TextState();
    char ch;
    Stack state = new Stack();
    int w = 0;

    if (lg != g) parse = true;
    lg = g;

    if (!parse) return;

    parse = false;
    width = 0;
    leading = 0;
    ascent = 0;
    descent = 0;
    height = 0;
    maxAscent = 0;
    maxDescent = 0;

    if (text == null || g == null) return;

    list.removeAllElements();

    if (font == null) current.f = g.getFont();
    else current.f = font;

    state.push(current);
    list.addElement(current);

    fm = g.getFontMetrics(current.f);

    for (int i = 0; i < text.length(); i++) {
      ch = text.charAt(i);

      switch (ch) {
        case '$':
          i++;
          if (i < text.length()) current.s.append(text.charAt(i));
          break;
          /*
           **                    Push the current state onto the state stack
           **                    and start a new storage string
           */
        case '{':
          w = current.getWidth(g);
          if (!current.isEmpty()) {
            current = current.copyState();
            list.addElement(current);
          }

          state.push(current);
          current.x += w;
          break;
          /*
           **                    Pop the state off the state stack and set the current
           **                    state to the top of the state stack
           */
        case '}':
          w = current.x + current.getWidth(g);
          state.pop();
          current = ((TextState) state.peek()).copyState();
          list.addElement(current);
          current.x = w;
          break;
        case '^':
          w = current.getWidth(g);
          if (!current.isEmpty()) {
            current = current.copyState();
            list.addElement(current);
          }
          current.f = getScriptFont(current.f);
          current.x += w;
          current.y -= (int) ((double) (current.getAscent(g)) * sup_offset + 0.5);
          break;
        case '_':
          w = current.getWidth(g);
          if (!current.isEmpty()) {
            current = current.copyState();
            list.addElement(current);
          }
          current.f = getScriptFont(current.f);
          current.x += w;
          current.y += (int) ((double) (current.getDescent(g)) * sub_offset + 0.5);
          break;

        default:
          current.s.append(ch);
          break;
      }
    }

    for (int i = 0; i < list.size(); i++) {
      current = ((TextState) (list.elementAt(i)));

      if (!current.isEmpty()) {
        width += current.getWidth(g);
        ascent = Math.max(ascent, Math.abs(current.y) + current.getAscent(g));
        descent = Math.max(descent, Math.abs(current.y) + current.getDescent(g));
        leading = Math.max(leading, current.getLeading(g));

        maxDescent = Math.max(maxDescent, Math.abs(current.y) + current.getMaxDescent(g));
        maxAscent = Math.max(maxAscent, Math.abs(current.y) + current.getMaxAscent(g));
      }
    }

    height = ascent + descent + leading;

    return;
  }
Пример #23
0
  /** The method to call when the thread starts */
  public void run() {
    boolean draw = true;
    FontMetrics fm;
    Rectangle r;
    int sw = 0;
    int sa = 0;
    int x = 0;
    int y = 0;

    setPriority(Thread.MIN_PRIORITY);

    while (true) {

      if (newmessage != null && draw) {
        message = newmessage;
        newmessage = null;
      }

      if (lg == null) {
        lg = g2d.getGraphics();
        if (lg != null) lg = lg.create();
      }

      if (lg != null) {
        if (f != null) lg.setFont(f);
        fm = lg.getFontMetrics(lg.getFont());
        sw = fm.stringWidth(message);
        sa = fm.getAscent();
      } else {
        draw = false;
      }

      if (draw) {
        lg.setColor(foreground);
        r = g2d.bounds();
        x = r.x + (r.width - sw) / 2;
        y = r.y + (r.height + sa) / 2;
        lg.drawString(message, x, y);

        g2d.repaint();

        try {
          sleep(visible);
        } catch (Exception e) {
        }
      } else {
        if (lg != null) {
          lg.setColor(g2d.getBackground());
          lg.drawString(message, x, y);

          g2d.repaint();
        }

        try {
          sleep(invisible);
        } catch (Exception e) {
        }
      }

      draw = !draw;
    }
  }
    public void paint(Graphics g) {
      path = findOptimizedPath(srcID, dstID, type);

      /// Create the drawing board
      Dimension d = getSize();
      g.setColor(Color.white);
      g.fillRect(1, 1, d.width - 2, d.height - 2);

      g.setColor(Color.black);
      g.drawRect(1, 1, d.width - 2, d.height - 2);
      g.setFont(serifFont);

      /// Draw the whole network, including all routers with
      ///     delay and flow level, sources and destinations.
      int numR = 1;
      int w = 95;
      int h = d.height / 5;
      int pos = -1;

      for (int i = 0; i < 3; i++) {
        g.drawOval(w, h + 100 * i, 40, 40);
        g.drawString("S" + String.valueOf(i + 1), w + 13, h + 100 * i - 5);
      }

      for (int i = 0; i < 3; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 110, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 123, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 125,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 125, h + 100 * i + 35);
      }

      h = d.height / 11;
      for (int i = 0; i < 4; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 210, h + 100 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 223, h + 100 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 225,
            h + 100 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 225, h + 100 * i + 35);
      }

      h = 20;
      for (int i = 0; i < 6; i++) {
        pos++;
        Router temp = statMux.getRouter(pos);
        g.drawOval(w + 310, h + 80 * i, 40, 40);
        g.drawString("R" + String.valueOf(numR++), w + 320, h + 80 * i - 5);
        g.drawString(
            String.valueOf(temp.getDelay() * temp.getPriority(type) + temp.getFlowLevel()),
            w + 325,
            h + 80 * i + 15);
        g.drawString(String.valueOf(temp.getFlowLevel()), w + 325, h + 80 * i + 35);
      }

      for (int i = 0; i < 4; i++) {
        g.drawOval(w + 410, d.height / 11 + 100 * i, 40, 40);
        g.drawString("D" + String.valueOf(i + 1), w + 423, d.height / 11 + 100 * i - 5);
      }

      g.setColor(Color.black);
      int[][] connection = statMux.getConnections();

      /// Check buffer for connections at each step and draw links at layer1
      for (int i = 0; i < connection[path[0] - 1].length; i++) {
        int temp = connection[path[0] - 1][i] - 3;
        g.drawLine(w + 40, (path[0]) * d.height / 5 + 20, w + 110, temp * d.height / 5 + 20);
      }

      /// Check buffer for connections at each step and draw links at layer2
      for (int i = 0; i < connection[path[1] - 1].length; i++) {
        int temp = connection[path[1] - 1][i] - 7;
        g.drawLine(
            w + 150, (path[1] - 3) * d.height / 5 + 20, w + 210, (d.height / 11) + 100 * temp + 20);
      }

      /// Check buffer for connections at each step and draw links at layer3
      for (int i = 0; i < connection[path[2] - 1].length; i++) {
        int temp = connection[path[2] - 1][i] - 11;
        g.drawLine(w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * temp + 40);
      }

      /// Draw optimized path for packets traveling between source
      /// and destination
      h = d.height / 5;
      Graphics2D g2 = (Graphics2D) g;
      g2.setStroke(new BasicStroke(2));
      g2.setColor(Color.red);

      g2.drawLine(w + 40, h * (path[0]) + 20, w + 110, h * (path[1] - 3) + 20);
      g2.drawLine(
          w + 150, h * (path[1] - 3) + 20, w + 210, (d.height / 11) + 100 * (path[2] - 7) + 20);
      g2.drawLine(
          w + 250, (d.height / 11) + 100 * (path[2] - 7) + 20, w + 310, 80 * (path[3] - 11) + 40);
      g2.drawLine(
          w + 350, 80 * (path[3] - 11) + 40, w + 410, (d.height / 11) + 100 * (path[4] - 17) + 20);

      /// Calculate and display loss, delay, and throughput
      delayTime = getDelay(path, type);
      throughPut = getThroughput(path);

      int numPackLost = getLossRate(numTransfer);

      lossRate = numPackLost / 100000.0 + 0.0005 * delayTime;
      delayVal.setText(String.format("%.2f", delayTime));
      throuVal.setText(String.valueOf(throughPut));
      lossVal.setText(String.format("%.4f", lossRate));
    }
Пример #25
0
  public int getLeading(Graphics g) {
    if (g == null || f == null) return 0;

    return g.getFontMetrics(f).getLeading();
  }
Пример #26
0
  public int getMaxDescent(Graphics g) {
    if (g == null || f == null) return 0;

    return g.getFontMetrics(f).getMaxDescent();
  }
Пример #27
0
  // ------------------------------------------------------------------
  // initialize the canvas contents or judge the user's mouse events and respond
  public void paint(Graphics g) {

    // if forceNumber < 0 and !mUp: do nothing until mUp

    // if forceNumber < 0 and mUp (click): start the forces
    if (forceNumber < 0 && mUp) {
      fInit = true;
      mDown = false;
      // next line added 4/17/08 (correction for case of zero force true answer)
      mUp = false;
      forceNumber = 0;
      forceName = forceNames[forceNumber];
      userPosX = tailPosX;
      userPosY = tailPosY;
      numTries = 0;
      messageCanvas.notifyMouseClick(blinkerStrings[forceNumber]);
      // create the force equation and vector objects
      canvasEquation = new CanvasEquation(g);
      canvasVector = new CanvasVector(g);
    }

    // if mouseDown and all forces finished: do end game
    if (mDown && (forceNumber == maxForceNumber + 1)) {
      endGame("OK", cgiScript, problemNo, mouseUpsString);
    }

    // if mouseDown or mouseDrag and really a force:
    //     erase user's old vector & eqn, update position
    if ((mDown || mDrag) && (forceNumber >= 0) && (forceNumber <= maxForceNumber)) {
      messageCanvas.notifyMouseDown(blinkerStrings[forceNumber]);
      eraseUserStuff(g, forceX[0], forceY[0], 0);
      if (numEquations == 2) {
        eraseUserStuff(g, forceX[1], forceY[1], 1);
      }
      userPosX = newUserPosX;
      userPosY = newUserPosY;
    }

    // if browserPaint or forceInit or mouseDown or mouseDrag and really a force:
    //     plot fixed & user's new stuff
    if ((ifBrowserPaint || fInit || mDown || mDrag)
        && (forceNumber >= 0)
        && (forceNumber <= maxForceNumber)) {

      // redraw the userCanvas bounding box and the apparatus
      g.setColor(Color.black);
      g.drawRect(0, 0, userFrameX, userFrameY);
      problemSelector.drawUserApparatus(g);

      // draw the user's previously-done correct vectors
      if (forceNumber > 0) {
        drawDoneVectors(forceNumber - 1, g);
      }

      // draw the user's new vector and equation
      canvasVector.plotVector(tailPosX, tailPosY, userPosX, userPosY, g);
      forceX[0] = p2fX(userPosX, userPosY);
      forceY[0] = p2fY(userPosX, userPosY);
      canvasEquation.plotEquation(g, forceName, units, forceX[0], forceY[0], 0);
      if (numEquations == 2) {
        forceX[1] = (int) Math.round(cost * forceX[0] - sint * forceY[0]);
        forceY[1] = (int) Math.round(sint * forceX[0] + cost * forceY[0]);
        canvasEquation.plotEquation(g, forceName, units, forceX[1], forceY[1], 1);
      }

      // get ready up for new input
      fInit = mDown = mDrag = false;
      if (ifBrowserPaint) {
        ifBrowserPaint = false;
      }
    }

    // if mouseUp, evaluate the user's answer
    if (mUp && (forceNumber >= 0) && (forceNumber < numForces)) {

      // keep track of the mouse ups
      String leftStr = "";
      String rightStr = "";
      String midStr = mouseUpsString.substring(forceNumber, forceNumber + 1);
      if (forceNumber > 0) {
        leftStr = mouseUpsString.substring(0, forceNumber);
      }
      if (forceNumber < numForces - 1) {
        rightStr = mouseUpsString.substring(forceNumber + 1, numForces);
      }
      int numTries = Integer.parseInt(midStr);
      numTries++;
      if (numTries <= 9) {
        midStr = Integer.toString(numTries);
      } else {
        midStr = "9";
      }
      mouseUpsString = leftStr + midStr + rightStr;

      // if correct, cycle to the next force or to the trailer message
      int matchIndex = matchForceComps[forceNumber] - 1;

      int depX = Math.abs(forceX[matchIndex] - truAnsX[forceNumber][matchIndex]);
      int depY = Math.abs(forceY[matchIndex] - truAnsY[forceNumber][matchIndex]);
      if ((depX <= forceTolerance) && (depY <= forceTolerance)) {

        // erase the user's stuff
        for (int n = 0; n <= numEquations - 1; n++) {
          eraseUserStuff(g, forceX[n], forceY[n], n);
        }

        // draw the apparatus
        problemSelector.drawUserApparatus(g);

        // draw the set of correctly done vectors
        drawDoneVectors(forceNumber, g);

        // notify the resultsCanvas of the user's correctly drawn force
        boolean ifResultsDone = false;
        if (forceNumber == maxForceNumber) {
          ifResultsDone = true;
        }
        resultsCanvas.notifyMouseUpOk(
            ifResultsDone,
            forceNumber,
            forceNames,
            units,
            truAnsX,
            truAnsY,
            resultsSpacingStrings,
            numEquations,
            numForces);

        // cycle the force or do the end game
        if (forceNumber < maxForceNumber) {
          forceNumber++;
          numTries = 0;
          forceName = forceNames[forceNumber];
          userPosX = tailPosX;
          userPosY = tailPosY;
          forceX[0] = forceY[0] = forceX[1] = forceY[1] = 0;
          // draw the equation and message for the *next* force
          for (int n = 0; n <= numEquations - 1; n++) {
            canvasEquation.plotEquation(g, forceName, units, forceX[n], forceY[n], n);
          }
          // notify the messageCanvas that there is a new force
          messageCanvas.notifyMouseUpOk(blinkerStrings[forceNumber]);
        } else {
          g.setColor(userTrailerColor);
          g.drawString(userTrailer, userTrailerPosX, userTrailerPosY);
          // notify the messageCanvas that we are all done
          messageCanvas.notifyMouseUpOk("done");
          forceNumber++;
        }
      }
      // if not correct and mode > 1, check # of tries
      else {
        if (problemMode > 1 && numTries >= maxTriesEachForce) {
          endGame("notOK", cgiScript, problemNo, mouseUpsString);
        }
      }
      fInit = mUp = mDown = false;
    }
  }
Пример #28
0
  public int getHeight(Graphics g) {
    if (g == null || f == null) return 0;

    return g.getFontMetrics(f).getHeight();
  }
Пример #29
0
  /**
   * Parse the text then draw it without any rotation.
   *
   * @param g Graphics context
   * @param x pixel position of the text
   * @param y pixel position of the text
   */
  public void draw(Graphics g, int x, int y) {
    TextState ts;
    int xoffset = x;
    int yoffset = y;

    if (g == null || text == null) return;

    Graphics lg = g.create();

    parseText(g);

    if (justification == CENTER) {
      xoffset = x - width / 2;
    } else if (justification == RIGHT) {
      xoffset = x - width;
    }

    if (background != null) {
      lg.setColor(background);
      lg.fillRect(xoffset, yoffset - ascent, width, height);
      lg.setColor(g.getColor());
    }

    if (font != null) lg.setFont(font);
    if (color != null) lg.setColor(color);

    for (int i = 0; i < list.size(); i++) {
      ts = ((TextState) (list.elementAt(i)));
      if (ts.f != null) lg.setFont(ts.f);
      if (ts.s != null) lg.drawString(ts.toString(), ts.x + xoffset, ts.y + yoffset);
    }

    lg.dispose();

    lg = null;
  }
Пример #30
0
  public int getWidth(Graphics g) {

    if (g == null || f == null || s.length() == 0) return 0;

    return g.getFontMetrics(f).stringWidth(s.toString());
  }