示例#1
0
 void drawRoiLabel(Graphics g, int index, Roi roi) {
   Rectangle r = roi.getBounds();
   int x = screenX(r.x);
   int y = screenY(r.y);
   double mag = getMagnification();
   int width = (int) (r.width * mag);
   int height = (int) (r.height * mag);
   int size = width > 40 && height > 40 ? 12 : 9;
   if (font != null) {
     g.setFont(font);
     size = font.getSize();
   } else if (size == 12) g.setFont(largeFont);
   else g.setFont(smallFont);
   boolean drawingList = index >= LIST_OFFSET;
   if (drawingList) index -= LIST_OFFSET;
   String label = "" + (index + 1);
   if (drawNames && roi.getName() != null) label = roi.getName();
   FontMetrics metrics = g.getFontMetrics();
   int w = metrics.stringWidth(label);
   x = x + width / 2 - w / 2;
   y = y + height / 2 + Math.max(size / 2, 6);
   int h = metrics.getAscent() + metrics.getDescent();
   if (bgColor != null) {
     g.setColor(bgColor);
     g.fillRoundRect(x - 1, y - h + 2, w + 1, h - 3, 5, 5);
   }
   if (!drawingList && labelRects != null && index < labelRects.length)
     labelRects[index] = new Rectangle(x - 1, y - h + 2, w + 1, h);
   g.setColor(labelColor);
   g.drawString(label, x, y - 2);
   g.setColor(defaultColor);
 }
示例#2
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);
    }
  }
示例#3
0
  /** Affichage du logo */
  protected void drawLogo(Graphics g) {

    int x = 5;
    int y = 2;

    g.setColor(getBackground());
    g.fillRect(0, 0, W, H);

    // Remplissage
    fillBG(g, x, y, Color.white);

    // Dessin
    drawGrid(
        g,
        x,
        y,
        !isAvailable()
            ? Aladin.MYGRAY
            : isActive() ? Aladin.GREEN : isMouseIn() ? Color.blue : Color.black);

    // Label
    g.setColor(isAvailable() ? Color.black : Aladin.MYGRAY);
    g.setFont(Aladin.SPLAIN);
    g.drawString(LABEL, W / 2 - g.getFontMetrics().stringWidth(LABEL) / 2, H - 2);
  }
示例#4
0
  // draws the button, based on the type of button (ImageIcon, Image, or String)
  public void draw(Graphics g) {
    if (visible) {
      // if its image/imageicon, draw it
      g.setColor(new Color(50, 200, 50));
      g.fillRect(x - 1, y - 1, width + 2, height + 2);
      if (mode.equals("Image") || mode.equals("ImageIcon")) {
        if (enabled) {
          g.drawImage(image, x, y, null);
        } else {
          g.drawImage(BWimage, x, y, null);
        }
        // if its string, draw the string
      } else {

        g.setFont(new Font("Arial", Font.PLAIN, 20));
        if (enabled) {
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        } else {
          g.setColor(new Color(255, 255, 255));
          g.fillRect(x - 1, y - 1, width + 2, height + 2);
          g.setColor(Color.black);
          g.drawString(message, x + 20, y + 20);
        }
      }
    }
  }
示例#5
0
 public Foundry(Font f, Color defcol) {
   font = f;
   this.defcol = defcol;
   BufferedImage junk = TexI.mkbuf(new Coord(10, 10));
   Graphics tmpl = junk.getGraphics();
   tmpl.setFont(f);
   m = tmpl.getFontMetrics();
 }
  public void paint(Graphics g) {
    g.setFont(getFont());

    Color boxColor = getBackgroundBoxColor();
    Color hatchColor = getHatchColor();
    Color backgroundLineColor = getBackgroundLineColor();
    //    Color textColor = getForeground();
    int outlineType = getOutlineType();
    Color outlineColor = getOutlineColor();

    if (backgroundLineColor != null) {
      g.setColor(backgroundLineColor);
      g.fillRect(0, getSize().height / 2 - 1, getSize().width, 2);
    }

    if (boxColor != null) {
      g.setColor(boxColor);
      g.fillRect(0, 0, getSize().width, getSize().height);
    }

    if (hatchColor != null) {
      g.setColor(hatchColor);

      // Bev thinks the cross-hatching makes it too hard to read the base.
      // For a single diagonal line, replace the following three lines with
      // g.drawLine(0,getSize().height, getSize().width,0);
      // For an underline, replace with
      // g.drawLine(0,getSize().height, getSize().width,getSize().height);

      // Draw three cross-hatch lines
      // g.drawLine(0,0,getSize().width,getSize().height);
      // g.drawLine(getSize().width/2,0,getSize().width,getSize().height/2);
      // g.drawLine(0,getSize().height/2,getSize().width/2,getSize().height);

      // Draw a line at top and bottom of matching base
      g.drawLine(0, getSize().height, getSize().width, getSize().height); // bottom
      g.drawLine(0, 0, getSize().width, 0); // top
      //      g.drawLine(0,0, 0,getSize().height);  // left side
      //      g.drawLine(getSize().width,0, getSize().width,getSize().height);  // right side
    }

    if (outlineType != NO_OUTLINE && outlineColor != null) {
      g.setColor(outlineColor);
      g.drawLine(0, 0, getSize().width - 1, 0);
      g.drawLine(0, getSize().height - 1, getSize().width - 1, getSize().height - 1);
      if (outlineType == LEFT_OUTLINE) g.drawLine(0, 0, 0, getSize().height - 1);
      else if (outlineType == RIGHT_OUTLINE) {
        g.drawLine(getSize().width - 1, 0, getSize().width - 1, getSize().height - 1);
      }
    }

    if (getTextColor() != null) {
      int leadDistance = (getSize().width - metrics.charWidth(c)) / 2;
      g.setColor(getTextColor());
      g.drawString(c + "", leadDistance, getSize().height - 2);
    }
  }
 public void displayScore2(
     Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) {
   g.setFont(scoreFont);
   g.setColor(Color.WHITE);
   g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this);
   g.drawString("" + coins, sx1, sy1);
   g.drawString("Score:  " + score, sx2, sy2);
   g.drawString("Height:  " + height + " m", sx3, sy3);
 }
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (myCurrentWindow == null || myCurrentWindow.getFiles().length == 0) {
      g.setColor(UIUtil.isUnderDarcula() ? UIUtil.getBorderColor() : new Color(0, 0, 0, 50));
      g.drawLine(0, 0, getWidth(), 0);
    }

    if (showEmptyText()) {
      UIUtil.applyRenderingHints(g);
      g.setColor(new JBColor(Gray._100, Gray._160));
      g.setFont(UIUtil.getLabelFont().deriveFont(UIUtil.isUnderDarcula() ? 24f : 18f));

      final UIUtil.TextPainter painter =
          new UIUtil.TextPainter().withShadow(true).withLineSpacing(1.4f);
      painter.appendLine("No files are open").underlined(new JBColor(Gray._150, Gray._100));

      if (!isProjectViewVisible()) {
        painter
            .appendLine(
                "Open Project View with "
                    + KeymapUtil.getShortcutText(
                        new KeyboardShortcut(
                            KeyStroke.getKeyStroke((SystemInfo.isMac ? "meta" : "alt") + " 1"),
                            null)))
            .smaller()
            .withBullet();
      }

      painter
          .appendLine("Open a file by name with " + getActionShortcutText("GotoFile"))
          .smaller()
          .withBullet()
          .appendLine(
              "Open Recent files with " + getActionShortcutText(IdeActions.ACTION_RECENT_FILES))
          .smaller()
          .withBullet()
          .appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar"))
          .smaller()
          .withBullet()
          .appendLine("Drag'n'Drop file(s) here from " + ShowFilePathAction.getFileManagerName())
          .smaller()
          .withBullet()
          .draw(
              g,
              new PairFunction<Integer, Integer, Pair<Integer, Integer>>() {
                @Override
                public Pair<Integer, Integer> fun(Integer width, Integer height) {
                  final Dimension s = getSize();
                  return Pair.create((s.width - width) / 2, (s.height - height) / 2);
                }
              });
    }
  }
示例#9
0
文件: Process.java 项目: gablank/NTNU
 /**
  * Draws this process as a colored box with a process ID inside.
  *
  * @param g The graphics context.
  * @param x The leftmost x-coordinate of the box.
  * @param y The topmost y-coordinate of the box.
  * @param w The width of the box.
  * @param h The height of the box.
  */
 public void draw(Graphics g, int x, int y, int w, int h) {
   g.setColor(color);
   g.fillRect(x, y, w, h);
   g.setColor(Color.black);
   g.drawRect(x, y, w, h);
   g.setFont(font);
   FontMetrics fm = g.getFontMetrics(font);
   g.drawString(
       "" + processId,
       x + w / 2 - fm.stringWidth("" + processId) / 2,
       y + h / 2 + fm.getHeight() / 2);
 }
示例#10
0
  /** This internal method begins a new page and prints the header. */
  protected void newpage() {
    page = job.getGraphics(); // Begin the new page
    linenum = 0;
    charnum = 0; // Reset line and char number
    pagenum++; // Increment page number
    page.setFont(headerfont); // Set the header font.
    page.drawString(jobname, x0, headery); // Print job name left justified

    String s = "- " + pagenum + " -"; // Print the page number centered.
    int w = headermetrics.stringWidth(s);
    page.drawString(s, x0 + (this.width - w) / 2, headery);
    w = headermetrics.stringWidth(time); // Print date right justified
    page.drawString(time, x0 + width - w, headery);

    // Draw a line beneath the header
    int y = headery + headermetrics.getDescent() + 1;
    page.drawLine(x0, y, x0 + width, y);

    // Set the basic monospaced font for the rest of the page.
    page.setFont(font);
  }
示例#11
0
 public void paint(Graphics g) {
   if (comp != null) {
     width = comp.getWidth() / 6;
     height = comp.getHeight() * 2 / 3;
   }
   g.setColor(bgColor);
   g.fillRect(x, y, width, height);
   g.setColor(fgColor);
   g.setFont(font);
   g.drawString(strTray, x / 2 + width / 2, y + height + 10);
   super.paint(g);
 }
示例#12
0
 public void gameOverMenu(
     Graphics g) { // CHANGE THIS TO INCLUDE HIGHSCORES AND STUFF AFTER TEXTFILES ARE MADE
   // Menu that shows up when user gets Game Over
   if (pause == true && die == true) {
     g.drawImage(
         new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // Graphics stuff
     g.setFont(scoreFont);
     g.setColor(Color.BLACK);
     g.drawImage(new ImageIcon("InGameMenu/GameOver.png").getImage(), 10, 200, this);
     displayScore2(g, 115, 350, 185, 385, 110, 440, 110, 490); // Shows stats
     g.drawImage(menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws menu button
   }
 }
示例#13
0
 /**
  * Set the font style. The argument should be one of the font style constants defined by the
  * java.awt.Font class. All subsequent output will be in that style. This method relies on all
  * styles of the Monospaced font having the same metrics.
  */
 public void setFontStyle(int style) {
   synchronized (this.lock) {
     // Try to set a new font, but restore current one if it fails
     Font current = font;
     try {
       font = new Font("Monospaced", style, fontsize);
     } catch (Exception e) {
       font = current;
     }
     // If a page is pending, set the new font.  Otherwise newpage() will.
     if (page != null) page.setFont(font);
   }
 }
示例#14
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
示例#15
0
 public Line render(String text, Color c) {
   text = Translate.get(text);
   Coord sz = strsize(text);
   if (sz.x < 1) sz = sz.add(1, 0);
   BufferedImage img = TexI.mkbuf(sz);
   Graphics g = img.createGraphics();
   if (aa) Utils.AA(g);
   g.setFont(font);
   g.setColor(c);
   FontMetrics m = g.getFontMetrics();
   g.drawString(text, 0, m.getAscent());
   g.dispose();
   return (new Line(text, img, m));
 }
示例#16
0
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      bubbleField.draw(g);

      for (Bubble bubble : bubbeList) {

        bubble.drawBubble(g);
      }

      g.setColor(Color.WHITE);
      g.setFont(new Font("Courier New", Font.PLAIN, 16));
      g.drawString("Bubble " + bubble.toString(), 10, 20);
    }
示例#17
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;
  }
示例#18
0
  public void CalculateSize(Graphics g) {
    oldwidth = sx2 - sx1;
    oldheight = sy2 - sy1;
    Font testfont;

    testfont = new Font("TimesRoman", Font.PLAIN, 100);
    g.setFont(testfont);
    int width = g.getFontMetrics().stringWidth(short_name);
    int height = g.getFontMetrics().getHeight();
    double xratio = ((double) (oldwidth)) / ((double) width);
    double yratio = ((double) (oldheight)) / ((double) height);
    double fsize;
    if (xratio > yratio) {
      // use yratio to calculate size
      fsize = 100.0 * yratio;
    } else fsize = 100.0 * xratio;
    if (fsize < 1.0) fsize = 1.0;
    fsize = fsize * Caption.FontScale;
    currfont = new Font("TimesRoman", Font.PLAIN, (int) fsize);

    g.setFont(currfont);
    xoff = (sx2 - sx1 - g.getFontMetrics().stringWidth(short_name)) / 2;
    yoff = g.getFontMetrics().getDescent();
  }
示例#19
0
  public void Draw() {
    Graphics g;
    Color cl;
    int c;
    int xdiff, ydiff;

    g = parentarea.screen;
    if ((Resize) || (ResizeAll)) Calculate_Coors();

    c = ((int) activation) * 255 / 100;
    if (c < 0) c = 0;
    if (c > 255) c = 255;
    cl = new Color(c, c, c);

    if (oldclamp != clamp) {
      g.setColor(Color.white);
      g.fillRect(sx1, sy1, 1 + sx2 - sx1, 1 + sy2 - sy1);
    }

    g.setColor(cl);
    g.fillOval(sx1, sy1, sx2 - sx1, sy2 - sy1);
    g.setColor(Color.black);
    if (activation == (double) 100.0) g.setColor(Color.red);
    g.drawOval(sx1, sy1, sx2 - sx1, sy2 - sy1);

    if (clamp) {
      xdiff = (sx2 - sx1);
      ydiff = (sy2 - sy1);
      g.drawRect(sx1, sy1, xdiff, ydiff);
    }

    if ((Resize) || (ResizeAll)) CalculateSize(g);
    g.setFont(currfont);
    if (activation > 50.0) g.setColor(Color.black);
    else g.setColor(Color.white);
    if (foreground != null) g.setColor(foreground);
    g.drawString(short_name, sx1 + xoff, sy2 - yoff);
    Redraw = false;
    Resize = false;
    if (oldclamp != clamp) {
      // draw all bonds - as they will have been erased
      oldclamp = clamp;
      for (int x = 0; x < outgoing_links.size(); x++) {
        slipnet_link s = (slipnet_link) outgoing_links.elementAt(x);
        s.Draw();
      }
    }
  }
示例#20
0
 static void paintDropShadowText(
     final Graphics g,
     final JComponent c,
     final Font font,
     final FontMetrics metrics,
     final int x,
     final int y,
     final int offsetX,
     final int offsetY,
     final Color textColor,
     final Color shadowColor,
     final String text) {
   g.setFont(font);
   g.setColor(shadowColor);
   SwingUtilities2.drawString(c, g, text, x + offsetX, y + offsetY + metrics.getAscent());
   g.setColor(textColor);
   SwingUtilities2.drawString(c, g, text, x, y + metrics.getAscent());
 }
示例#21
0
  // ------------------------------------------------------------------------------------------------------------------------------------
  // In game menus
  public void pauseMenu(Graphics g) {
    // Pause menu
    if (pause == true && lvlClear == false) {
      g.setFont(scoreFont);
      g.setColor(Color.BLACK);
      g.drawImage(new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this);
      g.drawString("P A U S E D", 155, 200);
      displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats
      g.drawImage(
          resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws the resume button
      g.drawImage(
          menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button

      if (musicOn == true) { // Draws the mute or unmute button (based on if music is on or not)
        g.drawImage(muteB.getPic(mx, my), muteB.getX(), muteB.getY(), this);
      }
      if (musicOn == false) {
        g.drawImage(unmuteB.getPic(mx, my), unmuteB.getX(), unmuteB.getY(), this);
      }
    }
  }
示例#22
0
  public static void drawValueBar(
      int x, int y, String labelhead, double value, double percentage, int colorindex, Graphics g) {
    g.setColor(GetColor(colorindex));
    g.drawRect(x, y, VALUE_BAR_WIDTH, VALUE_BAR_HEIGHT);

    int barwidth;
    if (percentage < 0.0) {
      // Unknown value
      barwidth = VALUE_BAR_WIDTH - 1;
    } else {
      barwidth = (int) ((VALUE_BAR_WIDTH - 1) * Math.min(1.0, percentage));
    }
    // g.setColor(gradientColor(percentage));
    g.fillRect(x + 1, y + 1, barwidth, VALUE_BAR_HEIGHT - 1);

    if (labelhead != null) {
      g.setFont(MainFrame.defaultFont);
      // g.setColor(MainFrame.labelColor);
      int off = 2;
      g.drawString(labelhead, x + VALUE_BAR_WIDTH + 2, y + VALUE_BAR_HEIGHT);
      // off += (labelhead.length()+1) * 4; // Just a guess
      String maxStr = new String("DateRate [/sec]:");
      off += (int) ((maxStr.length() + 1) * 5.5);

      if (value < 0.0) {
        g.drawString("?", x + VALUE_BAR_WIDTH + off, y + VALUE_BAR_HEIGHT);
      } else {
        if (percentage < 0.0) {
          g.drawString(format(value), x + VALUE_BAR_WIDTH + off, y + VALUE_BAR_HEIGHT);
        } else {
          g.drawString(
              format(value) + " (" + format(percentage * 100) + "%)",
              x + VALUE_BAR_WIDTH + off,
              y + VALUE_BAR_HEIGHT);
        }
      }
    }
  }
示例#23
0
  void drawEngineAt(Graphics g, int x, int y, Integer walk, Integer run, Integer current) {

    // Move this to a buffered Image

    final int engineWidth = 128;
    final int engineHeight = 16;

    int walkLocation = walk * engineWidth / run;
    int currentLocation = current * engineWidth / run;

    if (current <= walk) {
      g.setColor(java.awt.Color.GREEN);
    } else {
      g.setColor(java.awt.Color.ORANGE);
    }

    g.fillRect(x, y - 12, currentLocation, 8);

    g.setColor(java.awt.Color.BLACK);

    for (int i = 0; i <= run; i++) {
      int l = i * engineWidth / run;
      g.drawLine(x + l, y, x + l, y - engineHeight / 2);
    }

    g.drawLine(x, y, x, y - engineHeight);
    g.drawLine(x, y, x + engineWidth, y);
    g.drawLine(x + engineWidth, y, x + engineWidth, y - engineHeight);
    g.drawLine(x + walkLocation, y, x + walkLocation, y - engineHeight);

    g.drawString(run.toString(), x + engineWidth - 4, y - engineHeight - 2);
    g.drawString(walk.toString(), x + walkLocation - 4, y - engineHeight - 2);

    g.setFont(new Font("Eurostile", 0, 12));
    g.drawString("Speed", x, y - engineHeight - 2);
  }
示例#24
0
  public void paint(Graphics g) {
    // clears the area that the pannel is on
    gBuffer.setColor(Color.white);
    gBuffer.fillRect(0, 0, 65, 415);

    // pannel
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(5, 15, 60, 400);

    // color buttons
    gBuffer.setColor(Color.black); // first column
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.setColor(Color.red);
    gBuffer.fillRect(15, 40, 20, 20);
    gBuffer.setColor(Color.blue);
    gBuffer.fillRect(15, 60, 20, 20);
    gBuffer.setColor(Color.green);
    gBuffer.fillRect(15, 80, 20, 20);
    gBuffer.setColor(Color.yellow);
    gBuffer.fillRect(15, 100, 20, 20);
    gBuffer.setColor(Color.gray); // second column
    gBuffer.fillRect(35, 20, 20, 20);
    gBuffer.setColor(Color.magenta);
    gBuffer.fillRect(35, 40, 20, 20);
    gBuffer.setColor(Color.cyan);
    gBuffer.fillRect(35, 60, 20, 20);
    gBuffer.setColor(Color.orange);
    gBuffer.fillRect(35, 80, 20, 20);
    gBuffer.setColor(Color.pink);
    gBuffer.fillRect(35, 100, 20, 20);
    gBuffer.setColor(Color.black); // draw first column button outlines
    gBuffer.drawRect(15, 20, 20, 20);
    gBuffer.drawRect(15, 40, 20, 20);
    gBuffer.drawRect(15, 60, 20, 20);
    gBuffer.drawRect(15, 80, 20, 20);
    gBuffer.drawRect(15, 100, 20, 20);
    gBuffer.fillRect(15, 20, 20, 20);
    gBuffer.drawRect(35, 20, 20, 20); // draw second column button outlines
    gBuffer.drawRect(35, 40, 20, 20);
    gBuffer.drawRect(35, 60, 20, 20);
    gBuffer.drawRect(35, 80, 20, 20);
    gBuffer.drawRect(35, 100, 20, 20);

    // pen button design
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(23, 125, 3, 20);
    penta = new Polygon();
    penta.addPoint(23, 145);
    penta.addPoint(26, 145);
    penta.addPoint(25, 148);
    gBuffer.drawPolygon(penta);

    // brush button design
    gBuffer.setColor(Color.gray);
    gBuffer.fillRect(45, 128, 3, 10);
    penta = new Polygon();
    penta.addPoint(45, 138);
    penta.addPoint(48, 138);
    penta.addPoint(51, 141);
    penta.addPoint(42, 141);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawRect(42, 141, 9, 5);
    gBuffer.drawLine(45, 146, 45, 144);
    gBuffer.drawLine(48, 146, 48, 143);

    // roller button design
    gBuffer.setColor(Color.black); // handle
    gBuffer.fillRect(23, 155, 3, 10);
    gBuffer.drawRect(19, 165, 9, 4);
    gBuffer.setColor(Color.white); // roller front
    gBuffer.fillOval(27, 166, 4, 4);
    gBuffer.setColor(Color.black); // roller round side
    gBuffer.drawOval(27, 166, 3, 3);

    // spray paint button design
    gBuffer.setColor(Color.black); // top of can
    penta = new Polygon();
    penta.addPoint(43, 156);
    penta.addPoint(48, 160);
    penta.addPoint(43, 163);
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.blue); // spray button
    gBuffer.fillRect(42, 155, 2, 3);
    for (int n = 0; n <= 20; n++) // paint spray
    {
      x = 39 + ((int) (3 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
      y = 157 + ((int) (3 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
      gBuffer.fillRect(x, y, 1, 1);
    }
    penta = new Polygon(); // can
    penta.addPoint(43, 163);
    penta.addPoint(48, 160);
    penta.addPoint(53, 172);
    penta.addPoint(48, 177);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black);
    gBuffer.drawPolygon(penta);

    // rubber band drawing button design (20,185,30,205);
    gBuffer.setColor(Color.black);
    for (int a = 18, b = 200; a <= 35; a += 4, b += 2) {
      gBuffer.drawLine(18, 183, a, b);
    }

    // eraser button design
    gBuffer.setColor(Color.yellow); // top
    penta = new Polygon();
    penta.addPoint(45, 185);
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(40, 200);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    gBuffer.setColor(Color.yellow); // side
    penta = new Polygon();
    penta.addPoint(50, 185);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(52, 189);
    gBuffer.fillPolygon(penta);
    gBuffer.setColor(Color.black); // outline
    gBuffer.drawPolygon(penta);
    penta = new Polygon(); // front
    penta.addPoint(40, 200);
    penta.addPoint(45, 200);
    penta.addPoint(48, 204);
    penta.addPoint(43, 204);
    gBuffer.drawPolygon(penta);

    // clear button design
    gBuffer.setColor(Color.black);
    gBuffer.setFont(new Font("Arial", Font.BOLD, 20));
    gBuffer.drawString("Clear", 10, 239);
    gBuffer.drawRect(10, 220, 50, 25);

    gBuffer.setColor(Color.cyan);
    switch (numSize) {
      case 1:
        gBuffer.drawRect(15, 120, 20, 30);
        break;
      case 2:
        gBuffer.drawRect(35, 120, 20, 30);
        break;
      case 3:
        gBuffer.drawRect(15, 150, 20, 30);
        break;
      case 4:
        gBuffer.drawRect(35, 150, 20, 30);
        break;
      case 5:
        gBuffer.drawRect(15, 180, 20, 30);
        break;
      case 6:
        gBuffer.drawRect(35, 180, 20, 30);
        break;
    }

    if ((numSize == 4) || (numSize == 6)) {
      // draw different size buttons for spray paint, eraser, and rubber band
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
      gBuffer.setColor(Color.cyan);
      switch (size) {
        case 1:
          gBuffer.drawRect(26, 271, 18, 18);
          break;
        case 2:
          gBuffer.drawRect(26, 291, 18, 18);
          break;
        case 3:
          gBuffer.drawRect(26, 311, 18, 18);
      }
      gBuffer.setColor(Color.black);
      gBuffer.drawRect(20, 265, 30, 70); // size pannel
      gBuffer.drawRect(25, 270, 20, 20); // small
      gBuffer.drawRect(25, 290, 20, 20); // medium
      gBuffer.drawRect(25, 310, 20, 20); // large

      if (numSize == 4) {
        for (int n = 0; n <= 20; n++) {
          x = 35 + ((int) (4 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 280 + ((int) (4 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 40; n++) {
          x = 34 + ((int) (6 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 300 + ((int) (6 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        for (int n = 0; n <= 70; n++) {
          x = 35 + ((int) (8 * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
          y = 319 + ((int) (8 * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
          gBuffer.fillRect(x, y, 1, 1);
        }
        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 6;
            break;
          case 3:
            s = 8;
        }
      } else if (numSize == 6) {
        gBuffer.drawRect(33, 278, 4, 4);
        gBuffer.drawRect(32, 297, 7, 7);
        gBuffer.drawRect(30, 315, 10, 10);

        switch (size) {
          case 1:
            s = 4;
            break;
          case 2:
            s = 7;
            break;
          case 3:
            s = 10;
        }
      }
    } else {
      gBuffer.setColor(Color.white);
      gBuffer.fillRect(20, 265, 35, 75);
    }

    // draw pannel and buttons
    g.drawImage(virtualMem, 0, 0, this);

    // changing what color it draws with
    switch (numColor) {
      case 1:
        gBuffer.setColor(Color.black);
        break;
      case 2:
        gBuffer.setColor(Color.red);
        break;
      case 3:
        gBuffer.setColor(Color.blue);
        break;
      case 4:
        gBuffer.setColor(Color.green);
        break;
      case 5:
        gBuffer.setColor(Color.yellow);
        break;
      case 6:
        gBuffer.setColor(Color.gray);
        break;
      case 7:
        gBuffer.setColor(Color.magenta);
        break;
      case 8:
        gBuffer.setColor(Color.cyan);
        break;
      case 9:
        gBuffer.setColor(Color.orange);
        break;
      case 10:
        gBuffer.setColor(Color.pink);
        break;
      case 11:
        gBuffer.setColor(Color.white);
        break;
      default:
        gBuffer.setColor(Color.black);
    }

    // changing how it draws
    switch (numDraw) {
      case 1: // clear drawing
        gBuffer.setColor(Color.white);
        gBuffer.fillRect(0, 0, appletWidth, appletHeight);
        g.drawImage(virtualMem, 0, 0, this);
        numDraw = 0;
        repaint();
        break;
      default:
        switch (numSize) {
          case 1: // draw with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 2: // draw with brush
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 4, 4);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 3: // draw with roller
            if (!first) {
              gBuffer.fillRect(oldX, oldY, 10, 10);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 4: // draw with spray paint
            if (!first) {
              for (int n = 0; n <= 20; n++) {
                x = oldX + ((int) (s * Math.cos((rnd.nextDouble() * 2 * Math.PI))));
                y = oldY + ((int) (s * Math.sin((rnd.nextDouble() * 2 * Math.PI))));
                gBuffer.fillRect(x, y, 1, 1);
                g.drawImage(virtualMem, 0, 0, this);
              }
            } else first = false;

            break;
          case 5: // draw with rubber band style
            if (!first) {
              gBuffer.drawLine(startX, startY, endX, endY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          case 6: // eraser drawer
            if (!first) {
              gBuffer.fillRect(oldX, oldY, s, s);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
            break;
          default: // default to drawing with pen
            if (!first) {
              gBuffer.drawLine(oldX, oldY, newX, newY);
              g.drawImage(virtualMem, 0, 0, this);
            } else first = false;
        }
    }
  }
  /**
   * PAINT recall that paint() is called the first time the window needs to be drawn, or if
   * something damages the window, and in this case by RefreshScreenNow()
   */
  public void paint(Graphics g) {
    super.paint(g); // first paint the panel normally

    // the following block of code is used
    // if this is the first time being drawn or if the window was resized
    // Otherwise we don't creat a new buffer
    Dimension d = getSize();

    // if this is the first time being drawn or if the window was resized
    if ((doubleBufferImage == null)
        || (d.width != doubleBufferImageSize.width)
        || (d.height != doubleBufferImageSize.height)) {
      doubleBufferImage = createImage(d.width, d.height);
      doubleBufferImageSize = d;
      if (doubleBufferGraphic != null) {
        doubleBufferGraphic.dispose();
      }
      doubleBufferGraphic = doubleBufferImage.getGraphics();
      doubleBufferGraphic.setFont(getFont());
    }

    doubleBufferGraphic.setColor(Color.white);
    doubleBufferGraphic.fillRect(0, 0, d.width, d.height);

    if ((fitToScreenAutomatically) || (screenIsEmpty)) {
      // if the user wants all the nodes on the screen,
      // or if these are the first nodes on the screen,
      // fit all nodes to the visible area
      FitToScreen();
    }

    // draw things on the screen before any nodes or edges appear
    MainClass.displayManager.PaintUnderScreen(doubleBufferGraphic);

    // draw all the nodes
    DisplayManager.NodeInfo nodeDisplayInfo;
    int xCoord, yCoord, imageWidth, imageHeight;
    for (Enumeration nodes = MainClass.displayManager.GetNodeInfo(); nodes.hasMoreElements(); ) {
      nodeDisplayInfo = (DisplayManager.NodeInfo) nodes.nextElement();

      // figure out where to put the node on the screen
      xCoord =
          ScaleNodeXCoordToScreenCoord(
              MainClass.locationAnalyzer.GetX(nodeDisplayInfo.GetNodeNumber()));
      yCoord =
          ScaleNodeYCoordToScreenCoord(
              MainClass.locationAnalyzer.GetY(nodeDisplayInfo.GetNodeNumber()));

      // if that spot is not on the visible area, don't draw it at all
      if ((xCoord > this.getSize().getWidth()) || (yCoord > this.getSize().getHeight())) {
        continue;
      }

      // MDW: Don't scale size of dots
      // imageWidth = (int)Math.max(20,xScale*nodeDisplayInfo.GetImageWidth()/100);
      // imageHeight = (int)Math.max(20,yScale*nodeDisplayInfo.GetImageHeight()/100);
      imageWidth = imageHeight = 20;

      MainClass.displayManager.PaintAllNodes(
          nodeDisplayInfo.GetNodeNumber(),
          xCoord - imageWidth / 2,
          yCoord - imageHeight / 2,
          xCoord + imageWidth / 2,
          yCoord + imageHeight / 2,
          doubleBufferGraphic);
    }

    // draw all the edges
    try {
      DisplayManager.EdgeInfo edgeDisplayInfo;
      for (Enumeration edges = MainClass.displayManager.GetEdgeInfo(); edges.hasMoreElements(); ) {
        edgeDisplayInfo = (DisplayManager.EdgeInfo) edges.nextElement();

        // figure out the coordinates of the endpoints of the edge
        int x1 =
            ScaleNodeXCoordToScreenCoord(
                MainClass.locationAnalyzer.GetX(edgeDisplayInfo.GetSourceNodeNumber()));
        int y1 =
            ScaleNodeYCoordToScreenCoord(
                MainClass.locationAnalyzer.GetY(edgeDisplayInfo.GetSourceNodeNumber()));
        int x2 =
            ScaleNodeXCoordToScreenCoord(
                MainClass.locationAnalyzer.GetX(edgeDisplayInfo.GetDestinationNodeNumber()));
        int y2 =
            ScaleNodeYCoordToScreenCoord(
                MainClass.locationAnalyzer.GetY(edgeDisplayInfo.GetDestinationNodeNumber()));

        // edgeDisplayInfo.paint(doubleBufferGraphic);
        MainClass.displayManager.PaintAllEdges(
            edgeDisplayInfo.GetSourceNodeNumber(),
            edgeDisplayInfo.GetDestinationNodeNumber(),
            x1,
            y1,
            x2,
            y2,
            doubleBufferGraphic);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    // draw things over the entire display
    MainClass.displayManager.PaintOverScreen(doubleBufferGraphic);

    // Make everything that was drawn visible
    g.drawImage(doubleBufferImage, 0, 0, null);
  }
示例#26
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;
    }
  }
示例#27
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    RenderingHints rh = g2d.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);

    // Background.
    D = this.getSize();
    g.setColor(backgroundColor);
    g.fillRect(0, 0, D.width, D.height);
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(lineStroke);

    // Axes, bounding box.
    g.setColor(Color.gray);
    g.drawLine(inset, D.height - inset, D.width - inset, D.height - inset);
    g.drawLine(D.width - inset, inset, D.width - inset, D.height - inset);
    g.drawLine(inset, inset, inset, D.height - inset);
    g.drawLine(inset, inset, D.width - inset, inset);

    double xDelta = (maxX - minX) / numIntervals;

    // X-ticks and labels.
    for (int i = 1; i <= numIntervals; i++) {
      double xTickd = i * xDelta;
      int xTick = (int) (xTickd / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + xTick, D.height - inset - 5, inset + xTick, D.height - inset + 5);
      double x = minX + i * xDelta;
      g.drawString(df.format(x), xTick + inset - 5, D.height - inset + 20);
    }

    // Y-ticks
    double yDelta = (maxY - minY) / numIntervals;
    for (int i = 0; i < numIntervals; i++) {
      int yTick = (i + 1) * (int) ((D.height - 2 * inset) / (double) numIntervals);
      g.drawLine(inset - 5, D.height - yTick - inset, inset + 5, D.height - yTick - inset);
      double y = minY + (i + 1) * yDelta;
      g.drawString(df.format(y), 1, D.height - yTick - inset);
    }

    // Zoom+move
    Font savedFont = g.getFont();
    g.setFont(plusFont);
    g.drawString("+", D.width - 25, 20);
    g.setFont(minusFont);
    g.drawString("-", D.width - 25, 50);
    drawArrow(g2d, D.width - 70, 20, D.width - 70, 0, 1.0f, lineStroke); // Up
    drawArrow(g2d, D.width - 70, 30, D.width - 70, 50, 1.0f, lineStroke); // Down
    drawArrow(g2d, D.width - 65, 25, D.width - 45, 25, 1.0f, lineStroke); // Right
    drawArrow(g2d, D.width - 75, 25, D.width - 95, 25, 1.0f, lineStroke); // Left
    g.setFont(savedFont);

    // See if standard axes are in the middle.
    g.setColor(Color.gray);
    if ((minX < 0) && (maxX > 0) && (drawMiddleAxes)) {
      // Draw y-axis
      int x = (int) ((0 - minX) / (maxX - minX) * (D.width - 2 * inset));
      g.drawLine(inset + x, D.height - inset, inset + x, inset);
    }
    if ((minY < 0) && (maxY > 0) && (drawMiddleAxes)) {
      // Draw x-axis
      int y = (int) ((0 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
      g.drawLine(inset, D.height - y - inset, D.width - inset, D.height - y - inset);
    }

    // Draw the objects.
    drawObjects(g, points, lines, ovals, rectangles, images, labels, eqnLines);
    if (animationMode) {
      drawObjects(g, animPoints, animLines, animOvals, animRectangles, null, labels, eqnLines);
      // No images in animation mode.
    }

    drawScribbles(g);
  }
    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));
    }
示例#29
0
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      response.setContentType("image/jpeg");
      pageContext =
          _jspxFactory.getPageContext(
              this, request, response, "/myhtml/errorpage/erroe.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write('\r');
      out.write('\n');

      // 设置页面不缓存
      response.setHeader("Pragma", "No-cache");
      response.setHeader("Cache-Control", "no-cache");
      response.setDateHeader("Expires", 0);

      //   在内存中创建图象
      int width = 60, height = 20;
      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

      //   获取图形上下文
      Graphics g = image.getGraphics();

      // 生成随机类
      Random random = new Random();

      //   设定背景色
      g.setColor(getRandColor(200, 250));
      g.fillRect(0, 0, width, height);

      // 设定字体
      g.setFont(new Font("Times   New   Roman", Font.PLAIN, 18));

      // 画边框
      // g.setColor(new   Color());
      // g.drawRect(0,0,width-1,height-1);

      //   随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
      g.setColor(getRandColor(160, 200));
      for (int i = 0; i < 155; i++) {
        int x = random.nextInt(width);
        int y = random.nextInt(height);
        int xl = random.nextInt(12);
        int yl = random.nextInt(12);
        g.drawLine(x, y, x + xl, y + yl);
      }

      //   取随机产生的认证码(4位数字)
      String sRand = "";
      for (int i = 0; i < 4; i++) {
        String rand = String.valueOf(random.nextInt(10));
        sRand += rand;
        //   将认证码显示到图象中
        g.setColor(
            new Color(
                20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
        // 调用函数出来的颜色相同,可能是å›
        // ä¸ºç§å­å¤ªæŽ¥è¿‘,所以只能直接生成
        g.drawString(rand, 13 * i + 6, 16);
      }

      //   将认证码存入SESSION
      session.setAttribute("rand", sRand);

      //   图象生效
      g.dispose();

      //   输出图象到页面
      ImageIO.write(image, "JPEG", response.getOutputStream());
      out.clear();
      out = pageContext.pushBody();

    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            out.clearBuffer();
          } catch (java.io.IOException e) {
          }
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
  public void drawItem(Graphics g, int offset, boolean selected, boolean drawsec) {
    // g.setColor(0);
    boolean ralign = false;
    boolean underline = false;

    // #if NICK_COLORS
    // # 	boolean nick=false;
    // #endif

    int w = offset;
    int dw;
    int imageYOfs = ((getVHeight() - imgHeight()) >> 1);
    // #if ALCATEL_FONT
    // #         int fontYOfs=(( getVHeight()-font.getHeight() )>>1) +1;
    // #else
    int fontYOfs = ((getVHeight() - font.getHeight()) >> 1);
    // #endif
    int imgWidth = imgWidth();

    g.setFont(font);
    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          String s = (String) ob;
          // #if NICK_COLORS
          // #                     if (nick) {
          // #                         int color=g.getColor();
          // #                         dw=0;
          // #                         int p1=0;
          // #                         while (p1<s.length()) {
          // #                             int p2=p1;
          // #                             char c1=s.charAt(p1);
          // #                             //processing the same cp
          // #                             while (p2<s.length()) {
          // #                                 char c2=s.charAt(p2);
          // #                                 if ( (c1&0xff00) != (c2 &0xff00) ) break;
          // #                                 p2++;
          // #                             }
          // #                             g.setColor( (c1>255) ? ColorScheme.strong(color) :
          // color);
          // #                             dw=font.substringWidth(s, p1, p2-p1);
          // #                             if (ralign) w-=dw;
          // #                             g.drawSubstring( s, p1, p2-p1,
          // #                                     w,fontYOfs,Graphics.LEFT|Graphics.TOP);
          // #                             if (!ralign) w+=dw;
          // #                             p1=p2;
          // #                         }
          // #
          // #                         g.setColor(color);
          // #                     } else {
          // #endif
          dw = font.stringWidth(s);
          if (ralign) w -= dw;
          g.drawString(s, w, fontYOfs, Graphics.LEFT | Graphics.TOP);
          if (underline) {
            int y = getVHeight() - 1;
            g.drawLine(w, y, w + dw, y);
            underline = false;
          }
          if (!ralign) w += dw;
          // #if NICK_COLORS
          // #                     }
          // #endif

        } else if ((ob instanceof Integer)) {
          // image element or color
          int i = ((Integer) ob).intValue();
          switch (i & 0xff000000) {
            case IMAGE:
              if (imageList == null) break;
              if (ralign) w -= imgWidth;
              imageList.drawImage(g, ((Integer) ob).intValue(), w, imageYOfs);
              if (!ralign) w += imgWidth;
              break;
            case COLOR:
              g.setColor(0xFFFFFF & i);
              break;
            case RALIGN:
              ralign = true;
              w = g.getClipWidth() - 1;
              break;
            case UNDERLINE:
              underline = true;
              break;
              // #if NICK_COLORS
              // #                         case NICK_ON:
              // #                             nick=true;
              // #                             break;
              // #                         case NICK_OFF:
              // #                             nick=false;
              // #                             break;
              // #endif
          }
        } /* Integer*/ else if (ob instanceof VirtualElement) {
          int clipw = g.getClipWidth();
          int cliph = g.getClipHeight();
          ((VirtualElement) ob).drawItem(g, 0, false, false);
          g.setClip(g.getTranslateX(), g.getTranslateY(), clipw, cliph);
          // TODO: рисование не с нулевой позиции и вычисление ширины
        }
      } // if ob!=null
    } // for
  }