From e700f91bf737d925f1edf8785277be8deb7d38bc Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sat, 25 Apr 2015 20:21:10 +0200 Subject: [PATCH] various small fixes --- .../src/com/jpexs/decompiler/flash/SWF.java | 2 +- .../flash/tags/DefineSpriteTag.java | 14 +------- .../decompiler/flash/timeline/Timeline.java | 13 ++++++++ .../decompiler/flash/gui/ImagePanel.java | 2 +- .../decompiler/flash/gui/LoadingPanel.java | 12 +++++++ src/com/jpexs/decompiler/flash/gui/Main.java | 7 +++- src/com/jpexs/decompiler/flash/gui/View.java | 4 +++ .../flash/gui/player/FlashPlayerPanel.java | 33 ++++++++++++------- 8 files changed, 59 insertions(+), 28 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index f359715b6..f7315c384 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -194,7 +194,7 @@ public final class SWF implements SWFContainerItem, Timelined { public List tags = new ArrayList<>(); @Internal - public boolean hasEndTag; + public boolean hasEndTag = true; /** * ExportRectangle for the display diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index cd0262ada..a71e902b3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -313,18 +313,6 @@ public class DefineSpriteTag extends CharacterTag implements DrawableTag, Timeli return getTimeline().getFrameCount(); // frameCount } - private int getRealFrameCount() { - int cnt = 1; - Timeline timeline = getTimeline(); - for (int i = 1; i < timeline.getFrameCount(); i++) { - if (timeline.getFrame(i).layersChanged) { - cnt++; - } - } - - return cnt; - } - @Override public boolean isSingleFrame() { if (!isSingleFrameInitialized) { @@ -335,7 +323,7 @@ public class DefineSpriteTag extends CharacterTag implements DrawableTag, Timeli private synchronized void initialiteIsSingleFrame() { if (!isSingleFrameInitialized) { - if (getRealFrameCount() > 1) { + if (getTimeline().getRealFrameCount() > 1) { isSingleFrameInitialized = true; return; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java index 63d569bdc..369b8581b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/Timeline.java @@ -159,6 +159,19 @@ public class Timeline { return frames.size(); } + public int getRealFrameCount() { + ensureInitialized(); + + int cnt = 1; + for (int i = 1; i < frames.size(); i++) { + if (frames.get(i).layersChanged) { + cnt++; + } + } + + return cnt; + } + public int getFrameForAction(ASMSource asm) { Integer frame = actionFrames.get(asm); if (frame == null) { diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 9a5208504..efe4f390b 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -916,7 +916,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis int msPerFrame = frameRate == 0 ? 1000 : 1000 / frameRate; final int cnt = counter; - final boolean singleFrame = timeline.getFrameCount() <= 1 && timeline.isSingleFrame(); + final boolean singleFrame = timeline.getRealFrameCount() <= 1 && timeline.isSingleFrame(); shouldDraw.set(true); startTimer(cnt, singleFrame, msPerFrame); } diff --git a/src/com/jpexs/decompiler/flash/gui/LoadingPanel.java b/src/com/jpexs/decompiler/flash/gui/LoadingPanel.java index b5c98c52d..e643e452a 100644 --- a/src/com/jpexs/decompiler/flash/gui/LoadingPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/LoadingPanel.java @@ -139,4 +139,16 @@ public class LoadingPanel extends JPanel { g2.setTransform(t); g2.drawImage(lastImage, 0, 0, this); } + + @Override + public void setVisible(boolean visible) { + if (!visible) { + if (drawTimer != null) { + drawTimer.cancel(); + drawTimer = null; + } + } + + super.setVisible(visible); + } } diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 0e788a588..12997cc3c 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -439,9 +439,11 @@ public class Main { } catch (OutOfMemoryError ex) { logger.log(Level.SEVERE, null, ex); View.showMessageDialog(null, "Cannot load SWF file. Out of memory."); + continue; } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); View.showMessageDialog(null, "Cannot load SWF file."); + continue; } final SWFList swfs1 = swfs; @@ -1106,7 +1108,10 @@ public class Main { MainPanel mainPanel = mainFrame.getPanel(); TreePath tp = View.getTreePathByPathStrings(mainPanel.tagTree, Arrays.asList(path)); - mainPanel.setTagTreeSelectedNode((TreeItem) tp.getLastPathComponent()); + if (tp != null) { + // the current view is the Resources view, otherwise tp is null + mainPanel.setTagTreeSelectedNode((TreeItem) tp.getLastPathComponent()); + } } }); } diff --git a/src/com/jpexs/decompiler/flash/gui/View.java b/src/com/jpexs/decompiler/flash/gui/View.java index e931c2955..2bd5e2deb 100644 --- a/src/com/jpexs/decompiler/flash/gui/View.java +++ b/src/com/jpexs/decompiler/flash/gui/View.java @@ -538,6 +538,10 @@ public class View { public static TreePath getTreePathByPathStrings(JTree tree, List pathAsStringList) { TreeModel model = tree.getModel(); + if (model == null) { + return null; + } + Object node = model.getRoot(); if (pathAsStringList.isEmpty()) { diff --git a/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java b/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java index 6f66b3352..ad46f14de 100644 --- a/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java @@ -184,21 +184,30 @@ public final class FlashPlayerPanel extends Panel implements Closeable, MediaDis @Override public void run() { - boolean changed = false; + try { + ShockwaveFlash flash1 = flash; + if (flash1 == null) { + return; + } - boolean isPlaying = flash.IsPlaying(); - if (this.isPlaying != isPlaying) { - this.isPlaying = isPlaying; - } + boolean changed = false; - int currentFrame = flash.CurrentFrame(); - if (this.currentFrame != currentFrame) { - this.currentFrame = currentFrame; - changed = true; - } + boolean isPlaying = flash1.IsPlaying(); + if (this.isPlaying != isPlaying) { + this.isPlaying = isPlaying; + } - if (changed) { - fireMediaDisplayStateChanged(); + int currentFrame = flash1.CurrentFrame(); + if (this.currentFrame != currentFrame) { + this.currentFrame = currentFrame; + changed = true; + } + + if (changed) { + fireMediaDisplayStateChanged(); + } + } catch (Exception ex) { + // ignore } } }, 100, 100);