public void paintIcon(Component c, Graphics g, int x, int y) {
      boolean enabled = c.isEnabled();

      // paint the icon
      Icon paintedIcon = enabled ? icon : disabledIcon;
      if (paintedIcon != null) paintedIcon.paintIcon(c, g, x, y);

      // backup current color
      Color oldColor = g.getColor();
      int insetx = 4;
      if (c instanceof JComponent) {
        Insets borderinset = ((JComponent) c).getBorder().getBorderInsets(c);
        insetx = borderinset.left;
      }
      if (paintedIcon != null) {
        g.translate(paintedIcon.getIconWidth() + X_GAP + insetx, 0);
      }

      arrow.paintIcon(c, g, x, y);
      if (paintedIcon != null) {
        g.translate(-paintedIcon.getIconWidth() - X_GAP - insetx, 0);
      }

      // restore previous color
      g.setColor(oldColor);
    }
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   if (comp.hasFocus() || focusLostTemporarily) {
     Color color = g.getColor();
     g.setColor(focusColor);
     BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
     g.setColor(color);
   }
 }
    public void paintIcon(Component c, Graphics g, int x, int y) {
      Color oldColor = g.getColor();
      boolean enabled = c.isEnabled();
      boolean pressed = false;
      if (c instanceof JButton) {
        pressed = ((JButton) c).getModel().isPressed();
      }

      int i = 0;
      int j = 0;
      int w = Math.min(width, c.getWidth());
      int h = c.getHeight();
      if (h < 5 || w < 5) { // not enough space for the arrow
        g.setColor(oldColor);
        return;
      }

      int size = Math.min(h / 2, w / 2);
      size = Math.max(size, 2);
      int mid = size / 2;

      x = ((w - size) / 2); // center arrow
      y = (h - size) / 2; // center arrow
      if (pressed) {
        x++;
        y++;
      }
      g.translate(x, y); // move the x,y origin in the graphic

      if (enabled) g.setColor(UIManager.getColor("controlDkShadow")); // NOT
      // LOCALIZABLE
      else g.setColor(UIManager.getColor("controlShadow")); // NOT
      // LOCALIZABLE

      if (!enabled) {
        g.translate(1, 1);
        g.setColor(UIManager.getColor("controlLtHighlight")); // NOT
        // LOCALIZABLE
        for (i = size - 1; i >= 0; i--) {
          g.drawLine(mid - i, j, mid + i, j);
          j++;
        }
        g.translate(-1, -1);
        g.setColor(UIManager.getColor("controlShadow")); // NOT
        // LOCALIZABLE
      }

      j = 0;
      for (i = size - 1; i >= 0; i--) {
        g.drawLine(mid - i, j, mid + i, j);
        j++;
      }

      g.translate(-x, -y);
      g.setColor(oldColor);
    }
Example #4
0
  public void draw(Graphics g) {
    getDirection();
    move();

    Color c = g.getColor();
    g.setColor(TANK_COLOR);
    g.fillOval(xpos, ypos, TANK_RADIUS, TANK_RADIUS);
    drawPT(g);
    g.setColor(c);
  }
Example #5
0
  public void draw(Graphics g) {
    getDirection();
    move();

    Color c = g.getColor();
    Color tankColor = (isMe) ? MY_TANK_COLOR : ENENMY_TANK_COLOR;
    g.setColor(tankColor);
    g.fillOval(xpos, ypos, TANK_RADIUS, TANK_RADIUS);
    drawPT(g);
    g.setColor(c);
  }
Example #6
0
  public void update(Graphics g) {

    if (offScreenImage == null) offScreenImage = this.createImage(GAME_WIDTH, GAME_HEIGHT);
    Graphics gOffScreenImage = offScreenImage.getGraphics();

    Color c = gOffScreenImage.getColor();
    gOffScreenImage.setColor(BACKGROUND_COLOR);
    gOffScreenImage.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
    gOffScreenImage.setColor(c);

    paint(gOffScreenImage);
    g.drawImage(offScreenImage, 0, 0, null);
  }
  private void drawBalance(Graphics g)
        //  POST: Draws the balance of the current player
      {

    Font font; // Font used to draw balance
    String message; // Message for balance
    Color oldColor; // Sets for color
    int x1; // Upper-left x coordinate
    int y1; // Upper-left y coordinate
    int x2; // Bottom-right x coordinate
    int y2; // Bottom-right y coordinate
    int width; // Width of the dialogue box
    int height; // Height of the dialogue box
    int offset; // Offset so the dialogue box is positioned
    int balance; // Offset so the dialogue box is positioned
    User player; // User value for the player

    player = usersArray[0];

    balance = player.getBalance();
    oldColor = g.getColor();

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.81);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.86);
    width = x2 - x1;
    height = y2 - y1;
    message = "Balance:";
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.setColor(Color.WHITE);
    g.drawString(message, x1 + offset, y2);

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.865);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.915);

    width = x2 - x1;
    height = y2 - y1;
    message = "$" + Integer.toString(balance);
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.drawString(message, x1 + offset, y2);

    g.setColor(oldColor);
  }
Example #8
0
  public void draw(Graphics g) {
    if (!live) {
      // System.out.println("子弹死了");
      // t.missiles.remove(this);
      return;
    }
    Color c = g.getColor(); // 拿到前景色
    if (good) {
      g.setColor(Color.RED);
    } else {
      g.setColor(Color.YELLOW);
    }
    g.fillOval(x, y, WIDTH, HEIGHT); // 画一个实心圆并用当前颜色填充
    g.setColor(c);

    move();
  }
Example #9
0
 public void drawBomb(Graphics g, int x, int y) {
   Color c = g.getColor();
   g.setColor(new Color(128, 128, 128));
   g.drawLine(x + 2, y + 7, x + 12, y + 7);
   g.drawLine(x + 7, y + 2, x + 7, y + 12);
   g.fillRect(x + 6, y + 4, 3, 7);
   g.fillRect(x + 4, y + 6, 7, 3);
   g.setColor(Color.black);
   g.fillRect(x + 5, y + 5, 5, 5);
   g.drawLine(x + 3, y + 7, x + 11, y + 7);
   g.drawLine(x + 7, y + 3, x + 7, y + 11);
   g.drawLine(x + 4, y + 4, x + 4, y + 4);
   g.drawLine(x + 4, y + 10, x + 4, y + 10);
   g.drawLine(x + 10, y + 4, x + 10, y + 4);
   g.drawLine(x + 10, y + 10, x + 10, y + 10);
   g.setColor(Color.white);
   g.drawLine(x + 6, y + 6, x + 6, y + 6);
   g.setColor(c);
 }
Example #10
0
 private void drawPT(Graphics g) {
   Color c = g.getColor();
   g.setColor(PT_COLOR);
   switch (ptDir) {
     case U:
       g.drawLine(xpos + TANK_RADIUS / 2, ypos + TANK_RADIUS / 2, xpos + TANK_RADIUS / 2, ypos);
       break;
     case D:
       g.drawLine(
           xpos + TANK_RADIUS / 2,
           ypos + TANK_RADIUS / 2,
           xpos + TANK_RADIUS / 2,
           ypos + TANK_RADIUS);
       break;
     case L:
       g.drawLine(xpos + TANK_RADIUS / 2, ypos + TANK_RADIUS / 2, xpos, ypos + TANK_RADIUS / 2);
       break;
     case R:
       g.drawLine(
           xpos + TANK_RADIUS / 2,
           ypos + TANK_RADIUS / 2,
           xpos + TANK_RADIUS,
           ypos + TANK_RADIUS / 2);
       break;
     case UL:
       g.drawLine(xpos + TANK_RADIUS / 2, ypos + TANK_RADIUS / 2, xpos, ypos);
       break;
     case UR:
       g.drawLine(xpos + TANK_RADIUS / 2, ypos + TANK_RADIUS / 2, xpos + TANK_RADIUS, ypos);
       break;
     case DL:
       g.drawLine(xpos + TANK_RADIUS / 2, ypos + TANK_RADIUS / 2, xpos, ypos + TANK_RADIUS);
       break;
     case DR:
       g.drawLine(
           xpos + TANK_RADIUS / 2, ypos + TANK_RADIUS / 2, xpos + TANK_RADIUS, ypos + TANK_RADIUS);
       break;
     default:
       break;
   }
   g.setColor(c);
 }
  public void drawScene(Graphics g) {
    boolean darker = false;

    int halfwidth = size().width / 2;
    int halfheight = size().height / 2;

    for (int i = 0; i < npoint; i++) {
      SequencePoint sp = (SequencePoint) points.elementAt(i);
      int x = (int) ((float) (sp.coord[0] - centre[0]) * scale) + halfwidth;
      int y = (int) ((float) (sp.coord[1] - centre[1]) * scale) + halfheight;
      float z = sp.coord[1] - centre[2];
      if (sp.sequence instanceof DrawableSequence) {
        if (((DrawableSequence) sp.sequence).color == Color.black) {
          g.setColor(Color.white);
        } else {
          g.setColor(((DrawableSequence) sp.sequence).color);
        }
      } else {
        g.setColor(Color.red);
      }
      if (av != null) {
        if (av.getSelection().contains(((SequencePoint) points.elementAt(i)).sequence)) {
          g.setColor(Color.gray);
        }
      }
      if (z < 0) {
        g.setColor(g.getColor().darker());
      }

      g.fillRect(x - 3, y - 3, 6, 6);
      g.setColor(Color.red);
    }
    //    //Now the rectangle
    //    if (rectx2 != -1 && recty2 != -1) {
    //      g.setColor(Color.white);
    //
    //      g.drawRect(rectx1,recty1,rectx2-rectx1,recty2-recty1);
    //    }
  }
Example #12
0
 public void drawBlock(Graphics g, int r, int c, int mode) {
   Color curr = g.getColor();
   g.setColor(Color.black);
   int inc = 2;
   int xpos = inc + (c * wt), ypos = inc + (r * ht);
   switch (mode) {
     case 1:
       { // drawn on a square with an unclicked
         // bomb
         drawBomb(g, xpos, ypos);
         break;
       }
     case 2:
       { // draws a cell with a number on it
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
         if (field[r][c] > 0) {
           g.setFont(new Font("Serif", Font.BOLD, 12));
           g.setColor(list[field[r][c] - 1]);
           g.drawString(field[r][c] + "", xpos + 5, ypos + 12);
         }
       }
       break;
     case 3:
       { // drawn on the square where the bomb was clicked
         g.setColor(Color.red);
         g.fillRect(xpos, ypos, wt, ht);
         g.setColor(Color.black);
         drawBomb(g, xpos, ypos);
       }
       break;
     case 4:
       { // draws a plain unrevealed cell
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
       }
       break;
     case 5:
       { // a Flag.
         g.setColor(Color.lightGray);
         g.fill3DRect(xpos, ypos, wt, ht, true);
         g.setColor(Color.red);
         g.fillRect(xpos + 4, ypos + 3, 4, 4);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 8, ypos + 3, xpos + 8, ypos + 6);
         g.drawLine(xpos + 8, ypos + 6, xpos + 5, ypos + 6);
         g.drawLine(xpos + 6, ypos + 5, xpos + 7, ypos + 5);
         g.drawLine(xpos + 7, ypos + 5, xpos + 7, ypos + 4);
         g.setColor(new Color(128, 128, 128));
         g.drawLine(xpos + 5, ypos + 12, xpos + 11, ypos + 12);
         g.drawLine(xpos + 7, ypos + 11, xpos + 9, ypos + 11);
         g.setColor(Color.black);
         g.drawLine(xpos + 8, ypos + 7, xpos + 8, ypos + 11);
         g.drawLine(xpos + 6, ypos + 12, xpos + 10, ypos + 12);
       }
       break;
     case 6:
       { // A red cross - flag over non mine block
         g.setColor(Color.red);
         g.drawLine(xpos + 3, ypos + 3, xpos + 11, ypos + 11);
         g.drawLine(xpos + 4, ypos + 3, xpos + 12, ypos + 11);
         g.drawLine(xpos + 12, ypos + 3, xpos + 4, ypos + 11);
         g.drawLine(xpos + 3, ypos + 11, xpos + 11, ypos + 3);
         g.setColor(Color.red.darker());
         g.drawLine(xpos + 3, ypos + 12, xpos + 4, ypos + 12);
         g.drawLine(xpos + 4, ypos + 12, xpos + 7, ypos + 9);
         g.drawLine(xpos + 8, ypos + 9, xpos + 11, ypos + 12);
         g.drawLine(xpos + 11, ypos + 12, xpos + 12, ypos + 12);
         g.drawLine(xpos + 3, ypos + 4, xpos + 6, ypos + 7);
         g.drawLine(xpos + 12, ypos + 4, xpos + 9, ypos + 7);
       }
       break;
     case 7:
       {
         g.setColor(Color.lightGray);
         g.fillRect(xpos, ypos, wt, ht);
       }
       break;
   }
   g.setColor(curr);
 }
Example #13
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Color oldColor = g.getColor();
   g.setColor(color);
   g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true);
   g.setColor(oldColor);
 }
Example #14
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    int width = getWidth() - rightMargin - leftMargin - 10;
    int height = getHeight() - topMargin - bottomMargin;
    if (width <= 0 || height <= 0) {
      // not enough room to paint anything
      return;
    }

    Color oldColor = g.getColor();
    Font oldFont = g.getFont();
    Color fg = getForeground();
    Color bg = getBackground();
    boolean bgIsLight = (bg.getRed() > 200 && bg.getGreen() > 200 && bg.getBlue() > 200);

    ((Graphics2D) g)
        .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    if (smallFont == null) {
      smallFont = oldFont.deriveFont(9.0F);
    }

    r.x = leftMargin - 5;
    r.y = topMargin - 8;
    r.width = getWidth() - leftMargin - rightMargin;
    r.height = getHeight() - topMargin - bottomMargin + 16;

    if (border == null) {
      // By setting colors here, we avoid recalculating them
      // over and over.
      border =
          new BevelBorder(
              BevelBorder.LOWERED,
              getBackground().brighter().brighter(),
              getBackground().brighter(),
              getBackground().darker().darker(),
              getBackground().darker());
    }

    border.paintBorder(this, g, r.x, r.y, r.width, r.height);

    // Fill background color
    g.setColor(bgColor);
    g.fillRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4);
    g.setColor(oldColor);

    long tMin = Long.MAX_VALUE;
    long tMax = Long.MIN_VALUE;
    long vMin = Long.MAX_VALUE;
    long vMax = 1;

    int w = getWidth() - rightMargin - leftMargin - 10;
    int h = getHeight() - topMargin - bottomMargin;

    if (times.size > 1) {
      tMin = Math.min(tMin, times.time(0));
      tMax = Math.max(tMax, times.time(times.size - 1));
    }
    long viewRangeMS;
    if (viewRange > 0) {
      viewRangeMS = viewRange * MINUTE;
    } else {
      // Display full time range, but no less than a minute
      viewRangeMS = Math.max(tMax - tMin, 1 * MINUTE);
    }

    // Calculate min/max values
    for (Sequence seq : seqs) {
      if (seq.size > 0) {
        for (int i = 0; i < seq.size; i++) {
          if (seq.size == 1 || times.time(i) >= tMax - viewRangeMS) {
            long val = seq.value(i);
            if (val > Long.MIN_VALUE) {
              vMax = Math.max(vMax, val);
              vMin = Math.min(vMin, val);
            }
          }
        }
      } else {
        vMin = 0L;
      }
      if (unit == Unit.BYTES || !seq.isPlotted) {
        // We'll scale only to the first (main) value set.
        // TODO: Use a separate property for this.
        break;
      }
    }

    // Normalize scale
    vMax = normalizeMax(vMax);
    if (vMin > 0) {
      if (vMax / vMin > 4) {
        vMin = 0;
      } else {
        vMin = normalizeMin(vMin);
      }
    }

    g.setColor(fg);

    // Axes
    // Draw vertical axis
    int x = leftMargin - 18;
    int y = topMargin;
    FontMetrics fm = g.getFontMetrics();

    g.drawLine(x, y, x, y + h);

    int n = 5;
    if (("" + vMax).startsWith("2")) {
      n = 4;
    } else if (("" + vMax).startsWith("3")) {
      n = 6;
    } else if (("" + vMax).startsWith("4")) {
      n = 4;
    } else if (("" + vMax).startsWith("6")) {
      n = 6;
    } else if (("" + vMax).startsWith("7")) {
      n = 7;
    } else if (("" + vMax).startsWith("8")) {
      n = 8;
    } else if (("" + vMax).startsWith("9")) {
      n = 3;
    }

    // Ticks
    ArrayList<Long> tickValues = new ArrayList<Long>();
    tickValues.add(vMin);
    for (int i = 0; i < n; i++) {
      long v = i * vMax / n;
      if (v > vMin) {
        tickValues.add(v);
      }
    }
    tickValues.add(vMax);
    n = tickValues.size();

    String[] tickStrings = new String[n];
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      tickStrings[i] = getSizeString(v, vMax);
    }

    // Trim trailing decimal zeroes.
    if (decimals > 0) {
      boolean trimLast = true;
      boolean removedDecimalPoint = false;
      do {
        for (String str : tickStrings) {
          if (!(str.endsWith("0") || str.endsWith("."))) {
            trimLast = false;
            break;
          }
        }
        if (trimLast) {
          if (tickStrings[0].endsWith(".")) {
            removedDecimalPoint = true;
          }
          for (int i = 0; i < n; i++) {
            String str = tickStrings[i];
            tickStrings[i] = str.substring(0, str.length() - 1);
          }
        }
      } while (trimLast && !removedDecimalPoint);
    }

    // Draw ticks
    int lastY = Integer.MAX_VALUE;
    for (int i = 0; i < n; i++) {
      long v = tickValues.get(i);
      y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
      g.drawLine(x - 2, y, x + 2, y);
      String s = tickStrings[i];
      if (unit == Unit.PERCENT) {
        s += "%";
      }
      int sx = x - 6 - fm.stringWidth(s);
      if (y < lastY - 13) {
        if (checkLeftMargin(sx)) {
          // Wait for next repaint
          return;
        }
        g.drawString(s, sx, y + 4);
      }
      // Draw horizontal grid line
      g.setColor(Color.lightGray);
      g.drawLine(r.x + 4, y, r.x + r.width - 4, y);
      g.setColor(fg);
      lastY = y;
    }

    // Draw horizontal axis
    x = leftMargin;
    y = topMargin + h + 15;
    g.drawLine(x, y, x + w, y);

    long t1 = tMax;
    if (t1 <= 0L) {
      // No data yet, so draw current time
      t1 = System.currentTimeMillis();
    }
    long tz = timeDF.getTimeZone().getOffset(t1);
    long tickInterval = calculateTickInterval(w, 40, viewRangeMS);
    if (tickInterval > 3 * HOUR) {
      tickInterval = calculateTickInterval(w, 80, viewRangeMS);
    }
    long t0 = tickInterval - (t1 - viewRangeMS + tz) % tickInterval;
    while (t0 < viewRangeMS) {
      x = leftMargin + (int) (w * t0 / viewRangeMS);
      g.drawLine(x, y - 2, x, y + 2);

      long t = t1 - viewRangeMS + t0;
      String str = formatClockTime(t);
      g.drawString(str, x, y + 16);
      // if (tickInterval > (1 * HOUR) && t % (1 * DAY) == 0) {
      if ((t + tz) % (1 * DAY) == 0) {
        str = formatDate(t);
        g.drawString(str, x, y + 27);
      }
      // Draw vertical grid line
      g.setColor(Color.lightGray);
      g.drawLine(x, topMargin, x, topMargin + h);
      g.setColor(fg);
      t0 += tickInterval;
    }

    // Plot values
    int start = 0;
    int nValues = 0;
    int nLists = seqs.size();
    if (nLists > 0) {
      nValues = seqs.get(0).size;
    }
    if (nValues == 0) {
      g.setColor(oldColor);
      return;
    } else {
      Sequence seq = seqs.get(0);
      // Find starting point
      for (int p = 0; p < seq.size; p++) {
        if (times.time(p) >= tMax - viewRangeMS) {
          start = p;
          break;
        }
      }
    }

    // Optimization: collapse plot of more than four values per pixel
    int pointsPerPixel = (nValues - start) / w;
    if (pointsPerPixel < 4) {
      pointsPerPixel = 1;
    }

    // Draw graphs
    // Loop backwards over sequences because the first needs to be painted on top
    for (int i = nLists - 1; i >= 0; i--) {
      int x0 = leftMargin;
      int y0 = topMargin + h + 1;

      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Paint twice, with white and with color
        for (int pass = 0; pass < 2; pass++) {
          g.setColor((pass == 0) ? Color.white : seq.color);
          int x1 = -1;
          long v1 = -1;
          for (int p = start; p < nValues; p += pointsPerPixel) {
            // Make sure we get the last value
            if (pointsPerPixel > 1 && p >= nValues - pointsPerPixel) {
              p = nValues - 1;
            }
            int x2 = (int) (w * (times.time(p) - (t1 - viewRangeMS)) / viewRangeMS);
            long v2 = seq.value(p);
            if (v2 >= vMin && v2 <= vMax) {
              int y2 = (int) (h * (v2 - vMin) / (vMax - vMin));
              if (x1 >= 0 && v1 >= vMin && v1 <= vMax) {
                int y1 = (int) (h * (v1 - vMin) / (vMax - vMin));

                if (y1 == y2) {
                  // fillrect is much faster
                  g.fillRect(x0 + x1, y0 - y1 - pass, x2 - x1, 1);
                } else {
                  Graphics2D g2d = (Graphics2D) g;
                  Stroke oldStroke = null;
                  if (seq.transitionStroke != null) {
                    oldStroke = g2d.getStroke();
                    g2d.setStroke(seq.transitionStroke);
                  }
                  g.drawLine(x0 + x1, y0 - y1 - pass, x0 + x2, y0 - y2 - pass);
                  if (oldStroke != null) {
                    g2d.setStroke(oldStroke);
                  }
                }
              }
            }
            x1 = x2;
            v1 = v2;
          }
        }

        // Current value
        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          // a small triangle/arrow
          g.fillPolygon(new int[] {x + 2, x + 6, x + 6}, new int[] {y, y + 3, y - 3}, 3);
        }
        g.setColor(fg);
      }
    }

    int[] valueStringSlots = new int[nLists];
    for (int i = 0; i < nLists; i++) valueStringSlots[i] = -1;
    for (int i = 0; i < nLists; i++) {
      Sequence seq = seqs.get(i);
      if (seq.isPlotted && seq.size > 0) {
        // Draw current value

        // TODO: collapse values if pointsPerPixel >= 4

        long v = seq.value(seq.size - 1);
        if (v >= vMin && v <= vMax) {
          x = r.x + r.width + 2;
          y = topMargin + h - (int) (h * (v - vMin) / (vMax - vMin));
          int y2 = getValueStringSlot(valueStringSlots, y, 2 * 10, i);
          g.setFont(smallFont);
          if (bgIsLight) {
            g.setColor(seq.color);
          } else {
            g.setColor(fg);
          }
          String curValue = getFormattedValue(v, true);
          if (unit == Unit.PERCENT) {
            curValue += "%";
          }
          int valWidth = fm.stringWidth(curValue);
          String legend = (displayLegend ? seq.name : "");
          int legendWidth = fm.stringWidth(legend);
          if (checkRightMargin(valWidth) || checkRightMargin(legendWidth)) {
            // Wait for next repaint
            return;
          }
          g.drawString(legend, x + 17, Math.min(topMargin + h, y2 + 3 - 10));
          g.drawString(curValue, x + 17, Math.min(topMargin + h + 10, y2 + 3));

          // Maybe draw a short line to value
          if (y2 > y + 3) {
            g.drawLine(x + 9, y + 2, x + 14, y2);
          } else if (y2 < y - 3) {
            g.drawLine(x + 9, y - 2, x + 14, y2);
          }
        }
        g.setFont(oldFont);
        g.setColor(fg);
      }
    }
    g.setColor(oldColor);
  }
  /**
   * Paints the image.
   *
   * @param g the rendering surface to use
   * @param a the allocated region to render into
   * @see View#paint
   */
  public void paint(Graphics g, Shape a) {
    Color oldColor = g.getColor();
    fBounds = a.getBounds();
    int border = getBorder();
    int x = fBounds.x + border + getSpace(X_AXIS);
    int y = fBounds.y + border + getSpace(Y_AXIS);
    int width = fWidth;
    int height = fHeight;
    int sel = getSelectionState();

    // Make sure my Component is in the right place:
    /*
    if( fComponent == null ) {
    fComponent = new Component() { };
    fComponent.addMouseListener(this);
    fComponent.addMouseMotionListener(this);
    fComponent.setCursor(Cursor.getDefaultCursor());	// use arrow cursor
    fContainer.add(fComponent);
    }
    fComponent.setBounds(x,y,width,height);
    */
    // If no pixels yet, draw gray outline and icon:
    if (!hasPixels(this)) {
      g.setColor(Color.lightGray);
      g.drawRect(x, y, width - 1, height - 1);
      g.setColor(oldColor);
      loadIcons();
      Icon icon = fImage == null ? sMissingImageIcon : sPendingImageIcon;
      if (icon != null) icon.paintIcon(getContainer(), g, x, y);
    }

    // Draw image:
    if (fImage != null) {
      g.drawImage(fImage, x, y, width, height, this);
      // Use the following instead of g.drawImage when
      // BufferedImageGraphics2D.setXORMode is fixed (4158822).

      //  Use Xor mode when selected/highlighted.
      // ! Could darken image instead, but it would be more expensive.
      /*
      if( sel > 0 )
      g.setXORMode(Color.white);
      g.drawImage(fImage,x, y,
      width,height,this);
      if( sel > 0 )
      g.setPaintMode();
      */
    }

    // If selected exactly, we need a black border & grow-box:
    Color bc = getBorderColor();
    if (sel == 2) {
      // Make sure there's room for a border:
      int delta = 2 - border;
      if (delta > 0) {
        x += delta;
        y += delta;
        width -= delta << 1;
        height -= delta << 1;
        border = 2;
      }
      bc = null;
      g.setColor(Color.black);
      // Draw grow box:
      g.fillRect(x + width - 5, y + height - 5, 5, 5);
    }

    // Draw border:
    if (border > 0) {
      if (bc != null) g.setColor(bc);
      // Draw a thick rectangle:
      for (int i = 1; i <= border; i++)
        g.drawRect(x - i, y - i, width - 1 + i + i, height - 1 + i + i);
      g.setColor(oldColor);
    }
  }