Package ui.status

Source Code of ui.status.FakeBar$Animator

package ui.status;


import java.awt.BorderLayout;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JPanel;
import javax.swing.border.SoftBevelBorder;


public class FakeBar extends JPanel
{
  private static final long serialVersionUID = 3384614949446196984L;

  private class Animator extends TimerTask
  {
    private Timer timer;

    public Animator()
    {
      timer = new Timer("Scheduler: fakebar animation");
      timer.scheduleAtFixedRate(this, 0, 20);
    }

    public void run()
    {
      graphics.advanceCursor();
    }

    public void stop()
    {
      timer.cancel();
    }

  }

  private boolean activated;

  private FakeBarGraphics graphics;
  private Animator animator;

  public FakeBar()
  {
    super();
    setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED));
    setLayout(new BorderLayout());

    setVisible(false);
    activated = false;

    graphics = new FakeBarGraphics();
    add(graphics, BorderLayout.CENTER);
  }

  public void activate()
  {
    if (!activated)
    {
      animator = new Animator();
      activated = true;

      setVisible(true);
    }
  }

  public void stop()
  {
    if (activated)
    {
      setVisible(false);

      animator.stop();
      animator = null;

      activated = false;
      repaint();
    }
  }

}
TOP

Related Classes of ui.status.FakeBar$Animator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.