Пример #1
0
  public void paint(Graphics g) {
    m_fm = g.getFontMetrics();

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    m_insets = getInsets();
    int x = m_insets.left;
    int y = m_insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
      String sNext = st.nextToken();
      g.drawString(sNext, x, y);
      x += m_fm.stringWidth(sNext);

      if (!st.hasMoreTokens()) break;
      int index = 0;
      while (x >= getTab(index)) index++;
      x = getTab(index);
    }
  }
  public void draw(Graphics page) // draws letter on screen
      {

    page.setColor(color);
    page.setFont(new Font("TimesRoman", Font.PLAIN, 24));
    page.drawString(testString, x, y);
  }
Пример #3
0
 /**
  * Repaint the drawing panel
  *
  * @param g The Graphics context
  */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   // Draw the background that will be beside the board
   g.drawImage(background, 0, 0, this);
   for (int row = 0; row < 16; row++) {
     for (int col = 0; col < 16; col++) {
       board[row][col].draw(g);
     }
   }
   int seconds = (time / 10);
   g.setColor(Color.WHITE);
   g.setFont(new Font("Century Gothic", Font.BOLD, 65));
   g.drawString("" + seconds, 1075, 205);
 } // paint component method
    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));
    }
  public void paintComponent(Graphics screen) {
    if (inactive == null) {
      inactive = new Image[BUTTON_COUNT];
      rollover = new Image[BUTTON_COUNT];
      active = new Image[BUTTON_COUNT];

      int IMAGE_SIZE = 33;

      for (int i = 0; i < BUTTON_COUNT; i++) {
        inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        Graphics g = inactive[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -2 * IMAGE_SIZE, null);

        rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = rollover[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -1 * IMAGE_SIZE, null);

        active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = active[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -0 * IMAGE_SIZE, null);
      }

      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
    }
    Dimension size = getSize();
    if ((offscreen == null) || (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      y1 = 0;
      y2 = BUTTON_HEIGHT;

      x1 = new int[buttonCount];
      x2 = new int[buttonCount];

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); // getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    // int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2;
    int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
    g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY);

    screen.drawImage(offscreen, 0, 0, null);
  }
Пример #6
0
  @Override
  public void paintComponent(Graphics screen) {
    // this data is shared by all EditorToolbar instances
    if (buttonImages == null) {
      loadButtons();
    }

    // this happens once per instance of EditorToolbar
    if (stateImage == null) {
      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
      y1 = 0;
      y2 = BUTTON_HEIGHT;
      x1 = new int[buttonCount];
      x2 = new int[buttonCount];
    }

    Dimension size = getSize();
    if ((offscreen == null) ||
        (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2 || i == 6) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
      
      // Serial button must be on the right
      x1[SERIAL] = width - BUTTON_WIDTH - 14;
      x2[SERIAL] = width - 14;
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); //getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
     * 
     * whereas I love the Java2D API. --jdf. lol.
     * 
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    if (currentRollover != -1) {
      int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
      String status = shiftPressed ? titleShift[currentRollover] : (controlPressed ? titleControl[currentRollover] : title[currentRollover]);
           
      if (currentRollover != SERIAL)
        g.drawString(status, (buttonCount-1) * BUTTON_WIDTH + 3 * BUTTON_GAP, statusY);
      else {
      	// Pending
		if(editor.serialMonitor.isOpenPending!=null)
			if(editor.serialMonitor.isOpenPending)
				status += " (Monitor will open after upload)";
  		
        int statusX = x1[SERIAL] - BUTTON_GAP;
        statusX -= g.getFontMetrics().stringWidth(status);
        g.drawString(status, statusX, statusY);
      }
    }

    screen.drawImage(offscreen, 0, 0, null);
    
    if (!isEnabled()) {
      screen.setColor(new Color(0,0,0,100));
      screen.fillRect(0, 0, getWidth(), getHeight());
  	}
  }