#809 autogwow when button is hold, justify align fixes

This commit is contained in:
2015-02-28 20:35:26 +01:00
parent a9a1e8c5fd
commit ca30321d08
15 changed files with 223 additions and 57 deletions
@@ -661,11 +661,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
private void ensureActionPanel() {
if (actionPanel == null) {
final MainPanel diz = this;
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
actionPanel = new ActionPanel(diz);
actionPanel = new ActionPanel(MainPanel.this);
displayPanel.add(actionPanel, CARDACTIONSCRIPTPANEL);
}
});
@@ -1570,7 +1569,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath();
File textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER, TextExporter.TEXT_EXPORT_FILENAME_FORMATTED));
final MainPanel diz = this;
TextImporter textImporter = new TextImporter(getMissingCharacterHandler(), new TextImportErrorHandler() {
// "configuration items" for the current replace only
@@ -1591,14 +1589,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec
public boolean handle(TextTag textTag) {
String msg = translate("error.text.import");
logger.log(Level.SEVERE, msg + getTextTagInfo(textTag));
return View.showConfirmDialog(diz, msg, translate("error"), JOptionPane.OK_CANCEL_OPTION, showAgainImportError, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION;
return View.showConfirmDialog(MainPanel.this, msg, translate("error"), JOptionPane.OK_CANCEL_OPTION, showAgainImportError, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION;
}
@Override
public boolean handle(TextTag textTag, String message, long line) {
String msg = translate("error.text.invalid.continue").replace("%text%", message).replace("%line%", Long.toString(line));
logger.log(Level.SEVERE, msg + getTextTagInfo(textTag));
return View.showConfirmDialog(diz, msg, translate("error"), JOptionPane.OK_CANCEL_OPTION, showAgainInvalidText, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION;
return View.showConfirmDialog(MainPanel.this, msg, translate("error"), JOptionPane.OK_CANCEL_OPTION, showAgainInvalidText, JOptionPane.OK_OPTION) != JOptionPane.OK_OPTION;
}
});
@@ -755,16 +755,17 @@ public class PreviewPanel extends JSplitPane implements ActionListener {
tr.yOffset = 0;
tr.styleFlagsHasXOffset = true;
tr.styleFlagsHasYOffset = true;
tr.glyphEntries = new GLYPHENTRY[1];
tr.glyphEntries = new ArrayList<>(1);
tr.styleFlagsHasColor = true;
tr.textColor = new RGB(0, 0, 0);
tr.glyphEntries[0] = new GLYPHENTRY();
GLYPHENTRY ge = new GLYPHENTRY();
double ga = ft.getGlyphAdvance(f);
int cw = ga == -1 ? w : (int) (ga / ft.getDivider() * textHeight / 1024.0);
tr.glyphEntries[0].glyphAdvance = 0;
tr.glyphEntries[0].glyphIndex = f;
ge.glyphAdvance = 0;
ge.glyphIndex = f;
tr.glyphEntries.add(ge);
rec.add(tr);
tmat.translateX = x * width / cols + width / cols / 2 - w / 2;
@@ -19,6 +19,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.gui.controls.JRepeatButton;
import com.jpexs.decompiler.flash.tags.DefineEditTextTag;
import com.jpexs.decompiler.flash.tags.base.FontTag;
import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
@@ -117,8 +118,8 @@ public class TextPanel extends JPanel {
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, "textunindent16", "text.align.translatex.decrease", e -> translateX(-(int) SWF.unitDivisor));
increaseTranslateXButton = createButton(null, "textindent16", "text.align.translatex.increase", e -> translateX((int) SWF.unitDivisor));
decreaseTranslateXButton = createButton(null, "textunindent16", "text.align.translatex.decrease", e -> translateX(-(int) SWF.unitDivisor, ((JRepeatButton) e.getSource()).getRepeatCount()), true);
increaseTranslateXButton = createButton(null, "textindent16", "text.align.translatex.increase", e -> translateX((int) SWF.unitDivisor, ((JRepeatButton) e.getSource()).getRepeatCount()), true);
undoChangesButton = createButton(null, "reload16", "text.undo", e -> undoChanges());
textButtonsPanel.add(textAlignLeftButton);
@@ -145,8 +146,12 @@ public class TextPanel extends JPanel {
}
private JButton createButton(String textResource, String iconName, String toolTipResource, ActionListener actionListener) {
return createButton(textResource, iconName, toolTipResource, actionListener, false);
}
private JButton createButton(String textResource, String iconName, String toolTipResource, ActionListener actionListener, boolean repeat) {
String text = textResource == null ? "" : mainPanel.translate(textResource);
JButton button = new JButton(text, View.getIcon(iconName));
JButton button = repeat ? new JRepeatButton(text, View.getIcon(iconName)) : new JButton(text, View.getIcon(iconName));
button.setMargin(new Insets(3, 3, 3, 10));
button.addActionListener(actionListener);
if (toolTipResource != null) {
@@ -243,8 +248,8 @@ public class TextPanel extends JPanel {
}
}
private void translateX(int delta) {
if (mainPanel.translateText(textTag, delta)) {
private void translateX(int delta, int repeatCount) {
if (mainPanel.translateText(textTag, delta * repeatCount)) {
updateButtonsVisibility();
textTag.getSwf().clearImageCache();
mainPanel.refreshTree();
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2010-2015 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.controls;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
/**
*
* @author JPEXS
*/
public class JRepeatButton extends JButton {
final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
private int repeatCount;
public JRepeatButton(String text, ImageIcon icon) {
super(text, icon);
addMouseListener(new MouseAdapter() {
int counter = 0;
ScheduledFuture<?> future;
@Override
public void mousePressed(MouseEvent e) {
Runnable runnable = new Runnable() {
private int cnt = 0;
@Override
public void run() {
SwingUtilities.invokeLater(() -> {
cnt++;
JRepeatButton button = JRepeatButton.this;
repeatCount = cnt;
fireActionPerformed(new ActionEvent(button, ActionEvent.ACTION_PERFORMED, button.getActionCommand(), e.getWhen(), e.getModifiers()));
});
}
};
future = executor.scheduleAtFixedRate(runnable, 200, 200, TimeUnit.MILLISECONDS);
}
@Override
public void mouseReleased(MouseEvent e) {
if (future != null) {
future.cancel(true);
}
}
@Override
public void mouseExited(MouseEvent e) {
if (future != null) {
future.cancel(true);
}
}
});
}
public int getRepeatCount() {
return repeatCount;
}
}