16 package net.squiz.matrix.ui;
19 import java.awt.event.*;
21 import net.squiz.matrix.core.*;
23 import java.awt.image.*;
33 public class Spinner extends JComponent implements Runnable {
38 public static final int delay = 40;
45 private int framePtr = 0;
46 private volatile Thread animator;
47 private Image[] frames;
48 private Image stopImage;
55 ImageIcon spinner = (ImageIcon) GUIUtilities.getAssetMapIcon(
SPINNER_ICON);
56 Image spinnerImg = spinner.getImage();
58 BufferedImage spinnerSrc =
new BufferedImage(
59 spinner.getIconWidth(),
60 spinner.getIconHeight(),
61 BufferedImage.TYPE_INT_ARGB_PRE
64 Graphics2D g2d = (Graphics2D) spinnerSrc.createGraphics();
65 g2d.drawImage(spinnerImg, 0, 0, null);
70 int numFrames = (spinner.getIconWidth() /
IMG_OFFSET) - 1;
72 frames =
new Image[numFrames];
78 for (
int i = 0; i < numFrames; i++) {
88 Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
89 long tm = System.currentTimeMillis();
91 while (Thread.currentThread() == animator) {
92 Graphics g = getGraphics();
94 g.drawImage(frames[framePtr], 0, 0, null);
96 if (framePtr == frames.length - 1) {
104 Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
105 }
catch (InterruptedException e) {
108 Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
123 g.drawImage(stopImage, 0, 0, null);
160 animator =
new Thread(
this);
173 Graphics g = getGraphics();
175 g.drawImage(stopImage, 0, 0, null);