/*
* Copyright (C) 2010-2013 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler;
import com.jpexs.decompiler.flash.ApplicationInfo;
import com.jpexs.decompiler.flash.FrameNode;
import com.jpexs.decompiler.flash.PackageNode;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.TagNode;
import com.jpexs.decompiler.flash.TreeElementItem;
import com.jpexs.decompiler.flash.TreeNode;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.RenameType;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.abc.ABCPanel;
import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel;
import com.jpexs.decompiler.flash.gui.abc.DeobfuscationDialog;
import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane;
import com.jpexs.decompiler.flash.gui.abc.TreeElement;
import com.jpexs.decompiler.flash.gui.action.ActionPanel;
import com.jpexs.decompiler.flash.gui.player.FlashPlayerPanel;
import com.jpexs.decompiler.flash.gui.player.PlayerControls;
import com.jpexs.decompiler.flash.helpers.Freed;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag;
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag;
import com.jpexs.decompiler.flash.tags.DefineBitsJPEG4Tag;
import com.jpexs.decompiler.flash.tags.DefineBitsLossless2Tag;
import com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag;
import com.jpexs.decompiler.flash.tags.DefineBitsTag;
import com.jpexs.decompiler.flash.tags.DefineButton2Tag;
import com.jpexs.decompiler.flash.tags.DefineButtonTag;
import com.jpexs.decompiler.flash.tags.DefineEditTextTag;
import com.jpexs.decompiler.flash.tags.DefineFont2Tag;
import com.jpexs.decompiler.flash.tags.DefineFont3Tag;
import com.jpexs.decompiler.flash.tags.DefineFont4Tag;
import com.jpexs.decompiler.flash.tags.DefineFontTag;
import com.jpexs.decompiler.flash.tags.DefineMorphShape2Tag;
import com.jpexs.decompiler.flash.tags.DefineMorphShapeTag;
import com.jpexs.decompiler.flash.tags.DefineShape2Tag;
import com.jpexs.decompiler.flash.tags.DefineShape3Tag;
import com.jpexs.decompiler.flash.tags.DefineShape4Tag;
import com.jpexs.decompiler.flash.tags.DefineShapeTag;
import com.jpexs.decompiler.flash.tags.DefineSoundTag;
import com.jpexs.decompiler.flash.tags.DefineSpriteTag;
import com.jpexs.decompiler.flash.tags.DefineText2Tag;
import com.jpexs.decompiler.flash.tags.DefineTextTag;
import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag;
import com.jpexs.decompiler.flash.tags.DoActionTag;
import com.jpexs.decompiler.flash.tags.EndTag;
import com.jpexs.decompiler.flash.tags.ExportAssetsTag;
import com.jpexs.decompiler.flash.tags.JPEGTablesTag;
import com.jpexs.decompiler.flash.tags.PlaceObject2Tag;
import com.jpexs.decompiler.flash.tags.SetBackgroundColorTag;
import com.jpexs.decompiler.flash.tags.ShowFrameTag;
import com.jpexs.decompiler.flash.tags.SoundStreamBlockTag;
import com.jpexs.decompiler.flash.tags.SoundStreamHead2Tag;
import com.jpexs.decompiler.flash.tags.SoundStreamHeadTag;
import com.jpexs.decompiler.flash.tags.SymbolClassTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.VideoFrameTag;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.flash.tags.base.AloneTag;
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.Container;
import com.jpexs.decompiler.flash.tags.base.ContainerItem;
import com.jpexs.decompiler.flash.tags.base.DrawableTag;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag;
import com.jpexs.decompiler.flash.tags.base.SoundStreamHeadTypeTag;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.tags.gfx.DefineCompactedFont;
import com.jpexs.decompiler.flash.tags.text.ParseException;
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
import com.jpexs.decompiler.flash.types.MATRIX;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.RGB;
import com.jpexs.decompiler.flash.types.TEXTRECORD;
import com.jpexs.decompiler.graph.ExportMode;
import com.jpexs.helpers.CancellableWorker;
import com.jpexs.helpers.Helper;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.plaf.basic.BasicLabelUI;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
/**
*
* @author JPEXS
*/
public final class MainPanel extends JPanel implements ActionListener, TreeSelectionListener, Freed {
private MainFrame mainFrame;
private List swfs;
private ABCPanel abcPanel;
private ActionPanel actionPanel;
private JPanel welcomePanel;
private MainFrameStatusPanel statusPanel;
private MainFrameMenu mainMenu;
private FontPanel fontPanel;
private JProgressBar progressBar = new JProgressBar(0, 100);
private DeobfuscationDialog deobfuscationDialog;
public JTree tagTree;
private FlashPlayerPanel flashPanel;
private JPanel contentPanel;
private JPanel displayPanel;
private ImagePanel imagePanel;
private BinaryPanel binaryPanel;
private ImagePanel previewImagePanel;
private SWFPreviwPanel swfPreviewPanel;
private boolean isWelcomeScreen = true;
private static final String CARDFLASHPANEL = "Flash card";
private static final String CARDSWFPREVIEWPANEL = "SWF card";
private static final String CARDDRAWPREVIEWPANEL = "Draw card";
private static final String CARDIMAGEPANEL = "Image card";
private static final String CARDBINARYPANEL = "Binary card";
private static final String CARDEMPTYPANEL = "Empty card";
private static final String CARDACTIONSCRIPTPANEL = "ActionScript card";
private static final String CARDACTIONSCRIPT3PANEL = "ActionScript3 card";
private static final String DETAILCARDAS3NAVIGATOR = "Traits list";
private static final String DETAILCARDEMPTYPANEL = "Empty card";
private static final String CARDTEXTPANEL = "Text card";
private static final String CARDFONTPANEL = "Font card";
private static final String FLASH_VIEWER_CARD = "FLASHVIEWER";
private static final String INTERNAL_VIEWER_CARD = "INTERNALVIEWER";
private static final String SPLIT_PANE1 = "SPLITPANE1";
private static final String WELCOME_PANEL = "WELCOMEPANEL";
private LineMarkedEditorPane textValue;
private JSplitPane splitPane1;
private JSplitPane splitPane2;
private boolean splitsInited = false;
private JPanel detailPanel;
private JTextField filterField = new MyTextField("");
private JPanel searchPanel;
private JPanel displayWithPreview;
private JButton textSaveButton;
private JButton textEditButton;
private JButton textCancelButton;
private JPanel parametersPanel;
private JSplitPane previewSplitPane;
private JButton imageReplaceButton;
private JPanel imageButtonsPanel;
private JButton binaryReplaceButton;
private JPanel binaryButtonsPanel;
private PlayerControls flashControls;
private ImagePanel internelViewerPanel;
private JPanel viewerCards;
private AbortRetryIgnoreHandler errorHandler = new GuiAbortRetryIgnoreHandler();
private CancellableWorker setSourceWorker;
public TreeNode oldNode;
public TreeElementItem oldTag;
private File tempFile;
private static final String ACTION_SELECT_COLOR = "SELECTCOLOR";
private static final String ACTION_REPLACE_IMAGE = "REPLACEIMAGE";
private static final String ACTION_REPLACE_BINARY = "REPLACEBINARY";
private static final String ACTION_REMOVE_ITEM = "REMOVEITEM";
private static final String ACTION_EDIT_TEXT = "EDITTEXT";
private static final String ACTION_CANCEL_TEXT = "CANCELTEXT";
private static final String ACTION_SAVE_TEXT = "SAVETEXT";
private static final String ACTION_CLOSE_SWF = "CLOSESWF";
public void setPercent(int percent) {
progressBar.setValue(percent);
progressBar.setVisible(true);
}
public void hidePercent() {
if (progressBar.isVisible()) {
progressBar.setVisible(false);
}
}
static {
try {
File.createTempFile("temp", ".swf").delete(); //First call to this is slow, so make it first
} catch (IOException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static void addTab(JTabbedPane tabbedPane, Component tab, String title, Icon icon) {
tabbedPane.add(tab);
JLabel lbl = new JLabel(title);
lbl.setIcon(icon);
lbl.setIconTextGap(5);
lbl.setHorizontalTextPosition(SwingConstants.RIGHT);
tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1, lbl);
}
public void setStatus(String s) {
statusPanel.setStatus(s);
}
public void setWorkStatus(String s, CancellableWorker worker) {
statusPanel.setWorkStatus(s, worker);
}
private void createContextMenu() {
final JPopupMenu contextPopupMenu = new JPopupMenu();
final JMenuItem removeMenuItem = new JMenuItem(translate("contextmenu.remove"));
removeMenuItem.addActionListener(this);
removeMenuItem.setActionCommand(ACTION_REMOVE_ITEM);
final JMenuItem exportSelectionMenuItem = new JMenuItem(translate("menu.file.export.selection"));
exportSelectionMenuItem.setActionCommand(MainFrameRibbonMenu.ACTION_EXPORT_SEL);
exportSelectionMenuItem.addActionListener(this);
contextPopupMenu.add(exportSelectionMenuItem);
final JMenuItem replaceImageSelectionMenuItem = new JMenuItem(translate("button.replace"));
replaceImageSelectionMenuItem.setActionCommand(ACTION_REPLACE_IMAGE);
replaceImageSelectionMenuItem.addActionListener(this);
contextPopupMenu.add(replaceImageSelectionMenuItem);
final JMenuItem replaceBinarySelectionMenuItem = new JMenuItem(translate("button.replace"));
replaceBinarySelectionMenuItem.setActionCommand(ACTION_REPLACE_BINARY);
replaceBinarySelectionMenuItem.addActionListener(this);
contextPopupMenu.add(replaceBinarySelectionMenuItem);
final JMenuItem closeSelectionMenuItem = new JMenuItem(translate("contextmenu.closeSwf"));
closeSelectionMenuItem.setActionCommand(ACTION_CLOSE_SWF);
closeSelectionMenuItem.addActionListener(this);
contextPopupMenu.add(closeSelectionMenuItem);
contextPopupMenu.add(removeMenuItem);
tagTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
int row = tagTree.getClosestRowForLocation(e.getX(), e.getY());
int[] selectionRows = tagTree.getSelectionRows();
if (!Helper.contains(selectionRows, row)) {
tagTree.setSelectionRow(row);
}
TreePath[] paths = tagTree.getSelectionPaths();
if (paths == null || paths.length == 0) {
return;
}
boolean allSelectedIsTag = true;
for (TreePath treePath : paths) {
Object tagObj = treePath.getLastPathComponent();
if (tagObj instanceof TagNode) {
Object tag = ((TagNode) tagObj).tag;
if (!(tag instanceof Tag)) {
allSelectedIsTag = false;
break;
}
} else {
allSelectedIsTag = false;
}
}
replaceImageSelectionMenuItem.setVisible(false);
replaceBinarySelectionMenuItem.setVisible(false);
closeSelectionMenuItem.setVisible(false);
if (paths.length == 1) {
Object tagObj = paths[0].getLastPathComponent();
if (tagObj instanceof TagNode) {
Object tag = ((TagNode) tagObj).tag;
if (tag instanceof ImageTag && ((ImageTag) tag).importSupported()) {
replaceImageSelectionMenuItem.setVisible(true);
}
if (tag instanceof DefineBinaryDataTag) {
replaceBinarySelectionMenuItem.setVisible(true);
}
}
if (tagObj instanceof SWFRoot) {
closeSelectionMenuItem.setVisible(true);
}
}
removeMenuItem.setVisible(allSelectedIsTag);
contextPopupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
});
}
private JPanel createWelcomePanel() {
JPanel welcomePanel = new JPanel();
welcomePanel.setLayout(new BoxLayout(welcomePanel, BoxLayout.Y_AXIS));
JLabel welcomeToLabel = new JLabel(translate("startup.welcometo"));
welcomeToLabel.setFont(welcomeToLabel.getFont().deriveFont(40));
welcomeToLabel.setAlignmentX(0.5f);
JPanel appNamePanel = new JPanel(new FlowLayout());
JLabel jpLabel = new JLabel("JPEXS ");
jpLabel.setAlignmentX(0.5f);
jpLabel.setForeground(new Color(0, 0, 160));
jpLabel.setFont(new Font("Tahoma", Font.BOLD, 50));
jpLabel.setHorizontalAlignment(SwingConstants.CENTER);
appNamePanel.add(jpLabel);
JLabel ffLabel = new JLabel("Free Flash ");
ffLabel.setAlignmentX(0.5f);
ffLabel.setFont(new Font("Tahoma", Font.BOLD, 50));
ffLabel.setHorizontalAlignment(SwingConstants.CENTER);
appNamePanel.add(ffLabel);
JLabel decLabel = new JLabel("Decompiler");
decLabel.setAlignmentX(0.5f);
decLabel.setForeground(Color.red);
decLabel.setFont(new Font("Tahoma", Font.BOLD, 50));
decLabel.setHorizontalAlignment(SwingConstants.CENTER);
appNamePanel.add(decLabel);
appNamePanel.setAlignmentX(0.5f);
welcomePanel.add(Box.createGlue());
welcomePanel.add(welcomeToLabel);
welcomePanel.add(appNamePanel);
JLabel startLabel = new JLabel(translate("startup.selectopen"));
startLabel.setAlignmentX(0.5f);
startLabel.setFont(startLabel.getFont().deriveFont(30));
welcomePanel.add(startLabel);
welcomePanel.add(Box.createGlue());
return welcomePanel;
}
private JPanel createImagesCard() {
JPanel imagesCard = new JPanel(new BorderLayout());
imagePanel = new ImagePanel();
imagesCard.add(imagePanel, BorderLayout.CENTER);
imageReplaceButton = new JButton(translate("button.replace"), View.getIcon("edit16"));
imageReplaceButton.setMargin(new Insets(3, 3, 3, 10));
imageReplaceButton.setActionCommand(ACTION_REPLACE_IMAGE);
imageReplaceButton.addActionListener(this);
imageButtonsPanel = new JPanel(new FlowLayout());
imageButtonsPanel.add(imageReplaceButton);
imagesCard.add(imageButtonsPanel, BorderLayout.SOUTH);
return imagesCard;
}
private JPanel createBinaryCard() {
JPanel binaryCard = new JPanel(new BorderLayout());
binaryPanel = new BinaryPanel();
binaryCard.add(binaryPanel, BorderLayout.CENTER);
binaryReplaceButton = new JButton(translate("button.replace"), View.getIcon("edit16"));
binaryReplaceButton.setMargin(new Insets(3, 3, 3, 10));
binaryReplaceButton.setActionCommand(ACTION_REPLACE_BINARY);
binaryReplaceButton.addActionListener(this);
binaryButtonsPanel = new JPanel(new FlowLayout());
binaryButtonsPanel.add(binaryReplaceButton);
binaryCard.add(binaryButtonsPanel, BorderLayout.SOUTH);
return binaryCard;
}
private void showHideImageReplaceButton(boolean show) {
imageReplaceButton.setVisible(show);
setImageButtonPanelVisibility();
}
private void setImageButtonPanelVisibility() {
// hide button panel when no button is visible
// now there is only one button, later add here the other buttons
boolean visible = imageReplaceButton.isVisible();
imageButtonsPanel.setVisible(visible);
}
public String translate(String key) {
return mainFrame.translate(key);
}
public MainPanel(MainFrame mainFrame, MainFrameMenu mainMenu, FlashPlayerPanel flashPanel) {
super();
this.mainFrame = mainFrame;
this.mainMenu = mainMenu;
this.flashPanel = flashPanel;
mainFrame.setTitle(ApplicationInfo.applicationVerName);
setLayout(new BorderLayout());
swfs = new ArrayList<>();
detailPanel = new JPanel();
detailPanel.setLayout(new CardLayout());
JPanel whitePanel = new JPanel();
whitePanel.setBackground(Color.white);
detailPanel.add(whitePanel, DETAILCARDEMPTYPANEL);
CardLayout cl2 = (CardLayout) (detailPanel.getLayout());
cl2.show(detailPanel, DETAILCARDEMPTYPANEL);
UIManager.getDefaults().put("TreeUI", BasicTreeUI.class.getName());
tagTree = new JTree((TreeModel) null);
tagTree.setRootVisible(false);
tagTree.addTreeSelectionListener(this);
tagTree.setBackground(Color.white);
tagTree.setUI(new BasicTreeUI() {
@Override
public void paint(Graphics g, JComponent c) {
setHashColor(Color.gray);
super.paint(g, c);
}
});
DragSource dragSource = DragSource.getDefaultDragSource();
dragSource.createDefaultDragGestureRecognizer(tagTree, DnDConstants.ACTION_COPY_OR_MOVE, new DragGestureListener() {
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
dge.startDrag(DragSource.DefaultCopyDrop, new Transferable() {
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{DataFlavor.javaFileListFlavor};
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor.equals(DataFlavor.javaFileListFlavor);
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(DataFlavor.javaFileListFlavor)) {
List files = new ArrayList<>();
String tempDir = System.getProperty("java.io.tmpdir");
if (!tempDir.endsWith(File.separator)) {
tempDir += File.separator;
}
Random rnd = new Random();
tempDir += "ffdec" + File.separator + "export" + File.separator + System.currentTimeMillis() + "_" + rnd.nextInt(1000);
File fTempDir = new File(tempDir);
if (!fTempDir.exists()) {
if (!fTempDir.mkdirs()) {
if (!fTempDir.exists()) {
throw new IOException("cannot create directory " + fTempDir);
}
}
}
final ExportDialog export = new ExportDialog();
try {
File ftemp = new File(tempDir);
files = exportSelection(errorHandler, tempDir, export);
files.clear();
File[] fs = ftemp.listFiles();
files.addAll(Arrays.asList(fs));
Main.stopWork();
} catch (IOException ex) {
return null;
}
for (File f : files) {
f.deleteOnExit();
}
new File(tempDir).deleteOnExit();
return files;
}
return null;
}
}, new DragSourceListener() {
@Override
public void dragEnter(DragSourceDragEvent dsde) {
enableDrop(false);
}
@Override
public void dragOver(DragSourceDragEvent dsde) {
}
@Override
public void dropActionChanged(DragSourceDragEvent dsde) {
}
@Override
public void dragExit(DragSourceEvent dse) {
}
@Override
public void dragDropEnd(DragSourceDropEvent dsde) {
enableDrop(true);
}
});
}
});
createContextMenu();
TreeCellRenderer tcr = new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
Object val = value;
if (val instanceof TagNode) {
val = ((TagNode) val).tag;
}
TagType type = getTagType(val);
if (val instanceof SWFRoot) {
setIcon(View.getIcon("flash16"));
} else if (type != null) {
if (type == TagType.FOLDER && expanded) {
type = TagType.FOLDER_OPEN;
}
String tagTypeStr = type.toString().toLowerCase().replace("_", "");
setIcon(View.getIcon(tagTypeStr + "16"));
//setToolTipText("This book is in the Tutorial series.");
} else {
//setToolTipText(null); //no tool tip
}
String tos = value.toString();
int sw = getFontMetrics(getFont()).stringWidth(tos);
setPreferredSize(new Dimension(18 + sw, getPreferredSize().height));
setUI(new BasicLabelUI());
setOpaque(false);
//setBackground(Color.green);
setBackgroundNonSelectionColor(Color.white);
//setBackgroundSelectionColor(Color.ORANGE);
return this;
}
};
tagTree.setCellRenderer(tcr);
statusPanel = new MainFrameStatusPanel(this);
add(statusPanel, BorderLayout.SOUTH);
JPanel textTopPanel = new JPanel(new BorderLayout());
textValue = new LineMarkedEditorPane();
textTopPanel.add(new JScrollPane(textValue), BorderLayout.CENTER);
textValue.setEditable(false);
//textValue.setFont(UIManager.getFont("TextField.font"));
JPanel textButtonsPanel = new JPanel();
textButtonsPanel.setLayout(new FlowLayout());
textSaveButton = new JButton(translate("button.save"), View.getIcon("save16"));
textSaveButton.setMargin(new Insets(3, 3, 3, 10));
textSaveButton.setActionCommand(ACTION_SAVE_TEXT);
textSaveButton.addActionListener(this);
textEditButton = new JButton(translate("button.edit"), View.getIcon("edit16"));
textEditButton.setMargin(new Insets(3, 3, 3, 10));
textEditButton.setActionCommand(ACTION_EDIT_TEXT);
textEditButton.addActionListener(this);
textCancelButton = new JButton(translate("button.cancel"), View.getIcon("cancel16"));
textCancelButton.setMargin(new Insets(3, 3, 3, 10));
textCancelButton.setActionCommand(ACTION_CANCEL_TEXT);
textCancelButton.addActionListener(this);
textButtonsPanel.add(textEditButton);
textButtonsPanel.add(textSaveButton);
textButtonsPanel.add(textCancelButton);
textSaveButton.setVisible(false);
textCancelButton.setVisible(false);
textTopPanel.add(textButtonsPanel, BorderLayout.SOUTH);
displayWithPreview = new JPanel(new CardLayout());
displayWithPreview.add(textTopPanel, CARDTEXTPANEL);
fontPanel = new FontPanel(this);
displayWithPreview.add(fontPanel, CARDFONTPANEL);
Component leftComponent;
displayPanel = new JPanel(new CardLayout());
if (flashPanel != null) {
JPanel flashPlayPanel = new JPanel(new BorderLayout());
flashPlayPanel.add(flashPanel, BorderLayout.CENTER);
flashPlayPanel.add(flashControls = new PlayerControls(flashPanel), BorderLayout.SOUTH);
leftComponent = flashPlayPanel;
} else {
JPanel swtPanel = new JPanel(new BorderLayout());
swtPanel.add(new JLabel("" + translate("notavailonthisplatform") + "", JLabel.CENTER), BorderLayout.CENTER);
swtPanel.setBackground(View.DEFAULT_BACKGROUND_COLOR);
leftComponent = swtPanel;
}
previewSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
previewSplitPane.setDividerLocation(300);
JPanel pan = new JPanel(new BorderLayout());
JLabel prevLabel = new HeaderLabel(translate("swfpreview"));
prevLabel.setHorizontalAlignment(SwingConstants.CENTER);
//prevLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
JLabel paramsLabel = new HeaderLabel(translate("parameters"));
paramsLabel.setHorizontalAlignment(SwingConstants.CENTER);
//paramsLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
pan.add(prevLabel, BorderLayout.NORTH);
viewerCards = new JPanel();
viewerCards.setLayout(new CardLayout());
//viewerCards.add(leftComponent,FLASH_VIEWER_CARD);
internelViewerPanel = new ImagePanel();
JPanel ivPanel = new JPanel(new BorderLayout());
ivPanel.add(new HeaderLabel(translate("swfpreview.internal")), BorderLayout.NORTH);
ivPanel.add(internelViewerPanel, BorderLayout.CENTER);
viewerCards.add(ivPanel, INTERNAL_VIEWER_CARD);
((CardLayout) viewerCards.getLayout()).show(viewerCards, FLASH_VIEWER_CARD);
if (flashPanel != null) {
JPanel bottomPanel = new JPanel(new BorderLayout());
JPanel buttonsPanel = new JPanel(new FlowLayout());
JButton selectColorButton = new JButton(View.getIcon("color16"));
selectColorButton.addActionListener(this);
selectColorButton.setActionCommand(ACTION_SELECT_COLOR);
selectColorButton.setToolTipText(AppStrings.translate("button.selectcolor.hint"));
buttonsPanel.add(selectColorButton);
bottomPanel.add(buttonsPanel, BorderLayout.EAST);
pan.add(bottomPanel, BorderLayout.SOUTH);
}
pan.add(leftComponent, BorderLayout.CENTER);
viewerCards.add(pan, FLASH_VIEWER_CARD);
previewSplitPane.setLeftComponent(viewerCards);
parametersPanel = new JPanel(new BorderLayout());
parametersPanel.add(paramsLabel, BorderLayout.NORTH);
parametersPanel.add(displayWithPreview, BorderLayout.CENTER);
previewSplitPane.setRightComponent(parametersPanel);
parametersPanel.setVisible(false);
displayPanel.add(previewSplitPane, CARDFLASHPANEL);
displayPanel.add(createImagesCard(), CARDIMAGEPANEL);
displayPanel.add(createBinaryCard(), CARDBINARYPANEL);
JPanel shapesCard = new JPanel(new BorderLayout());
JPanel previewPanel = new JPanel(new BorderLayout());
previewImagePanel = new ImagePanel();
JPanel previewCnt = new JPanel(new BorderLayout());
previewCnt.add(previewImagePanel, BorderLayout.CENTER);
previewCnt.add(new PlayerControls(previewImagePanel), BorderLayout.SOUTH);
previewPanel.add(previewCnt, BorderLayout.CENTER);
JLabel prevIntLabel = new HeaderLabel(translate("swfpreview.internal"));
prevIntLabel.setHorizontalAlignment(SwingConstants.CENTER);
//prevIntLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
previewPanel.add(prevIntLabel, BorderLayout.NORTH);
shapesCard.add(previewPanel, BorderLayout.CENTER);
displayPanel.add(shapesCard, CARDDRAWPREVIEWPANEL);
swfPreviewPanel = new SWFPreviwPanel();
displayPanel.add(swfPreviewPanel, CARDSWFPREVIEWPANEL);
displayPanel.add(new JPanel(), CARDEMPTYPANEL);
CardLayout cl = (CardLayout) (displayPanel.getLayout());
cl.show(displayPanel, CARDEMPTYPANEL);
searchPanel = new JPanel();
searchPanel.setLayout(new BorderLayout());
searchPanel.add(filterField, BorderLayout.CENTER);
searchPanel.add(new JLabel(View.getIcon("search16")), BorderLayout.WEST);
JLabel closeSearchButton = new JLabel(View.getIcon("cancel16"));
closeSearchButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
filterField.setText("");
doFilter();
searchPanel.setVisible(false);
}
});
searchPanel.add(closeSearchButton, BorderLayout.EAST);
JPanel pan1 = new JPanel(new BorderLayout());
pan1.add(new JScrollPane(tagTree), BorderLayout.CENTER);
pan1.add(searchPanel, BorderLayout.SOUTH);
filterField.addActionListener(this);
searchPanel.setVisible(false);
filterField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
warn();
}
@Override
public void removeUpdate(DocumentEvent e) {
warn();
}
@Override
public void insertUpdate(DocumentEvent e) {
warn();
}
public void warn() {
doFilter();
}
});
//displayPanel.setBorder(BorderFactory.createLineBorder(Color.black));
splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pan1, detailPanel);
splitPane1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitPane2, displayPanel);
welcomePanel = createWelcomePanel();
add(welcomePanel, BorderLayout.CENTER);
//splitPane1.setDividerLocation(0.5);
splitPane1.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent pce) {
if (splitsInited) {
Configuration.guiSplitPane1DividerLocation.set((int) pce.getNewValue());
}
}
});
splitPane2.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent pce) {
if (detailPanel.isVisible()) {
Configuration.guiSplitPane2DividerLocation.set((int) pce.getNewValue());
}
}
});
CardLayout cl3 = new CardLayout();
contentPanel = new JPanel(cl3);
contentPanel.add(welcomePanel, WELCOME_PANEL);
contentPanel.add(splitPane1, SPLIT_PANE1);
add(contentPanel);
cl3.show(contentPanel, WELCOME_PANEL);
tagTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if ((e.getKeyCode() == 'F') && (e.isControlDown())) {
searchPanel.setVisible(true);
filterField.requestFocusInWindow();
}
}
});
detailPanel.setVisible(false);
updateUi();
//Opening files with drag&drop to main window
enableDrop(true);
}
public void load(SWF swf, boolean first) {
List objs = new ArrayList<>();
objs.addAll(swf.tags);
ArrayList abcList = new ArrayList<>();
getActionScript3(objs, abcList);
swfs.add(swf);
swf.abcList = abcList;
tagTree.setModel(new TagTreeModel(mainFrame, swfs));
boolean hasAbc = !abcList.isEmpty();
if (hasAbc) {
if (abcPanel == null) {
abcPanel = new ABCPanel(this);
displayPanel.add(abcPanel, CARDACTIONSCRIPT3PANEL);
detailPanel.add(abcPanel.tabbedPane, DETAILCARDAS3NAVIGATOR);
}
abcPanel.setSwf(swf);
} else {
if (actionPanel == null) {
actionPanel = new ActionPanel(this);
displayPanel.add(actionPanel, CARDACTIONSCRIPTPANEL);
}
}
expandSwfRoots();
for (Tag t : swf.tags) {
if (t instanceof JPEGTablesTag) {
swf.jtt = (JPEGTablesTag) t;
}
}
List list2 = new ArrayList<>();
list2.addAll(swf.tags);
swf.characters = new HashMap<>();
parseCharacters(swf, list2);
if (Configuration.autoRenameIdentifiers.get()) {
try {
swf.deobfuscateIdentifiers(RenameType.TYPENUMBER);
swf.assignClassesToSymbols();
clearCache();
if (abcPanel != null) {
abcPanel.reload();
}
updateClassesList();
} catch (InterruptedException ex) {
Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
showDetail(DETAILCARDEMPTYPANEL);
showCard(CARDEMPTYPANEL);
updateUi(swf);
if (first && Configuration.gotoMainClassOnStartup.get()) {
gotoDocumentClass(swf);
}
}
private void updateUi(final SWF swf) {
mainFrame.setTitle(ApplicationInfo.applicationVerName + (Configuration.displayFileName.get() ? " - " + swf.getFileTitle() : ""));
List abcList = swf.abcList;
boolean hasAbc = !abcList.isEmpty();
if (hasAbc) {
abcPanel.setSwf(swf);
}
if (isWelcomeScreen) {
CardLayout cl = (CardLayout) (contentPanel.getLayout());
cl.show(contentPanel, SPLIT_PANE1);
isWelcomeScreen = false;
}
mainMenu.updateComponets(swf, abcList);
}
private void updateUi() {
if (!isWelcomeScreen) {
CardLayout cl = (CardLayout) (contentPanel.getLayout());
cl.show(contentPanel, WELCOME_PANEL);
isWelcomeScreen = true;
}
if (swfs.isEmpty()) {
mainMenu.updateComponets(null, null);
} else {
SWF swf = swfs.get(0);
updateUi(swf);
}
}
public void closeAll() {
swfs.clear();
oldNode = null;
oldTag = null;
if (abcPanel != null) {
abcPanel.clearSwf();
}
if (actionPanel != null) {
actionPanel.clearSource();
}
updateUi();
updateTagTree();
}
public void close(SWF swf) {
swfs.remove(swf);
if (abcPanel != null && abcPanel.swf == swf) {
abcPanel.clearSwf();
}
if (actionPanel != null) {
actionPanel.clearSource();
}
oldNode = null;
oldTag = null;
updateUi();
updateTagTree();
}
private void updateTagTree() {
tagTree.setModel(new TagTreeModel(mainFrame, swfs));
expandSwfRoots();
}
public void enableDrop(boolean value) {
if (value) {
setDropTarget(new DropTarget() {
@Override
public synchronized void drop(DropTargetDropEvent dtde) {
try {
dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
@SuppressWarnings("unchecked")
List droppedFiles = (List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
if (!droppedFiles.isEmpty()) {
String path = droppedFiles.get(0).getAbsolutePath();
Main.openFile(path, null);
}
} catch (UnsupportedFlavorException | IOException ex) {
}
}
});
} else {
setDropTarget(null);
}
}
public void updateClassesList() {
List nodes = getASTagNode(tagTree);
boolean updateNeeded = false;
for (TagNode n : nodes) {
if (n.tag instanceof ClassesListTreeModel) {
((ClassesListTreeModel) n.tag).update();
updateNeeded = true;
}
}
refreshTree();
if (updateNeeded) {
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
tagTree.updateUI();
}
});
}
}
public void doFilter() {
List nodes = getASTagNode(tagTree);
boolean updateNeeded = false;
for (TagNode n : nodes) {
if (n.tag instanceof ClassesListTreeModel) {
((ClassesListTreeModel) n.tag).setFilter(filterField.getText());
updateNeeded = true;
}
}
if (updateNeeded) {
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
tagTree.updateUI();
}
});
}
}
@Override
public void setVisible(boolean b) {
super.setVisible(b);
if (b) {
if (abcPanel != null) {
abcPanel.initSplits();
}
if (actionPanel != null) {
actionPanel.initSplits();
}
final MainPanel t = this;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
splitPane1.setDividerLocation(Configuration.guiSplitPane1DividerLocation.get(getWidth() / 3));
int confDivLoc = Configuration.guiSplitPane2DividerLocation.get(splitPane2.getHeight() * 3 / 5);
if (confDivLoc > splitPane2.getHeight() - 10) { //In older releases, divider location was saved when detailPanel was invisible too
confDivLoc = splitPane2.getHeight() * 3 / 5;
}
splitPane2.setDividerLocation(confDivLoc);
splitPos = splitPane2.getDividerLocation();
splitsInited = true;
}
});
}
}
private void parseCharacters(SWF swf, List list) {
for (ContainerItem t : list) {
if (t instanceof CharacterTag) {
swf.characters.put(((CharacterTag) t).getCharacterId(), (CharacterTag) t);
}
if (t instanceof Container) {
parseCharacters(swf, ((Container) t).getSubItems());
}
}
}
public static void getShapes(List list, List shapes) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getShapes(((Container) t).getSubItems(), shapes);
}
if ((t instanceof DefineShapeTag)
|| (t instanceof DefineShape2Tag)
|| (t instanceof DefineShape3Tag)
|| (t instanceof DefineShape4Tag)) {
shapes.add((Tag) t);
}
}
}
public static void getFonts(List list, List fonts) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getFonts(((Container) t).getSubItems(), fonts);
}
if ((t instanceof DefineFontTag)
|| (t instanceof DefineFont2Tag)
|| (t instanceof DefineFont3Tag)
|| (t instanceof DefineFont4Tag)) {
fonts.add((Tag) t);
}
}
}
public static void getActionScript3(List list, List actionScripts) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getActionScript3(((Container) t).getSubItems(), actionScripts);
}
if (t instanceof ABCContainerTag) {
actionScripts.add((ABCContainerTag) t);
}
}
}
public static void getMorphShapes(List list, List morphShapes) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getMorphShapes(((Container) t).getSubItems(), morphShapes);
}
if ((t instanceof DefineMorphShapeTag) || (t instanceof DefineMorphShape2Tag)) {
morphShapes.add((Tag) t);
}
}
}
public static void getImages(List list, List images) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getImages(((Container) t).getSubItems(), images);
}
if ((t instanceof DefineBitsTag)
|| (t instanceof DefineBitsJPEG2Tag)
|| (t instanceof DefineBitsJPEG3Tag)
|| (t instanceof DefineBitsJPEG4Tag)
|| (t instanceof DefineBitsLosslessTag)
|| (t instanceof DefineBitsLossless2Tag)) {
images.add((Tag) t);
}
}
}
public static void getTexts(List list, List texts) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getTexts(((Container) t).getSubItems(), texts);
}
if ((t instanceof DefineTextTag)
|| (t instanceof DefineText2Tag)
|| (t instanceof DefineEditTextTag)) {
texts.add((Tag) t);
}
}
}
public static void getSprites(List list, List sprites) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getSprites(((Container) t).getSubItems(), sprites);
}
if (t instanceof DefineSpriteTag) {
sprites.add((Tag) t);
}
}
}
public static void getButtons(List list, List buttons) {
for (ContainerItem t : list) {
if (t instanceof Container) {
getButtons(((Container) t).getSubItems(), buttons);
}
if ((t instanceof DefineButtonTag) || (t instanceof DefineButton2Tag)) {
buttons.add((Tag) t);
}
}
}
public List getSelectedNodes() {
List ret = new ArrayList<>();
TreePath[] tps = tagTree.getSelectionPaths();
if (tps == null) {
return ret;
}
for (TreePath tp : tps) {
TagNode te = (TagNode) tp.getLastPathComponent();
ret.add(te);
}
return ret;
}
public static TagType getTagType(Object t) {
if ((t instanceof DefineFontTag)
|| (t instanceof DefineFont2Tag)
|| (t instanceof DefineFont3Tag)
|| (t instanceof DefineFont4Tag)
|| (t instanceof DefineCompactedFont)) {
return TagType.FONT;
}
if ((t instanceof DefineTextTag)
|| (t instanceof DefineText2Tag)
|| (t instanceof DefineEditTextTag)) {
return TagType.TEXT;
}
if ((t instanceof DefineBitsTag)
|| (t instanceof DefineBitsJPEG2Tag)
|| (t instanceof DefineBitsJPEG3Tag)
|| (t instanceof DefineBitsJPEG4Tag)
|| (t instanceof DefineBitsLosslessTag)
|| (t instanceof DefineBitsLossless2Tag)) {
return TagType.IMAGE;
}
if ((t instanceof DefineShapeTag)
|| (t instanceof DefineShape2Tag)
|| (t instanceof DefineShape3Tag)
|| (t instanceof DefineShape4Tag)) {
return TagType.SHAPE;
}
if ((t instanceof DefineMorphShapeTag) || (t instanceof DefineMorphShape2Tag)) {
return TagType.MORPH_SHAPE;
}
if (t instanceof DefineSpriteTag) {
return TagType.SPRITE;
}
if ((t instanceof DefineButtonTag) || (t instanceof DefineButton2Tag)) {
return TagType.BUTTON;
}
if (t instanceof ASMSource) {
return TagType.AS;
}
if (t instanceof TreeElement) {
TreeElement te = (TreeElement) t;
if (te.getItem() instanceof ScriptPack) {
return TagType.AS;
} else {
return TagType.PACKAGE;
}
}
if (t instanceof PackageNode) {
return TagType.PACKAGE;
}
if (t instanceof FrameNode) {
return TagType.FRAME;
}
if (t instanceof ShowFrameTag) {
return TagType.SHOW_FRAME;
}
if (t instanceof DefineVideoStreamTag) {
return TagType.MOVIE;
}
if ((t instanceof DefineSoundTag) || (t instanceof SoundStreamHeadTag) || (t instanceof SoundStreamHead2Tag)) {
return TagType.SOUND;
}
if (t instanceof DefineBinaryDataTag) {
return TagType.BINARY_DATA;
}
return TagType.FOLDER;
}
public List