1package aurelienribon.tweenengine.applets;
2
3import aurelienribon.tweenengine.BaseTween;
4import aurelienribon.tweenengine.Timeline;
5import aurelienribon.tweenengine.Tween;
6import aurelienribon.tweenengine.TweenCallback;
7import aurelienribon.tweenengine.TweenCallback.EventType;
8import aurelienribon.tweenengine.TweenManager;
9import aurelienribon.tweenengine.equations.Back;
10import aurelienribon.tweenengine.equations.Bounce;
11import aurelienribon.tweenengine.equations.Quart;
12import aurelienribon.utils.swing.DrawingCanvas;
13import java.awt.BorderLayout;
14import java.awt.Graphics;
15import java.awt.Graphics2D;
16import java.awt.Rectangle;
17import java.awt.TexturePaint;
18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener;
20import java.awt.image.BufferedImage;
21import java.io.IOException;
22import java.util.Hashtable;
23import javax.imageio.ImageIO;
24import javax.swing.JLabel;
25import javax.swing.UIManager;
26import javax.swing.UnsupportedLookAndFeelException;
27import javax.swing.event.ChangeEvent;
28import javax.swing.event.ChangeListener;
29
30/**
31 * @author Aurelien Ribon | http://www.aurelienribon.com
32 */
33public class TimelineApplet extends javax.swing.JApplet {
34	/*public static void main(String[] args) {
35		TimelineApplet applet = new TimelineApplet();
36		applet.init();
37		applet.start();
38
39		javax.swing.JFrame wnd = new javax.swing.JFrame();
40		wnd.add(applet);
41		wnd.setSize(600, 700);
42		wnd.setVisible(true);
43	}*/
44
45	// -------------------------------------------------------------------------
46	// Applet
47	// -------------------------------------------------------------------------
48
49	private MyCanvas canvas;
50	private boolean isPaused = false;
51
52	@Override
53	public void init() {
54		try {
55			java.awt.EventQueue.invokeAndWait(new Runnable() {
56				@Override public void run() {load();}
57			});
58		} catch (Exception ex) {
59		}
60	}
61
62	@Override
63	public void destroy() {
64		DrawingCanvas canvas = (DrawingCanvas) canvasWrapper.getComponent(0);
65		canvas.stop();
66	}
67
68	private void load() {
69		try {
70			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
71		} catch (ClassNotFoundException ex) {
72		} catch (InstantiationException ex) {
73		} catch (IllegalAccessException ex) {
74		} catch (UnsupportedLookAndFeelException ex) {
75		}
76
77		initComponents();
78
79		getContentPane().setBackground(Theme.MAIN_BACKGROUND);
80		Theme.apply(getContentPane());
81
82		OptionsListener listener = new OptionsListener();
83		rptSpinner.addChangeListener(listener);
84		rptDelaySpinner.addChangeListener(listener);
85		yoyoChk.addActionListener(listener);
86
87		generateCode();
88
89		Hashtable<Integer, JLabel> labels = new Hashtable<Integer, JLabel>();
90		labels.put(-300, new JLabel("-3"));
91		labels.put(-200, new JLabel("-2"));
92		labels.put(-100, new JLabel("-1"));
93		labels.put(0, new JLabel("0"));
94		labels.put(100, new JLabel("1"));
95		labels.put(200, new JLabel("2"));
96		labels.put(300, new JLabel("3"));
97		for (JLabel lbl : labels.values()) lbl.setForeground(Theme.MAIN_FOREGROUND);
98		speedSlider.setLabelTable(labels);
99
100		canvas = (MyCanvas) new MyCanvas().start();
101		canvasWrapper.add(canvas, BorderLayout.CENTER);
102		canvas.setCallback(new DrawingCanvas.Callback() {
103			@Override public void onUpdate(int elapsedMillis) {
104				if (canvas.getTimeline() == null || isPaused) return;
105				int delta = (int) (elapsedMillis * (speedSlider.getValue() / 100f));
106
107				if (canvas.getTimeline().getState()%4 == 2 && canvas.getTimeline().isYoyo())
108					iterationTimeSlider.setValue(iterationTimeSlider.getValue() - delta);
109				else if (canvas.getTimeline().getState()%2 == 0)
110					iterationTimeSlider.setValue(iterationTimeSlider.getValue() + delta);
111				totalTimeSlider.setValue(totalTimeSlider.getValue() + delta);
112			}
113		});
114
115		canvas.createTimeline();
116		initTimeline();
117	}
118
119	private void initTimeline() {
120		iterationTimeSlider.setMaximum(canvas.getTimeline().getDuration());
121		totalTimeSlider.setMaximum(canvas.getTimeline().getFullDuration());
122
123		canvas.getTimeline().addCallback(EventType.BEGIN, new TweenCallback() {
124			@Override public void onEvent(EventType eventType, BaseTween source) {
125				totalTimeSlider.setValue(0);
126			}
127		});
128
129		canvas.getTimeline().addCallback(EventType.START, new TweenCallback() {
130			@Override public void onEvent(EventType eventType, BaseTween source) {
131				if (canvas.getTimeline().getState()%4 == 2 && canvas.getTimeline().isYoyo())
132					iterationTimeSlider.setValue(canvas.getTimeline().getFullDuration());
133				else if (canvas.getTimeline().getState()%2 == 0)
134					iterationTimeSlider.setValue(0);
135			}
136		});
137	}
138
139	private void generateCode() {
140		int rptCnt = (Integer) rptSpinner.getValue();
141		int rptDelay = (Integer) rptDelaySpinner.getValue();
142		boolean isYoyo = yoyoChk.isSelected();
143
144		String code = "Timeline.createSequence()" +
145				"\n    .push(Tween.to(imgTweenSprite, POSITION_XY, 500).target(60, 90).ease(Quart.OUT))" +
146				"\n    .push(Tween.to(imgEngineSprite, POSITION_XY, 500).target(200, 90).ease(Quart.OUT))" +
147				"\n    .push(Tween.to(imgUniversalSprite, POSITION_XY, 1000).target(60, 55).ease(Bounce.OUT))" +
148				"\n    .pushPause(500)" +
149				"\n    .beginParallel()" +
150				"\n        .push(Tween.set(imgLogoSprite, VISIBILITY).target(1))" +
151				"\n        .push(Tween.to(imgLogoSprite, SCALE_XY, 800).target(1, 1).ease(Back.OUT))" +
152				"\n        .push(Tween.to(blankStripSprite, SCALE_XY, 500).target(1, 1).ease(Back.OUT))" +
153				"\n    .end()";
154
155		if (rptCnt > 0) code += "\n    .repeat" + (isYoyo ? "Yoyo" : "") + "(" + rptCnt + ", " + rptDelay + ")";
156
157		code += "\n    .start(myManager);";
158
159		resultArea.setText(code);
160	}
161
162	private void restart() {
163		speedSlider.setValue(100);
164		canvas.createTimeline();
165		initTimeline();
166	}
167
168	private class OptionsListener implements ChangeListener, ActionListener {
169		@Override public void stateChanged(ChangeEvent e) {onEvent();}
170		@Override public void actionPerformed(ActionEvent e) {onEvent();}
171		private void onEvent() {
172			generateCode();
173			restart();
174		}
175	}
176
177	// -------------------------------------------------------------------------
178	// Canvas
179	// -------------------------------------------------------------------------
180
181	private class MyCanvas extends DrawingCanvas {
182		private final TweenManager tweenManager = new TweenManager();
183		private final Sprite imgUniversalSprite;
184		private final Sprite imgTweenSprite;
185		private final Sprite imgEngineSprite;
186		private final Sprite imgLogoSprite;
187		private final Sprite blankStripSprite;
188		private TexturePaint bgPaint;
189		private Timeline timeline;
190
191		public MyCanvas() {
192			Tween.enablePooling(false);
193			Tween.registerAccessor(Sprite.class, new SpriteAccessor());
194
195			imgUniversalSprite = new Sprite("img-universal.png").setCentered(false);
196			imgTweenSprite = new Sprite("img-tween.png").setCentered(false);
197			imgEngineSprite = new Sprite("img-engine.png").setCentered(false);
198			imgLogoSprite = new Sprite("img-logo.png");
199			blankStripSprite = new Sprite("blankStrip.png");
200
201			try {
202				BufferedImage bgImage = ImageIO.read(TimelineApplet.class.getResource("/aurelienribon/tweenengine/applets/gfx/transparent-dark.png"));
203				bgPaint = new TexturePaint(bgImage, new Rectangle(0, 0, bgImage.getWidth(), bgImage.getHeight()));
204			} catch (IOException ex) {
205			}
206		}
207
208		@Override
209		protected void update(int elapsedMillis) {
210			if (isPaused) return;
211			int delta = (int) (elapsedMillis * (speedSlider.getValue() / 100f));
212			tweenManager.update(delta);
213			repaint();
214		}
215
216		@Override
217		protected void paintComponent(Graphics g) {
218			Graphics2D gg = (Graphics2D) g;
219
220			if (bgPaint != null) {
221				gg.setPaint(bgPaint);
222				gg.fillRect(0, 0, getWidth(), getHeight());
223				gg.setPaint(null);
224			}
225
226			blankStripSprite.draw(gg);
227			imgUniversalSprite.draw(gg);
228			imgTweenSprite.draw(gg);
229			imgEngineSprite.draw(gg);
230			imgLogoSprite.draw(gg);
231		}
232
233		public void createTimeline() {
234			tweenManager.killAll();
235
236			imgUniversalSprite.setPosition(60, 105 - 200);
237			imgTweenSprite.setPosition(60 - 300, 140);
238			imgEngineSprite.setPosition(200 + 300, 140);
239
240			imgLogoSprite.setPosition(310, 120);
241			imgLogoSprite.setScale(7, 7);
242			imgLogoSprite.setVisible(false);
243
244			blankStripSprite.setPosition(250, 140);
245			blankStripSprite.setScale(1, 0);
246
247			timeline = Timeline.createSequence()
248				.push(Tween.to(imgTweenSprite, SpriteAccessor.POSITION_XY, 500).target(60, 140).ease(Quart.OUT))
249				.push(Tween.to(imgEngineSprite, SpriteAccessor.POSITION_XY, 500).target(200, 140).ease(Quart.OUT))
250				.push(Tween.to(imgUniversalSprite, SpriteAccessor.POSITION_XY, 1000).target(60, 105).ease(Bounce.OUT))
251				.pushPause(500)
252				.beginParallel()
253					.push(Tween.set(imgLogoSprite, SpriteAccessor.VISIBILITY).target(1))
254					.push(Tween.to(imgLogoSprite, SpriteAccessor.SCALE_XY, 800).target(1, 1).ease(Back.OUT))
255					.push(Tween.to(blankStripSprite, SpriteAccessor.SCALE_XY, 500).target(1, 1).ease(Back.OUT))
256				.end();
257
258			int rptCnt = (Integer) rptSpinner.getValue();
259			int rpDelay = (Integer) rptDelaySpinner.getValue();
260			boolean yoyo = yoyoChk.isSelected();
261
262			if (rptCnt > 0 && yoyo) timeline.repeatYoyo(rptCnt, rpDelay);
263			else if (rptCnt > 0) timeline.repeat(rptCnt, rpDelay);
264
265			timeline.addCallback(EventType.COMPLETE, new TweenCallback() {
266				@Override public void onEvent(EventType eventType, BaseTween source) {
267					timeline = null;
268				}
269			});
270
271			timeline.addCallback(EventType.BACK_COMPLETE, new TweenCallback() {
272				@Override public void onEvent(EventType eventType, BaseTween source) {
273					timeline = null;
274				}
275			});
276
277			timeline.start(tweenManager);
278		}
279
280		public Timeline getTimeline() {
281			return timeline;
282		}
283	}
284
285	// -------------------------------------------------------------------------
286	// Generated stuff
287	// -------------------------------------------------------------------------
288
289    @SuppressWarnings("unchecked")
290    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
291    private void initComponents() {
292
293        jPanel1 = new javax.swing.JPanel();
294        jScrollPane1 = new javax.swing.JScrollPane();
295        resultArea = new javax.swing.JTextArea();
296        jLabel1 = new javax.swing.JLabel();
297        jLabel9 = new javax.swing.JLabel();
298        canvasWrapper = new javax.swing.JPanel();
299        jPanel3 = new javax.swing.JPanel();
300        jLabel2 = new javax.swing.JLabel();
301        jPanel2 = new javax.swing.JPanel();
302        jLabel4 = new javax.swing.JLabel();
303        rptSpinner = new javax.swing.JSpinner();
304        yoyoChk = new javax.swing.JCheckBox();
305        jLabel6 = new javax.swing.JLabel();
306        rptDelaySpinner = new javax.swing.JSpinner();
307        jPanel5 = new javax.swing.JPanel();
308        speedSlider = new javax.swing.JSlider();
309        jPanel4 = new javax.swing.JPanel();
310        restartBtn = new javax.swing.JButton();
311        pauseBtn = new javax.swing.JButton();
312        resumeBtn = new javax.swing.JButton();
313        reverseBtn = new javax.swing.JButton();
314        jLabel3 = new javax.swing.JLabel();
315        jLabel5 = new javax.swing.JLabel();
316        iterationTimeSlider = new javax.swing.JSlider();
317        totalTimeSlider = new javax.swing.JSlider();
318
319        jPanel1.setBorder(new aurelienribon.utils.swing.GroupBorder());
320
321        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
322
323        resultArea.setColumns(20);
324        jScrollPane1.setViewportView(resultArea);
325
326        jLabel1.setText("Java code:");
327
328        jLabel9.setText("<html>\nUniversal Tween Engine v6.0.0 - <font color=\"#77C8FF\">www.aurelienribon.com</font>");
329
330        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
331        jPanel1.setLayout(jPanel1Layout);
332        jPanel1Layout.setHorizontalGroup(
333            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
334            .addGroup(jPanel1Layout.createSequentialGroup()
335                .addContainerGap()
336                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
337                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 598, Short.MAX_VALUE)
338                    .addGroup(jPanel1Layout.createSequentialGroup()
339                        .addComponent(jLabel1)
340                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 273, Short.MAX_VALUE)
341                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
342                .addContainerGap())
343        );
344        jPanel1Layout.setVerticalGroup(
345            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346            .addGroup(jPanel1Layout.createSequentialGroup()
347                .addContainerGap()
348                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
349                    .addComponent(jLabel1)
350                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
351                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
352                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
353                .addContainerGap())
354        );
355
356        canvasWrapper.setLayout(new java.awt.BorderLayout());
357
358        jPanel3.setOpaque(false);
359
360        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
361        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/aurelienribon/tweenengine/applets/gfx/logo-timeline.png"))); // NOI18N
362
363        aurelienribon.utils.swing.GroupBorder groupBorder1 = new aurelienribon.utils.swing.GroupBorder();
364        groupBorder1.setTitle("Timeline options");
365        jPanel2.setBorder(groupBorder1);
366
367        jLabel4.setText("Repetitions:");
368
369        rptSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(2), Integer.valueOf(0), null, Integer.valueOf(1)));
370
371        yoyoChk.setSelected(true);
372        yoyoChk.setText("Yoyo repetitions");
373
374        jLabel6.setText("Repeat delay:");
375
376        rptDelaySpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(500), Integer.valueOf(0), null, Integer.valueOf(100)));
377
378        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
379        jPanel2.setLayout(jPanel2Layout);
380        jPanel2Layout.setHorizontalGroup(
381            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
382            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
383                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
384                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
385                    .addComponent(yoyoChk, javax.swing.GroupLayout.Alignment.TRAILING)
386                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
387                        .addComponent(jLabel4)
388                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
389                        .addComponent(rptSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
390                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
391                        .addComponent(jLabel6)
392                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
393                        .addComponent(rptDelaySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
394                .addContainerGap())
395        );
396        jPanel2Layout.setVerticalGroup(
397            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
398            .addGroup(jPanel2Layout.createSequentialGroup()
399                .addContainerGap()
400                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
401                    .addComponent(rptSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
402                    .addComponent(jLabel4))
403                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
404                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
405                    .addComponent(rptDelaySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
406                    .addComponent(jLabel6))
407                .addGap(18, 18, 18)
408                .addComponent(yoyoChk)
409                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
410        );
411
412        aurelienribon.utils.swing.GroupBorder groupBorder2 = new aurelienribon.utils.swing.GroupBorder();
413        groupBorder2.setTitle("Animation speed");
414        jPanel5.setBorder(groupBorder2);
415
416        speedSlider.setMajorTickSpacing(100);
417        speedSlider.setMaximum(300);
418        speedSlider.setMinimum(-300);
419        speedSlider.setPaintLabels(true);
420        speedSlider.setPaintTicks(true);
421        speedSlider.setValue(100);
422
423        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
424        jPanel5.setLayout(jPanel5Layout);
425        jPanel5Layout.setHorizontalGroup(
426            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
427            .addGroup(jPanel5Layout.createSequentialGroup()
428                .addContainerGap()
429                .addComponent(speedSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
430                .addContainerGap())
431        );
432        jPanel5Layout.setVerticalGroup(
433            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
434            .addGroup(jPanel5Layout.createSequentialGroup()
435                .addContainerGap()
436                .addComponent(speedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
437                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
438        );
439
440        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
441        jPanel3.setLayout(jPanel3Layout);
442        jPanel3Layout.setHorizontalGroup(
443            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
444            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
445            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
446            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
447        );
448        jPanel3Layout.setVerticalGroup(
449            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
450            .addGroup(jPanel3Layout.createSequentialGroup()
451                .addComponent(jLabel2)
452                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
453                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
454                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
455                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
456        );
457
458        jPanel4.setBorder(new aurelienribon.utils.swing.GroupBorder());
459
460        restartBtn.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
461        restartBtn.setText("Restart");
462        restartBtn.setMargin(new java.awt.Insets(2, 3, 2, 3));
463        restartBtn.addActionListener(new java.awt.event.ActionListener() {
464            public void actionPerformed(java.awt.event.ActionEvent evt) {
465                restartBtnActionPerformed(evt);
466            }
467        });
468
469        pauseBtn.setText("Pause");
470        pauseBtn.setMargin(new java.awt.Insets(2, 3, 2, 3));
471        pauseBtn.addActionListener(new java.awt.event.ActionListener() {
472            public void actionPerformed(java.awt.event.ActionEvent evt) {
473                pauseBtnActionPerformed(evt);
474            }
475        });
476
477        resumeBtn.setText("Resume");
478        resumeBtn.setMargin(new java.awt.Insets(2, 3, 2, 3));
479        resumeBtn.addActionListener(new java.awt.event.ActionListener() {
480            public void actionPerformed(java.awt.event.ActionEvent evt) {
481                resumeBtnActionPerformed(evt);
482            }
483        });
484
485        reverseBtn.setText("Reverse");
486        reverseBtn.setMargin(new java.awt.Insets(2, 3, 2, 3));
487        reverseBtn.addActionListener(new java.awt.event.ActionListener() {
488            public void actionPerformed(java.awt.event.ActionEvent evt) {
489                reverseBtnActionPerformed(evt);
490            }
491        });
492
493        jLabel3.setText("Total time:");
494
495        jLabel5.setText("Iteration time:");
496
497        iterationTimeSlider.setEnabled(false);
498
499        totalTimeSlider.setEnabled(false);
500
501        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
502        jPanel4.setLayout(jPanel4Layout);
503        jPanel4Layout.setHorizontalGroup(
504            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
505            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
506                .addContainerGap()
507                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
508                    .addComponent(restartBtn)
509                    .addComponent(reverseBtn))
510                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
511                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
512                    .addGroup(jPanel4Layout.createSequentialGroup()
513                        .addComponent(resumeBtn)
514                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
515                        .addComponent(jLabel3))
516                    .addGroup(jPanel4Layout.createSequentialGroup()
517                        .addComponent(pauseBtn)
518                        .addGap(18, 18, 18)
519                        .addComponent(jLabel5)))
520                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
521                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
522                    .addComponent(totalTimeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)
523                    .addComponent(iterationTimeSlider, javax.swing.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE))
524                .addContainerGap())
525        );
526
527        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {pauseBtn, restartBtn, resumeBtn, reverseBtn});
528
529        jPanel4Layout.setVerticalGroup(
530            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
531            .addGroup(jPanel4Layout.createSequentialGroup()
532                .addContainerGap()
533                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
534                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
535                        .addComponent(restartBtn)
536                        .addComponent(pauseBtn)
537                        .addComponent(jLabel5))
538                    .addComponent(iterationTimeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
539                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
540                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
541                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
542                        .addComponent(resumeBtn)
543                        .addComponent(reverseBtn)
544                        .addComponent(jLabel3))
545                    .addComponent(totalTimeSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
546                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
547        );
548
549        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
550        getContentPane().setLayout(layout);
551        layout.setHorizontalGroup(
552            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
553            .addGroup(layout.createSequentialGroup()
554                .addContainerGap()
555                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
556                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
557                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
558                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
559                        .addComponent(canvasWrapper, javax.swing.GroupLayout.DEFAULT_SIZE, 448, Short.MAX_VALUE)
560                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
561                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
562                .addContainerGap())
563        );
564        layout.setVerticalGroup(
565            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
566            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
567                .addContainerGap()
568                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
569                    .addComponent(canvasWrapper, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
570                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
571                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
572                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
573                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
574                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
575                .addContainerGap())
576        );
577    }// </editor-fold>//GEN-END:initComponents
578
579	private void restartBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_restartBtnActionPerformed
580		restart();
581	}//GEN-LAST:event_restartBtnActionPerformed
582
583	private void pauseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseBtnActionPerformed
584		isPaused = true;
585	}//GEN-LAST:event_pauseBtnActionPerformed
586
587	private void resumeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resumeBtnActionPerformed
588		isPaused = false;
589	}//GEN-LAST:event_resumeBtnActionPerformed
590
591	private void reverseBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reverseBtnActionPerformed
592		speedSlider.setValue(-speedSlider.getValue());
593	}//GEN-LAST:event_reverseBtnActionPerformed
594
595    // Variables declaration - do not modify//GEN-BEGIN:variables
596    private javax.swing.JPanel canvasWrapper;
597    private javax.swing.JSlider iterationTimeSlider;
598    private javax.swing.JLabel jLabel1;
599    private javax.swing.JLabel jLabel2;
600    private javax.swing.JLabel jLabel3;
601    private javax.swing.JLabel jLabel4;
602    private javax.swing.JLabel jLabel5;
603    private javax.swing.JLabel jLabel6;
604    private javax.swing.JLabel jLabel9;
605    private javax.swing.JPanel jPanel1;
606    private javax.swing.JPanel jPanel2;
607    private javax.swing.JPanel jPanel3;
608    private javax.swing.JPanel jPanel4;
609    private javax.swing.JPanel jPanel5;
610    private javax.swing.JScrollPane jScrollPane1;
611    private javax.swing.JButton pauseBtn;
612    private javax.swing.JButton restartBtn;
613    private javax.swing.JTextArea resultArea;
614    private javax.swing.JButton resumeBtn;
615    private javax.swing.JButton reverseBtn;
616    private javax.swing.JSpinner rptDelaySpinner;
617    private javax.swing.JSpinner rptSpinner;
618    private javax.swing.JSlider speedSlider;
619    private javax.swing.JSlider totalTimeSlider;
620    private javax.swing.JCheckBox yoyoChk;
621    // End of variables declaration//GEN-END:variables
622
623}
624