#809 Move left, right buttons for DefineTexts using translatex parameter

This commit is contained in:
2015-02-22 10:48:20 +01:00
parent 354fd1143e
commit 24e1e600b3
10 changed files with 110 additions and 92 deletions
@@ -665,6 +665,11 @@ public class DefineEditTextTag extends TextTag {
return true;
}
@Override
public boolean translateText(int diff) {
return true;
}
@Override
public RECT getRect(Set<BoundedTag> added) {
return bounds;
@@ -447,6 +447,13 @@ public class DefineText2Tag extends TextTag {
return true;
}
@Override
public boolean translateText(int diff) {
textMatrix.translateX += diff;
setModified(true);
return true;
}
@Override
public RECT getRect(Set<BoundedTag> added) {
return textBounds;
@@ -455,6 +455,13 @@ public class DefineTextTag extends TextTag {
return true;
}
@Override
public boolean translateText(int diff) {
textMatrix.translateX += diff;
setModified(true);
return true;
}
@Override
public int getCharacterId() {
return characterID;
@@ -87,6 +87,8 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
public abstract boolean alignText(TextAlign textAlign);
public abstract boolean translateText(int diff);
@Override
public abstract int getCharacterId();
@@ -2007,6 +2007,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
return false;
}
public boolean translateText(TextTag textTag, int diff) {
if (textTag.translateText(diff)) {
return true;
}
return false;
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane;
import com.jpexs.decompiler.flash.tags.DefineEditTextTag;
@@ -30,7 +31,6 @@ import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.logging.Level;
@@ -48,23 +48,7 @@ import jsyntaxpane.DefaultSyntaxKit;
*
* @author JPEXS
*/
public class TextPanel extends JPanel implements ActionListener {
private static final String ACTION_EDIT_TEXT = "EDITTEXT";
private static final String ACTION_CANCEL_TEXT = "CANCELTEXT";
private static final String ACTION_SAVE_TEXT = "SAVETEXT";
private static final String ACTION_TEXT_ALIGN_LEFT = "TEXTALIGNLEFT";
private static final String ACTION_TEXT_ALIGN_CENTER = "TEXTALIGNCENTER";
private static final String ACTION_TEXT_ALIGN_RIGHT = "TEXTALIGNRIGHT";
private static final String ACTION_TEXT_ALIGN_JUSTIFY = "TEXTALIGNJUSTIFY";
private static final String ACTION_UNDO_CHANGES = "UNDOCHANGES";
public class TextPanel extends JPanel {
private final MainPanel mainPanel;
@@ -86,6 +70,10 @@ public class TextPanel extends JPanel implements ActionListener {
private final JButton textAlignJustifyButton;
private final JButton decreaseTranslateXButton;
private final JButton increaseTranslateXButton;
private final JButton undoChangesButton;
public TextPanel(final MainPanel mainPanel) {
@@ -124,16 +112,20 @@ public class TextPanel extends JPanel implements ActionListener {
JPanel textButtonsPanel = new JPanel();
textButtonsPanel.setLayout(new FlowLayout(SwingConstants.WEST));
textAlignLeftButton = createButton(null, "textalignleft16", ACTION_TEXT_ALIGN_LEFT, "text.align.left");
textAlignCenterButton = createButton(null, "textaligncenter16", ACTION_TEXT_ALIGN_CENTER, "text.align.center");
textAlignRightButton = createButton(null, "textalignright16", ACTION_TEXT_ALIGN_RIGHT, "text.align.right");
textAlignJustifyButton = createButton(null, "textalignjustify16", ACTION_TEXT_ALIGN_JUSTIFY, "text.align.justify");
undoChangesButton = createButton(null, "reload16", ACTION_UNDO_CHANGES, "text.undo");
textAlignLeftButton = createButton(null, "textalignleft16", "text.align.left", e -> textAlign(TextAlign.LEFT));
textAlignCenterButton = createButton(null, "textaligncenter16", "text.align.center", e -> textAlign(TextAlign.CENTER));
textAlignRightButton = createButton(null, "textalignright16", "text.align.right", e -> textAlign(TextAlign.RIGHT));
textAlignJustifyButton = createButton(null, "textalignjustify16", "text.align.justify", e -> textAlign(TextAlign.JUSTIFY));
decreaseTranslateXButton = createButton(null, "textoutdent16", "text.align.translatex.decrease", e -> translateX(-(int) SWF.unitDivisor));
increaseTranslateXButton = createButton(null, "textindent16", "text.align.translatex.increase", e -> translateX((int) SWF.unitDivisor));
undoChangesButton = createButton(null, "reload16", "text.undo", e -> undoChanges());
textButtonsPanel.add(textAlignLeftButton);
textButtonsPanel.add(textAlignCenterButton);
textButtonsPanel.add(textAlignRightButton);
textButtonsPanel.add(textAlignJustifyButton);
textButtonsPanel.add(decreaseTranslateXButton);
textButtonsPanel.add(increaseTranslateXButton);
textButtonsPanel.add(undoChangesButton);
textButtonsPanel.setAlignmentX(0);
@@ -141,9 +133,9 @@ public class TextPanel extends JPanel implements ActionListener {
add(topPanel, BorderLayout.NORTH);
JPanel buttonsPanel = new JPanel(new FlowLayout());
textSaveButton = createButton("button.save", "save16", ACTION_SAVE_TEXT, null);
textEditButton = createButton("button.edit", "edit16", ACTION_EDIT_TEXT, null);
textCancelButton = createButton("button.cancel", "cancel16", ACTION_CANCEL_TEXT, null);
textSaveButton = createButton("button.save", "save16", null, e -> saveText());
textEditButton = createButton("button.edit", "edit16", null, e -> editText());
textCancelButton = createButton("button.cancel", "cancel16", null, e -> cancelText());
textSaveButton.setVisible(false);
textCancelButton.setVisible(false);
@@ -154,12 +146,11 @@ public class TextPanel extends JPanel implements ActionListener {
add(buttonsPanel, BorderLayout.SOUTH);
}
private JButton createButton(String textResource, String iconName, String command, String toolTipResource) {
private JButton createButton(String textResource, String iconName, String toolTipResource, ActionListener actionListener) {
String text = textResource == null ? "" : mainPanel.translate(textResource);
JButton button = new JButton(text, View.getIcon(iconName));
button.setMargin(new Insets(3, 3, 3, 10));
button.setActionCommand(command);
button.addActionListener(this);
button.addActionListener(actionListener);
if (toolTipResource != null) {
button.setToolTipText(mainPanel.translate(toolTipResource));
}
@@ -192,6 +183,8 @@ public class TextPanel extends JPanel implements ActionListener {
textAlignCenterButton.setVisible(alignable);
textAlignRightButton.setVisible(alignable);
textAlignJustifyButton.setVisible(alignable);
increaseTranslateXButton.setVisible(alignable);
decreaseTranslateXButton.setVisible(alignable);
undoChangesButton.setVisible(item != null && item instanceof TextTag && ((Tag) item).isModified());
}
@@ -207,78 +200,66 @@ public class TextPanel extends JPanel implements ActionListener {
});
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case ACTION_EDIT_TEXT:
setEditText(true);
textChanged();
break;
case ACTION_CANCEL_TEXT:
private void editText() {
setEditText(true);
textChanged();
}
private void cancelText() {
setEditText(false);
mainPanel.reload(true);
}
private void saveText() {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
TextTag textTag = (TextTag) item;
if (mainPanel.saveText(textTag, textValue.getText(), null)) {
setEditText(false);
mainPanel.reload(true);
break;
case ACTION_SAVE_TEXT: {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
TextTag textTag = (TextTag) item;
if (mainPanel.saveText(textTag, textValue.getText(), null)) {
setEditText(false);
item.getSwf().clearImageCache();
mainPanel.refreshTree();
}
}
break;
item.getSwf().clearImageCache();
mainPanel.refreshTree();
}
case ACTION_TEXT_ALIGN_LEFT:
case ACTION_TEXT_ALIGN_CENTER:
case ACTION_TEXT_ALIGN_RIGHT:
case ACTION_TEXT_ALIGN_JUSTIFY: {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
TextTag textTag = (TextTag) item;
TextAlign ta = null;
switch (e.getActionCommand()) {
case ACTION_TEXT_ALIGN_LEFT:
ta = TextAlign.LEFT;
break;
case ACTION_TEXT_ALIGN_CENTER:
ta = TextAlign.CENTER;
break;
case ACTION_TEXT_ALIGN_RIGHT:
ta = TextAlign.RIGHT;
break;
case ACTION_TEXT_ALIGN_JUSTIFY:
ta = TextAlign.JUSTIFY;
break;
}
}
}
if (mainPanel.alignText(textTag, ta)) {
setEditText(false);
item.getSwf().clearImageCache();
mainPanel.refreshTree();
}
}
undoChangesButton.setVisible(item != null && item instanceof TextTag && ((Tag) item).isModified());
break;
private void textAlign(TextAlign textAlign) {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
TextTag textTag = (TextTag) item;
if (mainPanel.alignText(textTag, textAlign)) {
setEditText(false);
item.getSwf().clearImageCache();
mainPanel.refreshTree();
}
case ACTION_UNDO_CHANGES: {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
try {
((Tag) item).undo();
} catch (InterruptedException | IOException ex) {
Logger.getLogger(TextPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
item.getSwf().clearImageCache();
mainPanel.refreshTree();
}
break;
private void translateX(int delta) {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
TextTag textTag = (TextTag) item;
if (mainPanel.translateText(textTag, delta)) {
setEditText(false);
item.getSwf().clearImageCache();
mainPanel.refreshTree();
}
}
}
private void undoChanges() {
TreeItem item = mainPanel.tagTree.getCurrentTreeItem();
if (item instanceof TextTag) {
try {
((Tag) item).undo();
} catch (InterruptedException | IOException ex) {
Logger.getLogger(TextPanel.class.getName()).log(Level.SEVERE, null, ex);
}
item.getSwf().clearImageCache();
mainPanel.refreshTree();
}
}
private void textChanged() {
if (!Configuration.showOldTextDuringTextEditing.get()) {
return;
Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

@@ -568,3 +568,7 @@ text.undo = Undo changes
menu.file.import.xml = Import SWF XML
menu.file.export.xml = Export SWF XML
#after version 4.1.1
text.align.translatex.decrease = Decrease TranslateX
text.align.translatex.increase = Increase TranslateX
@@ -567,3 +567,7 @@ text.undo = M\u00f3dos\u00edt\u00e1sok visszavon\u00e1sa
menu.file.import.xml = SWF XML import\u00e1l\u00e1s
menu.file.export.xml = SWF XML export\u00e1l\u00e1s
#after version 4.1.1
text.align.translatex.decrease = TranslateX cs\u00f6kkent\u00e9se
text.align.translatex.increase = TranslateX n\u00f6vel\u00e9se