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);
    }
  }
Ejemplo n.º 3
0
  public PlayControlPanel(
      SequencerWrapper seq, String playIconName, String pauseIconName, String stopIconName) {
    super(
        new TableLayout(
            new double[] {4, 0.50, PREFERRED, PREFERRED, 0.50, 4, PREFERRED, 4},
            new double[] {4, PREFERRED, 4, PREFERRED, 4}));

    this.sequencer = seq;

    this.playIcon = new ImageIcon(IconLoader.class.getResource(playIconName + ".png"));
    this.pauseIcon = new ImageIcon(IconLoader.class.getResource(pauseIconName + ".png"));
    Icon stopIcon = new ImageIcon(IconLoader.class.getResource(stopIconName + ".png"));

    songPositionBar = new SongPositionBar(seq);
    songPositionLabel = new SongPositionLabel(seq);

    playButton = new JButton(playIcon);
    playButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sequencer.setRunning(!sequencer.isRunning());
          }
        });

    stopButton = new JButton(stopIcon);
    stopButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            sequencer.reset(false);
          }
        });

    sequencer.addChangeListener(
        new SequencerListener() {
          public void propertyChanged(SequencerEvent evt) {
            updateButtonStates();
          }
        });

    updateButtonStates();

    add(songPositionBar, "1, 1, 4, 1");
    add(songPositionLabel, "6, 1");
    add(playButton, "2, 3");
    add(stopButton, "3, 3");
  }
Ejemplo n.º 4
0
 private void updateButtonStates() {
   playButton.setIcon(sequencer.isRunning() ? pauseIcon : playIcon);
   playButton.setEnabled(sequencer.isLoaded());
   stopButton.setEnabled(
       sequencer.isLoaded() && (sequencer.isRunning() || sequencer.getPosition() != 0));
 }