Issue #1118 Loading characters through ImportAssets - show as readonly

icon
This commit is contained in:
Jindra Petřík
2016-01-03 22:25:54 +01:00
parent c069d5e0e4
commit c2aba5fc08
21 changed files with 2325 additions and 2183 deletions

View File

@@ -219,6 +219,9 @@ public class FontPanel extends JPanel {
setAllowSave(true);
setEditable(false);
boolean readOnly = ((Tag) ft).isReadOnly();
addCharsPanel.setVisible(!readOnly);
buttonEdit.setVisible(!readOnly);
}
private void initComponents() {

View File

@@ -26,8 +26,10 @@ import com.jpexs.decompiler.flash.SWFBundle;
import com.jpexs.decompiler.flash.SWFSourceInfo;
import com.jpexs.decompiler.flash.SearchMode;
import com.jpexs.decompiler.flash.SwfOpenException;
import com.jpexs.decompiler.flash.UrlResolver;
import com.jpexs.decompiler.flash.Version;
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.Reference;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.configuration.SwfSpecificConfiguration;
import com.jpexs.decompiler.flash.console.CommandLineArgumentParser;
@@ -653,18 +655,149 @@ public class Main {
}
} else {
InputStream fInputStream = inputStream;
final String[] yesno = new String[]{AppStrings.translate("button.yes"), AppStrings.translate("button.no"), AppStrings.translate("button.yes.all"), AppStrings.translate("button.no.all")};
CancellableWorker<SWF> worker = new CancellableWorker<SWF>() {
@Override
public SWF doInBackground() throws Exception {
private boolean yestoall = false;
private boolean notoall = false;
private SWF open(InputStream is, String file, String fileTitle) throws IOException, InterruptedException {
final CancellableWorker worker = this;
SWF swf = new SWF(fInputStream, sourceInfo.getFile(), sourceInfo.getFileTitle(), new ProgressListener() {
SWF swf = new SWF(is, file, fileTitle, new ProgressListener() {
@Override
public void progress(int p) {
startWork(AppStrings.translate("work.reading.swf"), p, worker);
}
}, Configuration.parallelSpeedUp.get());
}, Configuration.parallelSpeedUp.get(), false, true, new UrlResolver() {
@Override
public SWF resolveUrl(final String url) {
int opt = -1;
if (!(yestoall || notoall)) {
opt = View.showOptionDialog(null, AppStrings.translate("message.imported.swf").replace("%url%", url), AppStrings.translate("message.warning"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, yesno, AppStrings.translate("button.yes"));
if (opt == 2) {
yestoall = true;
}
if (opt == 3) {
notoall = true;
}
}
if (yestoall) {
opt = 0; // yes
} else if (notoall) {
opt = 1; // no
}
if (opt == 1) //no
{
return null;
}
if (url.startsWith("http://") || url.startsWith("https://")) {
try {
URL u = new URL(url);
return open(u.openStream(), null, url); //?
} catch (Exception ex) {
//ignore
}
} else {
File f = new File(new File(file).getParentFile(), url);
if (f.exists()) {
try {
return open(new FileInputStream(f), f.getAbsolutePath(), f.getName());
} catch (Exception ex) {
//ignore
}
}
}
Reference<SWF> ret = new Reference<>(null);
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
while (JOptionPane.YES_OPTION == View.showConfirmDialog(null, AppStrings.translate("message.imported.swf.manually").replace("%url%", url), AppStrings.translate("error"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE)) {
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File(Configuration.lastOpenDir.get()));
FileFilter allSupportedFilter = new FileFilter() {
private final String[] supportedExtensions = new String[]{".swf", ".gfx"};
@Override
public boolean accept(File f) {
String name = f.getName().toLowerCase();
for (String ext : supportedExtensions) {
if (name.endsWith(ext)) {
return true;
}
}
return f.isDirectory();
}
@Override
public String getDescription() {
String exts = Helper.joinStrings(supportedExtensions, "*%s", "; ");
return AppStrings.translate("filter.supported") + " (" + exts + ")";
}
};
fc.setFileFilter(allSupportedFilter);
FileFilter swfFilter = new FileFilter() {
@Override
public boolean accept(File f) {
return (f.getName().toLowerCase().endsWith(".swf")) || (f.isDirectory());
}
@Override
public String getDescription() {
return AppStrings.translate("filter.swf");
}
};
fc.addChoosableFileFilter(swfFilter);
FileFilter gfxFilter = new FileFilter() {
@Override
public boolean accept(File f) {
return (f.getName().toLowerCase().endsWith(".gfx")) || (f.isDirectory());
}
@Override
public String getDescription() {
return AppStrings.translate("filter.gfx");
}
};
fc.addChoosableFileFilter(gfxFilter);
fc.setAcceptAllFileFilterUsed(false);
JFrame f = new JFrame();
View.setWindowIcon(f);
int returnVal = fc.showOpenDialog(f);
if (returnVal == JFileChooser.APPROVE_OPTION) {
Configuration.lastOpenDir.set(Helper.fixDialogFile(fc.getSelectedFile()).getParentFile().getAbsolutePath());
File selFile = Helper.fixDialogFile(fc.getSelectedFile());
try {
ret.setVal(open(new FileInputStream(selFile), selFile.getAbsolutePath(), selFile.getName()));
break;
} catch (Exception ex) {
//ignore;
}
} else {
break;
}
}
}
});
return ret.getVal();
}
});
return swf;
}
@Override
public SWF doInBackground() throws Exception {
return open(fInputStream, sourceInfo.getFile(), sourceInfo.getFileTitle());
}
};
if (loadingDialog != null) {
loadingDialog.setWroker(worker);

View File

@@ -833,10 +833,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (View.showConfirmDialog(this, translate("message.confirm.closeAll"), translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, Configuration.showCloseConfirmation, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION) {
return false;
}
} else {
if (View.showConfirmDialog(this, translate("message.confirm.close").replace("{swfName}", swfList.toString()), translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, Configuration.showCloseConfirmation, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION) {
return false;
}
} else if (View.showConfirmDialog(this, translate("message.confirm.close").replace("{swfName}", swfList.toString()), translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, Configuration.showCloseConfirmation, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION) {
return false;
}
return true;
@@ -1556,6 +1554,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
actionPanel.editor.refreshMarkers();
}
}
/*
public void debuggerBreakAt(SWF swf, String cls, int line) {
View.execInEventDispatchLater(new Runnable() {
@@ -1570,7 +1569,6 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
});
}*/
public void gotoScriptName(SWF swf, String scriptName) {
if (swf == null) {
return;
@@ -2166,10 +2164,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
List<TreeItem> sel = tagTree.getAllSelected();
if (!onlySel) {
sel = null;
} else {
if (sel.isEmpty()) {
return;
}
} else if (sel.isEmpty()) {
return;
}
final ExportDialog export = new ExportDialog(sel);
if (export.showExportDialog() == AppDialog.OK_OPTION) {
@@ -2818,10 +2814,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
if (detailPanel.isVisible()) {
detailPanel.setVisible(false);
}
} else {
if (!detailPanel.isVisible()) {
detailPanel.setVisible(true);
}
} else if (!detailPanel.isVisible()) {
detailPanel.setVisible(true);
}
}
@@ -3194,7 +3188,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
showCard(CARDACTIONSCRIPTPANEL);
} else if (treeItem instanceof ImageTag) {
ImageTag imageTag = (ImageTag) treeItem;
previewPanel.setImageReplaceButtonVisible(imageTag.importSupported(), imageTag instanceof DefineBitsJPEG3Tag || imageTag instanceof DefineBitsJPEG4Tag);
previewPanel.setImageReplaceButtonVisible(!((Tag) imageTag).isReadOnly() && imageTag.importSupported(), imageTag instanceof DefineBitsJPEG3Tag || imageTag instanceof DefineBitsJPEG4Tag);
previewPanel.showImagePanel(imageTag.getImage());
showCard(CARDPREVIEWPANEL);
} else if ((treeItem instanceof DrawableTag) && (!(treeItem instanceof TextTag)) && (!(treeItem instanceof FontTag)) && internalViewer) {
@@ -3227,7 +3221,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
showCard(CARDPREVIEWPANEL);
} else if ((treeItem instanceof SoundTag)) { //&& isInternalFlashViewerSelected() && (Arrays.asList("mp3", "wav").contains(((SoundTag) tagObj).getExportFormat())))) {
previewPanel.showImagePanel(new SerializableImage(View.loadImage("sound32")));
previewPanel.setImageReplaceButtonVisible(treeItem instanceof DefineSoundTag, false);
previewPanel.setImageReplaceButtonVisible(((Tag) treeItem).isReadOnly() && (treeItem instanceof DefineSoundTag), false);
try {
SoundTagPlayer soundThread = new SoundTagPlayer((SoundTag) treeItem, Configuration.loopMedia.get() ? Integer.MAX_VALUE : 1, true);
previewPanel.setMedia(soundThread);

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.helpers.HighlightedText;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import com.jpexs.decompiler.flash.tags.DefineEditTextTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
import com.jpexs.decompiler.flash.tags.base.TextTag;
@@ -59,6 +60,8 @@ public class TextPanel extends JPanel implements TagEditorPanel {
private final LineMarkedEditorPane textValue;
private final JPanel buttonsPanel;
private final JButton textEditButton;
private final JButton textSaveButton;
@@ -132,7 +135,7 @@ public class TextPanel extends JPanel implements TagEditorPanel {
topPanel.add(textButtonsPanel);
add(topPanel, BorderLayout.NORTH);
JPanel buttonsPanel = new JPanel(new FlowLayout());
buttonsPanel = new JPanel(new FlowLayout());
textEditButton = createButton("button.edit", "edit16", null, e -> editText());
textSaveButton = createButton("button.save", "save16", null, e -> saveText(true));
textCancelButton = createButton("button.cancel", "cancel16", null, e -> cancelText());
@@ -174,6 +177,17 @@ public class TextPanel extends JPanel implements TagEditorPanel {
textValue.setCaretPosition(0);
setModified(false);
setEditText(false);
boolean readOnly = ((Tag) textTag).isReadOnly();
textValue.setEditable(!readOnly);
buttonsPanel.setVisible(!readOnly);
textAlignLeftButton.setVisible(!readOnly);
textAlignCenterButton.setVisible(!readOnly);
textAlignRightButton.setVisible(!readOnly);
textAlignJustifyButton.setVisible(!readOnly);
decreaseTranslateXButton.setVisible(!readOnly);
increaseTranslateXButton.setVisible(!readOnly);
changeCaseButton.setVisible(!readOnly);
undoChangesButton.setVisible(!readOnly);
}
private boolean isModified() {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 864 B

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -702,3 +702,6 @@ menu.file.start.debugpcode = Debug P-code
#after 7.1.2
button.replaceNoFill = Replace - Update bounds...
message.warning.svgImportExperimental = Not all SVG features are supported. Only solid color fill mode is supported. Please check the log after import.
message.imported.swf = The SWF file uses assets from an imported SWF file:\n%url%\nDo you want the assets to be loaded from that URL?
message.imported.swf.manually = Cannot load imported SWF\n%url%\nThe file or URL does not exist.\nDo you want to select local file?

View File

@@ -206,19 +206,27 @@ public class TagTree extends JTree {
isModified = true;
}
}*/
boolean isReadOnly = false;
if (val instanceof Tag) {
isReadOnly = ((Tag) val).isReadOnly();
}
boolean isModified = val.isModified();
if (isModified) {
if (boldFont == null) {
Font font = getFont();
boldFont = font.deriveFont(Font.BOLD);
}
} else {
if (plainFont == null) {
Font font = getFont();
plainFont = font.deriveFont(Font.PLAIN);
}
} else if (plainFont == null) {
Font font = getFont();
plainFont = font.deriveFont(Font.PLAIN);
}
setFont(isModified ? boldFont : plainFont);
if (isReadOnly) {
setForeground(new Color(0xcc, 0xcc, 0xcc));
} else {
setForeground(Color.BLACK);
}
return this;
}