Saving files before refreshing line endings

This commit is contained in:
Jindra Petřík
2018-01-07 17:18:39 +01:00
parent cfb3931fcc
commit 0cb15e9c76
14 changed files with 7667 additions and 7667 deletions
File diff suppressed because it is too large Load Diff
@@ -1,386 +1,386 @@
/*
* Copyright (C) 2010-2016 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.BinaryDataExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ButtonExportMode;
import com.jpexs.decompiler.flash.exporters.modes.FontExportMode;
import com.jpexs.decompiler.flash.exporters.modes.FrameExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ImageExportMode;
import com.jpexs.decompiler.flash.exporters.modes.MorphShapeExportMode;
import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ShapeExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SpriteExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SymbolClassExportMode;
import com.jpexs.decompiler.flash.exporters.modes.TextExportMode;
import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineSpriteTag;
import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.flash.tags.base.ButtonTag;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.tags.base.MorphShapeTag;
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.tags.base.SymbolClassTypeTag;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.timeline.Frame;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.Arrays;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author JPEXS
*/
public class ExportDialog extends AppDialog {
private int result = ERROR_OPTION;
String[] optionNames = {
TagTreeModel.FOLDER_SHAPES,
TagTreeModel.FOLDER_TEXTS,
TagTreeModel.FOLDER_IMAGES,
TagTreeModel.FOLDER_MOVIES,
TagTreeModel.FOLDER_SOUNDS,
TagTreeModel.FOLDER_SCRIPTS,
TagTreeModel.FOLDER_BINARY_DATA,
TagTreeModel.FOLDER_FRAMES,
TagTreeModel.FOLDER_SPRITES,
TagTreeModel.FOLDER_BUTTONS,
TagTreeModel.FOLDER_FONTS,
TagTreeModel.FOLDER_MORPHSHAPES,
"symbolclass"
};
//Display options only when these classes found
Class[][] objClasses = {
{ShapeTag.class},
{TextTag.class},
{ImageTag.class},
{DefineVideoStreamTag.class},
{SoundTag.class},
{ASMSource.class, ScriptPack.class},
{DefineBinaryDataTag.class},
{Frame.class},
{Frame.class},
{ButtonTag.class},
{FontTag.class},
{MorphShapeTag.class},
{SymbolClassTypeTag.class},
};
//Enum classes for values
Class[] optionClasses = {
ShapeExportMode.class,
TextExportMode.class,
ImageExportMode.class,
MovieExportMode.class,
SoundExportMode.class,
ScriptExportMode.class,
BinaryDataExportMode.class,
FrameExportMode.class,
SpriteExportMode.class,
ButtonExportMode.class,
FontExportMode.class,
MorphShapeExportMode.class,
SymbolClassExportMode.class,
};
Class[] zoomClasses = {
ShapeExportMode.class,
MorphShapeExportMode.class,
TextExportMode.class,
FrameExportMode.class,
SpriteExportMode.class,
ButtonExportMode.class,
};
private final JComboBox[] combos;
private final JCheckBox[] checkBoxes;
private final JCheckBox selectAllCheckBox;
private JTextField zoomTextField = new JTextField();
public <E> E getValue(Class<E> option) {
for (int i = 0; i < optionClasses.length; i++) {
if (option == optionClasses[i]) {
E[] values = option.getEnumConstants();
return values[combos[i].getSelectedIndex()];
}
}
return null;
}
public boolean isOptionEnabled(Class<?> option) {
for (int i = 0; i < optionClasses.length; i++) {
if (option == optionClasses[i]) {
return checkBoxes[i].isSelected();
}
}
return false;
}
public double getZoom() {
return Double.parseDouble(zoomTextField.getText()) / 100;
}
private void saveConfig() {
StringBuilder cfg = new StringBuilder();
for (int i = 0; i < optionNames.length; i++) {
int selIndex = combos[i].getSelectedIndex();
Class c = optionClasses[i];
Object[] vals = c.getEnumConstants();
String key = optionNames[i] + "." + vals[selIndex].toString().toLowerCase();
if (i > 0) {
cfg.append(",");
}
cfg.append(key);
}
Configuration.lastSelectedExportZoom.set(Double.parseDouble(zoomTextField.getText()) / 100);
Configuration.lastSelectedExportFormats.set(cfg.toString());
}
private boolean optionCanHandle(int optionIndex, Object e) {
for (int i = 0; i < objClasses[optionIndex].length; i++) {
Class c = objClasses[optionIndex][i];
if (c.isInstance(e)) {
if (c == Frame.class) { //Frame class can be SWF frame or Sprite frame
Frame f = (Frame) e;
boolean isSprite = (f.timeline.timelined instanceof DefineSpriteTag);
boolean spritesWanted = optionClasses[optionIndex] == SpriteExportMode.class;
if (spritesWanted == isSprite) { //both true or both false
return true;
}
} else {
return true;
}
}
}
return false;
}
public ExportDialog(List<TreeItem> exportables) {
setTitle(translate("dialog.title"));
setResizable(false);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
JPanel comboPanel = new JPanel(null);
int labWidth = 0;
boolean[] exportableExistsArray = new boolean[optionNames.length];
for (int i = 0; i < optionNames.length; i++) {
boolean exportableExists = false;
if (exportables == null) {
exportableExists = true;
} else {
for (TreeItem e : exportables) {
if (optionCanHandle(i, e)) {
exportableExists = true;
}
}
}
if (!exportableExists) {
continue;
}
exportableExistsArray[i] = true;
JLabel label = new JLabel(translate(optionNames[i]));
if (label.getPreferredSize().width > labWidth) {
labWidth = label.getPreferredSize().width;
}
}
String exportFormatsStr = Configuration.lastSelectedExportFormats.get();
if ("".equals(exportFormatsStr)) {
exportFormatsStr = null;
}
String[] exportFormatsArr = new String[0];
if (exportFormatsStr != null) {
if (exportFormatsStr.contains(",")) {
exportFormatsArr = exportFormatsStr.split(",");
} else {
exportFormatsArr = new String[]{exportFormatsStr};
}
}
int comboWidth = 200;
int checkBoxWidth;
int top = 10;
List<String> exportFormats = Arrays.asList(exportFormatsArr);
combos = new JComboBox[optionNames.length];
checkBoxes = new JCheckBox[optionNames.length];
selectAllCheckBox = new JCheckBox();
checkBoxWidth = selectAllCheckBox.getPreferredSize().width;
selectAllCheckBox.setBounds(10 + labWidth + 10 + comboWidth + 10, top, checkBoxWidth, selectAllCheckBox.getPreferredSize().height);
selectAllCheckBox.setSelected(true);
selectAllCheckBox.addActionListener((ActionEvent e) -> {
boolean selected = selectAllCheckBox.isSelected();
for (JCheckBox checkBox : checkBoxes) {
if (checkBox != null) {
checkBox.setSelected(selected);
}
}
});
comboPanel.add(selectAllCheckBox);
top += selectAllCheckBox.getHeight();
boolean zoomable = false;
for (int i = 0; i < optionNames.length; i++) {
Class c = optionClasses[i];
Object[] vals = c.getEnumConstants();
String[] names = new String[vals.length];
int itemIndex = -1;
for (int j = 0; j < vals.length; j++) {
String key = optionNames[i] + "." + vals[j].toString().toLowerCase();
if (exportFormats.contains(key)) {
itemIndex = j;
}
names[j] = translate(key);
}
combos[i] = new JComboBox<>(names);
if (itemIndex > -1) {
combos[i].setSelectedIndex(itemIndex);
}
combos[i].setBounds(10 + labWidth + 10, top, comboWidth, combos[i].getPreferredSize().height);
checkBoxes[i] = new JCheckBox();
checkBoxes[i].setBounds(10 + labWidth + 10 + comboWidth + 10, top, checkBoxWidth, checkBoxes[i].getPreferredSize().height);
checkBoxes[i].setSelected(true);
if (!exportableExistsArray[i]) {
continue;
}
if (Arrays.asList(zoomClasses).contains(c)) {
zoomable = true;
}
JLabel lab = new JLabel(translate(optionNames[i]));
lab.setBounds(10, top, lab.getPreferredSize().width, lab.getPreferredSize().height);
comboPanel.add(lab);
comboPanel.add(checkBoxes[i]);
comboPanel.add(combos[i]);
top += combos[i].getHeight();
}
int zoomWidth = 50;
if (zoomable) {
top += 2;
JLabel zlab = new JLabel(translate("zoom"));
zlab.setBounds(10, top + 4, zlab.getPreferredSize().width, zlab.getPreferredSize().height);
zoomTextField.setBounds(10 + labWidth + 10, top, zoomWidth, zoomTextField.getPreferredSize().height);
JLabel pctLabel = new JLabel(translate("zoom.percent"));
pctLabel.setBounds(10 + labWidth + 10 + zoomWidth + 5, top + 4, 20, pctLabel.getPreferredSize().height);
comboPanel.add(zlab);
comboPanel.add(zoomTextField);
comboPanel.add(pctLabel);
top += zoomTextField.getHeight();
}
Dimension dim = new Dimension(10 + labWidth + 10 + checkBoxWidth + 10 + comboWidth + 10, top + 10);
comboPanel.setMinimumSize(dim);
comboPanel.setPreferredSize(dim);
cnt.add(comboPanel, BorderLayout.CENTER);
JPanel buttonsPanel = new JPanel(new FlowLayout());
JButton okButton = new JButton(translate("button.ok"));
okButton.addActionListener(this::okButtonActionPerformed);
JButton cancelButton = new JButton(translate("button.cancel"));
cancelButton.addActionListener(this::cancelButtonActionPerformed);
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
cnt.add(buttonsPanel, BorderLayout.SOUTH);
pack();
View.centerScreen(this);
View.setWindowIcon(this);
getRootPane().setDefaultButton(okButton);
setModal(true);
String pct = "" + Configuration.lastSelectedExportZoom.get() * 100;
if (pct.endsWith(".0")) {
pct = pct.substring(0, pct.length() - 2);
}
zoomTextField.setText(pct);
}
@Override
public void setVisible(boolean b) {
if (b) {
result = ERROR_OPTION;
}
super.setVisible(b);
}
private void okButtonActionPerformed(ActionEvent evt) {
result = OK_OPTION;
try {
saveConfig();
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(ExportDialog.this, translate("zoom.invalid"), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
zoomTextField.requestFocusInWindow();
return;
}
setVisible(false);
}
private void cancelButtonActionPerformed(ActionEvent evt) {
result = CANCEL_OPTION;
setVisible(false);
}
public int showExportDialog() {
setVisible(true);
return result;
}
}
/*
* Copyright (C) 2010-2016 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.BinaryDataExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ButtonExportMode;
import com.jpexs.decompiler.flash.exporters.modes.FontExportMode;
import com.jpexs.decompiler.flash.exporters.modes.FrameExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ImageExportMode;
import com.jpexs.decompiler.flash.exporters.modes.MorphShapeExportMode;
import com.jpexs.decompiler.flash.exporters.modes.MovieExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.exporters.modes.ShapeExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SpriteExportMode;
import com.jpexs.decompiler.flash.exporters.modes.SymbolClassExportMode;
import com.jpexs.decompiler.flash.exporters.modes.TextExportMode;
import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineSpriteTag;
import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.flash.tags.base.ButtonTag;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.tags.base.MorphShapeTag;
import com.jpexs.decompiler.flash.tags.base.ShapeTag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.tags.base.SymbolClassTypeTag;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.timeline.Frame;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.util.Arrays;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author JPEXS
*/
public class ExportDialog extends AppDialog {
private int result = ERROR_OPTION;
String[] optionNames = {
TagTreeModel.FOLDER_SHAPES,
TagTreeModel.FOLDER_TEXTS,
TagTreeModel.FOLDER_IMAGES,
TagTreeModel.FOLDER_MOVIES,
TagTreeModel.FOLDER_SOUNDS,
TagTreeModel.FOLDER_SCRIPTS,
TagTreeModel.FOLDER_BINARY_DATA,
TagTreeModel.FOLDER_FRAMES,
TagTreeModel.FOLDER_SPRITES,
TagTreeModel.FOLDER_BUTTONS,
TagTreeModel.FOLDER_FONTS,
TagTreeModel.FOLDER_MORPHSHAPES,
"symbolclass"
};
//Display options only when these classes found
Class[][] objClasses = {
{ShapeTag.class},
{TextTag.class},
{ImageTag.class},
{DefineVideoStreamTag.class},
{SoundTag.class},
{ASMSource.class, ScriptPack.class},
{DefineBinaryDataTag.class},
{Frame.class},
{Frame.class},
{ButtonTag.class},
{FontTag.class},
{MorphShapeTag.class},
{SymbolClassTypeTag.class},
};
//Enum classes for values
Class[] optionClasses = {
ShapeExportMode.class,
TextExportMode.class,
ImageExportMode.class,
MovieExportMode.class,
SoundExportMode.class,
ScriptExportMode.class,
BinaryDataExportMode.class,
FrameExportMode.class,
SpriteExportMode.class,
ButtonExportMode.class,
FontExportMode.class,
MorphShapeExportMode.class,
SymbolClassExportMode.class,
};
Class[] zoomClasses = {
ShapeExportMode.class,
MorphShapeExportMode.class,
TextExportMode.class,
FrameExportMode.class,
SpriteExportMode.class,
ButtonExportMode.class,
};
private final JComboBox[] combos;
private final JCheckBox[] checkBoxes;
private final JCheckBox selectAllCheckBox;
private JTextField zoomTextField = new JTextField();
public <E> E getValue(Class<E> option) {
for (int i = 0; i < optionClasses.length; i++) {
if (option == optionClasses[i]) {
E[] values = option.getEnumConstants();
return values[combos[i].getSelectedIndex()];
}
}
return null;
}
public boolean isOptionEnabled(Class<?> option) {
for (int i = 0; i < optionClasses.length; i++) {
if (option == optionClasses[i]) {
return checkBoxes[i].isSelected();
}
}
return false;
}
public double getZoom() {
return Double.parseDouble(zoomTextField.getText()) / 100;
}
private void saveConfig() {
StringBuilder cfg = new StringBuilder();
for (int i = 0; i < optionNames.length; i++) {
int selIndex = combos[i].getSelectedIndex();
Class c = optionClasses[i];
Object[] vals = c.getEnumConstants();
String key = optionNames[i] + "." + vals[selIndex].toString().toLowerCase();
if (i > 0) {
cfg.append(",");
}
cfg.append(key);
}
Configuration.lastSelectedExportZoom.set(Double.parseDouble(zoomTextField.getText()) / 100);
Configuration.lastSelectedExportFormats.set(cfg.toString());
}
private boolean optionCanHandle(int optionIndex, Object e) {
for (int i = 0; i < objClasses[optionIndex].length; i++) {
Class c = objClasses[optionIndex][i];
if (c.isInstance(e)) {
if (c == Frame.class) { //Frame class can be SWF frame or Sprite frame
Frame f = (Frame) e;
boolean isSprite = (f.timeline.timelined instanceof DefineSpriteTag);
boolean spritesWanted = optionClasses[optionIndex] == SpriteExportMode.class;
if (spritesWanted == isSprite) { //both true or both false
return true;
}
} else {
return true;
}
}
}
return false;
}
public ExportDialog(List<TreeItem> exportables) {
setTitle(translate("dialog.title"));
setResizable(false);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
JPanel comboPanel = new JPanel(null);
int labWidth = 0;
boolean[] exportableExistsArray = new boolean[optionNames.length];
for (int i = 0; i < optionNames.length; i++) {
boolean exportableExists = false;
if (exportables == null) {
exportableExists = true;
} else {
for (TreeItem e : exportables) {
if (optionCanHandle(i, e)) {
exportableExists = true;
}
}
}
if (!exportableExists) {
continue;
}
exportableExistsArray[i] = true;
JLabel label = new JLabel(translate(optionNames[i]));
if (label.getPreferredSize().width > labWidth) {
labWidth = label.getPreferredSize().width;
}
}
String exportFormatsStr = Configuration.lastSelectedExportFormats.get();
if ("".equals(exportFormatsStr)) {
exportFormatsStr = null;
}
String[] exportFormatsArr = new String[0];
if (exportFormatsStr != null) {
if (exportFormatsStr.contains(",")) {
exportFormatsArr = exportFormatsStr.split(",");
} else {
exportFormatsArr = new String[]{exportFormatsStr};
}
}
int comboWidth = 200;
int checkBoxWidth;
int top = 10;
List<String> exportFormats = Arrays.asList(exportFormatsArr);
combos = new JComboBox[optionNames.length];
checkBoxes = new JCheckBox[optionNames.length];
selectAllCheckBox = new JCheckBox();
checkBoxWidth = selectAllCheckBox.getPreferredSize().width;
selectAllCheckBox.setBounds(10 + labWidth + 10 + comboWidth + 10, top, checkBoxWidth, selectAllCheckBox.getPreferredSize().height);
selectAllCheckBox.setSelected(true);
selectAllCheckBox.addActionListener((ActionEvent e) -> {
boolean selected = selectAllCheckBox.isSelected();
for (JCheckBox checkBox : checkBoxes) {
if (checkBox != null) {
checkBox.setSelected(selected);
}
}
});
comboPanel.add(selectAllCheckBox);
top += selectAllCheckBox.getHeight();
boolean zoomable = false;
for (int i = 0; i < optionNames.length; i++) {
Class c = optionClasses[i];
Object[] vals = c.getEnumConstants();
String[] names = new String[vals.length];
int itemIndex = -1;
for (int j = 0; j < vals.length; j++) {
String key = optionNames[i] + "." + vals[j].toString().toLowerCase();
if (exportFormats.contains(key)) {
itemIndex = j;
}
names[j] = translate(key);
}
combos[i] = new JComboBox<>(names);
if (itemIndex > -1) {
combos[i].setSelectedIndex(itemIndex);
}
combos[i].setBounds(10 + labWidth + 10, top, comboWidth, combos[i].getPreferredSize().height);
checkBoxes[i] = new JCheckBox();
checkBoxes[i].setBounds(10 + labWidth + 10 + comboWidth + 10, top, checkBoxWidth, checkBoxes[i].getPreferredSize().height);
checkBoxes[i].setSelected(true);
if (!exportableExistsArray[i]) {
continue;
}
if (Arrays.asList(zoomClasses).contains(c)) {
zoomable = true;
}
JLabel lab = new JLabel(translate(optionNames[i]));
lab.setBounds(10, top, lab.getPreferredSize().width, lab.getPreferredSize().height);
comboPanel.add(lab);
comboPanel.add(checkBoxes[i]);
comboPanel.add(combos[i]);
top += combos[i].getHeight();
}
int zoomWidth = 50;
if (zoomable) {
top += 2;
JLabel zlab = new JLabel(translate("zoom"));
zlab.setBounds(10, top + 4, zlab.getPreferredSize().width, zlab.getPreferredSize().height);
zoomTextField.setBounds(10 + labWidth + 10, top, zoomWidth, zoomTextField.getPreferredSize().height);
JLabel pctLabel = new JLabel(translate("zoom.percent"));
pctLabel.setBounds(10 + labWidth + 10 + zoomWidth + 5, top + 4, 20, pctLabel.getPreferredSize().height);
comboPanel.add(zlab);
comboPanel.add(zoomTextField);
comboPanel.add(pctLabel);
top += zoomTextField.getHeight();
}
Dimension dim = new Dimension(10 + labWidth + 10 + checkBoxWidth + 10 + comboWidth + 10, top + 10);
comboPanel.setMinimumSize(dim);
comboPanel.setPreferredSize(dim);
cnt.add(comboPanel, BorderLayout.CENTER);
JPanel buttonsPanel = new JPanel(new FlowLayout());
JButton okButton = new JButton(translate("button.ok"));
okButton.addActionListener(this::okButtonActionPerformed);
JButton cancelButton = new JButton(translate("button.cancel"));
cancelButton.addActionListener(this::cancelButtonActionPerformed);
buttonsPanel.add(okButton);
buttonsPanel.add(cancelButton);
cnt.add(buttonsPanel, BorderLayout.SOUTH);
pack();
View.centerScreen(this);
View.setWindowIcon(this);
getRootPane().setDefaultButton(okButton);
setModal(true);
String pct = "" + Configuration.lastSelectedExportZoom.get() * 100;
if (pct.endsWith(".0")) {
pct = pct.substring(0, pct.length() - 2);
}
zoomTextField.setText(pct);
}
@Override
public void setVisible(boolean b) {
if (b) {
result = ERROR_OPTION;
}
super.setVisible(b);
}
private void okButtonActionPerformed(ActionEvent evt) {
result = OK_OPTION;
try {
saveConfig();
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(ExportDialog.this, translate("zoom.invalid"), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
zoomTextField.requestFocusInWindow();
return;
}
setVisible(false);
}
private void cancelButtonActionPerformed(ActionEvent evt) {
result = CANCEL_OPTION;
setVisible(false);
}
public int showExportDialog() {
setVisible(true);
return result;
}
}
@@ -1,137 +1,137 @@
/*
* Copyright (C) 2010-2016 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.ConvertData;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitType;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.search.ABCSearchResult;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class TraitsListItem {
private final TraitType type;
private final boolean isStatic;
private final ABC abc;
private final int classIndex;
private final int index;
private final int scriptIndex;
public static String STR_INSTANCE_INITIALIZER = ABCSearchResult.STR_INSTANCE_INITIALIZER;
public static String STR_CLASS_INITIALIZER = ABCSearchResult.STR_CLASS_INITIALIZER;
public static String STR_SCRIPT_INITIALIZER = ABCSearchResult.STR_SCRIPT_INITIALIZER;
public TraitsListItem(TraitType type, int index, boolean isStatic, ABC abc, int classIndex, int scriptIndex) {
this.type = type;
this.index = index;
this.isStatic = isStatic;
this.abc = abc;
this.classIndex = classIndex;
this.scriptIndex = scriptIndex;
}
public int getGlobalTraitId() {
return abc.getGlobalTraitId(type, isStatic, classIndex, index);
}
public String toStringName() {
if (type == TraitType.INITIALIZER) {
if (!isStatic) {
return "__" + STR_INSTANCE_INITIALIZER;
} else {
return "__" + STR_CLASS_INITIALIZER;
}
}
if (type == TraitType.SCRIPT_INITIALIZER) {
return "__" + STR_SCRIPT_INITIALIZER;
}
if (isStatic) {
return abc.class_info.get(classIndex).static_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
} else {
return abc.instance_info.get(classIndex).instance_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
}
}
@Override
public String toString() {
String s = "";
try {
if (type == TraitType.SCRIPT_INITIALIZER) {
s = STR_SCRIPT_INITIALIZER;
} else if (type == TraitType.INITIALIZER) {
if (!isStatic) {
s = STR_INSTANCE_INITIALIZER;
} else {
s = STR_CLASS_INITIALIZER;
}
} else if (isStatic) {
ConvertData convertData = new ConvertData();
Trait trait = abc.class_info.get(classIndex).static_traits.traits.get(index);
trait.convertHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
trait.toStringHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
s = writer.toString();
} else {
ConvertData convertData = new ConvertData();
Trait trait = abc.instance_info.get(classIndex).instance_traits.traits.get(index);
trait.convertHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
trait.toStringHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
s = writer.toString();
}
} catch (InterruptedException ex) {
Logger.getLogger(TraitsListItem.class.getName()).log(Level.SEVERE, null, ex);
}
s = s.replaceAll("[ \r\n]+", " ");
return s;
}
public TraitType getType() {
return type;
}
public boolean isStatic() {
return isStatic;
}
public int getClassIndex() {
return classIndex;
}
public int getIndex() {
return index;
}
}
/*
* Copyright (C) 2010-2016 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.ConvertData;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitType;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.search.ABCSearchResult;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class TraitsListItem {
private final TraitType type;
private final boolean isStatic;
private final ABC abc;
private final int classIndex;
private final int index;
private final int scriptIndex;
public static String STR_INSTANCE_INITIALIZER = ABCSearchResult.STR_INSTANCE_INITIALIZER;
public static String STR_CLASS_INITIALIZER = ABCSearchResult.STR_CLASS_INITIALIZER;
public static String STR_SCRIPT_INITIALIZER = ABCSearchResult.STR_SCRIPT_INITIALIZER;
public TraitsListItem(TraitType type, int index, boolean isStatic, ABC abc, int classIndex, int scriptIndex) {
this.type = type;
this.index = index;
this.isStatic = isStatic;
this.abc = abc;
this.classIndex = classIndex;
this.scriptIndex = scriptIndex;
}
public int getGlobalTraitId() {
return abc.getGlobalTraitId(type, isStatic, classIndex, index);
}
public String toStringName() {
if (type == TraitType.INITIALIZER) {
if (!isStatic) {
return "__" + STR_INSTANCE_INITIALIZER;
} else {
return "__" + STR_CLASS_INITIALIZER;
}
}
if (type == TraitType.SCRIPT_INITIALIZER) {
return "__" + STR_SCRIPT_INITIALIZER;
}
if (isStatic) {
return abc.class_info.get(classIndex).static_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
} else {
return abc.instance_info.get(classIndex).instance_traits.traits.get(index).getName(abc).getName(abc.constants, null, false, true);
}
}
@Override
public String toString() {
String s = "";
try {
if (type == TraitType.SCRIPT_INITIALIZER) {
s = STR_SCRIPT_INITIALIZER;
} else if (type == TraitType.INITIALIZER) {
if (!isStatic) {
s = STR_INSTANCE_INITIALIZER;
} else {
s = STR_CLASS_INITIALIZER;
}
} else if (isStatic) {
ConvertData convertData = new ConvertData();
Trait trait = abc.class_info.get(classIndex).static_traits.traits.get(index);
trait.convertHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
trait.toStringHeader(null, convertData, "", abc, true, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
s = writer.toString();
} else {
ConvertData convertData = new ConvertData();
Trait trait = abc.instance_info.get(classIndex).instance_traits.traits.get(index);
trait.convertHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<>(), false);
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
trait.toStringHeader(null, convertData, "", abc, false, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<>(), false);
s = writer.toString();
}
} catch (InterruptedException ex) {
Logger.getLogger(TraitsListItem.class.getName()).log(Level.SEVERE, null, ex);
}
s = s.replaceAll("[ \r\n]+", " ");
return s;
}
public TraitType getType() {
return type;
}
public boolean isStatic() {
return isStatic;
}
public int getClassIndex() {
return classIndex;
}
public int getIndex() {
return index;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,438 +1,438 @@
/*
* Copyright (C) 2010-2016 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.player;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.FlashUnsupportedException;
import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.helpers.CancellableWorker;
import com.jpexs.javactivex.ActiveX;
import com.jpexs.javactivex.ActiveXEvent;
import com.jpexs.javactivex.ActiveXException;
import com.jpexs.javactivex.example.controls.flash.ShockwaveFlash;
import com.sun.jna.Platform;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Component;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author JPEXS
*/
public final class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
private static final Logger logger = Logger.getLogger(FlashPlayerPanel.class.getName());
private final int setMovieDelay = Configuration.setMovieDelay.get();
private final List<MediaDisplayListener> listeners = new ArrayList<>();
private final ShockwaveFlash flash;
private final Timer timer;
private boolean stopped = true;
private boolean closed = false;
private float frameRate;
@Override
public boolean loopAvailable() {
return false;
}
@Override
public boolean screenAvailable() {
return true;
}
@Override
public boolean zoomAvailable() {
return true;
}
@Override
public double getZoomToFit() {
//TODO
return 1;
}
@Override
public Zoom getZoom() {
return null;
}
private double zoom = 1.0;
@Override
public synchronized void zoom(Zoom zoom) {
double zoomDouble = zoom.fit ? getZoomToFit() : zoom.value;
int zoomint = (int) Math.round(100 / (zoomDouble / this.zoom));
if (zoomint == 0) {
zoomint = 1;
}
if (zoomint > 32767) {
zoomint = 32767;
}
if (zoomint == 100) {
zoomint = 0;
}
flash.Zoom(0); // hack, but this call is needed otherwise unzoom will fail for larger zoom values
flash.Zoom(zoomint);
}
public synchronized String getVariable(String name) throws IOException {
return flash.GetVariable(name);
}
public synchronized void setVariable(String name, String value) throws IOException {
flash.SetVariable(name, value);
}
public synchronized String call(String callString) throws IOException {
return flash.CallFunction(callString);
}
@Override
public synchronized int getCurrentFrame() {
if (flash == null) {
return 0;
}
try {
return flash.getFrameNum();
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
return 0;
}
@Override
public synchronized int getTotalFrames() {
if (flash == null) {
return 0;
}
try {
if (flash.getReadyState() == 4) {
return flash.getTotalFrames();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
return 0;
}
@Override
public synchronized void setBackground(Color color) {
try {
flash.setBackgroundColor((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
public FlashPlayerPanel(Component frame) {
if (!Platform.isWindows()) {
throw new FlashUnsupportedException();
}
try {
Callable<ShockwaveFlash> callable = new Callable<ShockwaveFlash>() {
@Override
public ShockwaveFlash call() throws InterruptedException {
return ActiveX.createObject(ShockwaveFlash.class, FlashPlayerPanel.this);
}
};
// hack: Kernel32.INSTANCE.ConnectNamedPipe never completes in ActiveXControl static constructor
flash = CancellableWorker.call(callable, 5, TimeUnit.SECONDS);
} catch (ActiveXException | TimeoutException | InterruptedException | ExecutionException ex) {
logger.log(Level.WARNING, "Cannot initialize flash panel", ex);
throw new FlashUnsupportedException();
}
flash.setAllowScriptAccess("always");
try {
flash.setAllowNetworking("all");
} catch (ActiveXException ex) {
// ignore
}
flash.addOnReadyStateChangeListener((ActiveXEvent axe) -> {
fireMediaDisplayStateChanged();
});
flash.addFlashCallListener((ActiveXEvent axe) -> {
String req = (String) axe.args.get("request");
Matcher m = Pattern.compile("<invoke name=\"([^\"]+)\" returntype=\"xml\"><arguments><string>(.*)</string></arguments></invoke>").matcher(req);
if (m.matches()) {
String funname = m.group(1);
String msg = m.group(2);
if (funname.equals("alert") || funname.equals("console.log")) {
if (Main.debugDialog != null) {
Main.debugDialog.log(funname + ":" + msg);
}
}
}
});
timer = new Timer();
timer.schedule(new TimerTask() {
private boolean isPlaying = false;
private int currentFrame = 0;
@Override
public void run() {
if (closed) {
return;
}
try {
ShockwaveFlash flash1 = flash;
boolean changed = false;
if (flash1.getReadyState() >= 3) {
boolean isPlaying = flash1.IsPlaying();
if (this.isPlaying != isPlaying) {
this.isPlaying = isPlaying;
}
int currentFrame = flash1.CurrentFrame();
if (this.currentFrame != currentFrame) {
this.currentFrame = currentFrame;
changed = true;
}
} else {
this.isPlaying = false;
}
if (changed) {
fireMediaDisplayStateChanged();
}
} catch (Exception ex) {
// ignore
cancel();
}
}
}, 100, 100);
}
public synchronized void stopSWF() {
displaySWF("-", null, 1);
stopped = true;
fireMediaDisplayStateChanged();
}
public synchronized boolean isStopped() {
return stopped;
}
@Override
public BufferedImage printScreen() {
Point screenloc = getLocationOnScreen();
try {
return new Robot().createScreenCapture(new Rectangle(screenloc.x, screenloc.y, getWidth(), getHeight()));
} catch (AWTException ex) {
return null;
}
}
private String movieToPlay = null;
private Thread playQueue;
private final Object queueLock = new Object();
public synchronized void displaySWF(final String flashName, final Color bgColor, final float frameRate) {
// Minimum of 1000 ms (setMovieDelay) delay before calling flash.setMovie to avoid illegalAccess errors
if (playQueue == null) {
playQueue = new Thread() {
long lastTime;
@Override
public void run() {
while (true) {
boolean empty;
synchronized (queueLock) {
empty = movieToPlay == null;
if (empty) {
try {
queueLock.wait();
} catch (InterruptedException ex) {
break;
}
}
}
if (!empty) {
flash.setMovie(movieToPlay);
synchronized (queueLock) {
movieToPlay = null;
}
try {
Thread.sleep(setMovieDelay);
} catch (InterruptedException ex) {
break;
}
}
}
}
};
playQueue.start();
}
zoom = 1.0;
this.frameRate = frameRate;
if (bgColor != null) {
setBackground(bgColor);
}
synchronized (queueLock) {
movieToPlay = flashName;
queueLock.notify();
}
//play
stopped = false;
fireMediaDisplayStateChanged();
}
@Override
public synchronized void close() throws IOException {
timer.cancel();
closed = true;
}
@Override
public void pause() {
try {
if (flash.getReadyState() >= 3) {
flash.Stop();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public void stop() {
try {
if (flash.getReadyState() >= 3) {
flash.Stop();
flash.Rewind();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public void rewind() {
try {
if (flash.getReadyState() >= 3) {
flash.Rewind();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public void play() {
try {
if (flash.getReadyState() >= 3) {
flash.Play();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public boolean isPlaying() {
try {
if (flash.getReadyState() >= 3) {
return flash.IsPlaying();
} else {
return false;
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
return false;
}
}
@Override
public void setLoop(boolean loop
) {
}
@Override
public void gotoFrame(int frame
) {
if (frame < 0) {
return;
}
if (frame >= getTotalFrames()) {
return;
}
try {
if (flash.getReadyState() >= 3) {
flash.GotoFrame(frame);
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public float getFrameRate() {
return frameRate;
}
@Override
public boolean isLoaded() {
return !isStopped();
}
public void fireMediaDisplayStateChanged() {
for (MediaDisplayListener l : listeners) {
l.mediaDisplayStateChanged(this);
}
}
@Override
public void addEventListener(MediaDisplayListener listener) {
listeners.add(listener);
}
@Override
public void removeEventListener(MediaDisplayListener listener) {
listeners.remove(listener);
}
}
/*
* Copyright (C) 2010-2016 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.player;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.FlashUnsupportedException;
import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.helpers.CancellableWorker;
import com.jpexs.javactivex.ActiveX;
import com.jpexs.javactivex.ActiveXEvent;
import com.jpexs.javactivex.ActiveXException;
import com.jpexs.javactivex.example.controls.flash.ShockwaveFlash;
import com.sun.jna.Platform;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Component;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author JPEXS
*/
public final class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay {
private static final Logger logger = Logger.getLogger(FlashPlayerPanel.class.getName());
private final int setMovieDelay = Configuration.setMovieDelay.get();
private final List<MediaDisplayListener> listeners = new ArrayList<>();
private final ShockwaveFlash flash;
private final Timer timer;
private boolean stopped = true;
private boolean closed = false;
private float frameRate;
@Override
public boolean loopAvailable() {
return false;
}
@Override
public boolean screenAvailable() {
return true;
}
@Override
public boolean zoomAvailable() {
return true;
}
@Override
public double getZoomToFit() {
//TODO
return 1;
}
@Override
public Zoom getZoom() {
return null;
}
private double zoom = 1.0;
@Override
public synchronized void zoom(Zoom zoom) {
double zoomDouble = zoom.fit ? getZoomToFit() : zoom.value;
int zoomint = (int) Math.round(100 / (zoomDouble / this.zoom));
if (zoomint == 0) {
zoomint = 1;
}
if (zoomint > 32767) {
zoomint = 32767;
}
if (zoomint == 100) {
zoomint = 0;
}
flash.Zoom(0); // hack, but this call is needed otherwise unzoom will fail for larger zoom values
flash.Zoom(zoomint);
}
public synchronized String getVariable(String name) throws IOException {
return flash.GetVariable(name);
}
public synchronized void setVariable(String name, String value) throws IOException {
flash.SetVariable(name, value);
}
public synchronized String call(String callString) throws IOException {
return flash.CallFunction(callString);
}
@Override
public synchronized int getCurrentFrame() {
if (flash == null) {
return 0;
}
try {
return flash.getFrameNum();
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
return 0;
}
@Override
public synchronized int getTotalFrames() {
if (flash == null) {
return 0;
}
try {
if (flash.getReadyState() == 4) {
return flash.getTotalFrames();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
return 0;
}
@Override
public synchronized void setBackground(Color color) {
try {
flash.setBackgroundColor((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
public FlashPlayerPanel(Component frame) {
if (!Platform.isWindows()) {
throw new FlashUnsupportedException();
}
try {
Callable<ShockwaveFlash> callable = new Callable<ShockwaveFlash>() {
@Override
public ShockwaveFlash call() throws InterruptedException {
return ActiveX.createObject(ShockwaveFlash.class, FlashPlayerPanel.this);
}
};
// hack: Kernel32.INSTANCE.ConnectNamedPipe never completes in ActiveXControl static constructor
flash = CancellableWorker.call(callable, 5, TimeUnit.SECONDS);
} catch (ActiveXException | TimeoutException | InterruptedException | ExecutionException ex) {
logger.log(Level.WARNING, "Cannot initialize flash panel", ex);
throw new FlashUnsupportedException();
}
flash.setAllowScriptAccess("always");
try {
flash.setAllowNetworking("all");
} catch (ActiveXException ex) {
// ignore
}
flash.addOnReadyStateChangeListener((ActiveXEvent axe) -> {
fireMediaDisplayStateChanged();
});
flash.addFlashCallListener((ActiveXEvent axe) -> {
String req = (String) axe.args.get("request");
Matcher m = Pattern.compile("<invoke name=\"([^\"]+)\" returntype=\"xml\"><arguments><string>(.*)</string></arguments></invoke>").matcher(req);
if (m.matches()) {
String funname = m.group(1);
String msg = m.group(2);
if (funname.equals("alert") || funname.equals("console.log")) {
if (Main.debugDialog != null) {
Main.debugDialog.log(funname + ":" + msg);
}
}
}
});
timer = new Timer();
timer.schedule(new TimerTask() {
private boolean isPlaying = false;
private int currentFrame = 0;
@Override
public void run() {
if (closed) {
return;
}
try {
ShockwaveFlash flash1 = flash;
boolean changed = false;
if (flash1.getReadyState() >= 3) {
boolean isPlaying = flash1.IsPlaying();
if (this.isPlaying != isPlaying) {
this.isPlaying = isPlaying;
}
int currentFrame = flash1.CurrentFrame();
if (this.currentFrame != currentFrame) {
this.currentFrame = currentFrame;
changed = true;
}
} else {
this.isPlaying = false;
}
if (changed) {
fireMediaDisplayStateChanged();
}
} catch (Exception ex) {
// ignore
cancel();
}
}
}, 100, 100);
}
public synchronized void stopSWF() {
displaySWF("-", null, 1);
stopped = true;
fireMediaDisplayStateChanged();
}
public synchronized boolean isStopped() {
return stopped;
}
@Override
public BufferedImage printScreen() {
Point screenloc = getLocationOnScreen();
try {
return new Robot().createScreenCapture(new Rectangle(screenloc.x, screenloc.y, getWidth(), getHeight()));
} catch (AWTException ex) {
return null;
}
}
private String movieToPlay = null;
private Thread playQueue;
private final Object queueLock = new Object();
public synchronized void displaySWF(final String flashName, final Color bgColor, final float frameRate) {
// Minimum of 1000 ms (setMovieDelay) delay before calling flash.setMovie to avoid illegalAccess errors
if (playQueue == null) {
playQueue = new Thread() {
long lastTime;
@Override
public void run() {
while (true) {
boolean empty;
synchronized (queueLock) {
empty = movieToPlay == null;
if (empty) {
try {
queueLock.wait();
} catch (InterruptedException ex) {
break;
}
}
}
if (!empty) {
flash.setMovie(movieToPlay);
synchronized (queueLock) {
movieToPlay = null;
}
try {
Thread.sleep(setMovieDelay);
} catch (InterruptedException ex) {
break;
}
}
}
}
};
playQueue.start();
}
zoom = 1.0;
this.frameRate = frameRate;
if (bgColor != null) {
setBackground(bgColor);
}
synchronized (queueLock) {
movieToPlay = flashName;
queueLock.notify();
}
//play
stopped = false;
fireMediaDisplayStateChanged();
}
@Override
public synchronized void close() throws IOException {
timer.cancel();
closed = true;
}
@Override
public void pause() {
try {
if (flash.getReadyState() >= 3) {
flash.Stop();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public void stop() {
try {
if (flash.getReadyState() >= 3) {
flash.Stop();
flash.Rewind();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public void rewind() {
try {
if (flash.getReadyState() >= 3) {
flash.Rewind();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public void play() {
try {
if (flash.getReadyState() >= 3) {
flash.Play();
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public boolean isPlaying() {
try {
if (flash.getReadyState() >= 3) {
return flash.IsPlaying();
} else {
return false;
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
return false;
}
}
@Override
public void setLoop(boolean loop
) {
}
@Override
public void gotoFrame(int frame
) {
if (frame < 0) {
return;
}
if (frame >= getTotalFrames()) {
return;
}
try {
if (flash.getReadyState() >= 3) {
flash.GotoFrame(frame);
}
} catch (ActiveXException | NullPointerException ex) { // Can be "Data not available yet exception"
}
}
@Override
public float getFrameRate() {
return frameRate;
}
@Override
public boolean isLoaded() {
return !isStopped();
}
public void fireMediaDisplayStateChanged() {
for (MediaDisplayListener l : listeners) {
l.mediaDisplayStateChanged(this);
}
}
@Override
public void addEventListener(MediaDisplayListener listener) {
listeners.add(listener);
}
@Override
public void removeEventListener(MediaDisplayListener listener) {
listeners.remove(listener);
}
}