Removed unused exports and finished UpdateChecker.
[FinalKeyGui.git] / src / fkgui / Animation.java
1 package fkgui;
2
3 import java.util.Vector;
4
5 import org.eclipse.swt.graphics.Image;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.swt.widgets.Label;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.layout.FormLayout;
10 import org.eclipse.swt.layout.FormData;
11 import org.eclipse.swt.layout.FormAttachment;
12 import org.eclipse.wb.swt.SWTResourceManager;
13
14 public class Animation extends Composite {
15
16         /**
17          * Create the composite.
18          * @param parent
19          * @param style
20          */
21         
22         public int msDelay=1000;
23         public Boolean playing=false;
24         public int curFrame=0;
25         public Vector<Image> frames;
26         Label label;
27         
28         public Animation(Composite parent, int style, float FPS) {
29                 super(parent, style);
30                 setLayout(new FormLayout());
31                 
32                 label = new Label(this, SWT.NONE);
33                 FormData fd_label = new FormData();
34                 fd_label.top = new FormAttachment(0);
35                 fd_label.left = new FormAttachment(0);
36                 fd_label.bottom = new FormAttachment(0, 32);
37                 fd_label.right = new FormAttachment(0, 32);
38                 label.setLayoutData(fd_label);
39                 frames = new Vector<Image>(7);
40                 setFPS(FPS);
41                 addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/ani/1.png") ); //$NON-NLS-1$
42                 addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/ani/2.png") ); //$NON-NLS-1$
43                 addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/ani/3.png") ); //$NON-NLS-1$
44                 addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/ani/4.png") ); //$NON-NLS-1$
45                 addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/ani/5.png") ); //$NON-NLS-1$
46                 addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/ani/6.png") ); //$NON-NLS-1$
47                 addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/ani/7.png") ); //$NON-NLS-1$
48         }
49         
50         public void setPlaying(Boolean state )
51         {
52                 playing=state;
53                 if(playing)
54                 {
55                         animate();
56                 }
57         }
58
59         private void animate() {
60                 getDisplay().timerExec(msDelay, new Runnable() {
61                         
62                         @Override
63                         public void run() {
64
65                                 if( !label.isDisposed() )
66                                 {
67                                         if( isVisible() && frames.size() > 0 )
68                                         {
69                                                 curFrame++;
70
71                                                 if( curFrame > frames.size()-1 )
72                                                 {
73                                                         curFrame=0;
74                                                 }
75                                                 
76                                                 label.setImage( frames.get(curFrame) );
77         
78                                                 label.getDisplay().update();
79                                         }
80                                         if(playing)
81                                         {
82                                                 animate();
83                                         }
84                                 }
85                                 
86                         }
87                 });
88                 
89         }
90
91
92
93         @Override
94         protected void checkSubclass() {
95                 // Disable the check that prevents subclassing of SWT components
96         }
97
98         private void addFrame(Image image) {
99                 frames.addElement(image);
100         }
101         
102         private void setFPS( float fps )
103         {
104                 msDelay = (int)(1000.0 / fps);
105         }
106 }