Stop preview panel when swf is closed +code formatting

This commit is contained in:
Honfika
2014-03-15 15:11:01 +01:00
parent 6a8844440c
commit d8fdd06477
14 changed files with 91 additions and 92 deletions

View File

@@ -2211,7 +2211,7 @@ public final class SWF implements TreeItem, Timelined {
image.fillTransparent();
Matrix m = new Matrix();
m.translate(-rect.Xmin, -rect.Ymin);
frameToImage(timeline, frame,time, stateUnderCursor, mouseButton, image, m, colorTransform);
frameToImage(timeline, frame, time, stateUnderCursor, mouseButton, image, m, colorTransform);
putToCache(key, image);
return image;
}
@@ -2224,7 +2224,7 @@ public final class SWF implements TreeItem, Timelined {
image.fillTransparent();
Matrix m = new Matrix();
m.translate(-rect.Xmin, -rect.Ymin);
frameToImage(timeline, f,0, stateUnderCursor, mouseButton, image, m, colorTransform);
frameToImage(timeline, f, 0, stateUnderCursor, mouseButton, image, m, colorTransform);
ret.add(image);
}
}
@@ -2290,7 +2290,7 @@ public final class SWF implements TreeItem, Timelined {
DrawableTag drawable = (DrawableTag) character;
SerializableImage img;
Matrix drawMatrix = new Matrix();
int dframe = 0 + (time+layer.time) % drawable.getNumFrames();
int dframe = 0 + (time + layer.time) % drawable.getNumFrames();
if (character instanceof ButtonTag) {
ButtonTag bt = (ButtonTag) character;
dframe = ButtonTag.FRAME_UP;

View File

@@ -150,7 +150,7 @@ public class ScriptPack implements TreeElementItem {
public void toSource(GraphTextWriter writer, final List<ABCContainerTag> abcList, final Trait[] traits, final ScriptExportMode exportMode, final boolean parallel) throws InterruptedException {
writer.suspendMeasure();
int timeout = Configuration.decompilationTimeoutFile.get();
int timeout = Configuration.decompilationTimeoutFile.get();
try {
CancellableWorker.call(new Callable<Void>() {
@Override

View File

@@ -24,7 +24,7 @@ public enum SoundExportMode {
MP3_WAV_FLV(true, true, true), FLV(false, false, true), MP3_WAV(true, true, false), WAV(false, true, false);
private boolean mp3, wav, flv;
private final boolean mp3, wav, flv;
private SoundExportMode(boolean mp3, boolean wav, boolean flv) {
this.mp3 = mp3;

View File

@@ -83,8 +83,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
private JLabel debugLabel = new JLabel("-");
private DepthState stateUnderCursor = null;
private MouseEvent lastMouseEvent = null;
private List<SoundTagPlayer> soundPlayers = new ArrayList<>();
private IconPanel iconPanel;
private final List<SoundTagPlayer> soundPlayers = new ArrayList<>();
private final IconPanel iconPanel;
private int time = 0;
private class IconPanel extends JPanel {
@@ -424,7 +424,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
private void nextFrame() {
int newframe = frame == timelined.getTimeline().frames.size() - 1 ? 0 : frame + 1;
if(stillFrame){
if (stillFrame) {
newframe = frame;
}
if (newframe != frame) {
@@ -433,15 +433,15 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
}
frame = newframe;
updatePos(lastMouseEvent);
time = 0;
}else{
time = 0;
} else {
time++;
}
drawFrame();
}
private static SerializableImage getFrame(SWF swf, int frame,int time, Timelined drawable, DepthState stateUnderCursor, int mouseButton) {
String key = "drawable_" + frame + "_" + drawable.hashCode() + "_" + mouseButton + "_" + (stateUnderCursor == null ? "out" : stateUnderCursor.hashCode())+"_"+time;
private static SerializableImage getFrame(SWF swf, int frame, int time, Timelined drawable, DepthState stateUnderCursor, int mouseButton) {
String key = "drawable_" + frame + "_" + drawable.hashCode() + "_" + mouseButton + "_" + (stateUnderCursor == null ? "out" : stateUnderCursor.hashCode()) + "_" + time;
SerializableImage img = SWF.getFromCache(key);
if (img == null) {
if (drawable instanceof BoundedTag) {
@@ -491,8 +491,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
Matrix mat = new Matrix();
mat.translateX = swf.displayRect.Xmin;
mat.translateY = swf.displayRect.Ymin;
BufferedImage img = getFrame(swf, frame,time, timelined, stateUnderCursor, mouseButton).getBufferedImage();
List<Integer> sounds = timelined.getTimeline().getSounds(frame,time, stateUnderCursor, mouseButton);
BufferedImage img = getFrame(swf, frame, time, timelined, stateUnderCursor, mouseButton).getBufferedImage();
List<Integer> sounds = timelined.getTimeline().getSounds(frame, time, stateUnderCursor, mouseButton);
for (int sndId : sounds) {
CharacterTag c = swf.characters.get(sndId);
if (c instanceof SoundTag) {
@@ -543,7 +543,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
@Override
public void play() {
pause();
if (timelined!=null) {
if (timelined != null) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override

View File

@@ -284,10 +284,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
public TreeNode oldNode;
public TreeItem oldTag;
private File tempFile;
private PlayerControls imagePlayControls;
private final PlayerControls imagePlayControls;
private JPanel repPanel;
private JPanel repPanel2;
private final JPanel repPanel;
private final JPanel repPanel2;
private SoundTagPlayer soundThread = null;
@@ -977,8 +977,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
public void load(SWFList newSwfs, boolean first) {
swfPreviewPanel.stop();
imagePanel.stop();
stopImagePanels();
swfs.add(newSwfs);
@@ -1109,6 +1108,12 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
refreshTree();
}
private void stopImagePanels() {
imagePanel.stop();
previewImagePanel.stop();
swfPreviewPanel.stop();
}
public void enableDrop(boolean value) {
if (value) {
setDropTarget(new DropTarget() {
@@ -2170,8 +2175,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
}
public void refreshTree() {
swfPreviewPanel.stop();
imagePanel.stop();
stopImagePanels();
showCard(CARDEMPTYPANEL);
View.refreshTree(tagTree, new TagTreeModel(mainFrame, swfs));
setTreeItem(oldTag);
@@ -2546,8 +2550,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
if (flashPanel != null) {
flashPanel.specialPlayback = false;
}
swfPreviewPanel.stop();
imagePanel.stop();
stopImagePanels();
if (soundThread != null) {
soundThread.pause();
}
@@ -2697,11 +2700,12 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
int totalFrameCount = swf.frameCount;
Timelined timelined = swf;
if (fn.getParent() instanceof DefineSpriteTag) {
controlTags = ((DefineSpriteTag) fn.getParent()).subTags;
containerId = ((DefineSpriteTag) fn.getParent()).spriteId;
rect = ((DefineSpriteTag) fn.getParent()).getRect();
totalFrameCount = ((DefineSpriteTag) fn.getParent()).frameCount;
timelined = ((DefineSpriteTag) fn.getParent());
DefineSpriteTag parentSprite = (DefineSpriteTag) fn.getParent();
controlTags = parentSprite.subTags;
containerId = parentSprite.spriteId;
rect = parentSprite.getRect();
totalFrameCount = parentSprite.frameCount;
timelined = parentSprite;
}
previewImagePanel.setTimelined(timelined, swf, fn.getFrame() - 1);
} else if (((tagObj instanceof SoundTag) && mainMenu.isInternalFlashViewerSelected() && (Arrays.asList("mp3", "wav").contains(((SoundTag) tagObj).getExportFormat())))) {

View File

@@ -36,12 +36,12 @@ import javax.sound.sampled.UnsupportedAudioFileException;
*/
public class SoundTagPlayer implements MediaDisplay {
private SoundPlayer player;
private final SoundPlayer player;
private Thread thr;
private int actualPos = 0;
private SoundTag tag;
private List<PlayerListener> listeners = new ArrayList<>();
private final SoundTag tag;
private final List<PlayerListener> listeners = new ArrayList<>();
public void addListener(PlayerListener l) {
listeners.add(l);
@@ -61,7 +61,7 @@ public class SoundTagPlayer implements MediaDisplay {
private int loops;
private boolean paused = true;
private Object myLock = new Object();
private final Object myLock = new Object();
private final Object playLock = new Object();
public SoundTagPlayer(SoundTag tag, int loops) throws LineUnavailableException, IOException, UnsupportedAudioFileException {

View File

@@ -18,7 +18,6 @@ package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.gui.treenodes.StringNode;
import com.jpexs.decompiler.flash.gui.treenodes.TagTreeRoot;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag;
@@ -99,18 +98,18 @@ public class TagTree extends JTree {
if (type == TreeNodeType.FOLDER && expanded) {
type = TreeNodeType.FOLDER_OPEN;
}
String itemName=type.toString();
if(type == TreeNodeType.FOLDER || type==TreeNodeType.FOLDER_OPEN){
if(val instanceof StringItem){
StringItem si=(StringItem)val;
if(!TagTreeRoot.FOLDER_ROOT.equals(si.getName())){
itemName="folder"+si.getName();
String itemName = type.toString();
if (type == TreeNodeType.FOLDER || type == TreeNodeType.FOLDER_OPEN) {
if (val instanceof StringItem) {
StringItem si = (StringItem) val;
if (!TagTreeRoot.FOLDER_ROOT.equals(si.getName())) {
itemName = "folder" + si.getName();
}
}
}
String tagTypeStr = itemName.toLowerCase().replace("_", "");
setIcon(View.getIcon(tagTypeStr + "16"));
}
}
Font font = getFont();
boolean isModified = false;
@@ -245,42 +244,41 @@ public class TagTree extends JTree {
if (t instanceof Tag) {
return TreeNodeType.OTHER_TAG;
}
/*if(t instanceof StringNode){
StringNode sn=(StringNode)t;
String name = sn.getItem().getName();
if(name!=null){
switch(name){
case TagTreeModel.FOLDER_BINARY_DATA:
break;
case TagTreeModel.FOLDER_BUTTONS:
break;
case TagTreeModel.FOLDER_FONTS:
break;
case TagTreeModel.FOLDER_FRAMES:
break;
case TagTreeModel.FOLDER_IMAGES:
break;
case TagTreeModel.FOLDER_MORPHSHAPES:
break;
case TagTreeModel.FOLDER_MOVIES:
break;
case TagTreeModel.FOLDER_OTHERS:
break;
case TagTreeModel.FOLDER_SCRIPTS:
break;
case TagTreeModel.FOLDER_SHAPES:
break;
case TagTreeModel.FOLDER_SOUNDS:
break;
case TagTreeModel.FOLDER_SPRITES:
break;
case TagTreeModel.FOLDER_TEXTS:
break;
}
}
}*/
/*if(t instanceof StringNode){
StringNode sn=(StringNode)t;
String name = sn.getItem().getName();
if(name!=null){
switch(name){
case TagTreeModel.FOLDER_BINARY_DATA:
break;
case TagTreeModel.FOLDER_BUTTONS:
break;
case TagTreeModel.FOLDER_FONTS:
break;
case TagTreeModel.FOLDER_FRAMES:
break;
case TagTreeModel.FOLDER_IMAGES:
break;
case TagTreeModel.FOLDER_MORPHSHAPES:
break;
case TagTreeModel.FOLDER_MOVIES:
break;
case TagTreeModel.FOLDER_OTHERS:
break;
case TagTreeModel.FOLDER_SCRIPTS:
break;
case TagTreeModel.FOLDER_SHAPES:
break;
case TagTreeModel.FOLDER_SOUNDS:
break;
case TagTreeModel.FOLDER_SPRITES:
break;
case TagTreeModel.FOLDER_TEXTS:
break;
}
}
}*/
return TreeNodeType.FOLDER;
}

View File

@@ -26,7 +26,7 @@ import com.jpexs.decompiler.flash.treenodes.TreeNode;
public class TagTreeRoot extends TreeNode {
public static final String FOLDER_ROOT = "root";
public TagTreeRoot() {
super(new StringItem("root", FOLDER_ROOT, null));
}

View File

@@ -269,7 +269,7 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT
@Override
public void toImage(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, SerializableImage image, Matrix transformation, ColorTransform colorTransform) {
SWF.frameToImage(getTimeline(), frame,time, stateUnderCursor, mouseButton, image, transformation, colorTransform);
SWF.frameToImage(getTimeline(), frame, time, stateUnderCursor, mouseButton, image, transformation, colorTransform);
}
@Override
@@ -284,6 +284,6 @@ public class DefineSpriteTag extends CharacterTag implements Container, BoundedT
@Override
public Shape getOutline(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, Matrix transformation) {
return getTimeline().getOutline(frame,time, ratio, stateUnderCursor, mouseButton, transformation);
return getTimeline().getOutline(frame, time, ratio, stateUnderCursor, mouseButton, transformation);
}
}

View File

@@ -46,6 +46,7 @@ public abstract class ShapeTag extends CharacterTag implements BoundedTag, Drawa
return transformation.toTransform().createTransformedShape(getShapes().getOutline());
}
@Override
public void toImage(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, SerializableImage image, Matrix transformation, ColorTransform colorTransform) {
BitmapExporter.exportTo(swf, getShapes(), null, image, transformation, colorTransform);
}

View File

@@ -25,6 +25,7 @@ import java.util.List;
*/
public interface SoundStreamHeadTypeTag extends SoundTag {
@Override
public boolean getSoundSize();
public long getSoundSampleCount();

View File

@@ -17,16 +17,11 @@
package com.jpexs.decompiler.flash.timeline;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.exporters.Matrix;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.DrawableTag;
import com.jpexs.decompiler.flash.types.CLIPACTIONS;
import com.jpexs.decompiler.flash.types.ColorTransform;
import com.jpexs.decompiler.flash.types.MATRIX;
import com.jpexs.decompiler.flash.types.RGBA;
import com.jpexs.decompiler.flash.types.filters.FILTER;
import com.jpexs.helpers.SerializableImage;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

View File

@@ -179,7 +179,7 @@ public class Timeline {
}
public List<Integer> getSounds(int frame,int time, DepthState stateUnderCursor, int mouseButton) {
public List<Integer> getSounds(int frame, int time, DepthState stateUnderCursor, int mouseButton) {
List<Integer> ret = new ArrayList<>();
Frame fr = this.frames.get(frame);
ret.addAll(fr.sounds);
@@ -188,7 +188,7 @@ public class Timeline {
if (ds != null) {
CharacterTag c = swf.characters.get(ds.characterId);
if (c instanceof Timelined) {
int dframe = (time+ds.time) % ((Timelined) c).getTimeline().frames.size();
int dframe = (time + ds.time) % ((Timelined) c).getTimeline().frames.size();
if (c instanceof ButtonTag) {
ButtonTag bt = (ButtonTag) c;
dframe = ButtonTag.FRAME_UP;
@@ -200,7 +200,7 @@ public class Timeline {
}
}
}
ret.addAll(((Timelined) c).getTimeline().getSounds(dframe,time+ds.time, stateUnderCursor, mouseButton));
ret.addAll(((Timelined) c).getTimeline().getSounds(dframe, time + ds.time, stateUnderCursor, mouseButton));
}
}
}
@@ -248,7 +248,7 @@ public class Timeline {
}
}
}
Shape cshape = ((DrawableTag) c).getOutline(dframe, ds.time+time, ds.ratio, stateUnderCursor, mouseButton, m);
Shape cshape = ((DrawableTag) c).getOutline(dframe, ds.time + time, ds.ratio, stateUnderCursor, mouseButton, m);
Area addArea = new Area(cshape);
if (currentClip != null) {
@@ -264,7 +264,7 @@ public class Timeline {
outlines.add(addArea);
}
if (c instanceof Timelined) {
((Timelined) c).getTimeline().getObjectsOutlines(dframe,time+ds.time,ds.ratio, stateUnderCursor, mouseButton, m, objs, outlines);
((Timelined) c).getTimeline().getObjectsOutlines(dframe, time + ds.time, ds.ratio, stateUnderCursor, mouseButton, m, objs, outlines);
}
}
}
@@ -299,7 +299,7 @@ public class Timeline {
int dframe = 0;
if (c instanceof Timelined) {
dframe = (time+ds.time) % ((Timelined) c).getTimeline().frames.size();
dframe = (time + ds.time) % ((Timelined) c).getTimeline().frames.size();
if (c instanceof ButtonTag) {
ButtonTag bt = (ButtonTag) c;
dframe = ButtonTag.FRAME_UP;
@@ -312,7 +312,7 @@ public class Timeline {
}
}
}
Shape cshape = ((DrawableTag) c).getOutline(dframe, time+ds.time,ds.ratio, stateUnderCursor, mouseButton, m);
Shape cshape = ((DrawableTag) c).getOutline(dframe, time + ds.time, ds.ratio, stateUnderCursor, mouseButton, m);
Area addArea = new Area(cshape);
if (currentClip != null) {

View File

@@ -33,7 +33,7 @@ import javax.sound.sampled.UnsupportedAudioFileException;
*/
public class SoundPlayer {
private Clip clip;
private final Clip clip;
public SoundPlayer(InputStream is) throws LineUnavailableException, IOException, UnsupportedAudioFileException {
clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));