From 59f8113fc866cd5b1b78ef1cfa46eacedd53b7b3 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sat, 25 Apr 2015 16:24:21 +0200 Subject: [PATCH] player panel:prev/next button fixed --- .../decompiler/flash/gui/ImagePanel.java | 66 +++++++++++-------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index cde4afd42..c4d8a5fdd 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -875,42 +875,52 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis public synchronized void play() { pause(); if (timelined != null) { - timer = new Timer(); - int frameRate = timelined.getTimeline().frameRate; + Timeline timeline = timelined.getTimeline(); + int frameRate = timeline.frameRate; int msPerFrame = frameRate == 0 ? 1000 : 1000 / frameRate; final int cnt = counter; + final boolean singleFrame = timeline.getFrameCount() <= 1 && timeline.isSingleFrame(); shouldDraw.set(true); - TimerTask task = new TimerTask() { - public int counter = cnt; + startTimer(cnt, singleFrame, msPerFrame); + } + } - private final AtomicBoolean first = shouldDraw; + private void startTimer(int cnt, boolean singleFrame, int msPerFrame) { - @Override - public void run() { - try { - Timeline timeline; - synchronized (ImagePanel.class) { - if (timer == null) { - return; - } + TimerTask task = new TimerTask() { + public final int counter = cnt; - timeline = timelined.getTimeline(); + public final boolean isSingleFrame = singleFrame; + + private final AtomicBoolean first = shouldDraw; + + @Override + public void run() { + try { + synchronized (ImagePanel.class) { + if (timer == null) { + return; } - - if (timeline.getFrameCount() <= 1 && timeline.isSingleFrame()) { - if (first.getAndSet(false)) { - drawFrame(counter); - } - } else { - nextFrame(counter); - } - } catch (Exception ex) { - Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex); } - } - }; + if (isSingleFrame) { + if (first.getAndSet(false)) { + drawFrame(counter); + } + } else { + nextFrame(counter); + } + } catch (Exception ex) { + Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex); + } + } + }; + + timer = new Timer(); + if (singleFrame) { + timer.schedule(task, 0); + } else { timer.schedule(task, 0, msPerFrame); } } @@ -943,7 +953,11 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis if (frame < 0) { return; } + this.frame = frame; + stop(); + shouldDraw.set(true); + startTimer(counter, true, 0); } @Override