Ejemplo n.º 1
0
 private void updatePointerRect() {
   if (seq == null || seq.getLength() == 0) {
     ptrRect.x = 0;
   } else {
     ptrRect.x = (int) (getWidth() * seq.getThumbPosition() / seq.getLength() - PTR_WIDTH / 2);
   }
 }
Ejemplo n.º 2
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

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

    int ptrPos;
    if (seq == null || seq.getLength() == 0) {
      ptrPos = 0;
    } else {
      ptrPos =
          (int) (SIDE_PAD + (getWidth() - 2 * SIDE_PAD) * seq.getThumbPosition() / seq.getLength());
    }

    final int x = SIDE_PAD;
    final int y = (PTR_HEIGHT - BAR_HEIGHT) / 2;
    int right = getWidth() - SIDE_PAD;

    g2.setClip(new RoundRectangle2D.Float(x, y, right - x, BAR_HEIGHT, ROUND, ROUND));
    g2.setPaint(new GradientPaint(0, y, Color.DARK_GRAY, 0, y + BAR_HEIGHT, Color.GRAY));
    g2.fillRect(x, y, ptrPos - x, BAR_HEIGHT);

    g2.setPaint(new GradientPaint(0, y, Color.LIGHT_GRAY, 0, y + BAR_HEIGHT, Color.WHITE));
    g2.fillRect(ptrPos, y, right - ptrPos, BAR_HEIGHT);
    g2.setClip(null);

    g2.setColor(Color.BLACK);
    g2.drawRoundRect(x, y, right - x - 1, BAR_HEIGHT, ROUND, ROUND);

    if ((mouseHovering || seq.isDragging()) && this.isEnabled()) {
      int left = ptrPos - PTR_WIDTH / 2;

      final Color PTR_COLOR_1 = Color.WHITE;
      final Color PTR_COLOR_2 = Color.LIGHT_GRAY;

      g2.setPaint(new GradientPaint(left, 0, PTR_COLOR_1, left + PTR_WIDTH, 0, PTR_COLOR_2));
      g2.fillOval(left, 0, PTR_WIDTH, PTR_HEIGHT);
      g2.setColor(Color.BLACK);
      g2.drawOval(left, 0, PTR_WIDTH - 1, PTR_HEIGHT - 1);
    }
  }