Render text during text editing and show old text in background with lighter color

This commit is contained in:
2014-12-19 22:45:45 +01:00
parent 20b4160024
commit b857f01cc9
8 changed files with 145 additions and 27 deletions
@@ -662,11 +662,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
this.tag = tag;
SWF swf = tag.getSwf();
try {
byte[] data = tag.getData();
SWFInputStream tagDataStream = new SWFInputStream(swf, data, tag.getDataPos(), data.length);
TagStub copy = new TagStub(swf, tag.getId(), "Unresolved", tag.getOriginalRange(), tagDataStream);
copy.forceWriteAsLong = tag.forceWriteAsLong;
editedTag = SWFInputStream.resolveTag(copy, 0, false, true, false);
editedTag = tag.cloneTag();
} catch (InterruptedException ex) {
} catch (IOException ex) {
Logger.getLogger(GenericTagTreePanel.class.getName()).log(Level.SEVERE, null, ex);
@@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.tags.base.ButtonTag;
import com.jpexs.decompiler.flash.tags.base.CharacterTag;
import com.jpexs.decompiler.flash.tags.base.DrawableTag;
import com.jpexs.decompiler.flash.tags.base.SoundTag;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.timeline.DepthState;
import com.jpexs.decompiler.flash.timeline.Timeline;
import com.jpexs.decompiler.flash.timeline.Timelined;
@@ -74,6 +75,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
private boolean stillFrame = false;
private Timer timer;
private int frame = -1;
private boolean zoomAvailable = false;
private int counter = 0;
private AtomicBoolean shouldDraw = new AtomicBoolean();
private SWF swf;
@@ -90,6 +92,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
private final Object delayObject = new Object();
private boolean drawReady;
private final int drawWaitLimit = 50; // ms
private TextTag textTag;
private TextTag newTextTag;
public synchronized void selectDepth(int depth) {
if (depth != selectedDepth) {
@@ -417,6 +421,9 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
public synchronized void zoom(Zoom zoom) {
this.zoom = zoom;
shouldDraw.set(true);
if (textTag != null) {
setText(textTag, newTextTag);
}
}
@Override
@@ -468,7 +475,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
@Override
public synchronized boolean zoomAvailable() {
return timelined != null;
return zoomAvailable;
}
public void setTimelined(final Timelined drawable, final SWF swf, int frame) {
@@ -480,6 +487,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
this.timelined = drawable;
this.swf = swf;
zoomAvailable = true;
counter++;
if (frame > -1) {
this.frame = frame;
@@ -520,14 +528,63 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
public synchronized void setImage(SerializableImage image) {
setBackground(View.swfBackgroundColor);
if (timer != null) {
timer.cancel();
timer = null;
}
clear();
timelined = null;
loaded = true;
stillFrame = true;
zoomAvailable = false;
iconPanel.setImg(image);
iconPanel.setOutlines(new ArrayList<DepthState>(), new ArrayList<Shape>());
drawReady = true;
}
public synchronized void setText(TextTag textTag, TextTag newTextTag) {
setBackground(View.swfBackgroundColor);
clear();
timelined = null;
loaded = true;
stillFrame = true;
zoomAvailable = true;
this.textTag = textTag;
this.newTextTag = newTextTag;
double zoomDouble = zoom.fit ? getZoomToFit() : zoom.value;
RECT rect = textTag.getRect(new HashSet<BoundedTag>());
int width = (int) (rect.getWidth() * zoomDouble);
int height = (int) (rect.getHeight() * zoomDouble);
SerializableImage image = new SerializableImage((int) (width / SWF.unitDivisor) + 1,
(int) (height / SWF.unitDivisor) + 1, SerializableImage.TYPE_INT_ARGB);
image.fillTransparent();
Matrix m = new Matrix();
m.translate(-rect.Xmin * zoomDouble, -rect.Ymin * zoomDouble);
m.scale(zoomDouble);
textTag.toImage(0, 0, 0, null, 0, image, m, new ColorTransform() {
@Override
public int getBlueAdd() {
return 192;
}
@Override
public int getGreenAdd() {
return 192;
}
@Override
public int getRedAdd() {
return 192;
}
});
if (newTextTag != null) {
newTextTag.toImage(0, 0, 0, null, 0, image, m, new ColorTransform());
}
iconPanel.setImg(image);
iconPanel.setOutlines(new ArrayList<DepthState>(), new ArrayList<Shape>());
drawReady = true;
@@ -566,6 +623,13 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
}
soundPlayers.clear();
}
private void clear() {
if (timer != null) {
timer.cancel();
timer = null;
}
}
private void nextFrame(int counter) {
drawFrame(counter);
@@ -771,11 +835,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis
}
public synchronized void stop() {
if (timer != null) {
timer.cancel();
timer = null;
}
clear();
stopAllSounds();
}
@@ -2330,6 +2330,11 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
previewPanel.showTextPanel(textTag);
}
public void showTextTagWithNewValue(TextTag textTag, TextTag newTextTag) {
previewPanel.showTextComparePanel(textTag, newTextTag);
}
private void showFolderPreview(TreeItem treeNode) {
List<TreeItem> folderPreviewItems = new ArrayList<>();
FolderItem item = (FolderItem) treeNode;
@@ -388,6 +388,10 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
imagePlayControls.setMedia(imagePanel);
imagePanel.setImage(image);
}
public void showTextComparePanel(TextTag textTag, TextTag newTextTag) {
imagePanel.setText(textTag, newTextTag);
}
public void setMedia(MediaDisplay media) {
this.media = media;
@@ -17,7 +17,10 @@
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.tags.text.TextParseException;
import com.jpexs.decompiler.flash.treeitems.TreeItem;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
@@ -25,9 +28,12 @@ import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import jsyntaxpane.DefaultSyntaxKit;
/**
@@ -47,7 +53,7 @@ public class TextPanel extends JPanel implements ActionListener {
private final JButton textEditButton;
private final JButton textCancelButton;
public TextPanel(MainPanel mainPanel) {
public TextPanel(final MainPanel mainPanel) {
super(new BorderLayout());
DefaultSyntaxKit.initKit();
@@ -59,6 +65,23 @@ public class TextPanel extends JPanel implements ActionListener {
textValue.setEditable(false);
textValue.setFont(new Font("Monospaced", Font.PLAIN, textValue.getFont().getSize()));
textValue.setContentType("text/swftext");
textValue.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
textChanged();
}
@Override
public void removeUpdate(DocumentEvent e) {
textChanged();
}
@Override
public void changedUpdate(DocumentEvent e) {
textChanged();
}
});
JPanel textButtonsPanel = new JPanel();
textButtonsPanel.setLayout(new FlowLayout());
@@ -120,6 +143,7 @@ public class TextPanel extends JPanel implements ActionListener {
switch (e.getActionCommand()) {
case ACTION_EDIT_TEXT:
setEditText(true);
textChanged();
break;
case ACTION_CANCEL_TEXT:
setEditText(false);
@@ -138,4 +162,33 @@ public class TextPanel extends JPanel implements ActionListener {
break;
}
}
private void textChanged() {
if (textValue.isEditable()) {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
TextTag textTag = (TextTag) item;
boolean ok = false;
try {
TextTag copyTextTag = (TextTag) textTag.cloneTag();
if (copyTextTag.setFormattedText(new MissingCharacterHandler() {
@Override
public boolean handle(TextTag textTag, FontTag font, char character) {
return false;
}
}, textValue.getText(), null)) {
ok = true;
mainPanel.showTextTagWithNewValue(textTag, copyTextTag);
}
} catch (TextParseException | InterruptedException | IOException ex) {
}
if (!ok) {
mainPanel.showTextTagWithNewValue(textTag, null);
}
}
}
}
}
@@ -319,12 +319,7 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener {
@Override
public void actionPerformed(ActionEvent ae) {
try {
SWF sourceSwf = tag.getSwf();
byte[] data = tag.getData();
SWFInputStream tagDataStream = new SWFInputStream(sourceSwf, data, tag.getDataPos(), data.length);
TagStub copy = new TagStub(sourceSwf, tag.getId(), "Unresolved", tag.getOriginalRange(), tagDataStream);
copy.forceWriteAsLong = tag.forceWriteAsLong;
Tag copyTag = SWFInputStream.resolveTag(copy, 0, false, true, false);
Tag copyTag = tag.cloneTag();
copyTag.setSwf(targetSwf);
targetSwf.tags.add(copyTag);
copyTag.setModified(true);