From bb50f9a1efe42592e2b99d7b6801274d7ac5b32c Mon Sep 17 00:00:00 2001 From: Honfika Date: Fri, 27 Dec 2013 18:21:51 +0100 Subject: [PATCH] Issue #453 refresh (edit+save action) all texts button --- .../jpexs/decompiler/flash/gui/FontPanel.java | 33 ++++++--- .../decompiler/flash/gui/MainFramePanel.java | 71 +++++++++++-------- .../flash/gui/locales/MainFrame.properties | 3 + .../flash/gui/locales/MainFrame_hu.properties | 3 + 4 files changed, 72 insertions(+), 38 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java index be4d67d24..ee03442af 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java @@ -17,7 +17,9 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.FontTag; +import com.jpexs.decompiler.flash.tags.base.TextTag; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; @@ -37,6 +39,7 @@ import java.util.TreeSet; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -66,6 +69,7 @@ public class FontPanel extends JPanel implements ActionListener { private JLabel fontLeadingLabel; private JTextArea fontCharactersTextArea; private JTextField fontAddCharactersField; + private JCheckBox updateTextsCheckBox; private ComponentListener fontChangeList; private JComboBox fontSelection; @@ -164,6 +168,9 @@ public class FontPanel extends JPanel implements ActionListener { fontAddCharsButton.setActionCommand(ACTION_FONT_ADD_CHARS); fontAddCharsButton.addActionListener(this); fontAddCharsPanel.add(fontAddCharsButton); + + updateTextsCheckBox = new JCheckBox(translate("font.updateTexts")); + fontAddCharsPanel.add(updateTextsCheckBox); JButton fontEmbedButton = new JButton(translate("button.font.embed")); fontEmbedButton.setActionCommand(ACTION_FONT_EMBED); @@ -180,8 +187,8 @@ public class FontPanel extends JPanel implements ActionListener { fontSelection.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { - if (mainFramePanel.oldValue instanceof FontTag) { - FontTag f = (FontTag) mainFramePanel.oldValue; + if (mainFramePanel.oldTag instanceof FontTag) { + FontTag f = (FontTag) mainFramePanel.oldTag; sourceFontsMap.put(f.getFontId(), (String) fontSelection.getSelectedItem()); } } @@ -208,7 +215,7 @@ public class FontPanel extends JPanel implements ActionListener { } private void fontAddChars(FontTag ft, Set selChars, String selFont) { - FontTag f = (FontTag) mainFramePanel.oldValue; + FontTag f = (FontTag) mainFramePanel.oldTag; SWF swf = ft.getSwf(); String oldchars = f.getCharacters(swf.tags); for (int ic : selChars) { @@ -253,6 +260,16 @@ public class FontPanel extends JPanel implements ActionListener { f.addCharacter(swf.tags, c, fontSelection.getSelectedItem().toString()); oldchars += c; } + + if (updateTextsCheckBox.isSelected()) { + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + String text = textTag.getFormattedText(textTag.getSwf().tags); + mainFramePanel.saveText(textTag, text); + } + } + } } public void showFontTag(FontTag ft) { @@ -277,14 +294,14 @@ public class FontPanel extends JPanel implements ActionListener { public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { case ACTION_FONT_EMBED: - if (mainFramePanel.oldValue instanceof FontTag) { - FontEmbedDialog fed = new FontEmbedDialog(fontSelection.getSelectedItem().toString(), fontAddCharactersField.getText(), ((FontTag) mainFramePanel.oldValue).getFontStyle()); + if (mainFramePanel.oldTag instanceof FontTag) { + FontEmbedDialog fed = new FontEmbedDialog(fontSelection.getSelectedItem().toString(), fontAddCharactersField.getText(), ((FontTag) mainFramePanel.oldTag).getFontStyle()); if (fed.display()) { Set selChars = fed.getSelectedChars(); if (!selChars.isEmpty()) { String selFont = fed.getSelectedFont(); fontSelection.setSelectedItem(selFont); - fontAddChars((FontTag) mainFramePanel.oldValue, selChars, selFont); + fontAddChars((FontTag) mainFramePanel.oldTag, selChars, selFont); fontAddCharactersField.setText(""); mainFramePanel.reload(true); } @@ -293,12 +310,12 @@ public class FontPanel extends JPanel implements ActionListener { break; case ACTION_FONT_ADD_CHARS: String newchars = fontAddCharactersField.getText(); - if (mainFramePanel.oldValue instanceof FontTag) { + if (mainFramePanel.oldTag instanceof FontTag) { Set selChars = new TreeSet<>(); for (int c = 0; c < newchars.length(); c++) { selChars.add(newchars.codePointAt(c)); } - fontAddChars((FontTag) mainFramePanel.oldValue, selChars, fontSelection.getSelectedItem().toString()); + fontAddChars((FontTag) mainFramePanel.oldTag, selChars, fontSelection.getSelectedItem().toString()); fontAddCharactersField.setText(""); mainFramePanel.reload(true); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java index c941e85a3..eec303f39 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java @@ -246,7 +246,8 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree private JPanel viewerCards; private AbortRetryIgnoreHandler errorHandler = new GuiAbortRetryIgnoreHandler(); private CancellableWorker setSourceWorker; - public TreeNode oldValue; + public TreeNode oldNode; + public TreeElementItem oldTag; private File tempFile; private static final String ACTION_SELECT_COLOR = "SELECTCOLOR"; @@ -948,7 +949,8 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree public void closeAll() { swfs.clear(); - oldValue = null; + oldNode = null; + oldTag = null; if (abcPanel != null) { abcPanel.clearSwf(); } @@ -967,7 +969,8 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree if (actionPanel != null) { actionPanel.clearSource(); } - oldValue = null; + oldNode = null; + oldTag = null; updateUi(); updateTagTree(); } @@ -1951,6 +1954,34 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree updateClassesList(); } + public boolean saveText(TextTag textTag, String text) { + try { + if (textTag.setFormattedText(new MissingCharacterHandler() { + @Override + public boolean handle(FontTag font, List tags, char character) { + String fontName = fontPanel.sourceFontsMap.get(font.getFontId()); + if (fontName == null) { + fontName = font.getFontName(tags); + } + fontName = FontTag.findInstalledFontName(fontName); + Font f = new Font(fontName, font.getFontStyle(), 18); + if (!f.canDisplay(character)) { + View.showMessageDialog(null, translate("error.font.nocharacter").replace("%char%", "" + character), translate("error"), JOptionPane.ERROR_MESSAGE); + return false; + } + font.addCharacter(tags, character, fontName); + return true; + + } + }, textTag.getSwf().tags, text, fontPanel.getSelectedFont())) { + return true; + } + } catch (ParseException ex) { + View.showMessageDialog(null, translate("error.text.invalid").replace("%text%", ex.text).replace("%line%", "" + ex.line), translate("error"), JOptionPane.ERROR_MESSAGE); + } + return false; + } + @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { @@ -2076,31 +2107,10 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree setEditText(false); break; case ACTION_SAVE_TEXT: - if (oldValue instanceof TextTag) { - TextTag textTag = (TextTag) oldValue; - try { - if (textTag.setFormattedText(new MissingCharacterHandler() { - @Override - public boolean handle(FontTag font, List tags, char character) { - String fontName = fontPanel.sourceFontsMap.get(font.getFontId()); - if (fontName == null) { - fontName = font.getFontName(tags); - } - fontName = FontTag.findInstalledFontName(fontName); - Font f = new Font(fontName, font.getFontStyle(), 18); - if (!f.canDisplay(character)) { - View.showMessageDialog(null, translate("error.font.nocharacter").replace("%char%", "" + character), translate("error"), JOptionPane.ERROR_MESSAGE); - return false; - } - font.addCharacter(tags, character, fontName); - return true; - - } - }, textTag.getSwf().tags, textValue.getText(), fontPanel.getSelectedFont())) { - setEditText(false); - } - } catch (ParseException ex) { - View.showMessageDialog(null, translate("error.text.invalid").replace("%text%", ex.text).replace("%line%", "" + ex.line), translate("error"), JOptionPane.ERROR_MESSAGE); + if (oldTag instanceof TextTag) { + TextTag textTag = (TextTag) oldTag; + if (saveText(textTag, textValue.getText())) { + setEditText(false); } } break; @@ -2184,11 +2194,11 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree return; } - if (!forceReload && (treeNode == oldValue)) { + if (!forceReload && (treeNode == oldNode)) { return; } - oldValue = treeNode; + oldNode = treeNode; TreeElementItem tagObj = null; if (treeNode instanceof TagNode) { @@ -2198,6 +2208,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree tagObj = ((TreeElement) treeNode).getItem(); } + oldTag = tagObj; if (flashPanel != null) { flashPanel.specialPlayback = false; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 939018122..292f22500 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -383,3 +383,6 @@ contextmenu.closeSwf = Close SWF menu.settings.autoRenameIdentifiers = Auto rename identifiers menu.file.saveasexe = Save as Exe... filter.exe = Executable files (*.exe) + +#after version 1.8.0 +font.updateTexts = Update texts diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties index c57fd3433..629102688 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties @@ -383,3 +383,6 @@ contextmenu.closeSwf = SWF bez\u00e1r\u00e1sa menu.settings.autoRenameIdentifiers = Azonos\u00edt\u00f3k automatikus \u00e1tnevez\u00e9se menu.file.saveasexe = Ment\u00e9s Exe-k\u00e9nt... filter.exe = Futtathat\u00f3 f\u00e1jlok (*.exe) + +#after version 1.8.0 +font.updateTexts = Sz\u00f6vegek friss\u00edt\u00e9se