Issue #453 refresh (edit+save action) all texts button

This commit is contained in:
Honfika
2013-12-27 18:21:51 +01:00
parent e253a19eb4
commit bb50f9a1ef
4 changed files with 72 additions and 38 deletions

View File

@@ -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<String> 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<Integer> 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<Integer> 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<Integer> 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);
}

View File

@@ -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<Tag> 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<Tag> 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;

View File

@@ -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

View File

@@ -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